PeiUsbLib.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Common Libarary for PEI USB
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 "UsbPeim.h"
#include "PeiUsbLib.h"
/**
Get a given usb descriptor.
@param PeiServices General-purpose services that are available to every PEIM.
@param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
@param Value Request Value.
@param Index Request Index.
@param DescriptorLength Request descriptor Length.
@param Descriptor Request descriptor.
@retval EFI_SUCCESS Usb descriptor is obtained successfully.
@retval EFI_DEVICE_ERROR Cannot get the usb descriptor due to a hardware error.
@retval Others Other failure occurs.
**/
)
{
return UsbIoPpi->UsbControlTransfer (
&DevReq,
);
}
/**
Set a usb device with a specified address.
@param PeiServices General-purpose services that are available to every PEIM.
@param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
@param AddressValue The address to assign.
@retval EFI_SUCCESS Usb device address is set successfully.
@retval EFI_DEVICE_ERROR Cannot set the usb address due to a hardware error.
@retval Others Other failure occurs.
**/
)
{
return UsbIoPpi->UsbControlTransfer (
&DevReq,
NULL,
0
);
}
/**
Clear a given usb feature.
@param PeiServices General-purpose services that are available to every PEIM.
@param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
@param Value Request Value.
@param Target Request Index.
@retval EFI_SUCCESS Usb feature is cleared successfully.
@retval EFI_DEVICE_ERROR Cannot clear the usb feature due to a hardware error.
@retval Others Other failure occurs.
**/
)
{
switch (Recipient) {
case EfiUsbDevice:
break;
case EfiUsbInterface:
break;
case EfiUsbEndpoint:
break;
}
return UsbIoPpi->UsbControlTransfer (
&DevReq,
NULL,
0
);
}
/**
Configure a usb device to Configuration 1.
@param PeiServices General-purpose services that are available to every PEIM.
@param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
@retval EFI_SUCCESS Usb device is set to use Configuration 1 successfully.
@retval EFI_DEVICE_ERROR Cannot set the usb device due to a hardware error.
@retval Others Other failure occurs.
**/
)
{
return UsbIoPpi->UsbControlTransfer (
&DevReq,
NULL,
0
);
}
/**
Clear Endpoint Halt.
@param PeiServices General-purpose services that are available to every PEIM.
@param UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
@param EndpointAddress The endpoint address.
@retval EFI_SUCCESS Endpoint halt is cleared successfully.
@retval EFI_DEVICE_ERROR Cannot clear the endpoint halt status due to a hardware error.
@retval Others Other failure occurs.
**/
)
{
EndpointIndex = 0;
while (EndpointIndex < MAX_ENDPOINT) {
Status = UsbIoPpi->UsbGetEndpointDescriptor (PeiServices, UsbIoPpi, EndpointIndex, &EndpointDescriptor);
return EFI_INVALID_PARAMETER;
}
break;
}
}
if (EndpointIndex == MAX_ENDPOINT) {
return EFI_INVALID_PARAMETER;
}
);
//
// set data toggle to zero.
//
}
return Status;
}
/**
Judge if the port is connected with a usb device or not.
@param PortStatus The usb port status gotten.
@retval TRUE A usb device is connected with the port.
@retval FALSE No usb device is connected with the port.
**/
)
{
//
// return the bit 0 value of PortStatus
//
if ((PortStatus & USB_PORT_STAT_CONNECTION) != 0) {
return TRUE;
} else {
return FALSE;
}
}
/**
Judge if the port is connected with a low-speed usb device or not.
@param PortStatus The usb port status gotten.
@retval TRUE A low-speed usb device is connected with the port.
@retval FALSE No low-speed usb device is connected with the port.
**/
)
{
//
// return the bit 9 value of PortStatus
//
if ((PortStatus & USB_PORT_STAT_LOW_SPEED) != 0) {
return EFI_USB_SPEED_LOW;
} else if ((PortStatus & USB_PORT_STAT_HIGH_SPEED) != 0){
return EFI_USB_SPEED_HIGH;
} else {
return EFI_USB_SPEED_FULL;
}
}
/**
Judge if the port is in "connection change" status or not.
@param PortChangeStatus The usb port change status gotten.
@retval TRUE The port is in "connection change" status.
@retval FALSE The port is NOT in "connection change" status.
**/
)
{
//
// return the bit 0 value of PortChangeStatus
//
if ((PortChangeStatus & USB_PORT_STAT_C_CONNECTION) != 0) {
return TRUE;
} else {
return FALSE;
}
}