summaryrefslogtreecommitdiff
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorStar Zeng <star.zeng@intel.com>2014-02-11 08:00:52 +0000
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>2014-02-11 08:00:52 +0000
commit8a718ba91ba255f2629b274ff07bd7adb0ad7ab1 (patch)
tree4290431eb967d7437985d11c38fd4dc8f116bf9c /MdeModulePkg
parent3038da1b93b782334ad346be52d6cbaa19555830 (diff)
downloadedk2-8a718ba91ba255f2629b274ff07bd7adb0ad7ab1.zip
edk2-8a718ba91ba255f2629b274ff07bd7adb0ad7ab1.tar.gz
edk2-8a718ba91ba255f2629b274ff07bd7adb0ad7ab1.tar.bz2
MdeModulePkg UsbBusPei: Produce a USB I/O PPI for all USB Interfaces a USB Device advertises in its USB configuration.
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
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c160
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h3
2 files changed, 125 insertions, 38 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
index b63173d..23090f6 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c
@@ -1,7 +1,7 @@
/** @file
The module to produce Usb Bus PPI.
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
@@ -222,6 +222,8 @@ PeiHubEnumeration (
UINTN MemPages;
EFI_PHYSICAL_ADDRESS AllocateAddress;
PEI_USB_DEVICE *NewPeiUsbDevice;
+ UINTN InterfaceIndex;
+ UINTN EndpointIndex;
UsbIoPpi = &PeiUsbDevice->UsbIoPpi;
@@ -341,8 +343,43 @@ PeiHubEnumeration (
PeiHubEnumeration (PeiServices, NewPeiUsbDevice, CurrentAddress);
}
- }
+ for (InterfaceIndex = 1; InterfaceIndex < NewPeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
+ //
+ // Begin to deal with the new device
+ //
+ MemPages = sizeof (PEI_USB_DEVICE) / EFI_PAGE_SIZE + 1;
+ Status = PeiServicesAllocatePages (
+ EfiBootServicesCode,
+ MemPages,
+ &AllocateAddress
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ CopyMem ((VOID *)(UINTN)AllocateAddress, NewPeiUsbDevice, sizeof (PEI_USB_DEVICE));
+ NewPeiUsbDevice = (PEI_USB_DEVICE *) ((UINTN) AllocateAddress);
+ NewPeiUsbDevice->AllocateAddress = (UINTN) AllocateAddress;
+ NewPeiUsbDevice->UsbIoPpiList.Ppi = &NewPeiUsbDevice->UsbIoPpi;
+ NewPeiUsbDevice->InterfaceDesc = NewPeiUsbDevice->InterfaceDescList[InterfaceIndex];
+ for (EndpointIndex = 0; EndpointIndex < NewPeiUsbDevice->InterfaceDesc->NumEndpoints; EndpointIndex++) {
+ NewPeiUsbDevice->EndpointDesc[EndpointIndex] = NewPeiUsbDevice->EndpointDescList[InterfaceIndex][EndpointIndex];
+ }
+
+ Status = PeiServicesInstallPpi (&NewPeiUsbDevice->UsbIoPpiList);
+
+ if (NewPeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {
+ NewPeiUsbDevice->IsHub = 0x1;
+
+ Status = PeiDoHubConfig (PeiServices, NewPeiUsbDevice);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ PeiHubEnumeration (PeiServices, NewPeiUsbDevice, CurrentAddress);
+ }
+ }
+ }
}
}
@@ -377,7 +414,8 @@ PeiUsbEnumeration (
UINTN MemPages;
EFI_PHYSICAL_ADDRESS AllocateAddress;
UINT8 CurrentAddress;
-
+ UINTN InterfaceIndex;
+ UINTN EndpointIndex;
CurrentAddress = 0;
if (Usb2HcPpi != NULL) {
@@ -546,6 +584,42 @@ PeiUsbEnumeration (
PeiHubEnumeration (PeiServices, PeiUsbDevice, &CurrentAddress);
}
+
+ for (InterfaceIndex = 1; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
+ //
+ // Begin to deal with the new device
+ //
+ MemPages = sizeof (PEI_USB_DEVICE) / EFI_PAGE_SIZE + 1;
+ Status = PeiServicesAllocatePages (
+ EfiBootServicesCode,
+ MemPages,
+ &AllocateAddress
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ CopyMem ((VOID *)(UINTN)AllocateAddress, PeiUsbDevice, sizeof (PEI_USB_DEVICE));
+ PeiUsbDevice = (PEI_USB_DEVICE *) ((UINTN) AllocateAddress);
+ PeiUsbDevice->AllocateAddress = (UINTN) AllocateAddress;
+ PeiUsbDevice->UsbIoPpiList.Ppi = &PeiUsbDevice->UsbIoPpi;
+ PeiUsbDevice->InterfaceDesc = PeiUsbDevice->InterfaceDescList[InterfaceIndex];
+ for (EndpointIndex = 0; EndpointIndex < PeiUsbDevice->InterfaceDesc->NumEndpoints; EndpointIndex++) {
+ PeiUsbDevice->EndpointDesc[EndpointIndex] = PeiUsbDevice->EndpointDescList[InterfaceIndex][EndpointIndex];
+ }
+
+ Status = PeiServicesInstallPpi (&PeiUsbDevice->UsbIoPpiList);
+
+ if (PeiUsbDevice->InterfaceDesc->InterfaceClass == 0x09) {
+ PeiUsbDevice->IsHub = 0x1;
+
+ Status = PeiDoHubConfig (PeiServices, PeiUsbDevice);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ PeiHubEnumeration (PeiServices, PeiUsbDevice, &CurrentAddress);
+ }
+ }
} else {
//
// Disconnect change happen, currently we don't support
@@ -647,6 +721,7 @@ PeiConfigureUsbDevice (
DEBUG ((EFI_D_ERROR, "PeiUsbGetDescriptor First Failed\n"));
return Status;
}
+
//
// Get its default configuration and its first interface
//
@@ -654,7 +729,6 @@ PeiConfigureUsbDevice (
PeiServices,
PeiUsbDevice
);
-
if (EFI_ERROR (Status)) {
return Status;
}
@@ -695,6 +769,7 @@ PeiUsbGetAllConfiguration (
UINT8 *Ptr;
UINTN SkipBytes;
UINTN LengthLeft;
+ UINTN InterfaceIndex;
UINTN Index;
UINTN NumOfEndpoint;
@@ -758,43 +833,16 @@ PeiUsbGetAllConfiguration (
Ptr += sizeof (EFI_USB_CONFIG_DESCRIPTOR);
LengthLeft = ConfigDescLength - SkipBytes - sizeof (EFI_USB_CONFIG_DESCRIPTOR);
- //
- // Get the first interface descriptor
- //
- Status = GetExpectedDescriptor (
- Ptr,
- LengthLeft,
- USB_DT_INTERFACE,
- (UINT8) sizeof (EFI_USB_INTERFACE_DESCRIPTOR),
- &SkipBytes
- );
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- Ptr += SkipBytes;
- PeiUsbDevice->InterfaceDesc = (EFI_USB_INTERFACE_DESCRIPTOR *) Ptr;
+ for (InterfaceIndex = 0; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
- Ptr += sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
- LengthLeft -= SkipBytes;
- LengthLeft -= sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
-
- //
- // Parse all the endpoint descriptor within this interface
- //
- NumOfEndpoint = PeiUsbDevice->InterfaceDesc->NumEndpoints;
- ASSERT (NumOfEndpoint <= MAX_ENDPOINT);
-
- for (Index = 0; Index < NumOfEndpoint; Index++) {
//
- // Get the endpoint descriptor
+ // Get the interface descriptor
//
Status = GetExpectedDescriptor (
Ptr,
LengthLeft,
- USB_DT_ENDPOINT,
- (UINT8) sizeof (EFI_USB_ENDPOINT_DESCRIPTOR),
+ USB_DT_INTERFACE,
+ (UINT8) sizeof (EFI_USB_INTERFACE_DESCRIPTOR),
&SkipBytes
);
@@ -803,11 +851,47 @@ PeiUsbGetAllConfiguration (
}
Ptr += SkipBytes;
- PeiUsbDevice->EndpointDesc[Index] = (EFI_USB_ENDPOINT_DESCRIPTOR *) Ptr;
+ if (InterfaceIndex == 0) {
+ PeiUsbDevice->InterfaceDesc = (EFI_USB_INTERFACE_DESCRIPTOR *) Ptr;
+ }
+ PeiUsbDevice->InterfaceDescList[InterfaceIndex] = (EFI_USB_INTERFACE_DESCRIPTOR *) Ptr;
- Ptr += sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
+ Ptr += sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
LengthLeft -= SkipBytes;
- LengthLeft -= sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
+ LengthLeft -= sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
+
+ //
+ // Parse all the endpoint descriptor within this interface
+ //
+ NumOfEndpoint = PeiUsbDevice->InterfaceDescList[InterfaceIndex]->NumEndpoints;
+ ASSERT (NumOfEndpoint <= MAX_ENDPOINT);
+
+ for (Index = 0; Index < NumOfEndpoint; Index++) {
+ //
+ // Get the endpoint descriptor
+ //
+ Status = GetExpectedDescriptor (
+ Ptr,
+ LengthLeft,
+ USB_DT_ENDPOINT,
+ (UINT8) sizeof (EFI_USB_ENDPOINT_DESCRIPTOR),
+ &SkipBytes
+ );
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Ptr += SkipBytes;
+ if (InterfaceIndex == 0) {
+ PeiUsbDevice->EndpointDesc[Index] = (EFI_USB_ENDPOINT_DESCRIPTOR *) Ptr;
+ }
+ PeiUsbDevice->EndpointDescList[InterfaceIndex][Index] = (EFI_USB_ENDPOINT_DESCRIPTOR *) Ptr;
+
+ Ptr += sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
+ LengthLeft -= SkipBytes;
+ LengthLeft -= sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
+ }
}
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
index 21235b5..4685034 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
+++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h
@@ -34,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <IndustryStandard/Usb.h>
#define MAX_ROOT_PORT 2
+#define MAX_INTERFACE 8
#define MAX_ENDPOINT 16
#define USB_SLOW_SPEED_DEVICE 0x01
@@ -57,7 +58,9 @@ typedef struct {
UINT8 ConfigurationData[1024];
EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc;
EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc;
+ EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescList[MAX_INTERFACE];
EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc[MAX_ENDPOINT];
+ EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescList[MAX_INTERFACE][MAX_ENDPOINT];
EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;
} PEI_USB_DEVICE;