/** @file
Usb bus enumeration support.
Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
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
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"
/**
Return the endpoint descriptor in this interface.
@param UsbIf The interface to search in.
@param EpAddr The address of the endpoint to return.
@return The endpoint descriptor or NULL.
**/
)
{
return EpDesc;
}
}
return NULL;
}
/**
Free the resource used by USB interface.
@param UsbIf The USB interface to free.
**/
)
{
);
}
}
/**
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.
@return The created USB interface for the descriptor, or NULL.
**/
)
{
return NULL;
}
CopyMem (
sizeof (EFI_USB_IO_PROTOCOL)
);
//
// Install protocols for USBIO and device path
//
goto ON_ERROR;
}
);
goto ON_ERROR;
}
//
// Open USB Host Controller Protocol by Child
//
);
goto ON_ERROR;
}
return UsbIf;
}
return NULL;
}
/**
Free the resource used by this USB device.
@param Device The USB device to free.
**/
)
{
}
}
/**
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.
@return Created USB device, Or NULL.
**/
)
{
return NULL;
}
return Device;
}
/**
Connect the USB interface with its driver. EFI USB bus will
create a USB interface for each separate interface descriptor.
@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.
**/
)
{
//
// Hub is maintained by the USB bus driver. Otherwise try to
// connect drivers with this interface
//
if (UsbIsHubInterface (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.
//
//
// Only recursively wanted usb child device
//
OldTpl = UsbGetCurrentTpl ();
DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32)OldTpl, UsbIf->Handle));
}
}
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.
@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_SUCCESS The interface is set to Alternate setting.
**/
)
{
//
// Locate the active alternate setting
//
break;
}
}
return EFI_NOT_FOUND;
}
//
// Reset the endpoint toggle to zero
//
}
return EFI_SUCCESS;
}
/**
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).
@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.
**/
)
{
//
// Locate the active config, then set the device's pointer
//
ConfigDesc = NULL;
break;
}
}
return EFI_NOT_FOUND;
}
//
// Create interfaces for each USB interface descriptor.
//
//
// First select the default interface setting, and reset
// the endpoint toggles to zero for its endpoints.
//
//
// Create a USB_INTERFACE and install USB_IO and other protocols
//
return EFI_OUT_OF_RESOURCES;
}
//
// Connect the device to drivers, if it failed, ignore
// the error. Don't let the unsupported interfaces to block
// the supported interfaces.
//
}
}
return EFI_SUCCESS;
}
/**
Disconnect the USB interface with its driver.
@param UsbIf The interface to disconnect driver from.
**/
)
{
//
// Release the hub if it's a hub controller, otherwise
// disconnect the driver if it is managed by other drivers.
//
//
// 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 ();
DEBUG (( EFI_D_INFO, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32)UsbGetCurrentTpl(), Status));
}
}
/**
Remove the current device configuration.
@param Device The USB device to remove configuration from.
**/
)
{
//
// Remove each interface of the device
//
continue;
}
}
Device->NumOfInterface = 0;
}
/**
Remove the device and all its children from the bus.
@param Device The device to remove.
@retval EFI_SUCCESS The device is removed.
**/
)
{
//
// Remove all the devices on its downstream ports. Search from devices[1].
// Devices[0] is the root hub.
//
continue;
}
}
}
return EFI_SUCCESS;
}
/**
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.
@return The device on the hub's port, or NULL if there is none.
**/
)
{
//
// Start checking from device 1, device 0 is the root hub
//
return Device;
}
}
return NULL;
}
/**
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).
@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.
**/
)
{
//
// Hub resets the device for at least 10 milliseconds.
// and the hub is a EHCI root hub, ResetPort will release
// the device to its companion UHCI and return an error.
//
return Status;
}
return EFI_OUT_OF_RESOURCES;
}
//
// OK, now identify the device speed. After reset, hub
// fully knows the actual device speed.
//
goto ON_ERROR;
}
goto ON_ERROR;
} else {
}
//
// If the child is a low or full speed device, it is necessary to
// 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.
//
} else {
}
//
// After port is reset, hub establishes a signal path between
// 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 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.
//
break;
}
}
goto ON_ERROR;
}
goto ON_ERROR;
}
//
// Host sends a Get_Descriptor request to learn the max packet
// size of default pipe (only part of the device's descriptor).
//
goto ON_ERROR;
}
//
// Host learns about the device's abilities by requesting device's
// entire descriptions.
//
goto ON_ERROR;
}
//
// Select a default configuration: UEFI must set the configuration
// before the driver can connect to the device.
//
goto ON_ERROR;
}
//
// Host assigns and loads a device driver.
//
goto ON_ERROR;
}
return EFI_SUCCESS;
}
}
return Status;
}
/**
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).
@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.
**/
)
{
//
// Host learns of the new device by polling the hub for port changes.
//
return Status;
}
//
// 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) {
return EFI_SUCCESS;
}
//
// This driver only process two kinds of events now: over current and
// connect/disconnect. Other three events are: ENABLE, SUSPEND, RESET.
//
//
// 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.
//
return EFI_DEVICE_ERROR;
}
//
// 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.
//
}
//
// 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.
//
}
//
// Case4:
// Device connected or disconnected normally.
//
}
//
// Following as the above cases, it's safety to remove and create again.
//
DEBUG (( EFI_D_INFO, "UsbEnumeratePort: device at port %d removed from root hub %p\n", Port, HubIf));
}
//
// Now, new device connected, enumerate and configure the device
//
} else {
}
return Status;
}
/**
Enumerate all the changed hub ports.
@param Event The event that is triggered.
@param Context The context to the event.
**/
)
{
return ;
}
//
// HUB starts its port index with 1.
//
Byte = 0;
Bit = 1;
}
}
return ;
}
/**
Enumerate all the changed hub ports.
@param Event The event that is triggered.
@param Context The context to the event.
**/
)
{
}
}