spb.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. spb.h
  9. Abstract:
  10. This header contains definitions for the Simple Peripheral Bus
  11. interface.
  12. Author:
  13. Evan Green 14-Aug-2015
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. //
  19. // ---------------------------------------------------------------- Definitions
  20. //
  21. //
  22. // Interface UUID for the Simple Peripheral Bus.
  23. //
  24. #define UUID_SPB_INTERFACE \
  25. {{0xC56A4C6F, 0xA81547D7, 0xA8DE4E74, 0x0853B3D5}}
  26. //
  27. // Define flags that go on an individual SPB transfer.
  28. //
  29. //
  30. // This flag is set automatically by the SPB library on the first transfer of
  31. // a transfer set.
  32. //
  33. #define SPB_TRANSFER_FLAG_FIRST 0x00000001
  34. //
  35. // This flag is set automatically by the SPB library on the last transfer of
  36. // a transfer set.
  37. //
  38. #define SPB_TRANSFER_FLAG_LAST 0x00000002
  39. //
  40. // Define the set of SPB transfer flags that are set automatically by the SPB
  41. // library.
  42. //
  43. #define SPB_TRANSFER_FLAG_AUTO_MASK \
  44. (SPB_TRANSFER_FLAG_FIRST | SPB_TRANSFER_FLAG_LAST)
  45. //
  46. // ------------------------------------------------------ Data Type Definitions
  47. //
  48. //
  49. // Define the transfer directions for bus tranfers. Both is for busses like SPI
  50. // that can simultaneously read and write in full duplex mode.
  51. //
  52. typedef enum _SPB_TRANSFER_DIRECTION {
  53. SpbTransferDirectionInvalid,
  54. SpbTransferDirectionIn,
  55. SpbTransferDirectionOut,
  56. SpbTransferDirectionBoth
  57. } SPB_TRANSFER_DIRECTION, *PSPB_TRANSFER_DIRECTION;
  58. //
  59. // Define the type of an open SPB connection.
  60. //
  61. typedef PVOID SPB_HANDLE, *PSPB_HANDLE;
  62. typedef struct _SPB_INTERFACE SPB_INTERFACE, *PSPB_INTERFACE;
  63. typedef struct _SPB_TRANSFER_SET SPB_TRANSFER_SET, *PSPB_TRANSFER_SET;
  64. typedef
  65. VOID
  66. (*PSPB_TRANSFER_COMPLETION_CALLBACK) (
  67. PSPB_TRANSFER_SET TransferSet
  68. );
  69. /*++
  70. Routine Description:
  71. This routine is called when a transfer set has completed or errored out.
  72. Arguments:
  73. TransferSet - Supplies a pointer to the transfer set that completed.
  74. Return Value:
  75. None.
  76. --*/
  77. /*++
  78. Structure Description:
  79. This structure stores information about a grouped set of transfers on a
  80. Simple Peripheral Bus.
  81. Members:
  82. ListEntry - Stores a list entry used internally to keep transfer sets on a
  83. queue.
  84. Handle - Stores the handle that has queued this transfer set. This will be
  85. set by the SPB library upon submitting the transfer.
  86. TransferList - Stores the head of the list of transfers to execute in this
  87. set.
  88. Flags - Stores a set of flags governing the behavior of this transfer
  89. sequence.
  90. EntriesProcessed - Stores the number of entries that were completely or
  91. partially processed.
  92. Status - Stores the resulting status code of the transfer attempt.
  93. CompletionRoutine - Stores a pointer to the routine to call when the
  94. transfer has completed.
  95. CompletionContext - Stores a pointer's worth of context that the completion
  96. routine can use. The SPB bus functions do not touch this value.
  97. --*/
  98. struct _SPB_TRANSFER_SET {
  99. LIST_ENTRY ListEntry;
  100. SPB_HANDLE Handle;
  101. LIST_ENTRY TransferList;
  102. ULONG Flags;
  103. UINTN EntriesProcessed;
  104. KSTATUS Status;
  105. PSPB_TRANSFER_COMPLETION_CALLBACK CompletionRoutine;
  106. PVOID Context;
  107. };
  108. /*++
  109. Structure Description:
  110. This structure stores information about a single Simple Peripheral Bus
  111. transfer.
  112. Members:
  113. ListEntry - Stores pointers to the next and previous transfers in the
  114. transfer set.
  115. Direction - Stores the transfer direction. For "both" direction transfers,
  116. the same buffer will be used for both input and output.
  117. IoBuffer - Stores a pointer to the I/O buffer.
  118. Offset - Stores the offset within the I/O buffer for this data transfer
  119. portion.
  120. Size - Stores the size of the transfer in bytes. It is an error if this
  121. size does not translate evenly to bus sized words (where each word is
  122. rounded up to its next power of 2).
  123. ReceiveSizeCompleted - Stores the number of bytes that have been
  124. successfully received.
  125. TransmitSizeCompleted - Stores the number of bytes that have been
  126. successfully transmitted.
  127. MicrosecondDelay - Stores the minimum number of microseconds to delay
  128. before executing this transfer. If this is the first transfer, the
  129. device will be activated first (chip select, etc) before the delay
  130. begins. The delay may end up being larger than this value.
  131. Flags - Stores a bitfield of bus-specific flags regarding this transfer.
  132. --*/
  133. typedef struct _SPB_TRANSFER {
  134. LIST_ENTRY ListEntry;
  135. SPB_TRANSFER_DIRECTION Direction;
  136. PIO_BUFFER IoBuffer;
  137. UINTN Offset;
  138. UINTN Size;
  139. UINTN ReceiveSizeCompleted;
  140. UINTN TransmitSizeCompleted;
  141. ULONG MicrosecondDelay;
  142. ULONG Flags;
  143. } SPB_TRANSFER, *PSPB_TRANSFER;
  144. typedef
  145. KSTATUS
  146. (*PSPB_OPEN) (
  147. PSPB_INTERFACE Interface,
  148. PRESOURCE_SPB_DATA Configuration,
  149. PSPB_HANDLE Handle
  150. );
  151. /*++
  152. Routine Description:
  153. This routine opens a new connection to a Simple Peripheral Bus.
  154. Arguments:
  155. Interface - Supplies a pointer to the interface instance, used to identify
  156. which specific bus is being opened.
  157. Configuration - Supplies a pointer to the configuration data that specifies
  158. bus specific configuration parameters.
  159. Handle - Supplies a pointer where a handle will be returned on success
  160. representing the connection to the device.
  161. Return Value:
  162. Status code.
  163. --*/
  164. typedef
  165. VOID
  166. (*PSPB_CLOSE) (
  167. PSPB_INTERFACE Interface,
  168. SPB_HANDLE Handle
  169. );
  170. /*++
  171. Routine Description:
  172. This routine closes a previously opened to a Simple Peripheral Bus.
  173. Arguments:
  174. Interface - Supplies a pointer to the interface instance, used to identify
  175. which specific bus is being operated on.
  176. Handle - Supplies the open handle to close.
  177. Return Value:
  178. None.
  179. --*/
  180. typedef
  181. KSTATUS
  182. (*PSPB_SET_CONFIGURATION) (
  183. SPB_HANDLE Handle,
  184. PRESOURCE_SPB_DATA Configuration
  185. );
  186. /*++
  187. Routine Description:
  188. This routine writes a new set of bus parameters to the bus.
  189. Arguments:
  190. Handle - Supplies the open handle to change configuration of.
  191. Configuration - Supplies the new configuration to set.
  192. Return Value:
  193. Status code.
  194. --*/
  195. typedef
  196. VOID
  197. (*PSPB_LOCK_BUS) (
  198. SPB_HANDLE Handle
  199. );
  200. /*++
  201. Routine Description:
  202. This routine locks the bus so that this handle may perform a sequence of
  203. accesses without being interrupted. The perform transfer function
  204. automatically locks the bus throughout the sequence of transfers, so this
  205. routine should not be necessary for normal operations.
  206. Arguments:
  207. Handle - Supplies the open handle to the bus to lock.
  208. Return Value:
  209. None.
  210. --*/
  211. typedef
  212. VOID
  213. (*PSPB_UNLOCK_BUS) (
  214. SPB_HANDLE Handle
  215. );
  216. /*++
  217. Routine Description:
  218. This routine unlocks a bus that was previously locked with the lock
  219. function. See the lock function description for why this routine should not
  220. be needed for normal operation.
  221. Arguments:
  222. Handle - Supplies the open handle to the bus to unlock. The caller must
  223. have previously locked the bus.
  224. Return Value:
  225. None.
  226. --*/
  227. typedef
  228. KSTATUS
  229. (*PSPB_SUBMIT_TRANSFER_SET) (
  230. SPB_HANDLE Handle,
  231. PSPB_TRANSFER_SET TransferSet
  232. );
  233. /*++
  234. Routine Description:
  235. This routine submits a set of transfers to the bus for execution. This
  236. routine will ensure that other devices do not perform transfers while any
  237. transfer in this set is in progress. The submission is asynchronous, this
  238. routine will return immediately, and the callback function will be called
  239. when the transfer is complete.
  240. Arguments:
  241. Handle - Supplies the open handle to the bus to unlock.
  242. TransferSet - Supplies a pointer to the transfer set to execute.
  243. Return Value:
  244. Status code. This routine will return immediately, the transfer will not
  245. have been complete. The caller should utilize the callback function to get
  246. notified when a transfer has completed.
  247. --*/
  248. typedef
  249. KSTATUS
  250. (*PSPB_EXECUTE_TRANSFER_SET) (
  251. SPB_HANDLE Handle,
  252. PSPB_TRANSFER_SET TransferSet
  253. );
  254. /*++
  255. Routine Description:
  256. This routine submits a set of transfers to the bus for execution. This
  257. routine will ensure that other devices do not perform transfers while any
  258. transfer in this set is in progress. This routine is synchronous, it will
  259. not return until the transfer is complete.
  260. Arguments:
  261. Handle - Supplies the open handle to the bus to unlock.
  262. TransferSet - Supplies a pointer to the transfer set to execute.
  263. Return Value:
  264. Status code indicating completion status of the transfer. This routine will
  265. not return until the transfer is complete (or failed).
  266. --*/
  267. /*++
  268. Structure Description:
  269. This structure defines the interface to a Simple Peripheral Bus device.
  270. Each handle given out by the open function of this interface is not thread
  271. safe.
  272. Members:
  273. Context - Stores an opaque pointer to additinal data that the interface
  274. producer uses to identify this interface instance.
  275. Open - Stores a pointer to a function that opens a connection to a bus
  276. device.
  277. Close - Stores a pointer to a function that closes a previously opened
  278. connection to a bus device.
  279. SetConfiguration - Stores a pointer to a function used to set new bus
  280. parameters for the connection.
  281. LockBus - Stores a pointer to a function that locks the bus from all other
  282. users.
  283. UnlockBus - Stores a pointer to a function that unlocks the bus.
  284. SubmitTransferSet - Stores a pointer to a function used to submit a
  285. transfer on the bus asynchronously
  286. ExecuteTransferSet - Stores a pointer to a function used to submit a
  287. transfer on the bus synchronously.
  288. --*/
  289. struct _SPB_INTERFACE {
  290. PVOID Context;
  291. PSPB_OPEN Open;
  292. PSPB_CLOSE Close;
  293. PSPB_SET_CONFIGURATION SetConfiguration;
  294. PSPB_LOCK_BUS LockBus;
  295. PSPB_UNLOCK_BUS UnlockBus;
  296. PSPB_SUBMIT_TRANSFER_SET SubmitTransferSet;
  297. PSPB_EXECUTE_TRANSFER_SET ExecuteTransferSet;
  298. };
  299. //
  300. // -------------------------------------------------------------------- Globals
  301. //
  302. //
  303. // -------------------------------------------------------- Function Prototypes
  304. //