/** @file
Unified interface for RootHub and Hub.
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"
//
// Array that maps the change bit to feature value which is
// used to clear these change bit. USB HUB API will clear
// these change bit automatically. For non-root hub, these
// bits determine whether hub will report the port in changed
// bit maps.
//
};
};
//
// USB hub class specific requests. Although USB hub
// is related to an interface, these requests are sent
// to the control endpoint of the device.
//
/**
USB hub control transfer to set the hub depth.
@param HubDev The device of the hub.
@param Depth The depth to set.
@retval EFI_SUCCESS Depth of the hub is set.
@retval Others Failed to set the depth.
**/
)
{
Status = UsbCtrlRequest (
0,
NULL,
0
);
return Status;
}
/**
USB hub control transfer to clear the hub feature.
@param HubDev The device of the hub.
@param Feature The feature to clear.
@retval EFI_SUCCESS Feature of the hub is cleared.
@retval Others Failed to clear the feature.
**/
)
{
Status = UsbCtrlRequest (
0,
NULL,
0
);
return Status;
}
/**
Clear the feature of the device's port.
@param HubDev The hub device.
@param Port The port to clear feature.
@param Feature The feature to clear.
@retval EFI_SUCCESS The feature of the port is cleared.
@retval Others Failed to clear the feature.
**/
)
{
//
// In USB bus, all the port index starts from 0. But HUB
// indexes its port from 1. So, port number is added one.
//
Status = UsbCtrlRequest (
NULL,
0
);
return Status;
}
/**
uses this hub as translator.Remember to clear the TT
buffer of transaction translator, not that of the
parent.
@param HubDev The hub device.
@param Port The port of the hub.
@param DevAddr Address of the failed transaction.
@param EpNum The endpoint number of the failed transaction.
@param EpType The type of failed transaction.
@retval EFI_SUCCESS The TT buffer is cleared.
@retval Others Failed to clear the TT buffer.
**/
)
{
//
// Check USB2.0 spec page 424 for wValue's encoding
//
Status = UsbCtrlRequest (
NULL,
0
);
return Status;
}
/**
Usb hub control transfer to get the super speed hub descriptor.
@param HubDev The hub device.
@param Buf The buffer to hold the descriptor.
@retval EFI_SUCCESS The hub descriptor is retrieved.
@retval Others Failed to retrieve the hub descriptor.
**/
)
{
Status = UsbCtrlRequest (
0,
Buf,
32
);
return Status;
}
/**
Usb hub control transfer to get the hub descriptor.
@param HubDev The hub device.
@param Buf The buffer to hold the descriptor.
@param Len The length to retrieve.
@retval EFI_SUCCESS The hub descriptor is retrieved.
@retval Others Failed to retrieve the hub descriptor.
**/
)
{
Status = UsbCtrlRequest (
0,
Buf,
);
return Status;
}
/**
Usb hub control transfer to get the hub status.
@param HubDev The hub device.
@param State The variable to return the status.
@retval EFI_SUCCESS The hub status is returned in State.
@retval Others Failed to get the hub status.
**/
)
{
Status = UsbCtrlRequest (
0,
0,
4
);
return Status;
}
/**
Usb hub control transfer to get the port status.
@param HubDev The hub device.
@param Port The port of the hub.
@param State Variable to return the hub port state.
@retval EFI_SUCCESS The port state is returned in State.
@retval Others Failed to retrieve the port state.
**/
)
{
//
// In USB bus, all the port index starts from 0. But HUB
// indexes its port from 1. So, port number is added one.
// No need to convert the hub bit to UEFI definition, they
// are the same
//
Status = UsbCtrlRequest (
0,
4
);
return Status;
}
/**
Usb hub control transfer to reset the TT (Transaction Transaltor).
@param HubDev The hub device.
@param Port The port of the hub.
@retval EFI_SUCCESS The TT of the hub is reset.
@retval Others Failed to reset the port.
**/
)
{
Status = UsbCtrlRequest (
0,
NULL,
0
);
return Status;
}
/**
Usb hub control transfer to set the hub feature.
@param HubDev The hub device.
@param Feature The feature to set.
@retval EFI_SUCESS The feature is set for the hub.
@retval Others Failed to set the feature.
**/
)
{
Status = UsbCtrlRequest (
0,
NULL,
0
);
return Status;
}
/**
Usb hub control transfer to set the port feature.
@param HubDev The Usb hub device.
@param Port The Usb port to set feature for.
@param Feature The feature to set.
@retval EFI_SUCCESS The feature is set for the port.
@retval Others Failed to set the feature.
**/
)
{
//
// In USB bus, all the port index starts from 0. But HUB
// indexes its port from 1. So, port number is added one.
//
Status = UsbCtrlRequest (
NULL,
0
);
return Status;
}
/**
Read the whole usb hub descriptor. It is necessary
to do it in two steps because hub descriptor is of
variable length.
@param HubDev The hub device.
@param HubDesc The variable to return the descriptor.
@retval EFI_SUCCESS The hub descriptor is read.
@retval Others Failed to read the hub descriptor.
**/
)
{
//
// Get the super speed hub descriptor
//
} else {
//
// First get the hub descriptor length
//
return Status;
}
//
// Get the whole hub descriptor
//
}
return Status;
}
/**
Ack the hub change bits. If these bits are not ACKed, Hub will
always return changed bit map from its interrupt endpoint.
@param HubDev The hub device.
@retval EFI_SUCCESS The hub change status is ACKed.
@retval Others Failed to ACK the hub status.
**/
)
{
return Status;
}
}
}
return EFI_SUCCESS;
}
/**
Test whether the interface is a hub interface.
@param UsbIf The interface to test.
@retval TRUE The interface is a hub interface.
@retval FALSE The interface isn't a hub interface.
**/
)
{
//
// If the hub is a high-speed hub with multiple TT,
// the hub will has a default setting of single TT.
//
return TRUE;
}
return FALSE;
}
/**
The callback function to the USB hub status change
interrupt endpoint. It is called periodically by
the underlying host controller.
@param Data The data read.
@param DataLength The length of the data read.
@param Context The context.
@param Result The result of the last interrupt transfer.
@retval EFI_SUCCESS The process is OK.
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
**/
)
{
if (Result != EFI_USB_NOERROR) {
//
// If endpoint is stalled, clear the stall. Use UsbIo to access
// the control transfer so internal status are maintained.
//
);
}
//
// Delete and submit a new async interrupt
//
0,
0,
NULL,
);
return Status;
}
TRUE,
);
}
return Status;
}
return EFI_SUCCESS;
}
//
// OK, actually something is changed, save the change map
// then signal the HUB to do enumeration. This is a good
// practise since UsbOnHubInterrupt is called in the context
// of host contrller's AsyncInterrupt monitor.
//
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
/**
Initialize the device for a non-root hub.
@param HubIf The USB hub interface.
@retval EFI_SUCCESS The hub is initialized.
@retval EFI_DEVICE_ERROR Failed to initialize the hub.
**/
)
{
//
// Locate the interrupt endpoint for port change map
//
break;
}
}
if (Index == NumEndpoints) {
return EFI_DEVICE_ERROR;
}
return Status;
}
//
// OK, set IsHub to TRUE. Now usb bus can handle this device
// as a working HUB. If failed eariler, bus driver will not
// recognize it as a hub. Other parts of the bus should be able
// to work.
//
}
} else {
//
// Feed power to all the hub ports. It should be ok
// for both gang/individual powered hubs.
//
}
}
//
// Create an event to enumerate the hub's port. On
//
);
return Status;
}
//
// Create AsyncInterrupt to query hub port change endpoint
// periodically. If the hub ports are changed, hub will return
// changed port map from the interrupt endpoint. The port map
// must be able to hold (HubIf->NumOfPort + 1) bits (one bit for
// host change status).
//
TRUE,
);
return Status;
}
return Status;
}
/**
Get the port status. This function is required to
ACK the port change bits although it will return
the port changes in PortState. Bus enumeration code
doesn't need to ACK the port change bits.
@param HubIf The hub interface.
@param Port The port of the hub to get state.
@param PortState Variable to return the port state.
@retval EFI_SUCCESS The port status is successfully returned.
@retval Others Failed to return the status.
**/
)
{
return Status;
}
/**
Clear the port change status.
@param HubIf The hub interface.
@param Port The hub port.
**/
)
{
return;
}
//
// OK, get the usb port status, now ACK the change bits.
// Don't return error when failed to clear the change bits.
// It may lead to extra port state report. USB bus should
// be able to handle this.
//
}
}
}
/**
Function to set the port feature for non-root hub.
@param HubIf The hub interface.
@param Port The port of the hub.
@param Feature The feature of the port to set.
@retval EFI_SUCCESS The hub port feature is set.
@retval Others Failed to set the port feature.
**/
)
{
return Status;
}
/**
Interface function to clear the port feature for non-root hub.
@param HubIf The hub interface.
@param Port The port of the hub to clear feature for.
@param Feature The feature to clear.
@retval EFI_SUCCESS The port feature is cleared.
@retval Others Failed to clear the port feature.
**/
)
{
return Status;
}
/**
Interface function to reset the port.
@param HubIf The hub interface.
@param Port The port to reset.
@retval EFI_SUCCESS The hub port is reset.
@retval EFI_TIMEOUT Failed to reset the port in time.
@retval Others Failed to reset the port.
**/
)
{
return Status;
}
//
// Drive the reset signal for at least 10ms. Check USB 2.0 Spec
// section 7.1.7.5 for timing requirements.
//
//
// USB hub will clear RESET bit if reset is actually finished.
//
return EFI_SUCCESS;
}
}
return EFI_TIMEOUT;
}
/**
Release the hub's control of the interface.
@param HubIf The hub interface.
@retval EFI_SUCCESS The interface is release of hub control.
**/
)
{
0,
NULL,
0
);
return Status;
}
return EFI_SUCCESS;
}
/**
Initialize the interface for root hub.
@param HubIf The root hub interface.
@retval EFI_SUCCESS The interface is initialized for root hub.
@retval Others Failed to initialize the hub.
**/
)
{
return Status;
}
//
// Create a timer to poll root hub ports periodically
//
);
return Status;
}
//
// It should signal the event immediately here, or device detection
// by bus enumeration might be delayed by the timer interval.
//
);
}
return Status;
}
/**
Get the port status. This function is required to
ACK the port change bits although it will return
the port changes in PortState. Bus enumeration code
doesn't need to ACK the port change bits.
@param HubIf The root hub interface.
@param Port The root hub port to get the state.
@param PortState Variable to return the port state.
@retval EFI_SUCCESS The port state is returned.
@retval Others Failed to retrieve the port state.
**/
)
{
return Status;
}
/**
Clear the port change status.
@param HubIf The root hub interface.
@param Port The root hub port.
**/
)
{
return;
}
//
// OK, get the usb port status, now ACK the change bits.
// Don't return error when failed to clear the change bits.
// It may lead to extra port state report. USB bus should
// be able to handle this.
//
}
}
}
/**
Set the root hub port feature.
@param HubIf The Usb hub interface.
@param Port The hub port.
@param Feature The feature to set.
@retval EFI_SUCCESS The root hub port is set with the feature.
@retval Others Failed to set the feature.
**/
)
{
return Status;
}
/**
Clear the root hub port feature.
@param HubIf The root hub interface.
@param Port The root hub port.
@param Feature The feature to clear.
@retval EFI_SUCCESS The root hub port is cleared of the feature.
@retval Others Failed to clear the feature.
**/
)
{
return Status;
}
/**
Interface function to reset the root hub port.
@param RootIf The root hub interface.
@param Port The port to reset.
@retval EFI_SUCCESS The hub port is reset.
@retval EFI_TIMEOUT Failed to reset the port in time.
root hub is released to the companion UHCI.
@retval Others Failed to reset the port.
**/
)
{
//
// Notice: although EHCI requires that ENABLED bit be cleared
// when reset the port, we don't need to care that here. It
// should be handled in the EHCI driver.
//
return Status;
}
//
// Drive the reset signal for at least 50ms. Check USB 2.0 Spec
// section 7.1.7.5 for timing requirements.
//
return Status;
}
//
// USB host controller won't clear the RESET bit until
// reset is actually finished.
//
return Status;
}
break;
}
}
if (Index == USB_WAIT_PORT_STS_CHANGE_LOOP) {
return EFI_TIMEOUT;
}
//
// OK, the port is reset. If root hub is of high speed and
// companion UHCI. If root hub is of full speed, it won't
// automatically enable the port, we need to enable it manually.
//
return EFI_NOT_FOUND;
} else {
return Status;
}
}
}
return EFI_SUCCESS;
}
/**
Release the root hub's control of the interface.
@param HubIf The root hub interface.
@retval EFI_SUCCESS The root hub's control of the interface is
released.
**/
)
{
return EFI_SUCCESS;
}
};
};