ReactOS  0.4.13-dev-464-g6b95727
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 
26 NTAPI
28 {
30  PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
31  KIRQL OldIrql;
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 
64 VOID
65 NTAPI
67 {
69 
70  DPRINT("USBPORT_AddUSB1Fdo: FdoDevice - %p\n", FdoDevice);
71 
72  FdoExtension = FdoDevice->DeviceExtension;
74 
76  &FdoExtension->ControllerLink,
78 }
79 
80 VOID
81 NTAPI
83 {
85 
86  DPRINT("USBPORT_AddUSB2Fdo: FdoDevice - %p\n", FdoDevice);
87 
88  FdoExtension = FdoDevice->DeviceExtension;
90 
92  &FdoExtension->ControllerLink,
94 }
95 
96 VOID
97 NTAPI
99 {
101  KIRQL OldIrql;
102 
103  DPRINT("USBPORT_RemoveUSBxFdo: FdoDevice - %p\n", FdoDevice);
104 
105  FdoExtension = FdoDevice->DeviceExtension;
106 
108  RemoveEntryList(&FdoExtension->ControllerLink);
110 
112 
113  FdoExtension->ControllerLink.Flink = NULL;
114  FdoExtension->ControllerLink.Blink = NULL;
115 }
116 
117 BOOLEAN
118 NTAPI
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 
135 NTAPI
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;
145  KIRQL OldIrql;
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),
181  USB_PORT_TAG);
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 
223 Exit:
224 
226 
227  return ControllersList;
228 }
229 
230 MPSTATUS
231 NTAPI
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  {
242  return MP_STATUS_UNSUCCESSFUL;
243  }
244 }
245 
246 NTSTATUS
247 NTAPI
249  IN BOOL UseDriverKey,
250  IN ULONG Type,
251  IN PCWSTR ValueNameString,
252  IN PVOID Data,
253  IN ULONG DataSize)
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 
294 NTSTATUS
295 NTAPI
297  IN PDEVICE_OBJECT PdoDevice,
298  IN BOOL UseDriverKey,
300  IN ULONG LengthStr,
301  IN PVOID Buffer,
303 {
308  ULONG LengthKey;
309 
310  DPRINT("USBPORT_GetRegistryKeyValue: UseDriverKey - %x, SourceString - %S, LengthStr - %x, Buffer - %p, BufferLength - %x\n",
311  UseDriverKey,
312  SourceString,
313  LengthStr,
314  Buffer,
315  BufferLength);
316 
317  if (UseDriverKey)
318  {
319  Status = IoOpenDeviceRegistryKey(PdoDevice,
322  &KeyHandle);
323  }
324  else
325  {
326  Status = IoOpenDeviceRegistryKey(PdoDevice,
329  &KeyHandle);
330  }
331 
332  if (NT_SUCCESS(Status))
333  {
335 
336  LengthKey = sizeof(KEY_VALUE_FULL_INFORMATION) +
337  LengthStr +
338  BufferLength;
339 
340  KeyValue = ExAllocatePoolWithTag(PagedPool,
341  LengthKey,
342  USB_PORT_TAG);
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,
359  BufferLength);
360  }
361 
362  ExFreePoolWithTag(KeyValue, USB_PORT_TAG);
363  }
364 
366  }
367 
368  return Status;
369 }
370 
371 MPSTATUS
372 NTAPI
374  IN BOOL UseDriverKey,
376  IN SIZE_T LengthStr,
377  IN PVOID Buffer,
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,
387  SourceString,
388  LengthStr,
389  Buffer,
390  BufferLength);
391 
392  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
393  sizeof(USBPORT_DEVICE_EXTENSION));
394 
395  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
396 
398  FdoExtension->CommonExtension.LowerPdoDevice,
399  UseDriverKey,
400  SourceString,
401  LengthStr,
402  Buffer,
403  BufferLength);
404 
406 }
407 
408 NTSTATUS
409 NTAPI
411  IN BOOLEAN IsReadData,
412  IN PVOID Buffer,
413  IN ULONG Offset,
414  IN ULONG Length)
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 
454 MPSTATUS
455 NTAPI
457  IN BOOLEAN IsReadData,
458  IN PVOID Buffer,
459  IN ULONG Offset,
460  IN ULONG Length)
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 -
470  sizeof(USBPORT_DEVICE_EXTENSION));
471 
472  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
473 
475  IsReadData,
476  Buffer,
477  Offset,
478  Length);
479 
481 }
482 
483 NTSTATUS
484 NTAPI
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  {
502  case USBD_STATUS_SUCCESS:
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 
541 NTSTATUS
542 NTAPI
543 USBPORT_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 
553 VOID
554 NTAPI
556  IN BOOLEAN IsEnable)
557 {
560  BOOLEAN IsLock;
561  KIRQL OldIrql;
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);
582  }
583 
584  if (IsLock)
585  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
586 }
587 
588 VOID
589 NTAPI
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 
609 VOID
610 NTAPI
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 
633 VOID
634 NTAPI
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 
668 ULONG
669 NTAPI
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 -
680  sizeof(USBPORT_DEVICE_EXTENSION));
681  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
682 
684 
685  return 0;
686 }
687 
688 ULONG
689 NTAPI
691  IN PVOID MiniPortTransfer,
692  IN PVOID Buffer,
693  IN SIZE_T Length)
694 {
695  DPRINT1("USBPORT_NotifyDoubleBuffer: UNIMPLEMENTED. FIXME. \n");
696  return 0;
697 }
698 
699 VOID
700 NTAPI
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 
722 VOID
723 NTAPI
725 {
726  PUSBPORT_ENDPOINT Endpoint;
727  PDEVICE_OBJECT FdoDevice;
729  PURB Urb;
730  PIRP Irp;
731  KIRQL CancelIrql;
732  KIRQL OldIrql;
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 
762 VOID
763 NTAPI
765 {
767  PLIST_ENTRY DoneTransferList;
768  PUSBPORT_TRANSFER Transfer;
769  PUSBPORT_ENDPOINT Endpoint;
770  ULONG TransferCount;
771  KIRQL OldIrql;
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  {
799  USBPORT_DoneSplitTransfer(Transfer);
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 
823 VOID
824 NTAPI
829 {
830  PDEVICE_OBJECT FdoDevice;
831 
832  DPRINT_CORE("USBPORT_TransferFlushDpc: ... \n");
833  FdoDevice = DeferredContext;
834  USBPORT_FlushDoneTransfers(FdoDevice);
835 }
836 
837 BOOLEAN
838 NTAPI
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 
862 VOID
863 NTAPI
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 ||
891  Endpoint->Flags & ENDPOINT_FLAG_ROOTHUB_EP0)
892  {
893  InterlockedDecrement(&Endpoint->LockCounter);
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 
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  {
931  USBPORT_SignalWorkerThread(FdoDevice);
932  }
933 
934  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
935 
936  USBPORT_FlushDoneTransfers(FdoDevice);
937 }
938 
939 VOID
940 NTAPI
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  for (List = ExInterlockedRemoveHeadList(&FdoExtension->EpStateChangeList,
965  &FdoExtension->EpStateChangeSpinLock);
966  List != NULL;
967  List = ExInterlockedRemoveHeadList(&FdoExtension->EpStateChangeList,
968  &FdoExtension->EpStateChangeSpinLock))
969  {
970  Endpoint = CONTAINING_RECORD(List,
972  StateChangeLink);
973 
974  DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint - %p\n", Endpoint);
975 
977 
978  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
979  FrameNumber = Packet->Get32BitFrameNumber(FdoExtension->MiniPortExt);
980  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
981 
982  if (FrameNumber <= Endpoint->FrameNumber &&
983  !(Endpoint->Flags & ENDPOINT_FLAG_NUKE))
984  {
986 
987  ExInterlockedInsertHeadList(&FdoExtension->EpStateChangeList,
988  &Endpoint->StateChangeLink,
989  &FdoExtension->EpStateChangeSpinLock);
990 
991  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportSpinLock);
992  Packet->InterruptNextSOF(FdoExtension->MiniPortExt);
993  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportSpinLock);
994 
995  break;
996  }
997 
999 
1001  Endpoint->StateLast = Endpoint->StateNext;
1003 
1004  DPRINT_CORE("USBPORT_IsrDpcHandler: Endpoint->StateLast - %x\n",
1005  Endpoint->StateLast);
1006 
1007  if (IsDpcHandler)
1008  {
1010  Endpoint,
1012  }
1013  else
1014  {
1016  Endpoint,
1018  }
1019  }
1020 
1021  if (IsDpcHandler)
1022  {
1023  USBPORT_DpcHandler(FdoDevice);
1024  }
1025 
1026  InterlockedDecrement(&FdoExtension->IsrDpcHandlerCounter);
1027 }
1028 
1029 VOID
1030 NTAPI
1035 {
1036  PDEVICE_OBJECT FdoDevice;
1039  BOOLEAN InterruptEnable;
1040 
1041  DPRINT_INT("USBPORT_IsrDpc: DeferredContext - %p, SystemArgument2 - %p\n",
1043  SystemArgument2);
1044 
1045  FdoDevice = DeferredContext;
1046  FdoExtension = FdoDevice->DeviceExtension;
1047  Packet = &FdoExtension->MiniPortInterface->Packet;
1048 
1049  if (SystemArgument2)
1050  {
1051  InterlockedDecrement(&FdoExtension->IsrDpcCounter);
1052  }
1053 
1054  KeAcquireSpinLockAtDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1055  InterruptEnable = (FdoExtension->Flags & USBPORT_FLAG_INTERRUPT_ENABLED) ==
1057 
1058  Packet->InterruptDpc(FdoExtension->MiniPortExt, InterruptEnable);
1059 
1060  KeReleaseSpinLockFromDpcLevel(&FdoExtension->MiniportInterruptsSpinLock);
1061 
1062  if (FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND &&
1063  FdoExtension->TimerFlags & USBPORT_TMFLAG_WAKE)
1064  {
1065  USBPORT_CompletePdoWaitWake(FdoDevice);
1066  }
1067  else
1068  {
1069  USBPORT_IsrDpcHandler(FdoDevice, TRUE);
1070  }
1071 
1072  DPRINT_INT("USBPORT_IsrDpc: exit\n");
1073 }
1074 
1075 BOOLEAN
1076 NTAPI
1079 {
1080  PDEVICE_OBJECT FdoDevice;
1083  BOOLEAN Result = FALSE;
1084 
1085  FdoDevice = ServiceContext;
1086  FdoExtension = FdoDevice->DeviceExtension;
1087  Packet = &FdoExtension->MiniPortInterface->Packet;
1088 
1089  DPRINT_INT("USBPORT_InterruptService: FdoExtension[%p]->Flags - %08X\n",
1090  FdoExtension,
1091  FdoExtension->Flags);
1092 
1095  {
1096  Result = Packet->InterruptService(FdoExtension->MiniPortExt);
1097 
1098  if (Result)
1099  {
1100  KeInsertQueueDpc(&FdoExtension->IsrDpc, NULL, NULL);
1101  }
1102  }
1103 
1104  DPRINT_INT("USBPORT_InterruptService: return - %x\n", Result);
1105 
1106  return Result;
1107 }
1108 
1109 VOID
1110 NTAPI
1112 {
1114  KIRQL OldIrql;
1115 
1116  DPRINT_CORE("USBPORT_SignalWorkerThread ... \n");
1117 
1118  FdoExtension = FdoDevice->DeviceExtension;
1119 
1120  KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1121  KeSetEvent(&FdoExtension->WorkerThreadEvent, EVENT_INCREMENT, FALSE);
1122  KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1123 }
1124 
1125 VOID
1126 NTAPI
1128 {
1131  PLIST_ENTRY workerList;
1132  KIRQL OldIrql;
1133  PUSBPORT_ENDPOINT Endpoint;
1134  LIST_ENTRY list;
1135  BOOLEAN Result;
1136 
1137  DPRINT_CORE("USBPORT_WorkerThreadHandler: ... \n");
1138 
1139  FdoExtension = FdoDevice->DeviceExtension;
1140  Packet = &FdoExtension->MiniPortInterface->Packet;
1141 
1142  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1143 
1144  if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
1145  {
1146  Packet->CheckController(FdoExtension->MiniPortExt);
1147  }
1148 
1149  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1150 
1152 
1153  USBPORT_FlushAllEndpoints(FdoDevice);
1154 
1155  while (TRUE)
1156  {
1158  KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1159 
1160  workerList = &FdoExtension->WorkerList;
1161 
1162  if (IsListEmpty(workerList))
1163  break;
1164 
1165  Endpoint = CONTAINING_RECORD(workerList->Flink,
1167  WorkerLink);
1168 
1169  DPRINT_CORE("USBPORT_WorkerThreadHandler: Endpoint - %p\n", Endpoint);
1170 
1171  RemoveHeadList(workerList);
1172  Endpoint->WorkerLink.Blink = NULL;
1173  Endpoint->WorkerLink.Flink = NULL;
1174 
1175  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1176 
1177  Result = USBPORT_EndpointWorker(Endpoint, FALSE);
1178  KeAcquireSpinLockAtDpcLevel(&FdoExtension->EndpointListSpinLock);
1179 
1180  if (Result)
1181  {
1182  if (Endpoint->FlushAbortLink.Flink == NULL ||
1183  Endpoint->FlushAbortLink.Blink == NULL)
1184  {
1185  InsertTailList(&list, &Endpoint->FlushAbortLink);
1186  }
1187  }
1188 
1189  while (!IsListEmpty(&list))
1190  {
1191  Endpoint = CONTAINING_RECORD(list.Flink,
1193  FlushAbortLink);
1194 
1195  RemoveHeadList(&list);
1196 
1197  Endpoint->FlushAbortLink.Flink = NULL;
1198  Endpoint->FlushAbortLink.Blink = NULL;
1199 
1200  if (Endpoint->WorkerLink.Flink == NULL ||
1201  Endpoint->WorkerLink.Blink == NULL)
1202  {
1203  InsertTailList(&FdoExtension->WorkerList,
1204  &Endpoint->WorkerLink);
1205 
1206  USBPORT_SignalWorkerThread(FdoDevice);
1207  }
1208  }
1209 
1210  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1212  }
1213 
1214  KeReleaseSpinLockFromDpcLevel(&FdoExtension->EndpointListSpinLock);
1216 
1218 }
1219 
1220 VOID
1221 NTAPI
1223 {
1225  PDEVICE_OBJECT PdoDevice;
1227  PRH_INIT_CALLBACK RootHubInitCallback;
1228  PVOID RootHubInitContext;
1229 
1230  FdoExtension = FdoDevice->DeviceExtension;
1231 
1232  DPRINT("USBPORT_DoRootHubCallback: FdoDevice - %p\n", FdoDevice);
1233 
1234  PdoDevice = FdoExtension->RootHubPdo;
1235 
1236  if (PdoDevice)
1237  {
1238  PdoExtension = PdoDevice->DeviceExtension;
1239 
1240  RootHubInitContext = PdoExtension->RootHubInitContext;
1241  RootHubInitCallback = PdoExtension->RootHubInitCallback;
1242 
1243  PdoExtension->RootHubInitCallback = NULL;
1244  PdoExtension->RootHubInitContext = NULL;
1245 
1246  if (RootHubInitCallback)
1247  {
1248  RootHubInitCallback(RootHubInitContext);
1249  }
1250  }
1251 
1252  DPRINT("USBPORT_DoRootHubCallback: exit\n");
1253 }
1254 
1255 VOID
1256 NTAPI
1258  IN PDEVICE_OBJECT Usb2FdoDevice)
1259 {
1262  PUSBPORT_DEVICE_EXTENSION Usb2FdoExtension;
1263  PDEVICE_RELATIONS CompanionControllersList;
1264  PUSBPORT_DEVICE_EXTENSION CompanionFdoExtension;
1266  ULONG ix;
1267 
1268  DPRINT("USBPORT_SynchronizeRootHubCallback: FdoDevice - %p, Usb2FdoDevice - %p\n",
1269  FdoDevice,
1270  Usb2FdoDevice);
1271 
1272  FdoExtension = FdoDevice->DeviceExtension;
1273  Packet = &FdoExtension->MiniPortInterface->Packet;
1274 
1275  if (Usb2FdoDevice == NULL &&
1276  !(Packet->MiniPortFlags & USB_MINIPORT_FLAGS_USB2))
1277  {
1278  /* Not Companion USB11 Controller */
1279  USBPORT_DoRootHubCallback(FdoDevice);
1280 
1282  InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1283 
1284  DPRINT("USBPORT_SynchronizeRootHubCallback: exit \n");
1285  return;
1286  }
1287 
1288  /* USB2 or Companion USB11 */
1289 
1290  DPRINT("USBPORT_SynchronizeRootHubCallback: FdoExtension->Flags - %p\n",
1291  FdoExtension->Flags);
1292 
1293  if (!(FdoExtension->Flags & USBPORT_FLAG_COMPANION_HC))
1294  {
1295  KeWaitForSingleObject(&FdoExtension->ControllerSemaphore,
1296  Executive,
1297  KernelMode,
1298  FALSE,
1299  NULL);
1300 
1302 
1303  if (!(FdoExtension->Flags & (USBPORT_FLAG_HC_SUSPEND |
1305  {
1308  }
1309 
1311 
1312  KeReleaseSemaphore(&FdoExtension->ControllerSemaphore,
1314  1,
1315  FALSE);
1316 
1317  CompanionControllersList = USBPORT_FindCompanionControllers(FdoDevice,
1318  FALSE,
1319  TRUE);
1320 
1321  if (CompanionControllersList)
1322  {
1323  Entry = &CompanionControllersList->Objects[0];
1324 
1325  for (ix = 0; ix < CompanionControllersList->Count; ++ix)
1326  {
1327  CompanionFdoExtension = ((*Entry)->DeviceExtension);
1328 
1329  InterlockedCompareExchange(&CompanionFdoExtension->RHInitCallBackLock,
1330  0,
1331  1);
1332 
1333  ++Entry;
1334  }
1335 
1336  ExFreePoolWithTag(CompanionControllersList, USB_PORT_TAG);
1337  }
1338 
1339  USBPORT_DoRootHubCallback(FdoDevice);
1340 
1342  InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 0, 1);
1343  }
1344  else
1345  {
1346  Usb2FdoExtension = Usb2FdoDevice->DeviceExtension;
1347 
1348  USBPORT_Wait(FdoDevice, 50);
1349 
1350  while (FdoExtension->RHInitCallBackLock)
1351  {
1352  USBPORT_Wait(FdoDevice, 10);
1353 
1354  Usb2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1355  USBPORT_SignalWorkerThread(Usb2FdoDevice);
1356  }
1357 
1358  USBPORT_DoRootHubCallback(FdoDevice);
1359 
1361  }
1362 
1363  DPRINT("USBPORT_SynchronizeRootHubCallback: exit \n");
1364 }
1365 
1366 VOID
1367 NTAPI
1369 {
1370  PDEVICE_OBJECT FdoDevice;
1372  LARGE_INTEGER OldTime;
1373  LARGE_INTEGER NewTime;
1374  KIRQL OldIrql;
1375 
1376  DPRINT_CORE("USBPORT_WorkerThread ... \n");
1377 
1378  FdoDevice = StartContext;
1379  FdoExtension = FdoDevice->DeviceExtension;
1380 
1381  FdoExtension->WorkerThread = KeGetCurrentThread();
1382 
1383  do
1384  {
1385  KeQuerySystemTime(&OldTime);
1386 
1387  KeWaitForSingleObject(&FdoExtension->WorkerThreadEvent,
1388  Suspended,
1389  KernelMode,
1390  FALSE,
1391  NULL);
1392 
1393  KeQuerySystemTime(&NewTime);
1394 
1395  KeAcquireSpinLock(&FdoExtension->WorkerThreadEventSpinLock, &OldIrql);
1396  KeClearEvent(&FdoExtension->WorkerThreadEvent);
1397  KeReleaseSpinLock(&FdoExtension->WorkerThreadEventSpinLock, OldIrql);
1398  DPRINT_CORE("USBPORT_WorkerThread: run \n");
1399 
1400  if (FdoExtension->MiniPortFlags & USBPORT_MPFLAG_INTERRUPTS_ENABLED)
1401  {
1402  USBPORT_DoSetPowerD0(FdoDevice);
1403 
1405  {
1406  PDEVICE_OBJECT USB2FdoDevice = NULL;
1407 
1408  USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1409  USBPORT_SynchronizeRootHubCallback(FdoDevice, USB2FdoDevice);
1410  }
1411  }
1412 
1413  USBPORT_WorkerThreadHandler(FdoDevice);
1414  }
1415  while (!(FdoExtension->Flags & USBPORT_FLAG_WORKER_THREAD_ON));
1416 
1418 }
1419 
1420 NTSTATUS
1421 NTAPI
1423 {
1425  NTSTATUS Status;
1426 
1427  DPRINT("USBPORT_CreateWorkerThread ... \n");
1428 
1429  FdoExtension = FdoDevice->DeviceExtension;
1430 
1432 
1433  KeInitializeEvent(&FdoExtension->WorkerThreadEvent,
1435  FALSE);
1436 
1437  Status = PsCreateSystemThread(&FdoExtension->WorkerThreadHandle,
1439  NULL,
1440  NULL,
1441  NULL,
1443  (PVOID)FdoDevice);
1444 
1445  return Status;
1446 }
1447 
1448 VOID
1449 NTAPI
1451 {
1453  PDEVICE_OBJECT PdoDevice;
1455  PDEVICE_OBJECT USB2FdoDevice = NULL;
1456  PUSBPORT_DEVICE_EXTENSION USB2FdoExtension;
1457  BOOLEAN IsOn;
1458 
1459  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: FdoDevice - %p\n",
1460  FdoDevice);
1461 
1462  FdoExtension = FdoDevice->DeviceExtension;
1463 
1464  PdoDevice = FdoExtension->RootHubPdo;
1465 
1466  if (!PdoDevice)
1467  {
1468  return;
1469  }
1470 
1471  PdoExtension = PdoDevice->DeviceExtension;
1472 
1473  if (PdoExtension->RootHubInitCallback == NULL ||
1475  {
1476  return;
1477  }
1478 
1479  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: Flags - %p\n",
1480  FdoExtension->Flags);
1481 
1483  {
1484  IsOn = FALSE;
1485 
1486  USB2FdoDevice = USBPORT_FindUSB2Controller(FdoDevice);
1487 
1488  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: USB2FdoDevice - %p\n",
1489  USB2FdoDevice);
1490 
1491  if (USB2FdoDevice)
1492  {
1493  USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1494 
1495  if (USB2FdoExtension->CommonExtension.PnpStateFlags &
1497  {
1498  IsOn = TRUE;
1499  }
1500  }
1501 
1502  if (!(FdoExtension->Flags & USBPORT_FLAG_NO_HACTION))
1503  {
1504  goto Start;
1505  }
1506 
1507  USB2FdoDevice = NULL;
1508  }
1509 
1510  IsOn = TRUE;
1511 
1512  Start:
1513 
1514  if (IsOn &&
1515  !InterlockedCompareExchange(&FdoExtension->RHInitCallBackLock, 1, 0))
1516  {
1518  USBPORT_SignalWorkerThread(FdoDevice);
1519 
1520  if (USB2FdoDevice)
1521  {
1522  USB2FdoExtension = USB2FdoDevice->DeviceExtension;
1523 
1524  USB2FdoExtension->Flags |= USBPORT_FLAG_RH_INIT_CALLBACK;
1525  USBPORT_SignalWorkerThread(USB2FdoDevice);
1526  }
1527  }
1528 
1529  DPRINT_TIMER("USBPORT_SynchronizeControllersStart: exit\n");
1530 }
1531 
1532 VOID
1533 NTAPI
1538 {
1539  PDEVICE_OBJECT FdoDevice;
1542  LARGE_INTEGER DueTime = {{0, 0}};
1543  ULONG TimerFlags;
1544  PTIMER_WORK_QUEUE_ITEM IdleQueueItem;
1545  KIRQL OldIrql;
1546  KIRQL TimerOldIrql;
1547 
1548  DPRINT_TIMER("USBPORT_TimerDpc: Dpc - %p, DeferredContext - %p\n",
1549  Dpc,
1550  DeferredContext);
1551 
1552  FdoDevice = DeferredContext;
1553  FdoExtension = FdoDevice->DeviceExtension;
1554  Packet = &FdoExtension->MiniPortInterface->Packet;
1555 
1556  KeAcquireSpinLock(&FdoExtension->TimerFlagsSpinLock, &TimerOldIrql);
1557 
1558  TimerFlags = FdoExtension->TimerFlags;
1559 
1560  DPRINT_TIMER("USBPORT_TimerDpc: Flags - %p, TimerFlags - %p\n",
1561  FdoExtension->Flags,
1562  TimerFlags);
1563 
1564  if (FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND &&
1566  !(TimerFlags & USBPORT_TMFLAG_HC_RESUME))
1567  {
1568  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1569  Packet->PollController(FdoExtension->MiniPortExt);
1570  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1571  }
1572 
1574 
1575  if (TimerFlags & USBPORT_TMFLAG_HC_SUSPENDED)
1576  {
1577  USBPORT_BadRequestFlush(FdoDevice);
1578  goto Exit;
1579  }
1580 
1581  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1582 
1583  if (!(FdoExtension->Flags & USBPORT_FLAG_HC_SUSPEND))
1584  {
1585  Packet->CheckController(FdoExtension->MiniPortExt);
1586  }
1587 
1588  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1589 
1591  {
1592  KeAcquireSpinLock(&FdoExtension->MiniportSpinLock, &OldIrql);
1593  Packet->PollController(FdoExtension->MiniPortExt);
1594  KeReleaseSpinLock(&FdoExtension->MiniportSpinLock, OldIrql);
1595  }
1596 
1597  USBPORT_IsrDpcHandler(FdoDevice, FALSE);
1598 
1599  DPRINT_TIMER("USBPORT_TimerDpc: USBPORT_TimeoutAllEndpoints UNIMPLEMENTED.\n");
1600  //USBPORT_TimeoutAllEndpoints(FdoDevice);
1601  DPRINT_TIMER("USBPORT_TimerDpc: USBPORT_CheckIdleEndpoints UNIMPLEMENTED.\n");
1602  //USBPORT_CheckIdleEndpoints(FdoDevice);
1603 
1604  USBPORT_BadRequestFlush(FdoDevice);
1605 
1606  if (FdoExtension->IdleLockCounter > -1 &&
1607  !(TimerFlags & USBPORT_TMFLAG_IDLE_QUEUEITEM_ON))
1608  {
1609  IdleQueueItem = ExAllocatePoolWithTag(NonPagedPool,
1610  sizeof(TIMER_WORK_QUEUE_ITEM),
1611  USB_PORT_TAG);
1612 
1613  DPRINT("USBPORT_TimerDpc: IdleLockCounter - %x, IdleQueueItem - %p\n",
1614  FdoExtension->IdleLockCounter,
1615  IdleQueueItem);
1616 
1617  if (IdleQueueItem)
1618  {
1619  RtlZeroMemory(IdleQueueItem, sizeof(TIMER_WORK_QUEUE_ITEM));
1620 
1621  IdleQueueItem->WqItem.List.Flink = NULL;
1623  IdleQueueItem->WqItem.Parameter = IdleQueueItem;
1624 
1625  IdleQueueItem->FdoDevice = FdoDevice;
1626  IdleQueueItem->Context = 0;
1627 
1629 
1630  ExQueueWorkItem(&IdleQueueItem->WqItem, CriticalWorkQueue);
1631  }
1632  }
1633 
1634 Exit:
1635 
1636  KeReleaseSpinLock(&FdoExtension->TimerFlagsSpinLock, TimerOldIrql);
1637 
1638  if (TimerFlags & USBPORT_TMFLAG_TIMER_QUEUED)
1639  {
1640  DueTime.QuadPart -= FdoExtension->TimerValue * 10000 +
1641  (KeQueryTimeIncrement() - 1);
1642 
1643  KeSetTimer(&FdoExtension->TimerObject,
1644  DueTime,
1645  &FdoExtension->TimerDpc);
1646  }
1647 
1648  DPRINT_TIMER("USBPORT_TimerDpc: exit\n");
1649 }
1650 
1651 BOOLEAN
1652 NTAPI
1654  IN ULONG Time)
1655 {
1657  LARGE_INTEGER DueTime = {{0, 0}};
1658  ULONG TimeIncrement;
1659  BOOLEAN Result;
1660 
1661  DPRINT_TIMER("USBPORT_StartTimer: FdoDevice - %p, Time - %x\n",
1662  FdoDevice,
1663  Time);
1664 
1665  FdoExtension = FdoDevice->DeviceExtension;
1666 
1667  TimeIncrement = KeQueryTimeIncrement();
1668 
1670  FdoExtension->TimerValue = Time;
1671 
1672  KeInitializeTimer(&FdoExtension->TimerObject);
1673  KeInitializeDpc(&FdoExtension->TimerDpc, USBPORT_TimerDpc, FdoDevice);
1674 
1675  DueTime.QuadPart -= 10000 * Time + (TimeIncrement - 1);
1676 
1677  Result = KeSetTimer(&FdoExtension->TimerObject,
1678  DueTime,
1679  &FdoExtension->TimerDpc);
1680 
1681  return Result;
1682 }
1683 
1685 NTAPI
1688 {
1689  PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer = NULL;
1691  PDMA_ADAPTER DmaAdapter;
1692  PDMA_OPERATIONS DmaOperations;
1693  SIZE_T HeaderSize;
1694  ULONG Length = 0;
1695  ULONG LengthPadded;
1696  PHYSICAL_ADDRESS LogicalAddress;
1697  ULONG_PTR BaseVA;
1698  ULONG_PTR StartBufferVA;
1699  ULONG StartBufferPA;
1700 
1701  DPRINT("USBPORT_AllocateCommonBuffer: FdoDevice - %p, BufferLength - %p\n",
1702  FdoDevice,
1703  BufferLength);
1704 
1705  if (BufferLength == 0)
1706  goto Exit;
1707 
1708  FdoExtension = FdoDevice->DeviceExtension;
1709 
1710  DmaAdapter = FdoExtension->DmaAdapter;
1711  DmaOperations = DmaAdapter->DmaOperations;
1712 
1713  HeaderSize = sizeof(USBPORT_COMMON_BUFFER_HEADER);
1714  Length = ROUND_TO_PAGES(BufferLength + HeaderSize);
1715  LengthPadded = Length - (BufferLength + HeaderSize);
1716 
1717  BaseVA = (ULONG_PTR)DmaOperations->AllocateCommonBuffer(DmaAdapter,
1718  Length,
1719  &LogicalAddress,
1720  TRUE);
1721 
1722  if (!BaseVA)
1723  goto Exit;
1724 
1725  StartBufferVA = BaseVA & ~(PAGE_SIZE - 1);
1726  StartBufferPA = LogicalAddress.LowPart & ~(PAGE_SIZE - 1);
1727 
1728  HeaderBuffer = (PUSBPORT_COMMON_BUFFER_HEADER)(StartBufferVA +
1729  BufferLength +
1730  LengthPadded);
1731 
1732  HeaderBuffer->Length = Length;
1733  HeaderBuffer->BaseVA = BaseVA;
1734  HeaderBuffer->LogicalAddress = LogicalAddress;
1735 
1736  HeaderBuffer->BufferLength = BufferLength + LengthPadded;
1737  HeaderBuffer->VirtualAddress = StartBufferVA;
1738  HeaderBuffer->PhysicalAddress = StartBufferPA;
1739 
1740  RtlZeroMemory((PVOID)StartBufferVA, BufferLength + LengthPadded);
1741 
1742 Exit:
1743  return HeaderBuffer;
1744 }
1745 
1746 VOID
1747 NTAPI
1749  IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
1750 {
1752  PDMA_ADAPTER DmaAdapter;
1753  PDMA_OPERATIONS DmaOperations;
1754 
1755  DPRINT("USBPORT_FreeCommonBuffer: ... \n");
1756 
1757  FdoExtension = FdoDevice->DeviceExtension;
1758 
1759  DmaAdapter = FdoExtension->DmaAdapter;
1760  DmaOperations = DmaAdapter->DmaOperations;
1761 
1762  DmaOperations->FreeCommonBuffer(FdoExtension->DmaAdapter,
1763  HeaderBuffer->Length,
1764  HeaderBuffer->LogicalAddress,
1765  (PVOID)HeaderBuffer->VirtualAddress,
1766  TRUE);
1767 }
1768 
1770 NTAPI
1772 {
1773  KIRQL OldIrql;
1774  PLIST_ENTRY List;
1775  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1776  BOOLEAN IsFound = FALSE;
1777 
1778  DPRINT("USBPORT_FindMiniPort: ... \n");
1779 
1781 
1784  List = List->Flink)
1785  {
1786  MiniPortInterface = CONTAINING_RECORD(List,
1788  DriverLink);
1789 
1790  if (MiniPortInterface->DriverObject == DriverObject)
1791  {
1792  DPRINT("USBPORT_FindMiniPort: find MiniPortInterface - %p\n",
1793  MiniPortInterface);
1794 
1795  IsFound = TRUE;
1796  break;
1797  }
1798  }
1799 
1801 
1802  if (IsFound)
1803  return MiniPortInterface;
1804  else
1805  return NULL;
1806 
1807 }
1808 
1809 NTSTATUS
1810 NTAPI
1813 {
1814  NTSTATUS Status;
1815  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1816  ULONG DeviceNumber = 0;
1817  WCHAR CharDeviceName[64];
1821  PUSBPORT_COMMON_DEVICE_EXTENSION FdoCommonExtension;
1822  PDEVICE_OBJECT LowerDevice;
1823  ULONG Length;
1824 
1825  DPRINT("USBPORT_AddDevice: DriverObject - %p, PhysicalDeviceObject - %p\n",
1826  DriverObject,
1828 
1829  MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
1830 
1831  if (!MiniPortInterface)
1832  {
1833  DPRINT("USBPORT_AddDevice: USBPORT_FindMiniPort not found MiniPortInterface\n");
1834  return STATUS_UNSUCCESSFUL;
1835  }
1836 
1837  while (TRUE)
1838  {
1839  /* Construct device name */
1840  RtlStringCbPrintfW(CharDeviceName,
1841  sizeof(CharDeviceName),
1842  L"\\Device\\USBFDO-%d",
1843  DeviceNumber);
1844 
1845  RtlInitUnicodeString(&DeviceName, CharDeviceName);
1846 
1847  ASSERT(MiniPortInterface->Packet.MiniPortExtensionSize <=
1849  Length = (ULONG)(sizeof(USBPORT_DEVICE_EXTENSION) +
1850  MiniPortInterface->Packet.MiniPortExtensionSize +
1851  sizeof(USB2_HC_EXTENSION));
1852 
1853  /* Create device */
1855  Length,
1856  &DeviceName,
1858  0,
1859  FALSE,
1860  &DeviceObject);
1861 
1862  /* Check for success */
1863  if (NT_SUCCESS(Status)) break;
1864 
1865  /* Is there a device object with that same name */
1866  if ((Status == STATUS_OBJECT_NAME_EXISTS) ||
1868  {
1869  /* Try the next name */
1870  DeviceNumber++;
1871  continue;
1872  }
1873 
1874  /* Bail out on other errors */
1875  if (!NT_SUCCESS(Status))
1876  {
1877  DPRINT1("USBPORT_AddDevice: failed to create %wZ, Status %x\n",
1878  &DeviceName,
1879  Status);
1880 
1881  return Status;
1882  }
1883  }
1884 
1885  DPRINT("USBPORT_AddDevice: created device %p <%wZ>, Status %x\n",
1886  DeviceObject,
1887  &DeviceName,
1888  Status);
1889 
1891  FdoCommonExtension = &FdoExtension->CommonExtension;
1892 
1894 
1895  FdoCommonExtension->SelfDevice = DeviceObject;
1896  FdoCommonExtension->LowerPdoDevice = PhysicalDeviceObject;
1897  FdoCommonExtension->IsPDO = FALSE;
1898 
1901 
1902  FdoCommonExtension->LowerDevice = LowerDevice;
1903 
1904  FdoCommonExtension->DevicePowerState = PowerDeviceD3;
1905 
1906  FdoExtension->MiniPortExt = (PVOID)((ULONG_PTR)FdoExtension +
1907  sizeof(USBPORT_DEVICE_EXTENSION));
1908 
1909  if (MiniPortInterface->Packet.MiniPortFlags & USB_MINIPORT_FLAGS_USB2)
1910  {
1911  FdoExtension->Usb2Extension =
1912  (PUSB2_HC_EXTENSION)((ULONG_PTR)FdoExtension->MiniPortExt +
1913  MiniPortInterface->Packet.MiniPortExtensionSize);
1914 
1915  DPRINT("USBPORT_AddDevice: Usb2Extension - %p\n",
1916  FdoExtension->Usb2Extension);
1917 
1918  USB2_InitController(FdoExtension->Usb2Extension);
1919  }
1920  else
1921  {
1922  FdoExtension->Usb2Extension = NULL;
1923  }
1924 
1925  FdoExtension->MiniPortInterface = MiniPortInterface;
1926  FdoExtension->FdoNameNumber = DeviceNumber;
1927 
1928  KeInitializeSemaphore(&FdoExtension->DeviceSemaphore, 1, 1);
1929  KeInitializeSemaphore(&FdoExtension->ControllerSemaphore, 1, 1);
1930 
1931  InitializeListHead(&FdoExtension->EndpointList);
1932  InitializeListHead(&FdoExtension->DoneTransferList);
1933  InitializeListHead(&FdoExtension->WorkerList);
1934  InitializeListHead(&FdoExtension->EpStateChangeList);
1935  InitializeListHead(&FdoExtension->MapTransferList);
1936  InitializeListHead(&FdoExtension->DeviceHandleList);
1937  InitializeListHead(&FdoExtension->IdleIrpList);
1938  InitializeListHead(&FdoExtension->BadRequestList);
1939  InitializeListHead(&FdoExtension->EndpointClosedList);
1940 
1942 
1943  return Status;
1944 }
1945 
1946 VOID
1947 NTAPI
1949 {
1950  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
1951 
1952  DPRINT1("USBPORT_Unload: FIXME!\n");
1953 
1954  MiniPortInterface = USBPORT_FindMiniPort(DriverObject);
1955 
1956  if (!MiniPortInterface)
1957  {
1958  DPRINT("USBPORT_Unload: CRITICAL ERROR!!! Not found MiniPortInterface\n");
1959  KeBugCheckEx(BUGCODE_USB_DRIVER, 1, 0, 0, 0);
1960  }
1961 
1962  DPRINT1("USBPORT_Unload: UNIMPLEMENTED. FIXME. \n");
1963  //MiniPortInterface->DriverUnload(DriverObject); // Call MiniPort _HCI_Unload
1964 }
1965 
1966 VOID
1967 NTAPI
1969  IN PVOID MiniPortEndpoint,
1970  IN PVOID TransferParameters,
1971  IN USBD_STATUS USBDStatus,
1972  IN ULONG TransferLength)
1973 {
1974  PUSBPORT_TRANSFER Transfer;
1975  PUSBPORT_TRANSFER ParentTransfer;
1976  PUSBPORT_TRANSFER SplitTransfer;
1977  PLIST_ENTRY SplitHead;
1979  KIRQL OldIrql;
1980 
1981  DPRINT_CORE("USBPORT_MiniportCompleteTransfer: USBDStatus - %x, TransferLength - %x\n",
1982  USBDStatus,
1983  TransferLength);
1984 
1985  Transfer = CONTAINING_RECORD(TransferParameters,
1987  TransferParameters);
1988 
1989  Transfer->Flags |= TRANSFER_FLAG_COMPLETED;
1990  Transfer->CompletedTransferLen = TransferLength;
1991 
1992  if (((Transfer->Flags & TRANSFER_FLAG_SPLITED) == 0) ||
1993  TransferLength >= Transfer->TransferParameters.TransferBufferLength)
1994  {
1995  goto Exit;
1996  }
1997 
1998  ParentTransfer = Transfer->ParentTransfer;
1999 
2000  KeAcquireSpinLock(&ParentTransfer->TransferSpinLock, &OldIrql);
2001 
2002  if (IsListEmpty(&ParentTransfer->SplitTransfersList))
2003  {
2004  goto Exit;
2005  }
2006 
2007  SplitHead = &ParentTransfer->SplitTransfersList;
2008  Entry = SplitHead->Flink;
2009 
2010  while (Entry && !IsListEmpty(SplitHead))
2011  {
2012  SplitTransfer = CONTAINING_RECORD(Entry,
2014  SplitLink);
2015 
2016  if (!(SplitTransfer->Flags & TRANSFER_FLAG_SUBMITED))
2017  {
2018  DPRINT1("USBPORT_MiniportCompleteTransfer: SplitTransfer->Flags - %X\n",
2019  SplitTransfer->Flags);
2020  //Add TRANSFER_FLAG_xxx
2021  }
2022 
2023  Entry = Entry->Flink;
2024  }
2025 
2026  KeReleaseSpinLock(&ParentTransfer->TransferSpinLock, OldIrql);
2027 
2028 Exit:
2029  USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2030 }
2031 
2032 VOID
2033 NTAPI
2038 {
2039  PDEVICE_OBJECT FdoDevice;
2041  PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2042 
2043  DPRINT("USBPORT_AsyncTimerDpc: ... \n");
2044 
2045  AsyncCallbackData = DeferredContext;
2046  FdoDevice = AsyncCallbackData->FdoDevice;
2047  FdoExtension = FdoDevice->DeviceExtension;
2048 
2049  (*AsyncCallbackData->CallbackFunction)(FdoExtension->MiniPortExt,
2050  &AsyncCallbackData->CallbackContext);
2051 
2052  ExFreePoolWithTag(AsyncCallbackData, USB_PORT_TAG);
2053 }
2054 
2055 ULONG
2056 NTAPI
2058  IN ULONG TimerValue,
2059  IN PVOID Buffer,
2060  IN SIZE_T Length,
2061  IN ASYNC_TIMER_CALLBACK * Callback)
2062 {
2064  PDEVICE_OBJECT FdoDevice;
2065  PUSBPORT_ASYNC_CALLBACK_DATA AsyncCallbackData;
2066  LARGE_INTEGER DueTime = {{0, 0}};
2067 
2068  DPRINT("USBPORT_RequestAsyncCallback: ... \n");
2069 
2070  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2071  sizeof(USBPORT_DEVICE_EXTENSION));
2072 
2073  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2074 
2075  AsyncCallbackData = ExAllocatePoolWithTag(NonPagedPool,
2077  USB_PORT_TAG);
2078 
2079  if (!AsyncCallbackData)
2080  {
2081  DPRINT1("USBPORT_RequestAsyncCallback: Not allocated AsyncCallbackData!\n");
2082  return 0;
2083  }
2084 
2085  RtlZeroMemory(AsyncCallbackData,
2087 
2088  if (Length)
2089  {
2090  RtlCopyMemory(&AsyncCallbackData->CallbackContext, Buffer, Length);
2091  }
2092 
2093  AsyncCallbackData->FdoDevice = FdoDevice;
2094  AsyncCallbackData->CallbackFunction = Callback;
2095 
2096  KeInitializeTimer(&AsyncCallbackData->AsyncTimer);
2097 
2098  KeInitializeDpc(&AsyncCallbackData->AsyncTimerDpc,
2100  AsyncCallbackData);
2101 
2102  DueTime.QuadPart -= (KeQueryTimeIncrement() - 1) + 10000 * TimerValue;
2103 
2104  KeSetTimer(&AsyncCallbackData->AsyncTimer,
2105  DueTime,
2106  &AsyncCallbackData->AsyncTimerDpc);
2107 
2108  return 0;
2109 }
2110 
2111 PVOID
2112 NTAPI
2114  IN PVOID MiniPortExtension,
2115  IN PVOID MiniPortEndpoint)
2116 {
2117  PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer;
2118  PUSBPORT_ENDPOINT Endpoint;
2119  ULONG Offset;
2121 
2122  DPRINT_CORE("USBPORT_GetMappedVirtualAddress ... \n");
2123 
2124  Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2125  sizeof(USBPORT_ENDPOINT));
2126 
2127  if (!Endpoint)
2128  {
2129  ASSERT(FALSE);
2130  }
2131 
2132  HeaderBuffer = Endpoint->HeaderBuffer;
2133 
2134  Offset = PhysicalAddress - HeaderBuffer->PhysicalAddress;
2135  VirtualAddress = HeaderBuffer->VirtualAddress + Offset;
2136 
2137  return (PVOID)VirtualAddress;
2138 }
2139 
2140 ULONG
2141 NTAPI
2143  IN PVOID MiniPortEndpoint)
2144 {
2146  PDEVICE_OBJECT FdoDevice;
2147  PUSBPORT_ENDPOINT Endpoint;
2148 
2149  DPRINT_CORE("USBPORT_InvalidateEndpoint: ... \n");
2150 
2151  FdoExtension = (PUSBPORT_DEVICE_EXTENSION)((ULONG_PTR)MiniPortExtension -
2152  sizeof(USBPORT_DEVICE_EXTENSION));
2153 
2154  FdoDevice = FdoExtension->CommonExtension.SelfDevice;
2155 
2156  if (!MiniPortEndpoint)
2157  {
2159  NULL,
2161  return 0;
2162  }
2163 
2164  Endpoint = (PUSBPORT_ENDPOINT)((ULONG_PTR)MiniPortEndpoint -
2165  sizeof(USBPORT_ENDPOINT));
2166 
2168  Endpoint,
2170 
2171  return 0;
2172 }
2173 
2174 VOID
2175 NTAPI
2177  IN USBD_STATUS TransferStatus)
2178 {
2179  struct _URB_CONTROL_TRANSFER *UrbTransfer;
2180  PUSBPORT_TRANSFER Transfer;
2181  NTSTATUS Status;
2182  PIRP Irp;
2183  KIRQL OldIrql;
2184  PRKEVENT Event;
2185  BOOLEAN WriteToDevice;
2186  BOOLEAN IsFlushSuccess;
2187  PMDL Mdl;
2188  ULONG_PTR CurrentVa;
2189  SIZE_T TransferLength;
2190  PUSBPORT_ENDPOINT Endpoint;
2191  PDEVICE_OBJECT FdoDevice;
2193  PDMA_OPERATIONS DmaOperations;
2194 
2195  DPRINT("USBPORT_CompleteTransfer: Urb - %p, TransferStatus - %X\n",
2196  Urb,
2197  TransferStatus);
2198 
2199  UrbTransfer = &Urb->UrbControlTransfer;
2200  Transfer = UrbTransfer->hca.Reserved8[0];
2201 
2202  Transfer->USBDStatus = TransferStatus;
2203  Status = USBPORT_USBDStatusToNtStatus(Urb, TransferStatus);
2204 
2205  UrbTransfer->TransferBufferLength = Transfer->CompletedTransferLen;
2206 
2207  if (Transfer->Flags & TRANSFER_FLAG_DMA_MAPPED)
2208  {
2209  Endpoint = Transfer->Endpoint;
2210  FdoDevice = Endpoint->FdoDevice;
2211  FdoExtension = FdoDevice->DeviceExtension;
2212  DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2213 
2214  WriteToDevice = Transfer->Direction == USBPORT_DMA_DIRECTION_TO_DEVICE;
2215  Mdl = UrbTransfer->TransferBufferMDL;
2216  CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2217  TransferLength = UrbTransfer->TransferBufferLength;
2218 
2219  IsFlushSuccess = DmaOperations->FlushAdapterBuffers(FdoExtension->DmaAdapter,
2220  Mdl,
2221  Transfer->MapRegisterBase,
2222  (PVOID)CurrentVa,
2223  TransferLength,
2224  WriteToDevice);
2225 
2226  if (!IsFlushSuccess)
2227  {
2228  DPRINT("USBPORT_CompleteTransfer: no FlushAdapterBuffers !!!\n");
2229  ASSERT(FALSE);
2230  }
2231 
2233 
2234  DmaOperations->FreeMapRegisters(FdoExtension->DmaAdapter,
2235  Transfer->MapRegisterBase,
2236  Transfer->NumberOfMapRegisters);
2237 
2239  }
2240 
2241  if (Urb->UrbHeader.UsbdFlags & USBD_FLAG_ALLOCATED_MDL)
2242  {
2243  IoFreeMdl(Transfer->TransferBufferMDL);
2244  Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_MDL;
2245  }
2246 
2247  Urb->UrbControlTransfer.hca.Reserved8[0] = NULL;
2248  Urb->UrbHeader.UsbdFlags |= ~USBD_FLAG_ALLOCATED_TRANSFER;
2249 
2250  Irp = Transfer->Irp;
2251 
2252  if (Irp)
2253  {
2254  if (!NT_SUCCESS(Status))
2255  {
2256  //DbgBreakPoint();
2257  DPRINT1("USBPORT_CompleteTransfer: Irp - %p complete with Status - %lx\n",
2258  Irp,
2259  Status);
2260 
2261  USBPORT_DumpingURB(Urb);
2262  }
2263 
2264  Irp->IoStatus.Status = Status;
2265  Irp->IoStatus.Information = 0;
2266 
2270  }
2271 
2272  Event = Transfer->Event;
2273 
2274  if (Event)
2275  {
2277  }
2278 
2279  ExFreePoolWithTag(Transfer, USB_PORT_TAG);
2280 
2281  DPRINT_CORE("USBPORT_CompleteTransfer: exit\n");
2282 }
2283 
2285 NTAPI
2287  IN PIRP Irp,
2289  IN PVOID Context)
2290 {
2292  PDMA_ADAPTER DmaAdapter;
2293  PUSBPORT_TRANSFER Transfer;
2294  PURB Urb;
2295  PUSBPORT_ENDPOINT Endpoint;
2296  PMDL Mdl;
2297  ULONG_PTR CurrentVa;
2299  SIZE_T CurrentLength;
2300  ULONG ix;
2301  BOOLEAN WriteToDevice;
2302  PHYSICAL_ADDRESS PhAddr = {{0, 0}};
2303  PHYSICAL_ADDRESS PhAddress = {{0, 0}};
2304  ULONG TransferLength;
2305  SIZE_T SgCurrentLength;
2306  SIZE_T ElementLength;
2308  PDMA_OPERATIONS DmaOperations;
2309  USBD_STATUS USBDStatus;
2310  LIST_ENTRY List;
2311  PUSBPORT_TRANSFER transfer;
2312 
2313  DPRINT_CORE("USBPORT_MapTransfer: ... \n");
2314 
2315  FdoExtension = FdoDevice->DeviceExtension;
2316  DmaAdapter = FdoExtension->DmaAdapter;
2317  DmaOperations = DmaAdapter->DmaOperations;
2318 
2319  Transfer = Context;
2320 
2321  Urb = Transfer->Urb;
2322  Endpoint = Transfer->Endpoint;
2323  TransferLength = Transfer->TransferParameters.TransferBufferLength;
2324 
2325  Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2326  CurrentVa = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2327 
2328  sgList = &Transfer->SgList;
2329 
2330  sgList->Flags = 0;
2331  sgList->CurrentVa = CurrentVa;
2334  Transfer->MapRegisterBase = MapRegisterBase;
2335 
2336  ix = 0;
2337  CurrentLength = 0;
2338 
2339  do
2340  {
2341  WriteToDevice = Transfer->Direction == USBPORT_DMA_DIRECTION_TO_DEVICE;
2342  ASSERT(Transfer->Direction != 0);
2343 
2344  PhAddress = DmaOperations->MapTransfer(DmaAdapter,
2345  Mdl,
2347  (PVOID)CurrentVa,
2348  &TransferLength,
2349  WriteToDevice);
2350 
2351  DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, PhAddress.HighPart - %x, TransferLength - %x\n",
2352  PhAddress.LowPart,
2353  PhAddress.HighPart,
2354  TransferLength);
2355 
2356  PhAddress.HighPart = 0;
2357  SgCurrentLength = TransferLength;
2358 
2359  do
2360  {
2361  ElementLength = PAGE_SIZE - (PhAddress.LowPart & (PAGE_SIZE - 1));
2362 
2363  if (ElementLength > SgCurrentLength)
2364  ElementLength = SgCurrentLength;
2365 
2366  DPRINT_CORE("USBPORT_MapTransfer: PhAddress.LowPart - %p, HighPart - %x, ElementLength - %x\n",
2367  PhAddress.LowPart,
2368  PhAddress.HighPart,
2369  ElementLength);
2370 
2371  sgList->SgElement[ix].SgPhysicalAddress = PhAddress;
2372  sgList->SgElement[ix].SgTransferLength = ElementLength;
2373  sgList->SgElement[ix].SgOffset = CurrentLength +
2374  (TransferLength - SgCurrentLength);
2375 
2376  PhAddress.LowPart += ElementLength;
2377  SgCurrentLength -= ElementLength;
2378 
2379  ++ix;
2380  }
2381  while (SgCurrentLength);
2382 
2383  if (PhAddr.QuadPart == PhAddress.QuadPart)
2384  {
2385  DPRINT1("USBPORT_MapTransfer: PhAddr == PhAddress\n");
2386  ASSERT(FALSE);
2387  }
2388 
2389  PhAddr = PhAddress;
2390 
2391  CurrentLength += TransferLength;
2392  CurrentVa += TransferLength;
2393 
2394  TransferLength = Transfer->TransferParameters.TransferBufferLength -
2395  CurrentLength;
2396  }
2397  while (CurrentLength != Transfer->TransferParameters.TransferBufferLength);
2398 
2399  sgList->SgElementCount = ix;
2400 
2401  if (Endpoint->EndpointProperties.DeviceSpeed == UsbHighSpeed)
2402  {
2403  Transfer->Flags |= TRANSFER_FLAG_HIGH_SPEED;
2404  }
2405 
2406  Transfer->Flags |= TRANSFER_FLAG_DMA_MAPPED;
2407 
2408  if ((Transfer->Flags & TRANSFER_FLAG_ISO) == 0)
2409  {
2411  &Endpoint->EndpointOldIrql);
2412 
2413  USBPORT_SplitTransfer(FdoDevice, Endpoint, Transfer, &List);
2414 
2415  while (!IsListEmpty(&List))
2416  {
2417  transfer = CONTAINING_RECORD(List.Flink,
2419  TransferLink);
2420 
2421  RemoveHeadList(&List);
2422  InsertTailList(&Endpoint->TransferList, &transfer->TransferLink);
2423  }
2424 
2426  Endpoint->EndpointOldIrql);
2427  }
2428  else
2429  {
2430  USBDStatus = USBPORT_InitializeIsoTransfer(FdoDevice,
2431  &Urb->UrbIsochronousTransfer,
2432  Transfer);
2433 
2434  if (USBDStatus != USBD_STATUS_SUCCESS)
2435  {
2437  &Endpoint->EndpointOldIrql);
2438 
2439  USBPORT_QueueDoneTransfer(Transfer, USBDStatus);
2440 
2442  Endpoint->EndpointOldIrql);
2443  }
2444  }
2445 
2446  DeviceHandle = Urb->UrbHeader.UsbdDeviceHandle;
2447  InterlockedDecrement(&DeviceHandle->DeviceHandleLock);
2448 
2449  if (USBPORT_EndpointWorker(Endpoint, 0))
2450  {
2452  Endpoint,
2454  }
2455 
2457 }
2458 
2459 VOID
2460 NTAPI
2462 {
2464  PLIST_ENTRY MapTransferList;
2465  PUSBPORT_TRANSFER Transfer;
2466  ULONG NumMapRegisters;
2467  PMDL Mdl;
2469  ULONG_PTR VirtualAddr;
2470  KIRQL OldIrql;
2471  NTSTATUS Status;
2472  PDMA_OPERATIONS DmaOperations;
2473 
2474  DPRINT_CORE("USBPORT_FlushMapTransfers: ... \n");
2475 
2476  FdoExtension = FdoDevice->DeviceExtension;
2477  DmaOperations = FdoExtension->DmaAdapter->DmaOperations;
2478 
2480 
2481  while (TRUE)
2482  {
2483  MapTransferList = &FdoExtension->MapTransferList;
2484 
2485  if (IsListEmpty(&FdoExtension->MapTransferList))
2486  {
2488  return;
2489  }
2490 
2491  Transfer = CONTAINING_RECORD(MapTransferList->Flink,
2493  TransferLink);
2494 
2495  RemoveHeadList(MapTransferList);
2496 
2497  Mdl = Transfer->Urb->UrbControlTransfer.TransferBufferMDL;
2499  VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2500 
2501  NumMapRegisters = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2503 
2504  Transfer->NumberOfMapRegisters = NumMapRegisters;
2505 
2506  Status = DmaOperations->AllocateAdapterChannel(FdoExtension->DmaAdapter,
2507  FdoDevice,
2508  NumMapRegisters,
2510  Transfer);
2511 
2512  if (!NT_SUCCESS(Status))
2513  ASSERT(FALSE);
2514  }
2515 
2517 }
2518 
2520 NTAPI
2522  IN PURB Urb,
2524  IN PIRP Irp,
2525  IN PRKEVENT Event)
2526 {
2528  SIZE_T TransferLength;
2529  PMDL Mdl;
2530  ULONG_PTR VirtualAddr;
2531  ULONG PagesNeed = 0;
2532  SIZE_T PortTransferLength;
2533  SIZE_T FullTransferLength;
2534  PUSBPORT_TRANSFER Transfer;
2536  USBD_STATUS USBDStatus;
2537  SIZE_T IsoBlockLen = 0;
2538 
2539  DPRINT_CORE("USBPORT_AllocateTransfer: FdoDevice - %p, Urb - %p, DeviceHandle - %p, Irp - %p, Event - %p\n",
2540  FdoDevice,
2541  Urb,
2542  DeviceHandle,
2543  Irp,
2544  Event);
2545 
2546  FdoExtension = FdoDevice->DeviceExtension;
2547 
2548  TransferLength = Urb->UrbControlTransfer.TransferBufferLength;
2549  PipeHandle = Urb->UrbControlTransfer.PipeHandle;
2550 
2551  if (TransferLength)
2552  {
2553  Mdl = Urb->UrbControlTransfer.TransferBufferMDL;
2554  VirtualAddr = (ULONG_PTR)MmGetMdlVirtualAddress(Mdl);
2555 
2556  PagesNeed = ADDRESS_AND_SIZE_TO_SPAN_PAGES(VirtualAddr,
2557  TransferLength);
2558  if (PagesNeed > 0)
2559  {
2560  PagesNeed--;
2561  }
2562  }
2563 
2564  if (Urb->UrbHeader.Function == URB_FUNCTION_ISOCH_TRANSFER)
2565  {
2566  DPRINT1("USBPORT_AllocateTransfer: ISOCH_TRANSFER UNIMPLEMENTED. FIXME\n");
2567 
2568  //IsoBlockLen = sizeof(USBPORT_ISO_BLOCK) +
2569  // Urb->UrbIsochronousTransfer.NumberOfPackets *
2570  // sizeof(USBPORT_ISO_BLOCK_PACKET);
2571  }
2572 
2573  PortTransferLength = sizeof(USBPORT_TRANSFER) +
2574  PagesNeed * sizeof(USBPORT_SCATTER_GATHER_ELEMENT) +
2575  IsoBlockLen;
2576 
2577  FullTransferLength = PortTransferLength +
2578  FdoExtension->MiniPortInterface->Packet.MiniPortTransferSize;
2579 
2581  FullTransferLength,
2582  USB_PORT_TAG);
2583 
2584  if (!Transfer)
2585  {
2586  DPRINT1("USBPORT_AllocateTransfer: Transfer not allocated!\n");
2588  }
2589 
2590  RtlZeroMemory(Transfer, FullTransferLength);
2591 
2592  Transfer->Irp = Irp;
2593  Transfer->Urb = Urb;
2594  Transfer->Endpoint = PipeHandle->Endpoint;
2595  Transfer->Event = Event;
2596  Transfer->PortTransferLength = PortTransferLength;
2597  Transfer->FullTransferLength = FullTransferLength;
2598  Transfer->IsoBlockPtr = NULL;
2599  Transfer->Period = 0;
2600  Transfer->ParentTransfer = Transfer;
2601 
2602  if (IsoBlockLen)
2603  {
2604  Transfer->IsoBlockPtr = (PVOID)((ULONG_PTR)Transfer +
2605  PortTransferLength - IsoBlockLen);
2606 
2607  Transfer->Period = PipeHandle->Endpoint->EndpointProperties.Period;
2608  Transfer->Flags |= TRANSFER_FLAG_ISO;
2609  }
2610 
2611  Transfer->MiniportTransfer = (PVOID)((ULONG_PTR)Transfer +
2612  PortTransferLength);
2613 
2615 
2616  Urb->UrbControlTransfer.hca.Reserved8[0] = Transfer;
2617  Urb->UrbHeader.UsbdFlags |= USBD_FLAG_ALLOCATED_TRANSFER;
2618 
2619  USBDStatus = USBD_STATUS_SUCCESS;
2620 
2621  DPRINT_CORE("USBPORT_AllocateTransfer: return USBDStatus - %x\n",
2622  USBDStatus);
2623 
2624  return USBDStatus;
2625 }
2626 
2627 NTSTATUS
2628 NTAPI
2630  IN PIRP Irp)
2631 {
2632  PUSBPORT_COMMON_DEVICE_EXTENSION DeviceExtension;
2633  PIO_STACK_LOCATION IoStack;
2635 
2636  DeviceExtension = DeviceObject->DeviceExtension;
2637  IoStack = IoGetCurrentIrpStackLocation(Irp);
2638 
2639  if (DeviceExtension->PnpStateFlags & USBPORT_PNP_STATE_FAILED)
2640  {
2641  DPRINT1("USBPORT_Dispatch: USBPORT_PNP_STATE_FAILED\n");
2642  DbgBreakPoint();
2643  }
2644 
2645  switch (IoStack->MajorFunction)
2646  {
2647  case IRP_MJ_DEVICE_CONTROL:
2648  if (DeviceExtension->IsPDO)
2649  {
2650  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2651  IoStack->MajorFunction,
2652  IoStack->MinorFunction);
2653 
2655  }
2656  else
2657  {
2658  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2659  IoStack->MajorFunction,
2660  IoStack->MinorFunction);
2661 
2663  }
2664 
2665  break;
2666 
2668  if (DeviceExtension->IsPDO)
2669  {
2670  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2671  IoStack->MajorFunction,
2672  IoStack->MinorFunction);
2673 
2675  }
2676  else
2677  {
2678  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_INTERNAL_DEVICE_CONTROL. Major - %d, Minor - %d\n",
2679  IoStack->MajorFunction,
2680  IoStack->MinorFunction);
2681 
2683  }
2684 
2685  break;
2686 
2687  case IRP_MJ_POWER:
2688  if (DeviceExtension->IsPDO)
2689  {
2690  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2691  IoStack->MajorFunction,
2692  IoStack->MinorFunction);
2693 
2695  }
2696  else
2697  {
2698  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_POWER. Major - %d, Minor - %d\n",
2699  IoStack->MajorFunction,
2700  IoStack->MinorFunction);
2701 
2703  }
2704 
2705  break;
2706 
2707  case IRP_MJ_SYSTEM_CONTROL:
2708  if (DeviceExtension->IsPDO)
2709  {
2710  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2711  IoStack->MajorFunction,
2712  IoStack->MinorFunction);
2713 
2714  Status = Irp->IoStatus.Status;
2716  }
2717  else
2718  {
2719  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_SYSTEM_CONTROL. Major - %d, Minor - %d\n",
2720  IoStack->MajorFunction,
2721  IoStack->MinorFunction);
2722 
2724  Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
2725  }
2726 
2727  break;
2728 
2729  case IRP_MJ_PNP:
2730  if (DeviceExtension->IsPDO)
2731  {
2732  DPRINT("USBPORT_Dispatch: PDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2733  IoStack->MajorFunction,
2734  IoStack->MinorFunction);
2735 
2737  }
2738  else
2739  {
2740  DPRINT("USBPORT_Dispatch: FDO IRP_MJ_PNP. Major - %d, Minor - %d\n",
2741  IoStack->MajorFunction,
2742  IoStack->MinorFunction);
2743 
2745  }
2746 
2747  break;
2748 
2749  case IRP_MJ_CREATE:
2750  case IRP_MJ_CLOSE:
2751  DPRINT("USBPORT_Dispatch: IRP_MJ_CREATE | IRP_MJ_CLOSE\n");
2752  Irp->IoStatus.Status = Status;
2754  break;
2755 
2756  default:
2757  if (DeviceExtension->IsPDO)
2758  {
2759  DPRINT("USBPORT_Dispatch: PDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2760  IoStack->MajorFunction,
2761  IoStack->MinorFunction);
2762  }
2763  else
2764  {
2765  DPRINT("USBPORT_Dispatch: FDO unhandled IRP_MJ_???. Major - %d, Minor - %d\n",
2766  IoStack->MajorFunction,
2767  IoStack->MinorFunction);
2768  }
2769 
2771  Irp->IoStatus.Status = Status;
2773  break;
2774  }
2775 
2776  DPRINT("USBPORT_Dispatch: Status - %x\n", Status);
2777  return Status;
2778 }
2779 
2780 ULONG
2781 NTAPI
2783 {
2784  return USBPORT_HCI_MN;
2785 }
2786 
2787 NTSTATUS
2788 NTAPI
2790  IN ULONG Version,
2792 {
2793  PUSBPORT_MINIPORT_INTERFACE MiniPortInterface;
2794 
2795  DPRINT("USBPORT_RegisterUSBPortDriver: DriverObject - %p, Version - %p, RegPacket - %p\n",
2796  DriverObject,
2797  Version,
2798  RegPacket);
2799 
2800  DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_MINIPORT_INTERFACE) - %x\n",
2801  sizeof(USBPORT_MINIPORT_INTERFACE));
2802 
2803  DPRINT("USBPORT_RegisterUSBPortDriver: sizeof(USBPORT_DEVICE_EXTENSION) - %x\n",
2804  sizeof(USBPORT_DEVICE_EXTENSION));
2805 
2807  {
2808  return STATUS_UNSUCCESSFUL;
2809  }
2810 
2811  if (!USBPORT_Initialized)
2812  {
2816 
2819  }
2820 
2821  MiniPortInterface = ExAllocatePoolWithTag(NonPagedPool,
2823  USB_PORT_TAG);
2824  if (!MiniPortInterface)
2825  {
2827  }
2828 
2829  RtlZeroMemory(MiniPortInterface, sizeof(USBPORT_MINIPORT_INTERFACE));
2830 
2831  MiniPortInterface->DriverObject = DriverObject;
2832  MiniPortInterface->DriverUnload = DriverObject->DriverUnload;
2833  MiniPortInterface->Version = Version;
2834 
2836  &MiniPortInterface->DriverLink,
2837  &USBPORT_SpinLock);
2838 
2841 
2849 
2866 
2867  RtlCopyMemory(&MiniPortInterface->Packet,
2868  RegPacket,
2869  sizeof(USBPORT_REGISTRATION_PACKET));
2870 
2871  return STATUS_SUCCESS;
2872 }
2873 
2874 NTSTATUS
2875 NTAPI
2878 {
2879  return STATUS_SUCCESS;
2880 }
#define USBPORT_ENDPOINT_ACTIVE
Definition: usbmport.h:15
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
ULONG NumberOfMapRegisters
Definition: usbport.h:259
#define USBPORT_TMFLAG_IDLE_QUEUEITEM_ON
Definition: usbport.h:98
ULONG MPSTATUS
Definition: usbmport.h:131
VOID NTAPI USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer)
Definition: usbport.c:1748
#define USBPORT_INVALIDATE_CONTROLLER_SOFT_INTERRUPT
Definition: usbmport.h:491
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define USBD_STATUS_DEVICE_GONE
Definition: usb.h:210
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define USBPORT_DMA_DIRECTION_TO_DEVICE
Definition: usbport.h:42
USBPORT_SCATTER_GATHER_LIST SgList
Definition: usbport.h:270
enum _IO_ALLOCATION_ACTION IO_ALLOCATION_ACTION
PALLOCATE_COMMON_BUFFER AllocateCommonBuffer
Definition: iotypes.h:2311
#define USBD_STATUS_NOT_SUPPORTED
Definition: usb.h:202
#define DPRINT_CORE(...)
Definition: usbdebug.h:144
VOID NTAPI USBPORT_DpcHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:864
#define USBPORT_FLAG_POWER_AND_CHIRP_OK
Definition: usbport.h:82
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
VOID NTAPI USBPORT_CompleteTransfer(IN PURB Urb, IN USBD_STATUS TransferStatus)
Definition: usbport.c:2176
NTSTATUS NTAPI USBPORT_PdoPower(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: power.c:322
VOID NTAPI USBPORT_DumpingURB(IN PURB Urb)
Definition: debug.c:225
PFREE_COMMON_BUFFER FreeCommonBuffer
Definition: iotypes.h:2312
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
PDEVICE_OBJECT NTAPI USBPORT_FindUSB2Controller(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:27
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:444
LIST_ENTRY EndpointLink
Definition: usbport.h:231
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
VOID NTAPI USBPORT_TransferFlushDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:825
NTSTATUS NTAPI USBPORT_CreateWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1422
struct _USBPORT_TRANSFER USBPORT_TRANSFER
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define DPRINT_INT(...)
Definition: usbdebug.h:146
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
LIST_ENTRY List
Definition: extypes.h:203
LIST_ENTRY WorkerLink
Definition: usbport.h:232
USBPORT_REGISTRATION_PACKET RegPacket
Definition: usbehci.c:16
VOID NTAPI USBPORT_SynchronizeControllersStart(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1450
Type
Definition: Type.h:6
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define USBD_STATUS_INVALID_URB_FUNCTION
Definition: usb.h:191
struct _Entry Entry
Definition: kefuncs.h:640
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
LIST_ENTRY ControllerLink
Definition: usbport.h:301
#define MmGetMdlVirtualAddress(_Mdl)
VOID NTAPI USBPORT_WorkerThreadHandler(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1127
PUSBPORT_TEST_DEBUG_BREAK UsbPortTestDebugBreak
Definition: usbmport.h:611
PUSBPORT_GET_MAPPED_VIRTUAL_ADDRESS UsbPortGetMappedVirtualAddress
Definition: usbmport.h:619
#define USBPORT_TMFLAG_WAKE
Definition: usbport.h:97
struct _KEY_VALUE_FULL_INFORMATION KEY_VALUE_FULL_INFORMATION
LIST_ENTRY FlushAbortLink
Definition: usbport.h:237
NTSTATUS NTAPI USBPORT_GetSetConfigSpaceData(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:410
USBD_STATUS NTAPI USBPORT_InitializeIsoTransfer(PDEVICE_OBJECT FdoDevice, struct _URB_ISOCH_TRANSFER *Urb, PUSBPORT_TRANSFER Transfer)
Definition: iso.c:15
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2738
PUSBPORT_ASSERT_FAILURE UsbPortAssertFailure
Definition: usbmport.h:612
_In_ PIRP Irp
Definition: csq.h:116
PUSBPORT_COMPLETE_ISO_TRANSFER UsbPortCompleteIsoTransfer
Definition: usbmport.h:617
BOOLEAN NTAPI USBPORT_InterruptService(IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
Definition: usbport.c:1077
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
ULONG NTAPI USBPORT_GetHciMn(VOID)
Definition: usbport.c:2782
PDEVICE_OBJECT LowerPdoDevice
Definition: usbport.h:281
PFREE_MAP_REGISTERS FreeMapRegisters
Definition: iotypes.h:2316
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2054
PUSBPORT_INVALIDATE_ENDPOINT UsbPortInvalidateEndpoint
Definition: usbmport.h:615
unsigned char * PUCHAR
Definition: retypes.h:3
LIST_ENTRY USBPORT_USB1FdoList
Definition: usbport.c:19
VOID NTAPI USBPORT_SoftInterrupt(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:611
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
VOID NTAPI USBPORT_AsyncTimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:2034
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
USBPORT_TRANSFER_PARAMETERS TransferParameters
Definition: usbport.h:253
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI USBPORT_Unload(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:1948
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
VOID NTAPI USBPORT_CompletePdoWaitWake(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:15
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define USBD_FLAG_ALLOCATED_TRANSFER
Definition: usbport.h:122
PUSBPORT_COMPLETE_TRANSFER UsbPortCompleteTransfer
Definition: usbmport.h:616
VOID NTAPI USBPORT_IsrDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1031
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define InterlockedCompareExchange
Definition: interlocked.h:104
VOID NTAPI USBPORT_DoRootHubCallback(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1222
struct _USBPORT_COMMON_BUFFER_HEADER USBPORT_COMMON_BUFFER_HEADER
NTSTATUS NTAPI USBPORT_PdoInternalDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:317
USBPORT_REGISTRATION_PACKET Packet
Definition: usbmport.h:644
NTSTATUS NTAPI USBPORT_FdoDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:396
struct _USBPORT_COMMON_BUFFER_HEADER * PUSBPORT_COMMON_BUFFER_HEADER
#define LOW_REALTIME_PRIORITY
PMDL TransferBufferMDL
Definition: usbport.h:254
PDRIVER_OBJECT DriverObject
Definition: usbmport.h:640
BOOLEAN NTAPI USBPORT_EndpointWorker(IN PUSBPORT_ENDPOINT Endpoint, IN BOOLEAN LockNotChecked)
Definition: endpoint.c:1658
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:433
PHYSICAL_ADDRESS SgPhysicalAddress
Definition: usbmport.h:107
#define USBPORT_INVALIDATE_CONTROLLER_SURPRISE_REMOVE
Definition: usbmport.h:490
ULONG NTAPI USBPORT_CompleteIsoTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN ULONG TransferLength)
Definition: iso.c:25
PDRIVER_UNLOAD DriverUnload
Definition: usbmport.h:642
#define ENDPOINT_FLAG_ROOTHUB_EP0
Definition: usbport.h:111
ULONG NTAPI USBPORT_TestDebugBreak(IN PVOID MiniPortExtension)
Definition: debug.c:31
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define InsertTailList(ListHead, Entry)
PUSBPORT_NOTIFY_DOUBLE_BUFFER UsbPortNotifyDoubleBuffer
Definition: usbmport.h:625
USB_DEVICE_SPEED DeviceSpeed
Definition: usbmport.h:73
IoSetCancelRoutine(Irp, CancelRoutine)
#define USBPORT_FLAG_RH_INIT_CALLBACK
Definition: usbport.h:83
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
void DbgBreakPoint()
Definition: mach.c:558
PRKEVENT Event
Definition: usbport.h:248
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
MPSTATUS NTAPI USBPORT_ReadWriteConfigSpace(IN PVOID MiniPortExtension, IN BOOLEAN IsReadData, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: usbport.c:456
LIST_ENTRY USBPORT_USB2FdoList
Definition: usbport.c:20
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
volatile PVOID Parameter
Definition: extypes.h:205
USBPORT_COMMON_DEVICE_EXTENSION CommonExtension
Definition: usbport.h:291
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
struct _DMA_OPERATIONS * DmaOperations
Definition: iotypes.h:2186
struct _USB2_HC_EXTENSION USB2_HC_EXTENSION
#define TRANSFER_FLAG_DMA_MAPPED
Definition: usbport.h:130
KSPIN_LOCK StateChangeSpinLock
Definition: usbport.h:224
PUSBPORT_MINIPORT_INTERFACE NTAPI USBPORT_FindMiniPort(IN PDRIVER_OBJECT DriverObject)
Definition: usbport.c:1771
#define USBPORT_FLAG_HC_WAKE_SUPPORT
Definition: usbport.h:75
PUSBPORT_READ_WRITE_CONFIG_SPACE UsbPortReadWriteConfigSpace
Definition: usbmport.h:621
LIST_ENTRY DispatchLink
Definition: usbport.h:234
BOOLEAN USBPORT_Initialized
Definition: usbport.c:23
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define USBD_STATUS_INSUFFICIENT_RESOURCES
Definition: usb.h:204
#define USB_PORT_TAG
Definition: usbport.h:44
PUSBPORT_COMMON_BUFFER_HEADER NTAPI USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice, IN SIZE_T BufferLength)
Definition: usbport.c:1686
IO_ALLOCATION_ACTION NTAPI USBPORT_MapTransfer(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp, IN PVOID MapRegisterBase, IN PVOID Context)
Definition: usbport.c:2286
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI USBPORT_InvalidateControllerHandler(IN PDEVICE_OBJECT FdoDevice, IN ULONG Type)
Definition: usbport.c:635
VOID NTAPI USBPORT_WorkerRequestDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:701
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
NTSTATUS NTAPI USBPORT_FdoPnP(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: pnp.c:1110
NTSTATUS NTAPI USBPORT_Wait(IN PVOID MiniPortExtension, IN ULONG Milliseconds)
Definition: usbport.c:543
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
#define USBPORT_PNP_STATE_FAILED
Definition: usbport.h:88
struct _USBPORT_TRANSFER * ParentTransfer
Definition: usbport.h:263
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:109
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
WORK_QUEUE_ITEM WqItem
Definition: usbport.h:443
#define TRANSFER_FLAG_HIGH_SPEED
Definition: usbport.h:131
#define USB_MINIPORT_FLAGS_USB2
Definition: usbmport.h:534
PDEVICE_OBJECT FdoDevice
Definition: usbport.h:205
unsigned int BOOL
Definition: ntddk_ex.h:94
PUSBPORT_COMMON_BUFFER_HEADER HeaderBuffer
Definition: usbport.h:206
PUSBPORT_DBG_PRINT UsbPortDbgPrint
Definition: usbmport.h:610
long LONG
Definition: pedump.c:60
PUSBPORT_LOG_ENTRY UsbPortLogEntry
Definition: usbmport.h:618
_In_ ULONG BufferLength
Definition: usbdlib.h:225
PMAP_TRANSFER MapTransfer
Definition: iotypes.h:2317
LIST_ENTRY TransferList
Definition: usbport.h:227
KIRQL EndpointOldIrql
Definition: usbport.h:215
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
struct _USBPORT_DEVICE_EXTENSION USBPORT_DEVICE_EXTENSION
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2173
VOID NTAPI USBPORT_FlushDoneTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:764
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
VOID NTAPI USBPORT_MiniportInterrupts(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsEnable)
Definition: usbport.c:555
PUSBPORT_REQUEST_ASYNC_CALLBACK UsbPortRequestAsyncCallback
Definition: usbmport.h:620
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define USBPORT_FLAG_PWR_AND_CHIRP_LOCK
Definition: usbport.h:81
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
struct _URB_HCD_AREA hca
Definition: usb.h:474
NTSTATUS NTAPI USBPORT_PdoPnP(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: pnp.c:1517
Definition: bufpool.h:45
VOID NTAPI USBPORT_DoIdleNotificationCallback(IN PVOID Context)
Definition: power.c:545
void * PVOID
Definition: retypes.h:9
#define USBPORT_FLAG_COMPANION_HC
Definition: usbport.h:77
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define USBPORT_HCI_MN
Definition: usbmport.h:4
VOID NTAPI USBPORT_RootHubPowerAndChirpAllCcPorts(IN PDEVICE_OBJECT FdoDevice)
Definition: roothub.c:963
SIZE_T PortTransferLength
Definition: usbport.h:250
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
PUSBPORT_ENDPOINT Endpoint
Definition: usbport.h:252
DWORD Interval
Definition: netstat.c:30
PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers
Definition: iotypes.h:2314
BOOLEAN NTAPI USBPORT_StartTimer(IN PDEVICE_OBJECT FdoDevice, IN ULONG Time)
Definition: usbport.c:1653
#define INVALIDATE_ENDPOINT_ONLY
Definition: usbport.h:36
struct _URB_HEADER UrbHeader
Definition: usb.h:531
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
LIST_ENTRY TransferLink
Definition: usbport.h:256
ULONG NTAPI USBPORT_InvalidateRootHub(PVOID MiniPortExtension)
Definition: roothub.c:917
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
PVOID NTAPI USBPORT_GetMappedVirtualAddress(IN ULONG PhysicalAddress, IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2113
PMDL TransferBufferMDL
Definition: usb.h:472
_In_ LARGE_INTEGER _In_opt_ PKDPC Dpc
Definition: kefuncs.h:524
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_FlushPendingTransfers(IN PUSBPORT_ENDPOINT Endpoint)
Definition: queue.c:785
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define USBPORT_FLAG_WORKER_THREAD_ON
Definition: usbport.h:69
VOID NTAPI USBPORT_SynchronizeRootHubCallback(IN PDEVICE_OBJECT FdoDevice, IN PDEVICE_OBJECT Usb2FdoDevice)
Definition: usbport.c:1257
PUSBPORT_INVALIDATE_ROOT_HUB UsbPortInvalidateRootHub
Definition: usbmport.h:614
#define USBD_FLAG_ALLOCATED_MDL
Definition: usbport.h:120
VOID NTAPI USBPORT_MiniportCompleteTransfer(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint, IN PVOID TransferParameters, IN USBD_STATUS USBDStatus, IN ULONG TransferLength)
Definition: usbport.c:1968
#define USBPORT_FLAG_HC_POLLING
Definition: usbport.h:68
LIST_ENTRY List
Definition: psmgr.c:57
ASYNC_TIMER_CALLBACK * CallbackFunction
Definition: usbport.h:436
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:2057
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID NTAPI USBPORT_DoSetPowerD0(IN PDEVICE_OBJECT FdoDevice)
Definition: power.c:104
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DPRINT_TIMER(...)
Definition: usbdebug.h:147
static void Exit(void)
Definition: sock.c:1331
struct _URB_CONTROL_TRANSFER UrbControlTransfer
Definition: usb.h:539
struct _USBPORT_ENDPOINT USBPORT_ENDPOINT
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID NTAPI USBPORT_FlushAllEndpoints(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1171
ULONG NTAPI USBPORT_NotifyDoubleBuffer(IN PVOID MiniPortExtension, IN PVOID MiniPortTransfer, IN PVOID Buffer, IN SIZE_T Length)
Definition: usbport.c:690
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
PVOID MiniportTransfer
Definition: usbport.h:249
MPSTATUS NTAPI USBPORT_NtStatusToMpStatus(NTSTATUS NtStatus)
Definition: usbport.c:232
struct _USBPORT_ENDPOINT * PUSBPORT_ENDPOINT
Definition: usbport.h:154
NTSTATUS NTAPI USBPORT_Dispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbport.c:2629
VOID NTAPI USBPORT_AddUSB2Fdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:82
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
RH_INIT_CALLBACK * PRH_INIT_CALLBACK
Definition: hubbusif.h:270
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
struct _USBPORT_DEVICE_EXTENSION * PUSBPORT_DEVICE_EXTENSION
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:798
VOID NTAPI USBPORT_SplitTransfer(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PUSBPORT_TRANSFER Transfer, IN PLIST_ENTRY List)
Definition: trfsplit.c:232
VOID NTAPI USBPORT_DoneTransfer(IN PUSBPORT_TRANSFER Transfer)
Definition: usbport.c:724
Definition: partlist.h:33
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define ENDPOINT_FLAG_NUKE
Definition: usbport.h:112
VOID NTAPI USBPORT_DoneSplitTransfer(IN PUSBPORT_TRANSFER SplitTransfer)
Definition: trfsplit.c:278
VOID NTAPI USBPORT_SignalWorkerThread(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:1111
#define PCI_WHICHSPACE_CONFIG
Definition: iotypes.h:3287
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USBD_STATUS_SUCCESS
Definition: usb.h:170
ULONG NTAPI USBPORT_GetEndpointState(IN PUSBPORT_ENDPOINT Endpoint)
Definition: endpoint.c:332
BOOLEAN NTAPI USBPORT_IsCompanionFdoExtension(IN PDEVICE_OBJECT USB2FdoDevice, IN PUSBPORT_DEVICE_EXTENSION USB1FdoExtension)
Definition: usbport.c:119
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1060
PUSBPORT_INVALIDATE_CONTROLLER UsbPortInvalidateController
Definition: usbmport.h:623
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
struct _USB2_HC_EXTENSION * PUSB2_HC_EXTENSION
Definition: usbport.h:156
#define USBPORT_FLAG_REGISTERED_FDO
Definition: usbport.h:78
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1869
static const WCHAR L[]
Definition: oid.c:1250
#define USBPORT_FLAG_NO_HACTION
Definition: usbport.h:79
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: ketypes.h:687
LONG USBD_STATUS
Definition: usb.h:165
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
VOID NTAPI USBPORT_SoftInterruptDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:590
NTSTATUS NTAPI USBPORT_RegisterUSBPortDriver(IN PDRIVER_OBJECT DriverObject, IN ULONG Version, IN PUSBPORT_REGISTRATION_PACKET RegPacket)
Definition: usbport.c:2789
#define USBPORT_TMFLAG_HC_RESUME
Definition: usbport.h:94
PWORKER_THREAD_ROUTINE WorkerRoutine
Definition: extypes.h:204
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
ULONG LowPart
Definition: typedefs.h:104
Definition: _list.h:228
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:117
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
NTSTATUS NTAPI USBPORT_USBDStatusToNtStatus(IN PURB Urb, IN USBD_STATUS USBDStatus)
Definition: usbport.c:485
static __inline NTSTATUS 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:1120
#define USBPORT_FLAG_INTERRUPT_ENABLED
Definition: usbport.h:71
#define IRP_MJ_SYSTEM_CONTROL
VOID NTAPI USBPORT_FlushMapTransfers(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:2461
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
USBPORT_ENDPOINT_PROPERTIES EndpointProperties
Definition: usbport.h:210
Status
Definition: gdiplustypes.h:24
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: usbport.c:2876
#define MAXULONG
Definition: typedefs.h:250
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
PDEVICE_RELATIONS NTAPI USBPORT_FindCompanionControllers(IN PDEVICE_OBJECT USB2FdoDevice, IN BOOLEAN IsObRefer, IN BOOLEAN IsFDOsReturned)
Definition: usbport.c:136
#define TRANSFER_FLAG_ISO
Definition: usbport.h:134
#define USBD_ERROR(Status)
Definition: usb.h:169
#define USBPORT_FLAG_HC_SUSPEND
Definition: usbport.h:70
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
SIZE_T FullTransferLength
Definition: usbport.h:251
#define USBD_STATUS_BAD_START_FRAME
Definition: usb.h:198
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define MP_STATUS_UNSUCCESSFUL
Definition: usbmport.h:142
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2111
DEVICE_POWER_STATE DevicePowerState
Definition: usbport.h:286
struct _URB_ISOCH_TRANSFER UrbIsochronousTransfer
Definition: usb.h:544
#define TRANSFER_FLAG_SPLITED
Definition: usbport.h:136
_Inout_ struct _IRP _In_ PVOID MapRegisterBase
Definition: iotypes.h:189
#define EVENT_INCREMENT
Definition: iotypes.h:564
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InterlockedIncrement
Definition: armddk.h:53
BOOLEAN NTAPI USBPORT_EndpointHasQueuedTransfers(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN PULONG TransferCount)
Definition: endpoint.c:254
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel
Definition: iotypes.h:2313
Definition: usb.h:529
#define ROUND_TO_PAGES(Size)
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
VOID NTAPI USBPORT_WorkerThread(IN PVOID StartContext)
Definition: usbport.c:1368
#define USBPORT_MPFLAG_INTERRUPTS_ENABLED
Definition: usbport.h:101
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID NTAPI USBPORT_RemoveUSBxFdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:98
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:2521
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
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
BOOLEAN NTAPI USBPORT_QueueDoneTransfer(IN PUSBPORT_TRANSFER Transfer, IN USBD_STATUS USBDStatus)
Definition: usbport.c:839
ULONG NTAPI USBPORT_AssertFailure(PVOID MiniPortExtension, PVOID FailedAssertion, PVOID FileName, ULONG LineNumber, PCHAR Message)
Definition: debug.c:39
#define list
Definition: rosglue.h:35
LIST_ENTRY StateChangeLink
Definition: usbport.h:223
VOID NTAPI USBPORT_IsrDpcHandler(IN PDEVICE_OBJECT FdoDevice, IN BOOLEAN IsDpcHandler)
Definition: usbport.c:941
ULONG NTAPI USBPORT_DbgPrint(IN PVOID MiniPortExtension, IN ULONG Level, IN PCH Format,...)
Definition: debug.c:20
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
USBPORT_SCATTER_GATHER_ELEMENT SgElement[2]
Definition: usbmport.h:121
#define MP_STATUS_SUCCESS
Definition: usbmport.h:134
VOID NTAPI USBPORT_FlushClosedEndpointList(IN PDEVICE_OBJECT FdoDevice)
Definition: endpoint.c:1281
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
PHYSICAL_ADDRESS LogicalAddress
Definition: usbport.h:148
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define USBD_STATUS_CANCELED
Definition: usb.h:213
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:4565
PUSBPORT_GET_MINIPORT_REGISTRY_KEY_VALUE UsbPortGetMiniportRegistryKeyValue
Definition: usbmport.h:613
LIST_ENTRY SplitTransfersList
Definition: usbport.h:265
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI USBPORT_FdoPower(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: power.c:489
PUSBPORT_ISO_BLOCK IsoBlockPtr
Definition: usbport.h:268
NTSTATUS NTAPI USBPORT_PdoDeviceControl(IN PDEVICE_OBJECT PdoDevice, IN PIRP Irp)
Definition: ioctl.c:308
ULONG NTAPI USBPORT_InvalidateEndpoint(IN PVOID MiniPortExtension, IN PVOID MiniPortEndpoint)
Definition: usbport.c:2142
VOID NTAPI USBPORT_BugCheck(IN PVOID MiniPortExtension)
Definition: debug.c:52
PIRP NTAPI USBPORT_RemoveActiveTransferIrp(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: queue.c:357
#define ObReferenceObject
Definition: obfuncs.h:204
KSPIN_LOCK USBPORT_SpinLock
Definition: usbport.c:22
#define USB_MINIPORT_FLAGS_NOT_LOCK_INT
Definition: usbmport.h:536
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
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
struct tagContext Context
Definition: acpixf.h:1012
VOID NTAPI USB2_InitController(IN PUSB2_HC_EXTENSION HcExtension)
Definition: usb2.c:2217
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
NTSTATUS NTAPI USBPORT_FdoInternalDeviceControl(IN PDEVICE_OBJECT FdoDevice, IN PIRP Irp)
Definition: ioctl.c:454
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
ULONG NTAPI USBPORT_InvalidateController(IN PVOID MiniPortExtension, IN ULONG Type)
Definition: usbport.c:670
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define USBPORT_INVALIDATE_CONTROLLER_RESET
Definition: usbmport.h:489
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI USBPORT_TimerDpc(IN PRKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbport.c:1534
#define ULONG_PTR
Definition: config.h:101
#define INVALIDATE_ENDPOINT_WORKER_THREAD
Definition: usbport.h:37
KSPIN_LOCK TransferSpinLock
Definition: usbport.h:264
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define INVALIDATE_ENDPOINT_WORKER_DPC
Definition: usbport.h:38
#define USBPORT_TMFLAG_HC_SUSPENDED
Definition: usbport.h:93
VOID NTAPI USBPORT_AddUSB1Fdo(IN PDEVICE_OBJECT FdoDevice)
Definition: usbport.c:66
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define USBD_STATUS_INVALID_PIPE_HANDLE
Definition: usb.h:194
VOID NTAPI USBPORT_BadRequestFlush(IN PDEVICE_OBJECT FdoDevice)
Definition: queue.c:1327
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1036
PUSBPORT_WAIT UsbPortWait
Definition: usbmport.h:622
USBD_STATUS USBDStatus
Definition: usbport.h:257
#define KeGetCurrentThread
Definition: hal.h:44
#define TRANSFER_FLAG_COMPLETED
Definition: usbport.h:137
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
PUSBPORT_BUG_CHECK UsbPortBugCheck
Definition: usbmport.h:624
NTSTATUS NTAPI USBPORT_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: usbport.c:1811
ULONG CompletedTransferLen
Definition: usbport.h:258
PVOID MapRegisterBase
Definition: usbport.h:260
return STATUS_SUCCESS
Definition: btrfs.c:2777
VOID NTAPI USBPORT_InvalidateEndpointHandler(IN PDEVICE_OBJECT FdoDevice, IN PUSBPORT_ENDPOINT Endpoint, IN ULONG Type)
Definition: endpoint.c:1317
#define USB10_MINIPORT_INTERFACE_VERSION
Definition: usbmport.h:636
LPFNPSPCALLBACK Callback
Definition: desk.c:111
KSPIN_LOCK EndpointSpinLock
Definition: usbport.h:214
#define USBPORT_PNP_STATE_STARTED
Definition: usbport.h:87
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
ULONG TransferBufferLength
Definition: usb.h:470
static PLARGE_INTEGER Time
Definition: time.c:105
LIST_ENTRY USBPORT_MiniPortDrivers
Definition: usbport.c:18
base of all file and directory entries
Definition: entries.h:82
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:107
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:61
LONGLONG QuadPart
Definition: typedefs.h:112
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define USBPORT_TMFLAG_TIMER_QUEUED
Definition: usbport.h:92
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
#define TRANSFER_FLAG_SUBMITED
Definition: usbport.h:132
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:675