2238a0e7e70e68ef8ab2407a07e50bc38f8c31e4
[reactos.git] / reactos / drivers / usb / usbport / usbport.h
1 #ifndef USBPORT_H__
2 #define USBPORT_H__
3
4 #include <ntddk.h>
5 #include <windef.h>
6 #include <stdio.h>
7 #include <wdmguid.h>
8 #include <ntstrsafe.h>
9 #include <usb.h>
10 #include <hubbusif.h>
11 #include <usbbusif.h>
12 #include <usbdlib.h>
13 #include <usbuser.h>
14 #include <drivers/usbport/usbmport.h>
15
16 #define PCI_INTERFACE_USB_ID_UHCI 0x00
17 #define PCI_INTERFACE_USB_ID_OHCI 0x10
18 #define PCI_INTERFACE_USB_ID_EHCI 0x20
19 #define PCI_INTERFACE_USB_ID_XHCI 0x30
20
21 #ifdef USBD_TRANSFER_DIRECTION // due hubbusif.h included usbdi.h (Which overwrites...)
22 #undef USBD_TRANSFER_DIRECTION
23 #define USBD_TRANSFER_DIRECTION 0x00000001
24 #endif
25
26 #define USBPORT_RECIPIENT_ROOT_HUB BMREQUEST_TO_DEVICE
27 #define USBPORT_RECIPIENT_ROOT_PORT BMREQUEST_TO_OTHER
28
29 #define INVALIDATE_ENDPOINT_ONLY 0
30 #define INVALIDATE_ENDPOINT_WORKER_THREAD 1
31 #define INVALIDATE_ENDPOINT_WORKER_DPC 2
32 #define INVALIDATE_ENDPOINT_INT_NEXT_SOF 3
33
34 #define USBPORT_DMA_DIRECTION_FROM_DEVICE 1
35 #define USBPORT_DMA_DIRECTION_TO_DEVICE 2
36
37 #define USB_PORT_TAG 'pbsu'
38 #define URB_FUNCTION_MAX 0x31
39
40 /* Hub Class Feature Selectors (Recipient - Port) */
41 #define FEATURE_PORT_CONNECTION 0
42 #define FEATURE_PORT_ENABLE 1
43 #define FEATURE_PORT_SUSPEND 2
44 #define FEATURE_PORT_OVER_CURRENT 3
45 #define FEATURE_PORT_RESET 4
46 #define FEATURE_PORT_POWER 8
47 #define FEATURE_PORT_LOW_SPEED 9
48 #define FEATURE_C_PORT_CONNECTION 16
49 #define FEATURE_C_PORT_ENABLE 17
50 #define FEATURE_C_PORT_SUSPEND 18
51 #define FEATURE_C_PORT_OVER_CURRENT 19
52 #define FEATURE_C_PORT_RESET 20
53
54 /* Hub Class Feature Selectors (Recipient - Hub) */
55 #define FEATURE_C_HUB_LOCAL_POWER 0
56 #define FEATURE_C_HUB_OVER_CURRENT 1
57
58 /* Flags */
59 #define USBPORT_FLAG_INT_CONNECTED 0x00000001
60 #define USBPORT_FLAG_HC_STARTED 0x00000002
61 #define USBPORT_FLAG_HC_POLLING 0x00000004
62 #define USBPORT_FLAG_WORKER_THREAD_ON 0x00000008
63 #define USBPORT_FLAG_HC_SUSPEND 0x00000100
64 #define USBPORT_FLAG_INTERRUPT_ENABLED 0x00000400
65 #define USBPORT_FLAG_SELECTIVE_SUSPEND 0x00000800
66 #define USBPORT_FLAG_DOS_SYMBOLIC_NAME 0x00010000
67 #define USBPORT_FLAG_LEGACY_SUPPORT 0x00080000
68 #define USBPORT_FLAG_HC_WAKE_SUPPORT 0x00200000
69 #define USBPORT_FLAG_DIAGNOSTIC_MODE 0x00800000 //IOCTL_USB_DIAGNOSTIC_MODE_ON
70 #define USBPORT_FLAG_COMPANION_HC 0x01000000
71 #define USBPORT_FLAG_REGISTERED_FDO 0x02000000
72 #define USBPORT_FLAG_NO_HACTION 0x04000000
73 #define USBPORT_FLAG_BIOS_DISABLE_SS 0x08000000 //Selective Suspend
74 #define USBPORT_FLAG_PWR_AND_CHIRP_LOCK 0x10000000
75 #define USBPORT_FLAG_POWER_AND_CHIRP_OK 0x40000000
76 #define USBPORT_FLAG_RH_INIT_CALLBACK 0x80000000
77
78 /* PnP state Flags */
79 #define USBPORT_PNP_STATE_NOT_INIT 0x00000001
80 #define USBPORT_PNP_STATE_STARTED 0x00000002
81 #define USBPORT_PNP_STATE_FAILED 0x00000004
82 #define USBPORT_PNP_STATE_STOPPED 0x00000008
83
84 /* Timer Flags */
85 #define USBPORT_TMFLAG_TIMER_QUEUED 0x00000001
86 #define USBPORT_TMFLAG_HC_SUSPENDED 0x00000002
87 #define USBPORT_TMFLAG_HC_RESUME 0x00000004
88 #define USBPORT_TMFLAG_RH_SUSPENDED 0x00000008
89 #define USBPORT_TMFLAG_TIMER_STARTED 0x00000010
90 #define USBPORT_TMFLAG_WAKE 0x00000020
91 #define USBPORT_TMFLAG_IDLE_QUEUEITEM_ON 0x00000040
92
93 /* Miniport Flags */
94 #define USBPORT_MPFLAG_INTERRUPTS_ENABLED 0x00000001
95 #define USBPORT_MPFLAG_SUSPENDED 0x00000002
96
97 /* Device handle Flags (USBPORT_DEVICE_HANDLE) */
98 #define DEVICE_HANDLE_FLAG_ROOTHUB 0x00000002
99 #define DEVICE_HANDLE_FLAG_REMOVED 0x00000008
100 #define DEVICE_HANDLE_FLAG_INITIALIZED 0x00000010
101
102 /* Endpoint Flags (USBPORT_ENDPOINT) */
103 #define ENDPOINT_FLAG_DMA_TYPE 0x00000001
104 #define ENDPOINT_FLAG_ROOTHUB_EP0 0x00000002
105 #define ENDPOINT_FLAG_NUKE 0x00000008
106 #define ENDPOINT_FLAG_QUEUENE_EMPTY 0x00000010
107 #define ENDPOINT_FLAG_ABORTING 0x00000020
108 #define ENDPOINT_FLAG_IDLE 0x00000100
109 #define ENDPOINT_FLAG_OPENED 0x00000200
110 #define ENDPOINT_FLAG_CLOSED 0x00000400
111
112 /* UsbdFlags Flags (URB) */
113 #define USBD_FLAG_ALLOCATED_MDL 0x00000002
114 #define USBD_FLAG_NOT_ISO_TRANSFER 0x00000010
115 #define USBD_FLAG_ALLOCATED_TRANSFER 0x00000020
116
117 /* Pipe handle Flags (USBPORT_PIPE_HANDLE) */
118 #define PIPE_HANDLE_FLAG_CLOSED 0x00000001
119 #define PIPE_HANDLE_FLAG_NULL_PACKET_SIZE 0x00000002
120
121 /* Transfer Flags (USBPORT_TRANSFER) */
122 #define TRANSFER_FLAG_CANCELED 0x00000001
123 #define TRANSFER_FLAG_DMA_MAPPED 0x00000002
124 #define TRANSFER_FLAG_SUBMITED 0x00000008
125 #define TRANSFER_FLAG_ABORTED 0x00000010
126 #define TRANSFER_FLAG_ISO 0x00000020
127 #define TRANSFER_FLAG_DEVICE_GONE 0x00000080
128 #define TRANSFER_FLAG_SPLITED 0x00000100
129
130 extern KSPIN_LOCK USBPORT_SpinLock;
131 extern LIST_ENTRY USBPORT_MiniPortDrivers;
132
133 typedef USBD_STATUS* PUSBD_STATUS;
134
135 typedef struct _USBPORT_COMMON_BUFFER_HEADER {
136 ULONG Length;
137 ULONG_PTR BaseVA;
138 PHYSICAL_ADDRESS LogicalAddress;
139 SIZE_T BufferLength;
140 ULONG_PTR VirtualAddress;
141 ULONG_PTR PhysicalAddress;
142 } USBPORT_COMMON_BUFFER_HEADER, *PUSBPORT_COMMON_BUFFER_HEADER;
143
144 typedef struct _USBPORT_ENDPOINT *PUSBPORT_ENDPOINT;
145
146 typedef struct _USBPORT_PIPE_HANDLE {
147 ULONG Flags;
148 ULONG PipeFlags;
149 USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
150 UCHAR Padded;
151 PUSBPORT_ENDPOINT Endpoint;
152 LIST_ENTRY PipeLink;
153 } USBPORT_PIPE_HANDLE, *PUSBPORT_PIPE_HANDLE;
154
155 typedef struct _USBPORT_CONFIGURATION_HANDLE {
156 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
157 LIST_ENTRY InterfaceHandleList;
158 //USB_CONFIGURATION_DESCRIPTOR CfgDescriptor; // Body.
159 } USBPORT_CONFIGURATION_HANDLE, *PUSBPORT_CONFIGURATION_HANDLE;
160
161 typedef struct _USBPORT_INTERFACE_HANDLE {
162 LIST_ENTRY InterfaceLink;
163 UCHAR AlternateSetting;
164 UCHAR Pad1[3];
165 USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
166 UCHAR Pad2[3];
167 USBPORT_PIPE_HANDLE PipeHandle[1];
168 } USBPORT_INTERFACE_HANDLE, *PUSBPORT_INTERFACE_HANDLE;
169
170 typedef struct _USBPORT_DEVICE_HANDLE {
171 ULONG Flags;
172 USHORT DeviceAddress;
173 USHORT PortNumber;
174 USBPORT_PIPE_HANDLE PipeHandle;
175 ULONG DeviceSpeed;
176 BOOL IsRootHub;
177 LIST_ENTRY PipeHandleList;
178 PUSBPORT_CONFIGURATION_HANDLE ConfigHandle;
179 struct _USBPORT_DEVICE_HANDLE *HubDeviceHandle;
180 USB_DEVICE_DESCRIPTOR DeviceDescriptor;
181 LIST_ENTRY DeviceHandleLink;
182 LONG DeviceHandleLock;
183 ULONG TtCount;
184 } USBPORT_DEVICE_HANDLE, *PUSBPORT_DEVICE_HANDLE;
185
186 typedef struct _USBPORT_ENDPOINT {
187 ULONG Flags;
188 PDEVICE_OBJECT FdoDevice;
189 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
190 PUSBPORT_DEVICE_HANDLE DeviceHandle;
191 USBPORT_ENDPOINT_PROPERTIES EndpointProperties;
192 ULONG EndpointWorker;
193 ULONG FrameNumber;
194 /* Locks */
195 KSPIN_LOCK EndpointSpinLock;
196 KIRQL EndpointOldIrql;
197 KIRQL EndpointStateOldIrql;
198 UCHAR Padded[2];
199 LONG LockCounter;
200 LONG FlushPendingLock;
201 /* State */
202 ULONG StateLast;
203 ULONG StateNext;
204 LIST_ENTRY StateChangeLink;
205 KSPIN_LOCK StateChangeSpinLock;
206 /* Transfer lists */
207 LIST_ENTRY PendingTransferList;
208 LIST_ENTRY TransferList;
209 LIST_ENTRY CancelList;
210 LIST_ENTRY AbortList;
211 /* Links */
212 LIST_ENTRY EndpointLink;
213 LIST_ENTRY WorkerLink;
214 LIST_ENTRY CloseLink;
215 LIST_ENTRY DispatchLink;
216 LIST_ENTRY FlushLink;
217 LIST_ENTRY FlushControllerLink;
218 LIST_ENTRY FlushAbortLink;
219 } USBPORT_ENDPOINT, *PUSBPORT_ENDPOINT;
220
221 typedef struct _USBPORT_TRANSFER {
222 ULONG Flags;
223 PIRP Irp;
224 PURB Urb;
225 PRKEVENT Event;
226 PVOID MiniportTransfer;
227 SIZE_T PortTransferLength; // Only port part
228 SIZE_T FullTransferLength; // Port + miniport
229 PUSBPORT_ENDPOINT Endpoint;
230 USBPORT_TRANSFER_PARAMETERS TransferParameters;
231 PMDL TransferBufferMDL;
232 ULONG Direction;
233 LIST_ENTRY TransferLink;
234 USBD_STATUS USBDStatus;
235 ULONG CompletedTransferLen;
236 ULONG NumberOfMapRegisters;
237 PVOID MapRegisterBase;
238 ULONG TimeOut;
239 LARGE_INTEGER Time;
240 // SgList should be LAST field
241 USBPORT_SCATTER_GATHER_LIST SgList; // Non IsoTransfer
242 } USBPORT_TRANSFER, *PUSBPORT_TRANSFER;
243
244 typedef struct _USBPORT_IRP_TABLE {
245 struct _USBPORT_IRP_TABLE * LinkNextTable;
246 PIRP irp[0X200];
247 } USBPORT_IRP_TABLE, *PUSBPORT_IRP_TABLE;
248
249 typedef struct _USBPORT_COMMON_DEVICE_EXTENSION {
250 PDEVICE_OBJECT SelfDevice;
251 PDEVICE_OBJECT LowerPdoDevice; // PhysicalDeviceObject
252 PDEVICE_OBJECT LowerDevice; // TopOfStackDeviceObject
253 ULONG IsPDO;
254 UNICODE_STRING SymbolicLinkName;
255 BOOL IsInterfaceEnabled;
256 DEVICE_POWER_STATE DevicePowerState;
257 ULONG PnpStateFlags;
258 } USBPORT_COMMON_DEVICE_EXTENSION, *PUSBPORT_COMMON_DEVICE_EXTENSION;
259
260 typedef struct _USBPORT_DEVICE_EXTENSION {
261 USBPORT_COMMON_DEVICE_EXTENSION CommonExtension;
262 ULONG Flags;
263 PDEVICE_OBJECT RootHubPdo; // RootHubDeviceObject
264 KSPIN_LOCK RootHubCallbackSpinLock;
265 LONG RHInitCallBackLock;
266 LONG ChirpRootPortLock;
267 KSEMAPHORE ControllerSemaphore;
268 ULONG FdoNameNumber;
269 UNICODE_STRING DosDeviceSymbolicName;
270 ULONG UsbBIOSx;
271 LIST_ENTRY ControllerLink;
272 ULONG CommonBufferLimit;
273 /* Miniport */
274 ULONG MiniPortFlags;
275 PVOID MiniPortExt;
276 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
277 USBPORT_RESOURCES UsbPortResources;
278 PUSBPORT_COMMON_BUFFER_HEADER MiniPortCommonBuffer;
279 KSPIN_LOCK MiniportSpinLock;
280 /* Bus Interface */
281 BUS_INTERFACE_STANDARD BusInterface;
282 USHORT VendorID;
283 USHORT DeviceID;
284 UCHAR RevisionID;
285 UCHAR ProgIf;
286 UCHAR SubClass;
287 UCHAR BaseClass;
288 /* Dma Adapter */
289 PDMA_ADAPTER DmaAdapter;
290 ULONG NumberMapRegs;
291 /* Interrupt */
292 PKINTERRUPT InterruptObject;
293 KDPC IsrDpc;
294 LONG IsrDpcCounter;
295 LONG IsrDpcHandlerCounter;
296 KSPIN_LOCK MiniportInterruptsSpinLock;
297 KTIMER TimerSoftInterrupt;
298 KDPC SoftInterruptDpc;
299 /* Endpoints */
300 ULONG PeriodicEndpoints;
301 LIST_ENTRY EndpointList;
302 KSPIN_LOCK EndpointListSpinLock;
303 LIST_ENTRY EpStateChangeList;
304 KSPIN_LOCK EpStateChangeSpinLock;
305 LIST_ENTRY EndpointClosedList;
306 KSPIN_LOCK EndpointClosedSpinLock;
307 LIST_ENTRY WorkerList;
308 /* Transfers */
309 LIST_ENTRY MapTransferList;
310 KSPIN_LOCK MapTransferSpinLock;
311 LIST_ENTRY DoneTransferList;
312 KSPIN_LOCK DoneTransferSpinLock;
313 KDPC TransferFlushDpc;
314 KSPIN_LOCK FlushTransferSpinLock;
315 KSPIN_LOCK FlushPendingTransferSpinLock;
316 /* Timer */
317 ULONG TimerValue; // Timer period (500) msec. default
318 ULONG TimerFlags;
319 KTIMER TimerObject;
320 KDPC TimerDpc;
321 KSPIN_LOCK TimerFlagsSpinLock;
322 /* Worker Thread */
323 PRKTHREAD WorkerThread;
324 HANDLE WorkerThreadHandle;
325 KEVENT WorkerThreadEvent;
326 KSPIN_LOCK WorkerThreadEventSpinLock;
327 /* Usb Devices */
328 ULONG UsbAddressBitMap[4];
329 LIST_ENTRY DeviceHandleList;
330 KSPIN_LOCK DeviceHandleSpinLock;
331 KSEMAPHORE DeviceSemaphore;
332 /* Device Capabilities */
333 DEVICE_CAPABILITIES Capabilities;
334 ULONG BusNumber;
335 ULONG PciDeviceNumber;
336 ULONG PciFunctionNumber;
337 ULONG TotalBusBandwidth;
338 /* Idle */
339 LARGE_INTEGER IdleTime;
340 IO_CSQ IdleIoCsq;
341 KSPIN_LOCK IdleIoCsqSpinLock;
342 LIST_ENTRY IdleIrpList;
343 LONG IdleLockCounter;
344 /* Bad Requests */
345 IO_CSQ BadRequestIoCsq;
346 KSPIN_LOCK BadRequestIoCsqSpinLock;
347 LIST_ENTRY BadRequestList;
348 LONG BadRequestLockCounter;
349 /* Irp Queues */
350 PUSBPORT_IRP_TABLE PendingIrpTable;
351 PUSBPORT_IRP_TABLE ActiveIrpTable;
352 /* Power */
353 LONG SetPowerLockCounter;
354 KSPIN_LOCK PowerWakeSpinLock;
355 KSPIN_LOCK SetPowerD0SpinLock;
356 KDPC WorkerRequestDpc;
357 KDPC HcWakeDpc;
358
359 /* Miniport extension should be aligned on 0x100 */
360 #if !defined(_M_X64)
361 ULONG Padded[34];
362 #endif
363
364 } USBPORT_DEVICE_EXTENSION, *PUSBPORT_DEVICE_EXTENSION;
365
366 C_ASSERT(sizeof(USBPORT_DEVICE_EXTENSION) == 0x400);
367
368 typedef struct _USBPORT_RH_DESCRIPTORS {
369 USB_DEVICE_DESCRIPTOR DeviceDescriptor;
370 USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor;
371 USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
372 USB_ENDPOINT_DESCRIPTOR EndPointDescriptor;
373 USB_HUB_DESCRIPTOR Descriptor; // Size may be: 7 + 2[1..32] (7 + 2..64)
374 } USBPORT_RH_DESCRIPTORS, *PUSBPORT_RH_DESCRIPTORS;
375
376 typedef struct _USBPORT_RHDEVICE_EXTENSION {
377 USBPORT_COMMON_DEVICE_EXTENSION CommonExtension;
378 ULONG Flags;
379 PDEVICE_OBJECT FdoDevice;
380 ULONG PdoNameNumber;
381 USBPORT_DEVICE_HANDLE DeviceHandle;
382 PUSBPORT_RH_DESCRIPTORS RootHubDescriptors;
383 PUSBPORT_ENDPOINT Endpoint;
384 ULONG ConfigurationValue;
385 PRH_INIT_CALLBACK RootHubInitCallback;
386 PVOID RootHubInitContext;
387 DEVICE_CAPABILITIES Capabilities;
388 PIRP WakeIrp;
389 } USBPORT_RHDEVICE_EXTENSION, *PUSBPORT_RHDEVICE_EXTENSION;
390
391 typedef struct _USBPORT_ASYNC_CALLBACK_DATA {
392 ULONG Reserved;
393 PDEVICE_OBJECT FdoDevice;
394 KTIMER AsyncTimer;
395 KDPC AsyncTimerDpc;
396 ASYNC_TIMER_CALLBACK *CallbackFunction;
397 ULONG CallbackContext;
398 } USBPORT_ASYNC_CALLBACK_DATA, *PUSBPORT_ASYNC_CALLBACK_DATA;
399
400 C_ASSERT(sizeof(USBPORT_ASYNC_CALLBACK_DATA) == 84 + sizeof(PVOID));
401
402 typedef struct _TIMER_WORK_QUEUE_ITEM {
403 WORK_QUEUE_ITEM WqItem;
404 PDEVICE_OBJECT FdoDevice;
405 ULONG Context;
406 } TIMER_WORK_QUEUE_ITEM, *PTIMER_WORK_QUEUE_ITEM;
407
408 /* usbport.c */
409 NTSTATUS
410 NTAPI
411 USBPORT_USBDStatusToNtStatus(
412 IN PURB Urb,
413 IN USBD_STATUS USBDStatus);
414
415 NTSTATUS
416 NTAPI
417 USBPORT_Wait(
418 IN PVOID MiniPortExtension,
419 IN ULONG Milliseconds);
420
421 VOID
422 NTAPI
423 USBPORT_TransferFlushDpc(
424 IN PRKDPC Dpc,
425 IN PVOID DeferredContext,
426 IN PVOID SystemArgument1,
427 IN PVOID SystemArgument2);
428
429 NTSTATUS
430 NTAPI
431 USBPORT_CreateWorkerThread(
432 IN PDEVICE_OBJECT FdoDevice);
433
434 BOOLEAN
435 NTAPI
436 USBPORT_StartTimer(
437 IN PDEVICE_OBJECT FdoDevice,
438 IN ULONG Time);
439
440 PUSBPORT_COMMON_BUFFER_HEADER
441 NTAPI
442 USBPORT_AllocateCommonBuffer(
443 IN PDEVICE_OBJECT FdoDevice,
444 IN SIZE_T BufferLength);
445
446 VOID
447 NTAPI
448 USBPORT_FreeCommonBuffer(
449 IN PDEVICE_OBJECT FdoDevice,
450 IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer);
451
452 USBD_STATUS
453 NTAPI
454 USBPORT_AllocateTransfer(
455 IN PDEVICE_OBJECT FdoDevice,
456 IN PURB Urb,
457 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
458 IN PIRP Irp,
459 IN PRKEVENT Event);
460
461 VOID
462 NTAPI
463 USBPORT_FlushMapTransfers(
464 IN PDEVICE_OBJECT FdoDevice);
465
466 VOID
467 NTAPI
468 USBPORT_IsrDpc(
469 IN PRKDPC Dpc,
470 IN PVOID DeferredContext,
471 IN PVOID SystemArgument1,
472 IN PVOID SystemArgument2);
473
474 BOOLEAN
475 NTAPI
476 USBPORT_InterruptService(
477 IN PKINTERRUPT Interrupt,
478 IN PVOID ServiceContext);
479
480 VOID
481 NTAPI
482 USBPORT_SignalWorkerThread(
483 IN PDEVICE_OBJECT FdoDevice);
484
485 VOID
486 NTAPI
487 USBPORT_CompleteTransfer(
488 IN PURB Urb,
489 IN USBD_STATUS TransferStatus);
490
491 VOID
492 NTAPI
493 USBPORT_DpcHandler(
494 IN PDEVICE_OBJECT FdoDevice);
495
496 VOID
497 NTAPI
498 USBPORT_WorkerRequestDpc(
499 IN PRKDPC Dpc,
500 IN PVOID DeferredContext,
501 IN PVOID SystemArgument1,
502 IN PVOID SystemArgument2);
503
504 BOOLEAN
505 NTAPI
506 USBPORT_QueueDoneTransfer(
507 IN PUSBPORT_TRANSFER Transfer,
508 IN USBD_STATUS USBDStatus);
509
510 VOID
511 NTAPI
512 USBPORT_MiniportInterrupts(
513 IN PDEVICE_OBJECT FdoDevice,
514 IN BOOLEAN IsEnable);
515
516 NTSTATUS
517 NTAPI
518 USBPORT_SetRegistryKeyValue(
519 IN PDEVICE_OBJECT DeviceObject,
520 IN BOOL UseDriverKey,
521 IN ULONG Type,
522 IN PCWSTR ValueNameString,
523 IN PVOID Data,
524 IN ULONG DataSize);
525
526 NTSTATUS
527 NTAPI
528 USBPORT_GetRegistryKeyValueFullInfo(
529 IN PDEVICE_OBJECT FdoDevice,
530 IN PDEVICE_OBJECT PdoDevice,
531 IN BOOL UseDriverKey,
532 IN PCWSTR SourceString,
533 IN ULONG LengthStr,
534 IN PVOID Buffer,
535 IN ULONG NumberOfBytes);
536
537 VOID
538 NTAPI
539 USBPORT_AddUSB1Fdo(
540 IN PDEVICE_OBJECT FdoDevice);
541
542 VOID
543 NTAPI
544 USBPORT_AddUSB2Fdo(
545 IN PDEVICE_OBJECT FdoDevice);
546
547 VOID
548 NTAPI
549 USBPORT_RemoveUSBxFdo(
550 IN PDEVICE_OBJECT FdoDevice);
551
552 PDEVICE_OBJECT
553 NTAPI
554 USBPORT_FindUSB2Controller(
555 IN PDEVICE_OBJECT FdoDevice);
556
557 PDEVICE_RELATIONS
558 NTAPI
559 USBPORT_FindCompanionControllers(
560 IN PDEVICE_OBJECT USB2FdoDevice,
561 IN BOOLEAN IsObRefer,
562 IN BOOLEAN IsFDOsReturned);
563
564 VOID
565 NTAPI
566 USBPORT_InvalidateControllerHandler(
567 IN PDEVICE_OBJECT FdoDevice,
568 IN ULONG Type);
569
570 /* debug.c */
571 ULONG
572 NTAPI
573 USBPORT_DbgPrint(
574 IN PVOID MiniPortExtension,
575 IN ULONG Level,
576 IN PCH Format,
577 ...);
578
579 ULONG
580 NTAPI
581 USBPORT_TestDebugBreak(
582 IN PVOID MiniPortExtension);
583
584 ULONG
585 NTAPI
586 USBPORT_AssertFailure(
587 PVOID MiniPortExtension,
588 PVOID FailedAssertion,
589 PVOID FileName,
590 ULONG LineNumber,
591 PCHAR Message);
592
593 VOID
594 NTAPI
595 USBPORT_BugCheck(
596 IN PVOID MiniPortExtension);
597
598 ULONG
599 NTAPI
600 USBPORT_LogEntry(
601 IN PVOID MiniPortExtension,
602 IN ULONG DriverTag,
603 IN ULONG EnumTag,
604 IN ULONG P1,
605 IN ULONG P2,
606 IN ULONG P3);
607
608 VOID
609 NTAPI
610 USBPORT_DumpingDeviceDescriptor(
611 IN PUSB_DEVICE_DESCRIPTOR DeviceDescriptor);
612
613 VOID
614 NTAPI
615 USBPORT_DumpingConfiguration(
616 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor);
617
618 VOID
619 NTAPI
620 USBPORT_DumpingCapabilities(
621 IN PDEVICE_CAPABILITIES Capabilities);
622
623 VOID
624 NTAPI
625 USBPORT_DumpingSetupPacket(
626 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket);
627
628 VOID
629 NTAPI
630 USBPORT_DumpingURB(
631 IN PURB Urb);
632
633 VOID
634 NTAPI
635 USBPORT_DumpingIDs(
636 IN PVOID Buffer);
637
638 /* device.c */
639 NTSTATUS
640 NTAPI
641 USBPORT_HandleSelectConfiguration(
642 IN PDEVICE_OBJECT FdoDevice,
643 IN PIRP Irp,
644 IN PURB Urb);
645
646 VOID
647 NTAPI
648 USBPORT_AddDeviceHandle(
649 IN PDEVICE_OBJECT FdoDevice,
650 IN PUSBPORT_DEVICE_HANDLE DeviceHandle);
651
652 VOID
653 NTAPI
654 USBPORT_RemoveDeviceHandle(
655 IN PDEVICE_OBJECT FdoDevice,
656 IN PUSBPORT_DEVICE_HANDLE DeviceHandle);
657
658 BOOLEAN
659 NTAPI
660 USBPORT_ValidateDeviceHandle(
661 IN PDEVICE_OBJECT FdoDevice,
662 IN PUSBPORT_DEVICE_HANDLE DeviceHandle);
663
664 NTSTATUS
665 NTAPI
666 USBPORT_CreateDevice(
667 IN OUT PUSB_DEVICE_HANDLE *pUsbdDeviceHandle,
668 IN PDEVICE_OBJECT FdoDevice,
669 IN PUSBPORT_DEVICE_HANDLE HubDeviceHandle,
670 IN USHORT PortStatus,
671 IN USHORT Port);
672
673 NTSTATUS
674 NTAPI
675 USBPORT_InitializeDevice(
676 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
677 IN PDEVICE_OBJECT FdoDevice);
678
679 NTSTATUS
680 NTAPI
681 USBPORT_GetUsbDescriptor(
682 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
683 IN PDEVICE_OBJECT FdoDevice,
684 IN UCHAR Type,
685 IN PUCHAR ConfigDesc,
686 IN PULONG ConfigDescSize);
687
688 NTSTATUS
689 NTAPI
690 USBPORT_HandleSelectInterface(
691 IN PDEVICE_OBJECT FdoDevice,
692 IN PIRP Irp,
693 IN PURB Urb);
694
695 NTSTATUS
696 NTAPI
697 USBPORT_RemoveDevice(
698 IN PDEVICE_OBJECT FdoDevice,
699 IN OUT PUSBPORT_DEVICE_HANDLE DeviceHandle,
700 IN ULONG Flags);
701
702 NTSTATUS
703 NTAPI
704 USBPORT_SendSetupPacket(
705 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
706 IN PDEVICE_OBJECT FdoDevice,
707 IN PUSB_DEFAULT_PIPE_SETUP_PACKET SetupPacket,
708 IN PVOID Buffer,
709 IN ULONG Length,
710 IN OUT PULONG TransferedLen,
711 IN OUT PUSBD_STATUS pUSBDStatus);
712
713 NTSTATUS
714 NTAPI
715 USBPORT_RestoreDevice(
716 IN PDEVICE_OBJECT FdoDevice,
717 IN OUT PUSBPORT_DEVICE_HANDLE OldDeviceHandle,
718 IN OUT PUSBPORT_DEVICE_HANDLE NewDeviceHandle);
719
720 NTSTATUS
721 NTAPI
722 USBPORT_Initialize20Hub(
723 IN PDEVICE_OBJECT FdoDevice,
724 IN PUSBPORT_DEVICE_HANDLE HubDeviceHandle,
725 IN ULONG TtCount);
726
727 /* endpoint.c */
728 NTSTATUS
729 NTAPI
730 USBPORT_OpenPipe(
731 IN PDEVICE_OBJECT FdoDevice,
732 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
733 IN PUSBPORT_PIPE_HANDLE PipeHandle,
734 IN PUSBD_STATUS UsbdStatus);
735
736 MPSTATUS
737 NTAPI
738 MiniportOpenEndpoint(
739 IN PDEVICE_OBJECT FdoDevice,
740 IN PUSBPORT_ENDPOINT Endpoint);
741
742 NTSTATUS
743 NTAPI
744 USBPORT_ReopenPipe(
745 IN PDEVICE_OBJECT FdoDevice,
746 IN PUSBPORT_ENDPOINT Endpoint);
747
748 VOID
749 NTAPI
750 USBPORT_ClosePipe(
751 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
752 IN PDEVICE_OBJECT FdoDevice,
753 IN PUSBPORT_PIPE_HANDLE PipeHandle);
754
755 VOID
756 NTAPI
757 MiniportCloseEndpoint(
758 IN PDEVICE_OBJECT FdoDevice,
759 IN PUSBPORT_ENDPOINT Endpoint);
760
761 VOID
762 NTAPI
763 USBPORT_AddPipeHandle(
764 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
765 IN PUSBPORT_PIPE_HANDLE PipeHandle);
766
767 VOID
768 NTAPI
769 USBPORT_RemovePipeHandle(
770 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
771 IN PUSBPORT_PIPE_HANDLE PipeHandle);
772
773 BOOLEAN
774 NTAPI
775 USBPORT_ValidatePipeHandle(
776 IN PUSBPORT_DEVICE_HANDLE DeviceHandle,
777 IN PUSBPORT_PIPE_HANDLE PipeHandle);
778
779 VOID
780 NTAPI
781 USBPORT_FlushClosedEndpointList(
782 IN PDEVICE_OBJECT FdoDevice);
783
784 VOID
785 NTAPI
786 USBPORT_SetEndpointState(
787 IN PUSBPORT_ENDPOINT Endpoint,
788 IN ULONG State);
789
790 ULONG
791 NTAPI
792 USBPORT_GetEndpointState(
793 IN PUSBPORT_ENDPOINT Endpoint);
794
795 VOID
796 NTAPI
797 USBPORT_InvalidateEndpointHandler(
798 IN PDEVICE_OBJECT FdoDevice,
799 IN PUSBPORT_ENDPOINT Endpoint,
800 IN ULONG Type);
801
802 BOOLEAN
803 NTAPI
804 USBPORT_EndpointWorker(
805 IN PUSBPORT_ENDPOINT Endpoint,
806 IN BOOLEAN Flag);
807
808 VOID
809 NTAPI
810 USBPORT_NukeAllEndpoints(
811 IN PDEVICE_OBJECT FdoDevice);
812
813 BOOLEAN
814 NTAPI
815 USBPORT_EndpointHasQueuedTransfers(
816 IN PDEVICE_OBJECT FdoDevice,
817 IN PUSBPORT_ENDPOINT Endpoint,
818 IN PULONG TransferCount);
819
820 /* iface.c */
821 NTSTATUS
822 NTAPI
823 USBPORT_PdoQueryInterface(
824 IN PDEVICE_OBJECT FdoDevice,
825 IN PDEVICE_OBJECT PdoDevice,
826 IN PIRP Irp);
827
828 /* ioctl.c */
829 NTSTATUS
830 NTAPI
831 USBPORT_PdoDeviceControl(
832 PDEVICE_OBJECT PdoDevice,
833 PIRP Irp);
834
835 NTSTATUS
836 NTAPI
837 USBPORT_FdoDeviceControl(
838 PDEVICE_OBJECT FdoDevice,
839 PIRP Irp);
840
841 NTSTATUS
842 NTAPI
843 USBPORT_FdoInternalDeviceControl(
844 IN PDEVICE_OBJECT FdoDevice,
845 IN PIRP Irp);
846
847 NTSTATUS
848 NTAPI
849 USBPORT_PdoInternalDeviceControl(
850 IN PDEVICE_OBJECT FdoDevice,
851 IN PIRP Irp);
852
853 NTSTATUS
854 NTAPI
855 USBPORT_GetSymbolicName(
856 IN PDEVICE_OBJECT RootHubPdo,
857 IN PUNICODE_STRING DestinationString);
858
859 /* pnp.c */
860 NTSTATUS
861 NTAPI
862 USBPORT_FdoPnP(
863 IN PDEVICE_OBJECT FdoDevice,
864 IN PIRP Irp);
865
866 NTSTATUS
867 NTAPI
868 USBPORT_PdoPnP(
869 IN PDEVICE_OBJECT FdoDevice,
870 IN PIRP Irp);
871
872 /* power.c */
873 NTSTATUS
874 NTAPI
875 USBPORT_PdoPower(
876 IN PDEVICE_OBJECT PdoDevice,
877 IN PIRP Irp);
878
879 NTSTATUS
880 NTAPI
881 USBPORT_FdoPower(
882 IN PDEVICE_OBJECT FdoDevice,
883 IN PIRP Irp);
884
885 NTSTATUS
886 NTAPI
887 USBPORT_IdleNotification(
888 IN PDEVICE_OBJECT PdoDevice,
889 IN PIRP Irp);
890
891 VOID
892 NTAPI
893 USBPORT_AdjustDeviceCapabilities(
894 IN PDEVICE_OBJECT FdoDevice,
895 IN PDEVICE_OBJECT PdoDevice);
896
897 VOID
898 NTAPI
899 USBPORT_DoIdleNotificationCallback(
900 IN PVOID Context);
901
902 VOID
903 NTAPI
904 USBPORT_CompletePdoWaitWake(
905 IN PDEVICE_OBJECT FdoDevice);
906
907 VOID
908 NTAPI
909 USBPORT_DoSetPowerD0(
910 IN PDEVICE_OBJECT FdoDevice);
911
912 VOID
913 NTAPI
914 USBPORT_HcWakeDpc(
915 IN PRKDPC Dpc,
916 IN PVOID DeferredContext,
917 IN PVOID SystemArgument1,
918 IN PVOID SystemArgument2);
919
920 VOID
921 NTAPI
922 USBPORT_HcQueueWakeDpc(
923 IN PDEVICE_OBJECT FdoDevice);
924
925 /* queue.c */
926 VOID
927 NTAPI
928 USBPORT_InsertIdleIrp(
929 IN PIO_CSQ Csq,
930 IN PIRP Irp);
931
932 VOID
933 NTAPI
934 USBPORT_RemoveIdleIrp(
935 IN PIO_CSQ Csq,
936 IN PIRP Irp);
937
938 PIRP
939 NTAPI
940 USBPORT_PeekNextIdleIrp(
941 IN PIO_CSQ Csq,
942 IN PIRP Irp,
943 IN PVOID PeekContext);
944
945 VOID
946 NTAPI
947 USBPORT_AcquireIdleLock(
948 IN PIO_CSQ Csq,
949 IN PKIRQL Irql);
950
951 VOID
952 NTAPI
953 USBPORT_ReleaseIdleLock(
954 IN PIO_CSQ Csq,
955 IN KIRQL Irql);
956
957 VOID
958 NTAPI
959 USBPORT_CompleteCanceledIdleIrp(
960 IN PIO_CSQ Csq,
961 IN PIRP Irp);
962
963 VOID
964 NTAPI
965 USBPORT_InsertBadRequest(
966 IN PIO_CSQ Csq,
967 IN PIRP Irp);
968
969 VOID
970 NTAPI
971 USBPORT_RemoveBadRequest(
972 IN PIO_CSQ Csq,
973 IN PIRP Irp);
974
975 PIRP
976 NTAPI
977 USBPORT_PeekNextBadRequest(
978 IN PIO_CSQ Csq,
979 IN PIRP Irp,
980 IN PVOID PeekContext);
981
982 VOID
983 NTAPI
984 USBPORT_AcquireBadRequestLock(
985 IN PIO_CSQ Csq,
986 IN PKIRQL Irql);
987
988 VOID
989 NTAPI
990 USBPORT_ReleaseBadRequestLock(
991 IN PIO_CSQ Csq,
992 IN KIRQL Irql);
993
994 VOID
995 NTAPI
996 USBPORT_CompleteCanceledBadRequest(
997 IN PIO_CSQ Csq,
998 IN PIRP Irp);
999
1000 VOID
1001 NTAPI
1002 USBPORT_InsertIrpInTable(
1003 IN PUSBPORT_IRP_TABLE IrpTable,
1004 IN PIRP Irp);
1005
1006 PIRP
1007 NTAPI
1008 USBPORT_RemovePendingTransferIrp(
1009 IN PDEVICE_OBJECT FdoDevice,
1010 IN PIRP Irp);
1011
1012 PIRP
1013 NTAPI
1014 USBPORT_RemoveActiveTransferIrp(
1015 IN PDEVICE_OBJECT FdoDevice,
1016 IN PIRP Irp);
1017
1018 VOID
1019 NTAPI
1020 USBPORT_FindUrbInIrpTable(
1021 IN PUSBPORT_IRP_TABLE IrpTable,
1022 IN PURB Urb,
1023 IN PIRP Irp);
1024
1025 VOID
1026 NTAPI
1027 USBPORT_CancelActiveTransferIrp(
1028 IN PDEVICE_OBJECT DeviceObject,
1029 IN PIRP Irp);
1030
1031 VOID
1032 NTAPI
1033 USBPORT_FlushAbortList(
1034 IN PUSBPORT_ENDPOINT Endpoint);
1035
1036 VOID
1037 NTAPI
1038 USBPORT_FlushCancelList(
1039 IN PUSBPORT_ENDPOINT Endpoint);
1040
1041 VOID
1042 NTAPI
1043 USBPORT_QueueTransferUrb(
1044 IN PURB Urb);
1045
1046 VOID
1047 NTAPI
1048 USBPORT_FlushAllEndpoints(
1049 IN PDEVICE_OBJECT FdoDevice);
1050
1051 VOID
1052 NTAPI
1053 USBPORT_FlushPendingTransfers(
1054 IN PUSBPORT_ENDPOINT Endpoint);
1055
1056 BOOLEAN
1057 NTAPI
1058 USBPORT_QueueActiveUrbToEndpoint(
1059 IN PUSBPORT_ENDPOINT Endpoint,
1060 IN PURB Urb);
1061
1062 VOID
1063 NTAPI
1064 USBPORT_FlushController(
1065 IN PDEVICE_OBJECT FdoDevice);
1066
1067 VOID
1068 NTAPI
1069 USBPORT_BadRequestFlush(
1070 IN PDEVICE_OBJECT FdoDevice);
1071
1072 VOID
1073 NTAPI
1074 USBPORT_AbortEndpoint(
1075 IN PDEVICE_OBJECT FdoDevice,
1076 IN PUSBPORT_ENDPOINT Endpoint,
1077 IN PIRP Irp);
1078
1079 /* roothub.c */
1080 VOID
1081 NTAPI
1082 USBPORT_RootHubEndpointWorker(
1083 PUSBPORT_ENDPOINT Endpoint);
1084
1085 NTSTATUS
1086 NTAPI
1087 USBPORT_RootHubCreateDevice(
1088 IN PDEVICE_OBJECT FdoDevice,
1089 IN PDEVICE_OBJECT PdoDevice);
1090
1091 ULONG
1092 NTAPI
1093 USBPORT_InvalidateRootHub(
1094 PVOID MiniPortExtension);
1095
1096 VOID
1097 NTAPI
1098 USBPORT_RootHubPowerAndChirpAllCcPorts(
1099 IN PDEVICE_OBJECT FdoDevice);
1100
1101 /* urb.c */
1102 NTSTATUS
1103 NTAPI
1104 USBPORT_HandleSubmitURB(
1105 IN PDEVICE_OBJECT PdoDevice,
1106 IN PIRP Irp,
1107 IN PURB Urb);
1108
1109 /* usb2.c */
1110 BOOLEAN
1111 NTAPI
1112 USBPORT_AllocateBandwidthUSB2(
1113 IN PDEVICE_OBJECT FdoDevice,
1114 IN PUSBPORT_ENDPOINT Endpoint);
1115
1116 VOID
1117 NTAPI
1118 USBPORT_FreeBandwidthUSB2(
1119 IN PDEVICE_OBJECT FdoDevice,
1120 IN PUSBPORT_ENDPOINT Endpoint);
1121
1122 #endif /* USBPORT_H__ */