X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FUsb%2FUsbBusDxe%2FUsbEnumer.c;h=6b46e5c3ce4548ef91f249a29b394e9f3d31a015;hp=0b5532ec5656af9f3f37d9c56f4c2012a0c4c898;hb=ecb575d9e65c9d52c17866eebba5f798f178effe;hpb=50fa1b3a86faee57ca597e778c9db4ed4233f83e diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c index 0b5532ec56..6b46e5c3ce 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c @@ -143,7 +143,7 @@ UsbCreateInterface ( UsbIf->DevicePath = AppendDevicePathNode (HubIf->DevicePath, &UsbNode.Header); if (UsbIf->DevicePath == NULL) { - USB_ERROR (("UsbCreateInterface: failed to create device path\n")); + DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to create device path\n")); Status = EFI_OUT_OF_RESOURCES; goto ON_ERROR; @@ -159,7 +159,7 @@ UsbCreateInterface ( ); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbCreateInterface: failed to install UsbIo - %r\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to install UsbIo - %r\n", Status)); goto ON_ERROR; } @@ -178,7 +178,7 @@ UsbCreateInterface ( NULL ); - USB_ERROR (("UsbCreateInterface: failed to open host for child - %r\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to open host for child - %r\n", Status)); goto ON_ERROR; } @@ -277,7 +277,7 @@ UsbConnectDriver ( // connect drivers with this interface // if (UsbIsHubInterface (UsbIf)) { - USB_DEBUG (("UsbConnectDriver: found a hub device\n")); + DEBUG ((EFI_D_INFO, "UsbConnectDriver: found a hub device\n")); Status = mUsbHubApi.Init (UsbIf); } else { @@ -288,18 +288,24 @@ UsbConnectDriver ( // twisted TPL used. It should be no problem for us to connect // or disconnect at CALLBACK. // - OldTpl = UsbGetCurrentTpl (); - USB_DEBUG (("UsbConnectDriver: TPL before connect is %d\n", OldTpl)); + + // + // Only recursively wanted usb child device + // + if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) { + OldTpl = UsbGetCurrentTpl (); + DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", OldTpl)); - gBS->RestoreTPL (TPL_CALLBACK); + gBS->RestoreTPL (TPL_CALLBACK); - Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE); - UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status); + Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE); + UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status); - USB_DEBUG (("UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl())); - ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); + DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl())); + ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); - gBS->RaiseTPL (OldTpl); + gBS->RaiseTPL (OldTpl); + } } return Status; @@ -347,7 +353,7 @@ UsbSelectSetting ( IfDesc->ActiveIndex = Index; - USB_DEBUG (("UsbSelectSetting: setting %d selected for interface %d\n", + DEBUG ((EFI_D_INFO, "UsbSelectSetting: setting %d selected for interface %d\n", Alternate, Setting->Desc.InterfaceNumber)); // @@ -406,7 +412,7 @@ UsbSelectConfig ( Device->ActiveConfig = ConfigDesc; - USB_DEBUG (("UsbSelectConfig: config %d selected for device %d\n", + DEBUG ((EFI_D_INFO, "UsbSelectConfig: config %d selected for device %d\n", ConfigValue, Device->Address)); // @@ -439,7 +445,7 @@ UsbSelectConfig ( Status = UsbConnectDriver (UsbIf); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbSelectConfig: failed to connect driver %r, ignored\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbSelectConfig: failed to connect driver %r, ignored\n", Status)); } } @@ -482,14 +488,14 @@ UsbDisconnectDriver ( // or disconnect at CALLBACK. // OldTpl = UsbGetCurrentTpl (); - USB_DEBUG (("UsbDisconnectDriver: old TPL is %d\n", OldTpl)); + DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d\n", OldTpl)); gBS->RestoreTPL (TPL_CALLBACK); gBS->DisconnectController (UsbIf->Handle, NULL, NULL); UsbIf->IsManaged = FALSE; - USB_DEBUG (("UsbDisconnectDriver: TPL after disconnect is %d\n", UsbGetCurrentTpl())); + DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d\n", UsbGetCurrentTpl())); ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK); gBS->RaiseTPL (OldTpl); @@ -569,14 +575,14 @@ UsbRemoveDevice ( Status = UsbRemoveDevice (Child); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbRemoveDevice: failed to remove child, ignore error\n")); + DEBUG ((EFI_D_ERROR, "UsbRemoveDevice: failed to remove child, ignore error\n")); Bus->Devices[Index] = NULL; } } UsbRemoveConfig (Device); - USB_DEBUG (("UsbRemoveDevice: device %d removed\n", Device->Address)); + DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address)); Bus->Devices[Device->Address] = NULL; UsbFreeDevice (Device); @@ -656,13 +662,9 @@ UsbEnumerateNewDev ( Parent = HubIf->Device; Bus = Parent->Bus; HubApi = HubIf->HubApi; - - - // - // Wait at least 100 ms for the power on port to stable - // - gBS->Stall (100 * USB_STALL_1_MS); - + + gBS->Stall (USB_WAIT_PORT_STABLE_STALL); + // // Hub resets the device for at least 10 milliseconds. // Host learns device speed. If device is of low/full speed @@ -672,12 +674,12 @@ UsbEnumerateNewDev ( Status = HubApi->ResetPort (HubIf, Port); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to reset port %d - %r\n", Port, Status)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - %r\n", Port, Status)); return Status; } - USB_DEBUG (("UsbEnumerateNewDev: hub port %d is reset\n", Port)); + DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port)); Child = UsbCreateDevice (HubIf, Port); @@ -692,7 +694,7 @@ UsbEnumerateNewDev ( Status = HubApi->GetPortStatus (HubIf, Port, &PortState); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to get speed of port %d\n", Port)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get speed of port %d\n", Port)); goto ON_ERROR; } @@ -706,7 +708,7 @@ UsbEnumerateNewDev ( Child->Speed = EFI_USB_SPEED_FULL; } - USB_DEBUG (("UsbEnumerateNewDev: device is of %d speed\n", Child->Speed)); + DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device is of %d speed\n", Child->Speed)); if (Child->Speed != EFI_USB_SPEED_HIGH) { // @@ -723,7 +725,7 @@ UsbEnumerateNewDev ( Child->Translator = Parent->Translator; } - USB_DEBUG (("UsbEnumerateNewDev: device uses translator (%d, %d)\n", + DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device uses translator (%d, %d)\n", Child->Translator.TranslatorHubAddress, Child->Translator.TranslatorPortNumber)); } @@ -742,11 +744,11 @@ UsbEnumerateNewDev ( Status = UsbGetMaxPacketSize0 (Child); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status)); goto ON_ERROR; } - USB_DEBUG (("UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0)); + DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0)); // // Host assigns an address to the device. Device completes the @@ -760,7 +762,7 @@ UsbEnumerateNewDev ( } if (Address == USB_MAX_DEVICES) { - USB_ERROR (("UsbEnumerateNewDev: address pool is full for port %d\n", Port)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port)); Status = EFI_ACCESS_DENIED; goto ON_ERROR; @@ -771,16 +773,13 @@ UsbEnumerateNewDev ( Child->Address = Address; if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to set device address - %r\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to set device address - %r\n", Status)); goto ON_ERROR; } + + gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL); - // - // Wait 20ms for set address to complete - // - gBS->Stall (20 * USB_STALL_1_MS); - - USB_DEBUG (("UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address)); + DEBUG ((EFI_D_INFO, "UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address)); // // Host learns about the device¡¯s abilities by requesting device's @@ -789,7 +788,7 @@ UsbEnumerateNewDev ( Status = UsbBuildDescTable (Child); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to build descriptor table - %r\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to build descriptor table - %r\n", Status)); goto ON_ERROR; } @@ -801,11 +800,11 @@ UsbEnumerateNewDev ( Status = UsbSetConfig (Child, Config); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to set configure %d - %r\n", Config, Status)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to set configure %d - %r\n", Config, Status)); goto ON_ERROR; } - USB_DEBUG (("UsbEnumerateNewDev: device %d is now in CONFIGED state\n", Address)); + DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device %d is now in CONFIGED state\n", Address)); // // Host assigns and loads a device driver. @@ -813,7 +812,7 @@ UsbEnumerateNewDev ( Status = UsbSelectConfig (Child, Config); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumerateNewDev: failed to create interfaces - %r\n", Status)); + DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to create interfaces - %r\n", Status)); goto ON_ERROR; } @@ -865,7 +864,7 @@ UsbEnumeratePort ( Status = HubApi->GetPortStatus (HubIf, Port, &PortState); if (EFI_ERROR (Status)) { - USB_ERROR (("UsbEnumeratePort: failed to get state of port %d\n", Port)); + DEBUG ((EFI_D_ERROR, "UsbEnumeratePort: failed to get state of port %d\n", Port)); return Status; } @@ -873,7 +872,7 @@ UsbEnumeratePort ( return EFI_SUCCESS; } - USB_DEBUG (("UsbEnumeratePort: port %d state - %x, change - %x\n", + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: port %d state - %x, change - %x\n", Port, PortState.PortStatus, PortState.PortChangeStatus)); // @@ -886,52 +885,49 @@ UsbEnumeratePort ( if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_OVERCURRENT)) { // - // Both OverCurrent and OverCurrentChange set, means over current occurs, - // which probably is caused by short circuit. It has to wait system hardware - // to perform recovery. + // Case1: + // Both OverCurrent and OverCurrentChange set, means over current occurs, + // which probably is caused by short circuit. It has to wait system hardware + // to perform recovery. // - USB_DEBUG (("UsbEnumeratePort: Critical Over Current\n", Port)); + DEBUG (( EFI_D_ERROR, "UsbEnumeratePort: Critical Over Current\n", Port)); return EFI_DEVICE_ERROR; - } else { - // - // Only OverCurrentChange set, means system has been recoveried from - // over current. As a result, all ports are nearly power-off, so - // it's necessary to detach and enumerate all ports again. - // - USB_DEBUG (("UsbEnumeratePort: 2.0 device Recovery Over Current\n", Port)); - goto ON_ENUMERATE; - - } + } + // + // Case2: + // Only OverCurrentChange set, means system has been recoveried from + // over current. As a result, all ports are nearly power-off, so + // it's necessary to detach and enumerate all ports again. + // + DEBUG (( EFI_D_ERROR, "UsbEnumeratePort: 2.0 device Recovery Over Current\n", Port)); } if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_ENABLE)) { // - // 1.1 roothub port reg doesn't reflect over-current state, while its counterpart - // on 2.0 roothub does. When over-current has influence on 1.1 device, the port - // would be disabled, so it's also necessary to detach and enumerate again. + // Case3: + // 1.1 roothub port reg doesn't reflect over-current state, while its counterpart + // on 2.0 roothub does. When over-current has influence on 1.1 device, the port + // would be disabled, so it's also necessary to detach and enumerate again. // - USB_DEBUG (("UsbEnumeratePort: 1.1 device Recovery Over Current\n", Port)); - goto ON_ENUMERATE; + DEBUG (( EFI_D_ERROR, "UsbEnumeratePort: 1.1 device Recovery Over Current\n", Port)); } if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_CONNECTION)) { // - // Device connected or disconnected normally. + // Case4: + // Device connected or disconnected normally. // - goto ON_ENUMERATE; + DEBUG ((EFI_D_ERROR, "UsbEnumeratePort: Device Connect/Discount Normally\n", Port)); } -ON_ENUMERATE: - // - // In case there is already a device on this port logically, it's safety to remove - // and enumerate again. + // Following as the above cases, it's safety to remove and create again. // Child = UsbFindChild (HubIf, Port); if (Child != NULL) { - USB_DEBUG (("UsbEnumeratePort: device at port %d removed from system\n", Port)); + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from system\n", Port)); UsbRemoveDevice (Child); } @@ -939,11 +935,11 @@ ON_ENUMERATE: // // Now, new device connected, enumerate and configure the device // - USB_DEBUG (("UsbEnumeratePort: new device connected at port %d\n", Port)); + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: new device connected at port %d\n", Port)); Status = UsbEnumerateNewDev (HubIf, Port); } else { - USB_DEBUG (("UsbEnumeratePort: device disconnected event on port %d\n", Port)); + DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device disconnected event on port %d\n", Port)); } HubApi->ClearPortChange (HubIf, Port); @@ -1011,6 +1007,7 @@ UsbHubEnumeration ( **/ VOID +EFIAPI UsbRootHubEnumeration ( IN EFI_EVENT Event, IN VOID *Context