spb.h 10 KB

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