From: Star Zeng Date: Tue, 11 Feb 2014 08:00:52 +0000 (+0000) Subject: MdeModulePkg UsbBusPei: Produce a USB I/O PPI for all USB Interfaces a USB Device... X-Git-Tag: edk2-stable201903~11739 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=8a718ba91ba255f2629b274ff07bd7adb0ad7ab1;hp=3038da1b93b782334ad346be52d6cbaa19555830 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 Reviewed-by: Feng Tian git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15218 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c index b63173d181..23090f68f3 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.
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
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 21235b5699..4685034a5c 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 #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;