MdeModulePkg UsbBusPei: Produce a USB I/O PPI for all USB Interfaces a USB Device...
authorStar Zeng <star.zeng@intel.com>
Tue, 11 Feb 2014 08:00:52 +0000 (08:00 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 11 Feb 2014 08:00:52 +0000 (08:00 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15218 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h

index b63173d..23090f6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 The module to produce Usb Bus PPI.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
   \r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
@@ -222,6 +222,8 @@ PeiHubEnumeration (
   UINTN                 MemPages;\r
   EFI_PHYSICAL_ADDRESS  AllocateAddress;\r
   PEI_USB_DEVICE        *NewPeiUsbDevice;\r
+  UINTN                 InterfaceIndex;\r
+  UINTN                 EndpointIndex;\r
 \r
 \r
   UsbIoPpi    = &PeiUsbDevice->UsbIoPpi;\r
@@ -341,8 +343,43 @@ PeiHubEnumeration (
 \r
           PeiHubEnumeration (PeiServices, NewPeiUsbDevice, CurrentAddress);\r
         }\r
-      }\r
 \r
+        for (InterfaceIndex = 1; InterfaceIndex < NewPeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {\r
+          //\r
+          // Begin to deal with the new device\r
+          //\r
+          MemPages = sizeof (PEI_USB_DEVICE) / EFI_PAGE_SIZE + 1;\r
+          Status = PeiServicesAllocatePages (\r
+                     EfiBootServicesCode,\r
+                     MemPages,\r
+                     &AllocateAddress\r
+                     );\r
+          if (EFI_ERROR (Status)) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+          CopyMem ((VOID *)(UINTN)AllocateAddress, NewPeiUsbDevice, sizeof (PEI_USB_DEVICE));\r
+          NewPeiUsbDevice = (PEI_USB_DEVICE *) ((UINTN) AllocateAddress);\r
+          NewPeiUsbDevice->AllocateAddress  = (UINTN) AllocateAddress;\r
+          NewPeiUsbDevice->UsbIoPpiList.Ppi = &NewPeiUsbDevice->UsbIoPpi;\r
+          NewPeiUsbDevice->InterfaceDesc = NewPeiUsbDevice->InterfaceDescList[InterfaceIndex];\r
+          for (EndpointIndex = 0; EndpointIndex < NewPeiUsbDevice->InterfaceDesc->NumEndpoints; EndpointIndex++) {\r
+            NewPeiUsbDevice->EndpointDesc[EndpointIndex] = NewPeiUsbDevice->EndpointDescList[InterfaceIndex][EndpointIndex];\r
+          }\r
+\r
+          Status = PeiServicesInstallPpi (&NewPeiUsbDevice->UsbIoPpiList);\r
+\r
+          if (NewPeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {\r
+            NewPeiUsbDevice->IsHub  = 0x1;\r
+\r
+            Status = PeiDoHubConfig (PeiServices, NewPeiUsbDevice);\r
+            if (EFI_ERROR (Status)) {\r
+              return Status;\r
+            }\r
+\r
+            PeiHubEnumeration (PeiServices, NewPeiUsbDevice, CurrentAddress);\r
+          }\r
+        }\r
+      }\r
     }\r
   }\r
 \r
@@ -377,7 +414,8 @@ PeiUsbEnumeration (
   UINTN                 MemPages;\r
   EFI_PHYSICAL_ADDRESS  AllocateAddress;\r
   UINT8                 CurrentAddress;\r
-\r
+  UINTN                 InterfaceIndex;\r
+  UINTN                 EndpointIndex;\r
 \r
   CurrentAddress = 0;\r
   if (Usb2HcPpi != NULL) {\r
@@ -546,6 +584,42 @@ PeiUsbEnumeration (
 \r
           PeiHubEnumeration (PeiServices, PeiUsbDevice, &CurrentAddress);\r
         }\r
+\r
+        for (InterfaceIndex = 1; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {\r
+          //\r
+          // Begin to deal with the new device\r
+          //\r
+          MemPages = sizeof (PEI_USB_DEVICE) / EFI_PAGE_SIZE + 1;\r
+          Status = PeiServicesAllocatePages (\r
+                     EfiBootServicesCode,\r
+                     MemPages,\r
+                     &AllocateAddress\r
+                     );\r
+          if (EFI_ERROR (Status)) {\r
+            return EFI_OUT_OF_RESOURCES;\r
+          }\r
+          CopyMem ((VOID *)(UINTN)AllocateAddress, PeiUsbDevice, sizeof (PEI_USB_DEVICE));\r
+          PeiUsbDevice = (PEI_USB_DEVICE *) ((UINTN) AllocateAddress);\r
+          PeiUsbDevice->AllocateAddress  = (UINTN) AllocateAddress;\r
+          PeiUsbDevice->UsbIoPpiList.Ppi = &PeiUsbDevice->UsbIoPpi;\r
+          PeiUsbDevice->InterfaceDesc = PeiUsbDevice->InterfaceDescList[InterfaceIndex];\r
+          for (EndpointIndex = 0; EndpointIndex < PeiUsbDevice->InterfaceDesc->NumEndpoints; EndpointIndex++) {\r
+            PeiUsbDevice->EndpointDesc[EndpointIndex] = PeiUsbDevice->EndpointDescList[InterfaceIndex][EndpointIndex];\r
+          }\r
+\r
+          Status = PeiServicesInstallPpi (&PeiUsbDevice->UsbIoPpiList);\r
+\r
+          if (PeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {\r
+            PeiUsbDevice->IsHub = 0x1;\r
+\r
+            Status = PeiDoHubConfig (PeiServices, PeiUsbDevice);\r
+            if (EFI_ERROR (Status)) {\r
+              return Status;\r
+            }\r
+\r
+            PeiHubEnumeration (PeiServices, PeiUsbDevice, &CurrentAddress);\r
+          }\r
+        }\r
       } else {\r
         //\r
         // Disconnect change happen, currently we don't support\r
@@ -647,6 +721,7 @@ PeiConfigureUsbDevice (
     DEBUG ((EFI_D_ERROR, "PeiUsbGetDescriptor First Failed\n"));\r
     return Status;\r
   }\r
+\r
   //\r
   // Get its default configuration and its first interface\r
   //\r
@@ -654,7 +729,6 @@ PeiConfigureUsbDevice (
             PeiServices,\r
             PeiUsbDevice\r
             );\r
-\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -695,6 +769,7 @@ PeiUsbGetAllConfiguration (
   UINT8                     *Ptr;\r
   UINTN                     SkipBytes;\r
   UINTN                     LengthLeft;\r
+  UINTN                     InterfaceIndex;\r
   UINTN                     Index;\r
   UINTN                     NumOfEndpoint;\r
 \r
@@ -758,43 +833,16 @@ PeiUsbGetAllConfiguration (
   Ptr += sizeof (EFI_USB_CONFIG_DESCRIPTOR);\r
   LengthLeft = ConfigDescLength - SkipBytes - sizeof (EFI_USB_CONFIG_DESCRIPTOR);\r
 \r
-  //\r
-  // Get the first interface descriptor\r
-  //\r
-  Status = GetExpectedDescriptor (\r
-            Ptr,\r
-            LengthLeft,\r
-            USB_DT_INTERFACE,\r
-            (UINT8) sizeof (EFI_USB_INTERFACE_DESCRIPTOR),\r
-            &SkipBytes\r
-            );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Ptr += SkipBytes;\r
-  PeiUsbDevice->InterfaceDesc = (EFI_USB_INTERFACE_DESCRIPTOR *) Ptr;\r
+  for (InterfaceIndex = 0; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {\r
 \r
-  Ptr += sizeof (EFI_USB_INTERFACE_DESCRIPTOR);\r
-  LengthLeft -= SkipBytes;\r
-  LengthLeft -= sizeof (EFI_USB_INTERFACE_DESCRIPTOR);\r
-\r
-  //\r
-  // Parse all the endpoint descriptor within this interface\r
-  //\r
-  NumOfEndpoint = PeiUsbDevice->InterfaceDesc->NumEndpoints;\r
-  ASSERT (NumOfEndpoint <= MAX_ENDPOINT);\r
-\r
-  for (Index = 0; Index < NumOfEndpoint; Index++) {\r
     //\r
-    // Get the endpoint descriptor\r
+    // Get the interface descriptor\r
     //\r
     Status = GetExpectedDescriptor (\r
               Ptr,\r
               LengthLeft,\r
-              USB_DT_ENDPOINT,\r
-              (UINT8) sizeof (EFI_USB_ENDPOINT_DESCRIPTOR),\r
+              USB_DT_INTERFACE,\r
+              (UINT8) sizeof (EFI_USB_INTERFACE_DESCRIPTOR),\r
               &SkipBytes\r
               );\r
 \r
@@ -803,11 +851,47 @@ PeiUsbGetAllConfiguration (
     }\r
 \r
     Ptr += SkipBytes;\r
-    PeiUsbDevice->EndpointDesc[Index] = (EFI_USB_ENDPOINT_DESCRIPTOR *) Ptr;\r
+    if (InterfaceIndex == 0) {\r
+      PeiUsbDevice->InterfaceDesc = (EFI_USB_INTERFACE_DESCRIPTOR *) Ptr;\r
+    }\r
+    PeiUsbDevice->InterfaceDescList[InterfaceIndex] = (EFI_USB_INTERFACE_DESCRIPTOR *) Ptr;\r
 \r
-    Ptr += sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);\r
+    Ptr += sizeof (EFI_USB_INTERFACE_DESCRIPTOR);\r
     LengthLeft -= SkipBytes;\r
-    LengthLeft -= sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);\r
+    LengthLeft -= sizeof (EFI_USB_INTERFACE_DESCRIPTOR);\r
+\r
+    //\r
+    // Parse all the endpoint descriptor within this interface\r
+    //\r
+    NumOfEndpoint = PeiUsbDevice->InterfaceDescList[InterfaceIndex]->NumEndpoints;\r
+    ASSERT (NumOfEndpoint <= MAX_ENDPOINT);\r
+\r
+    for (Index = 0; Index < NumOfEndpoint; Index++) {\r
+      //\r
+      // Get the endpoint descriptor\r
+      //\r
+      Status = GetExpectedDescriptor (\r
+                Ptr,\r
+                LengthLeft,\r
+                USB_DT_ENDPOINT,\r
+                (UINT8) sizeof (EFI_USB_ENDPOINT_DESCRIPTOR),\r
+                &SkipBytes\r
+                );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+\r
+      Ptr += SkipBytes;\r
+      if (InterfaceIndex == 0) {\r
+        PeiUsbDevice->EndpointDesc[Index] = (EFI_USB_ENDPOINT_DESCRIPTOR *) Ptr;\r
+      }\r
+      PeiUsbDevice->EndpointDescList[InterfaceIndex][Index] = (EFI_USB_ENDPOINT_DESCRIPTOR *) Ptr;\r
+\r
+      Ptr += sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);\r
+      LengthLeft -= SkipBytes;\r
+      LengthLeft -= sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
index 21235b5..4685034 100644 (file)
@@ -34,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <IndustryStandard/Usb.h>\r
 \r
 #define MAX_ROOT_PORT             2\r
+#define MAX_INTERFACE             8\r
 #define MAX_ENDPOINT              16\r
 \r
 #define USB_SLOW_SPEED_DEVICE     0x01\r
@@ -57,7 +58,9 @@ typedef struct {
   UINT8                         ConfigurationData[1024];\r
   EFI_USB_CONFIG_DESCRIPTOR     *ConfigDesc;\r
   EFI_USB_INTERFACE_DESCRIPTOR  *InterfaceDesc;\r
+  EFI_USB_INTERFACE_DESCRIPTOR  *InterfaceDescList[MAX_INTERFACE];\r
   EFI_USB_ENDPOINT_DESCRIPTOR   *EndpointDesc[MAX_ENDPOINT];\r
+  EFI_USB_ENDPOINT_DESCRIPTOR   *EndpointDescList[MAX_INTERFACE][MAX_ENDPOINT];\r
   EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;  \r
 } PEI_USB_DEVICE;\r
 \r