spbhost.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. spbhost.h
  5. Abstract:
  6. This header contains definitions for creating and managing Simple
  7. Peripheral Bus controllers.
  8. Author:
  9. Evan Green 14-Aug-2015
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. #include <minoca/spb/spb.h>
  15. //
  16. // ---------------------------------------------------------------- Definitions
  17. //
  18. #ifndef SPB_API
  19. #define SPB_API __DLLIMPORT
  20. #endif
  21. #define SPB_CONTROLLER_INFORMATION_VERSION 1
  22. //
  23. // ------------------------------------------------------ Data Type Definitions
  24. //
  25. typedef struct _SPB_CONTROLLER SPB_CONTROLLER, *PSPB_CONTROLLER;
  26. typedef
  27. KSTATUS
  28. (*PSPB_HOST_CONFIGURE) (
  29. PVOID Context,
  30. PRESOURCE_SPB_DATA Configuration
  31. );
  32. /*++
  33. Routine Description:
  34. This routine configures the given Simple Peripheral Bus controller.
  35. Arguments:
  36. Context - Supplies the host controller context.
  37. Configuration - Supplies a pointer to the new configuration to set.
  38. Return Value:
  39. Status code.
  40. --*/
  41. typedef
  42. KSTATUS
  43. (*PSPB_HOST_SUBMIT_TRANSFER) (
  44. PVOID Context,
  45. PSPB_TRANSFER Transfer
  46. );
  47. /*++
  48. Routine Description:
  49. This routine is called to execute a single transfer on the Simple
  50. Peripheral Bus. The host controller is responsible for implementing the
  51. delay set in the transfer.
  52. Arguments:
  53. Context - Supplies the host controller context.
  54. Transfer - Supplies a pointer to the transfer to begin executing. The
  55. controller can return immediately, and should call
  56. SpbProcessCompletedTransfer when the transfer completes.
  57. Return Value:
  58. Status code indicating whether or not the transfer was successfully
  59. started.
  60. --*/
  61. typedef
  62. VOID
  63. (*PSPB_HOST_LOCK_BUS) (
  64. PVOID Context,
  65. PRESOURCE_SPB_DATA Configuration
  66. );
  67. /*++
  68. Routine Description:
  69. This routine is called when the bus is being locked for a particular
  70. transfer set or directly via the interface. The software synchronization
  71. portion of locking the bus is handled by the SPB library, this routine
  72. only needs to do hardware-specific actions (like selecting or deselecting
  73. device lines).
  74. Arguments:
  75. Context - Supplies the host controller context.
  76. Configuration - Supplies a pointer to the configuration of the handle that
  77. locked this bus. The configure bus function will still be called, this
  78. is only passed for reference if bus-specific actions need to be
  79. performed (like selecting or deselecting the device).
  80. Return Value:
  81. None.
  82. --*/
  83. typedef
  84. VOID
  85. (*PSPB_HOST_UNLOCK_BUS) (
  86. PVOID Context
  87. );
  88. /*++
  89. Routine Description:
  90. This routine is called when the bus is being unlocked.
  91. Arguments:
  92. Context - Supplies the host controller context.
  93. Return Value:
  94. None.
  95. --*/
  96. /*++
  97. Structure Description:
  98. This structure stores the set of Simple Peripheral Bus controller functions
  99. called by the SPB library.
  100. Members:
  101. Configure - Stores a pointer to a function used to set the current bus
  102. parameters.
  103. SubmitTransfer - Stores a pointer to a function used to begin a new
  104. transfer.
  105. LockBus - Stores an optional pointer to a function that is called when the
  106. bus is being locked.
  107. UnlockBus - Stores an optional pointer to a function that is called when
  108. the bus is being unlocked.
  109. --*/
  110. typedef struct _SPB_FUNCTION_TABLE {
  111. PSPB_HOST_CONFIGURE Configure;
  112. PSPB_HOST_SUBMIT_TRANSFER SubmitTransfer;
  113. PSPB_HOST_LOCK_BUS LockBus;
  114. PSPB_HOST_UNLOCK_BUS UnlockBus;
  115. } SPB_FUNCTION_TABLE, *PSPB_FUNCTION_TABLE;
  116. /*++
  117. Structure Description:
  118. This structure defines the information provided to the SPB library by a
  119. Simple Peripheral Bus controller.
  120. Members:
  121. Version - Stores the value SPB_CONTROLLER_INFORMATION_VERSION, used to
  122. enable future expansion of this structure.
  123. Context - Stores an opaque context pointer that is passed to the SPB
  124. controller functions.
  125. Device - Stores a pointer to the OS device associated with this controller.
  126. MaxFrequency - Stores the maximum bus clock frequency.
  127. BusType - Stores the bus type for this controller.
  128. Features - Stores a bitfield of features about this controller. See
  129. SPB_FEATURE_* definitions.
  130. FunctionTable - Stores the table of functions the library uses to call back
  131. into the controller.
  132. --*/
  133. typedef struct _SPB_CONTROLLER_INFORMATION {
  134. ULONG Version;
  135. PVOID Context;
  136. PDEVICE Device;
  137. ULONG MaxFrequency;
  138. RESOURCE_SPB_BUS_TYPE BusType;
  139. ULONG Features;
  140. SPB_FUNCTION_TABLE FunctionTable;
  141. } SPB_CONTROLLER_INFORMATION, *PSPB_CONTROLLER_INFORMATION;
  142. //
  143. // -------------------------------------------------------------------- Globals
  144. //
  145. //
  146. // -------------------------------------------------------- Function Prototypes
  147. //
  148. SPB_API
  149. KSTATUS
  150. SpbCreateController (
  151. PSPB_CONTROLLER_INFORMATION Registration,
  152. PSPB_CONTROLLER *Controller
  153. );
  154. /*++
  155. Routine Description:
  156. This routine creates a new Simple Peripheral Bus controller.
  157. Arguments:
  158. Registration - Supplies a pointer to the host registration information.
  159. Controller - Supplies a pointer where a pointer to the new controller will
  160. be returned on success.
  161. Return Value:
  162. Status code.
  163. --*/
  164. SPB_API
  165. VOID
  166. SpbDestroyController (
  167. PSPB_CONTROLLER Controller
  168. );
  169. /*++
  170. Routine Description:
  171. This routine destroys a Simple Peripheral Bus controller.
  172. Arguments:
  173. Controller - Supplies a pointer to the controller to tear down.
  174. Return Value:
  175. None.
  176. --*/
  177. SPB_API
  178. KSTATUS
  179. SpbStartController (
  180. PSPB_CONTROLLER Controller
  181. );
  182. /*++
  183. Routine Description:
  184. This routine starts a Simple Peripheral Bus controller.
  185. Arguments:
  186. Controller - Supplies a pointer to the controller.
  187. Return Value:
  188. Status code.
  189. --*/
  190. SPB_API
  191. VOID
  192. SpbStopController (
  193. PSPB_CONTROLLER Controller
  194. );
  195. /*++
  196. Routine Description:
  197. This routine stops a Simple Peripheral Bus controller.
  198. Arguments:
  199. Controller - Supplies a pointer to the controller.
  200. Return Value:
  201. None.
  202. --*/
  203. SPB_API
  204. PSPB_TRANSFER
  205. SpbTransferCompletion (
  206. PSPB_CONTROLLER Controller,
  207. PSPB_TRANSFER Transfer,
  208. KSTATUS Status
  209. );
  210. /*++
  211. Routine Description:
  212. This routine is called by an SPB host controller when a transfer has
  213. completed.
  214. Arguments:
  215. Controller - Supplies a pointer to the controller.
  216. Transfer - Supplies a pointer to the transfer that completed.
  217. Status - Supplies the status code the transfer completed with.
  218. Return Value:
  219. Returns a new transfer to begin executing if there are additional transfers
  220. in this set and the previous transfer completed successfully.
  221. NULL if no new transfers should be started at this time.
  222. --*/