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
This commit is contained in:
Star Zeng 2014-02-11 08:00:52 +00:00 committed by lzeng14
parent 3038da1b93
commit 8a718ba91b
2 changed files with 125 additions and 38 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
The module to produce Usb Bus PPI. 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 This program and the accompanying materials
are licensed and made available under the terms and conditions are licensed and made available under the terms and conditions
@ -222,6 +222,8 @@ PeiHubEnumeration (
UINTN MemPages; UINTN MemPages;
EFI_PHYSICAL_ADDRESS AllocateAddress; EFI_PHYSICAL_ADDRESS AllocateAddress;
PEI_USB_DEVICE *NewPeiUsbDevice; PEI_USB_DEVICE *NewPeiUsbDevice;
UINTN InterfaceIndex;
UINTN EndpointIndex;
UsbIoPpi = &PeiUsbDevice->UsbIoPpi; UsbIoPpi = &PeiUsbDevice->UsbIoPpi;
@ -341,8 +343,43 @@ PeiHubEnumeration (
PeiHubEnumeration (PeiServices, NewPeiUsbDevice, CurrentAddress); 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; UINTN MemPages;
EFI_PHYSICAL_ADDRESS AllocateAddress; EFI_PHYSICAL_ADDRESS AllocateAddress;
UINT8 CurrentAddress; UINT8 CurrentAddress;
UINTN InterfaceIndex;
UINTN EndpointIndex;
CurrentAddress = 0; CurrentAddress = 0;
if (Usb2HcPpi != NULL) { if (Usb2HcPpi != NULL) {
@ -546,6 +584,42 @@ PeiUsbEnumeration (
PeiHubEnumeration (PeiServices, PeiUsbDevice, &CurrentAddress); 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 { } else {
// //
// Disconnect change happen, currently we don't support // Disconnect change happen, currently we don't support
@ -647,6 +721,7 @@ PeiConfigureUsbDevice (
DEBUG ((EFI_D_ERROR, "PeiUsbGetDescriptor First Failed\n")); DEBUG ((EFI_D_ERROR, "PeiUsbGetDescriptor First Failed\n"));
return Status; return Status;
} }
// //
// Get its default configuration and its first interface // Get its default configuration and its first interface
// //
@ -654,7 +729,6 @@ PeiConfigureUsbDevice (
PeiServices, PeiServices,
PeiUsbDevice PeiUsbDevice
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -695,6 +769,7 @@ PeiUsbGetAllConfiguration (
UINT8 *Ptr; UINT8 *Ptr;
UINTN SkipBytes; UINTN SkipBytes;
UINTN LengthLeft; UINTN LengthLeft;
UINTN InterfaceIndex;
UINTN Index; UINTN Index;
UINTN NumOfEndpoint; UINTN NumOfEndpoint;
@ -758,43 +833,16 @@ PeiUsbGetAllConfiguration (
Ptr += sizeof (EFI_USB_CONFIG_DESCRIPTOR); Ptr += sizeof (EFI_USB_CONFIG_DESCRIPTOR);
LengthLeft = ConfigDescLength - SkipBytes - sizeof (EFI_USB_CONFIG_DESCRIPTOR); LengthLeft = ConfigDescLength - SkipBytes - sizeof (EFI_USB_CONFIG_DESCRIPTOR);
// for (InterfaceIndex = 0; InterfaceIndex < PeiUsbDevice->ConfigDesc->NumInterfaces; InterfaceIndex++) {
// 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;
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 ( Status = GetExpectedDescriptor (
Ptr, Ptr,
LengthLeft, LengthLeft,
USB_DT_ENDPOINT, USB_DT_INTERFACE,
(UINT8) sizeof (EFI_USB_ENDPOINT_DESCRIPTOR), (UINT8) sizeof (EFI_USB_INTERFACE_DESCRIPTOR),
&SkipBytes &SkipBytes
); );
@ -803,11 +851,47 @@ PeiUsbGetAllConfiguration (
} }
Ptr += SkipBytes; 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 -= 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; return EFI_SUCCESS;

View File

@ -34,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <IndustryStandard/Usb.h> #include <IndustryStandard/Usb.h>
#define MAX_ROOT_PORT 2 #define MAX_ROOT_PORT 2
#define MAX_INTERFACE 8
#define MAX_ENDPOINT 16 #define MAX_ENDPOINT 16
#define USB_SLOW_SPEED_DEVICE 0x01 #define USB_SLOW_SPEED_DEVICE 0x01
@ -57,7 +58,9 @@ typedef struct {
UINT8 ConfigurationData[1024]; UINT8 ConfigurationData[1024];
EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc; EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc;
EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc; EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc;
EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescList[MAX_INTERFACE];
EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc[MAX_ENDPOINT]; EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc[MAX_ENDPOINT];
EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescList[MAX_INTERFACE][MAX_ENDPOINT];
EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator; EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;
} PEI_USB_DEVICE; } PEI_USB_DEVICE;