kdusb.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*++
  2. Copyright (c) 2014 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. kdusb.h
  9. Abstract:
  10. This header contains definitions for USB debug devices.
  11. Author:
  12. Evan Green 26-Mar-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. #define DEBUG_USB_HOST_DESCRIPTION_VERSION 1
  21. //
  22. // Define USB port status bits.
  23. //
  24. #define DEBUG_USB_PORT_STATUS_CONNECTED 0x00000001
  25. #define DEBUG_USB_PORT_STATUS_ENABLED 0x00000002
  26. #define DEBUG_USB_PORT_STATUS_SUSPENDED 0x00000004
  27. #define DEBUG_USB_PORT_STATUS_OVER_CURRENT 0x00000008
  28. #define DEBUG_USB_PORT_STATUS_RESET 0x00000010
  29. #define DEBUG_USB_PORT_STATUS_LOW_SPEED 0x00000100
  30. #define DEBUG_USB_PORT_STATUS_FULL_SPEED 0x00000200
  31. #define DEBUG_USB_PORT_STATUS_HIGH_SPEED 0x00000400
  32. #define DEBUG_USB_PORT_STATUS_SUPER_SPEED 0x00000800
  33. #define DEBUG_USB_SETUP_PACKET_SIZE 8
  34. #define DEBUG_USB_ENDPOINT_ADDRESS_MASK 0x0F
  35. //
  36. // ------------------------------------------------------ Data Type Definitions
  37. //
  38. typedef enum _DEBUG_USB_DEVICE_SPEED {
  39. DebugUsbDeviceSpeedInvalid,
  40. DebugUsbDeviceSpeedLow,
  41. DebugUsbDeviceSpeedFull,
  42. DebugUsbDeviceSpeedHigh,
  43. DebugUsbDeviceSpeedSuper,
  44. } DEBUG_USB_DEVICE_SPEED, *PDEBUG_USB_DEVICE_SPEED;
  45. typedef enum _DEBUG_USB_TRANSFER_TYPE {
  46. DebugUsbTransferTypeInvalid,
  47. DebugUsbTransferTypeControl,
  48. DebugUsbTransferTypeInterrupt,
  49. DebugUsbTransferTypeBulk,
  50. DebugUsbTransferTypeIsochronous,
  51. DebugUsbTransferTypeCount
  52. } DEBUG_USB_TRANSFER_TYPE, *PDEBUG_USB_TRANSFER_TYPE;
  53. typedef enum _DEBUG_USB_TRANSFER_DIRECTION {
  54. DebugUsbTransferDirectionInvalid,
  55. DebugUsbTransferDirectionIn,
  56. DebugUsbTransferDirectionOut,
  57. DebugUsbTransferBidirectional,
  58. DebugUsbTransferDirectionCount
  59. } DEBUG_USB_TRANSFER_DIRECTION, *PDEBUG_USB_TRANSFER_DIRECTION;
  60. /*++
  61. Structure Description:
  62. This structure stores information about a debug USB transfer request.
  63. Members:
  64. Type - Stores the type of USB request that this transfer is.
  65. Direction - Stores the direction of the USB endpoint.
  66. Speed - Stores the speed of the destination device.
  67. HubAddress - Stores the address of the hub this device is connected to.
  68. This is only required for full or low speed devices on a high speed
  69. bus.
  70. HubPort - Stores the one-based port number of the hub this device is
  71. connected to. This is only required for full or low speed devices on a
  72. high speed bus.
  73. EndpointNumber - Stores the endpoint number, including the high 0x80 bit.
  74. DeviceAddress - Stores the device address of the device that owns this
  75. endpoint.
  76. DataToggle - Stores the data toggle value of the next transfer descriptor
  77. to be filled out.
  78. Halted - Stores a boolean indicating if the endpoint is halted.
  79. MaxPacketSize - Stores the maximum packet size of this endpoint.
  80. --*/
  81. typedef struct _DEBUG_USB_ENDPOINT {
  82. DEBUG_USB_TRANSFER_TYPE Type;
  83. DEBUG_USB_TRANSFER_DIRECTION Direction;
  84. DEBUG_USB_DEVICE_SPEED Speed;
  85. UCHAR HubAddress;
  86. UCHAR HubPort;
  87. UCHAR EndpointNumber;
  88. UCHAR DeviceAddress;
  89. BOOL DataToggle;
  90. BOOL Halted;
  91. ULONG MaxPacketSize;
  92. } DEBUG_USB_ENDPOINT, *PDEBUG_USB_ENDPOINT;
  93. /*++
  94. Structure Description:
  95. This structure stores information about a debug USB transfer request.
  96. Members:
  97. Endpoint - Stores a pointer to the endpoint this transfer is associated
  98. with.
  99. Direction - Stores the direction of the USB transfer. This must be
  100. consistent with the endpoint being sent to.
  101. Length - Stores the length of the request, in bytes.
  102. LengthTransferred - Stores the number of bytes that have actually been
  103. transferred.
  104. Buffer - Stores a pointer to the data buffer.
  105. BufferPhysicalAddress - Stores the physical address of the data buffer.
  106. HostContext - Stores a pointer of context for the host controller.
  107. HostDescriptorCount - Stores a value used optionally and internally by the
  108. host controller. Consumers should not use this value.
  109. Status - Stores the completion status of the request.
  110. --*/
  111. typedef struct _DEBUG_USB_TRANSFER {
  112. PDEBUG_USB_ENDPOINT Endpoint;
  113. DEBUG_USB_TRANSFER_DIRECTION Direction;
  114. ULONG Length;
  115. ULONG LengthTransferred;
  116. PVOID Buffer;
  117. PHYSICAL_ADDRESS BufferPhysicalAddress;
  118. PVOID HostContext;
  119. ULONG HostDescriptorCount;
  120. KSTATUS Status;
  121. } DEBUG_USB_TRANSFER, *PDEBUG_USB_TRANSFER;
  122. typedef
  123. KSTATUS
  124. (*PDEBUG_USB_HOST_INITIALIZE) (
  125. PVOID Context
  126. );
  127. /*++
  128. Routine Description:
  129. This routine initializes a USB debug device, preparing it to return the
  130. root hub status and ultimately send and receive transfers.
  131. Arguments:
  132. Context - Supplies a pointer to the device context.
  133. Return Value:
  134. Status code.
  135. --*/
  136. typedef
  137. KSTATUS
  138. (*PDEBUG_USB_HOST_GET_ROOT_HUB_STATUS) (
  139. PVOID Context,
  140. ULONG PortIndex,
  141. PULONG PortStatus
  142. );
  143. /*++
  144. Routine Description:
  145. This routine queries the host controller for the status of a root hub port.
  146. Arguments:
  147. Context - Supplies a pointer to the device context.
  148. PortIndex - Supplies the zero-based port number to query.
  149. PortStatus - Supplies a pointer where the port status is returned.
  150. Return Value:
  151. STATUS_SUCCESS if the hub status was successfully queried.
  152. STATUS_OUT_OF_BOUNDS if the controller port index is out of range.
  153. STATUS_DEVICE_IO_ERROR if a device error occurred.
  154. --*/
  155. typedef
  156. KSTATUS
  157. (*PDEBUG_USB_HOST_SET_ROOT_HUB_STATUS) (
  158. PVOID Context,
  159. ULONG PortIndex,
  160. ULONG PortStatus
  161. );
  162. /*++
  163. Routine Description:
  164. This routine sets the host controller for the status of a root hub port.
  165. Arguments:
  166. Context - Supplies a pointer to the device context.
  167. PortIndex - Supplies the zero-based port number to set.
  168. PortStatus - Supplies the port status to set.
  169. Return Value:
  170. STATUS_SUCCESS if the hub status was successfully queried.
  171. STATUS_OUT_OF_BOUNDS if the controller port index is out of range.
  172. STATUS_DEVICE_IO_ERROR if a device error occurred.
  173. --*/
  174. typedef
  175. KSTATUS
  176. (*PDEBUG_USB_HOST_SETUP_TRANSFER) (
  177. PVOID Context,
  178. PDEBUG_USB_TRANSFER Transfer
  179. );
  180. /*++
  181. Routine Description:
  182. This routine allocates a buffer and initializes the given USB transfer.
  183. Arguments:
  184. Context - Supplies a pointer to the device context.
  185. Transfer - Supplies a pointer to the transfer to initialize to. The caller
  186. must have filled out the endpoint, direction, and length members. This
  187. routine will allocate buffer space for the transfer data.
  188. Return Value:
  189. STATUS_SUCCESS if the hub status was successfully queried.
  190. STATUS_INVALID_PARAMETER if the given transfer was not filled out correctly.
  191. STATUS_INSUFFICIENT_RESOURCES if a buffer for the transfer could not be
  192. allocated.
  193. STATUS_DEVICE_IO_ERROR if a device error occurred.
  194. --*/
  195. typedef
  196. KSTATUS
  197. (*PDEBUG_USB_HOST_SUBMIT_TRANSFER) (
  198. PVOID Context,
  199. PDEBUG_USB_TRANSFER Transfer,
  200. BOOL WaitForCompletion
  201. );
  202. /*++
  203. Routine Description:
  204. This routine submits a previously set up USB transfer.
  205. Arguments:
  206. Context - Supplies a pointer to the device context.
  207. Transfer - Supplies a pointer to the transfer to submit.
  208. WaitForCompletion - Supplies a boolean indicating if the routine should
  209. block until the transfer completes.
  210. Return Value:
  211. STATUS_SUCCESS if the hub status was successfully queried.
  212. STATUS_INVALID_PARAMETER if the given transfer was not initialized
  213. correctly.
  214. STATUS_DEVICE_IO_ERROR if a device error occurred.
  215. STATUS_TIMEOUT if the caller wanted to wait for the transfer but it
  216. never completed.
  217. --*/
  218. typedef
  219. KSTATUS
  220. (*PDEBUG_USB_HOST_CHECK_TRANSFER) (
  221. PVOID Context,
  222. PDEBUG_USB_TRANSFER Transfer
  223. );
  224. /*++
  225. Routine Description:
  226. This routine checks on the completion status of a transfer.
  227. Arguments:
  228. Context - Supplies a pointer to the device context.
  229. Transfer - Supplies a pointer to the transfer to check.
  230. Return Value:
  231. STATUS_SUCCESS if the hub status was successfully queried.
  232. STATUS_INVALID_PARAMETER if the given transfer was not initialized
  233. correctly.
  234. STATUS_DEVICE_IO_ERROR if a device error occurred.
  235. STATUS_MORE_PROCESSING_REQUIRED if the transfer is still in progress.
  236. --*/
  237. typedef
  238. KSTATUS
  239. (*PDEBUG_USB_HOST_RETIRE_TRANSFER) (
  240. PVOID Context,
  241. PDEBUG_USB_TRANSFER Transfer
  242. );
  243. /*++
  244. Routine Description:
  245. This routine retires an EHCI. This frees the buffer allocated during setup.
  246. Arguments:
  247. Context - Supplies a pointer to the device context.
  248. Transfer - Supplies a pointer to the transfer to retire.
  249. Return Value:
  250. STATUS_SUCCESS if the hub status was successfully queried.
  251. STATUS_INVALID_PARAMETER if the given transfer was not initialized
  252. correctly.
  253. STATUS_DEVICE_IO_ERROR if a device error occurred.
  254. --*/
  255. typedef
  256. KSTATUS
  257. (*PDEBUG_USB_HOST_STALL) (
  258. PVOID Context,
  259. ULONG Milliseconds
  260. );
  261. /*++
  262. Routine Description:
  263. This routine burns time using the frame index register to mark time.
  264. Arguments:
  265. Context - Supplies a pointer to the device context.
  266. Milliseconds - Supplies the number of milliseconds to stall for.
  267. Return Value:
  268. STATUS_SUCCESS if the hub status was successfully queried.
  269. STATUS_DEVICE_IO_ERROR if a device error occurred.
  270. --*/
  271. typedef
  272. KSTATUS
  273. (*PDEBUG_USB_HOST_GET_HANDOFF_DATA) (
  274. PVOID Context,
  275. PDEBUG_USB_HANDOFF_DATA HandoffData
  276. );
  277. /*++
  278. Routine Description:
  279. This routine returns the controller specific handoff data in preparation
  280. for the real USB driver taking over primary functionality.
  281. Arguments:
  282. Context - Supplies a pointer to the device context.
  283. HandoffData - Supplies a pointer to the handoff data. The controller should
  284. fill in the host controller specific data and size fields.
  285. Return Value:
  286. Status code.
  287. --*/
  288. /*++
  289. Structure Description:
  290. This structure contains the function table for a debug USB host device.
  291. Members:
  292. Initialize - Stores a pointer to a function used to initialize the USB
  293. host controller.
  294. GetRootHubStatus - Stores a pointer to a function used to get the status
  295. of a port on the root hub of the USB host controller.
  296. SetRootHubStatus - Stores a pointer to a function used to set the status
  297. of a port on the root hub of the USB host controller.
  298. SetupTransfer - Stores a pointer to a function used to allocate and
  299. initialize a transfer that will be submitted to the USB host controller.
  300. SubmitTransfer - Stores a pointer to a function use to submit a transfer
  301. to the USB host controller.
  302. CheckTransfer - Stores a pointer to a function used to check the completion
  303. status of a submitted transfer.
  304. RetireTransfer - Stores a pointer to a function used to deschedule and
  305. deallocate a previously set up usb transfer.
  306. Stall - Stores a pointer to a function that provides time-based busy
  307. spinning using the USB host controller's frame counter.
  308. GetHandoffData - Stores a pointer to a function used to get the handoff
  309. data in preparation for the official USB host controller driver taking
  310. over.
  311. --*/
  312. typedef struct _DEBUG_USB_HOST_FUNCTION_TABLE {
  313. PDEBUG_USB_HOST_INITIALIZE Initialize;
  314. PDEBUG_USB_HOST_GET_ROOT_HUB_STATUS GetRootHubStatus;
  315. PDEBUG_USB_HOST_SET_ROOT_HUB_STATUS SetRootHubStatus;
  316. PDEBUG_USB_HOST_SETUP_TRANSFER SetupTransfer;
  317. PDEBUG_USB_HOST_SUBMIT_TRANSFER SubmitTransfer;
  318. PDEBUG_USB_HOST_CHECK_TRANSFER CheckTransfer;
  319. PDEBUG_USB_HOST_RETIRE_TRANSFER RetireTransfer;
  320. PDEBUG_USB_HOST_STALL Stall;
  321. PDEBUG_USB_HOST_GET_HANDOFF_DATA GetHandoffData;
  322. } DEBUG_USB_HOST_FUNCTION_TABLE, *PDEBUG_USB_HOST_FUNCTION_TABLE;
  323. /*++
  324. Structure Description:
  325. This structure is used to describe a USB host controller implementation
  326. that can be used for kernel debugging.
  327. Members:
  328. TableVersion - Stores the version of the USB host controller description
  329. table as understood by the hardware module. Set this to
  330. DEBUG_USB_HOST_DESCRIPTION_VERSION.
  331. FunctionTable - Stores the table of pointers to the hardware module's
  332. functions.
  333. Context - Stores a pointer's worth of data specific to this instance. This
  334. pointer will be passed back to the hardware module on each call.
  335. Identifier - Stores the unique identifier of the controller.
  336. PortSubType - Stores the host controller sub-type, as defined by the Debug
  337. Port Table 2 specification.
  338. --*/
  339. typedef struct _DEBUG_USB_HOST_DESCRIPTION {
  340. ULONG TableVersion;
  341. DEBUG_USB_HOST_FUNCTION_TABLE FunctionTable;
  342. PVOID Context;
  343. ULONGLONG Identifier;
  344. USHORT PortSubType;
  345. } DEBUG_USB_HOST_DESCRIPTION, *PDEBUG_USB_HOST_DESCRIPTION;
  346. /*++
  347. Structure Description:
  348. This structure stores the information about a USB debug device.
  349. Members:
  350. Host - Stores a pointer to the host controller.
  351. --*/
  352. typedef struct _HARDWARE_USB_DEBUG_DEVICE {
  353. PDEBUG_USB_HOST_DESCRIPTION Host;
  354. } HARDWARE_USB_DEBUG_DEVICE, *PHARDWARE_USB_DEBUG_DEVICE;
  355. //
  356. // -------------------------------------------------------------------- Globals
  357. //
  358. //
  359. // -------------------------------------------------------- Function Prototypes
  360. //
  361. KSTATUS
  362. KdUsbInitialize (
  363. PDEBUG_USB_HOST_DESCRIPTION Host,
  364. BOOL TestInterface
  365. );
  366. /*++
  367. Routine Description:
  368. This routine initializes a USB debug based transport.
  369. Arguments:
  370. Host - Supplies a pointer to the host controller.
  371. TestInterface - Supplies a boolean indicating if the interface test should
  372. be run. This is only true under debugging scenarios where the USB
  373. debug transport itself is being debugged.
  374. Return Value:
  375. Status code.
  376. --*/
  377. //
  378. // Host controller module initialization functions.
  379. //
  380. VOID
  381. KdEhciModuleEntry (
  382. VOID
  383. );
  384. /*++
  385. Routine Description:
  386. This routine is the entry point for a hardware module. Its role is to
  387. detect the prescense of any of the hardware modules it contains
  388. implementations for and instantiate them with the kernel.
  389. Arguments:
  390. None.
  391. Return Value:
  392. None.
  393. --*/