2007-07-11 08:46:38 +02:00
|
|
|
/** @file
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
The UHCI register operation routines.
|
|
|
|
|
2007-07-11 08:46:38 +02:00
|
|
|
Copyright (c) 2007, Intel Corporation
|
|
|
|
All rights reserved. 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
|
|
|
|
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-07-09 03:50:16 +02:00
|
|
|
Read a UHCI register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The EFI_PCI_IO_PROTOCOL to use.
|
|
|
|
@param Offset Register offset to USB_BAR_INDEX.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return Content of register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
UINT16
|
|
|
|
UhciReadReg (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo,
|
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = PciIo->Io.Read (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoWidthUint16,
|
|
|
|
USB_BAR_INDEX,
|
|
|
|
Offset,
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-02-13 10:08:24 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "UhciReadReg: PciIo Io.Read error: %r at offset %d\n", Status, Offset));
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
Data = 0xFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Write data to UHCI register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The EFI_PCI_IO_PROTOCOL to use.
|
|
|
|
@param Offset Register offset to USB_BAR_INDEX.
|
|
|
|
@param Data Data to write.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return None.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciWriteReg (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo,
|
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT16 Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = PciIo->Io.Write (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoWidthUint16,
|
|
|
|
USB_BAR_INDEX,
|
|
|
|
Offset,
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-02-13 10:08:24 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "UhciWriteReg: PciIo Io.Write error: %r at offset %d\n", Status, Offset));
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Set a bit of the UHCI Register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The EFI_PCI_IO_PROTOCOL to use.
|
|
|
|
@param Offset Register offset to USB_BAR_INDEX.
|
|
|
|
@param Bit The bit to set.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return None.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciSetRegBit (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo,
|
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT16 Bit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 Data;
|
|
|
|
|
|
|
|
Data = UhciReadReg (PciIo, Offset);
|
2007-07-17 03:48:09 +02:00
|
|
|
Data = (UINT16) (Data |Bit);
|
2007-07-11 08:46:38 +02:00
|
|
|
UhciWriteReg (PciIo, Offset, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Clear a bit of the UHCI Register.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The PCI_IO protocol to access the PCI.
|
|
|
|
@param Offset Register offset to USB_BAR_INDEX.
|
|
|
|
@param Bit The bit to clear.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return None.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciClearRegBit (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo,
|
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT16 Bit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 Data;
|
|
|
|
|
|
|
|
Data = UhciReadReg (PciIo, Offset);
|
2007-07-17 03:48:09 +02:00
|
|
|
Data = (UINT16) (Data & ~Bit);
|
2007-07-11 08:46:38 +02:00
|
|
|
UhciWriteReg (PciIo, Offset, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear all the interrutp status bits, these bits
|
2008-07-09 03:50:16 +02:00
|
|
|
are Write-Clean.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Uhc The UHCI device.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return None.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciAckAllInterrupt (
|
|
|
|
IN USB_HC_DEV *Uhc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UhciWriteReg (Uhc->PciIo, USBSTS_OFFSET, 0x3F);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If current HC is halted, re-enable it. Host Controller Process Error
|
|
|
|
// is a temporary error status.
|
|
|
|
//
|
|
|
|
if (!UhciIsHcWorking (Uhc->PciIo)) {
|
2008-02-13 10:08:24 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "UhciAckAllInterrupt: re-enable the UHCI from system error\n"));
|
2008-01-23 10:41:04 +01:00
|
|
|
Uhc->Usb2Hc.SetState (&Uhc->Usb2Hc, EfiUsbHcStateOperational);
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Stop the host controller.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param Uhc The UHCI device.
|
|
|
|
@param Timeout Max time allowed.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@retval EFI_SUCCESS The host controller is stopped.
|
|
|
|
@retval EFI_TIMEOUT Failed to stop the host controller.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
UhciStopHc (
|
2008-01-23 10:41:04 +01:00
|
|
|
IN USB_HC_DEV *Uhc,
|
|
|
|
IN UINTN Timeout
|
2007-07-11 08:46:38 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 UsbSts;
|
|
|
|
UINTN Index;
|
|
|
|
|
|
|
|
UhciClearRegBit (Uhc->PciIo, USBCMD_OFFSET, USBCMD_RS);
|
|
|
|
|
|
|
|
//
|
|
|
|
// ensure the HC is in halt status after send the stop command
|
|
|
|
// Timeout is in us unit.
|
|
|
|
//
|
|
|
|
for (Index = 0; Index < (Timeout / 50) + 1; Index++) {
|
|
|
|
UsbSts = UhciReadReg (Uhc->PciIo, USBSTS_OFFSET);
|
|
|
|
|
|
|
|
if ((UsbSts & USBSTS_HCH) == USBSTS_HCH) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->Stall (50);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Check whether the host controller operates well.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The PCI_IO protocol to use.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@retval TRUE Host controller is working.
|
|
|
|
@retval FALSE Host controller is halted or system error.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
UhciIsHcWorking (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 UsbSts;
|
|
|
|
|
|
|
|
UsbSts = UhciReadReg (PciIo, USBSTS_OFFSET);
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
if ((UsbSts & (USBSTS_HCPE | USBSTS_HSE | USBSTS_HCH)) != 0) {
|
2008-02-13 10:08:24 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "UhciIsHcWorking: current USB state is %x\n", UsbSts));
|
2007-07-11 08:46:38 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the UHCI frame list base address. It can't use
|
|
|
|
UhciWriteReg which access memory in UINT16.
|
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The EFI_PCI_IO_PROTOCOL to use.
|
|
|
|
@param Addr Address to set.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return None.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciSetFrameListBaseAddr (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo,
|
|
|
|
IN VOID *Addr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 Data;
|
|
|
|
|
|
|
|
Data = (UINT32) ((UINTN) Addr & 0xFFFFF000);
|
|
|
|
|
|
|
|
Status = PciIo->Io.Write (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
USB_BAR_INDEX,
|
|
|
|
(UINT64) USB_FRAME_BASE_OFFSET,
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2008-02-13 10:08:24 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "UhciSetFrameListBaseAddr: PciIo Io.Write error: %r\n", Status));
|
2007-07-11 08:46:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-07-09 03:50:16 +02:00
|
|
|
Disable USB Emulation.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@param PciIo The EFI_PCI_IO_PROTOCOL protocol to use.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
2008-07-09 03:50:16 +02:00
|
|
|
@return None.
|
2007-07-11 08:46:38 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UhciTurnOffUsbEmulation (
|
|
|
|
IN EFI_PCI_IO_PROTOCOL *PciIo
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT16 Command;
|
|
|
|
|
|
|
|
Command = 0;
|
|
|
|
|
|
|
|
PciIo->Pci.Write (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoWidthUint16,
|
|
|
|
USB_EMULATION_OFFSET,
|
|
|
|
1,
|
|
|
|
&Command
|
|
|
|
);
|
|
|
|
}
|