usbcore.h 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. usbcore.h
  5. Abstract:
  6. This header contains internal definitions for the core USB library.
  7. Author:
  8. Evan Green 15-Jan-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // Redefine the API define into an export.
  15. //
  16. #define USB_API __DLLEXPORT
  17. #include <minoca/usb/usbhost.h>
  18. #include <minoca/kernel/kdebug.h>
  19. #include <minoca/kernel/kdusb.h>
  20. //
  21. // ---------------------------------------------------------------- Definitions
  22. //
  23. //
  24. // Define the allocation tag used across the USB core library.
  25. //
  26. #define USB_CORE_ALLOCATION_TAG 0x43627355 // 'CbsU'
  27. //
  28. // Define the magic number used to catch people who attempt to allocate USB
  29. // transfers themselves.
  30. //
  31. #define USB_TRANSFER_INTERNAL_MAGIC 0xBEEF57A8
  32. //
  33. // Define the number of entries in the first level table of USB children by
  34. // address.
  35. //
  36. #define USB_HOST_ADDRESS_SEGMENT_COUNT 8
  37. //
  38. // Define the number of addresses per segment.
  39. //
  40. #define USB_HOST_ADDRESSES_PER_SEGMENT 16
  41. //
  42. // Define private transfer flags.
  43. //
  44. //
  45. // This flag is set if the tranfser was submitted synchronously.
  46. //
  47. #define USB_TRANSFER_PRIVATE_SYNCHRONOUS 0x00000001
  48. //
  49. // Define USB debug flags.
  50. //
  51. #define USB_DEBUG_TRANSFERS 0x00000001
  52. #define USB_DEBUG_TRANSFER_COMPLETION 0x00000002
  53. #define USB_DEBUG_HUB 0x00000004
  54. #define USB_DEBUG_ENUMERATION 0x00000008
  55. #define USB_DEBUG_DEBUGGER_HANDOFF 0x00000010
  56. #define USB_DEBUG_ERRORS 0x00000020
  57. //
  58. // Define USB core specific errors that are reported to the system.
  59. //
  60. #define USB_CORE_ERROR_ENDPOINT_HALTED 0x00000001
  61. //
  62. // ------------------------------------------------------ Data Type Definitions
  63. //
  64. /*++
  65. Structure Description:
  66. This structure stores information about a transfer completion queue.
  67. Members:
  68. WorkQueue - Stores a pointer to the work queue on which the work item runs.
  69. WorkItem - Stores a pointer to the work item that does the work of
  70. completing the transfers.
  71. CompletedTransfersList - Stores the head of the list of completed transfers
  72. whose callback routines need to be invoked.
  73. CompletedTransfersListLock - Stores a spin lock that protects the completed
  74. transfers list.
  75. --*/
  76. typedef struct _USB_TRANSFER_COMPLETION_QUEUE {
  77. PWORK_QUEUE WorkQueue;
  78. PWORK_ITEM WorkItem;
  79. LIST_ENTRY CompletedTransfersList;
  80. KSPIN_LOCK CompletedTransfersListLock;
  81. } USB_TRANSFER_COMPLETION_QUEUE, *PUSB_TRANSFER_COMPLETION_QUEUE;
  82. /*++
  83. Structure Description:
  84. This structure stores information about a host controller instance, internal
  85. to the USB core library.
  86. Members:
  87. ListEntry - Stores pointers to the next and previous host controllers in the
  88. master list.
  89. Device - Stores the interface back to the host controller.
  90. RootDevice - Stores a pointer to the root hub's USB device.
  91. RootHub - Stores a pointer to the root hub.
  92. ChildrenByAddress - Stores an array of arrays that index the allocated
  93. devices by device address. They're segmented so as to avoid allocating
  94. 128 * sizeof(PVOID) bytes for every host controller.
  95. Lock - Stores a pointer to the lock that synchronizes some accesses to this
  96. controller, including control transfers sent to address zero.
  97. AddressLock - Stores a pointer to the lock that synchronizes address
  98. assignment for this controller.
  99. ControllerFull - Stores a boolean indicating that every address in the
  100. controller is currently allocated.
  101. TransferWorkItem - Stores a pointer to the work item used to process
  102. finished transfers.
  103. CompletedTransfersList - Stores a pointer to the list of transfers that are
  104. complete and awaiting processing.
  105. TransferWorkItemQueued - Stores a boolean indicating if the transfer work
  106. item has already been queued.
  107. CompletedTransfersListLock - Stores a lock protecting the completed
  108. transfers list and the work item queued flag.
  109. PortStatusWorkItem - Stores a pointer to the work item used to process port
  110. status changes.
  111. PortStatusWorkItemQueued - Stores a boolean indicating if the port status
  112. work item is queued.
  113. HandoffData - Stores a pointer to the KD debug handoff data for this
  114. controller.
  115. --*/
  116. typedef struct _USB_HOST_CONTROLLER {
  117. LIST_ENTRY ListEntry;
  118. USB_HOST_CONTROLLER_INTERFACE Device;
  119. PUSB_DEVICE RootDevice;
  120. PUSB_HUB RootHub;
  121. PUSB_DEVICE *ChildrenByAddress[USB_HOST_ADDRESS_SEGMENT_COUNT];
  122. PQUEUED_LOCK Lock;
  123. PQUEUED_LOCK AddressLock;
  124. BOOL ControllerFull;
  125. USB_TRANSFER_COMPLETION_QUEUE TransferCompletionQueue;
  126. PWORK_ITEM PortStatusWorkItem;
  127. volatile ULONG PortStatusWorkItemQueued;
  128. PDEBUG_HANDOFF_DATA HandoffData;
  129. } USB_HOST_CONTROLLER, *PUSB_HOST_CONTROLLER;
  130. /*++
  131. Structure Description:
  132. This structure stores information about a USB device configuration.
  133. Members:
  134. Description - Stores the public description.
  135. ListEntry - Stores pointers to the next and previous cached configurations
  136. for the owning device.
  137. --*/
  138. typedef struct _USB_CONFIGURATION {
  139. USB_CONFIGURATION_DESCRIPTION Description;
  140. LIST_ENTRY ListEntry;
  141. } USB_CONFIGURATION, *PUSB_CONFIGURATION;
  142. /*++
  143. Structure Description:
  144. This structure stores information about an active USB endpoint.
  145. Members:
  146. ListEntry - Stores pointers to the next and previous endpoints in the
  147. interface.
  148. ReferenceCount - Stores the reference count on the endpoint.
  149. HostControllerContext - Stores a pointer to the opaque host controller
  150. data associated with this endpoint.
  151. Type - Stores the USB endpoint flavor.
  152. Direction - Stores the direction of the endpoint. Not all combinations of
  153. endpoint type and direction are valid.
  154. Number - Stores the endpoint number.
  155. MaxPacketSize - Stores the maximum packet size of the endpoint.
  156. PollRate - Stores the polling rate for interrupt and isochronous endpoints,
  157. in (micro)frames. It stores the NAK rate for high-speed control and
  158. bulk out endpoints.
  159. --*/
  160. typedef struct _USB_ENDPOINT {
  161. LIST_ENTRY ListEntry;
  162. volatile ULONG ReferenceCount;
  163. PVOID HostControllerContext;
  164. USB_TRANSFER_TYPE Type;
  165. USB_TRANSFER_DIRECTION Direction;
  166. UCHAR Number;
  167. ULONG MaxPacketSize;
  168. USHORT PollRate;
  169. } USB_ENDPOINT, *PUSB_ENDPOINT;
  170. /*++
  171. Enumeration Description:
  172. This enumeration describes the different types of USB devices.
  173. Values:
  174. UsbDeviceTypeNonHub - Indicates a USB device that is not a hub.
  175. UsbDeviceTypeHub - Indicates a USB device that is a hub, but not the root.
  176. UsbDeviceTypeRootHub - Indicates a USB device that is the root hub.
  177. --*/
  178. typedef enum _USB_DEVICE_TYPE {
  179. UsbDeviceTypeNonHub,
  180. UsbDeviceTypeHub,
  181. UsbDeviceTypeRootHub,
  182. } USB_DEVICE_TYPE, *PUSB_DEVICE_TYPE;
  183. /*++
  184. Structure Description:
  185. This structure stores information about an active USB device.
  186. Members:
  187. ListEntry - Stores pointers to the next and previous devices enumerated by
  188. the parent hub.
  189. GlobalListEntry - Stores pointers to the next and previous USB devices in
  190. the entire system.
  191. ReferenceCount - Stores the number of references currently held against
  192. the device.
  193. Type - Stores the device type.
  194. Controller - Stores a pointer to the host controller that owns this device.
  195. Parent - Stores a pointer to the parent device. Root hubs have no parent.
  196. Speed - Stores the device speed.
  197. Device - Stores a pointer to the OS device associated with this USB device.
  198. Driver - Stores a pointer to the OS driver associated with this USB device.
  199. BusAddress - Stores the device address on the USB.
  200. EndpointZero - Stores a pointer to the default control pipe endpoint.
  201. ConfigurationLock - Stores a pointer to a queued lock that guards access to
  202. the configuration settings.
  203. ConfigurationCount - Stores the number of configurations in the device.
  204. ConfigurationList - Stores the head of the list of cached configurations.
  205. ActiveConfiguration - Stores a pointer to the currently active configuration
  206. of the device.
  207. ChildLock - Stores a pointer to a queued lock that guards access to the
  208. child list and the port status of the children.
  209. ChildList - Stores the head of the list of children for a hub device.
  210. ChildPortCount - Stores the number of downstream ports the hub has. For
  211. non-hub devices, this value will be zero.
  212. PortNumber - Stores which port of the parent hub this device lives in.
  213. Depth - Stores the hub depth of the device. Zero is a root hub, one is a
  214. device attached to the root hub, etc.
  215. Manufacturer - Stores a pointer to the manufacturer string.
  216. ProductName - Stores a pointer to the product name string.
  217. SerialNumber - Stores a pointer to the serial number string.
  218. VendorId - Stores the Vendor ID (VID) of the device.
  219. ProductId - Stores the Product ID (PID) of the device.
  220. ClassCode - Stores the device class code.
  221. SubclassCode - Stores the device subclass.
  222. ProtocolCode - Stores the device protocol code (remember the class,
  223. subclass, and protocol form a tuple).
  224. Lock - Stores a pointer to a queued lock that guards access to the device's
  225. status, including its connected state and transfer list.
  226. Connected - Stores a boolean indicating if the device is connected to the
  227. system (TRUE), or is removed and waiting for remaining handles to be
  228. closed (FALSE).
  229. DebugDevice - Stores a boolean indicating that this is the debug device.
  230. TransferList - Stores the head of the list of transfers for the device.
  231. --*/
  232. struct _USB_DEVICE {
  233. LIST_ENTRY ListEntry;
  234. LIST_ENTRY GlobalListEntry;
  235. volatile ULONG ReferenceCount;
  236. USB_DEVICE_TYPE Type;
  237. PUSB_HOST_CONTROLLER Controller;
  238. PUSB_DEVICE Parent;
  239. USB_DEVICE_SPEED Speed;
  240. PDEVICE Device;
  241. PDRIVER Driver;
  242. UCHAR BusAddress;
  243. PUSB_ENDPOINT EndpointZero;
  244. PQUEUED_LOCK ConfigurationLock;
  245. UCHAR ConfigurationCount;
  246. LIST_ENTRY ConfigurationList;
  247. PUSB_CONFIGURATION ActiveConfiguration;
  248. PQUEUED_LOCK ChildLock;
  249. LIST_ENTRY ChildList;
  250. ULONG ChildPortCount;
  251. UCHAR PortNumber;
  252. UCHAR Depth;
  253. PSTR Manufacturer;
  254. PSTR ProductName;
  255. PSTR SerialNumber;
  256. USHORT VendorId;
  257. USHORT ProductId;
  258. UCHAR ClassCode;
  259. UCHAR SubclassCode;
  260. UCHAR ProtocolCode;
  261. PQUEUED_LOCK Lock;
  262. BOOL Connected;
  263. BOOL DebugDevice;
  264. LIST_ENTRY TransferList;
  265. };
  266. /*++
  267. Structure Description:
  268. This structure stores information about an active USB interface.
  269. Members:
  270. Description - Stores the public description of the interface.
  271. EndpointList - Stores the head of the list of USB endpoints (the internal
  272. structures).
  273. Device - Stores a pointer to the OS device associated with this interface.
  274. Driver - Stores a pointer to the OS driver associated with this interface.
  275. --*/
  276. typedef struct _USB_INTERFACE {
  277. USB_INTERFACE_DESCRIPTION Description;
  278. LIST_ENTRY EndpointList;
  279. PDEVICE Device;
  280. PDRIVER Driver;
  281. } USB_INTERFACE, *PUSB_INTERFACE;
  282. /*++
  283. Enumeration Description:
  284. This enumeration describes the various states of a USB transfer.
  285. Values:
  286. TransferInvalid - Indicates that the transfer is not yet fully initialized.
  287. TransferInactive - Indicates that the transfer is not actively being
  288. processed by USB core.
  289. TransferActive - Indicates that the transfer is actively being processed by
  290. USB core.
  291. TransferInCallback - Indicates that the transfer is in the middle of the
  292. driver's callback routine.
  293. --*/
  294. typedef enum _USB_TRANSFER_STATE {
  295. TransferInvalid,
  296. TransferInactive,
  297. TransferActive,
  298. TransferInCallback
  299. } USB_TRANSFER_STATE, *PUSB_TRANSFER_STATE;
  300. /*++
  301. Structure Description:
  302. This structure stores information about an active USB transfer.
  303. Members:
  304. Protected - Stores the public and semi-public portions of the transfer.
  305. Magic - Stores a magic number, used to ensure that some cowboy didn't try
  306. to allocate the public version of the structure on his own. Set to
  307. USB_TRANSFER_INTERNAL_MAGIC.
  308. ReferenceCount - Stores a reference count for the transfer.
  309. CompletionListEntry - Stores pointers to the next and previous transfers in
  310. the list of unprocessed but completed transfers.
  311. DeviceListEntry - Stores pointers to the next and previous transfers in
  312. the list of transfers that belong to the transfer's device.
  313. Device - Stores a copy of the pointer to the device the transfer was
  314. allocated for, used to ensure that people trying to be clever don't
  315. change this pointer to a different device.
  316. Endpoint - Stores a pointer to the endpoint this transfer is aimed at. This
  317. value is calculated when the transfer is submitted.
  318. LastEndpointNumber - Stores the endpoint number of the transfer last time
  319. it was submitted. This is used to avoid traversing the linked lists
  320. again if the endpoint number hasn't changed.
  321. MaxTransferSize - Stores the maximum length that can be supported with
  322. this transfer.
  323. HostControllerContext - Stores an pointer to the host controller context for
  324. the transfer.
  325. PrivateFlags - Stores a bitfield of internal flags. See
  326. USB_TRANSFER_PRIVATE_* definitions.
  327. Event - Supplies a pointer to the event used for synchronous transfers.
  328. State - Stores the current state of the transfer. This is of type
  329. USB_TRANSFER_STATE.
  330. --*/
  331. typedef struct _USB_TRANSFER_PRIVATE {
  332. USB_TRANSFER_INTERNAL Protected;
  333. ULONG Magic;
  334. volatile ULONG ReferenceCount;
  335. LIST_ENTRY CompletionListEntry;
  336. LIST_ENTRY DeviceListEntry;
  337. PUSB_DEVICE Device;
  338. PUSB_ENDPOINT Endpoint;
  339. UCHAR LastEndpointNumber;
  340. ULONG MaxTransferSize;
  341. PVOID HostControllerContext;
  342. ULONG PrivateFlags;
  343. PKEVENT Event;
  344. volatile ULONG State;
  345. } USB_TRANSFER_PRIVATE, *PUSB_TRANSFER_PRIVATE;
  346. //
  347. // -------------------------------------------------------------------- Globals
  348. //
  349. extern PDRIVER UsbCoreDriver;
  350. //
  351. // Store a list of all active host controllers and a lock that protects this
  352. // list.
  353. //
  354. extern LIST_ENTRY UsbHostControllerList;
  355. extern PQUEUED_LOCK UsbHostControllerListLock;
  356. //
  357. // Store a pointer to the USB core work queue.
  358. //
  359. extern PWORK_QUEUE UsbCoreWorkQueue;
  360. //
  361. // Store a list of all active USB devices in the system.
  362. //
  363. extern LIST_ENTRY UsbDeviceList;
  364. extern PQUEUED_LOCK UsbDeviceListLock;
  365. //
  366. // Store a bitfield of enabled USB debug flags. See USB_DEBUG_* definitions.
  367. //
  368. extern ULONG UsbDebugFlags;
  369. //
  370. // Set this to enable debugging only a single device address. If this is zero,
  371. // it's enabled on all addresses.
  372. //
  373. extern UCHAR UsbDebugDeviceAddress;
  374. //
  375. // Store a pointer to the USB debugger handoff data.
  376. //
  377. extern PDEBUG_HANDOFF_DATA UsbDebugHandoffData;
  378. //
  379. // Define transfer direction and endpoint type strings.
  380. //
  381. extern PSTR UsbTransferDirectionStrings[UsbTransferDirectionCount];
  382. extern PSTR UsbTransferTypeStrings[UsbTransferTypeCount];
  383. extern PSTR UsbErrorStrings[UsbErrorCount];
  384. //
  385. // -------------------------------------------------------- Function Prototypes
  386. //
  387. //
  388. // Core routines
  389. //
  390. PUSB_TRANSFER
  391. UsbpAllocateTransfer (
  392. PUSB_DEVICE Device,
  393. UCHAR EndpointNumber,
  394. ULONG MaxTransferSize,
  395. ULONG Flags
  396. );
  397. /*++
  398. Routine Description:
  399. This routine allocates a new USB transfer structure. This routine must be
  400. used to allocate transfers.
  401. Arguments:
  402. Device - Supplies a pointer to the device the transfer will eventually be
  403. submitted to. This must not be changed by the caller in the transfer
  404. structure once set.
  405. EndpointNumber - Supplies the endpoint number that the transfer will go to.
  406. MaxTransferSize - Supplies the maximum length, in bytes, of the transfer.
  407. Attempts to submit a transfer with lengths longer than this initialized
  408. length will fail. Longer transfer sizes do require more resources as
  409. they are split into subpackets, so try to be reasonable.
  410. Flags - Supplies a bitfield of flags regarding the transaction. See
  411. USB_TRANSFER_FLAG_* definitions.
  412. Return Value:
  413. Returns a pointer to the new USB transfer on success.
  414. NULL when there are insufficient resources to complete the request.
  415. --*/
  416. VOID
  417. UsbpCancelAllTransfers (
  418. PUSB_DEVICE Device
  419. );
  420. /*++
  421. Routine Description:
  422. This routine cancels all transfers for the given USB core device. The
  423. device must be disconnected before calling into this routine.
  424. Arguments:
  425. Device - Supplies the core handle to the device whose transfers are
  426. to be cancelled.
  427. Return Value:
  428. None.
  429. --*/
  430. KSTATUS
  431. UsbpReadConfigurationDescriptors (
  432. PUSB_DEVICE Device,
  433. PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
  434. );
  435. /*++
  436. Routine Description:
  437. This routine attempts to read all configuration descriptors from the device.
  438. Arguments:
  439. Device - Supplies a pointer to the device to query.
  440. DeviceDescriptor - Supplies a pointer to the device descriptor.
  441. Return Value:
  442. Status code.
  443. --*/
  444. KSTATUS
  445. UsbpInitializeTransferCompletionQueue (
  446. PUSB_TRANSFER_COMPLETION_QUEUE CompletionQueue,
  447. BOOL PrivateWorkQueue
  448. );
  449. /*++
  450. Routine Description:
  451. This routine initializes the given transfer completion queue.
  452. Arguments:
  453. CompletionQueue - Supplies a pointer to a USB transfer completion queue
  454. that is to be initialized.
  455. PrivateWorkQueue - Supplies a boolean indicating whether or not the
  456. completion queue requires a private work queue for queuing its work
  457. item.
  458. Return Value:
  459. Status code.
  460. --*/
  461. VOID
  462. UsbpDestroyTransferCompletionQueue (
  463. PUSB_TRANSFER_COMPLETION_QUEUE CompletionQueue
  464. );
  465. /*++
  466. Routine Description:
  467. This routine destroys the given transfer completion queue. It does not
  468. release the completion queue's memory.
  469. Arguments:
  470. CompletionQueue - Supplies a pointer to a USB transfer completion queue
  471. that is to be destroyed.
  472. Return Value:
  473. Status code.
  474. --*/
  475. VOID
  476. UsbpProcessCompletedTransfer (
  477. PUSB_TRANSFER_INTERNAL Transfer
  478. );
  479. /*++
  480. Routine Description:
  481. This routine processes the completed transfer. It will either signal
  482. synchronous transfers or queue asynchronous transfers on the correct
  483. transfer completion queue so that its callback routine can be completed at
  484. low level. This routine is called at dispatch.
  485. Arguments:
  486. Transfer - Supplies a pointer to a completed transfer.
  487. Return Value:
  488. None.
  489. --*/
  490. //
  491. // Host routines
  492. //
  493. KSTATUS
  494. UsbpCreateEndpoint (
  495. PUSB_DEVICE Device,
  496. UCHAR Number,
  497. USB_TRANSFER_DIRECTION Direction,
  498. USB_TRANSFER_TYPE Type,
  499. ULONG MaxPacketSize,
  500. ULONG PollRate,
  501. PUSB_ENDPOINT *CreatedEndpoint
  502. );
  503. /*++
  504. Routine Description:
  505. This routine creates the accounting structures associated with a new USB
  506. endpoint.
  507. Arguments:
  508. Device - Supplies a pointer to the device that will own the endpoint.
  509. Number - Supplies the endpoint number of the new endpoint.
  510. Direction - Supplies the direction of the endpoint.
  511. Type - Supplies the type of the endpoint.
  512. MaxPacketSize - Supplies the maximum packet size for the endpoint, in bytes.
  513. PollRate - Supplies the polling rate of the endpoint.
  514. CreatedEndpoint - Supplies a pointer where the newly minted endpoint will
  515. be returned.
  516. Return Value:
  517. Status code.
  518. --*/
  519. VOID
  520. UsbpResetEndpoint (
  521. PUSB_DEVICE Device,
  522. PUSB_ENDPOINT Endpoint
  523. );
  524. /*++
  525. Routine Description:
  526. This routine resets a USB endpoint.
  527. Arguments:
  528. Device - Supplies a pointer to the device to which the endpoint belongs.
  529. Endpoint - Supplies a pointer to the USB endpoint.
  530. Return Value:
  531. None.
  532. --*/
  533. KSTATUS
  534. UsbpFlushEndpoint (
  535. PUSB_DEVICE Device,
  536. PUSB_ENDPOINT Endpoint,
  537. PULONG TransferCount
  538. );
  539. /*++
  540. Routine Description:
  541. This routine flushes the given endpoint for the given USB device. This
  542. includes busily waiting for all active transfers to complete. This is only
  543. meant to be used at high run level when preparing to write a crash dump
  544. file using USB Mass Storage.
  545. Arguments:
  546. Device - Supplies a pointer to the device to which the endpoint belongs.
  547. Endpoint - Supplies a pointer to the USB endpoint.
  548. TransferCount - Supplies a pointer that receives the total number of
  549. transfers that were flushed.
  550. Return Value:
  551. Status code.
  552. --*/
  553. VOID
  554. UsbpEndpointAddReference (
  555. PUSB_ENDPOINT Endpoint
  556. );
  557. /*++
  558. Routine Description:
  559. This routine increments the reference count on the given endpoint.
  560. Arguments:
  561. Endpoint - Supplies a pointer to the endpoint whose reference count should
  562. be incremented.
  563. Return Value:
  564. None.
  565. --*/
  566. VOID
  567. UsbpEndpointReleaseReference (
  568. PUSB_DEVICE Device,
  569. PUSB_ENDPOINT Endpoint
  570. );
  571. /*++
  572. Routine Description:
  573. This routine decrements the reference count on the given endpoint, and
  574. destroys it if it hits zero.
  575. Arguments:
  576. Device - Supplies a pointer to the device that owns the endpoint.
  577. Endpoint - Supplies a pointer to the endpoint whose reference count should
  578. be decremented.
  579. Return Value:
  580. None.
  581. --*/
  582. //
  583. // Enumeration routines
  584. //
  585. VOID
  586. UsbpDeviceAddReference (
  587. PUSB_DEVICE Device
  588. );
  589. /*++
  590. Routine Description:
  591. This routine increments the reference count on the given device.
  592. Arguments:
  593. Device - Supplies a pointer to the device whose reference count should be
  594. incremented.
  595. Return Value:
  596. None.
  597. --*/
  598. VOID
  599. UsbpDeviceReleaseReference (
  600. PUSB_DEVICE Device
  601. );
  602. /*++
  603. Routine Description:
  604. This routine decrements the reference count on the given device, and
  605. destroys it if it hits zero.
  606. Arguments:
  607. Device - Supplies a pointer to the device whose reference count should be
  608. decremented.
  609. Return Value:
  610. None.
  611. --*/
  612. KSTATUS
  613. UsbpEnumerateDevice (
  614. PUSB_HUB ParentHub,
  615. PUSB_DEVICE ParentHubDevice,
  616. UCHAR PortNumber,
  617. USB_DEVICE_SPEED DeviceSpeed,
  618. PHANDLE DeviceHandle
  619. );
  620. /*++
  621. Routine Description:
  622. This routine creates a new USB device in the system. This routine must be
  623. called at low level, and must be called with the parent hub's child lock
  624. held.
  625. Arguments:
  626. ParentHub - Supplies a pointer to the parent hub object.
  627. ParentHubDevice - Supplies the handle of the parent USB hub device
  628. enumerating the new device.
  629. PortNumber - Supplies the parent hub's one-based port number where this
  630. device exists.
  631. DeviceSpeed - Supplies the speed of the device being enumerated.
  632. DeviceHandle - Supplies a pointer where a handle representing the device
  633. will be returned upon success.
  634. Return Value:
  635. Status code.
  636. --*/
  637. VOID
  638. UsbpRemoveDevice (
  639. PUSB_DEVICE Device
  640. );
  641. /*++
  642. Routine Description:
  643. This routine removes a device from its parent hub. The parent USB device's
  644. child lock should be held.
  645. Arguments:
  646. Device - Supplies a pointer to the device that is to be removed.
  647. Return Value:
  648. None.
  649. --*/
  650. KSTATUS
  651. UsbpReserveDeviceAddress (
  652. PUSB_HOST_CONTROLLER Controller,
  653. PUSB_DEVICE Device,
  654. UCHAR Address
  655. );
  656. /*++
  657. Routine Description:
  658. This routine assigns the given device to a specific address.
  659. Arguments:
  660. Controller - Supplies a pointer to the controller the device lives on.
  661. Device - Supplies a pointer to the USB device reserving the address. This
  662. can be NULL.
  663. Address - Supplies the address to reserve.
  664. Return Value:
  665. STATUS_SUCCESS on success.
  666. STATUS_INSUFFICIENT_RESOURCES if an allocation failed.
  667. STATUS_RESOURCE_IN_USE if the address is already assigned.
  668. --*/
  669. //
  670. // Hub routines
  671. //
  672. VOID
  673. UsbpNotifyRootHubStatusChange (
  674. PUSB_HUB RootHub
  675. );
  676. /*++
  677. Routine Description:
  678. This routine handles notifications from the host controller indicating that
  679. a port on the root hub has changed. It queries the port status for the hub
  680. and notifies the system if something is different.
  681. Arguments:
  682. RootHub - Supplies a pointer to the USB root hub.
  683. Return Value:
  684. None.
  685. --*/
  686. KSTATUS
  687. UsbpResetHubPort (
  688. PUSB_HUB Hub,
  689. UCHAR PortIndex
  690. );
  691. /*++
  692. Routine Description:
  693. This routine resets the device behind the given port. The controller lock
  694. must be held.
  695. Arguments:
  696. Hub - Supplies a pointer to the context of the hub whose port is to be
  697. reset.
  698. PortIndex - Supplies the zero-based port index on the hub to reset.
  699. Return Value:
  700. Status code.
  701. --*/