ReactOS 0.4.16-dev-2284-g3529151
usbport.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS USB Port Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: USBPort main driver functions
5 * COPYRIGHT: Copyright 2017 Vadim Galyant <vgal@rambler.ru>
6 */
7
8#include "usbport.h"
9
10#define NDEBUG
11#include <debug.h>
12
13#define NDEBUG_USBPORT_CORE
14#define NDEBUG_USBPORT_INTERRUPT
15#define NDEBUG_USBPORT_TIMER
16#include "usbdebug.h"
17
21
24
28{
30 PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
32 PLIST_ENTRY USB2FdoEntry;
33 PDEVICE_OBJECT USB2FdoDevice = NULL;
34
35 DPRINT("USBPORT_FindUSB2Controller: FdoDevice - %p\n", FdoDevice);
36
37 FdoExtension = FdoDevice->DeviceExtension;
38
40
41 USB2FdoEntry = USBPORT_USB2FdoList.Flink;
42
43 while (USB2FdoEntry && USB2FdoEntry != &USBPORT_USB2FdoList)
44 {
45 USB2FdoExtension = CONTAINING_RECORD(USB2FdoEntry,
47 ControllerLink);
48
49 if (USB2FdoExtension->BusNumber == FdoExtension->BusNumber &&
50 USB2FdoExtension->PciDeviceNumber == FdoExtension->PciDeviceNumber)
51 {
52 USB2FdoDevice = USB2FdoExtension->CommonExtension.SelfDevice;
53 break;
54 }
55
56 USB2FdoEntry = USB2FdoEntry->Flink;
57 }
58
60
61 return USB2FdoDevice;
62}
63
64VOID
67{
69
70 DPRINT("USBPORT_AddUSB1Fdo: FdoDevice - %p\n", FdoDevice);
71
72 FdoExtension = FdoDevice->DeviceExtension;
74
76 &FdoExtension->ControllerLink,
78}
79
80VOID
83{
85
86 DPRINT("USBPORT_AddUSB2Fdo: FdoDevice - %p\n", FdoDevice);
87
88 FdoExtension = FdoDevice->DeviceExtension;
90
92 &FdoExtension->ControllerLink,
94}
95
96VOID
99{
102
103 DPRINT("USBPORT_RemoveUSBxFdo: FdoDevice - %p\n", FdoDevice);
104
105 FdoExtension = FdoDevice->DeviceExtension;
106
108 RemoveEntryList(&FdoExtension->ControllerLink);
110
111 FdoExtension->Flags &= ~USBPORT_FLAG_REGISTERED_FDO;
112
113 FdoExtension->ControllerLink.Flink = NULL;
114 FdoExtension->ControllerLink.Blink = NULL;
115}
116
118NTAPI
120 IN PUSBPORT_DEVICE_EXTENSION USB1FdoExtension)
121{
122 PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
123
124 DPRINT("USBPORT_IsCompanionFdoExtension: USB2Fdo - %p, USB1FdoExtension - %p\n",
125 USB2FdoDevice,
126 USB1FdoExtension);
127
128 USB2FdoExtension = USB2FdoDevice->DeviceExtension;
129
130 return USB2FdoExtension->BusNumber == USB1FdoExtension->BusNumber &&
131 USB2FdoExtension->PciDeviceNumber == USB1FdoExtension->PciDeviceNumber;
132}
133
135NTAPI
137 IN BOOLEAN IsObRefer,
138 IN BOOLEAN IsFDOsReturned)
139{
140 PLIST_ENTRY USB1FdoList;
141 PUSBPORT_DEVICE_EXTENSION USB1FdoExtension;
142 ULONG NumControllers = 0;
144 PDEVICE_RELATIONS ControllersList = NULL;
146
147 DPRINT("USBPORT_FindCompanionControllers: USB2Fdo - %p, IsObRefer - %x, IsFDOs - %x\n",
148 USB2FdoDevice,
149 IsObRefer,
150 IsFDOsReturned);
151
153
154 USB1FdoList = USBPORT_USB1FdoList.Flink;
155
156 while (USB1FdoList && USB1FdoList != &USBPORT_USB1FdoList)
157 {
158 USB1FdoExtension = CONTAINING_RECORD(USB1FdoList,
160 ControllerLink);
161
162 if (USB1FdoExtension->Flags & USBPORT_FLAG_COMPANION_HC &&
163 USBPORT_IsCompanionFdoExtension(USB2FdoDevice, USB1FdoExtension))
164 {
165 ++NumControllers;
166 }
167
168 USB1FdoList = USB1FdoExtension->ControllerLink.Flink;
169 }
170
171 DPRINT("USBPORT_FindCompanionControllers: NumControllers - %x\n",
172 NumControllers);
173
174 if (!NumControllers)
175 {
176 goto Exit;
177 }
178
179 ControllersList = ExAllocatePoolWithTag(NonPagedPool,
180 NumControllers * sizeof(DEVICE_RELATIONS),
182
183 if (!ControllersList)
184 {
185 goto Exit;
186 }
187
188 RtlZeroMemory(ControllersList, NumControllers * sizeof(DEVICE_RELATIONS));
189
190 ControllersList->Count = NumControllers;
191
192 USB1FdoList = USBPORT_USB1FdoList.Flink;
193
194 Entry = &ControllersList->Objects[0];
195
196 while (USB1FdoList && USB1FdoList != &USBPORT_USB1FdoList)
197 {
198 USB1FdoExtension = CONTAINING_RECORD(USB1FdoList,
200 ControllerLink);
201
202 if (USB1FdoExtension->Flags & USBPORT_FLAG_COMPANION_HC &&
203 USBPORT_IsCompanionFdoExtension(USB2FdoDevice, USB1FdoExtension))
204 {
205 *Entry = USB1FdoExtension->CommonExtension.LowerPdoDevice;
206
207 if (IsObRefer)
208 {
210 }
211
212 if (IsFDOsReturned)
213 {
214 *Entry = USB1FdoExtension->CommonExtension.SelfDevice;
215 }
216
217 ++Entry;
218 }
219
220 USB1FdoList = USB1FdoExtension->ControllerLink.Flink;
221 }
222
223Exit:
224
226
227 return ControllersList;
228}
229
231NTAPI
233{
234 DPRINT("USBPORT_NtStatusToMpStatus: NtStatus - %x\n", NtStatus);
235
236 if (NtStatus == STATUS_SUCCESS)
237 {
238 return MP_STATUS_SUCCESS;
239 }
240 else
241 {
243 }
244}
245
247NTAPI
249 IN BOOL UseDriverKey,
250 IN ULONG Type,
251 IN PCWSTR ValueNameString,
252 IN PVOID Data,
254{
258
259 DPRINT("USBPORT_SetRegistryKeyValue: ValueNameString - %S\n",
260 ValueNameString);
261
262 if (UseDriverKey)
263 {
267 &KeyHandle);
268 }
269 else
270 {
274 &KeyHandle);
275 }
276
277 if (NT_SUCCESS(Status))
278 {
279 RtlInitUnicodeString(&ValueName, ValueNameString);
280
281 Status = ZwSetValueKey(KeyHandle,
282 &ValueName,
283 0,
284 Type,
285 Data,
286 DataSize);
287
289 }
290
291 return Status;
292}
293
295NTAPI
297 IN PDEVICE_OBJECT PdoDevice,
298 IN BOOL UseDriverKey,
300 IN ULONG LengthStr,
303{
308 ULONG LengthKey;
309
310 DPRINT("USBPORT_GetRegistryKeyValue: UseDriverKey - %x, SourceString - %S, LengthStr - %x, Buffer - %p, BufferLength - %x\n",
311 UseDriverKey,
313 LengthStr,
314 Buffer,
316
317 if (UseDriverKey)
318 {
322 &KeyHandle);
323 }
324 else
325 {
329 &KeyHandle);
330 }
331
332 if (NT_SUCCESS(Status))
333 {
335
336 LengthKey = sizeof(KEY_VALUE_FULL_INFORMATION) +
337 LengthStr +
339
341 LengthKey,
343
344 if (KeyValue)
345 {
346 RtlZeroMemory(KeyValue, LengthKey);
347
348 Status = ZwQueryValueKey(KeyHandle,
349 &ValueName,
351 KeyValue,
352 LengthKey,
353 &LengthKey);
354
355 if (NT_SUCCESS(Status))
356 {
358 (PUCHAR)KeyValue + KeyValue->DataOffset,
360 }
361
363 }
364
366 }
367
368 return Status;
369}
370
372NTAPI
374 IN BOOL UseDriverKey,
376 IN SIZE_T LengthStr,
379{
381 PDEVICE_OBJECT FdoDevice;
383
384 DPRINT("USBPORT_GetMiniportRegistryKeyValue: MiniPortExtension - %p, UseDriverKey - %x, SourceString - %S, LengthStr - %x, Buffer - %p, BufferLength - %x\n",
385 MiniPortExtension,
386 UseDriverKey,
388 LengthStr,
389 Buffer,
391
392 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
394
395 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
396
398 FdoExtension->CommonExtension.LowerPdoDevice,
399 UseDriverKey,
401 LengthStr,
402 Buffer,
404
406}
407
409NTAPI
411 IN BOOLEAN IsReadData,
415{
417 ULONG BytesReadWrite;
418
419 DPRINT("USBPORT_GetSetConfigSpaceData ...\n");
420
421 FdoExtension = FdoDevice->DeviceExtension;
422
423 BytesReadWrite = Length;
424
425 if (IsReadData)
426 {
428
429 BytesReadWrite = (*FdoExtension->BusInterface.GetBusData)
430 (FdoExtension->BusInterface.Context,
432 Buffer,
433 Offset,
434 Length);
435 }
436 else
437 {
438 BytesReadWrite = (*FdoExtension->BusInterface.SetBusData)
439 (FdoExtension->BusInterface.Context,
441 Buffer,
442 Offset,
443 Length);
444 }
445
446 if (BytesReadWrite == Length)
447 {
448 return STATUS_SUCCESS;
449 }
450
451 return STATUS_UNSUCCESSFUL;
452}
453
455NTAPI
457 IN BOOLEAN IsReadData,
461{
464 PDEVICE_OBJECT FdoDevice;
465
466 DPRINT("USBPORT_ReadWriteConfigSpace: ...\n");
467
468 //FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension + sizeof(USBPORT_DEVICE_EXTENSION));
469 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
471
472 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
473
475 IsReadData,
476 Buffer,
477 Offset,
478 Length);
479
481}
482
484NTAPI
486 IN USBD_STATUS USBDStatus)
487{
489
490 if (USBD_ERROR(USBDStatus))
491 {
492 DPRINT1("USBPORT_USBDStatusToNtStatus: Urb - %p, USBDStatus - %x\n",
493 Urb,
494 USBDStatus);
495 }
496
497 if (Urb)
498 Urb->UrbHeader.Status = USBDStatus;
499
500 switch (USBDStatus)
501 {
504 break;
505
508 break;
509
512 break;
513
516 break;
517
520 break;
521
527 break;
528
529 default:
530 if (USBD_ERROR(USBDStatus))
532 else
534
535 break;
536 }
537
538 return Status;
539}
540
542NTAPI
543USBPORT_Wait(IN PVOID MiniPortExtension,
544 IN ULONG Milliseconds)
545{
546 LARGE_INTEGER Interval = {{0, 0}};
547
548 DPRINT("USBPORT_Wait: Milliseconds - %x\n", Milliseconds);
549 Interval.QuadPart -= 10000 * Milliseconds + (KeQueryTimeIncrement() - 1);
551}
552
553VOID
554NTAPI
556 IN BOOLEAN IsEnable)
557{
560 BOOLEAN IsLock;
562
563 DPRINT_INT("USBPORT_MiniportInterrupts: IsEnable - %p\n", IsEnable);
564
565 FdoExtension = FdoDevice->DeviceExtension;
566 Packet = &FdoExtension->MiniPortInterface->Packet;
567
568 IsLock = (Packet->MiniPortFlags & USB_MINIPORT_FLAGS_NOT_LOCK_INT) == 0;
569
570 if (IsLock)
571 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
572
573 if (IsEnable)
574 {
576 Packet->EnableInterrupts(FdoExtension->MiniPortExt);
577 }
578 else
579 {
580 Packet->DisableInterrupts(FdoExtension->MiniPortExt);
581 FdoExtension->Flags &= ~USBPORT_FLAG_INTERRUPT_ENABLED;
582 }
583
584 if (IsLock)
585 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
586}
587
588VOID
589NTAPI
594{
595 PDEVICE_OBJECT FdoDevice;
597
598 DPRINT_INT("USBPORT_SoftInterruptDpc: ...\n");
599
600 FdoDevice = DeferredContext;
601 FdoExtension = FdoDevice->DeviceExtension;
602
603 if (!KeInsertQueueDpc(&FdoExtension->IsrDpc, NULL, (PVOID)1))
604 {
605 InterlockedDecrement(&FdoExtension->IsrDpcCounter);
606 }
607}
608
609VOID
610NTAPI
612{
614 LARGE_INTEGER DueTime = {{0, 0}};
615
616 DPRINT_INT("USBPORT_SoftInterrupt: ...\n");
617
618 FdoExtension = FdoDevice->DeviceExtension;
619
620 KeInitializeTimer(&FdoExtension->TimerSoftInterrupt);
621
622 KeInitializeDpc(&FdoExtension->SoftInterruptDpc,
624 FdoDevice);
625
626 DueTime.QuadPart -= 10000 + (KeQueryTimeIncrement() - 1);
627
628 KeSetTimer(&FdoExtension->TimerSoftInterrupt,
629 DueTime,
630 &FdoExtension->SoftInterruptDpc);
631}
632
633VOID
634NTAPI
636 IN ULONG Type)
637{
639
640 DPRINT_CORE("USBPORT_InvalidateControllerHandler: Invalidate Type - %x\n",
641 Type);
642
643 FdoExtension = FdoDevice->DeviceExtension;
644
645 switch (Type)
646 {
648 DPRINT1("USBPORT_InvalidateControllerHandler: INVALIDATE_CONTROLLER_RESET UNIMPLEMENTED. FIXME.\n");
649 break;
650
652 DPRINT1("USBPORT_InvalidateControllerHandler: INVALIDATE_CONTROLLER_SURPRISE_REMOVE UNIMPLEMENTED. FIXME.\n");
653 break;
654
656 if (InterlockedIncrement(&FdoExtension->IsrDpcCounter))
657 {
658 InterlockedDecrement(&FdoExtension->IsrDpcCounter);
659 }
660 else
661 {
662 USBPORT_SoftInterrupt(FdoDevice);
663 }
664 break;
665 }
666}
667
668ULONG
669NTAPI
671 IN ULONG Type)
672{
674 PDEVICE_OBJECT FdoDevice;
675
676 DPRINT("USBPORT_InvalidateController: Invalidate Type - %x\n", Type);
677
678 //FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension + sizeof(USBPORT_DEVICE_EXTENSION));
679 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
681 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
682
684
685 return 0;
686}
687
688ULONG
689NTAPI
691 IN PVOID MiniPortTransfer,
694{
695 DPRINT1("USBPORT_NotifyDoubleBuffer: UNIMPLEMENTED. FIXME.\n");
696 return 0;
697}
698
699VOID
700NTAPI
705{
706 PDEVICE_OBJECT FdoDevice;
708
709 DPRINT("USBPORT_WorkerRequestDpc: ...\n");
710
711 FdoDevice = DeferredContext;
712 FdoExtension = FdoDevice->DeviceExtension;
713
714 if (!InterlockedIncrement(&FdoExtension->IsrDpcHandlerCounter))
715 {
716 USBPORT_DpcHandler(FdoDevice);
717 }
718
719 InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
720}
721
722VOID
723NTAPI
725{
726 PUSBPORT_ENDPOINT Endpoint;
727 PDEVICE_OBJECT FdoDevice;
729 PURB Urb;
730 PIRP Irp;
731 KIRQL CancelIrql;
733
734 DPRINT_CORE("USBPORT_DoneTransfer: Transfer - %p\n", Transfer);
735
736 Endpoint = Transfer->Endpoint;
737 FdoDevice = Endpoint->FdoDevice;
738 FdoExtension = FdoDevice->DeviceExtension;
739
740 Urb = Transfer->Urb;
741 Irp = Transfer->Irp;
742
743 KeAcquireSpinLock(&FdoExtension->FlushTransferSpinLock, &OldIrql);
744
745 if (Irp)
746 {
747 IoAcquireCancelSpinLock(&CancelIrql);
749 IoReleaseCancelSpinLock(CancelIrql);
750
752 }
753
754 KeReleaseSpinLock(&FdoExtension->FlushTransferSpinLock, OldIrql);
755
756 USBPORT_USBDStatusToNtStatus(Transfer->Urb, Transfer->USBDStatus);
757 USBPORT_CompleteTransfer(Urb, Urb->UrbHeader.Status);
758
759 DPRINT_CORE("USBPORT_DoneTransfer: exit\n");
760}
761
762VOID
763NTAPI
765{
767 PLIST_ENTRY DoneTransferList;
768 PUSBPORT_TRANSFER Transfer;
769 PUSBPORT_ENDPOINT Endpoint;
770 ULONG TransferCount;
772 BOOLEAN IsHasTransfers;
773
774 DPRINT_CORE("USBPORT_FlushDoneTransfers: ...\n");
775
776 FdoExtension = FdoDevice->DeviceExtension;
777 DoneTransferList = &FdoExtension->DoneTransferList;
778
779 while (TRUE)
780 {
781 KeAcquireSpinLock(&FdoExtension->DoneTransferSpinLock, &OldIrql);
782
783 if (IsListEmpty(DoneTransferList))
784 break;
785
786 Transfer = CONTAINING_RECORD(DoneTransferList->Flink,
788 TransferLink);
789
790 RemoveHeadList(DoneTransferList);
791 KeReleaseSpinLock(&FdoExtension->DoneTransferSpinLock, OldIrql);
792
793 if (Transfer)
794 {
795 Endpoint = Transfer->Endpoint;
796
797 if ((Transfer->Flags & TRANSFER_FLAG_SPLITED))
798 {
800 }
801 else
802 {
803 USBPORT_DoneTransfer(Transfer);
804 }
805
806 IsHasTransfers = USBPORT_EndpointHasQueuedTransfers(FdoDevice,
807 Endpoint,
808 &TransferCount);
809
810 if (IsHasTransfers && !TransferCount)
811 {
813 Endpoint,
815 }
816 }
817 }
818
819 KeReleaseSpinLock(&FdoExtension->DoneTransferSpinLock, OldIrql);
820}
821
822
823VOID
824NTAPI
829{
830 PDEVICE_OBJECT FdoDevice;
831
832 DPRINT_CORE("USBPORT_TransferFlushDpc: ...\n");
833 FdoDevice = DeferredContext;
835}
836
838NTAPI
840 IN USBD_STATUS USBDStatus)
841{
842 PDEVICE_OBJECT FdoDevice;
844
845 DPRINT_CORE("USBPORT_QueueDoneTransfer: Transfer - %p, USBDStatus - %p\n",
846 Transfer,
847 USBDStatus);
848
849 FdoDevice = Transfer->Endpoint->FdoDevice;
850 FdoExtension = FdoDevice->DeviceExtension;
851
852 RemoveEntryList(&Transfer->TransferLink);
853 Transfer->USBDStatus = USBDStatus;
854
855 ExInterlockedInsertTailList(&FdoExtension->DoneTransferList,
856 &Transfer->TransferLink,
857 &FdoExtension->DoneTransferSpinLock);
858
859 return KeInsertQueueDpc(&FdoExtension->TransferFlushDpc, NULL, NULL);
860}
861
862VOID
863NTAPI
865{
867 PUSBPORT_ENDPOINT Endpoint;
870 LONG LockCounter;
871
872 DPRINT_CORE("USBPORT_DpcHandler: ...\n");
873
874 FdoExtension = FdoDevice->DeviceExtension;
875
877
878 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
879 Entry = FdoExtension->EndpointList.Flink;
880
881 while (Entry && Entry != &FdoExtension->EndpointList)
882 {
883 Endpoint = CONTAINING_RECORD(Entry,
885 EndpointLink);
886
887 LockCounter = InterlockedIncrement(&Endpoint->LockCounter);
888
890 LockCounter ||
892 {
894 }
895 else
896 {
897 InsertTailList(&List, &Endpoint->DispatchLink);
898
899 if (Endpoint->WorkerLink.Flink && Endpoint->WorkerLink.Blink)
900 {
901 RemoveEntryList(&Endpoint->WorkerLink);
902
903 Endpoint->WorkerLink.Flink = NULL;
904 Endpoint->WorkerLink.Blink = NULL;
905 }
906 }
907
908 Entry = Endpoint->EndpointLink.Flink;
909 }
910
911 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
912
913 while (!IsListEmpty(&List))
914 {
915 Endpoint = CONTAINING_RECORD(List.Flink,
917 DispatchLink);
918
919 RemoveEntryList(List.Flink);
920 Endpoint->DispatchLink.Flink = NULL;
921 Endpoint->DispatchLink.Blink = NULL;
922
923 USBPORT_EndpointWorker(Endpoint, TRUE);
925 }
926
927 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
928
929 if (!IsListEmpty(&FdoExtension->WorkerList))
930 {
932 }
933
934 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
935
937}
938
939VOID
940NTAPI
942 IN BOOLEAN IsDpcHandler)
943{
946 PUSBPORT_ENDPOINT Endpoint;
948 ULONG FrameNumber;
949
951
952 DPRINT_CORE("USBPORT_IsrDpcHandler: IsDpcHandler - %x\n", IsDpcHandler);
953
954 FdoExtension = FdoDevice->DeviceExtension;
955 Packet = &FdoExtension->MiniPortInterface->Packet;
956
957 if (InterlockedIncrement(&FdoExtension->IsrDpcHandlerCounter))
958 {
960 InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
961 return;
962 }
963
964 /* Process the state change list.
965 * - Always process the list (don't flush during suspend)
966 * - If controller is suspended/off, mark endpoints as ready immediately
967 * - Don't request interrupts if suspended */
968 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EpStateChangeSpinLock);
969 List = FdoExtension->EpStateChangeList.Flink;
970 while (List != &FdoExtension->EpStateChangeList)
971 {
972 BOOLEAN EndpointReady = FALSE;
973 PLIST_ENTRY NextList;
974 BOOLEAN ControllerSuspended;
975
976 Endpoint = CONTAINING_RECORD(List,
978 StateChangeLink);
979
980 DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint - %p\n", Endpoint);
981
982 /* Save the next entry before we potentially remove this one */
983 NextList = List->Flink;
984
985 /* Check if controller is suspended/off */
986 ControllerSuspended = (FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND) != 0 ||
987 (FdoExtension->CommonExtension.DevicePowerState == PowerDeviceD3);
988
989 if (ControllerSuspended)
990 {
991 /* Controller is suspended/off - mark endpoint as ready immediately */
992 EndpointReady = TRUE;
993 }
994 else
995 {
996 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
997 FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
999
1000 /* Check if the endpoint is ready to be processed */
1001 if (FrameNumber > Endpoint->FrameNumber ||
1002 (Endpoint->Flags & ENDPOINT_FLAG_NUKE))
1003 {
1004 EndpointReady = TRUE;
1005 }
1006 }
1007
1008
1009 if (EndpointReady)
1010 {
1011 /* Endpoint is ready - remove it from the list and process it */
1012 RemoveEntryList(&Endpoint->StateChangeLink);
1013 Endpoint->StateChangeLink.Flink = NULL;
1014 Endpoint->StateChangeLink.Blink = NULL;
1015
1017 Endpoint->StateLast = Endpoint->StateNext;
1019
1020 DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint->StateLast - %x\n",
1021 Endpoint->StateLast);
1022
1023 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EpStateChangeSpinLock);
1024
1025 if (IsDpcHandler)
1026 {
1028 Endpoint,
1030 }
1031 else
1032 {
1034 Endpoint,
1036 }
1037
1038 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EpStateChangeSpinLock);
1039 }
1040 else if (!ControllerSuspended)
1041 {
1042 /* Endpoint is not ready yet - leave it in the list and request interrupt.
1043 * Don't request interrupts if controller is suspended. */
1044 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
1045 Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
1046 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
1047 }
1048 /* If suspended and not ready, leave it in list but don't request interrupt */
1049
1050 /* Move to the next entry */
1051 List = NextList;
1052 }
1053
1054 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EpStateChangeSpinLock);
1055
1056 if (IsDpcHandler)
1057 {
1058 USBPORT_DpcHandler(FdoDevice);
1059 }
1060
1061 InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
1062}
1063
1064VOID
1065NTAPI
1070{
1071 PDEVICE_OBJECT FdoDevice;
1074 BOOLEAN InterruptEnable;
1075
1076 DPRINT_INT("USBPORT_IsrDpc: DeferredContext - %p, SystemArgument2 - %p\n",
1079
1080 FdoDevice = DeferredContext;
1081 FdoExtension = FdoDevice->DeviceExtension;
1082 Packet = &FdoExtension->MiniPortInterface->Packet;
1083
1084 if (SystemArgument2)
1085 {
1086 InterlockedDecrement(&FdoExtension->IsrDpcCounter);
1087 }
1088
1089 KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1090 InterruptEnable = (FdoExtension->Flags & USBPORT_FLAG_INTERRUPT_ENABLED) ==
1092
1093 Packet->InterruptDpc(FdoExtension->MiniPortExt, InterruptEnable);
1094
1095 KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1096
1098 FdoExtension->TimerFlags & USBPORT_TMFLAG_WAKE)
1099 {
1100 USBPORT_CompletePdoWaitWake(FdoDevice);
1101 }
1102 else
1103 {
1104 USBPORT_IsrDpcHandler(FdoDevice, TRUE);
1105 }
1106
1107 DPRINT_INT("USBPORT_IsrDpc: exit\n");
1108}
1109
1110BOOLEAN
1111NTAPI
1114{
1115 PDEVICE_OBJECT FdoDevice;
1119
1120 FdoDevice = ServiceContext;
1121 FdoExtension = FdoDevice->DeviceExtension;
1122 Packet = &FdoExtension->MiniPortInterface->Packet;
1123
1124 DPRINT_INT("USBPORT_InterruptService: FdoExtension[%p]->Flags - %08X\n",
1126 FdoExtension->Flags);
1127
1130 {
1131 Result = Packet->InterruptService(FdoExtension->MiniPortExt);
1132
1133 if (Result)
1134 {
1136 }
1137 }
1138
1139 DPRINT_INT("USBPORT_InterruptService: return - %x\n", Result);
1140
1141 return Result;
1142}
1143
1144VOID
1145NTAPI
1147{
1149 KIRQL OldIrql;
1150
1151 DPRINT_CORE("USBPORT_SignalWorkerThread ...\n");
1152
1153 FdoExtension = FdoDevice->DeviceExtension;
1154
1155 KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1156 KeSetEvent(&FdoExtension->WorkerThreadEvent, EVENT_INCREMENT, FALSE);
1157 KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1158}
1159
1160VOID
1161NTAPI
1163{
1166 PLIST_ENTRY workerList;
1167 KIRQL OldIrql;
1168 PUSBPORT_ENDPOINT Endpoint;
1171
1172 DPRINT_CORE("USBPORT_WorkerThreadHandler: ...\n");
1173
1174 FdoExtension = FdoDevice->DeviceExtension;
1175 Packet = &FdoExtension->MiniPortInterface->Packet;
1176
1177 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1178
1179 if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
1180 {
1181 Packet->CheckController(FdoExtension->MiniPortExt);
1182 }
1183
1184 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1185
1187
1188 USBPORT_FlushAllEndpoints(FdoDevice);
1189
1190 while (TRUE)
1191 {
1193 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1194
1195 workerList = &FdoExtension->WorkerList;
1196
1197 if (IsListEmpty(workerList))
1198 break;
1199
1200 Endpoint = CONTAINING_RECORD(workerList->Flink,
1202 WorkerLink);
1203
1204 DPRINT_CORE("USBPORT_WorkerThreadHandler: Endpoint - %p\n", Endpoint);
1205
1206 RemoveHeadList(workerList);
1207 Endpoint->WorkerLink.Blink = NULL;
1208 Endpoint->WorkerLink.Flink = NULL;
1209
1210 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1211
1212 Result = USBPORT_EndpointWorker(Endpoint, FALSE);
1213 KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1214
1215 if (Result)
1216 {
1217 if (Endpoint->FlushAbortLink.Flink == NULL ||
1218 Endpoint->FlushAbortLink.Blink == NULL)
1219 {
1220 InsertTailList(&list, &Endpoint->FlushAbortLink);
1221 }
1222 }
1223
1224 while (!IsListEmpty(&list))
1225 {
1226 Endpoint = CONTAINING_RECORD(list.Flink,
1228 FlushAbortLink);
1229
1231
1232 Endpoint->FlushAbortLink.Flink = NULL;
1233 Endpoint->FlushAbortLink.Blink = NULL;
1234
1235 if (Endpoint->WorkerLink.Flink == NULL ||
1236 Endpoint->WorkerLink.Blink == NULL)
1237 {
1238 InsertTailList(&FdoExtension->WorkerList,
1239 &Endpoint->WorkerLink);
1240
1241 USBPORT_SignalWorkerThread(FdoDevice);
1242 }
1243 }
1244
1245 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1247 }
1248
1249 KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1251
1253}
1254
1255VOID
1256NTAPI
1258{
1260 PDEVICE_OBJECT PdoDevice;
1262 PRH_INIT_CALLBACK RootHubInitCallback;
1263 PVOID RootHubInitContext;
1264
1265 FdoExtension = FdoDevice->DeviceExtension;
1266
1267 DPRINT("USBPORT_DoRootHubCallback: FdoDevice - %p\n", FdoDevice);
1268
1269 PdoDevice = FdoExtension->RootHubPdo;
1270
1271 if (PdoDevice)
1272 {
1273 PdoExtension = PdoDevice->DeviceExtension;
1274
1275 RootHubInitContext = PdoExtension->RootHubInitContext;
1276 RootHubInitCallback = PdoExtension->RootHubInitCallback;
1277
1278 PdoExtension->RootHubInitCallback = NULL;
1279 PdoExtension->RootHubInitContext = NULL;
1280
1281 if (RootHubInitCallback)
1282 {
1283 RootHubInitCallback(RootHubInitContext);
1284 }
1285 }
1286
1287 DPRINT("USBPORT_DoRootHubCallback: exit\n");
1288}
1289
1290VOID
1291NTAPI
1293 IN PDEVICE_OBJECT Usb2FdoDevice)
1294{
1297 PUSBPORT_DEVICE_EXTENSION Usb2FdoExtension;
1298 PDEVICE_RELATIONS CompanionControllersList;
1299 PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension;
1301 ULONG ix;
1302
1303 DPRINT("USBPORT_SynchronizeRootHubCallback: FdoDevice - %p, Usb2FdoDevice - %p\n",
1304 FdoDevice,
1305 Usb2FdoDevice);
1306
1307 FdoExtension = FdoDevice->DeviceExtension;
1308 Packet = &FdoExtension->MiniPortInterface->Packet;
1309
1310 if (Usb2FdoDevice == NULL &&
1311 !(Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2))
1312 {
1313 /* Not Companion USB11 Controller */
1314 USBPORT_DoRootHubCallback(FdoDevice);
1315
1316 FdoExtension->Flags &= ~USBPORT_FLAG_RH_INIT_CALLBACK;
1317 InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1318
1319 DPRINT("USBPORT_SynchronizeRootHubCallback: exit\n");
1320 return;
1321 }
1322
1323 /* USB2 or Companion USB11 */
1324
1325 DPRINT("USBPORT_SynchronizeRootHubCallback: FdoExtension->Flags - %p\n",
1326 FdoExtension->Flags);
1327
1329 {
1330 KeWaitForSingleObject(&FdoExtension->ControllerSemaphore,
1331 Executive,
1332 KernelMode,
1333 FALSE,
1334 NULL);
1335
1337
1338 if (!(FdoExtension->Flags & (USBPORT_FLAG_HC_SUSPEND |
1340 {
1343 }
1344
1345 FdoExtension->Flags &= ~USBPORT_FLAG_PWR_AND_CHIRP_LOCK;
1346
1347 KeReleaseSemaphore(&FdoExtension->ControllerSemaphore,
1349 1,
1350 FALSE);
1351
1352 CompanionControllersList = USBPORT_FindCompanionControllers(FdoDevice,
1353 FALSE,
1354 TRUE);
1355
1356 if (CompanionControllersList)
1357 {
1358 Entry = &CompanionControllersList->Objects[0];
1359
1360 for (ix = 0; ix < CompanionControllersList->Count; ++ix)
1361 {
1362 CompanionFdoExtension = ((*Entry)->DeviceExtension);
1363
1364 InterlockedCompareExchange(&CompanionFdoExtension->RHInitCallBackLock,
1365 0,
1366 1);
1367
1368 ++Entry;
1369 }
1370
1371 ExFreePoolWithTag(CompanionControllersList, USB_PORT_TAG);
1372 }
1373
1374 USBPORT_DoRootHubCallback(FdoDevice);
1375
1376 FdoExtension->Flags &= ~USBPORT_FLAG_RH_INIT_CALLBACK;
1377 InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1378 }
1379 else
1380 {
1381 Usb2FdoExtension = Usb2FdoDevice->DeviceExtension;
1382
1383 USBPORT_Wait(FdoDevice, 50);
1384
1385 while (FdoExtension->RHInitCallBackLock)
1386 {
1387 USBPORT_Wait(FdoDevice, 10);
1388
1389 Usb2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1390 USBPORT_SignalWorkerThread(Usb2FdoDevice);
1391 }
1392
1393 USBPORT_DoRootHubCallback(FdoDevice);
1394
1395 FdoExtension->Flags &= ~USBPORT_FLAG_RH_INIT_CALLBACK;
1396 }
1397
1398 DPRINT("USBPORT_SynchronizeRootHubCallback: exit\n");
1399}
1400
1401VOID
1402NTAPI
1404{
1405 PDEVICE_OBJECT FdoDevice;
1407 LARGE_INTEGER OldTime;
1408 LARGE_INTEGER NewTime;
1409 KIRQL OldIrql;
1410
1411 DPRINT_CORE("USBPORT_WorkerThread ...\n");
1412
1413 FdoDevice = StartContext;
1414 FdoExtension = FdoDevice->DeviceExtension;
1415
1416 FdoExtension->WorkerThread = KeGetCurrentThread();
1417
1418 do
1419 {
1420 KeQuerySystemTime(&OldTime);
1421
1422 KeWaitForSingleObject(&FdoExtension->WorkerThreadEvent,
1423 Suspended,
1424 KernelMode,
1425 FALSE,
1426 NULL);
1427
1429 {
1430 break;
1431 }
1432
1433 KeQuerySystemTime(&NewTime);
1434
1435 KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1436 KeClearEvent(&FdoExtension->WorkerThreadEvent);
1437 KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1438 DPRINT_CORE("USBPORT_WorkerThread: run\n");
1439
1441 {
1442 USBPORT_DoSetPowerD0(FdoDevice);
1443
1445 {
1446 PDEVICE_OBJECT USB2FdoDevice = NULL;
1447
1448 USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1449 USBPORT_SynchronizeRootHubCallback(FdoDevice, USB2FdoDevice);
1450 }
1451 }
1452
1453 USBPORT_WorkerThreadHandler(FdoDevice);
1454 }
1455 while (!(FdoExtension->Flags & USBPORT_FLAG_WORKER_THREAD_ON));
1456
1458}
1459
1461NTAPI
1463{
1466
1467 DPRINT("USBPORT_CreateWorkerThread ...\n");
1468
1469 FdoExtension = FdoDevice->DeviceExtension;
1470
1471 FdoExtension->Flags &= ~USBPORT_FLAG_WORKER_THREAD_ON;
1472
1473 KeInitializeEvent(&FdoExtension->WorkerThreadEvent,
1475 FALSE);
1476
1477 Status = PsCreateSystemThread(&FdoExtension->WorkerThreadHandle,
1479 NULL,
1480 NULL,
1481 NULL,
1483 (PVOID)FdoDevice);
1484
1485 return Status;
1486}
1487
1488VOID
1489NTAPI
1491{
1494
1495 DPRINT("USBPORT_StopWorkerThread ...\n");
1496
1497 FdoExtension = FdoDevice->DeviceExtension;
1498
1500 USBPORT_SignalWorkerThread(FdoDevice);
1501 Status = ZwWaitForSingleObject(FdoExtension->WorkerThreadHandle, FALSE, NULL);
1503}
1504
1505VOID
1506NTAPI
1508{
1510 PDEVICE_OBJECT PdoDevice;
1512 PDEVICE_OBJECT USB2FdoDevice = NULL;
1513 PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
1514 BOOLEAN IsOn;
1515
1516 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: FdoDevice - %p\n",
1517 FdoDevice);
1518
1519 FdoExtension = FdoDevice->DeviceExtension;
1520
1521 PdoDevice = FdoExtension->RootHubPdo;
1522
1523 if (!PdoDevice)
1524 {
1525 return;
1526 }
1527
1528 PdoExtension = PdoDevice->DeviceExtension;
1529
1530 if (PdoExtension->RootHubInitCallback == NULL ||
1532 {
1533 return;
1534 }
1535
1536 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: Flags - %p\n",
1537 FdoExtension->Flags);
1538
1540 {
1541 IsOn = FALSE;
1542
1543 USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1544
1545 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: USB2FdoDevice - %p\n",
1546 USB2FdoDevice);
1547
1548 if (USB2FdoDevice)
1549 {
1550 USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1551
1552 if (USB2FdoExtension->CommonExtension.PnpStateFlags &
1554 {
1555 IsOn = TRUE;
1556 }
1557 }
1558
1559 if (!(FdoExtension->Flags & USBPORT_FLAG_NO_HACTION))
1560 {
1561 goto Start;
1562 }
1563
1564 USB2FdoDevice = NULL;
1565 }
1566
1567 IsOn = TRUE;
1568
1569 Start:
1570
1571 if (IsOn &&
1572 !InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 1, 0))
1573 {
1575 USBPORT_SignalWorkerThread(FdoDevice);
1576
1577 if (USB2FdoDevice)
1578 {
1579 USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1580
1581 USB2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1582 USBPORT_SignalWorkerThread(USB2FdoDevice);
1583 }
1584 }
1585
1586 DPRINT_TIMER("USBPORT_SynchronizeControllersStart: exit\n");
1587}
1588
1589VOID
1590NTAPI
1595{
1596 PDEVICE_OBJECT FdoDevice;
1599 LARGE_INTEGER DueTime = {{0, 0}};
1600 ULONG TimerFlags;
1601 PTIMER_WORK_QUEUE_ITEM IdleQueueItem;
1602 KIRQL OldIrql;
1603 KIRQL TimerOldIrql;
1604
1605 DPRINT_TIMER("USBPORT_TimerDpc: Dpc - %p, DeferredContext - %p\n",
1606 Dpc,
1608
1609 FdoDevice = DeferredContext;
1610 FdoExtension = FdoDevice->DeviceExtension;
1611 Packet = &FdoExtension->MiniPortInterface->Packet;
1612
1613 KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &TimerOldIrql);
1614
1615 TimerFlags = FdoExtension->TimerFlags;
1616
1617 DPRINT_TIMER("USBPORT_TimerDpc: Flags - %p, TimerFlags - %p\n",
1618 FdoExtension->Flags,
1619 TimerFlags);
1620
1623 !(TimerFlags & USBPORT_TMFLAG_HC_RESUME))
1624 {
1625 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1626 Packet->PollController(FdoExtension->MiniPortExt);
1627 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1628 }
1629
1631
1632 if (TimerFlags & USBPORT_TMFLAG_HC_SUSPENDED)
1633 {
1634 USBPORT_BadRequestFlush(FdoDevice);
1635 goto Exit;
1636 }
1637
1638 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1639
1640 if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
1641 {
1642 Packet->CheckController(FdoExtension->MiniPortExt);
1643 }
1644
1645 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1646
1648 {
1649 KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1650 Packet->PollController(FdoExtension->MiniPortExt);
1651 KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1652 }
1653
1654 USBPORT_IsrDpcHandler(FdoDevice, FALSE);
1655
1656 DPRINT_TIMER("USBPORT_TimerDpc: USBPORT_TimeoutAllEndpoints UNIMPLEMENTED.\n");
1657 //USBPORT_TimeoutAllEndpoints(FdoDevice);
1658 DPRINT_TIMER("USBPORT_TimerDpc: USBPORT_CheckIdleEndpoints UNIMPLEMENTED.\n");
1659 //USBPORT_CheckIdleEndpoints(FdoDevice);
1660
1661 USBPORT_BadRequestFlush(FdoDevice);
1662
1663 if (FdoExtension->IdleLockCounter > -1 &&
1664 !(TimerFlags & USBPORT_TMFLAG_IDLE_QUEUEITEM_ON))
1665 {
1666 IdleQueueItem = ExAllocatePoolWithTag(NonPagedPool,
1667 sizeof(TIMER_WORK_QUEUE_ITEM),
1668 USB_PORT_TAG);
1669
1670 DPRINT("USBPORT_TimerDpc: IdleLockCounter - %x, IdleQueueItem - %p\n",
1671 FdoExtension->IdleLockCounter,
1672 IdleQueueItem);
1673
1674 if (IdleQueueItem)
1675 {
1676 RtlZeroMemory(IdleQueueItem, sizeof(TIMER_WORK_QUEUE_ITEM));
1677
1678 IdleQueueItem->WqItem.List.Flink = NULL;
1680 IdleQueueItem->WqItem.Parameter = IdleQueueItem;
1681
1682 IdleQueueItem->FdoDevice = FdoDevice;
1683 IdleQueueItem->Context = 0;
1684
1686
1687 ExQueueWorkItem(&IdleQueueItem->WqItem, CriticalWorkQueue);
1688 }
1689 }
1690
1691Exit:
1692
1693 KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, TimerOldIrql);
1694
1695 if (TimerFlags & USBPORT_TMFLAG_TIMER_QUEUED)
1696 {
1697 DueTime.QuadPart -= FdoExtension->TimerValue * 10000 +
1698 (KeQueryTimeIncrement() - 1);
1699
1700 KeSetTimer(&FdoExtension->TimerObject,
1701 DueTime,
1702 &FdoExtension->TimerDpc);
1703 }
1704
1705 DPRINT_TIMER("USBPORT_TimerDpc: exit\n");
1706}
1707
1708BOOLEAN
1709NTAPI
1711 IN ULONG Time)
1712{
1714 LARGE_INTEGER DueTime = {{0, 0}};
1715 ULONG TimeIncrement;
1717
1718 DPRINT_TIMER("USBPORT_StartTimer: FdoDevice - %p, Time - %x\n",
1719 FdoDevice,
1720 Time);
1721
1722 FdoExtension = FdoDevice->DeviceExtension;
1723
1724 TimeIncrement = KeQueryTimeIncrement();
1725
1727 FdoExtension->TimerValue = Time;
1728
1729 KeInitializeTimer(&FdoExtension->TimerObject);
1730 KeInitializeDpc(&FdoExtension->TimerDpc, USBPORT_TimerDpc, FdoDevice);
1731
1732 DueTime.QuadPart -= 10000 * Time + (TimeIncrement - 1);
1733
1734 Result = KeSetTimer(&FdoExtension->TimerObject,
1735 DueTime,
1736 &FdoExtension->TimerDpc);
1737
1738 return Result;
1739}
1740
1742NTAPI
1745{
1746 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer = NULL;
1748 PDMA_ADAPTER DmaAdapter;
1749 PDMA_OPERATIONS DmaOperations;
1750 SIZE_T HeaderSize;
1751 ULONG Length = 0;
1752 ULONG LengthPadded;
1753 PHYSICAL_ADDRESS LogicalAddress;
1754 ULONG_PTR BaseVA;
1755 ULONG_PTR StartBufferVA;
1756 ULONG StartBufferPA;
1757
1758 DPRINT("USBPORT_AllocateCommonBuffer: FdoDevice - %p, BufferLength - %p\n",
1759 FdoDevice,
1760 BufferLength);
1761
1762 if (BufferLength == 0)
1763 goto Exit;
1764
1765 FdoExtension = FdoDevice->DeviceExtension;
1766
1767 DmaAdapter = FdoExtension->DmaAdapter;
1768 DmaOperations = DmaAdapter->DmaOperations;
1769
1770 HeaderSize = sizeof(USBPORT_COMMON_BUFFER_HEADER);
1771 Length = ROUND_TO_PAGES(BufferLength + HeaderSize);
1772 LengthPadded = Length - (BufferLength + HeaderSize);
1773
1774 BaseVA = (ULONG_PTR)DmaOperations->AllocateCommonBuffer(DmaAdapter,
1775 Length,
1776 &LogicalAddress,
1777 TRUE);
1778
1779 if (!BaseVA)
1780 goto Exit;
1781
1782 StartBufferVA = BaseVA & ~(PAGE_SIZE - 1);
1783 StartBufferPA = LogicalAddress.LowPart & ~(PAGE_SIZE - 1);
1784
1785 HeaderBuffer = (PUSBPORT_COMMON_BUFFER_HEADER)(StartBufferVA +
1786 BufferLength +
1787 LengthPadded);
1788
1789 HeaderBuffer->Length = Length;
1790 HeaderBuffer->BaseVA = BaseVA;
1791 HeaderBuffer->LogicalAddress = LogicalAddress;
1792
1793 HeaderBuffer->BufferLength = BufferLength + LengthPadded;
1794 HeaderBuffer->VirtualAddress = StartBufferVA;
1795 HeaderBuffer->PhysicalAddress = StartBufferPA;
1796
1797 RtlZeroMemory((PVOID)StartBufferVA, BufferLength + LengthPadded);
1798
1799Exit:
1800 return HeaderBuffer;
1801}
1802
1803VOID
1804NTAPI
1806 IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
1807{
1809 PDMA_ADAPTER DmaAdapter;
1810 PDMA_OPERATIONS DmaOperations;
1811
1812 DPRINT("USBPORT_FreeCommonBuffer: ...\n");
1813
1814 FdoExtension = FdoDevice->DeviceExtension;
1815
1816 DmaAdapter = FdoExtension->DmaAdapter;
1817 DmaOperations = DmaAdapter->DmaOperations;
1818
1819 DmaOperations->FreeCommonBuffer(FdoExtension->DmaAdapter,
1820 HeaderBuffer->Length,
1821 HeaderBuffer->LogicalAddress,
1822 (PVOID)HeaderBuffer->VirtualAddress,
1823 TRUE);
1824}
1825
1827NTAPI
1829{
1830 KIRQL OldIrql;
1832 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1833 BOOLEAN IsFound = FALSE;
1834
1835 DPRINT("USBPORT_FindMiniPort: ...\n");
1836
1838
1841 List = List->Flink)
1842 {
1843 MiniPortInterface = CONTAINING_RECORD(List,
1845 DriverLink);
1846
1847 if (MiniPortInterface->DriverObject == DriverObject)
1848 {
1849 DPRINT("USBPORT_FindMiniPort: find MiniPortInterface - %p\n",
1850 MiniPortInterface);
1851
1852 IsFound = TRUE;
1853 break;
1854 }
1855 }
1856
1858
1859 if (IsFound)
1860 return MiniPortInterface;
1861 else
1862 return NULL;
1863
1864}
1865
1867NTAPI
1870{
1872 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1873 ULONG DeviceNumber = 0;
1874 WCHAR CharDeviceName[64];
1878 PUSBPORT_COMMON_DEVICE_EXTENSION FdoCommonExtension;
1879 PDEVICE_OBJECT LowerDevice;
1880 ULONG Length;
1881
1882 DPRINT("USBPORT_AddDevice: DriverObject - %p, PhysicalDeviceObject - %p\n",
1885
1886 MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
1887
1888 if (!MiniPortInterface)
1889 {
1890 DPRINT("USBPORT_AddDevice: USBPORT_FindMiniPort not found MiniPortInterface\n");
1891 return STATUS_UNSUCCESSFUL;
1892 }
1893
1894 while (TRUE)
1895 {
1896 /* Construct device name */
1897 RtlStringCbPrintfW(CharDeviceName,
1898 sizeof(CharDeviceName),
1899 L"\\Device\\USBFDO-%d",
1900 DeviceNumber);
1901
1902 RtlInitUnicodeString(&DeviceName, CharDeviceName);
1903
1904 ASSERT(MiniPortInterface->Packet.MiniPortExtensionSize <=
1907 MiniPortInterface->Packet.MiniPortExtensionSize +
1908 sizeof(USB2_HC_EXTENSION));
1909
1910 /* Create device */
1912 Length,
1913 &DeviceName,
1915 0,
1916 FALSE,
1917 &DeviceObject);
1918
1919 /* Check for success */
1920 if (NT_SUCCESS(Status)) break;
1921
1922 /* Is there a device object with that same name */
1925 {
1926 /* Try the next name */
1927 DeviceNumber++;
1928 continue;
1929 }
1930
1931 /* Bail out on other errors */
1932 if (!NT_SUCCESS(Status))
1933 {
1934 DPRINT1("USBPORT_AddDevice: failed to create %wZ, Status %x\n",
1935 &DeviceName,
1936 Status);
1937
1938 return Status;
1939 }
1940 }
1941
1942 DPRINT("USBPORT_AddDevice: created device %p <%wZ>, Status %x\n",
1944 &DeviceName,
1945 Status);
1946
1947 FdoExtension = DeviceObject->DeviceExtension;
1948 FdoCommonExtension = &FdoExtension->CommonExtension;
1949
1951
1952 FdoCommonExtension->SelfDevice = DeviceObject;
1953 FdoCommonExtension->LowerPdoDevice = PhysicalDeviceObject;
1954 FdoCommonExtension->IsPDO = FALSE;
1955
1958
1959 FdoCommonExtension->LowerDevice = LowerDevice;
1960
1961 FdoCommonExtension->DevicePowerState = PowerDeviceD3;
1962
1963 FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension +
1964 sizeof(USBPORT_DEVICE_EXTENSION));
1965
1966 if (MiniPortInterface->Packet.MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1967 {
1968 FdoExtension->Usb2Extension =
1969 (PUSB2_HC_EXTENSION)((ULONG_PTR)FdoExtension->MiniPortExt +
1970 MiniPortInterface->Packet.MiniPortExtensionSize);
1971
1972 DPRINT("USBPORT_AddDevice: Usb2Extension - %p\n",
1973 FdoExtension->Usb2Extension);
1974
1975 USB2_InitController(FdoExtension->Usb2Extension);
1976 }
1977 else
1978 {
1979 FdoExtension->Usb2Extension = NULL;
1980 }
1981
1982 FdoExtension->MiniPortInterface = MiniPortInterface;
1983 FdoExtension->FdoNameNumber = DeviceNumber;
1984
1985 KeInitializeSemaphore(&FdoExtension->DeviceSemaphore, 1, 1);
1986 KeInitializeSemaphore(&FdoExtension->ControllerSemaphore, 1, 1);
1987
1988 InitializeListHead(&FdoExtension->EndpointList);
1989 InitializeListHead(&FdoExtension->DoneTransferList);
1990 InitializeListHead(&FdoExtension->WorkerList);
1991 InitializeListHead(&FdoExtension->EpStateChangeList);
1992 InitializeListHead(&FdoExtension->MapTransferList);
1993 InitializeListHead(&FdoExtension->DeviceHandleList);
1994 InitializeListHead(&FdoExtension->IdleIrpList);
1995 InitializeListHead(&FdoExtension->BadRequestList);
1996 InitializeListHead(&FdoExtension->EndpointClosedList);
1997
1998 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
1999
2000 return Status;
2001}
2002
2003VOID
2004NTAPI
2006{
2007 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
2008
2009 DPRINT1("USBPORT_Unload: FIXME!\n");
2010
2011 MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
2012
2013 if (!MiniPortInterface)
2014 {
2015 DPRINT("USBPORT_Unload: CRITICAL ERROR!!! Not found MiniPortInterface\n");
2016 KeBugCheckEx(BUGCODE_USB_DRIVER, 1, 0, 0, 0);
2017 }
2018
2019 DPRINT1("USBPORT_Unload: UNIMPLEMENTED. FIXME.\n");
2020 //MiniPortInterface->DriverUnload(DriverObject); // Call MiniPort _HCI_Unload
2021}
2022
2023VOID
2024NTAPI
2026 IN PVOID MiniPortEndpoint,
2027 IN PVOID TransferParameters,
2028 IN USBD_STATUS USBDStatus,
2029 IN ULONG TransferLength)
2030{
2031 PUSBPORT_TRANSFER Transfer;
2032 PUSBPORT_TRANSFER ParentTransfer;
2033 PUSBPORT_TRANSFER SplitTransfer;
2034 PLIST_ENTRY SplitHead;
2036 KIRQL OldIrql;
2037
2038 DPRINT_CORE("USBPORT_MiniportCompleteTransfer: USBDStatus - %x, TransferLength - %x\n",
2039 USBDStatus,
2040 TransferLength);
2041
2042 Transfer = CONTAINING_RECORD(TransferParameters,
2044 TransferParameters);
2045
2046 Transfer->Flags |= TRANSFER_FLAG_COMPLETED;
2047 Transfer->CompletedTransferLen = TransferLength;
2048
2049 if (((Transfer->Flags & TRANSFER_FLAG_SPLITED) == 0) ||
2050 TransferLength >= Transfer->TransferParameters.TransferBufferLength)
2051 {
2052 goto Exit;
2053 }
2054
2055 ParentTransfer = Transfer->ParentTransfer;
2056
2057 KeAcquireSpinLock(&ParentTransfer->TransferSpinLock, &OldIrql);
2058
2059 if (IsListEmpty(&ParentTransfer->SplitTransfersList))
2060 {
2061 goto Exit;
2062 }
2063
2064 SplitHead = &ParentTransfer->SplitTransfersList;
2065 Entry = SplitHead->Flink;
2066
2067 while (Entry && !IsListEmpty(SplitHead))
2068 {
2069 SplitTransfer = CONTAINING_RECORD(Entry,
2071 SplitLink);
2072
2073 if (!(SplitTransfer->Flags & TRANSFER_FLAG_SUBMITED))
2074 {
2075 DPRINT1("USBPORT_MiniportCompleteTransfer: SplitTransfer->Flags - %X\n",
2076 SplitTransfer->Flags);
2077 //Add TRANSFER_FLAG_xxx
2078 }
2079
2080 Entry = Entry->Flink;
2081 }
2082
2083 KeReleaseSpinLock(&ParentTransfer->TransferSpinLock, OldIrql);
2084
2085Exit:
2086 USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2087}
2088
2089VOID
2090NTAPI
2095{
2096 PDEVICE_OBJECT FdoDevice;
2098 PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2099
2100 DPRINT("USBPORT_AsyncTimerDpc: ...\n");
2101
2102 AsyncCallbackData = DeferredContext;
2103 FdoDevice = AsyncCallbackData->FdoDevice;
2104 FdoExtension = FdoDevice->DeviceExtension;
2105
2106 (*AsyncCallbackData->CallbackFunction)(FdoExtension->MiniPortExt,
2107 &AsyncCallbackData->CallbackContext);
2108
2109 ExFreePoolWithTag(AsyncCallbackData, USB_PORT_TAG);
2110}
2111
2112ULONG
2113NTAPI
2115 IN ULONG TimerValue,
2116 IN PVOID Buffer,
2118 IN ASYNC_TIMER_CALLBACK * Callback)
2119{
2121 PDEVICE_OBJECT FdoDevice;
2122 PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2123 LARGE_INTEGER DueTime = {{0, 0}};
2124
2125 DPRINT("USBPORT_RequestAsyncCallback: ...\n");
2126
2127 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2128 sizeof(USBPORT_DEVICE_EXTENSION));
2129
2130 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2131
2132 AsyncCallbackData = ExAllocatePoolWithTag(NonPagedPool,
2134 USB_PORT_TAG);
2135
2136 if (!AsyncCallbackData)
2137 {
2138 DPRINT1("USBPORT_RequestAsyncCallback: Not allocated AsyncCallbackData!\n");
2139 return 0;
2140 }
2141
2142 RtlZeroMemory(AsyncCallbackData,
2144
2145 if (Length)
2146 {
2147 RtlCopyMemory(&AsyncCallbackData->CallbackContext, Buffer, Length);
2148 }
2149
2150 AsyncCallbackData->FdoDevice = FdoDevice;
2151 AsyncCallbackData->CallbackFunction = Callback;
2152
2153 KeInitializeTimer(&AsyncCallbackData->AsyncTimer);
2154
2155 KeInitializeDpc(&AsyncCallbackData->AsyncTimerDpc,
2157 AsyncCallbackData);
2158
2159 DueTime.QuadPart -= (KeQueryTimeIncrement() - 1) + 10000 * TimerValue;
2160
2161 KeSetTimer(&AsyncCallbackData->AsyncTimer,
2162 DueTime,
2163 &AsyncCallbackData->AsyncTimerDpc);
2164
2165 return 0;
2166}
2167
2168PVOID
2169NTAPI
2171 IN PVOID MiniPortExtension,
2172 IN PVOID MiniPortEndpoint)
2173{
2174 PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
2175 PUSBPORT_ENDPOINT Endpoint;
2176 ULONG Offset;
2178
2179 DPRINT_CORE("USBPORT_GetMappedVirtualAddress ...\n");
2180
2181 Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2182 sizeof(USBPORT_ENDPOINT));
2183
2184 if (!Endpoint)
2185 {
2186 ASSERT(FALSE);
2187 }
2188
2189 HeaderBuffer = Endpoint->HeaderBuffer;
2190
2191 Offset = PhysicalAddress - HeaderBuffer->PhysicalAddress;
2192 VirtualAddress = HeaderBuffer->VirtualAddress + Offset;
2193
2194 return (PVOID)VirtualAddress;
2195}
2196
2197ULONG
2198NTAPI
2200 IN PVOID MiniPortEndpoint)
2201{
2203 PDEVICE_OBJECT FdoDevice;
2204 PUSBPORT_ENDPOINT Endpoint;
2205
2206 DPRINT_CORE("USBPORT_InvalidateEndpoint: ...\n");
2207
2208 FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2209 sizeof(USBPORT_DEVICE_EXTENSION));
2210
2211 FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2212
2213 if (!MiniPortEndpoint)
2214 {
2216 NULL,
2218 return 0;
2219 }
2220
2221 Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2222 sizeof(USBPORT_ENDPOINT));
2223
2225 Endpoint,
2227
2228 return 0;
2229}
2230
2231VOID
2232NTAPI
2234 IN USBD_STATUS TransferStatus)
2235{
2236 struct _URB_CONTROL_TRANSFER *UrbTransfer;
2237 PUSBPORT_TRANSFER Transfer;
2239 PIRP Irp;
2240 KIRQL OldIrql;
2243 BOOLEAN IsFlushSuccess;
2244 PMDL Mdl;
2245 ULONG_PTR CurrentVa;
2246 SIZE_T TransferLength;
2247 PUSBPORT_ENDPOINT Endpoint;
2248 PDEVICE_OBJECT FdoDevice;
2250 PDMA_OPERATIONS DmaOperations;
2251
2252 DPRINT("USBPORT_CompleteTransfer: Urb - %p, TransferStatus - %X\n",
2253 Urb,
2254 TransferStatus);
2255
2256 UrbTransfer = &Urb->UrbControlTransfer;
2257 Transfer = UrbTransfer->hca.Reserved8[0];
2258
2259 Transfer->USBDStatus = TransferStatus;
2260 Status = USBPORT_USBDStatusToNtStatus(Urb, TransferStatus);
2261
2262 UrbTransfer->TransferBufferLength = Transfer->CompletedTransferLen;
2263
2264 if (Transfer->Flags & TRANSFER_FLAG_DMA_MAPPED)
2265 {
2266 Endpoint = Transfer->Endpoint;
2267 FdoDevice = Endpoint->FdoDevice;
2268 FdoExtension = FdoDevice->DeviceExtension;
2269 DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2270
2272 Mdl = UrbTransfer->TransferBufferMDL;
2273 CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2274 TransferLength = UrbTransfer->TransferBufferLength;
2275
2276 IsFlushSuccess = DmaOperations->FlushAdapterBuffers(FdoExtension->DmaAdapter,
2277 Mdl,
2278 Transfer->MapRegisterBase,
2279 (PVOID)CurrentVa,
2280 TransferLength,
2282
2283 if (!IsFlushSuccess)
2284 {
2285 DPRINT("USBPORT_CompleteTransfer: no FlushAdapterBuffers !!!\n");
2286 ASSERT(FALSE);
2287 }
2288
2290
2291 DmaOperations->FreeMapRegisters(FdoExtension->DmaAdapter,
2292 Transfer->MapRegisterBase,
2293 Transfer->NumberOfMapRegisters);
2294
2296 }
2297
2298 if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_ALLOCATED_MDL)
2299 {
2300 IoFreeMdl(Transfer->TransferBufferMDL);
2301 Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_MDL;
2302 }
2303
2304 Urb->UrbControlTransfer.hca.Reserved8[0] = NULL;
2305 Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_TRANSFER;
2306
2307 Irp = Transfer->Irp;
2308
2309 if (Irp)
2310 {
2311 if (!NT_SUCCESS(Status))
2312 {
2313 //DbgBreakPoint();
2314 DPRINT1("USBPORT_CompleteTransfer: Irp - %p complete with Status - %lx\n",
2315 Irp,
2316 Status);
2317
2319 }
2320
2321 Irp->IoStatus.Status = Status;
2322 Irp->IoStatus.Information = 0;
2323
2327 }
2328
2329 Event = Transfer->Event;
2330
2331 if (Event)
2332 {
2334 }
2335
2337
2338 DPRINT_CORE("USBPORT_CompleteTransfer: exit\n");
2339}
2340
2342NTAPI
2344 IN PIRP Irp,
2347{
2349 PDMA_ADAPTER DmaAdapter;
2350 PUSBPORT_TRANSFER Transfer;
2351 PURB Urb;
2352 PUSBPORT_ENDPOINT Endpoint;
2353 PMDL Mdl;
2354 ULONG_PTR CurrentVa;
2356 SIZE_T CurrentLength;
2357 ULONG ix;
2359 PHYSICAL_ADDRESS PhAddr = {{0, 0}};
2360 PHYSICAL_ADDRESS PhAddress = {{0, 0}};
2361 ULONG TransferLength;
2362 SIZE_T SgCurrentLength;
2363 SIZE_T ElementLength;
2365 PDMA_OPERATIONS DmaOperations;
2366 USBD_STATUS USBDStatus;
2368 PUSBPORT_TRANSFER transfer;
2369
2370 DPRINT_CORE("USBPORT_MapTransfer: ...\n");
2371
2372 FdoExtension = FdoDevice->DeviceExtension;
2373 DmaAdapter = FdoExtension->DmaAdapter;
2374 DmaOperations = DmaAdapter->DmaOperations;
2375
2376 Transfer = Context;
2377
2378 Urb = Transfer->Urb;
2379 Endpoint = Transfer->Endpoint;
2380 TransferLength = Transfer->TransferParameters.TransferBufferLength;
2381
2382 Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2383 CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2384
2385 sgList = &Transfer->SgList;
2386
2387 sgList->Flags = 0;
2388 sgList->CurrentVa = CurrentVa;
2391 Transfer->MapRegisterBase = MapRegisterBase;
2392
2393 ix = 0;
2394 CurrentLength = 0;
2395
2396 do
2397 {
2399 ASSERT(Transfer->Direction != 0);
2400
2401 PhAddress = DmaOperations->MapTransfer(DmaAdapter,
2402 Mdl,
2404 (PVOID)CurrentVa,
2405 &TransferLength,
2407
2408 DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, PhAddress.HighPart - %x, TransferLength - %x\n",
2409 PhAddress.LowPart,
2410 PhAddress.HighPart,
2411 TransferLength);
2412
2413 PhAddress.HighPart = 0;
2414 SgCurrentLength = TransferLength;
2415
2416 do
2417 {
2418 ElementLength = PAGE_SIZE - (PhAddress.LowPart & (PAGE_SIZE - 1));
2419
2420 if (ElementLength > SgCurrentLength)
2421 ElementLength = SgCurrentLength;
2422
2423 DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, HighPart - %x, ElementLength - %x\n",
2424 PhAddress.LowPart,
2425 PhAddress.HighPart,
2426 ElementLength);
2427
2428 sgList->SgElement[ix].SgPhysicalAddress = PhAddress;
2429 sgList->SgElement[ix].SgTransferLength = ElementLength;
2430 sgList->SgElement[ix].SgOffset = CurrentLength +
2431 (TransferLength - SgCurrentLength);
2432
2433 PhAddress.LowPart += ElementLength;
2434 SgCurrentLength -= ElementLength;
2435
2436 ++ix;
2437 }
2438 while (SgCurrentLength);
2439
2440 if (PhAddr.QuadPart == PhAddress.QuadPart)
2441 {
2442 DPRINT1("USBPORT_MapTransfer: PhAddr == PhAddress\n");
2443 ASSERT(FALSE);
2444 }
2445
2446 PhAddr = PhAddress;
2447
2448 CurrentLength += TransferLength;
2449 CurrentVa += TransferLength;
2450
2451 TransferLength = Transfer->TransferParameters.TransferBufferLength -
2452 CurrentLength;
2453 }
2454 while (CurrentLength != Transfer->TransferParameters.TransferBufferLength);
2455
2456 sgList->SgElementCount = ix;
2457
2459 {
2460 Transfer->Flags |= TRANSFER_FLAG_HIGH_SPEED;
2461 }
2462
2463 Transfer->Flags |= TRANSFER_FLAG_DMA_MAPPED;
2464
2465 if ((Transfer->Flags & TRANSFER_FLAG_ISO) == 0)
2466 {
2468 &Endpoint->EndpointOldIrql);
2469
2470 USBPORT_SplitTransfer(FdoDevice, Endpoint, Transfer, &List);
2471
2472 while (!IsListEmpty(&List))
2473 {
2474 transfer = CONTAINING_RECORD(List.Flink,
2476 TransferLink);
2477
2479 InsertTailList(&Endpoint->TransferList, &transfer->TransferLink);
2480 }
2481
2483 Endpoint->EndpointOldIrql);
2484 }
2485 else
2486 {
2487 USBDStatus = USBPORT_InitializeIsoTransfer(FdoDevice,
2488 &Urb->UrbIsochronousTransfer,
2489 Transfer);
2490
2491 if (USBDStatus != USBD_STATUS_SUCCESS)
2492 {
2494 &Endpoint->EndpointOldIrql);
2495
2496 USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2497
2499 Endpoint->EndpointOldIrql);
2500 }
2501 }
2502
2503 DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
2504 InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
2505
2506 if (USBPORT_EndpointWorker(Endpoint, 0))
2507 {
2509 Endpoint,
2511 }
2512
2514}
2515
2516VOID
2517NTAPI
2519{
2521 PLIST_ENTRY MapTransferList;
2522 PUSBPORT_TRANSFER Transfer;
2523 ULONG NumMapRegisters;
2524 PMDL Mdl;
2526 ULONG_PTR VirtualAddr;
2527 KIRQL OldIrql;
2529 PDMA_OPERATIONS DmaOperations;
2530
2531 DPRINT_CORE("USBPORT_FlushMapTransfers: ...\n");
2532
2533 FdoExtension = FdoDevice->DeviceExtension;
2534 DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2535
2537
2538 while (TRUE)
2539 {
2540 MapTransferList = &FdoExtension->MapTransferList;
2541
2542 if (IsListEmpty(&FdoExtension->MapTransferList))
2543 {
2545 return;
2546 }
2547
2548 Transfer = CONTAINING_RECORD(MapTransferList->Flink,
2550 TransferLink);
2551
2552 RemoveHeadList(MapTransferList);
2553
2554 Mdl = Transfer->Urb->UrbControlTransfer.TransferBufferMDL;
2556 VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2557
2558 NumMapRegisters = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2560
2561 Transfer->NumberOfMapRegisters = NumMapRegisters;
2562
2563 Status = DmaOperations->AllocateAdapterChannel(FdoExtension->DmaAdapter,
2564 FdoDevice,
2565 NumMapRegisters,
2567 Transfer);
2568
2569 if (!NT_SUCCESS(Status))
2570 ASSERT(FALSE);
2571 }
2572
2574}
2575
2577NTAPI
2579 IN PURB Urb,
2581 IN PIRP Irp,
2583{
2585 SIZE_T TransferLength;
2586 PMDL Mdl;
2587 ULONG_PTR VirtualAddr;
2588 ULONG PagesNeed = 0;
2589 SIZE_T PortTransferLength;
2590 SIZE_T FullTransferLength;
2591 PUSBPORT_TRANSFER Transfer;
2593 USBD_STATUS USBDStatus;
2594 SIZE_T IsoBlockLen = 0;
2595
2596 DPRINT_CORE("USBPORT_AllocateTransfer: FdoDevice - %p, Urb - %p, DeviceHandle - %p, Irp - %p, Event - %p\n",
2597 FdoDevice,
2598 Urb,
2600 Irp,
2601 Event);
2602
2603 FdoExtension = FdoDevice->DeviceExtension;
2604
2605 TransferLength = Urb->UrbControlTransfer.TransferBufferLength;
2606 PipeHandle = Urb->UrbControlTransfer.PipeHandle;
2607
2608 if (TransferLength)
2609 {
2610 Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2611 VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2612
2613 PagesNeed = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2614 TransferLength);
2615 if (PagesNeed > 0)
2616 {
2617 PagesNeed--;
2618 }
2619 }
2620
2621 if (Urb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
2622 {
2623 DPRINT1("USBPORT_AllocateTransfer: ISOCH_TRANSFER UNIMPLEMENTED. FIXME\n");
2624
2625 //IsoBlockLen = sizeof(USBPORT_ISO_BLOCK) +
2626 // Urb->UrbIsochronousTransfer.NumberOfPackets *
2627 // sizeof(USBPORT_ISO_BLOCK_PACKET);
2628 }
2629
2630 PortTransferLength = sizeof(USBPORT_TRANSFER) +
2631 PagesNeed * sizeof(USBPORT_SCATTER_GATHER_ELEMENT) +
2632 IsoBlockLen;
2633
2634 FullTransferLength = PortTransferLength +
2635 FdoExtension->MiniPortInterface->Packet.MiniPortTransferSize;
2636
2638 FullTransferLength,
2639 USB_PORT_TAG);
2640
2641 if (!Transfer)
2642 {
2643 DPRINT1("USBPORT_AllocateTransfer: Transfer not allocated!\n");
2645 }
2646
2647 RtlZeroMemory(Transfer, FullTransferLength);
2648
2649 Transfer->Irp = Irp;
2650 Transfer->Urb = Urb;
2651 Transfer->Endpoint = PipeHandle->Endpoint;
2652 Transfer->Event = Event;
2653 Transfer->PortTransferLength = PortTransferLength;
2654 Transfer->FullTransferLength = FullTransferLength;
2655 Transfer->IsoBlockPtr = NULL;
2656 Transfer->Period = 0;
2657 Transfer->ParentTransfer = Transfer;
2658
2659 if (IsoBlockLen)
2660 {
2661 Transfer->IsoBlockPtr = (PVOID)((ULONG_PTR)Transfer +
2662 PortTransferLength - IsoBlockLen);
2663
2664 Transfer->Period = PipeHandle->Endpoint->EndpointProperties.Period;
2665 Transfer->Flags |= TRANSFER_FLAG_ISO;
2666 }
2667
2668 Transfer->MiniportTransfer = (PVOID)((ULONG_PTR)Transfer +
2669 PortTransferLength);
2670
2672
2673 Urb->UrbControlTransfer.hca.Reserved8[0] = Transfer;
2674 Urb->UrbHeader.UsbdFlags |= USBD_FLAG_ALLOCATED_TRANSFER;
2675
2676 USBDStatus = USBD_STATUS_SUCCESS;
2677
2678 DPRINT_CORE("USBPORT_AllocateTransfer: return USBDStatus - %x\n",
2679 USBDStatus);
2680
2681 return USBDStatus;
2682}
2683
2685NTAPI
2687 IN PIRP Irp)
2688{
2689 PUSBPORT_COMMON_DEVICE_EXTENSION DeviceExtension;
2690 PIO_STACK_LOCATION IoStack;
2692
2693 DeviceExtension = DeviceObject->DeviceExtension;
2695
2696 if (DeviceExtension->PnpStateFlags & USBPORT_PNP_STATE_FAILED)
2697 {
2698 DPRINT1("USBPORT_Dispatch: USBPORT_PNP_STATE_FAILED\n");
2699 DbgBreakPoint();
2700 }
2701
2702 switch (IoStack->MajorFunction)
2703 {
2705 if (DeviceExtension->IsPDO)
2706 {
2707 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2708 IoStack->MajorFunction,
2709 IoStack->MinorFunction);
2710
2712 }
2713 else
2714 {
2715 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2716 IoStack->MajorFunction,
2717 IoStack->MinorFunction);
2718
2720 }
2721
2722 break;
2723
2725 if (DeviceExtension->IsPDO)
2726 {
2727 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2728 IoStack->MajorFunction,
2729 IoStack->MinorFunction);
2730
2732 }
2733 else
2734 {
2735 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2736 IoStack->MajorFunction,
2737 IoStack->MinorFunction);
2738
2740 }
2741
2742 break;
2743
2744 case IRP_MJ_POWER:
2745 if (DeviceExtension->IsPDO)
2746 {
2747 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2748 IoStack->MajorFunction,
2749 IoStack->MinorFunction);
2750
2752 }
2753 else
2754 {
2755 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2756 IoStack->MajorFunction,
2757 IoStack->MinorFunction);
2758
2760 }
2761
2762 break;
2763
2765 if (DeviceExtension->IsPDO)
2766 {
2767 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2768 IoStack->MajorFunction,
2769 IoStack->MinorFunction);
2770
2771 Status = Irp->IoStatus.Status;
2773 }
2774 else
2775 {
2776 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2777 IoStack->MajorFunction,
2778 IoStack->MinorFunction);
2779
2781 Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
2782 }
2783
2784 break;
2785
2786 case IRP_MJ_PNP:
2787 if (DeviceExtension->IsPDO)
2788 {
2789 DPRINT("USBPORT_Dispatch: PDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2790 IoStack->MajorFunction,
2791 IoStack->MinorFunction);
2792
2794 }
2795 else
2796 {
2797 DPRINT("USBPORT_Dispatch: FDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2798 IoStack->MajorFunction,
2799 IoStack->MinorFunction);
2800
2802 }
2803
2804 break;
2805
2806 case IRP_MJ_CREATE:
2807 case IRP_MJ_CLOSE:
2808 DPRINT("USBPORT_Dispatch: IRP_MJ_CREATE | IRP_MJ_CLOSE\n");
2809 Irp->IoStatus.Status = Status;
2811 break;
2812
2813 default:
2814 if (DeviceExtension->IsPDO)
2815 {
2816 DPRINT("USBPORT_Dispatch: PDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2817 IoStack->MajorFunction,
2818 IoStack->MinorFunction);
2819 }
2820 else
2821 {
2822 DPRINT("USBPORT_Dispatch: FDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2823 IoStack->MajorFunction,
2824 IoStack->MinorFunction);
2825 }
2826
2828 Irp->IoStatus.Status = Status;
2830 break;
2831 }
2832
2833 DPRINT("USBPORT_Dispatch: Status - %x\n", Status);
2834 return Status;
2835}
2836
2837ULONG
2838NTAPI
2840{
2841 return USBPORT_HCI_MN;
2842}
2843
2845NTAPI
2849{
2850 PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
2851
2852 DPRINT("USBPORT_RegisterUSBPortDriver: DriverObject - %p, Version - %p, RegPacket - %p\n",
2854 Version,
2855 RegPacket);
2856
2857 DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_MINIPORT_INTERFACE) - %x\n",
2859
2860 DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_DEVICE_EXTENSION) - %x\n",
2861 sizeof(USBPORT_DEVICE_EXTENSION));
2862
2864 {
2865 return STATUS_UNSUCCESSFUL;
2866 }
2867
2869 {
2873
2876 }
2877
2878 MiniPortInterface = ExAllocatePoolWithTag(NonPagedPool,
2880 USB_PORT_TAG);
2881 if (!MiniPortInterface)
2882 {
2884 }
2885
2886 RtlZeroMemory(MiniPortInterface, sizeof(USBPORT_MINIPORT_INTERFACE));
2887
2888 MiniPortInterface->DriverObject = DriverObject;
2889 MiniPortInterface->DriverUnload = DriverObject->DriverUnload;
2890 MiniPortInterface->Version = Version;
2891
2893 &MiniPortInterface->DriverLink,
2895
2896 DriverObject->DriverExtension->AddDevice = USBPORT_AddDevice;
2897 DriverObject->DriverUnload = USBPORT_Unload;
2898
2900 DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBPORT_Dispatch;
2903 DriverObject->MajorFunction[IRP_MJ_PNP] = USBPORT_Dispatch;
2904 DriverObject->MajorFunction[IRP_MJ_POWER] = USBPORT_Dispatch;
2906
2923
2924 RtlCopyMemory(&MiniPortInterface->Packet,
2925 RegPacket,
2927
2928 return STATUS_SUCCESS;
2929}
2930
2932NTAPI
2935{
2936 return STATUS_SUCCESS;
2937}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
Type
Definition: Type.h:7
unsigned char BOOLEAN
Definition: actypes.h:127
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx(IN ULONG BugCheckCode, IN ULONG_PTR BugCheckParameter1, IN ULONG_PTR BugCheckParameter2, IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4)
Definition: debug.c:502
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
_In_ PSCSI_REQUEST_BLOCK _In_opt_ PVOID _In_ ULONG _In_ BOOLEAN WriteToDevice
Definition: cdrom.h:992
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
Definition: bufpool.h:45
Definition: list.h:37
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define L(x)
Definition: resources.c:13
#define ULONG_PTR
Definition: config.h:101
@ PdoExtension
Definition: precomp.h:49
@ FdoExtension
Definition: precomp.h:48
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:224
ULONG NTAPI USBPORT_LogEntry(IN PVOID MiniPortExtension, IN ULONG DriverTag, IN ULONG EnumTag, IN ULONG P1, IN ULONG P2, IN ULONG P3)
Definition: debug.c:60
VOID NTAPI USBPORT_BugCheck(IN PVOID MiniPortExtension)
Definition: debug.c:51
ULONG NTAPI USBPORT_AssertFailure(PVOID MiniPortExtension, PVOID FailedAssertion, PVOID FileName, ULONG LineNumber, PCHAR Message)
Definition: debug.c:38
ULONG NTAPI USBPORT_TestDebugBreak(IN PVOID MiniPortExtension)
Definition: debug.c:30
ULONG USBPORT_DbgPrint(IN PVOID MiniPortExtension, IN ULONG Level, IN PCH Format,...)
Definition: debug.c:19
NTSTATUS NTAPI USBPORT_FdoInternalDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:454
NTSTATUS NTAPI USBPORT_FdoDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:396
NTSTATUS NTAPI USBPORT_PdoInternalDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:317
NTSTATUS NTAPI USBPORT_PdoDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:308
USBD_STATUS NTAPI USBPORT_InitializeIsoTransfer(PDEVICE_OBJECT FdoDevice, struct _URB_ISOCH_TRANSFER *Urb, PUSBPORT_TRANSFER Transfer)
Definition: iso.c:15
ULONG NTAPI USBPORT_CompleteIsoTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN ULONG TransferLength)
Definition: iso.c:25
NTSTATUS NTAPI USBPORT_PdoPnP(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: pnp.c:1517
NTSTATUS NTAPI USBPORT_FdoPnP(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: pnp.c:1110
VOID NTAPI USBPORT_DoSetPowerD0(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:104
NTSTATUS NTAPI USBPORT_FdoPower(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:489
NTSTATUS NTAPI USBPORT_PdoPower(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:322
VOID NTAPI USBPORT_CompletePdoWaitWake(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:15
VOID NTAPI USBPORT_DoIdleNotificationCallback(IN PVOID Context)
Definition: power.c:545
VOID NTAPI USBPORT_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
VOID NTAPI USBPORT_FlushAllEndpoints(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1171
PIRP NTAPI USBPORT_RemoveActiveTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:357
VOID NTAPI USBPORT_BadRequestFlush(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1328
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
Definition: endpoint.c:1685
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1346
BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PULONG TransferCount)
Definition: endpoint.c:254
VOID NTAPI USBPORT_FlushClosedEndpointList(IN PDEVICE_OBJECT FdoDevice)
Definition: endpoint.c:1310
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define KeDelayExecutionThread(mode, foo, t)
Definition: env_spec_w32.h:484
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define PagedPool
Definition: env_spec_w32.h:308
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
unsigned int BOOL
Definition: ntddk_ex.h:94
return pTarget Start()
#define IoFreeMdl
Definition: fxmdl.h:89
Status
Definition: gdiplustypes.h:25
#define KeGetCurrentThread
Definition: hal.h:55
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
RH_INIT_CALLBACK * PRH_INIT_CALLBACK
Definition: hubbusif.h:270
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define LOW_REALTIME_PRIORITY
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define InterlockedCompareExchange
Definition: interlocked.h:119
IoSetCancelRoutine(Irp, CancelRoutine)
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
@ NormalPagePriority
Definition: imports.h:54
static PLARGE_INTEGER Time
Definition: time.c:105
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KernelMode
Definition: asm.h:38
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1957
DWORD Interval
Definition: netstat.c:30
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1342
struct _KEY_VALUE_FULL_INFORMATION KEY_VALUE_FULL_INFORMATION
@ KeyValueFullInformation
Definition: nt_native.h:1184
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ NotificationEvent
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define IoCompleteRequest
Definition: irp.c:1240
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1145
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
@ PowerDeviceD3
Definition: ntpoapi.h:52
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:189
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
long LONG
Definition: pedump.c:60
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:49
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define list
Definition: rosglue.h:35
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
static void Exit(void)
Definition: sock.c:1330
base of all file and directory entries
Definition: entries.h:83
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2165
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2297
PALLOCATE_COMMON_BUFFER AllocateCommonBuffer
Definition: iotypes.h:2637
PFREE_COMMON_BUFFER FreeCommonBuffer
Definition: iotypes.h:2638
PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel
Definition: iotypes.h:2639
PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers
Definition: iotypes.h:2640
PFREE_MAP_REGISTERS FreeMapRegisters
Definition: iotypes.h:2642
PMAP_TRANSFER MapTransfer
Definition: iotypes.h:2643
Definition: ketypes.h:751
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
WORK_QUEUE_ITEM WqItem
Definition: usbport.h:444
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:445
PMDL TransferBufferMDL
Definition: usb.h:472
USBD_PIPE_HANDLE PipeHandle
Definition: usb.h:468
struct _URB_HCD_AREA hca
Definition: usb.h:474
ULONG TransferBufferLength
Definition: usb.h:470
Definition: usb.h:529
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:434
ASYNC_TIMER_CALLBACK * CallbackFunction
Definition: usbport.h:437
PHYSICAL_ADDRESS LogicalAddress
Definition: usbport.h:149
DEVICE_POWER_STATE DevicePowerState
Definition: usbport.h:287
PDEVICE_OBJECT LowerPdoDevice
Definition: usbport.h:282
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:292
LIST_ENTRY ControllerLink
Definition: usbport.h:302
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
KIRQL EndpointOldIrql
Definition: usbport.h:216
LIST_ENTRY EndpointLink
Definition: usbport.h:232
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:225
LIST_ENTRY StateChangeLink
Definition: usbport.h:224
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:206
LIST_ENTRY TransferList
Definition: usbport.h:228
LIST_ENTRY FlushAbortLink
Definition: usbport.h:238
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:215
ULONG FrameNumber
Definition: usbport.h:213
LIST_ENTRY DispatchLink
Definition: usbport.h:235
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:211
LIST_ENTRY WorkerLink
Definition: usbport.h:233
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
Definition: usbport.h:207
USBPORT_REGISTRATION_PACKET Packet
Definition: usbmport.h:644
PDRIVER_OBJECT DriverObject
Definition: usbmport.h:640
PDRIVER_UNLOAD DriverUnload
Definition: usbmport.h:642
PUSBPORT_GET_MINIPORT_REGISTRY_KEY_VALUE UsbPortGetMiniportRegistryKeyValue
Definition: usbmport.h:613
PUSBPORT_INVALIDATE_CONTROLLER UsbPortInvalidateController
Definition: usbmport.h:623
PUSBPORT_REQUEST_ASYNC_CALLBACK UsbPortRequestAsyncCallback
Definition: usbmport.h:620
PUSBPORT_TEST_DEBUG_BREAK UsbPortTestDebugBreak
Definition: usbmport.h:611
PUSBPORT_LOG_ENTRY UsbPortLogEntry
Definition: usbmport.h:618
PUSBPORT_BUG_CHECK UsbPortBugCheck
Definition: usbmport.h:624
PUSBPORT_NOTIFY_DOUBLE_BUFFER UsbPortNotifyDoubleBuffer
Definition: usbmport.h:625
PUSBPORT_INVALIDATE_ROOT_HUB UsbPortInvalidateRootHub
Definition: usbmport.h:614
PUSBPORT_COMPLETE_ISO_TRANSFER UsbPortCompleteIsoTransfer
Definition: usbmport.h:617
PUSBPORT_DBG_PRINT UsbPortDbgPrint
Definition: usbmport.h:610
PUSBPORT_WAIT UsbPortWait
Definition: usbmport.h:622
PUSBPORT_COMPLETE_TRANSFER UsbPortCompleteTransfer
Definition: usbmport.h:616
PUSBPORT_READ_WRITE_CONFIG_SPACE UsbPortReadWriteConfigSpace
Definition: usbmport.h:621
PUSBPORT_ASSERT_FAILURE UsbPortAssertFailure
Definition: usbmport.h:612
PUSBPORT_GET_MAPPED_VIRTUAL_ADDRESS UsbPortGetMappedVirtualAddress
Definition: usbmport.h:619
PUSBPORT_INVALIDATE_ENDPOINT UsbPortInvalidateEndpoint
Definition: usbmport.h:615
PHYSICAL_ADDRESS SgPhysicalAddress
Definition: usbmport.h:107
USBPORT_SCATTER_GATHER_ELEMENT SgElement[2]
Definition: usbmport.h:121
SIZE_T PortTransferLength
Definition: usbport.h:251
ULONG CompletedTransferLen
Definition: usbport.h:259
PMDL TransferBufferMDL
Definition: usbport.h:255
PUSBPORT_ISO_BLOCK IsoBlockPtr
Definition: usbport.h:269
ULONG NumberOfMapRegisters
Definition: usbport.h:260
PRKEVENT Event
Definition: usbport.h:249
USBD_STATUS USBDStatus
Definition: usbport.h:258
KSPIN_LOCK TransferSpinLock
Definition: usbport.h:265
struct _USBPORT_TRANSFER * ParentTransfer
Definition: usbport.h:264
PVOID MiniportTransfer
Definition: usbport.h:250
LIST_ENTRY SplitTransfersList
Definition: usbport.h:266
PVOID MapRegisterBase
Definition: usbport.h:261
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:254
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:253
SIZE_T FullTransferLength
Definition: usbport.h:252
LIST_ENTRY TransferLink
Definition: usbport.h:257
USBPORT_SCATTER_GATHER_LIST SgList
Definition: usbport.h:271
volatile PVOID Parameter
Definition: extypes.h:205
LIST_ENTRY List
Definition: extypes.h:203
PWORKER_THREAD_ROUTINE WorkerRoutine
Definition: extypes.h:204
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:282
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
VOID NTAPI USBPORT_DoneSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
Definition: trfsplit.c:278
VOID NTAPI USBPORT_SplitTransfer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PUSBPORT_TRANSFER Transfer, IN PLIST_ENTRY List)
Definition: trfsplit.c:232
#define MAXULONG
Definition: typedefs.h:251
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
@ UsbHighSpeed
Definition: usb200.h:44
VOID NTAPI USB2_InitController(IN PUSB2_HC_EXTENSION HcExtension)
Definition: usb2.c:2217
#define USBD_STATUS_DEVICE_GONE
Definition: usb.h:210
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
#define USBD_STATUS_CANCELED
Definition: usb.h:213
#define USBD_ERROR(Status)
Definition: usb.h:169
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
#define USBD_STATUS_NOT_SUPPORTED
Definition: usb.h:202
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:204
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
LONG USBD_STATUS
Definition: usb.h:165
#define USBD_STATUS_INVALID_URB_FUNCTION
Definition: usb.h:191
#define USBD_STATUS_BAD_START_FRAME
Definition: usb.h:198
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
#define DPRINT_TIMER(...)
Definition: usbdebug.h:147
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
#define DPRINT_INT(...)
Definition: usbdebug.h:146
_In_ PIO_STACK_LOCATION _In_ PURB Urb
Definition: usbdlib.h:267
USBPORT_REGISTRATION_PACKET RegPacket
Definition: usbehci.c:16
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
ULONG MPSTATUS
Definition: usbmport.h:131
#define USBPORT_HCI_MN
Definition: usbmport.h:4
#define MP_STATUS_UNSUCCESSFUL
Definition: usbmport.h:142
#define USBPORT_INVALIDATE_CONTROLLER_RESET
Definition: usbmport.h:489
#define USB_MINIPORT_FLAGS_NOT_LOCK_INT
Definition: usbmport.h:536
#define USBPORT_INVALIDATE_CONTROLLER_SURPRISE_REMOVE
Definition: usbmport.h:490
#define MP_STATUS_SUCCESS
Definition: usbmport.h:134
#define USB10_MINIPORT_INTERFACE_VERSION
Definition: usbmport.h:636
#define USBPORT_INVALIDATE_CONTROLLER_SOFT_INTERRUPT
Definition: usbmport.h:491
ULONG NTAPI USBPORT_InvalidateRootHub(PVOID MiniPortExtension)
Definition: roothub.c:916
VOID NTAPI USBPORT_RootHubPowerAndChirpAllCcPorts(IN PDEVICE_OBJECT FdoDevice)
Definition: roothub.c:962
BOOLEAN USBPORT_Initialized
Definition: usbport.c:23
VOID NTAPI USBPORT_SynchronizeControllersStart(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1507
USBD_STATUS NTAPI USBPORT_AllocateTransfer(IN PDEVICE_OBJECT FdoDevice, IN PURB Urb, IN PUSBPORT_DEVICE_HANDLE DeviceHandle, IN PIRP Irp, IN PRKEVENT Event)
Definition: usbport.c:2578
BOOLEAN NTAPI USBPORT_QueueDoneTransfer(IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
Definition: usbport.c:839
VOID NTAPI USBPORT_TransferFlushDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:825
MPSTATUS NTAPI USBPORT_GetMiniportRegistryKeyValue(IN PVOID MiniPortExtension, IN BOOL UseDriverKey, IN PCWSTR SourceString, IN SIZE_T LengthStr, IN PVOID Buffer, IN SIZE_T BufferLength)
Definition: usbport.c:373
MPSTATUS NTAPI USBPORT_ReadWriteConfigSpace(IN PVOID MiniPortExtension, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:456
VOID NTAPI USBPORT_WorkerThread(IN PVOID StartContext)
Definition: usbport.c:1403
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
VOID NTAPI USBPORT_DoneTransfer(IN PUSBPORT_TRANSFER Transfer)
Definition: usbport.c:724
VOID NTAPI USBPORT_FlushDoneTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:764
NTSTATUS NTAPI USBPORT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbport.c:1868
VOID NTAPI USBPORT_SynchronizeRootHubCallback(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT Usb2FdoDevice)
Definition: usbport.c:1292
ULONG NTAPI USBPORT_GetHciMn(VOID)
Definition: usbport.c:2839
ULONG NTAPI USBPORT_InvalidateController(IN PVOID MiniPortExtension, IN ULONG Type)
Definition: usbport.c:670
LIST_ENTRY USBPORT_USB2FdoList
Definition: usbport.c:20
VOID NTAPI USBPORT_AddUSB2Fdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:82
ULONG NTAPI USBPORT_InvalidateEndpoint(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2199
VOID NTAPI USBPORT_AddUSB1Fdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:66
VOID NTAPI USBPORT_RemoveUSBxFdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:98
VOID NTAPI USBPORT_IsrDpcHandler(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsDpcHandler)
Definition: usbport.c:941
PUSBPORT_MINIPORT_INTERFACE NTAPI USBPORT_FindMiniPort(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:1828
VOID NTAPI USBPORT_SoftInterrupt(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:611
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
Definition: usbport.c:1743
IO_ALLOCATION_ACTION NTAPI USBPORT_MapTransfer(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: usbport.c:2343
BOOLEAN NTAPI USBPORT_IsCompanionFdoExtension(IN PDEVICE_OBJECT USB2FdoDevice, IN PUSBPORT_DEVICE_EXTENSION USB1FdoExtension)
Definition: usbport.c:119
VOID NTAPI USBPORT_IsrDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1066
PDEVICE_OBJECT NTAPI USBPORT_FindUSB2Controller(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:27
VOID NTAPI USBPORT_StopWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1490
VOID NTAPI USBPORT_InvalidateControllerHandler(IN PDEVICE_OBJECT FdoDevice, IN ULONG Type)
Definition: usbport.c:635
BOOLEAN NTAPI USBPORT_InterruptService(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
Definition: usbport.c:1112
LIST_ENTRY USBPORT_MiniPortDrivers
Definition: usbport.c:18
NTSTATUS NTAPI USBPORT_GetRegistryKeyValueFullInfo(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT PdoDevice, IN BOOL UseDriverKey, IN PCWSTR SourceString, IN ULONG LengthStr, IN PVOID Buffer, IN ULONG BufferLength)
Definition: usbport.c:296
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
Definition: usbport.c:1805
ULONG NTAPI USBPORT_NotifyDoubleBuffer(IN PVOID MiniPortExtension, IN PVOID MiniPortTransfer, IN PVOID Buffer, IN SIZE_T Length)
Definition: usbport.c:690
NTSTATUS NTAPI USBPORT_RegisterUSBPortDriver(IN PDRIVER_OBJECT DriverObject, IN ULONG Version, IN PUSBPORT_REGISTRATION_PACKET RegPacket)
Definition: usbport.c:2846
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1146
NTSTATUS NTAPI USBPORT_SetRegistryKeyValue(IN PDEVICE_OBJECT DeviceObject, IN BOOL UseDriverKey, IN ULONG Type, IN PCWSTR ValueNameString, IN PVOID Data, IN ULONG DataSize)
Definition: usbport.c:248
VOID NTAPI USBPORT_FlushMapTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:2518
VOID NTAPI USBPORT_TimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1591
PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers(IN PDEVICE_OBJECT USB2FdoDevice, IN BOOLEAN IsObRefer, IN BOOLEAN IsFDOsReturned)
Definition: usbport.c:136
MPSTATUS NTAPI USBPORT_NtStatusToMpStatus(NTSTATUS NtStatus)
Definition: usbport.c:232
NTSTATUS NTAPI USBPORT_GetSetConfigSpaceData(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:410
NTSTATUS NTAPI USBPORT_CreateWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1462
PVOID NTAPI USBPORT_GetMappedVirtualAddress(IN ULONG PhysicalAddress, IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2170
VOID NTAPI USBPORT_MiniportInterrupts(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsEnable)
Definition: usbport.c:555
VOID NTAPI USBPORT_SoftInterruptDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:590
NTSTATUS NTAPI USBPORT_Dispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbport.c:2686
ULONG NTAPI USBPORT_RequestAsyncCallback(IN PVOID MiniPortExtension, IN ULONG TimerValue, IN PVOID Buffer, IN SIZE_T Length, IN ASYNC_TIMER_CALLBACK *Callback)
Definition: usbport.c:2114
VOID NTAPI USBPORT_AsyncTimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:2091
VOID NTAPI USBPORT_WorkerThreadHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1162
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2233
VOID NTAPI USBPORT_WorkerRequestDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:701
VOID NTAPI USBPORT_Unload(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:2005
LIST_ENTRY USBPORT_USB1FdoList
Definition: usbport.c:19
VOID NTAPI USBPORT_DoRootHubCallback(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1257
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
VOID NTAPI USBPORT_DpcHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:864
BOOLEAN NTAPI USBPORT_StartTimer(IN PDEVICE_OBJECT FdoDevice, IN ULONG Time)
Definition: usbport.c:1710
VOID NTAPI USBPORT_MiniportCompleteTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN USBD_STATUS USBDStatus, IN ULONG TransferLength)
Definition: usbport.c:2025
#define USBPORT_FLAG_WORKER_THREAD_ON
Definition: usbport.h:69
#define TRANSFER_FLAG_DMA_MAPPED
Definition: usbport.h:131
#define USBPORT_FLAG_WORKER_THREAD_EXIT
Definition: usbport.h:70
#define USBPORT_FLAG_RH_INIT_CALLBACK
Definition: usbport.h:84
#define USBPORT_FLAG_HC_WAKE_SUPPORT
Definition: usbport.h:76
#define USBPORT_DMA_DIRECTION_TO_DEVICE
Definition: usbport.h:42
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
Definition: usbport.h:102
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:155
#define USBPORT_FLAG_HC_POLLING
Definition: usbport.h:68
#define USBPORT_FLAG_PWR_AND_CHIRP_LOCK
Definition: usbport.h:82
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:98
#define USBPORT_TMFLAG_HC_SUSPENDED
Definition: usbport.h:94
#define USBPORT_FLAG_NO_HACTION
Definition: usbport.h:80
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:112
struct _USBPORT_COMMON_BUFFER_HEADER * PUSBPORT_COMMON_BUFFER_HEADER
#define TRANSFER_FLAG_HIGH_SPEED
Definition: usbport.h:132
#define USB_PORT_TAG
Definition: usbport.h:44
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
struct _USBPORT_TRANSFER USBPORT_TRANSFER
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:123
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:71
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:133
struct _USBPORT_COMMON_BUFFER_HEADER USBPORT_COMMON_BUFFER_HEADER
#define TRANSFER_FLAG_ISO
Definition: usbport.h:135
#define USBPORT_FLAG_POWER_AND_CHIRP_OK
Definition: usbport.h:83
#define USBPORT_PNP_STATE_STARTED
Definition: usbport.h:88
#define USBPORT_PNP_STATE_FAILED
Definition: usbport.h:89
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:78
#define USBPORT_TMFLAG_TIMER_QUEUED
Definition: usbport.h:93
#define TRANSFER_FLAG_COMPLETED
Definition: usbport.h:138
#define USBPORT_TMFLAG_HC_RESUME
Definition: usbport.h:95
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
#define USBPORT_FLAG_REGISTERED_FDO
Definition: usbport.h:79
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:113
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36
#define USBD_FLAG_ALLOCATED_MDL
Definition: usbport.h:121
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:137
struct _USB2_HC_EXTENSION * PUSB2_HC_EXTENSION
Definition: usbport.h:157
#define USBPORT_TMFLAG_IDLE_QUEUEITEM_ON
Definition: usbport.h:99
struct _USB2_HC_EXTENSION USB2_HC_EXTENSION
#define INVALIDATE_ENDPOINT_WORKER_DPC
Definition: usbport.h:38
#define USBPORT_FLAG_INTERRUPT_ENABLED
Definition: usbport.h:72
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_INTERRUPT_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFINTERRUPT * Interrupt
Definition: wdfinterrupt.h:379
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
@ CriticalWorkQueue
Definition: extypes.h:189
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:801
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3646
#define EVENT_INCREMENT
Definition: iotypes.h:597
#define IO_NO_INCREMENT
Definition: iotypes.h:598
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:213
enum _IO_ALLOCATION_ACTION IO_ALLOCATION_ACTION
@ DeallocateObjectKeepRegisters
Definition: iotypes.h:204
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
@ Suspended
Definition: ketypes.h:472
@ Executive
Definition: ketypes.h:467
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:740
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:739
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:741
#define ROUND_TO_PAGES(Size)
#define MmGetMdlVirtualAddress(_Mdl)
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define ObReferenceObject
Definition: obfuncs.h:204
#define NT_ASSERT
Definition: rtlfuncs.h:3327
__wchar_t WCHAR
Definition: xmlstorage.h:180