/** @file
PEIM to produce gPeiUsbHostControllerPpiGuid based on gPeiUsbControllerPpiGuid
which is used to enable recovery function from USB Drivers.
Copyright (c) 2006 - 2010, 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 "UhcPeim.h"
/**
Initializes Usb Host Controller.
@param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
@retval EFI_SUCCESS PPI successfully installed.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
**/
)
{
//
// Shadow this PEIM to run from memory
//
return EFI_SUCCESS;
}
0,
NULL,
(VOID **) &ChipSetUsbControllerPpi
);
//
// If failed to locate, it is a bug in dispather as depex has gPeiUsbControllerPpiGuid.
//
Index = 0;
while (TRUE) {
(EFI_PEI_SERVICES **) PeiServices,
);
//
// When status is error, meant no controller is found
//
break;
}
//
// This PEIM is for UHC type controller.
//
if (ControllerType != PEI_UHCI_CONTROLLER) {
Index++;
continue;
}
);
return EFI_OUT_OF_RESOURCES;
}
//
// Init local memory management service
//
return Status;
}
//
// Initialize Uhc's hardware
//
return Status;
}
Index++;
continue;
}
Index++;
}
return EFI_SUCCESS;
}
/**
Submits control transfer to a target USB device.
@param PeiServices The pointer of EFI_PEI_SERVICES.
@param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
@param DeviceAddress The target device address.
@param DeviceSpeed Target device speed.
@param MaximumPacketLength Maximum packet size the default control transfer
endpoint is capable of sending or receiving.
@param Request USB device request to send.
@param TransferDirection Specifies the data direction for the data stage.
@param Data Data buffer to be transmitted or received from USB device.
@param DataLength The size (in bytes) of the data buffer.
@param TimeOut Indicates the maximum timeout, in millisecond.
@param TransferResult Return the result of this control transfer.
@retval EFI_SUCCESS Transfer was completed successfully.
@retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
@retval EFI_INVALID_PARAMETER Some parameters are invalid.
@retval EFI_TIMEOUT Transfer failed due to timeout.
@retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
**/
)
{
return EFI_INVALID_PARAMETER;
}
//
// if errors exist that cause host controller halt,
// then return EFI_DEVICE_ERROR.
//
return EFI_DEVICE_ERROR;
}
//
// generate Setup Stage TD
//
0,
(UINT8) sizeof (EFI_USB_DEVICE_REQUEST),
);
//
// link setup TD structures to QH structure
//
//
// Data Stage of Control Transfer
//
switch (TransferDirection) {
case EfiUsbDataIn:
Ptr = PtrDataSource;
break;
case EfiUsbDataOut:
Ptr = PtrDataSource;
break;
//
// no data stage
//
case EfiUsbNoData:
if (*DataLength != 0) {
return EFI_INVALID_PARAMETER;
}
DataLen = 0;
break;
default:
return EFI_INVALID_PARAMETER;
}
DataToggle = 1;
PtrTD = PtrSetupTD;
while (DataLen > 0) {
//
// create TD structures and link together
//
//
// PacketSize is the data load size of each TD carries.
//
if (DataLen > MaximumPacketLength) {
}
0,
Ptr,
);
//
// Link two TDs in vertical depth
//
DataToggle ^= 1;
Ptr += PacketSize;
DataLen -= PacketSize;
}
//
// PtrPreTD points to the last TD before the Setup-Stage TD.
//
//
// Status Stage of Control Transfer
//
if (PktID == OUTPUT_PACKET_ID) {
} else {
}
//
// create Status Stage TD structure
//
0,
);
//
// Poll QH-TDs execution and get result.
// detail status is returned
//
);
//
// TRUE means must search other framelistindex
//
//
// if has errors that cause host controller halt, then return EFI_DEVICE_ERROR directly.
//
return EFI_DEVICE_ERROR;
}
return Status;
}
/**
Submits bulk transfer to a bulk endpoint of a USB device.
@param PeiServices The pointer of EFI_PEI_SERVICES.
@param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
@param DeviceAddress Target device address.
@param EndPointAddress Endpoint number and its direction in bit 7.
@param MaximumPacketLength Maximum packet size the endpoint is capable of
sending or receiving.
@param Data Array of pointers to the buffers of data to transmit
from or receive into.
@param DataLength The lenght of the data buffer.
@param DataToggle On input, the initial data toggle for the transfer;
On output, it is updated to to next data toggle to use of
the subsequent bulk transfer.
@param TimeOut Indicates the maximum time, in millisecond, which the
transfer is allowed to complete.
@param TransferResult A pointer to the detailed result information of the
bulk transfer.
@retval EFI_SUCCESS The transfer was completed successfully.
@retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
@retval EFI_INVALID_PARAMETER Parameters are invalid.
@retval EFI_TIMEOUT The transfer failed due to timeout.
@retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
**/
)
{
//
// Enable the maximum packet size (64bytes)
// that can be used for full speed bandwidth reclamation
// at the end of a frame.
//
}
//
// these code lines are added here per complier's strict demand
//
PtrFirstTD = NULL;
DataLen = 0;
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
return EFI_INVALID_PARAMETER;
}
//
// if has errors that cause host controller halt, then return EFI_DEVICE_ERROR directly.
//
return EFI_DEVICE_ERROR;
}
if ((EndPointAddress & 0x80) != 0) {
} else {
}
switch (TransferDirection) {
case EfiUsbDataIn:
Ptr = PtrDataSource;
break;
case EfiUsbDataOut:
Ptr = PtrDataSource;
break;
default:
break;
}
while (DataLen > 0) {
//
// create TD structures and link together
//
if (DataLen > MaximumPacketLength) {
}
Ptr,
);
//
// Enable short packet detection.
// (default action is disabling short packet detection)
//
if (ShortPacketEnable) {
}
if (IsFirstTD) {
PtrFirstTD = PtrTD;
} else {
//
// Link two TDs in vertical depth
//
}
*DataToggle ^= 1;
Ptr += PacketSize;
DataLen -= PacketSize;
}
//
// link TD structures to QH structure
//
//
// Execute QH-TD and get result
//
//
// detail status is put into the Result field in the pIRP
// the Data Toggle value is also re-updated to the value
// of the last successful TD
//
);
//
// Delete Bulk transfer TD structure
//
//
// if has errors that cause host controller halt, then return EFI_DEVICE_ERROR directly.
//
return EFI_DEVICE_ERROR;
}
return Status;
}
/**
Retrieves the number of root hub ports.
@param[in] PeiServices The pointer to the PEI Services Table.
@param[in] This The pointer to this instance of the
PEI_USB_HOST_CONTROLLER_PPI.
@param[out] PortNumber The pointer to the number of the root hub ports.
@retval EFI_SUCCESS The port number was retrieved successfully.
@retval EFI_INVALID_PARAMETER PortNumber is NULL.
**/
)
{
if (PortNumber == NULL) {
return EFI_INVALID_PARAMETER;
}
*PortNumber = 0;
//
// Port Register content is valid
//
if (RHPortControl != 0xff) {
(*PortNumber)++;
}
}
return EFI_SUCCESS;
}
/**
Retrieves the current status of a USB root hub port.
@param PeiServices The pointer of EFI_PEI_SERVICES.
@param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
@param PortNumber The root hub port to retrieve the state from.
@param PortStatus Variable to receive the port state.
@retval EFI_SUCCESS The status of the USB root hub port specified.
by PortNumber was returned in PortStatus.
@retval EFI_INVALID_PARAMETER PortNumber is invalid.
**/
)
{
if (PortStatus == NULL) {
return EFI_INVALID_PARAMETER;
}
if (PortNumber > TotalPortNumber) {
return EFI_INVALID_PARAMETER;
}
PortStatus->PortStatus = 0;
PortStatus->PortChangeStatus = 0;
//
// Current Connect Status
//
if ((RHPortStatus & USBPORTSC_CCS) != 0) {
}
//
//
if ((RHPortStatus & USBPORTSC_PED) != 0) {
}
//
// Port Suspend
//
if ((RHPortStatus & USBPORTSC_SUSP) != 0) {
}
//
// Port Reset
//
if ((RHPortStatus & USBPORTSC_PR) != 0) {
}
//
// Low Speed Device Attached
//
if ((RHPortStatus & USBPORTSC_LSDA) != 0) {
}
//
// Fill Port Status Change bits
//
//
// Connect Status Change
//
if ((RHPortStatus & USBPORTSC_CSC) != 0) {
}
//
//
if ((RHPortStatus & USBPORTSC_PEDC) != 0) {
}
return EFI_SUCCESS;
}
/**
Sets a feature for the specified root hub port.
@param PeiServices The pointer of EFI_PEI_SERVICES
@param This The pointer of PEI_USB_HOST_CONTROLLER_PPI
@param PortNumber Root hub port to set.
@param PortFeature Feature to set.
@retval EFI_SUCCESS The feature specified by PortFeature was set.
@retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
@retval EFI_TIMEOUT The time out occurred.
**/
)
{
if (PortNumber > TotalPortNumber) {
return EFI_INVALID_PARAMETER;
}
switch (PortFeature) {
case EfiUsbPortSuspend:
//
// if global suspend is not active, can set port suspend
//
RHPortControl &= 0xfff5;
}
break;
case EfiUsbPortReset:
RHPortControl &= 0xfff5;
//
// Set the reset bit
//
break;
case EfiUsbPortPower:
break;
case EfiUsbPortEnable:
RHPortControl &= 0xfff5;
break;
default:
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
Clears a feature for the specified root hub port.
@param PeiServices The pointer of EFI_PEI_SERVICES.
@param This The pointer of PEI_USB_HOST_CONTROLLER_PPI.
@param PortNumber Specifies the root hub port whose feature
is requested to be cleared.
@param PortFeature Indicates the feature selector associated with the
feature clear request.
@retval EFI_SUCCESS The feature specified by PortFeature was cleared
for the USB root hub port specified by PortNumber.
@retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
**/
)
{
if (PortNumber > TotalPortNumber) {
return EFI_INVALID_PARAMETER;
}
switch (PortFeature) {
//
// clear PORT_ENABLE feature means disable port.
//
case EfiUsbPortEnable:
RHPortControl &= 0xfff5;
break;
//
// clear PORT_SUSPEND feature means resume the port.
// (cause a resume on the specified port if in suspend mode)
//
case EfiUsbPortSuspend:
RHPortControl &= 0xfff5;
break;
//
// no operation
//
case EfiUsbPortPower:
break;
//
// clear PORT_RESET means clear the reset signal.
//
case EfiUsbPortReset:
RHPortControl &= 0xfff5;
break;
//
// clear connect status change
//
case EfiUsbPortConnectChange:
RHPortControl &= 0xfff5;
break;
//
//
case EfiUsbPortEnableChange:
RHPortControl &= 0xfff5;
break;
//
// root hub does not support this request
//
case EfiUsbPortSuspendChange:
break;
//
// root hub does not support this request
//
break;
//
// root hub does not support this request
//
case EfiUsbPortResetChange:
break;
default:
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
Initialize UHCI.
@param UhcDev UHCI Device.
@retval EFI_SUCCESS UHCI successfully initialized.
@retval EFI_OUT_OF_RESOURCES Resource can not be allocated.
**/
)
{
//
// Create and Initialize Frame List For the Host Controller.
//
return Status;
}
//
// Set Frame List Base Address to the specific register to inform the hardware.
//
Command |= USBCMD_GRESET;
Command &= ~USBCMD_GRESET;
//
//UHCI spec page120 reset recovery time
//
//
//
return EFI_SUCCESS;
}
/**
Create Frame List Structure.
@param UhcDev UHCI device.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
@retval EFI_SUCCESS Success.
**/
)
{
//
// The Frame List ocupies 4K bytes,
// and must be aligned on 4-Kbyte boundaries.
//
1,
);
if (Status != EFI_SUCCESS) {
return EFI_OUT_OF_RESOURCES;
}
//
//Create Control QH and Bulk QH and link them into Framelist Entry
//
if (Status != EFI_SUCCESS) {
return EFI_OUT_OF_RESOURCES;
}
if (Status != EFI_SUCCESS) {
return EFI_OUT_OF_RESOURCES;
}
//
//Set the corresponding QH pointer
//
FrameListPtr->FrameListRsvd = 0;
FrameListPtr ++;
}
return EFI_SUCCESS;
}
/**
Read a 16bit width data from Uhc HC IO space register.
@param UhcDev The UHCI device.
@param Port The IO space address of the register.
@retval the register content read.
**/
)
{
}
/**
Write a 16bit width data into Uhc HC IO space register.
@param UhcDev The UHCI device.
@param Port The IO space address of the register.
@param Data The data written into the register.
**/
)
{
}
/**
Write a 32bit width data into Uhc HC IO space register.
@param UhcDev The UHCI device.
@param Port The IO space address of the register.
@param Data The data written into the register.
**/
)
{
}
/**
Clear the content of UHCI's Status Register.
@param UhcDev The UHCI device.
@param StatusAddr The IO space address of the register.
**/
)
{
//
// Clear the content of UHCI's Status Register
//
}
/**
Check whether the host controller operates well.
@param UhcDev The UHCI device.
@param StatusRegAddr The io address of status register.
@retval TRUE Host controller is working.
@retval FALSE Host controller is halted or system error.
**/
)
{
return FALSE;
} else {
return TRUE;
}
}
/**
Get Current Frame Number.
@param UhcDev The UHCI device.
@param FrameNumberAddr The address of frame list register.
@retval The content of the frame list register.
**/
)
{
//
// Gets value in the USB frame number register.
//
}
/**
Set Frame List Base Address.
@param UhcDev The UHCI device.
@param FrameListRegAddr The address of frame list register.
@param Addr The address of frame list table.
**/
)
{
//
// Sets value in the USB Frame List Base Address register.
//
}
/**
Create QH and initialize.
@param UhcDev The UHCI device.
@param PtrQH Place to store QH_STRUCT pointer.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
@retval EFI_SUCCESS Success.
**/
CreateQH (
)
{
//
// allocate align memory for QH_STRUCT
//
return EFI_OUT_OF_RESOURCES;
}
//
// init each field of the QH_STRUCT
//
return EFI_SUCCESS;
}
/**
Set the horizontal link pointer in QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param PtrNext Place to the next QH_STRUCT.
**/
)
{
//
// Since the QH_STRUCT is aligned on 16-byte boundaries,
// Only the highest 28bit of the address is valid
// (take 32bit address as an example).
//
}
/**
Get the horizontal link pointer in QH.
@param PtrQH Place to store QH_STRUCT pointer.
@retval The horizontal link pointer in QH.
**/
VOID *
)
{
//
// Restore the 28bit address to 32bit address
// (take 32bit address as an example)
//
}
/**
Set a QH or TD horizontally to be connected with a specific QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param IsQH Specify QH or TD is connected.
**/
)
{
//
// if QH is connected, the specified bit is set,
// if TD is connected, the specified bit is cleared.
//
}
/**
Set the horizontal validor bit in QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param IsValid Specify the horizontal linker is valid or not.
**/
)
{
//
// Valid means the horizontal link pointer is valid,
// else, it's invalid.
//
}
/**
Set the vertical link pointer in QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param PtrNext Place to the next QH_STRUCT.
**/
)
{
//
// Since the QH_STRUCT is aligned on 16-byte boundaries,
// Only the highest 28bit of the address is valid
// (take 32bit address as an example).
//
}
/**
Set a QH or TD vertically to be connected with a specific QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param IsQH Specify QH or TD is connected.
**/
)
{
//
// Set the specified bit if the Vertical Link Pointer pointing to a QH,
// Clear the specified bit if the Vertical Link Pointer pointing to a TD.
//
}
/**
Set the vertical validor bit in QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param IsValid Specify the vertical linker is valid or not.
**/
)
{
//
// If TRUE, meaning the Vertical Link Pointer field is valid,
// else, the field is invalid.
//
}
/**
Get the vertical validor bit in QH.
@param PtrQH Place to store QH_STRUCT pointer.
@retval The vertical linker is valid or not.
**/
)
{
//
// If TRUE, meaning the Horizontal Link Pointer field is valid,
// else, the field is invalid.
//
}
/**
Allocate TD or QH Struct.
@param UhcDev The UHCI device.
@param Size The size of allocation.
@param PtrStruct Place to store TD_STRUCT pointer.
@return EFI_SUCCESS Allocate successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
**/
)
{
);
return Status;
}
return Status;
}
/**
Create a TD Struct.
@param UhcDev The UHCI device.
@param PtrTD Place to store TD_STRUCT pointer.
@return EFI_SUCCESS Allocate successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
**/
CreateTD (
)
{
//
// create memory for TD_STRUCT, and align the memory.
//
return Status;
}
//
// Make TD ready.
//
return EFI_SUCCESS;
}
/**
Generate Setup Stage TD.
@param UhcDev The UHCI device.
@param DevAddr Device address.
@param Endpoint Endpoint number.
@param DeviceSpeed Device Speed.
@param DevRequest Device reuquest.
@param RequestLen Request length.
@param PtrTD TD_STRUCT generated.
@return EFI_SUCCESS Generate setup stage TD successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
**/
)
{
return Status;
}
//
// Depth first fashion
//
//
// initialize as the last TD in the QH context,
// this field will be updated in the TD linkage process.
//
//
// Disable Short Packet Detection by default
//
//
// Max error counter is 3, retry 3 times when error encountered.
//
//
// set device speed attribute
// (TRUE - Slow Device; FALSE - Full Speed Device)
//
switch (DeviceSpeed) {
case USB_SLOW_SPEED_DEVICE:
break;
case USB_FULL_SPEED_DEVICE:
break;
}
//
// Non isochronous transfer TD
//
//
// Interrupt On Complete bit be set to zero,
// Disable IOC interrupt.
//
//
// Set TD Active bit
//
return EFI_SUCCESS;
}
/**
Generate Data Stage TD.
@param UhcDev The UHCI device.
@param DevAddr Device address.
@param Endpoint Endpoint number.
@param PtrData Data buffer.
@param Len Data length.
@param PktID PacketID.
@param Toggle Data toggle value.
@param DeviceSpeed Device Speed.
@param PtrTD TD_STRUCT generated.
@return EFI_SUCCESS Generate data stage TD successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
**/
)
{
return Status;
}
//
// Depth first fashion
//
//
// Link pointer pointing to TD struct
//
//
// initialize as the last TD in the QH context,
// this field will be updated in the TD linkage process.
//
//
// Disable short packet detect
//
//
// Max error counter is 3
//
//
// set device speed attribute
// (TRUE - Slow Device; FALSE - Full Speed Device)
//
switch (DeviceSpeed) {
case USB_SLOW_SPEED_DEVICE:
break;
case USB_FULL_SPEED_DEVICE:
break;
}
//
// Non isochronous transfer TD
//
//
// Disable Interrupt On Complete
// Disable IOC interrupt.
//
//
// Set Active bit
//
if (Toggle != 0) {
} else {
}
return EFI_SUCCESS;
}
/**
Generate Status Stage TD.
@param UhcDev The UHCI device.
@param DevAddr Device address.
@param Endpoint Endpoint number.
@param PktID PacketID.
@param DeviceSpeed Device Speed.
@param PtrTD TD_STRUCT generated.
@return EFI_SUCCESS Generate status stage TD successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
**/
)
{
return Status;
}
//
// Depth first fashion
//
//
// initialize as the last TD in the QH context,
// this field will be updated in the TD linkage process.
//
//
// Disable short packet detect
//
//
// Max error counter is 3
//
//
// set device speed attribute
// (TRUE - Slow Device; FALSE - Full Speed Device)
//
switch (DeviceSpeed) {
case USB_SLOW_SPEED_DEVICE:
break;
case USB_FULL_SPEED_DEVICE:
break;
}
//
// Non isochronous transfer TD
//
//
// Disable Interrupt On Complete
// Disable IOC interrupt.
//
//
// Set TD Active bit
//
PtrTDStruct->TDBufferLength = 0;
*PtrTD = PtrTDStruct;
return EFI_SUCCESS;
}
/**
Set the link pointer validor bit in TD.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsValid Specify the linker pointer is valid or not.
**/
)
{
//
// Valid means the link pointer is valid,
// else, it's invalid.
//
}
/**
Set the Link Pointer pointing to a QH or TD.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsQH Specify QH or TD is connected.
**/
)
{
//
// Indicate whether the Link Pointer pointing to a QH or TD
//
}
/**
Set the traverse is depth-first or breadth-first.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsDepth Specify the traverse is depth-first or breadth-first.
**/
)
{
//
// If TRUE, indicating the host controller should process in depth first fashion,
// else, the host controller should process in breadth first fashion
//
}
/**
Set TD Link Pointer in TD.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param PtrNext Place to the next TD_STRUCT.
**/
)
{
//
// Set TD Link Pointer. Since QH,TD align on 16-byte boundaries,
// only the highest 28 bits are valid. (if take 32bit address as an example)
//
}
/**
Get TD Link Pointer.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval Get TD Link Pointer in TD.
**/
VOID *
)
{
//
// Get TD Link Pointer. Restore it back to 32bit
// (if take 32bit address as an example)
//
}
/**
Get the information about whether the Link Pointer field pointing to
a QH or a TD.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval whether the Link Pointer field pointing to a QH or a TD.
**/
)
{
//
// Get the information about whether the Link Pointer field pointing to
// a QH or a TD.
//
}
/**
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsEnable Enable or disable short packet detection mechanism.
**/
)
{
//
// TRUE means enable short packet detection mechanism.
//
}
/**
Set the max error counter in TD.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param MaxErrors The number of allowable error.
**/
)
{
//
// valid value of MaxErrors is 0,1,2,3
//
if (MaxErrors > 3) {
MaxErrors = 3;
}
}
/**
Set the TD is targeting a low-speed device or not.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsLowSpeedDevice Whether The device is low-speed.
**/
)
{
//
// TRUE means the TD is targeting at a Low-speed device
//
}
/**
Set the TD is isochronous transfer type or not.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsIsochronous Whether the transaction isochronous transfer type.
**/
)
{
//
// TRUE means the TD belongs to Isochronous transfer type.
//
}
/**
Set if UCHI should issue an interrupt on completion of the frame
in which this TD is executed
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsSet Whether HC should issue an interrupt on completion.
**/
)
{
//
// If this bit is set, it indicates that the host controller should issue
// an interrupt on completion of the frame in which this TD is executed.
//
}
/**
Set if the TD is active and can be executed.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param IsActive Whether the TD is active and can be executed.
**/
)
{
//
// If this bit is set, it indicates that the TD is active and can be
// executed.
//
if (IsActive) {
} else {
}
}
/**
Specifies the maximum number of data bytes allowed for the transfer.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param MaxLen The maximum number of data bytes allowed.
@retval The allowed maximum number of data.
**/
)
{
//
// Specifies the maximum number of data bytes allowed for the transfer.
// the legal value extent is 0 ~ 0x500.
//
if (MaxLen > 0x500) {
MaxLen = 0x500;
}
return MaxLen;
}
/**
Set the data toggle bit to DATA1.
@param PtrTDStruct Place to store TD_STRUCT pointer.
**/
)
{
//
// Set the data toggle bit to DATA1
//
}
/**
Set the data toggle bit to DATA0.
@param PtrTDStruct Place to store TD_STRUCT pointer.
**/
)
{
//
// Set the data toggle bit to DATA0
//
}
/**
Set EndPoint Number the TD is targeting at.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param EndPoint The Endport number of the target.
**/
)
{
//
// Set EndPoint Number the TD is targeting at.
//
}
/**
Set Device Address the TD is targeting at.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param DevAddr The Device Address of the target.
**/
)
{
//
// Set Device Address the TD is targeting at.
//
}
/**
Set Packet Identification the TD is targeting at.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@param PacketID The Packet Identification of the target.
**/
)
{
//
// Set the Packet Identification to be used for this transaction.
//
}
/**
Set the beginning address of the data buffer that will be used
during the transaction.
@param PtrTDStruct Place to store TD_STRUCT pointer.
**/
)
{
//
// Set the beginning address of the data buffer that will be used
// during the transaction.
//
}
/**
Detect whether the TD is active.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The TD is active or not.
**/
)
{
//
// Detect whether the TD is active.
//
}
/**
Detect whether the TD is stalled.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The TD is stalled or not.
**/
)
{
//
//
}
/**
Detect whether Data Buffer Error is happened.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The Data Buffer Error is happened or not.
**/
)
{
//
// Detect whether Data Buffer Error is happened.
//
}
/**
Detect whether Babble Error is happened.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The Babble Error is happened or not.
**/
)
{
//
// Detect whether Babble Error is happened.
//
}
/**
Detect whether NAK is received.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The NAK is received or not.
**/
)
{
//
// Detect whether NAK is received.
//
}
/**
@param PtrTDStruct Place to store TD_STRUCT pointer.
**/
)
{
//
//
}
/**
Detect whether Bitstuff Error is received.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The Bitstuff Error is received or not.
**/
)
{
//
// Detect whether Bitstuff Error is received.
//
}
/**
Retrieve the actual number of bytes that were tansferred.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The actual number of bytes that were tansferred.
**/
)
{
//
// Retrieve the actual number of bytes that were tansferred.
// the value is encoded as n-1. so return the decoded value.
//
}
/**
Retrieve the information of whether the Link Pointer field is valid or not.
@param PtrTDStruct Place to store TD_STRUCT pointer.
@retval The linker pointer field is valid or not.
**/
)
{
//
// Retrieve the information of whether the Link Pointer field
// is valid or not.
//
return FALSE;
} else {
return TRUE;
}
}
/**
Count TD Number from PtrFirstTD.
@param PtrFirstTD Place to store TD_STRUCT pointer.
@retval The queued TDs number.
**/
)
{
//
// Count the queued TDs number.
//
Number = 0;
Ptr = PtrFirstTD;
while (Ptr != 0) {
Number++;
}
return Number;
}
/**
Link TD To QH.
@param PtrQH Place to store QH_STRUCT pointer.
@param PtrTD Place to store TD_STRUCT pointer.
**/
)
{
return ;
}
//
// Validate QH Vertical Ptr field
//
//
// Vertical Ptr pointing to TD structure
//
}
/**
Link TD To TD.
@param PtrPreTD Place to store TD_STRUCT pointer.
@param PtrTD Place to store TD_STRUCT pointer.
**/
)
{
return ;
}
//
// Depth first fashion
//
//
// Link pointer pointing to TD struct
//
//
// Validate the link pointer valid bit
//
}
/**
Execute Control Transfer.
@param UhcDev The UCHI device.
@param PtrTD A pointer to TD_STRUCT data.
@param ActualLen Actual transfer Length.
@param TimeOut TimeOut value.
@param TransferResult Transfer Result.
@return EFI_DEVICE_ERROR The transfer failed due to transfer error.
@return EFI_TIMEOUT The transfer failed due to time out.
@return EFI_SUCCESS The transfer finished OK.
**/
)
{
ErrTDPos = 0;
*ActualLen = 0;
do {
//
// TD is inactive, means the control transfer is end.
//
break;
}
MicroSecondDelay (200);
Delay--;
} while (Delay != 0);
if (*TransferResult != EFI_USB_NOERROR) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Execute Bulk Transfer.
@param UhcDev The UCHI device.
@param PtrTD A pointer to TD_STRUCT data.
@param ActualLen Actual transfer Length.
@param DataToggle DataToggle value.
@param TimeOut TimeOut value.
@param TransferResult Transfer Result.
@return EFI_DEVICE_ERROR The transfer failed due to transfer error.
@return EFI_TIMEOUT The transfer failed due to time out.
@return EFI_SUCCESS The transfer finished OK.
**/
)
{
ErrTDPos = 0;
*ActualLen = 0;
do {
//
// TD is inactive, thus meaning bulk transfer's end.
//
break;
}
MicroSecondDelay (200);
Delay--;
} while (Delay != 0);
//
// has error
//
if (*TransferResult != EFI_USB_NOERROR) {
//
// scroll the Data Toggle back to the last success TD
//
if ((ScrollNum % 2) != 0) {
*DataToggle ^= 1;
}
//
// If error, wait 100ms to retry by upper layer
//
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
Delete Queued TDs.
@param UhcDev The UCHI device.
@param PtrFirstTD Place to store TD_STRUCT pointer.
**/
)
{
Tptr1 = PtrFirstTD;
//
// Delete all the TDs in a queue.
//
if (!GetTDLinkPtrValidorInvalid (Tptr2)) {
} else {
//
// has more than one TD in the queue.
//
}
}
return ;
}
/**
Check TDs Results.
@param PtrTD A pointer to TD_STRUCT data.
@param Result The result to return.
@param ErrTDPos The Error TD position.
@param ActualTransferSize Actual transfer size.
@retval The TD is executed successfully or not.
**/
)
{
*ErrTDPos = 0;
//
// Init to zero.
//
*ActualTransferSize = 0;
if (IsTDStatusActive (PtrTD)) {
}
if (IsTDStatusStalled (PtrTD)) {
*Result |= EFI_USB_ERR_STALL;
}
if (IsTDStatusBufferError (PtrTD)) {
*Result |= EFI_USB_ERR_BUFFER;
}
if (IsTDStatusBabbleError (PtrTD)) {
*Result |= EFI_USB_ERR_BABBLE;
}
if (IsTDStatusNAKReceived (PtrTD)) {
*Result |= EFI_USB_ERR_NAK;
}
if (IsTDStatusCRCTimeOutError (PtrTD)) {
}
if (IsTDStatusBitStuffError (PtrTD)) {
}
//
// Accumulate actual transferred data length in each TD.
//
*ActualTransferSize += Len;
//
// if any error encountered, stop processing the left TDs.
//
if ((*Result) != 0) {
return FALSE;
}
//
// Record the first Error TD's position in the queue,
// this value is zero-based.
//
(*ErrTDPos)++;
}
return TRUE;
}
/**
Create Memory Block.
@param UhcDev The UCHI device.
@param MemoryHeader The Pointer to allocated memory block.
@param MemoryBlockSizeInPages The page size of memory block to be allocated.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
@retval EFI_SUCCESS Success.
**/
)
{
//
// Memory Block uses MemoryBlockSizeInPages pages,
// memory management header and bit array use 1 page
//
);
return Status;
}
//
// adjust Ptr pointer to the next empty memory
//
Ptr += sizeof (MEMORY_MANAGE_HEADER);
//
// Set Bit Array initial address
//
//
// Memory block initial address
//
Ptr += EFI_PAGE_SIZE;
//
// set Memory block size
//
//
// each bit in Bit Array will manage 32byte memory in memory block
//
return EFI_SUCCESS;
}
/**
Initialize UHCI memory management.
@param UhcDev The UCHI device.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
@retval EFI_SUCCESS Success.
**/
)
{
return Status;
}
return EFI_SUCCESS;
}
/**
Initialize UHCI memory management.
@param UhcDev The UCHI device.
@param Pool Buffer pointer to store the buffer pointer.
@param AllocSize The size of the pool to be allocated.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
@retval EFI_SUCCESS Success.
**/
)
{
//
// allocate unit is 32 byte (align on 32 byte)
//
if ((AllocSize & 0x1F) != 0) {
} else {
}
RealAllocSize / 32
);
return EFI_SUCCESS;
}
}
//
// There is no enough memory,
// Create a new Memory Block
//
//
// if pool size is larger than NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES,
// just allocate a large enough memory block.
//
} else {
}
return Status;
}
//
// Link the new Memory Block to the Memory Header list
//
RealAllocSize / 32
);
return Status;
}
/**
Alloc Memory In MemoryBlock.
@param MemoryHeader The pointer to memory manage header.
@param Pool Buffer pointer to store the buffer pointer.
@param NumberOfMemoryUnit The size of the pool to be allocated.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
@retval EFI_SUCCESS Success.
**/
)
{
FoundBytePos = 0;
FoundBitPos = 0;
NumberOfZeros = 0;
Index = 0;
//
// Pop out BitValue from a byte in TempBytePos.
//
if (BitValue == 0) {
//
// Found a free bit, the NumberOfZeros only record the number of those consecutive zeros
//
//
// Found enough consecutive free space, break the loop
//
if (NumberOfZeros >= NumberOfMemoryUnit) {
break;
}
} else {
//
// Encountering a '1', meant the bit is ocupied.
//
if (NumberOfZeros >= NumberOfMemoryUnit) {
//
// Found enough consecutive free space,break the loop
//
break;
} else {
//
// the NumberOfZeros only record the number of those consecutive zeros,
// so reset the NumberOfZeros to 0 when encountering '1' before finding
// enough consecutive '0's
//
NumberOfZeros = 0;
//
// reset the (FoundBytePos,FoundBitPos) to the position of '1'
//
FoundBitPos = Index;
}
}
//
// right shift the byte
//
ByteValue /= 2;
//
// step forward a bit
//
Index++;
if (Index == 8) {
//
// step forward a byte, getting the byte value,
// and reset the bit pos.
//
TempBytePos += 1;
Index = 0;
}
}
if (NumberOfZeros < NumberOfMemoryUnit) {
return EFI_NOT_FOUND;
}
//
// Found enough free space.
//
//
// The values recorded in (FoundBytePos,FoundBitPos) have two conditions:
// 1)(FoundBytePos,FoundBitPos) record the position
// of the last '1' before the consecutive '0's, it must
// be adjusted to the start position of the consecutive '0's.
// 2)the start address of the consecutive '0's is just the start of
// the bitarray. so no need to adjust the values of (FoundBytePos,FoundBitPos).
//
FoundBitPos += 1;
}
//
// Have the (FoundBytePos,FoundBitPos) make sense.
//
if (FoundBitPos > 7) {
FoundBytePos += 1;
FoundBitPos -= 8;
}
//
// Set the memory as allocated
//
for (TempBytePos = FoundBytePos, Index = FoundBitPos, Count = 0; Count < NumberOfMemoryUnit; Count++) {
MemoryHeader->BitArrayPtr[TempBytePos] = (UINT8) (MemoryHeader->BitArrayPtr[TempBytePos] | (1 << Index));
Index++;
if (Index == 8) {
TempBytePos += 1;
Index = 0;
}
}
return EFI_SUCCESS;
}
/**
Uhci Free Pool.
@param UhcDev The UHCI device.
@param Pool A pointer to store the buffer address.
@param AllocSize The size of the pool to be freed.
**/
)
{
//
// allocate unit is 32 byte (align on 32 byte)
//
if ((AllocSize & 0x1F) != 0) {
} else {
}
//
// Pool is in the Memory Block area,
// find the start byte and bit in the bit array
//
//
// reset associated bits in bit arry
//
for (Index = StartBytePos, Index2 = StartBitPos, Count = 0; Count < (RealAllocSize / 32); Count++) {
Index2++;
if (Index2 == 8) {
Index += 1;
Index2 = 0;
}
}
//
// break the loop
//
break;
}
}
}
/**
Insert a new memory header into list.
@param MemoryHeader A pointer to the memory header list.
@param NewMemoryHeader A new memory header to be inserted into the list.
**/
)
{
break;
}
}
}
/**
Judge the memory block in the memory header is empty or not.
@param MemoryHeaderPtr A pointer to the memory header list.
@retval Whether the memory block in the memory header is empty or not.
**/
)
{
return FALSE;
}
}
return TRUE;
}
/**
remove a memory header from list.
@param FirstMemoryHeader A pointer to the memory header list.
@param FreeMemoryHeader A memory header to be removed into the list.
**/
)
{
return ;
}
for (TempHeaderPtr = FirstMemoryHeader; TempHeaderPtr != NULL; TempHeaderPtr = TempHeaderPtr->Next) {
//
// Link the before and after
//
break;
}
}
}