/** @file
The module to produce Usb Bus PPI.
Copyright (c) 2006 - 2011, 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 "UsbPeim.h"
#include "HubPeim.h"
#include "PeiUsbLib.h"
//
// UsbIo PPI interface function
//
};
};
/**
The enumeration routine to detect device change.
@param PeiServices Describes the list of possible PEI Services.
@param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@retval EFI_SUCCESS The usb is enumerated successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
);
/**
Configure new detected usb device.
@param PeiServices Describes the list of possible PEI Services.
@param PeiUsbDevice The pointer of PEI_USB_DEVICE instance.
@param Port The port to be configured.
@param DeviceAddress The device address to be configured.
@retval EFI_SUCCESS The new detected usb device is configured successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
);
/**
Get all configurations from a detected usb device.
@param PeiServices Describes the list of possible PEI Services.
@param PeiUsbDevice The pointer of PEI_USB_DEVICE instance.
@retval EFI_SUCCESS The new detected usb device is configured successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
);
/**
Get the start position of next wanted descriptor.
@param Buffer Buffer containing data to parse.
@param Length Buffer length.
@param DescType Descriptor type.
@param DescLength Descriptor length.
@param ParsedBytes Bytes has been parsed.
@retval EFI_SUCCESS Get wanted descriptor successfully.
@retval EFI_DEVICE_ERROR Error occurred.
**/
);
/**
The entrypoint of the module, it will enumerate all HCs.
@param FileHandle Handle of the file being invoked.
@param PeiServices Describes the list of possible PEI Services.
@retval EFI_SUCCESS Usb initialization is done successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval EFI_UNSUPPORTED Can't find required PPI.
**/
)
{
return EFI_SUCCESS;
}
//
// gPeiUsbHostControllerPpiGuid and gPeiUsb2HostControllerPpiGuid should not
// be produced at the same time
//
Index = 0;
while (TRUE) {
//
// Get UsbHcPpi at first.
//
NULL,
);
//
// No more host controller, break out
//
break;
}
Index++;
}
if (Index == 0) {
//
// Then try to get Usb2HcPpi.
//
while (TRUE) {
NULL,
);
//
// No more host controller, break out
//
break;
}
Index++;
}
}
if (Index == 0) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
/**
The Hub Enumeration just scans the hub ports one time. It also
doesn't support hot-plug.
@param PeiServices Describes the list of possible PEI Services.
@param PeiUsbDevice The pointer of PEI_USB_DEVICE instance.
@param CurrentAddress The DeviceAddress of usb device.
@retval EFI_SUCCESS The usb hub is enumerated successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
)
{
(UINT32 *) &PortStatus
);
continue;
}
);
(UINT32 *) &PortStatus
);
//
// Begin to deal with the new device
//
);
return EFI_OUT_OF_RESOURCES;
}
NewPeiUsbDevice->DeviceAddress = 0;
NewPeiUsbDevice->DataToggle = 0;
CopyMem (
&(NewPeiUsbDevice->UsbIoPpi),
sizeof (PEI_USB_IO_PPI)
);
CopyMem (
sizeof (EFI_PEI_PPI_DESCRIPTOR)
);
(UINT32 *) &PortStatus
);
} else {
CopyMem(&(NewPeiUsbDevice->Translator), &(PeiUsbDevice->Translator), sizeof(EFI_USB2_HC_TRANSACTION_TRANSLATOR));
}
}
//
// Configure that Usb Device
//
);
continue;
}
return Status;
}
}
}
}
}
return EFI_SUCCESS;
}
/**
The enumeration routine to detect device change.
@param PeiServices Describes the list of possible PEI Services.
@param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@retval EFI_SUCCESS The usb is enumerated successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
)
{
CurrentAddress = 0;
(UINT8 *) &NumOfRootPort
);
(UINT8 *) &NumOfRootPort
);
} else {
return EFI_INVALID_PARAMETER;
}
//
// First get root port status to detect changes happen
//
);
} else {
);
}
DEBUG ((EFI_D_INFO, "USB Status --- ConnectChange[%04x] Status[%04x]\n", PortStatus.PortChangeStatus, PortStatus.PortStatus));
//
// Changes happen, first clear this change status
//
);
} else {
);
}
);
} else {
);
}
//
// Connect change happen
//
);
return EFI_OUT_OF_RESOURCES;
}
PeiUsbDevice->DeviceAddress = 0;
PeiUsbDevice->DataToggle = 0;
CopyMem (
&(PeiUsbDevice->UsbIoPpi),
sizeof (PEI_USB_IO_PPI)
);
CopyMem (
&(PeiUsbDevice->UsbIoPpiList),
sizeof (EFI_PEI_PPI_DESCRIPTOR)
);
0
);
);
} else {
);
}
//
// Configure that Usb Device
//
);
continue;
}
return Status;
}
}
} else {
//
// Disconnect change happen, currently we don't support
//
}
}
}
return EFI_SUCCESS;
}
/**
Configure new detected usb device.
@param PeiServices Describes the list of possible PEI Services.
@param PeiUsbDevice The pointer of PEI_USB_DEVICE instance.
@param Port The port to be configured.
@param DeviceAddress The device address to be configured.
@retval EFI_SUCCESS The new detected usb device is configured successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
)
{
//
// Get USB device descriptor
//
(USB_DT_DEVICE << 8),
0,
8,
);
break;
}
}
if (Retry == 3) {
return Status;
}
(*DeviceAddress) ++;
);
return Status;
}
//
// Get whole USB device descriptor
//
(USB_DT_DEVICE << 8),
0,
(UINT16) sizeof (EFI_USB_DEVICE_DESCRIPTOR),
);
return Status;
}
//
// Get its default configuration and its first interface
//
);
return Status;
}
);
return Status;
}
return EFI_SUCCESS;
}
/**
Get all configurations from a detected usb device.
@param PeiServices Describes the list of possible PEI Services.
@param PeiUsbDevice The pointer of PEI_USB_DEVICE instance.
@retval EFI_SUCCESS The new detected usb device is configured successfully.
@retval EFI_OUT_OF_RESOURCES Can't allocate memory resource.
@retval Others Other failure occurs.
**/
)
{
//
// First get its 4-byte configuration descriptor
//
0, // Index
4, // Length
);
return Status;
}
//
// Then we get the total descriptors for this configuration
//
(USB_DT_CONFIG << 8),
0,
);
return Status;
}
//
// Parse this configuration descriptor
// First get the current config descriptor;
//
(UINT8) sizeof (EFI_USB_CONFIG_DESCRIPTOR),
);
return Status;
}
Ptr += sizeof (EFI_USB_CONFIG_DESCRIPTOR);
//
// Get the first interface descriptor
//
Ptr,
(UINT8) sizeof (EFI_USB_INTERFACE_DESCRIPTOR),
);
return Status;
}
Ptr += sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
LengthLeft -= SkipBytes;
LengthLeft -= sizeof (EFI_USB_INTERFACE_DESCRIPTOR);
//
// Parse all the endpoint descriptor within this interface
//
//
// Get the endpoint descriptor
//
Ptr,
(UINT8) sizeof (EFI_USB_ENDPOINT_DESCRIPTOR),
);
return Status;
}
Ptr += sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
LengthLeft -= SkipBytes;
LengthLeft -= sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
}
return EFI_SUCCESS;
}
/**
Get the start position of next wanted descriptor.
@param Buffer Buffer containing data to parse.
@param Length Buffer length.
@param DescType Descriptor type.
@param DescLength Descriptor length.
@param ParsedBytes Bytes has been parsed.
@retval EFI_SUCCESS Get wanted descriptor successfully.
@retval EFI_DEVICE_ERROR Error occurred.
**/
)
{
Parsed = 0;
while (TRUE) {
//
// Buffer length should not less than Desc length
//
if (Length < DescLength) {
return EFI_DEVICE_ERROR;
}
//
// Check to see if it is a start of expected descriptor
//
break;
}
if (Len > DescLength) {
return EFI_DEVICE_ERROR;
}
}
//
// Descriptor length should be at least 2
// and should not exceed the buffer length
//
if (Len < 2) {
return EFI_DEVICE_ERROR;
}
return EFI_DEVICE_ERROR;
}
//
// Skip this mismatch descriptor
//
}
*ParsedBytes = Parsed;
return EFI_SUCCESS;
}
/**
Send reset signal over the given root hub port.
@param PeiServices Describes the list of possible PEI Services.
@param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
@param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
@param PortNum The port to be reset.
@param RetryIndex The retry times.
**/
)
{
//
// reset root port
//
);
return;
}
//
// clear reset root port
//
);
return;
}
);
//
// Set port enable
//
);
);
} else {
//
// reset root port
//
);
return;
}
//
// clear reset root port
//
);
return;
}
);
//
// Set port enable
//
);
);
}
return;
}