2007-07-11 08:46:38 +02:00
|
|
|
/** @file
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
The UHCI driver model and HC protocol routines.
|
|
|
|
|
2012-10-30 05:23:40 +01:00
|
|
|
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-11 08:46:38 +02:00
|
|
|
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
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
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 "Uhci.h"
|
|
|
|
|
2008-12-03 09:52:39 +01:00
|
|
|
|
|
|
|
EFI_DRIVER_BINDING_PROTOCOL gUhciDriverBinding = {
|
|
|
|
UhciDriverBindingSupported,
|
|
|
|
UhciDriverBindingStart,
|
|
|
|
UhciDriverBindingStop,
|
|
|
|
0x20,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Provides software reset for the USB host controller according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param Attributes A bit mask of the reset operation to perform. See
|
|
|
|
below for a list of the supported bit mask values.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS The reset operation succeeded.
|
|
|
|
@return EFI_INVALID_PARAMETER Attributes is not valid.
|
|
|
|
@return EFI_UNSUPPORTED This type of reset is not currently supported.
|
|
|
|
@return EFI_DEVICE_ERROR Other errors.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2Reset (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT16 Attributes
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
if ((Attributes == EFI_USB_HC_RESET_GLOBAL_WITH_DEBUG) ||
|
|
|
|
(Attributes == EFI_USB_HC_RESET_HOST_WITH_DEBUG)) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2012-10-30 05:23:40 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
|
|
|
|
|
|
|
if (Uhc->DevicePath != NULL) {
|
|
|
|
//
|
|
|
|
// Report Status Code to indicate reset happens
|
|
|
|
//
|
|
|
|
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
|
|
|
|
EFI_PROGRESS_CODE,
|
|
|
|
(EFI_IO_BUS_USB | EFI_IOB_PC_RESET),
|
|
|
|
Uhc->DevicePath
|
|
|
|
);
|
|
|
|
}
|
2008-01-23 10:41:04 +01:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
|
|
|
|
switch (Attributes) {
|
|
|
|
case EFI_USB_HC_RESET_GLOBAL:
|
|
|
|
//
|
|
|
|
// Stop schedule and set the Global Reset bit in the command register
|
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT);
|
2007-07-11 08:46:38 +02:00
|
|
|
UhciSetRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_GRESET);
|
|
|
|
|
2007-10-08 08:14:13 +02:00
|
|
|
gBS->Stall (UHC_ROOT_PORT_RESET_STALL);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Clear the Global Reset bit to zero.
|
|
|
|
//
|
|
|
|
UhciClearRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_GRESET);
|
|
|
|
|
2007-10-08 08:14:13 +02:00
|
|
|
gBS->Stall (UHC_ROOT_PORT_RECOVERY_STALL);
|
2007-07-11 08:46:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EFI_USB_HC_RESET_HOST_CONTROLLER:
|
|
|
|
//
|
|
|
|
// Stop schedule and set Host Controller Reset bit to 1
|
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT);
|
2007-07-11 08:46:38 +02:00
|
|
|
UhciSetRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_HCRESET);
|
|
|
|
|
2007-10-08 08:14:13 +02:00
|
|
|
gBS->Stall (UHC_ROOT_PORT_RECOVERY_STALL);
|
2007-07-11 08:46:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto ON_INVAILD_PARAMETER;
|
|
|
|
}
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// Delete all old transactions on the USB bus, then
|
|
|
|
// reinitialize the frame list
|
|
|
|
//
|
|
|
|
UhciFreeAllAsyncReq (Uhc);
|
|
|
|
UhciDestoryFrameList (Uhc);
|
|
|
|
UhciInitFrameList (Uhc);
|
|
|
|
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
ON_INVAILD_PARAMETER:
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
gBS->RestoreTPL (OldTpl);
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Retrieves current state of the USB host controller according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param State Variable to receive current device state.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS The state is returned.
|
|
|
|
@return EFI_INVALID_PARAMETER State is not valid.
|
|
|
|
@return EFI_DEVICE_ERROR Other errors.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2GetState (
|
2011-08-24 11:38:10 +02:00
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
OUT EFI_USB_HC_STATE *State
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
UINT16 UsbSts;
|
|
|
|
UINT16 UsbCmd;
|
|
|
|
|
|
|
|
if (State == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
UsbCmd = UhciReadReg (Uhc->PciIo, USBCMD_OFFSET);
|
|
|
|
UsbSts = UhciReadReg (Uhc->PciIo, USBSTS_OFFSET);
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((UsbCmd & USBCMD_EGSM) !=0 ) {
|
2007-07-11 08:46:38 +02:00
|
|
|
*State = EfiUsbHcStateSuspend;
|
|
|
|
|
|
|
|
} else if ((UsbSts & USBSTS_HCH) != 0) {
|
|
|
|
*State = EfiUsbHcStateHalt;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
*State = EfiUsbHcStateOperational;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Sets the USB host controller to a specific state according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param State Indicates the state of the host controller that will
|
|
|
|
be set.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS Host controller was successfully placed in the state.
|
|
|
|
@return EFI_INVALID_PARAMETER State is invalid.
|
|
|
|
@return EFI_DEVICE_ERROR Failed to set the state.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2SetState (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
2007-07-11 08:46:38 +02:00
|
|
|
IN EFI_USB_HC_STATE State
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_USB_HC_STATE CurState;
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT16 UsbCmd;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
|
|
|
Status = Uhci2GetState (This, &CurState);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurState == State) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
|
|
|
|
switch (State) {
|
|
|
|
case EfiUsbHcStateHalt:
|
2007-10-08 08:14:13 +02:00
|
|
|
Status = UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT);
|
2007-07-11 08:46:38 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbHcStateOperational:
|
|
|
|
UsbCmd = UhciReadReg (Uhc->PciIo, USBCMD_OFFSET);
|
|
|
|
|
|
|
|
if (CurState == EfiUsbHcStateHalt) {
|
|
|
|
//
|
|
|
|
// Set Run/Stop bit to 1, also set the bandwidht reclamation
|
|
|
|
// point to 64 bytes
|
|
|
|
//
|
|
|
|
UsbCmd |= USBCMD_RS | USBCMD_MAXP;
|
|
|
|
UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, UsbCmd);
|
|
|
|
|
|
|
|
} else if (CurState == EfiUsbHcStateSuspend) {
|
|
|
|
//
|
|
|
|
// If FGR(Force Global Resume) bit is 0, set it
|
|
|
|
//
|
|
|
|
if ((UsbCmd & USBCMD_FGR) == 0) {
|
|
|
|
UsbCmd |= USBCMD_FGR;
|
|
|
|
UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, UsbCmd);
|
|
|
|
}
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// wait 20ms to let resume complete (20ms is specified by UHCI spec)
|
|
|
|
//
|
2007-10-08 08:14:13 +02:00
|
|
|
gBS->Stall (UHC_FORCE_GLOBAL_RESUME_STALL);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Write FGR bit to 0 and EGSM(Enter Global Suspend Mode) bit to 0
|
|
|
|
//
|
|
|
|
UsbCmd &= ~USBCMD_FGR;
|
|
|
|
UsbCmd &= ~USBCMD_EGSM;
|
|
|
|
UsbCmd |= USBCMD_RS;
|
|
|
|
UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, UsbCmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbHcStateSuspend:
|
2008-01-23 10:41:04 +01:00
|
|
|
Status = Uhci2SetState (This, EfiUsbHcStateHalt);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// Set Enter Global Suspend Mode bit to 1.
|
|
|
|
//
|
|
|
|
UsbCmd = UhciReadReg (Uhc->PciIo, USBCMD_OFFSET);
|
|
|
|
UsbCmd |= USBCMD_EGSM;
|
|
|
|
UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, UsbCmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Retrieves capabilities of USB host controller according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param MaxSpeed A pointer to the max speed USB host controller
|
|
|
|
supports.
|
|
|
|
@param PortNumber A pointer to the number of root hub ports.
|
|
|
|
@param Is64BitCapable A pointer to an integer to show whether USB host
|
|
|
|
controller supports 64-bit memory addressing.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS capabilities were retrieved successfully.
|
|
|
|
@return EFI_INVALID_PARAMETER MaxSpeed or PortNumber or Is64BitCapable is NULL.
|
|
|
|
@return EFI_DEVICE_ERROR An error was encountered.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2GetCapability (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
OUT UINT8 *MaxSpeed,
|
|
|
|
OUT UINT8 *PortNumber,
|
|
|
|
OUT UINT8 *Is64BitCapable
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
UINT32 Offset;
|
|
|
|
UINT16 PortSC;
|
|
|
|
UINT32 Index;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
if ((NULL == MaxSpeed) || (NULL == PortNumber) || (NULL == Is64BitCapable)) {
|
2007-07-11 08:46:38 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
*MaxSpeed = EFI_USB_SPEED_FULL;
|
|
|
|
*Is64BitCapable = (UINT8) FALSE;
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
*PortNumber = 0;
|
|
|
|
|
|
|
|
for (Index = 0; Index < USB_MAX_ROOTHUB_PORT; Index++) {
|
|
|
|
Offset = USBPORTSC_OFFSET + Index * 2;
|
|
|
|
PortSC = UhciReadReg (Uhc->PciIo, Offset);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Port status's bit 7 is reserved and always returns 1 if
|
|
|
|
// the port number is valid. Intel's UHCI (in EHCI controller)
|
|
|
|
// returns 0 in this bit if port number is invalid. Also, if
|
|
|
|
// PciIo IoRead returns error, 0xFFFF is returned to caller.
|
|
|
|
//
|
2008-06-25 07:50:41 +02:00
|
|
|
if (((PortSC & 0x80) == 0) || (PortSC == 0xFFFF)) {
|
|
|
|
break;
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
2008-06-25 07:50:41 +02:00
|
|
|
(*PortNumber)++;
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Uhc->RootPorts = *PortNumber;
|
|
|
|
|
2008-12-18 09:48:36 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "Uhci2GetCapability: %d ports\n", (UINT32)Uhc->RootPorts));
|
2007-07-11 08:46:38 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Retrieves the current status of a USB root hub port according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL.
|
|
|
|
@param PortNumber The port to get status.
|
|
|
|
@param PortStatus A pointer to the current port status bits and port
|
|
|
|
status change bits.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS status of the USB root hub port was returned in PortStatus.
|
|
|
|
@return EFI_INVALID_PARAMETER PortNumber is invalid.
|
|
|
|
@return EFI_DEVICE_ERROR Can't read register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2GetRootHubPortStatus (
|
2011-08-24 11:38:10 +02:00
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 PortNumber,
|
|
|
|
OUT EFI_USB_PORT_STATUS *PortStatus
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
UINT32 Offset;
|
|
|
|
UINT16 PortSC;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (PortStatus == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PortNumber >= Uhc->RootPorts) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Offset = USBPORTSC_OFFSET + PortNumber * 2;
|
|
|
|
PortStatus->PortStatus = 0;
|
|
|
|
PortStatus->PortChangeStatus = 0;
|
|
|
|
|
|
|
|
PortSC = UhciReadReg (Uhc->PciIo, Offset);
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_CCS) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortStatus |= USB_PORT_STAT_CONNECTION;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_PED) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortStatus |= USB_PORT_STAT_ENABLE;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_SUSP) != 0) {
|
2008-02-13 10:08:24 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "Uhci2GetRootHubPortStatus: port %d is suspended\n", PortNumber));
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortStatus |= USB_PORT_STAT_SUSPEND;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_PR) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortStatus |= USB_PORT_STAT_RESET;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_LSDA) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CHC will always return one in port owner bit
|
|
|
|
//
|
|
|
|
PortStatus->PortStatus |= USB_PORT_STAT_OWNER;
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_CSC) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortChangeStatus |= USB_PORT_STAT_C_CONNECTION;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((PortSC & USBPORTSC_PEDC) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
PortStatus->PortChangeStatus |= USB_PORT_STAT_C_ENABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Sets a feature for the specified root hub port according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL.
|
|
|
|
@param PortNumber Specifies the root hub port whose feature is
|
|
|
|
requested to be set.
|
|
|
|
@param PortFeature Indicates the feature selector associated with the
|
|
|
|
feature set request.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS PortFeature was set for the root port.
|
|
|
|
@return EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
|
|
|
|
@return EFI_DEVICE_ERROR Can't read register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2SetRootHubPortFeature (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 PortNumber,
|
|
|
|
IN EFI_USB_PORT_FEATURE PortFeature
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
UINT32 Offset;
|
|
|
|
UINT16 PortSC;
|
|
|
|
UINT16 Command;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (PortNumber >= Uhc->RootPorts) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Offset = USBPORTSC_OFFSET + PortNumber * 2;
|
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
PortSC = UhciReadReg (Uhc->PciIo, Offset);
|
|
|
|
|
|
|
|
switch (PortFeature) {
|
|
|
|
case EfiUsbPortSuspend:
|
|
|
|
Command = UhciReadReg (Uhc->PciIo, USBCMD_OFFSET);
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((Command & USBCMD_EGSM) == 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// if global suspend is not active, can set port suspend
|
|
|
|
//
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC |= USBPORTSC_SUSP;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortReset:
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC |= USBPORTSC_PR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortPower:
|
|
|
|
//
|
|
|
|
// No action
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortEnable:
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC |= USBPORTSC_PED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
UhciWriteReg (Uhc->PciIo, Offset, PortSC);
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Clears a feature for the specified root hub port according to Uefi 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@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.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS PortFeature was cleared for the USB root hub port.
|
|
|
|
@return EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
|
|
|
|
@return EFI_DEVICE_ERROR Can't read register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2ClearRootHubPortFeature (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 PortNumber,
|
|
|
|
IN EFI_USB_PORT_FEATURE PortFeature
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
UINT32 Offset;
|
|
|
|
UINT16 PortSC;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (PortNumber >= Uhc->RootPorts) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
Offset = USBPORTSC_OFFSET + PortNumber * 2;
|
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
PortSC = UhciReadReg (Uhc->PciIo, Offset);
|
|
|
|
|
|
|
|
switch (PortFeature) {
|
|
|
|
case EfiUsbPortEnable:
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC &= ~USBPORTSC_PED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortSuspend:
|
|
|
|
//
|
|
|
|
// Cause a resume on the specified port if in suspend mode.
|
|
|
|
//
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC &= ~USBPORTSC_SUSP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortPower:
|
|
|
|
//
|
|
|
|
// No action
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortReset:
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC &= ~USBPORTSC_PR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortConnectChange:
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC |= USBPORTSC_CSC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortEnableChange:
|
|
|
|
PortSC &= 0xfff5;
|
|
|
|
PortSC |= USBPORTSC_PEDC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortSuspendChange:
|
|
|
|
//
|
|
|
|
// Root hub does not support this
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortOverCurrentChange:
|
|
|
|
//
|
|
|
|
// Root hub does not support this
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiUsbPortResetChange:
|
|
|
|
//
|
|
|
|
// Root hub does not support this
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
UhciWriteReg (Uhc->PciIo, Offset, PortSC);
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Submits control transfer to a target USB device accroding to UEFI 2.0 spec.
|
|
|
|
|
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param DeviceAddress Target device address.
|
|
|
|
@param DeviceSpeed Device speed.
|
|
|
|
@param MaximumPacketLength Maximum packet size of the target endpoint.
|
|
|
|
@param Request USB device request to send.
|
|
|
|
@param TransferDirection Data direction of the Data stage in control transfer.
|
|
|
|
@param Data Data to transmit/receive in data stage.
|
|
|
|
@param DataLength Length of the data.
|
|
|
|
@param TimeOut Maximum time, in microseconds, for transfer to complete.
|
|
|
|
@param Translator Transaction translator to be used by this device.
|
|
|
|
@param TransferResult Variable to receive the transfer result.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS The control transfer was completed successfully.
|
|
|
|
@return EFI_OUT_OF_RESOURCES Failed due to lack of resource.
|
|
|
|
@return EFI_INVALID_PARAMETER Some parameters are invalid.
|
|
|
|
@return EFI_TIMEOUT Failed due to timeout.
|
|
|
|
@return EFI_DEVICE_ERROR Failed due to host controller or device error.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2ControlTransfer (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 DeviceAddress,
|
|
|
|
IN UINT8 DeviceSpeed,
|
|
|
|
IN UINTN MaximumPacketLength,
|
|
|
|
IN EFI_USB_DEVICE_REQUEST *Request,
|
|
|
|
IN EFI_USB_DATA_DIRECTION TransferDirection,
|
|
|
|
IN OUT VOID *Data,
|
|
|
|
IN OUT UINTN *DataLength,
|
|
|
|
IN UINTN TimeOut,
|
|
|
|
IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
|
|
|
|
OUT UINT32 *TransferResult
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
UHCI_TD_SW *TDs;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UHCI_QH_RESULT QhResult;
|
|
|
|
UINT8 PktId;
|
|
|
|
UINT8 *RequestPhy;
|
|
|
|
VOID *RequestMap;
|
|
|
|
UINT8 *DataPhy;
|
|
|
|
VOID *DataMap;
|
2008-01-23 10:41:04 +01:00
|
|
|
BOOLEAN IsSlowDevice;
|
2009-02-02 06:50:45 +01:00
|
|
|
UINTN TransferDataLength;
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
TDs = NULL;
|
|
|
|
DataPhy = NULL;
|
|
|
|
DataMap = NULL;
|
|
|
|
RequestPhy = NULL;
|
|
|
|
RequestMap = NULL;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE);
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// Parameters Checking
|
|
|
|
//
|
|
|
|
if (Request == NULL || TransferResult == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSlowDevice && (MaximumPacketLength != 8)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((MaximumPacketLength != 8) && (MaximumPacketLength != 16) &&
|
|
|
|
(MaximumPacketLength != 32) && (MaximumPacketLength != 64)) {
|
|
|
|
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2009-02-02 06:50:45 +01:00
|
|
|
if ((TransferDirection != EfiUsbNoData) && (Data == NULL || DataLength == NULL)) {
|
2007-07-11 08:46:38 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2009-02-02 06:50:45 +01:00
|
|
|
if (TransferDirection == EfiUsbNoData) {
|
|
|
|
TransferDataLength = 0;
|
|
|
|
} else {
|
|
|
|
TransferDataLength = *DataLength;
|
|
|
|
}
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
*TransferResult = EFI_USB_ERR_SYSTEM;
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If errors exist that cause host controller halt,
|
|
|
|
// clear status then return EFI_DEVICE_ERROR.
|
|
|
|
//
|
|
|
|
UhciAckAllInterrupt (Uhc);
|
|
|
|
|
|
|
|
if (!UhciIsHcWorking (Uhc->PciIo)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Map the Request and data for bus master access,
|
|
|
|
// then create a list of TD for this transfer
|
|
|
|
//
|
|
|
|
Status = UhciMapUserRequest (Uhc, Request, &RequestPhy, &RequestMap);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = UhciMapUserData (Uhc, TransferDirection, Data, DataLength, &PktId, &DataPhy, &DataMap);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, RequestMap);
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
TDs = UhciCreateCtrlTds (
|
|
|
|
Uhc,
|
|
|
|
DeviceAddress,
|
|
|
|
PktId,
|
2009-09-14 07:26:09 +02:00
|
|
|
(UINT8*)Request,
|
2007-07-11 08:46:38 +02:00
|
|
|
RequestPhy,
|
2009-09-14 07:26:09 +02:00
|
|
|
(UINT8*)Data,
|
2007-07-11 08:46:38 +02:00
|
|
|
DataPhy,
|
2009-02-02 06:50:45 +01:00
|
|
|
TransferDataLength,
|
2008-01-23 10:41:04 +01:00
|
|
|
(UINT8) MaximumPacketLength,
|
2007-07-11 08:46:38 +02:00
|
|
|
IsSlowDevice
|
|
|
|
);
|
|
|
|
|
|
|
|
if (TDs == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto UNMAP_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// According to the speed of the end point, link
|
|
|
|
// the TD to corrosponding queue head, then check
|
|
|
|
// the execution result
|
|
|
|
//
|
2009-09-14 07:26:09 +02:00
|
|
|
UhciLinkTdToQh (Uhc, Uhc->CtrlQh, TDs);
|
2007-07-11 08:46:38 +02:00
|
|
|
Status = UhciExecuteTransfer (Uhc, Uhc->CtrlQh, TDs, TimeOut, IsSlowDevice, &QhResult);
|
|
|
|
UhciUnlinkTdFromQh (Uhc->CtrlQh, TDs);
|
|
|
|
|
|
|
|
Uhc->PciIo->Flush (Uhc->PciIo);
|
|
|
|
|
|
|
|
*TransferResult = QhResult.Result;
|
|
|
|
|
|
|
|
if (DataLength != NULL) {
|
|
|
|
*DataLength = QhResult.Complete;
|
|
|
|
}
|
|
|
|
|
|
|
|
UhciDestoryTds (Uhc, TDs);
|
|
|
|
|
|
|
|
UNMAP_DATA:
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, RequestMap);
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Submits bulk transfer to a bulk endpoint of a USB device.
|
|
|
|
|
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param DeviceAddress Target device address.
|
|
|
|
@param EndPointAddress Endpoint number and direction.
|
|
|
|
@param DeviceSpeed Device speed.
|
|
|
|
@param MaximumPacketLength Maximum packet size of the target endpoint.
|
|
|
|
@param DataBuffersNumber Number of data buffers prepared for the transfer.
|
|
|
|
@param Data Array of pointers to the buffers of data.
|
|
|
|
@param DataLength On input, size of the data buffer, On output,
|
|
|
|
actually transferred data size.
|
|
|
|
@param DataToggle On input, data toggle to use; On output, next data toggle.
|
|
|
|
@param TimeOut Maximum time out, in microseconds.
|
|
|
|
@param Translator A pointr to the transaction translator data.
|
|
|
|
@param TransferResult Variable to receive transfer result.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS The bulk transfer was completed successfully.
|
|
|
|
@return EFI_OUT_OF_RESOURCES Failed due to lack of resource.
|
|
|
|
@return EFI_INVALID_PARAMETER Some parameters are invalid.
|
|
|
|
@return EFI_TIMEOUT Failed due to timeout.
|
|
|
|
@return EFI_DEVICE_ERROR Failed due to host controller or device error.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2BulkTransfer (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 DeviceAddress,
|
|
|
|
IN UINT8 EndPointAddress,
|
|
|
|
IN UINT8 DeviceSpeed,
|
|
|
|
IN UINTN MaximumPacketLength,
|
|
|
|
IN UINT8 DataBuffersNumber,
|
|
|
|
IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
|
|
|
|
IN OUT UINTN *DataLength,
|
|
|
|
IN OUT UINT8 *DataToggle,
|
|
|
|
IN UINTN TimeOut,
|
|
|
|
IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
|
|
|
|
OUT UINT32 *TransferResult
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_USB_DATA_DIRECTION Direction;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
UHCI_TD_SW *TDs;
|
|
|
|
UHCI_QH_SW *BulkQh;
|
|
|
|
UHCI_QH_RESULT QhResult;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT8 PktId;
|
|
|
|
UINT8 *DataPhy;
|
|
|
|
VOID *DataMap;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
DataPhy = NULL;
|
|
|
|
DataMap = NULL;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
if (DeviceSpeed == EFI_USB_SPEED_LOW) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((DataLength == NULL) || (*DataLength == 0) || (Data == NULL) || (TransferResult == NULL)) {
|
2007-07-11 08:46:38 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*DataToggle != 1) && (*DataToggle != 0)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((MaximumPacketLength != 8) && (MaximumPacketLength != 16) &&
|
|
|
|
(MaximumPacketLength != 32) && (MaximumPacketLength != 64)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*TransferResult = EFI_USB_ERR_SYSTEM;
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If has errors that cause host controller halt,
|
|
|
|
// then return EFI_DEVICE_ERROR directly.
|
|
|
|
//
|
|
|
|
UhciAckAllInterrupt (Uhc);
|
|
|
|
|
|
|
|
if (!UhciIsHcWorking (Uhc->PciIo)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Map the source data buffer for bus master access,
|
|
|
|
// then create a list of TDs
|
|
|
|
//
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((EndPointAddress & 0x80) != 0) {
|
2007-07-11 08:46:38 +02:00
|
|
|
Direction = EfiUsbDataIn;
|
|
|
|
} else {
|
|
|
|
Direction = EfiUsbDataOut;
|
|
|
|
}
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Status = UhciMapUserData (Uhc, Direction, *Data, DataLength, &PktId, &DataPhy, &DataMap);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
TDs = UhciCreateBulkOrIntTds (
|
|
|
|
Uhc,
|
|
|
|
DeviceAddress,
|
|
|
|
EndPointAddress,
|
|
|
|
PktId,
|
2009-09-14 07:26:09 +02:00
|
|
|
(UINT8 *)*Data,
|
2007-07-11 08:46:38 +02:00
|
|
|
DataPhy,
|
|
|
|
*DataLength,
|
|
|
|
DataToggle,
|
2008-01-23 10:41:04 +01:00
|
|
|
(UINT8) MaximumPacketLength,
|
2007-07-11 08:46:38 +02:00
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
|
|
|
|
if (TDs == NULL) {
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Link the TDs to bulk queue head. According to the platfore
|
|
|
|
// defintion of UHCI_NO_BW_RECLAMATION, BulkQh is either configured
|
|
|
|
// to do full speed bandwidth reclamation or not.
|
|
|
|
//
|
|
|
|
BulkQh = Uhc->BulkQh;
|
|
|
|
|
2009-09-14 07:26:09 +02:00
|
|
|
UhciLinkTdToQh (Uhc, BulkQh, TDs);
|
2007-07-11 08:46:38 +02:00
|
|
|
Status = UhciExecuteTransfer (Uhc, BulkQh, TDs, TimeOut, FALSE, &QhResult);
|
|
|
|
UhciUnlinkTdFromQh (BulkQh, TDs);
|
|
|
|
|
|
|
|
Uhc->PciIo->Flush (Uhc->PciIo);
|
|
|
|
|
|
|
|
*TransferResult = QhResult.Result;
|
|
|
|
*DataToggle = QhResult.NextToggle;
|
|
|
|
*DataLength = QhResult.Complete;
|
|
|
|
|
|
|
|
UhciDestoryTds (Uhc, TDs);
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Submits an asynchronous interrupt transfer to an
|
|
|
|
interrupt endpoint of a USB device according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param DeviceAddress Target device address.
|
|
|
|
@param EndPointAddress Endpoint number and direction.
|
|
|
|
@param DeviceSpeed Device speed.
|
|
|
|
@param MaximumPacketLength Maximum packet size of the target endpoint.
|
|
|
|
@param IsNewTransfer If TRUE, submit a new transfer, if FALSE cancel old transfer.
|
|
|
|
@param DataToggle On input, data toggle to use; On output, next data toggle.
|
|
|
|
@param PollingInterval Interrupt poll rate in milliseconds.
|
|
|
|
@param DataLength On input, size of the data buffer, On output,
|
|
|
|
actually transferred data size.
|
|
|
|
@param Translator A pointr to the transaction translator data.
|
|
|
|
@param CallBackFunction Function to call periodically.
|
|
|
|
@param Context User context.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS Transfer was submitted.
|
|
|
|
@return EFI_INVALID_PARAMETER Some parameters are invalid.
|
|
|
|
@return EFI_OUT_OF_RESOURCES Failed due to a lack of resources.
|
|
|
|
@return EFI_DEVICE_ERROR Can't read register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2AsyncInterruptTransfer (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
2007-07-11 08:46:38 +02:00
|
|
|
IN UINT8 DeviceAddress,
|
|
|
|
IN UINT8 EndPointAddress,
|
2008-01-23 10:41:04 +01:00
|
|
|
IN UINT8 DeviceSpeed,
|
|
|
|
IN UINTN MaximumPacketLength,
|
2007-07-11 08:46:38 +02:00
|
|
|
IN BOOLEAN IsNewTransfer,
|
|
|
|
IN OUT UINT8 *DataToggle,
|
2008-01-23 10:41:04 +01:00
|
|
|
IN UINTN PollingInterval,
|
|
|
|
IN UINTN DataLength,
|
|
|
|
IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
|
|
|
|
IN EFI_ASYNC_USB_TRANSFER_CALLBACK CallBackFunction,
|
|
|
|
IN VOID *Context
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
2008-01-23 10:41:04 +01:00
|
|
|
BOOLEAN IsSlowDevice;
|
2007-07-11 08:46:38 +02:00
|
|
|
UHCI_QH_SW *Qh;
|
|
|
|
UHCI_TD_SW *IntTds;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT8 *DataPtr;
|
|
|
|
UINT8 *DataPhy;
|
|
|
|
UINT8 PktId;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
Qh = NULL;
|
|
|
|
IntTds = NULL;
|
|
|
|
DataPtr = NULL;
|
|
|
|
DataPhy = NULL;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE);
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
if ((EndPointAddress & 0x80) == 0) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Delete Async interrupt transfer request
|
|
|
|
//
|
|
|
|
if (!IsNewTransfer) {
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
Status = UhciRemoveAsyncReq (Uhc, DeviceAddress, EndPointAddress, DataToggle);
|
|
|
|
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PollingInterval < 1 || PollingInterval > 255) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DataLength == 0) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*DataToggle != 1) && (*DataToggle != 0)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If has errors that cause host controller halt,
|
|
|
|
// then return EFI_DEVICE_ERROR directly.
|
|
|
|
//
|
|
|
|
UhciAckAllInterrupt (Uhc);
|
|
|
|
|
|
|
|
if (!UhciIsHcWorking (Uhc->PciIo)) {
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-03-19 07:54:35 +01:00
|
|
|
if ((EndPointAddress & 0x80) == 0) {
|
|
|
|
PktId = OUTPUT_PACKET_ID;
|
|
|
|
} else {
|
|
|
|
PktId = INPUT_PACKET_ID;
|
|
|
|
}
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// Allocate and map source data buffer for bus master access.
|
|
|
|
//
|
2010-03-19 07:54:35 +01:00
|
|
|
DataPtr = UsbHcAllocateMem (Uhc->MemPool, DataLength);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (DataPtr == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2010-03-20 07:49:56 +01:00
|
|
|
DataPhy = (UINT8 *) (UINTN) UsbHcGetPciAddressForHostMem (Uhc->MemPool, DataPtr, DataLength);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2010-03-19 07:54:35 +01:00
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
Qh = UhciCreateQh (Uhc, PollingInterval);
|
|
|
|
|
|
|
|
if (Qh == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2010-03-19 07:54:35 +01:00
|
|
|
goto FREE_DATA;
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IntTds = UhciCreateBulkOrIntTds (
|
|
|
|
Uhc,
|
|
|
|
DeviceAddress,
|
|
|
|
EndPointAddress,
|
|
|
|
PktId,
|
2009-09-14 07:26:09 +02:00
|
|
|
DataPtr,
|
2007-07-11 08:46:38 +02:00
|
|
|
DataPhy,
|
|
|
|
DataLength,
|
|
|
|
DataToggle,
|
2008-01-23 10:41:04 +01:00
|
|
|
(UINT8) MaximumPacketLength,
|
2007-07-11 08:46:38 +02:00
|
|
|
IsSlowDevice
|
|
|
|
);
|
|
|
|
|
|
|
|
if (IntTds == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto DESTORY_QH;
|
|
|
|
}
|
|
|
|
|
2009-09-14 07:26:09 +02:00
|
|
|
UhciLinkTdToQh (Uhc, Qh, IntTds);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Save QH-TD structures to async Interrupt transfer list,
|
|
|
|
// for monitor interrupt transfer execution routine use.
|
|
|
|
//
|
|
|
|
Status = UhciCreateAsyncReq (
|
|
|
|
Uhc,
|
|
|
|
Qh,
|
|
|
|
IntTds,
|
|
|
|
DeviceAddress,
|
|
|
|
EndPointAddress,
|
|
|
|
DataLength,
|
|
|
|
PollingInterval,
|
|
|
|
DataPtr,
|
|
|
|
CallBackFunction,
|
|
|
|
Context,
|
|
|
|
IsSlowDevice
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto DESTORY_QH;
|
|
|
|
}
|
|
|
|
|
2009-09-14 07:26:09 +02:00
|
|
|
UhciLinkQhToFrameList (Uhc, Qh);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
DESTORY_QH:
|
|
|
|
UsbHcFreeMem (Uhc->MemPool, Qh, sizeof (UHCI_QH_SW));
|
|
|
|
|
|
|
|
FREE_DATA:
|
2010-03-19 07:54:35 +01:00
|
|
|
UsbHcFreeMem (Uhc->MemPool, DataPtr, DataLength);
|
2007-07-11 08:46:38 +02:00
|
|
|
Uhc->PciIo->Flush (Uhc->PciIo);
|
|
|
|
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Submits synchronous interrupt transfer to an interrupt endpoint
|
|
|
|
of a USB device according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
|
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param DeviceAddress Target device address.
|
|
|
|
@param EndPointAddress Endpoint number and direction.
|
|
|
|
@param DeviceSpeed Device speed.
|
|
|
|
@param MaximumPacketLength Maximum packet size of the target endpoint.
|
|
|
|
@param Data Array of pointers to the buffers of data.
|
|
|
|
@param DataLength On input, size of the data buffer, On output,
|
|
|
|
actually transferred data size.
|
|
|
|
@param DataToggle On input, data toggle to use; On output, next data toggle.
|
|
|
|
@param TimeOut Maximum time out, in microseconds.
|
|
|
|
@param Translator A pointr to the transaction translator data.
|
|
|
|
@param TransferResult Variable to receive transfer result.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS The transfer was completed successfully.
|
|
|
|
@return EFI_OUT_OF_RESOURCES Failed due to lack of resource.
|
|
|
|
@return EFI_INVALID_PARAMETER Some parameters are invalid.
|
|
|
|
@return EFI_TIMEOUT Failed due to timeout.
|
|
|
|
@return EFI_DEVICE_ERROR Failed due to host controller or device error.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2SyncInterruptTransfer (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 DeviceAddress,
|
|
|
|
IN UINT8 EndPointAddress,
|
|
|
|
IN UINT8 DeviceSpeed,
|
|
|
|
IN UINTN MaximumPacketLength,
|
|
|
|
IN OUT VOID *Data,
|
|
|
|
IN OUT UINTN *DataLength,
|
|
|
|
IN OUT UINT8 *DataToggle,
|
|
|
|
IN UINTN TimeOut,
|
|
|
|
IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
|
|
|
|
OUT UINT32 *TransferResult
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
UHCI_TD_SW *TDs;
|
|
|
|
UHCI_QH_RESULT QhResult;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
UINT8 *DataPhy;
|
|
|
|
VOID *DataMap;
|
|
|
|
UINT8 PktId;
|
2008-01-23 10:41:04 +01:00
|
|
|
BOOLEAN IsSlowDevice;
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-07-11 08:46:38 +02:00
|
|
|
DataPhy = NULL;
|
|
|
|
DataMap = NULL;
|
|
|
|
TDs = NULL;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
if (DeviceSpeed == EFI_USB_SPEED_HIGH) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE);
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
if ((DataLength == NULL) || (Data == NULL) || (TransferResult == NULL)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((EndPointAddress & 0x80) == 0) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*DataToggle != 1) && (*DataToggle != 0)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*DataLength == 0) || (MaximumPacketLength > 64)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSlowDevice && (MaximumPacketLength > 8)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*TransferResult = EFI_USB_ERR_SYSTEM;
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
UhciAckAllInterrupt (Uhc);
|
|
|
|
|
|
|
|
if (!UhciIsHcWorking (Uhc->PciIo)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (UHCI_TPL);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Map the source data buffer for bus master access.
|
|
|
|
// Create Tds list, then link it to the UHC's interrupt list
|
|
|
|
//
|
|
|
|
Status = UhciMapUserData (
|
|
|
|
Uhc,
|
|
|
|
EfiUsbDataIn,
|
|
|
|
Data,
|
|
|
|
DataLength,
|
|
|
|
&PktId,
|
|
|
|
&DataPhy,
|
|
|
|
&DataMap
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
TDs = UhciCreateBulkOrIntTds (
|
|
|
|
Uhc,
|
|
|
|
DeviceAddress,
|
|
|
|
EndPointAddress,
|
|
|
|
PktId,
|
2009-09-14 07:26:09 +02:00
|
|
|
(UINT8 *)Data,
|
2007-07-11 08:46:38 +02:00
|
|
|
DataPhy,
|
|
|
|
*DataLength,
|
|
|
|
DataToggle,
|
2008-01-23 10:41:04 +01:00
|
|
|
(UINT8) MaximumPacketLength,
|
2007-07-11 08:46:38 +02:00
|
|
|
IsSlowDevice
|
|
|
|
);
|
|
|
|
|
|
|
|
if (TDs == NULL) {
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);
|
|
|
|
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-14 07:26:09 +02:00
|
|
|
UhciLinkTdToQh (Uhc, Uhc->SyncIntQh, TDs);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
Status = UhciExecuteTransfer (Uhc, Uhc->SyncIntQh, TDs, TimeOut, IsSlowDevice, &QhResult);
|
|
|
|
|
|
|
|
UhciUnlinkTdFromQh (Uhc->SyncIntQh, TDs);
|
|
|
|
Uhc->PciIo->Flush (Uhc->PciIo);
|
|
|
|
|
|
|
|
*TransferResult = QhResult.Result;
|
|
|
|
*DataToggle = QhResult.NextToggle;
|
|
|
|
*DataLength = QhResult.Complete;
|
|
|
|
|
|
|
|
UhciDestoryTds (Uhc, TDs);
|
|
|
|
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Submits isochronous transfer to a target USB device according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param DeviceAddress Target device address.
|
|
|
|
@param EndPointAddress Endpoint number and direction.
|
|
|
|
@param DeviceSpeed Device speed.
|
|
|
|
@param MaximumPacketLength Maximum packet size of the target endpoint.
|
|
|
|
@param DataBuffersNumber Number of data buffers prepared for the transfer.
|
|
|
|
@param Data Array of pointers to the buffers of data.
|
|
|
|
@param DataLength On input, size of the data buffer, On output,
|
|
|
|
actually transferred data size.
|
|
|
|
@param Translator A pointr to the transaction translator data.
|
|
|
|
@param TransferResult Variable to receive transfer result.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
@return EFI_UNSUPPORTED
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2IsochronousTransfer (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 DeviceAddress,
|
|
|
|
IN UINT8 EndPointAddress,
|
|
|
|
IN UINT8 DeviceSpeed,
|
|
|
|
IN UINTN MaximumPacketLength,
|
|
|
|
IN UINT8 DataBuffersNumber,
|
|
|
|
IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM],
|
|
|
|
IN UINTN DataLength,
|
|
|
|
IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
|
|
|
|
OUT UINT32 *TransferResult
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-23 10:41:04 +01:00
|
|
|
Submits Async isochronous transfer to a target USB device according to UEFI 2.0 spec.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param This A pointer to the EFI_USB2_HC_PROTOCOL instance.
|
|
|
|
@param DeviceAddress Target device address.
|
|
|
|
@param EndPointAddress Endpoint number and direction.
|
|
|
|
@param DeviceSpeed Device speed.
|
|
|
|
@param MaximumPacketLength Maximum packet size of the target endpoint.
|
|
|
|
@param DataBuffersNumber Number of data buffers prepared for the transfer.
|
|
|
|
@param Data Array of pointers to the buffers of data.
|
|
|
|
@param DataLength On input, size of the data buffer, On output,
|
|
|
|
actually transferred data size.
|
|
|
|
@param Translator A pointr to the transaction translator data.
|
|
|
|
@param IsochronousCallBack Function to call when the transfer complete.
|
|
|
|
@param Context Pass to the call back function as parameter.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
@return EFI_UNSUPPORTED
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhci2AsyncIsochronousTransfer (
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This,
|
|
|
|
IN UINT8 DeviceAddress,
|
|
|
|
IN UINT8 EndPointAddress,
|
|
|
|
IN UINT8 DeviceSpeed,
|
|
|
|
IN UINTN MaximumPacketLength,
|
|
|
|
IN UINT8 DataBuffersNumber,
|
|
|
|
IN OUT VOID *Data[EFI_USB_MAX_ISO_BUFFER_NUM],
|
|
|
|
IN UINTN DataLength,
|
|
|
|
IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator,
|
|
|
|
IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack,
|
|
|
|
IN VOID *Context
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
/**
|
|
|
|
Entry point for EFI drivers.
|
|
|
|
|
|
|
|
@param ImageHandle EFI_HANDLE.
|
|
|
|
@param SystemTable EFI_SYSTEM_TABLE.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Driver is successfully loaded.
|
|
|
|
@return Others Failed.
|
|
|
|
|
|
|
|
**/
|
2007-07-11 08:46:38 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
UhciDriverEntryPoint (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
2007-09-30 04:42:47 +02:00
|
|
|
return EfiLibInstallDriverBindingComponentName2 (
|
2007-07-11 08:46:38 +02:00
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&gUhciDriverBinding,
|
|
|
|
ImageHandle,
|
|
|
|
&gUhciComponentName,
|
2007-09-30 04:42:47 +02:00
|
|
|
&gUhciComponentName2
|
2007-07-11 08:46:38 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test to see if this driver supports ControllerHandle. Any
|
|
|
|
ControllerHandle that has UsbHcProtocol installed will be supported.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Controller Handle of device to test.
|
|
|
|
@param RemainingDevicePath Not used.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return EFI_SUCCESS This driver supports this device.
|
|
|
|
@return EFI_UNSUPPORTED This driver does not support this device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
UhciDriverBindingSupported (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS OpenStatus;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
USB_CLASSC UsbClassCReg;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Test whether there is PCI IO Protocol attached on the controller handle.
|
|
|
|
//
|
|
|
|
OpenStatus = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
2007-07-17 03:48:09 +02:00
|
|
|
(VOID **) &PciIo,
|
2007-07-11 08:46:38 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (OpenStatus)) {
|
|
|
|
return OpenStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = PciIo->Pci.Read (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoWidthUint8,
|
2009-07-24 07:34:55 +02:00
|
|
|
PCI_CLASSCODE_OFFSET,
|
2007-07-11 08:46:38 +02:00
|
|
|
sizeof (USB_CLASSC) / sizeof (UINT8),
|
|
|
|
&UsbClassCReg
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Test whether the controller belongs to UHCI type
|
|
|
|
//
|
|
|
|
if ((UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) ||
|
|
|
|
(UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB) ||
|
2010-01-19 07:42:21 +01:00
|
|
|
(UsbClassCReg.ProgInterface != PCI_IF_UHCI)
|
2007-07-11 08:46:38 +02:00
|
|
|
) {
|
|
|
|
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Allocate and initialize the empty UHCI device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The PCIIO to use.
|
|
|
|
@param OriginalPciAttributes The original PCI attributes.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return Allocated UHCI device. If err, return NULL.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
USB_HC_DEV *
|
|
|
|
UhciAllocateDev (
|
2012-10-30 05:23:40 +01:00
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
|
|
|
IN UINT64 OriginalPciAttributes
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Uhc = AllocateZeroPool (sizeof (USB_HC_DEV));
|
|
|
|
|
|
|
|
if (Uhc == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This driver supports both USB_HC_PROTOCOL and USB2_HC_PROTOCOL.
|
|
|
|
// USB_HC_PROTOCOL is for EFI 1.1 backward compability.
|
|
|
|
//
|
|
|
|
Uhc->Signature = USB_HC_DEV_SIGNATURE;
|
|
|
|
Uhc->Usb2Hc.GetCapability = Uhci2GetCapability;
|
|
|
|
Uhc->Usb2Hc.Reset = Uhci2Reset;
|
|
|
|
Uhc->Usb2Hc.GetState = Uhci2GetState;
|
|
|
|
Uhc->Usb2Hc.SetState = Uhci2SetState;
|
|
|
|
Uhc->Usb2Hc.ControlTransfer = Uhci2ControlTransfer;
|
|
|
|
Uhc->Usb2Hc.BulkTransfer = Uhci2BulkTransfer;
|
|
|
|
Uhc->Usb2Hc.AsyncInterruptTransfer = Uhci2AsyncInterruptTransfer;
|
|
|
|
Uhc->Usb2Hc.SyncInterruptTransfer = Uhci2SyncInterruptTransfer;
|
|
|
|
Uhc->Usb2Hc.IsochronousTransfer = Uhci2IsochronousTransfer;
|
|
|
|
Uhc->Usb2Hc.AsyncIsochronousTransfer = Uhci2AsyncIsochronousTransfer;
|
|
|
|
Uhc->Usb2Hc.GetRootHubPortStatus = Uhci2GetRootHubPortStatus;
|
|
|
|
Uhc->Usb2Hc.SetRootHubPortFeature = Uhci2SetRootHubPortFeature;
|
|
|
|
Uhc->Usb2Hc.ClearRootHubPortFeature = Uhci2ClearRootHubPortFeature;
|
|
|
|
Uhc->Usb2Hc.MajorRevision = 0x1;
|
|
|
|
Uhc->Usb2Hc.MinorRevision = 0x1;
|
|
|
|
|
2007-10-25 09:59:45 +02:00
|
|
|
Uhc->PciIo = PciIo;
|
2012-10-30 05:23:40 +01:00
|
|
|
Uhc->DevicePath = DevicePath;
|
2007-10-25 09:59:45 +02:00
|
|
|
Uhc->OriginalPciAttributes = OriginalPciAttributes;
|
|
|
|
Uhc->MemPool = UsbHcInitMemPool (PciIo, TRUE, 0);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (Uhc->MemPool == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeListHead (&Uhc->AsyncIntList);
|
|
|
|
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_TIMER | EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_CALLBACK,
|
|
|
|
UhciMonitorAsyncReqList,
|
|
|
|
Uhc,
|
|
|
|
&Uhc->AsyncIntMonitor
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
UsbHcFreeMemPool (Uhc->MemPool);
|
|
|
|
goto ON_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Uhc;
|
|
|
|
|
|
|
|
ON_ERROR:
|
2008-12-26 07:53:45 +01:00
|
|
|
FreePool (Uhc);
|
2007-07-11 08:46:38 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Free the UHCI device and release its associated resources.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Uhc The UHCI device to release.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciFreeDev (
|
|
|
|
IN USB_HC_DEV *Uhc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Uhc->AsyncIntMonitor != NULL) {
|
|
|
|
gBS->CloseEvent (Uhc->AsyncIntMonitor);
|
|
|
|
}
|
|
|
|
|
2009-04-10 10:31:45 +02:00
|
|
|
if (Uhc->ExitBootServiceEvent != NULL) {
|
|
|
|
gBS->CloseEvent (Uhc->ExitBootServiceEvent);
|
|
|
|
}
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
if (Uhc->MemPool != NULL) {
|
|
|
|
UsbHcFreeMemPool (Uhc->MemPool);
|
|
|
|
}
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if (Uhc->CtrlNameTable != NULL) {
|
2007-07-11 08:46:38 +02:00
|
|
|
FreeUnicodeStringTable (Uhc->CtrlNameTable);
|
|
|
|
}
|
|
|
|
|
2008-12-26 07:53:45 +01:00
|
|
|
FreePool (Uhc);
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Uninstall all Uhci Interface.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Controller Controller handle.
|
2007-07-11 08:46:38 +02:00
|
|
|
@param This Protocol instance pointer.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciCleanDevUp (
|
2008-01-23 10:41:04 +01:00
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_USB2_HC_PROTOCOL *This
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Uninstall the USB_HC and USB_HC2 protocol, then disable the controller
|
|
|
|
//
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc = UHC_FROM_USB2_HC_PROTO (This);
|
2007-10-08 08:14:13 +02:00
|
|
|
UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
gBS->UninstallProtocolInterface (
|
|
|
|
Controller,
|
|
|
|
&gEfiUsb2HcProtocolGuid,
|
|
|
|
&Uhc->Usb2Hc
|
|
|
|
);
|
|
|
|
|
|
|
|
UhciFreeAllAsyncReq (Uhc);
|
|
|
|
UhciDestoryFrameList (Uhc);
|
2007-10-25 09:59:45 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Restore original PCI attributes
|
|
|
|
//
|
2007-07-11 08:46:38 +02:00
|
|
|
Uhc->PciIo->Attributes (
|
2007-10-25 09:59:45 +02:00
|
|
|
Uhc->PciIo,
|
|
|
|
EfiPciIoAttributeOperationSet,
|
|
|
|
Uhc->OriginalPciAttributes,
|
|
|
|
NULL
|
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
UhciFreeDev (Uhc);
|
|
|
|
}
|
|
|
|
|
2009-04-10 10:31:45 +02:00
|
|
|
/**
|
|
|
|
One notified function to stop the Host Controller when gBS->ExitBootServices() called.
|
|
|
|
|
|
|
|
@param Event Pointer to this event
|
|
|
|
@param Context Event hanlder private data
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
UhcExitBootService (
|
|
|
|
EFI_EVENT Event,
|
|
|
|
VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
USB_HC_DEV *Uhc;
|
|
|
|
|
|
|
|
Uhc = (USB_HC_DEV *) Context;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Stop the Host Controller
|
|
|
|
//
|
|
|
|
UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT);
|
|
|
|
|
2010-05-08 00:46:14 +02:00
|
|
|
//
|
|
|
|
// Reset the Host Controller
|
|
|
|
//
|
|
|
|
UhciSetRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_HCRESET);
|
|
|
|
gBS->Stall (UHC_ROOT_PORT_RECOVERY_STALL);
|
2009-04-10 10:31:45 +02:00
|
|
|
}
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Starting the Usb UHCI Driver.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Controller Handle of device to test.
|
|
|
|
@param RemainingDevicePath Not used.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver supports this device.
|
|
|
|
@retval EFI_UNSUPPORTED This driver does not support this device.
|
2008-07-09 03:50:16 +02:00
|
|
|
@retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
|
|
|
|
EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
UhciDriverBindingStart (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
USB_HC_DEV *Uhc;
|
2007-10-15 09:44:27 +02:00
|
|
|
UINT64 Supports;
|
2007-10-25 09:59:45 +02:00
|
|
|
UINT64 OriginalPciAttributes;
|
2007-11-28 04:55:36 +01:00
|
|
|
BOOLEAN PciAttributesSaved;
|
2012-10-30 05:23:40 +01:00
|
|
|
EFI_DEVICE_PATH_PROTOCOL *HcDevicePath;
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Open PCIIO, then enable the EHC device and turn off emulation
|
|
|
|
//
|
|
|
|
Uhc = NULL;
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
2007-07-17 03:48:09 +02:00
|
|
|
(VOID **) &PciIo,
|
2007-07-11 08:46:38 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-10-30 05:23:40 +01:00
|
|
|
//
|
|
|
|
// Open Device Path Protocol for on USB host controller
|
|
|
|
//
|
|
|
|
HcDevicePath = NULL;
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiDevicePathProtocolGuid,
|
|
|
|
(VOID **) &HcDevicePath,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
|
2007-11-28 04:55:36 +01:00
|
|
|
PciAttributesSaved = FALSE;
|
2007-10-25 09:59:45 +02:00
|
|
|
//
|
|
|
|
// Save original PCI attributes
|
|
|
|
//
|
|
|
|
Status = PciIo->Attributes (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoAttributeOperationGet,
|
|
|
|
0,
|
|
|
|
&OriginalPciAttributes
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-11-28 04:55:36 +01:00
|
|
|
goto CLOSE_PCIIO;
|
2007-10-25 09:59:45 +02:00
|
|
|
}
|
2007-11-28 04:55:36 +01:00
|
|
|
PciAttributesSaved = TRUE;
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2008-03-14 06:06:26 +01:00
|
|
|
//
|
|
|
|
// Robustnesss improvement such as for UoL
|
|
|
|
// Default is not required.
|
|
|
|
//
|
2008-05-06 11:34:46 +02:00
|
|
|
if (FeaturePcdGet (PcdTurnOffUsbLegacySupport)) {
|
2008-04-17 13:02:59 +02:00
|
|
|
UhciTurnOffUsbEmulation (PciIo);
|
|
|
|
}
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
Status = PciIo->Attributes (
|
|
|
|
PciIo,
|
2007-10-15 09:44:27 +02:00
|
|
|
EfiPciIoAttributeOperationSupported,
|
|
|
|
0,
|
|
|
|
&Supports
|
2007-07-11 08:46:38 +02:00
|
|
|
);
|
2007-10-15 09:44:27 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Supports &= EFI_PCI_DEVICE_ENABLE;
|
|
|
|
Status = PciIo->Attributes (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoAttributeOperationEnable,
|
|
|
|
Supports,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto CLOSE_PCIIO;
|
|
|
|
}
|
|
|
|
|
2012-10-30 05:23:40 +01:00
|
|
|
Uhc = UhciAllocateDev (PciIo, HcDevicePath, OriginalPciAttributes);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
if (Uhc == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto CLOSE_PCIIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate and Init Host Controller's Frame List Entry
|
|
|
|
//
|
|
|
|
Status = UhciInitFrameList (Uhc);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto FREE_UHC;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->SetTimer (
|
|
|
|
Uhc->AsyncIntMonitor,
|
|
|
|
TimerPeriodic,
|
2007-10-08 08:14:13 +02:00
|
|
|
UHC_ASYNC_POLL_INTERVAL
|
2007-07-11 08:46:38 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FREE_UHC;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-01-23 10:41:04 +01:00
|
|
|
// Install USB2_HC_PROTOCOL
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&Controller,
|
|
|
|
&gEfiUsb2HcProtocolGuid,
|
|
|
|
&Uhc->Usb2Hc,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FREE_UHC;
|
|
|
|
}
|
|
|
|
|
2009-04-10 10:31:45 +02:00
|
|
|
//
|
|
|
|
// Create event to stop the HC when exit boot service.
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
UhcExitBootService,
|
|
|
|
Uhc,
|
|
|
|
&gEfiEventExitBootServicesGuid,
|
|
|
|
&Uhc->ExitBootServiceEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto UNINSTALL_USBHC;
|
|
|
|
}
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
//
|
|
|
|
// Install the component name protocol
|
|
|
|
//
|
|
|
|
Uhc->CtrlNameTable = NULL;
|
|
|
|
|
2007-09-30 04:42:47 +02:00
|
|
|
AddUnicodeString2 (
|
2007-07-11 08:46:38 +02:00
|
|
|
"eng",
|
|
|
|
gUhciComponentName.SupportedLanguages,
|
|
|
|
&Uhc->CtrlNameTable,
|
2007-09-30 04:42:47 +02:00
|
|
|
L"Usb Universal Host Controller",
|
|
|
|
TRUE
|
2007-07-11 08:46:38 +02:00
|
|
|
);
|
2007-09-30 04:42:47 +02:00
|
|
|
AddUnicodeString2 (
|
|
|
|
"en",
|
|
|
|
gUhciComponentName2.SupportedLanguages,
|
|
|
|
&Uhc->CtrlNameTable,
|
|
|
|
L"Usb Universal Host Controller",
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Start the UHCI hardware, also set its reclamation point to 64 bytes
|
|
|
|
//
|
|
|
|
UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, USBCMD_RS | USBCMD_MAXP);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2009-04-10 10:31:45 +02:00
|
|
|
|
|
|
|
UNINSTALL_USBHC:
|
|
|
|
gBS->UninstallMultipleProtocolInterfaces (
|
|
|
|
Controller,
|
|
|
|
&gEfiUsb2HcProtocolGuid,
|
|
|
|
&Uhc->Usb2Hc,
|
|
|
|
NULL
|
|
|
|
);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
FREE_UHC:
|
|
|
|
UhciFreeDev (Uhc);
|
|
|
|
|
|
|
|
CLOSE_PCIIO:
|
2008-07-02 07:45:04 +02:00
|
|
|
if (PciAttributesSaved) {
|
2007-11-28 04:55:36 +01:00
|
|
|
//
|
|
|
|
// Restore original PCI attributes
|
|
|
|
//
|
|
|
|
PciIo->Attributes (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoAttributeOperationSet,
|
|
|
|
OriginalPciAttributes,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
2007-10-25 09:59:45 +02:00
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Stop this driver on ControllerHandle. Support stoping any child handles
|
|
|
|
created by this driver.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Controller Handle of device to stop driver on.
|
|
|
|
@param NumberOfChildren Number of Children in the ChildHandleBuffer.
|
2007-07-11 08:46:38 +02:00
|
|
|
@param ChildHandleBuffer List of handles for the children we need to stop.
|
|
|
|
|
|
|
|
@return EFI_SUCCESS
|
|
|
|
@return others
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
UhciDriverBindingStop (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN UINTN NumberOfChildren,
|
|
|
|
IN EFI_HANDLE *ChildHandleBuffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_USB2_HC_PROTOCOL *Usb2Hc;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
Status = gBS->OpenProtocol (
|
2007-07-11 08:46:38 +02:00
|
|
|
Controller,
|
|
|
|
&gEfiUsb2HcProtocolGuid,
|
2007-07-17 03:48:09 +02:00
|
|
|
(VOID **) &Usb2Hc,
|
2007-07-11 08:46:38 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Test whether the Controller handler passed in is a valid
|
|
|
|
// Usb controller handle that should be supported, if not,
|
|
|
|
// return the error status directly
|
|
|
|
//
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-01-23 10:41:04 +01:00
|
|
|
UhciCleanDevUp (Controller, Usb2Hc);
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|