1 #ifndef USBMPORT_H__
2 #define USBMPORT_H__
3 
4 #define USBPORT_HCI_MN 0x10000001
5 
6 /* Tranfer types */
7 #define USBPORT_TRANSFER_TYPE_ISOCHRONOUS 0
8 #define USBPORT_TRANSFER_TYPE_CONTROL     1
9 #define USBPORT_TRANSFER_TYPE_BULK        2
10 #define USBPORT_TRANSFER_TYPE_INTERRUPT   3
11 
12 /* Endpoint states */
13 #define USBPORT_ENDPOINT_UNKNOWN 0
14 #define USBPORT_ENDPOINT_PAUSED 2
15 #define USBPORT_ENDPOINT_ACTIVE 3
16 #define USBPORT_ENDPOINT_REMOVE 4
17 #define USBPORT_ENDPOINT_CLOSED 5
18 
19 /* Endpoint status */
20 #define USBPORT_ENDPOINT_RUN     0
21 #define USBPORT_ENDPOINT_HALT    1
22 #define USBPORT_ENDPOINT_CONTROL 4
23 
24 /* Interrupt Endpoint Poll Interval */
25 #define ENDPOINT_INTERRUPT_1ms   1
26 #define ENDPOINT_INTERRUPT_2ms   2
27 #define ENDPOINT_INTERRUPT_4ms   4
28 #define ENDPOINT_INTERRUPT_8ms   8
29 #define ENDPOINT_INTERRUPT_16ms  16
30 #define ENDPOINT_INTERRUPT_32ms  32
31 
32 #define INTERRUPT_ENDPOINTs (ENDPOINT_INTERRUPT_32ms + \
33                              ENDPOINT_INTERRUPT_16ms + \
34                              ENDPOINT_INTERRUPT_8ms  + \
35                              ENDPOINT_INTERRUPT_4ms  + \
36                              ENDPOINT_INTERRUPT_2ms  + \
37                              ENDPOINT_INTERRUPT_1ms)
38 
39 /* Types of resources. For USBPORT_RESOURCES::ResourcesTypes */
40 #define USBPORT_RESOURCES_PORT      1
41 #define USBPORT_RESOURCES_INTERRUPT 2
42 #define USBPORT_RESOURCES_MEMORY    4
43 
44 typedef struct _USBPORT_RESOURCES {
45   ULONG ResourcesTypes;
46   USB_CONTROLLER_FLAVOR HcFlavor;
47   ULONG InterruptVector;
48   KIRQL InterruptLevel;
49   UCHAR Padded1[3];
50   KAFFINITY InterruptAffinity;
51   BOOLEAN ShareVector;
52   UCHAR Padded2[3];
53   KINTERRUPT_MODE InterruptMode;
54   ULONG_PTR Reserved;
55   PVOID ResourceBase;
56   ULONG IoSpaceLength;
57   ULONG_PTR StartVA;
58   ULONG StartPA;
59   UCHAR LegacySupport;
60   BOOLEAN IsChirpHandled;
61   UCHAR Reserved2;
62   UCHAR Reserved3;
63 } USBPORT_RESOURCES, *PUSBPORT_RESOURCES;
64 
65 C_ASSERT(sizeof(USBPORT_RESOURCES) == 32 + 5 * sizeof(PVOID));
66 
67 typedef struct _USBPORT_ENDPOINT_PROPERTIES {
68   USHORT DeviceAddress;
69   USHORT EndpointAddress;
70   USHORT TotalMaxPacketSize; // TransactionPerMicroframe * MaxPacketSize
71   UCHAR Period;
72   UCHAR Reserved1;
73   USB_DEVICE_SPEED DeviceSpeed;
74   ULONG UsbBandwidth;
75   ULONG ScheduleOffset;
76   ULONG TransferType;
77   ULONG Direction;
78   ULONG_PTR BufferVA;
79   ULONG BufferPA;
80   ULONG BufferLength;
81   ULONG Reserved3;
82   ULONG MaxTransferSize;
83   USHORT HubAddr;
84   USHORT PortNumber;
85   UCHAR InterruptScheduleMask;
86   UCHAR SplitCompletionMask;
87   UCHAR TransactionPerMicroframe; // 1 + additional transactions. Total: from 1 to 3)
88   UCHAR Reserved4;
89   ULONG MaxPacketSize;
90   ULONG Reserved6;
91 } USBPORT_ENDPOINT_PROPERTIES, *PUSBPORT_ENDPOINT_PROPERTIES;
92 
93 C_ASSERT(sizeof(USBPORT_ENDPOINT_PROPERTIES) == 56 + 2 * sizeof(PVOID));
94 
95 typedef struct _USBPORT_TRANSFER_PARAMETERS {
96   ULONG TransferFlags;
97   ULONG TransferBufferLength;
98   ULONG TransferCounter;
99   BOOL IsTransferSplited;
100   ULONG Reserved2;
101   USB_DEFAULT_PIPE_SETUP_PACKET SetupPacket;
102 } USBPORT_TRANSFER_PARAMETERS, *PUSBPORT_TRANSFER_PARAMETERS;
103 
104 C_ASSERT(sizeof(USBPORT_TRANSFER_PARAMETERS) == 28);
105 
106 typedef struct _USBPORT_SCATTER_GATHER_ELEMENT {
107   PHYSICAL_ADDRESS SgPhysicalAddress;
108   ULONG Reserved1;
109   ULONG SgTransferLength;
110   ULONG SgOffset;
111   ULONG Reserved2;
112 } USBPORT_SCATTER_GATHER_ELEMENT, *PUSBPORT_SCATTER_GATHER_ELEMENT;
113 
114 C_ASSERT(sizeof(USBPORT_SCATTER_GATHER_ELEMENT) == 24);
115 
116 typedef struct _USBPORT_SCATTER_GATHER_LIST {
117   ULONG Flags;
118   ULONG_PTR CurrentVa;
119   PVOID MappedSystemVa;
120   ULONG SgElementCount;
121   USBPORT_SCATTER_GATHER_ELEMENT SgElement[2];
122 } USBPORT_SCATTER_GATHER_LIST, *PUSBPORT_SCATTER_GATHER_LIST;
123 
124 C_ASSERT(sizeof(USBPORT_SCATTER_GATHER_LIST) == 48 + 4 * sizeof(PVOID));
125 
126 typedef struct _USBPORT_ENDPOINT_REQUIREMENTS {
127   ULONG HeaderBufferSize;
128   ULONG MaxTransferSize;
129 } USBPORT_ENDPOINT_REQUIREMENTS, *PUSBPORT_ENDPOINT_REQUIREMENTS;
130 
131 typedef ULONG MPSTATUS; // Miniport status
132 typedef ULONG RHSTATUS; // Roothub status
133 
134 #define MP_STATUS_SUCCESS       0
135 #define MP_STATUS_FAILURE       1
136 #define MP_STATUS_NO_RESOURCES  2
137 #define MP_STATUS_NO_BANDWIDTH  3
138 #define MP_STATUS_ERROR         4
139 #define MP_STATUS_RESERVED1     5
140 #define MP_STATUS_NOT_SUPPORTED 6
141 #define MP_STATUS_HW_ERROR      7
142 #define MP_STATUS_UNSUCCESSFUL  8
143 
144 #define RH_STATUS_SUCCESS       0
145 #define RH_STATUS_NO_CHANGES    1
146 #define RH_STATUS_UNSUCCESSFUL  2
147 
148 /* Additional USB Class Codes from USB.org */
149 #define USBC_DEVICE_CLASS_TYPE_C_BRIDGE         0x12
150 
151 /* Miniport functions */
152 typedef MPSTATUS
153 (NTAPI *PHCI_OPEN_ENDPOINT)(
154   PVOID,
155   PUSBPORT_ENDPOINT_PROPERTIES,
156   PVOID);
157 
158 typedef MPSTATUS
159 (NTAPI *PHCI_REOPEN_ENDPOINT)(
160   PVOID,
161   PUSBPORT_ENDPOINT_PROPERTIES,
162   PVOID);
163 
164 typedef VOID
165 (NTAPI *PHCI_QUERY_ENDPOINT_REQUIREMENTS)(
166   PVOID,
167   PUSBPORT_ENDPOINT_PROPERTIES,
168   PUSBPORT_ENDPOINT_REQUIREMENTS);
169 
170 typedef VOID
171 (NTAPI *PHCI_CLOSE_ENDPOINT)(
172   PVOID,
173   PVOID,
174   BOOLEAN);
175 
176 typedef MPSTATUS
177 (NTAPI *PHCI_START_CONTROLLER)(
178   PVOID,
179   PUSBPORT_RESOURCES);
180 
181 typedef VOID
182 (NTAPI *PHCI_STOP_CONTROLLER)(
183   PVOID,
184   BOOLEAN);
185 
186 typedef VOID
187 (NTAPI *PHCI_SUSPEND_CONTROLLER)(PVOID);
188 
189 typedef MPSTATUS
190 (NTAPI *PHCI_RESUME_CONTROLLER)(PVOID);
191 
192 typedef BOOLEAN
193 (NTAPI *PHCI_INTERRUPT_SERVICE)(PVOID);
194 
195 typedef VOID
196 (NTAPI *PHCI_INTERRUPT_DPC)(
197   PVOID,
198   BOOLEAN);
199 
200 typedef MPSTATUS
201 (NTAPI *PHCI_SUBMIT_TRANSFER)(
202   PVOID,
203   PVOID,
204   PUSBPORT_TRANSFER_PARAMETERS,
205   PVOID,
206   PUSBPORT_SCATTER_GATHER_LIST);
207 
208 typedef MPSTATUS
209 (NTAPI *PHCI_SUBMIT_ISO_TRANSFER)(
210   PVOID,
211   PVOID,
212   PUSBPORT_TRANSFER_PARAMETERS,
213   PVOID,
214   PVOID);
215 
216 typedef VOID
217 (NTAPI *PHCI_ABORT_TRANSFER)(
218   PVOID,
219   PVOID,
220   PVOID,
221   PULONG);
222 
223 typedef ULONG
224 (NTAPI *PHCI_GET_ENDPOINT_STATE)(
225   PVOID,
226   PVOID);
227 
228 typedef VOID
229 (NTAPI *PHCI_SET_ENDPOINT_STATE)(
230   PVOID,
231   PVOID,
232   ULONG);
233 
234 typedef VOID
235 (NTAPI *PHCI_POLL_ENDPOINT)(
236   PVOID,
237   PVOID);
238 
239 typedef VOID
240 (NTAPI *PHCI_CHECK_CONTROLLER)(PVOID);
241 
242 typedef ULONG
243 (NTAPI *PHCI_GET_32BIT_FRAME_NUMBER)(PVOID);
244 
245 typedef VOID
246 (NTAPI *PHCI_INTERRUPT_NEXT_SOF)(PVOID);
247 
248 typedef VOID
249 (NTAPI *PHCI_ENABLE_INTERRUPTS)(PVOID);
250 
251 typedef VOID
252 (NTAPI *PHCI_DISABLE_INTERRUPTS)(PVOID);
253 
254 typedef VOID
255 (NTAPI *PHCI_POLL_CONTROLLER)(PVOID);
256 
257 typedef VOID
258 (NTAPI *PHCI_SET_ENDPOINT_DATA_TOGGLE)(
259   PVOID,
260   PVOID,
261   ULONG);
262 
263 typedef ULONG
264 (NTAPI *PHCI_GET_ENDPOINT_STATUS)(
265   PVOID,
266   PVOID);
267 
268 typedef VOID
269 (NTAPI *PHCI_SET_ENDPOINT_STATUS)(
270   PVOID,
271   PVOID,
272   ULONG);
273 
274 typedef VOID
275 (NTAPI *PHCI_RESET_CONTROLLER)(PVOID);
276 
277 /* Roothub functions */
278 typedef VOID
279 (NTAPI *PHCI_RH_GET_ROOT_HUB_DATA)(
280   PVOID,
281   PVOID);
282 
283 typedef MPSTATUS
284 (NTAPI *PHCI_RH_GET_STATUS)(
285   PVOID,
286   PUSHORT);
287 
288 #define USB20_PORT_STATUS_RESERVED1_OWNED_BY_COMPANION (1 << 2)
289 
290 typedef MPSTATUS
291 (NTAPI *PHCI_RH_GET_PORT_STATUS)(
292   PVOID,
293   USHORT,
294   PUSB_PORT_STATUS_AND_CHANGE);
295 
296 typedef MPSTATUS
297 (NTAPI *PHCI_RH_GET_HUB_STATUS)(
298   PVOID,
299   PUSB_HUB_STATUS_AND_CHANGE);
300 
301 typedef MPSTATUS
302 (NTAPI *PHCI_RH_SET_FEATURE_PORT_RESET)(
303   PVOID,
304   USHORT);
305 
306 typedef MPSTATUS
307 (NTAPI *PHCI_RH_SET_FEATURE_PORT_POWER)(
308   PVOID,
309   USHORT);
310 
311 typedef MPSTATUS
312 (NTAPI *PHCI_RH_SET_FEATURE_PORT_ENABLE)(
313   PVOID,
314   USHORT);
315 
316 typedef MPSTATUS
317 (NTAPI *PHCI_RH_SET_FEATURE_PORT_SUSPEND)(
318   PVOID,
319   USHORT);
320 
321 typedef MPSTATUS
322 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_ENABLE)(
323   PVOID,
324   USHORT);
325 
326 typedef MPSTATUS
327 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_POWER)(
328   PVOID,
329   USHORT);
330 
331 typedef MPSTATUS
332 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_SUSPEND)(
333   PVOID,
334   USHORT);
335 
336 typedef MPSTATUS
337 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_ENABLE_CHANGE)(
338   PVOID,
339   USHORT);
340 
341 typedef MPSTATUS
342 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_CONNECT_CHANGE)(
343   PVOID,
344   USHORT);
345 
346 typedef MPSTATUS
347 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_RESET_CHANGE)(
348   PVOID,
349   USHORT);
350 
351 typedef MPSTATUS
352 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_SUSPEND_CHANGE)(
353   PVOID,
354   USHORT);
355 
356 typedef MPSTATUS
357 (NTAPI *PHCI_RH_CLEAR_FEATURE_PORT_OVERCURRENT_CHANGE)(
358   PVOID,
359   USHORT);
360 
361 typedef VOID
362 (NTAPI *PHCI_RH_DISABLE_IRQ)(PVOID);
363 
364 typedef VOID
365 (NTAPI *PHCI_RH_ENABLE_IRQ)(PVOID);
366 
367 /* Miniport ioctl functions */
368 typedef MPSTATUS
369 (NTAPI *PHCI_START_SEND_ONE_PACKET)(
370   PVOID,
371   PVOID,
372   PVOID,
373   PULONG,
374   PVOID,
375   PVOID,
376   ULONG,
377   USBD_STATUS *);
378 
379 typedef MPSTATUS
380 (NTAPI *PHCI_END_SEND_ONE_PACKET)(
381   PVOID,
382   PVOID,
383   PVOID,
384   PULONG,
385   PVOID,
386   PVOID,
387   ULONG,
388   USBD_STATUS *);
389 
390 typedef MPSTATUS
391 (NTAPI *PHCI_PASS_THRU)(
392   PVOID,
393   PVOID,
394   ULONG,
395   PVOID);
396 
397 /* Port functions */
398 typedef ULONG
399 (*PUSBPORT_DBG_PRINT)(
400   PVOID,
401   ULONG,
402   PCH,
403   ...);
404 
405 typedef ULONG
406 (NTAPI *PUSBPORT_TEST_DEBUG_BREAK)(PVOID);
407 
408 typedef ULONG
409 (NTAPI *PUSBPORT_ASSERT_FAILURE)(
410   PVOID,
411   PVOID,
412   PVOID,
413   ULONG,
414   PCHAR);
415 
416 typedef MPSTATUS
417 (NTAPI *PUSBPORT_GET_MINIPORT_REGISTRY_KEY_VALUE)(
418   PVOID,
419   BOOL,
420   PCWSTR,
421   SIZE_T,
422   PVOID,
423   SIZE_T);
424 
425 typedef ULONG
426 (NTAPI *PUSBPORT_INVALIDATE_ROOT_HUB)(PVOID);
427 
428 typedef ULONG
429 (NTAPI *PUSBPORT_INVALIDATE_ENDPOINT)(
430   PVOID,
431   PVOID);
432 
433 typedef VOID
434 (NTAPI *PUSBPORT_COMPLETE_TRANSFER)(
435   PVOID,
436   PVOID,
437   PVOID,
438   USBD_STATUS,
439   ULONG);
440 
441 typedef ULONG
442 (NTAPI *PUSBPORT_COMPLETE_ISO_TRANSFER)(
443   PVOID,
444   PVOID,
445   PVOID,
446   ULONG);
447 
448 typedef ULONG
449 (NTAPI *PUSBPORT_LOG_ENTRY)(
450   PVOID,
451   ULONG,
452   ULONG,
453   ULONG,
454   ULONG,
455   ULONG);
456 
457 typedef PVOID
458 (NTAPI *PUSBPORT_GET_MAPPED_VIRTUAL_ADDRESS)(
459   ULONG,
460   PVOID,
461   PVOID);
462 
463 typedef VOID
464 (NTAPI ASYNC_TIMER_CALLBACK)(
465   IN PVOID MiniportExtension,
466   IN PVOID CallBackContext);
467 
468 typedef ULONG
469 (NTAPI *PUSBPORT_REQUEST_ASYNC_CALLBACK)(
470   PVOID,
471   ULONG,
472   PVOID,
473   SIZE_T,
474   ASYNC_TIMER_CALLBACK *);
475 
476 typedef MPSTATUS
477 (NTAPI *PUSBPORT_READ_WRITE_CONFIG_SPACE)(
478   PVOID,
479   BOOLEAN,
480   PVOID,
481   ULONG,
482   ULONG);
483 
484 typedef NTSTATUS
485 (NTAPI *PUSBPORT_WAIT)(
486   PVOID,
487   ULONG);
488 
489 #define USBPORT_INVALIDATE_CONTROLLER_RESET            1
490 #define USBPORT_INVALIDATE_CONTROLLER_SURPRISE_REMOVE  2
491 #define USBPORT_INVALIDATE_CONTROLLER_SOFT_INTERRUPT   3
492 
493 typedef ULONG
494 (NTAPI *PUSBPORT_INVALIDATE_CONTROLLER)(
495   PVOID,
496   ULONG);
497 
498 typedef VOID
499 (NTAPI *PUSBPORT_BUG_CHECK)(PVOID);
500 
501 typedef ULONG
502 (NTAPI *PUSBPORT_NOTIFY_DOUBLE_BUFFER)(
503   PVOID,
504   PVOID,
505   PVOID,
506   SIZE_T);
507 
508 /* Miniport functions */
509 typedef VOID
510 (NTAPI *PHCI_REBALANCE_ENDPOINT)(
511   PVOID,
512   PUSBPORT_ENDPOINT_PROPERTIES,
513   PVOID);
514 
515 typedef VOID
516 (NTAPI *PHCI_FLUSH_INTERRUPTS)(PVOID);
517 
518 typedef MPSTATUS
519 (NTAPI *PHCI_RH_CHIRP_ROOT_PORT)(
520   PVOID,
521   USHORT);
522 
523 typedef VOID
524 (NTAPI *PHCI_TAKE_PORT_CONTROL)(PVOID);
525 
526 #define USB_MINIPORT_VERSION_OHCI 0x01
527 #define USB_MINIPORT_VERSION_UHCI 0x02
528 #define USB_MINIPORT_VERSION_EHCI 0x03
529 #define USB_MINIPORT_VERSION_XHCI 0x04
530 
531 #define USB_MINIPORT_FLAGS_INTERRUPT    0x0001
532 #define USB_MINIPORT_FLAGS_PORT_IO      0x0002
533 #define USB_MINIPORT_FLAGS_MEMORY_IO    0x0004
534 #define USB_MINIPORT_FLAGS_USB2         0x0010
535 #define USB_MINIPORT_FLAGS_DISABLE_SS   0x0020
536 #define USB_MINIPORT_FLAGS_NOT_LOCK_INT 0x0040
537 #define USB_MINIPORT_FLAGS_POLLING      0x0080
538 #define USB_MINIPORT_FLAGS_NO_DMA       0x0100
539 #define USB_MINIPORT_FLAGS_WAKE_SUPPORT 0x0200
540 
541 #define TOTAL_USB11_BUS_BANDWIDTH  12000
542 #define TOTAL_USB20_BUS_BANDWIDTH  400000
543 
544 typedef struct _USBPORT_REGISTRATION_PACKET {
545   ULONG MiniPortVersion;
546   ULONG MiniPortFlags;
547   ULONG MiniPortBusBandwidth;
548   ULONG Reserved1;
549   SIZE_T MiniPortExtensionSize;
550   SIZE_T MiniPortEndpointSize;
551   SIZE_T MiniPortTransferSize;
552   ULONG Reserved2;
553   ULONG Reserved3;
554   SIZE_T MiniPortResourcesSize;
555 
556   /* Miniport */
557   PHCI_OPEN_ENDPOINT OpenEndpoint;
558   PHCI_REOPEN_ENDPOINT ReopenEndpoint;
559   PHCI_QUERY_ENDPOINT_REQUIREMENTS QueryEndpointRequirements;
560   PHCI_CLOSE_ENDPOINT CloseEndpoint;
561   PHCI_START_CONTROLLER StartController;
562   PHCI_STOP_CONTROLLER StopController;
563   PHCI_SUSPEND_CONTROLLER SuspendController;
564   PHCI_RESUME_CONTROLLER ResumeController;
565   PHCI_INTERRUPT_SERVICE InterruptService;
566   PHCI_INTERRUPT_DPC InterruptDpc;
567   PHCI_SUBMIT_TRANSFER SubmitTransfer;
568   PHCI_SUBMIT_ISO_TRANSFER SubmitIsoTransfer;
569   PHCI_ABORT_TRANSFER AbortTransfer;
570   PHCI_GET_ENDPOINT_STATE GetEndpointState;
571   PHCI_SET_ENDPOINT_STATE SetEndpointState;
572   PHCI_POLL_ENDPOINT PollEndpoint;
573   PHCI_CHECK_CONTROLLER CheckController;
574   PHCI_GET_32BIT_FRAME_NUMBER Get32BitFrameNumber;
575   PHCI_INTERRUPT_NEXT_SOF InterruptNextSOF;
576   PHCI_ENABLE_INTERRUPTS EnableInterrupts;
577   PHCI_DISABLE_INTERRUPTS DisableInterrupts;
578   PHCI_POLL_CONTROLLER PollController;
579   PHCI_SET_ENDPOINT_DATA_TOGGLE SetEndpointDataToggle;
580   PHCI_GET_ENDPOINT_STATUS GetEndpointStatus;
581   PHCI_SET_ENDPOINT_STATUS SetEndpointStatus;
582   PHCI_RESET_CONTROLLER ResetController;
583 
584   /* Roothub */
585   PHCI_RH_GET_ROOT_HUB_DATA RH_GetRootHubData;
586   PHCI_RH_GET_STATUS RH_GetStatus;
587   PHCI_RH_GET_PORT_STATUS RH_GetPortStatus;
588   PHCI_RH_GET_HUB_STATUS RH_GetHubStatus;
589   PHCI_RH_SET_FEATURE_PORT_RESET RH_SetFeaturePortReset;
590   PHCI_RH_SET_FEATURE_PORT_POWER RH_SetFeaturePortPower;
591   PHCI_RH_SET_FEATURE_PORT_ENABLE RH_SetFeaturePortEnable;
592   PHCI_RH_SET_FEATURE_PORT_SUSPEND RH_SetFeaturePortSuspend;
593   PHCI_RH_CLEAR_FEATURE_PORT_ENABLE RH_ClearFeaturePortEnable;
594   PHCI_RH_CLEAR_FEATURE_PORT_POWER RH_ClearFeaturePortPower;
595   PHCI_RH_CLEAR_FEATURE_PORT_SUSPEND RH_ClearFeaturePortSuspend;
596   PHCI_RH_CLEAR_FEATURE_PORT_ENABLE_CHANGE RH_ClearFeaturePortEnableChange;
597   PHCI_RH_CLEAR_FEATURE_PORT_CONNECT_CHANGE RH_ClearFeaturePortConnectChange;
598   PHCI_RH_CLEAR_FEATURE_PORT_RESET_CHANGE RH_ClearFeaturePortResetChange;
599   PHCI_RH_CLEAR_FEATURE_PORT_SUSPEND_CHANGE RH_ClearFeaturePortSuspendChange;
600   PHCI_RH_CLEAR_FEATURE_PORT_OVERCURRENT_CHANGE RH_ClearFeaturePortOvercurrentChange;
601   PHCI_RH_DISABLE_IRQ RH_DisableIrq;
602   PHCI_RH_ENABLE_IRQ RH_EnableIrq;
603 
604   /* Miniport ioctl */
605   PHCI_START_SEND_ONE_PACKET StartSendOnePacket;
606   PHCI_END_SEND_ONE_PACKET EndSendOnePacket;
607   PHCI_PASS_THRU PassThru;
608 
609   /* Port */
610   PUSBPORT_DBG_PRINT UsbPortDbgPrint;
611   PUSBPORT_TEST_DEBUG_BREAK UsbPortTestDebugBreak;
612   PUSBPORT_ASSERT_FAILURE UsbPortAssertFailure;
613   PUSBPORT_GET_MINIPORT_REGISTRY_KEY_VALUE UsbPortGetMiniportRegistryKeyValue;
614   PUSBPORT_INVALIDATE_ROOT_HUB UsbPortInvalidateRootHub;
615   PUSBPORT_INVALIDATE_ENDPOINT UsbPortInvalidateEndpoint;
616   PUSBPORT_COMPLETE_TRANSFER UsbPortCompleteTransfer;
617   PUSBPORT_COMPLETE_ISO_TRANSFER UsbPortCompleteIsoTransfer;
618   PUSBPORT_LOG_ENTRY UsbPortLogEntry;
619   PUSBPORT_GET_MAPPED_VIRTUAL_ADDRESS UsbPortGetMappedVirtualAddress;
620   PUSBPORT_REQUEST_ASYNC_CALLBACK UsbPortRequestAsyncCallback;
621   PUSBPORT_READ_WRITE_CONFIG_SPACE UsbPortReadWriteConfigSpace;
622   PUSBPORT_WAIT UsbPortWait;
623   PUSBPORT_INVALIDATE_CONTROLLER UsbPortInvalidateController;
624   PUSBPORT_BUG_CHECK UsbPortBugCheck;
625   PUSBPORT_NOTIFY_DOUBLE_BUFFER UsbPortNotifyDoubleBuffer;
626 
627   /* Miniport */
628   PHCI_REBALANCE_ENDPOINT RebalanceEndpoint;
629   PHCI_FLUSH_INTERRUPTS FlushInterrupts;
630   PHCI_RH_CHIRP_ROOT_PORT RH_ChirpRootPort;
631   PHCI_TAKE_PORT_CONTROL TakePortControl;
632   ULONG Reserved4;
633   ULONG Reserved5;
634 } USBPORT_REGISTRATION_PACKET, *PUSBPORT_REGISTRATION_PACKET;
635 
636 #define USB10_MINIPORT_INTERFACE_VERSION  100
637 #define USB20_MINIPORT_INTERFACE_VERSION  200
638 
639 typedef struct _USBPORT_MINIPORT_INTERFACE {
640   PDRIVER_OBJECT DriverObject;
641   LIST_ENTRY DriverLink;
642   PDRIVER_UNLOAD DriverUnload;
643   ULONG Version;
644   USBPORT_REGISTRATION_PACKET Packet;
645 } USBPORT_MINIPORT_INTERFACE, *PUSBPORT_MINIPORT_INTERFACE;
646 
647 C_ASSERT(sizeof(USBPORT_MINIPORT_INTERFACE) == 32 + 76 * sizeof(PVOID));
648 
649 #define USBPORT_TRANSFER_DIRECTION_OUT  1 // From host to device
650 #define USBPORT_MAX_DEVICE_ADDRESS      127
651 
652 /* For USB1.1 or USB3 Hub Descriptors */
653 typedef union _USBPORT_HUB_11_CHARACTERISTICS {
654   struct {
655     USHORT PowerControlMode :1;
656     USHORT NoPowerSwitching :1; // Reserved. Used only on 1.0 compliant hubs that implement no power switching.
657     USHORT PartOfCompoundDevice :1;
658     USHORT OverCurrentProtectionMode :1;
659     USHORT NoOverCurrentProtection :1;
660     USHORT Reserved1 :11;
661   };
662   USHORT AsUSHORT;
663 } USBPORT_HUB_11_CHARACTERISTICS;
664 
665 C_ASSERT(sizeof(USBPORT_HUB_11_CHARACTERISTICS) == sizeof(USHORT));
666 
667 /* For USB2.0 Hub Descriptors */
668 typedef union _USBPORT_HUB_20_CHARACTERISTICS {
669   struct {
670     USHORT PowerControlMode :1;
671     USHORT NoPowerSwitching :1; // Reserved. Used only on 1.0 compliant hubs that implement no power switching.
672     USHORT PartOfCompoundDevice :1;
673     USHORT OverCurrentProtectionMode :1;
674     USHORT NoOverCurrentProtection :1;
675     USHORT TtThinkTime :2;
676     USHORT PortIndicatorsSupported :1;
677     USHORT Reserved1 :8;
678   };
679   USHORT AsUSHORT;
680 } USBPORT_HUB_20_CHARACTERISTICS;
681 
682 C_ASSERT(sizeof(USBPORT_HUB_20_CHARACTERISTICS) == sizeof(USHORT));
683 
684 typedef USBPORT_HUB_11_CHARACTERISTICS USBPORT_HUB_30_CHARACTERISTICS;
685 
686 typedef union _USBPORT_HUB_CHARACTERISTICS {
687   USHORT AsUSHORT;
688   USBPORT_HUB_11_CHARACTERISTICS Usb11HubCharacteristics;
689   USBPORT_HUB_20_CHARACTERISTICS Usb20HubCharacteristics;
690   USBPORT_HUB_30_CHARACTERISTICS Usb30HubCharacteristics;
691 } USBPORT_HUB_CHARACTERISTICS;
692 
693 C_ASSERT(sizeof(USBPORT_HUB_CHARACTERISTICS) == sizeof(USHORT));
694 
695 typedef struct _USBPORT_ROOT_HUB_DATA {
696   ULONG NumberOfPorts;
697   USBPORT_HUB_CHARACTERISTICS HubCharacteristics;
698   USHORT Padded1;
699   ULONG PowerOnToPowerGood;
700   ULONG HubControlCurrent;
701 } USBPORT_ROOT_HUB_DATA, *PUSBPORT_ROOT_HUB_DATA;
702 
703 C_ASSERT(sizeof(USBPORT_ROOT_HUB_DATA) == 16);
704 
705 ULONG
706 NTAPI
707 USBPORT_GetHciMn(VOID);
708 
709 NTSTATUS
710 NTAPI
711 USBPORT_RegisterUSBPortDriver(
712   IN PDRIVER_OBJECT DriverObject,
713   IN ULONG Version,
714   IN PUSBPORT_REGISTRATION_PACKET RegistrationPacket);
715 
716 #endif /* USBMPORT_H__ */
717