X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FUsb%2FUsbBusDxe%2FUsbEnumer.c;h=a6dc1c0c29d52f5d1d7c29d7bfc9068a917e5b4c;hp=6b46e5c3ce4548ef91f249a29b394e9f3d31a015;hb=cd5ebaa06dca3e6ef3c464081e6defe00d358c69;hpb=ecb575d9e65c9d52c17866eebba5f798f178effe diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c index 6b46e5c3ce..a6dc1c0c29 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -1,7 +1,9 @@ /** @file -Copyright (c) 2007, Intel Corporation -All rights reserved. This program and the accompanying materials + Usb bus enumeration support. + +Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -9,29 +11,18 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - Module Name: - - UsbEnumer.c - - Abstract: - - Usb bus enumeration support - - Revision History - - **/ #include "UsbBus.h" /** - Return the endpoint descriptor in this interface + Return the endpoint descriptor in this interface. - @param UsbIf The interface to search in - @param EpAddr The address of the endpoint to return + @param UsbIf The interface to search in. + @param EpAddr The address of the endpoint to return. - @return The endpoint descriptor or NULL + @return The endpoint descriptor or NULL. **/ USB_ENDPOINT_DESC * @@ -41,9 +32,12 @@ UsbGetEndpointDesc ( ) { USB_ENDPOINT_DESC *EpDesc; - UINTN Index; - - for (Index = 0; Index < UsbIf->IfSetting->Desc.NumEndpoints; Index++) { + UINT8 Index; + UINT8 NumEndpoints; + + NumEndpoints = UsbIf->IfSetting->Desc.NumEndpoints; + + for (Index = 0; Index < NumEndpoints; Index++) { EpDesc = UsbIf->IfSetting->Endpoints[Index]; if (EpDesc->Desc.EndpointAddress == EpAddr) { @@ -56,14 +50,11 @@ UsbGetEndpointDesc ( /** - Free the resource used by USB interface - - @param UsbIf The USB interface to free + Free the resource used by USB interface. - @return None + @param UsbIf The USB interface to free. **/ -STATIC VOID UsbFreeInterface ( IN USB_INTERFACE *UsbIf @@ -81,10 +72,10 @@ UsbFreeInterface ( ); if (UsbIf->DevicePath != NULL) { - gBS->FreePool (UsbIf->DevicePath); + FreePool (UsbIf->DevicePath); } - gBS->FreePool (UsbIf); + FreePool (UsbIf); } @@ -92,13 +83,12 @@ UsbFreeInterface ( Create an interface for the descriptor IfDesc. Each device's configuration can have several interfaces. - @param Device The device has the interface descriptor - @param IfDesc The interface descriptor + @param Device The device has the interface descriptor. + @param IfDesc The interface descriptor. @return The created USB interface for the descriptor, or NULL. **/ -STATIC USB_INTERFACE * UsbCreateInterface ( IN USB_DEVICE *Device, @@ -119,6 +109,7 @@ UsbCreateInterface ( UsbIf->Signature = USB_INTERFACE_SIGNATURE; UsbIf->Device = Device; UsbIf->IfDesc = IfDesc; + ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING); UsbIf->IfSetting = IfDesc->Settings[IfDesc->ActiveIndex]; CopyMem ( @@ -185,24 +176,21 @@ UsbCreateInterface ( return UsbIf; ON_ERROR: - if (UsbIf->DevicePath) { - gBS->FreePool (UsbIf->DevicePath); + if (UsbIf->DevicePath != NULL) { + FreePool (UsbIf->DevicePath); } - gBS->FreePool (UsbIf); + FreePool (UsbIf); return NULL; } /** - Free the resource used by this USB device - - @param Device The USB device to free + Free the resource used by this USB device. - @return None + @param Device The USB device to free. **/ -STATIC VOID UsbFreeDevice ( IN USB_DEVICE *Device @@ -219,13 +207,12 @@ UsbFreeDevice ( /** Create a device which is on the parent's ParentPort port. - @param ParentIf The parent HUB interface - @param ParentPort The port on the HUB this device is connected to + @param ParentIf The parent HUB interface. + @param ParentPort The port on the HUB this device is connected to. - @return Created USB device + @return Created USB device, Or NULL. **/ -STATIC USB_DEVICE * UsbCreateDevice ( IN USB_INTERFACE *ParentIf, @@ -253,15 +240,14 @@ UsbCreateDevice ( /** Connect the USB interface with its driver. EFI USB bus will - create a USB interface for each seperate interface descriptor. + create a USB interface for each separate interface descriptor. - @param UsbIf The interface to connect driver to + @param UsbIf The interface to connect driver to. - @return EFI_SUCCESS : Interface is managed by some driver - @return Others : Failed to locate a driver for this interface + @return EFI_SUCCESS Interface is managed by some driver. + @return Others Failed to locate a driver for this interface. **/ -STATIC EFI_STATUS UsbConnectDriver ( IN USB_INTERFACE *UsbIf @@ -294,14 +280,14 @@ UsbConnectDriver ( // if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) { OldTpl = UsbGetCurrentTpl (); - DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", OldTpl)); + DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle)); gBS->RestoreTPL (TPL_CALLBACK); Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE); UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status); - DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl())); + DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", (UINT32)UsbGetCurrentTpl())); ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); gBS->RaiseTPL (OldTpl); @@ -318,10 +304,10 @@ UsbConnectDriver ( settings. Only one setting is active. It will also reset its endpoints' toggle to zero. - @param IfDesc The interface descriptor to set - @param Alternate The alternate setting number to locate + @param IfDesc The interface descriptor to set. + @param Alternate The alternate setting number to locate. - @retval EFI_NOT_FOUND There is no setting with this alternate index + @retval EFI_NOT_FOUND There is no setting with this alternate index. @retval EFI_SUCCESS The interface is set to Alternate setting. **/ @@ -340,6 +326,7 @@ UsbSelectSetting ( Setting = NULL; for (Index = 0; Index < IfDesc->NumOfSetting; Index++) { + ASSERT (Index < USB_MAX_INTERFACE_SETTING); Setting = IfDesc->Settings[Index]; if (Setting->Desc.AlternateSetting == Alternate) { @@ -353,6 +340,7 @@ UsbSelectSetting ( IfDesc->ActiveIndex = Index; + ASSERT (Setting != NULL); DEBUG ((EFI_D_INFO, "UsbSelectSetting: setting %d selected for interface %d\n", Alternate, Setting->Desc.InterfaceNumber)); @@ -371,11 +359,11 @@ UsbSelectSetting ( Select a new configuration for the device. Each device may support several configurations. - @param Device The device to select configuration - @param ConfigValue The index of the configuration ( != 0) + @param Device The device to select configuration. + @param ConfigValue The index of the configuration ( != 0). - @retval EFI_NOT_FOUND There is no configuration with the index - @retval EFI_OUT_OF_RESOURCES Failed to allocate resource + @retval EFI_NOT_FOUND There is no configuration with the index. + @retval EFI_OUT_OF_RESOURCES Failed to allocate resource. @retval EFI_SUCCESS The configuration is selected. **/ @@ -435,6 +423,7 @@ UsbSelectConfig ( return EFI_OUT_OF_RESOURCES; } + ASSERT (Index < USB_MAX_INTERFACE); Device->Interfaces[Index] = UsbIf; // @@ -455,22 +444,19 @@ UsbSelectConfig ( } - /** Disconnect the USB interface with its driver. - @param UsbIf The interface to disconnect driver from - - @return None + @param UsbIf The interface to disconnect driver from. **/ -STATIC VOID UsbDisconnectDriver ( IN USB_INTERFACE *UsbIf ) { EFI_TPL OldTpl; + EFI_STATUS Status; // // Release the hub if it's a hub controller, otherwise @@ -488,14 +474,14 @@ UsbDisconnectDriver ( // or disconnect at CALLBACK. // OldTpl = UsbGetCurrentTpl (); - DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d\n", OldTpl)); + DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle)); gBS->RestoreTPL (TPL_CALLBACK); - gBS->DisconnectController (UsbIf->Handle, NULL, NULL); + Status = gBS->DisconnectController (UsbIf->Handle, NULL, NULL); UsbIf->IsManaged = FALSE; - DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d\n", UsbGetCurrentTpl())); + DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status)); ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); gBS->RaiseTPL (OldTpl); @@ -503,13 +489,10 @@ UsbDisconnectDriver ( } - /** - Remove the current device configuration - - @param Device The USB device to remove configuration from + Remove the current device configuration. - @return None + @param Device The USB device to remove configuration from. **/ VOID @@ -523,7 +506,8 @@ UsbRemoveConfig ( // // Remove each interface of the device // - for (Index = 0; Index < Device->NumOfInterface; Index++) { + for (Index = 0; Index < Device->NumOfInterface; Index++) { + ASSERT (Index < USB_MAX_INTERFACE); UsbIf = Device->Interfaces[Index]; if (UsbIf == NULL) { @@ -540,13 +524,12 @@ UsbRemoveConfig ( } - /** Remove the device and all its children from the bus. - @param Device The device to remove + @param Device The device to remove. - @retval EFI_SUCCESS The device is removed + @retval EFI_SUCCESS The device is removed. **/ EFI_STATUS @@ -584,6 +567,7 @@ UsbRemoveDevice ( DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address)); + ASSERT (Device->Address < USB_MAX_DEVICES); Bus->Devices[Device->Address] = NULL; UsbFreeDevice (Device); @@ -592,15 +576,14 @@ UsbRemoveDevice ( /** - Find the child device on the hub's port + Find the child device on the hub's port. - @param HubIf The hub interface - @param Port The port of the hub this child is connected to + @param HubIf The hub interface. + @param Port The port of the hub this child is connected to. - @return The device on the hub's port, or NULL if there is none + @return The device on the hub's port, or NULL if there is none. **/ -STATIC USB_DEVICE * UsbFindChild ( IN USB_INTERFACE *HubIf, @@ -630,19 +613,17 @@ UsbFindChild ( } - /** Enumerate and configure the new device on the port of this HUB interface. - @param HubIf The HUB that has the device connected - @param Port The port index of the hub (started with zero) + @param HubIf The HUB that has the device connected. + @param Port The port index of the hub (started with zero). - @retval EFI_SUCCESS The device is enumerated (added or removed) - @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the device - @retval Others Failed to enumerate the device + @retval EFI_SUCCESS The device is enumerated (added or removed). + @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the device. + @retval Others Failed to enumerate the device. **/ -STATIC EFI_STATUS UsbEnumerateNewDev ( IN USB_INTERFACE *HubIf, @@ -713,13 +694,14 @@ UsbEnumerateNewDev ( if (Child->Speed != EFI_USB_SPEED_HIGH) { // // If the child isn't a high speed device, it is necessary to - // set the transaction translator. This is quite simple: + // set the transaction translator. Port TT is 1-based. + // This is quite simple: // 1. if parent is of high speed, then parent is our translator // 2. otherwise use parent's translator. // if (Parent->Speed == EFI_USB_SPEED_HIGH) { Child->Translator.TranslatorHubAddress = Parent->Address; - Child->Translator.TranslatorPortNumber = Port; + Child->Translator.TranslatorPortNumber = (UINT8) (Port + 1); } else { Child->Translator = Parent->Translator; @@ -732,14 +714,14 @@ UsbEnumerateNewDev ( // // After port is reset, hub establishes a signal path between - // the device and host (DEFALUT state). Device¡¯s registers are + // the device and host (DEFALUT state). Device's registers are // reset, use default address 0 (host enumerates one device at // a time) , and ready to respond to control transfer at EP 0. // // // Host sends a Get_Descriptor request to learn the max packet - // size of default pipe (only part of the device¡¯s descriptor). + // size of default pipe (only part of the device's descriptor). // Status = UsbGetMaxPacketSize0 (Child); @@ -782,7 +764,7 @@ UsbEnumerateNewDev ( DEBUG ((EFI_D_INFO, "UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address)); // - // Host learns about the device¡¯s abilities by requesting device's + // Host learns about the device's abilities by requesting device's // entire descriptions. // Status = UsbBuildDescTable (Child); @@ -831,19 +813,17 @@ ON_ERROR: } - /** Process the events on the port. - @param HubIf The HUB that has the device connected - @param Port The port index of the hub (started with zero) + @param HubIf The HUB that has the device connected. + @param Port The port index of the hub (started with zero). - @retval EFI_SUCCESS The device is enumerated (added or removed) - @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the device - @retval Others Failed to enumerate the device + @retval EFI_SUCCESS The device is enumerated (added or removed). + @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the device. + @retval Others Failed to enumerate the device. **/ -STATIC EFI_STATUS UsbEnumeratePort ( IN USB_INTERFACE *HubIf, @@ -872,8 +852,8 @@ UsbEnumeratePort ( return EFI_SUCCESS; } - DEBUG (( EFI_D_INFO, "UsbEnumeratePort: port %d state - %x, change - %x\n", - Port, PortState.PortStatus, PortState.PortChangeStatus)); + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: port %d state - %x, change - %x on %p\n", + Port, PortState.PortStatus, PortState.PortChangeStatus, HubIf)); // // This driver only process two kinds of events now: over current and @@ -927,7 +907,7 @@ UsbEnumeratePort ( Child = UsbFindChild (HubIf, Port); if (Child != NULL) { - DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from system\n", Port)); + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from root hub %p\n", Port, HubIf)); UsbRemoveDevice (Child); } @@ -948,15 +928,14 @@ UsbEnumeratePort ( /** - Enumerate all the changed hub ports + Enumerate all the changed hub ports. - @param Event The event that is triggered - @param Context The context to the event - - @return None + @param Event The event that is triggered. + @param Context The context to the event. **/ VOID +EFIAPI UsbHubEnumeration ( IN EFI_EVENT Event, IN VOID *Context @@ -967,7 +946,7 @@ UsbHubEnumeration ( UINT8 Bit; UINT8 Index; - ASSERT (Context); + ASSERT (Context != NULL); HubIf = (USB_INTERFACE *) Context; @@ -998,12 +977,10 @@ UsbHubEnumeration ( /** - Enumerate all the changed hub ports - - @param Event The event that is triggered - @param Context The context to the event + Enumerate all the changed hub ports. - @return None + @param Event The event that is triggered. + @param Context The context to the event. **/ VOID