[USBPORT] Implement USBPORT_InitializeTT().
authorVadim Galyant <vgal@rambler.ru>
Mon, 27 Nov 2017 09:20:28 +0000 (18:20 +0900)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 21 Jan 2018 18:35:38 +0000 (19:35 +0100)
drivers/usb/usbport/device.c
drivers/usb/usbport/usbport.h

index f7180aa..268571f 100644 (file)
@@ -1770,7 +1770,55 @@ USBPORT_InitializeTT(IN PDEVICE_OBJECT FdoDevice,
                      IN PUSBPORT_DEVICE_HANDLE HubDeviceHandle,
                      IN ULONG TtNumber)
 {
-    DPRINT1("USBPORT_InitializeTT: UNIMPLEMENTED. FIXME. \n");
+    PUSBPORT_DEVICE_EXTENSION FdoExtension;
+    PUSB2_TT_EXTENSION TtExtension;
+    ULONG ix;
+
+    DPRINT("USBPORT_InitializeTT: HubDeviceHandle - %p, TtNumber - %X\n",
+           HubDeviceHandle,
+           TtNumber);
+
+    FdoExtension = FdoDevice->DeviceExtension;
+
+    TtExtension = ExAllocatePoolWithTag(NonPagedPool,
+                                        sizeof(USB2_TT_EXTENSION),
+                                        USB_PORT_TAG);
+
+    if (!TtExtension)
+    {
+        DPRINT1("USBPORT_InitializeTT: ExAllocatePoolWithTag return NULL\n");
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    DPRINT("USBPORT_InitializeTT: TtExtension - %p\n", TtExtension);
+
+    RtlZeroMemory(TtExtension, sizeof(USB2_TT_EXTENSION));
+
+    TtExtension->DeviceAddress = HubDeviceHandle->DeviceAddress;
+    TtExtension->TtNumber = TtNumber;
+    TtExtension->RootHubPdo = FdoExtension->RootHubPdo;
+    TtExtension->BusBandwidth = TOTAL_USB11_BUS_BANDWIDTH;
+
+    InitializeListHead(&TtExtension->TtList);
+
+    /* 90% maximum allowed for periodic endpoints */
+    for (ix = 0; ix < USB2_FRAMES; ix++)
+    {
+        TtExtension->Bandwidth[ix] = TtExtension->BusBandwidth -
+                                     TtExtension->BusBandwidth / 10;
+    }
+
+    USBPORT_UpdateAllocatedBwTt(TtExtension);
+
+    for (ix = 0; ix < USB2_FRAMES; ix++)
+    {
+        FdoExtension->Bandwidth[ix] -= TtExtension->MaxBandwidth;
+    }
+
+    USB2_InitTT(FdoExtension->Usb2Extension, &TtExtension->Tt);
+
+    InsertTailList(&HubDeviceHandle->TtList, &TtExtension->Link);
+
     return STATUS_SUCCESS;
 }
 
@@ -1783,7 +1831,7 @@ USBPORT_Initialize20Hub(IN PDEVICE_OBJECT FdoDevice,
     NTSTATUS Status;
     ULONG ix;
 
-    DPRINT("USBPORT_Initialize20Hub \n");
+    DPRINT("USBPORT_Initialize20Hub: TtCount - %X\n", TtCount);
 
     if (!HubDeviceHandle)
     {
index 93c71a9..026b297 100644 (file)
@@ -194,6 +194,7 @@ typedef struct _USBPORT_DEVICE_HANDLE {
   LIST_ENTRY DeviceHandleLink;
   LONG DeviceHandleLock;
   ULONG TtCount;
+  LIST_ENTRY TtList;
 } USBPORT_DEVICE_HANDLE, *PUSBPORT_DEVICE_HANDLE;
 
 typedef struct _USBPORT_ENDPOINT {
@@ -379,10 +380,11 @@ typedef struct _USBPORT_DEVICE_EXTENSION {
   KDPC HcWakeDpc;
   /* Usb 2.0 HC Extension */
   PUSB2_HC_EXTENSION Usb2Extension;
+  ULONG Bandwidth[32];
 
   /* Miniport extension should be aligned on 0x100 */
 #if !defined(_M_X64)
-  ULONG Padded[33];
+  ULONG Padded[1];
 #else
   ULONG Padded[0];
 #endif
@@ -1294,6 +1296,12 @@ USBPORT_FreeBandwidthUSB2(
   IN PDEVICE_OBJECT FdoDevice,
   IN PUSBPORT_ENDPOINT Endpoint);
 
+VOID
+NTAPI
+USB2_InitTT(
+  IN PUSB2_HC_EXTENSION HcExtension,
+  IN PUSB2_TT Tt);
+
 VOID
 NTAPI
 USB2_InitController(