2007-07-11 10:47:37 +02:00
|
|
|
/** @file
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
Usb bus enumeration support.
|
|
|
|
|
2012-03-07 09:39:35 +01:00
|
|
|
Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-11 10:47:37 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "UsbBus.h"
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Return the endpoint descriptor in this interface.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param UsbIf The interface to search in.
|
|
|
|
@param EpAddr The address of the endpoint to return.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@return The endpoint descriptor or NULL.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
USB_ENDPOINT_DESC *
|
|
|
|
UsbGetEndpointDesc (
|
|
|
|
IN USB_INTERFACE *UsbIf,
|
|
|
|
IN UINT8 EpAddr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_ENDPOINT_DESC *EpDesc;
|
2008-12-26 09:42:24 +01:00
|
|
|
UINT8 Index;
|
|
|
|
UINT8 NumEndpoints;
|
|
|
|
|
|
|
|
NumEndpoints = UsbIf->IfSetting->Desc.NumEndpoints;
|
|
|
|
|
|
|
|
for (Index = 0; Index < NumEndpoints; Index++) {
|
2007-07-11 10:47:37 +02:00
|
|
|
EpDesc = UsbIf->IfSetting->Endpoints[Index];
|
|
|
|
|
|
|
|
if (EpDesc->Desc.EndpointAddress == EpAddr) {
|
|
|
|
return EpDesc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Free the resource used by USB interface.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param UsbIf The USB interface to free.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UsbFreeInterface (
|
|
|
|
IN USB_INTERFACE *UsbIf
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UsbCloseHostProtoByChild (UsbIf->Device->Bus, UsbIf->Handle);
|
|
|
|
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
UsbIf->Handle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
UsbIf->DevicePath,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
&UsbIf->UsbIo,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (UsbIf->DevicePath != NULL) {
|
2008-12-26 09:42:24 +01:00
|
|
|
FreePool (UsbIf->DevicePath);
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
2008-12-26 09:42:24 +01:00
|
|
|
FreePool (UsbIf);
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create an interface for the descriptor IfDesc. Each
|
|
|
|
device's configuration can have several interfaces.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Device The device has the interface descriptor.
|
|
|
|
@param IfDesc The interface descriptor.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
@return The created USB interface for the descriptor, or NULL.
|
|
|
|
|
|
|
|
**/
|
|
|
|
USB_INTERFACE *
|
|
|
|
UsbCreateInterface (
|
|
|
|
IN USB_DEVICE *Device,
|
|
|
|
IN USB_INTERFACE_DESC *IfDesc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_DEVICE_PATH UsbNode;
|
|
|
|
USB_INTERFACE *UsbIf;
|
|
|
|
USB_INTERFACE *HubIf;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
UsbIf = AllocateZeroPool (sizeof (USB_INTERFACE));
|
|
|
|
|
|
|
|
if (UsbIf == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbIf->Signature = USB_INTERFACE_SIGNATURE;
|
|
|
|
UsbIf->Device = Device;
|
|
|
|
UsbIf->IfDesc = IfDesc;
|
2009-02-12 07:23:15 +01:00
|
|
|
ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING);
|
2007-07-11 10:47:37 +02:00
|
|
|
UsbIf->IfSetting = IfDesc->Settings[IfDesc->ActiveIndex];
|
2007-07-12 04:14:05 +02:00
|
|
|
|
|
|
|
CopyMem (
|
|
|
|
&(UsbIf->UsbIo),
|
|
|
|
&mUsbIoProtocol,
|
|
|
|
sizeof (EFI_USB_IO_PROTOCOL)
|
|
|
|
);
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Install protocols for USBIO and device path
|
|
|
|
//
|
|
|
|
UsbNode.Header.Type = MESSAGING_DEVICE_PATH;
|
|
|
|
UsbNode.Header.SubType = MSG_USB_DP;
|
|
|
|
UsbNode.ParentPortNumber = Device->ParentPort;
|
|
|
|
UsbNode.InterfaceNumber = UsbIf->IfSetting->Desc.InterfaceNumber;
|
|
|
|
|
|
|
|
SetDevicePathNodeLength (&UsbNode.Header, sizeof (UsbNode));
|
|
|
|
|
|
|
|
HubIf = Device->ParentIf;
|
|
|
|
ASSERT (HubIf != NULL);
|
|
|
|
|
|
|
|
UsbIf->DevicePath = AppendDevicePathNode (HubIf->DevicePath, &UsbNode.Header);
|
|
|
|
|
|
|
|
if (UsbIf->DevicePath == NULL) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to create device path\n"));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&UsbIf->Handle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
UsbIf->DevicePath,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
&UsbIf->UsbIo,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to install UsbIo - %r\n", Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Open USB Host Controller Protocol by Child
|
|
|
|
//
|
|
|
|
Status = UsbOpenHostProtoByChild (Device->Bus, UsbIf->Handle);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
&UsbIf->Handle,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
UsbIf->DevicePath,
|
|
|
|
&gEfiUsbIoProtocolGuid,
|
|
|
|
&UsbIf->UsbIo,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbCreateInterface: failed to open host for child - %r\n", Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UsbIf;
|
|
|
|
|
|
|
|
ON_ERROR:
|
2008-07-09 12:02:26 +02:00
|
|
|
if (UsbIf->DevicePath != NULL) {
|
2008-12-26 09:42:24 +01:00
|
|
|
FreePool (UsbIf->DevicePath);
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
2008-12-26 09:42:24 +01:00
|
|
|
FreePool (UsbIf);
|
2007-07-11 10:47:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Free the resource used by this USB device.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Device The USB device to free.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UsbFreeDevice (
|
|
|
|
IN USB_DEVICE *Device
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Device->DevDesc != NULL) {
|
|
|
|
UsbFreeDevDesc (Device->DevDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->FreePool (Device);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create a device which is on the parent's ParentPort port.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param ParentIf The parent HUB interface.
|
|
|
|
@param ParentPort The port on the HUB this device is connected to.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@return Created USB device, Or NULL.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
USB_DEVICE *
|
|
|
|
UsbCreateDevice (
|
|
|
|
IN USB_INTERFACE *ParentIf,
|
|
|
|
IN UINT8 ParentPort
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_DEVICE *Device;
|
|
|
|
|
|
|
|
ASSERT (ParentIf != NULL);
|
|
|
|
|
|
|
|
Device = AllocateZeroPool (sizeof (USB_DEVICE));
|
|
|
|
|
|
|
|
if (Device == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Device->Bus = ParentIf->Device->Bus;
|
|
|
|
Device->MaxPacket0 = 8;
|
|
|
|
Device->ParentAddr = ParentIf->Device->Address;
|
|
|
|
Device->ParentIf = ParentIf;
|
|
|
|
Device->ParentPort = ParentPort;
|
2011-08-25 12:19:11 +02:00
|
|
|
Device->Tier = (UINT8)(ParentIf->Device->Tier + 1);
|
2007-07-11 10:47:37 +02:00
|
|
|
return Device;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Connect the USB interface with its driver. EFI USB bus will
|
2008-12-26 09:42:24 +01:00
|
|
|
create a USB interface for each separate interface descriptor.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param UsbIf The interface to connect driver to.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@return EFI_SUCCESS Interface is managed by some driver.
|
|
|
|
@return Others Failed to locate a driver for this interface.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UsbConnectDriver (
|
|
|
|
IN USB_INTERFACE *UsbIf
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Hub is maintained by the USB bus driver. Otherwise try to
|
|
|
|
// connect drivers with this interface
|
|
|
|
//
|
|
|
|
if (UsbIsHubInterface (UsbIf)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbConnectDriver: found a hub device\n"));
|
2007-07-11 10:47:37 +02:00
|
|
|
Status = mUsbHubApi.Init (UsbIf);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// This function is called in both UsbIoControlTransfer and
|
|
|
|
// the timer callback in hub enumeration. So, at least it is
|
|
|
|
// called at TPL_CALLBACK. Some driver sitting on USB has
|
|
|
|
// twisted TPL used. It should be no problem for us to connect
|
|
|
|
// or disconnect at CALLBACK.
|
|
|
|
//
|
2007-12-26 07:38:15 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Only recursively wanted usb child device
|
|
|
|
//
|
|
|
|
if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) {
|
|
|
|
OldTpl = UsbGetCurrentTpl ();
|
2009-02-12 07:23:15 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-12-26 07:38:15 +01:00
|
|
|
gBS->RestoreTPL (TPL_CALLBACK);
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-12-26 07:38:15 +01:00
|
|
|
Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE);
|
|
|
|
UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status);
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-12-18 09:48:36 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", (UINT32)UsbGetCurrentTpl()));
|
2007-12-26 07:38:15 +01:00
|
|
|
ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK);
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-12-26 07:38:15 +01:00
|
|
|
gBS->RaiseTPL (OldTpl);
|
|
|
|
}
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Select an alternate setting for the interface.
|
|
|
|
Each interface can have several mutually exclusive
|
|
|
|
settings. Only one setting is active. It will
|
|
|
|
also reset its endpoints' toggle to zero.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param IfDesc The interface descriptor to set.
|
|
|
|
@param Alternate The alternate setting number to locate.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@retval EFI_NOT_FOUND There is no setting with this alternate index.
|
2007-07-11 10:47:37 +02:00
|
|
|
@retval EFI_SUCCESS The interface is set to Alternate setting.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UsbSelectSetting (
|
|
|
|
IN USB_INTERFACE_DESC *IfDesc,
|
|
|
|
IN UINT8 Alternate
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_INTERFACE_SETTING *Setting;
|
|
|
|
UINT8 Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate the active alternate setting
|
|
|
|
//
|
|
|
|
Setting = NULL;
|
|
|
|
|
|
|
|
for (Index = 0; Index < IfDesc->NumOfSetting; Index++) {
|
2009-02-12 07:23:15 +01:00
|
|
|
ASSERT (Index < USB_MAX_INTERFACE_SETTING);
|
2007-07-11 10:47:37 +02:00
|
|
|
Setting = IfDesc->Settings[Index];
|
|
|
|
|
|
|
|
if (Setting->Desc.AlternateSetting == Alternate) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Index == IfDesc->NumOfSetting) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
IfDesc->ActiveIndex = Index;
|
|
|
|
|
2009-02-12 09:41:34 +01:00
|
|
|
ASSERT (Setting != NULL);
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbSelectSetting: setting %d selected for interface %d\n",
|
2007-07-11 10:47:37 +02:00
|
|
|
Alternate, Setting->Desc.InterfaceNumber));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Reset the endpoint toggle to zero
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < Setting->Desc.NumEndpoints; Index++) {
|
|
|
|
Setting->Endpoints[Index]->Toggle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Select a new configuration for the device. Each
|
|
|
|
device may support several configurations.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Device The device to select configuration.
|
|
|
|
@param ConfigValue The index of the configuration ( != 0).
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@retval EFI_NOT_FOUND There is no configuration with the index.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
|
2007-07-11 10:47:37 +02:00
|
|
|
@retval EFI_SUCCESS The configuration is selected.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UsbSelectConfig (
|
|
|
|
IN USB_DEVICE *Device,
|
|
|
|
IN UINT8 ConfigValue
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_DEVICE_DESC *DevDesc;
|
|
|
|
USB_CONFIG_DESC *ConfigDesc;
|
|
|
|
USB_INTERFACE_DESC *IfDesc;
|
|
|
|
USB_INTERFACE *UsbIf;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT8 Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Locate the active config, then set the device's pointer
|
|
|
|
//
|
|
|
|
DevDesc = Device->DevDesc;
|
|
|
|
ConfigDesc = NULL;
|
|
|
|
|
|
|
|
for (Index = 0; Index < DevDesc->Desc.NumConfigurations; Index++) {
|
|
|
|
ConfigDesc = DevDesc->Configs[Index];
|
|
|
|
|
|
|
|
if (ConfigDesc->Desc.ConfigurationValue == ConfigValue) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Index == DevDesc->Desc.NumConfigurations) {
|
|
|
|
return EFI_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
Device->ActiveConfig = ConfigDesc;
|
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbSelectConfig: config %d selected for device %d\n",
|
2007-07-11 10:47:37 +02:00
|
|
|
ConfigValue, Device->Address));
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create interfaces for each USB interface descriptor.
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < ConfigDesc->Desc.NumInterfaces; Index++) {
|
|
|
|
//
|
|
|
|
// First select the default interface setting, and reset
|
|
|
|
// the endpoint toggles to zero for its endpoints.
|
|
|
|
//
|
|
|
|
IfDesc = ConfigDesc->Interfaces[Index];
|
|
|
|
UsbSelectSetting (IfDesc, IfDesc->Settings[0]->Desc.AlternateSetting);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a USB_INTERFACE and install USB_IO and other protocols
|
|
|
|
//
|
|
|
|
UsbIf = UsbCreateInterface (Device, ConfigDesc->Interfaces[Index]);
|
|
|
|
|
|
|
|
if (UsbIf == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2009-02-12 07:23:15 +01:00
|
|
|
ASSERT (Index < USB_MAX_INTERFACE);
|
2007-07-11 10:47:37 +02:00
|
|
|
Device->Interfaces[Index] = UsbIf;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Connect the device to drivers, if it failed, ignore
|
|
|
|
// the error. Don't let the unsupported interfaces to block
|
|
|
|
// the supported interfaces.
|
|
|
|
//
|
|
|
|
Status = UsbConnectDriver (UsbIf);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbSelectConfig: failed to connect driver %r, ignored\n", Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Device->NumOfInterface = Index;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Disconnect the USB interface with its driver.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param UsbIf The interface to disconnect driver from.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UsbDisconnectDriver (
|
|
|
|
IN USB_INTERFACE *UsbIf
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_TPL OldTpl;
|
2009-02-12 07:23:15 +01:00
|
|
|
EFI_STATUS Status;
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Release the hub if it's a hub controller, otherwise
|
|
|
|
// disconnect the driver if it is managed by other drivers.
|
|
|
|
//
|
|
|
|
if (UsbIf->IsHub) {
|
|
|
|
UsbIf->HubApi->Release (UsbIf);
|
|
|
|
|
|
|
|
} else if (UsbIf->IsManaged) {
|
|
|
|
//
|
|
|
|
// This function is called in both UsbIoControlTransfer and
|
|
|
|
// the timer callback in hub enumeration. So, at least it is
|
|
|
|
// called at TPL_CALLBACK. Some driver sitting on USB has
|
|
|
|
// twisted TPL used. It should be no problem for us to connect
|
|
|
|
// or disconnect at CALLBACK.
|
|
|
|
//
|
|
|
|
OldTpl = UsbGetCurrentTpl ();
|
2009-02-12 07:23:15 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
gBS->RestoreTPL (TPL_CALLBACK);
|
|
|
|
|
2009-02-12 07:23:15 +01:00
|
|
|
Status = gBS->DisconnectController (UsbIf->Handle, NULL, NULL);
|
2007-07-11 10:47:37 +02:00
|
|
|
UsbIf->IsManaged = FALSE;
|
|
|
|
|
2009-02-12 07:23:15 +01:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK);
|
|
|
|
|
|
|
|
gBS->RaiseTPL (OldTpl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Remove the current device configuration.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Device The USB device to remove configuration from.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UsbRemoveConfig (
|
|
|
|
IN USB_DEVICE *Device
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_INTERFACE *UsbIf;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Remove each interface of the device
|
|
|
|
//
|
2009-02-12 07:23:15 +01:00
|
|
|
for (Index = 0; Index < Device->NumOfInterface; Index++) {
|
|
|
|
ASSERT (Index < USB_MAX_INTERFACE);
|
2007-07-11 10:47:37 +02:00
|
|
|
UsbIf = Device->Interfaces[Index];
|
|
|
|
|
|
|
|
if (UsbIf == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbDisconnectDriver (UsbIf);
|
|
|
|
UsbFreeInterface (UsbIf);
|
|
|
|
Device->Interfaces[Index] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Device->ActiveConfig = NULL;
|
|
|
|
Device->NumOfInterface = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Remove the device and all its children from the bus.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Device The device to remove.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@retval EFI_SUCCESS The device is removed.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UsbRemoveDevice (
|
|
|
|
IN USB_DEVICE *Device
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_BUS *Bus;
|
|
|
|
USB_DEVICE *Child;
|
|
|
|
EFI_STATUS Status;
|
2011-08-23 16:36:33 +02:00
|
|
|
UINTN Index;
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
Bus = Device->Bus;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Remove all the devices on its downstream ports. Search from devices[1].
|
|
|
|
// Devices[0] is the root hub.
|
|
|
|
//
|
2011-09-14 14:13:03 +02:00
|
|
|
for (Index = 1; Index < Bus->MaxDevices; Index++) {
|
2007-07-11 10:47:37 +02:00
|
|
|
Child = Bus->Devices[Index];
|
|
|
|
|
|
|
|
if ((Child == NULL) || (Child->ParentAddr != Device->Address)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = UsbRemoveDevice (Child);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbRemoveDevice: failed to remove child, ignore error\n"));
|
2007-07-11 10:47:37 +02:00
|
|
|
Bus->Devices[Index] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbRemoveConfig (Device);
|
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
ASSERT (Device->Address < Bus->MaxDevices);
|
2007-07-11 10:47:37 +02:00
|
|
|
Bus->Devices[Device->Address] = NULL;
|
|
|
|
UsbFreeDevice (Device);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Find the child device on the hub's port.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param HubIf The hub interface.
|
|
|
|
@param Port The port of the hub this child is connected to.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@return The device on the hub's port, or NULL if there is none.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
USB_DEVICE *
|
|
|
|
UsbFindChild (
|
|
|
|
IN USB_INTERFACE *HubIf,
|
|
|
|
IN UINT8 Port
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_DEVICE *Device;
|
|
|
|
USB_BUS *Bus;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
Bus = HubIf->Device->Bus;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Start checking from device 1, device 0 is the root hub
|
|
|
|
//
|
2011-09-14 14:13:03 +02:00
|
|
|
for (Index = 1; Index < Bus->MaxDevices; Index++) {
|
2007-07-11 10:47:37 +02:00
|
|
|
Device = Bus->Devices[Index];
|
|
|
|
|
|
|
|
if ((Device != NULL) && (Device->ParentAddr == HubIf->Device->Address) &&
|
|
|
|
(Device->ParentPort == Port)) {
|
|
|
|
|
|
|
|
return Device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Enumerate and configure the new device on the port of this HUB interface.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param HubIf The HUB that has the device connected.
|
|
|
|
@param Port The port index of the hub (started with zero).
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@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.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UsbEnumerateNewDev (
|
|
|
|
IN USB_INTERFACE *HubIf,
|
|
|
|
IN UINT8 Port
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_BUS *Bus;
|
|
|
|
USB_HUB_API *HubApi;
|
|
|
|
USB_DEVICE *Child;
|
|
|
|
USB_DEVICE *Parent;
|
|
|
|
EFI_USB_PORT_STATUS PortState;
|
2011-08-23 16:36:33 +02:00
|
|
|
UINTN Address;
|
2007-07-11 10:47:37 +02:00
|
|
|
UINT8 Config;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Parent = HubIf->Device;
|
|
|
|
Bus = Parent->Bus;
|
2011-09-14 14:13:03 +02:00
|
|
|
HubApi = HubIf->HubApi;
|
|
|
|
Address = Bus->MaxDevices;
|
|
|
|
|
2007-10-08 08:14:13 +02:00
|
|
|
gBS->Stall (USB_WAIT_PORT_STABLE_STALL);
|
|
|
|
|
2007-07-11 10:47:37 +02:00
|
|
|
//
|
|
|
|
// Hub resets the device for at least 10 milliseconds.
|
|
|
|
// Host learns device speed. If device is of low/full speed
|
|
|
|
// and the hub is a EHCI root hub, ResetPort will release
|
|
|
|
// the device to its companion UHCI and return an error.
|
|
|
|
//
|
|
|
|
Status = HubApi->ResetPort (HubIf, Port);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to reset port %d - %r\n", Port, Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: hub port %d is reset\n", Port));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
Child = UsbCreateDevice (HubIf, Port);
|
|
|
|
|
|
|
|
if (Child == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// OK, now identify the device speed. After reset, hub
|
|
|
|
// fully knows the actual device speed.
|
|
|
|
//
|
|
|
|
Status = HubApi->GetPortStatus (HubIf, Port, &PortState);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get speed of port %d\n", Port));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
if (!USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_CONNECTION)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: No device presented at port %d\n", Port));
|
|
|
|
goto ON_ERROR;
|
|
|
|
} else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_SUPER_SPEED)){
|
|
|
|
Child->Speed = EFI_USB_SPEED_SUPER;
|
|
|
|
Child->MaxPacket0 = 512;
|
2007-07-11 10:47:37 +02:00
|
|
|
} else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_HIGH_SPEED)) {
|
2011-08-23 16:36:33 +02:00
|
|
|
Child->Speed = EFI_USB_SPEED_HIGH;
|
|
|
|
Child->MaxPacket0 = 64;
|
|
|
|
} else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_LOW_SPEED)) {
|
|
|
|
Child->Speed = EFI_USB_SPEED_LOW;
|
|
|
|
Child->MaxPacket0 = 8;
|
2007-07-11 10:47:37 +02:00
|
|
|
} else {
|
2011-08-23 16:36:33 +02:00
|
|
|
Child->Speed = EFI_USB_SPEED_FULL;
|
|
|
|
Child->MaxPacket0 = 8;
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device is of %d speed\n", Child->Speed));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2012-03-07 09:39:35 +01:00
|
|
|
if (((Child->Speed == EFI_USB_SPEED_LOW) || (Child->Speed == EFI_USB_SPEED_FULL)) &&
|
|
|
|
(Parent->Speed == EFI_USB_SPEED_HIGH)) {
|
2007-07-11 10:47:37 +02:00
|
|
|
//
|
2012-03-07 09:39:35 +01:00
|
|
|
// If the child is a low or full speed device, it is necessary to
|
2008-06-25 07:50:41 +02:00
|
|
|
// set the transaction translator. Port TT is 1-based.
|
|
|
|
// This is quite simple:
|
2007-07-11 10:47:37 +02:00
|
|
|
// 1. if parent is of high speed, then parent is our translator
|
|
|
|
// 2. otherwise use parent's translator.
|
|
|
|
//
|
2012-03-07 09:39:35 +01:00
|
|
|
Child->Translator.TranslatorHubAddress = Parent->Address;
|
|
|
|
Child->Translator.TranslatorPortNumber = (UINT8) (Port + 1);
|
|
|
|
} else {
|
|
|
|
Child->Translator = Parent->Translator;
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
2012-03-07 09:39:35 +01:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device uses translator (%d, %d)\n",
|
|
|
|
Child->Translator.TranslatorHubAddress,
|
|
|
|
Child->Translator.TranslatorPortNumber));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// After port is reset, hub establishes a signal path between
|
2008-05-27 05:24:01 +02:00
|
|
|
// the device and host (DEFALUT state). Device's registers are
|
2007-07-11 10:47:37 +02:00
|
|
|
// reset, use default address 0 (host enumerates one device at
|
|
|
|
// a time) , and ready to respond to control transfer at EP 0.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host assigns an address to the device. Device completes the
|
|
|
|
// status stage with default address, then switches to new address.
|
|
|
|
// ADDRESS state. Address zero is reserved for root hub.
|
|
|
|
//
|
2011-09-14 14:13:03 +02:00
|
|
|
ASSERT (Bus->MaxDevices <= 256);
|
|
|
|
for (Address = 1; Address < Bus->MaxDevices; Address++) {
|
2007-07-11 10:47:37 +02:00
|
|
|
if (Bus->Devices[Address] == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
if (Address >= Bus->MaxDevices) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
Status = EFI_ACCESS_DENIED;
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
Status = UsbSetAddress (Child, (UINT8)Address);
|
|
|
|
Child->Address = (UINT8)Address;
|
2007-07-11 10:47:37 +02:00
|
|
|
Bus->Devices[Address] = Child;
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to set device address - %r\n", Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
2011-08-23 16:36:33 +02:00
|
|
|
|
2007-10-08 08:14:13 +02:00
|
|
|
gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
//
|
|
|
|
// Host sends a Get_Descriptor request to learn the max packet
|
|
|
|
// size of default pipe (only part of the device's descriptor).
|
|
|
|
//
|
|
|
|
Status = UsbGetMaxPacketSize0 (Child);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status));
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0));
|
|
|
|
|
2007-07-11 10:47:37 +02:00
|
|
|
//
|
2008-05-27 05:24:01 +02:00
|
|
|
// Host learns about the device's abilities by requesting device's
|
2007-07-11 10:47:37 +02:00
|
|
|
// entire descriptions.
|
|
|
|
//
|
|
|
|
Status = UsbBuildDescTable (Child);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to build descriptor table - %r\n", Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Select a default configuration: UEFI must set the configuration
|
|
|
|
// before the driver can connect to the device.
|
|
|
|
//
|
|
|
|
Config = Child->DevDesc->Configs[0]->Desc.ConfigurationValue;
|
|
|
|
Status = UsbSetConfig (Child, Config);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to set configure %d - %r\n", Config, Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device %d is now in CONFIGED state\n", Address));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Host assigns and loads a device driver.
|
|
|
|
//
|
|
|
|
Status = UsbSelectConfig (Child, Config);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to create interfaces - %r\n", Status));
|
2007-07-11 10:47:37 +02:00
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
ON_ERROR:
|
2011-09-14 14:13:03 +02:00
|
|
|
if (Address != Bus->MaxDevices) {
|
2007-07-11 10:47:37 +02:00
|
|
|
Bus->Devices[Address] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Child != NULL) {
|
|
|
|
UsbFreeDevice (Child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Process the events on the port.
|
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param HubIf The HUB that has the device connected.
|
|
|
|
@param Port The port index of the hub (started with zero).
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@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.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UsbEnumeratePort (
|
|
|
|
IN USB_INTERFACE *HubIf,
|
|
|
|
IN UINT8 Port
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HUB_API *HubApi;
|
|
|
|
USB_DEVICE *Child;
|
|
|
|
EFI_USB_PORT_STATUS PortState;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Child = NULL;
|
|
|
|
HubApi = HubIf->HubApi;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Host learns of the new device by polling the hub for port changes.
|
|
|
|
//
|
|
|
|
Status = HubApi->GetPortStatus (HubIf, Port, &PortState);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumeratePort: failed to get state of port %d\n", Port));
|
2007-07-11 10:47:37 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
//
|
|
|
|
// Only handle connection/enable/overcurrent/reset change.
|
|
|
|
// Usb super speed hub may report other changes, such as warm reset change. Ignore them.
|
|
|
|
//
|
|
|
|
if ((PortState.PortChangeStatus & (USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | USB_PORT_STAT_C_OVERCURRENT | USB_PORT_STAT_C_RESET)) == 0) {
|
2007-07-11 10:47:37 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumeratePort: port %d state - %02x, change - %02x on %p\n",
|
|
|
|
Port, PortState.PortChangeStatus, PortState.PortStatus, HubIf));
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// This driver only process two kinds of events now: over current and
|
|
|
|
// connect/disconnect. Other three events are: ENABLE, SUSPEND, RESET.
|
|
|
|
// ENABLE/RESET is used to reset port. SUSPEND isn't supported.
|
|
|
|
//
|
2007-07-24 11:54:50 +02:00
|
|
|
|
|
|
|
if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_OVERCURRENT)) {
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-07-24 11:54:50 +02:00
|
|
|
if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_OVERCURRENT)) {
|
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
// 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.
|
2007-07-24 11:54:50 +02:00
|
|
|
//
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_ERROR, "UsbEnumeratePort: Critical Over Current\n", Port));
|
2007-07-24 11:54:50 +02:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
|
2007-10-08 08:14:13 +02:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// 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));
|
2007-07-24 11:54:50 +02:00
|
|
|
}
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-07-24 11:54:50 +02:00
|
|
|
if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_ENABLE)) {
|
2007-07-11 10:47:37 +02:00
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
// 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.
|
2007-07-11 10:47:37 +02:00
|
|
|
//
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_ERROR, "UsbEnumeratePort: 1.1 device Recovery Over Current\n", Port));
|
2007-07-24 11:54:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (USB_BIT_IS_SET (PortState.PortChangeStatus, USB_PORT_STAT_C_CONNECTION)) {
|
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
// Case4:
|
|
|
|
// Device connected or disconnected normally.
|
2007-07-24 11:54:50 +02:00
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UsbEnumeratePort: Device Connect/Discount Normally\n", Port));
|
2007-07-24 11:54:50 +02:00
|
|
|
}
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2007-07-24 11:54:50 +02:00
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
// Following as the above cases, it's safety to remove and create again.
|
2007-07-24 11:54:50 +02:00
|
|
|
//
|
|
|
|
Child = UsbFindChild (HubIf, Port);
|
|
|
|
|
|
|
|
if (Child != NULL) {
|
2009-02-12 07:23:15 +01:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from root hub %p\n", Port, HubIf));
|
2007-07-24 11:54:50 +02:00
|
|
|
UsbRemoveDevice (Child);
|
2007-07-11 10:47:37 +02:00
|
|
|
}
|
2007-07-24 11:54:50 +02:00
|
|
|
|
|
|
|
if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_CONNECTION)) {
|
|
|
|
//
|
|
|
|
// Now, new device connected, enumerate and configure the device
|
|
|
|
//
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumeratePort: new device connected at port %d\n", Port));
|
2007-07-24 11:54:50 +02:00
|
|
|
Status = UsbEnumerateNewDev (HubIf, Port);
|
|
|
|
|
|
|
|
} else {
|
2007-08-20 05:13:24 +02:00
|
|
|
DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device disconnected event on port %d\n", Port));
|
2007-07-24 11:54:50 +02:00
|
|
|
}
|
|
|
|
|
2007-07-11 10:47:37 +02:00
|
|
|
HubApi->ClearPortChange (HubIf, Port);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Enumerate all the changed hub ports.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Event The event that is triggered.
|
|
|
|
@param Context The context to the event.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2008-07-09 12:02:26 +02:00
|
|
|
EFIAPI
|
2007-07-11 10:47:37 +02:00
|
|
|
UsbHubEnumeration (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_INTERFACE *HubIf;
|
|
|
|
UINT8 Byte;
|
|
|
|
UINT8 Bit;
|
|
|
|
UINT8 Index;
|
|
|
|
|
2008-12-26 09:07:22 +01:00
|
|
|
ASSERT (Context != NULL);
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
HubIf = (USB_INTERFACE *) Context;
|
|
|
|
|
|
|
|
if (HubIf->ChangeMap == NULL) {
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// HUB starts its port index with 1.
|
|
|
|
//
|
|
|
|
Byte = 0;
|
|
|
|
Bit = 1;
|
|
|
|
|
|
|
|
for (Index = 0; Index < HubIf->NumOfPort; Index++) {
|
|
|
|
if (USB_BIT_IS_SET (HubIf->ChangeMap[Byte], USB_BIT (Bit))) {
|
|
|
|
UsbEnumeratePort (HubIf, Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
USB_NEXT_BIT (Byte, Bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
UsbHubAckHubStatus (HubIf->Device);
|
|
|
|
|
|
|
|
gBS->FreePool (HubIf->ChangeMap);
|
|
|
|
HubIf->ChangeMap = NULL;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 12:02:26 +02:00
|
|
|
Enumerate all the changed hub ports.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
2008-07-09 12:02:26 +02:00
|
|
|
@param Event The event that is triggered.
|
|
|
|
@param Context The context to the event.
|
2007-07-11 10:47:37 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2007-08-30 22:42:05 +02:00
|
|
|
EFIAPI
|
2007-07-11 10:47:37 +02:00
|
|
|
UsbRootHubEnumeration (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_INTERFACE *RootHub;
|
|
|
|
UINT8 Index;
|
|
|
|
|
|
|
|
RootHub = (USB_INTERFACE *) Context;
|
|
|
|
|
|
|
|
for (Index = 0; Index < RootHub->NumOfPort; Index++) {
|
|
|
|
UsbEnumeratePort (RootHub, Index);
|
|
|
|
}
|
|
|
|
}
|