usbcore.h 25 KB

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