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