2011-08-23 16:36:33 +02:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
The XHCI register operation routines.
|
|
|
|
|
2015-08-19 05:41:38 +02:00
|
|
|
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
|
2011-08-23 16:36:33 +02:00
|
|
|
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 "Xhci.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read 1-byte width XHCI capability register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the 1-byte width capability register.
|
|
|
|
|
|
|
|
@return The register content read.
|
|
|
|
@retval If err, return 0xFF.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT8
|
|
|
|
XhcReadCapReg8 (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT8 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Read (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint8,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) Offset,
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcReadCapReg: Pci Io read error - %r at %d\n", Status, Offset));
|
|
|
|
Data = 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read 4-bytes width XHCI capability register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the 4-bytes width capability register.
|
|
|
|
|
|
|
|
@return The register content read.
|
|
|
|
@retval If err, return 0xFFFFFFFF.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
XhcReadCapReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Read (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) Offset,
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcReadCapReg: Pci Io read error - %r at %d\n", Status, Offset));
|
|
|
|
Data = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read 4-bytes width XHCI Operational register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the 4-bytes width operational register.
|
|
|
|
|
|
|
|
@return The register content read.
|
|
|
|
@retval If err, return 0xFFFFFFFF.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
XhcReadOpReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->CapLength != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Read (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->CapLength + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcReadOpReg: Pci Io Read error - %r at %d\n", Status, Offset));
|
|
|
|
Data = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Write the data to the 4-bytes width XHCI operational register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the 4-bytes width operational register.
|
|
|
|
@param Data The data to write.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcWriteOpReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->CapLength != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Write (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->CapLength + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcWriteOpReg: Pci Io Write error: %r at %d\n", Status, Offset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Write the data to the 2-bytes width XHCI operational register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the 2-bytes width operational register.
|
|
|
|
@param Data The data to write.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcWriteOpReg16 (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT16 Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->CapLength != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Write (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint16,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->CapLength + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcWriteOpReg16: Pci Io Write error: %r at %d\n", Status, Offset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read XHCI door bell register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the door bell register.
|
|
|
|
|
|
|
|
@return The register content read
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
XhcReadDoorBellReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->DBOff != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Read (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->DBOff + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcReadDoorBellReg: Pci Io Read error - %r at %d\n", Status, Offset));
|
|
|
|
Data = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Write the data to the XHCI door bell register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the door bell register.
|
|
|
|
@param Data The data to write.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcWriteDoorBellReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->DBOff != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Write (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->DBOff + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcWriteOpReg: Pci Io Write error: %r at %d\n", Status, Offset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read XHCI runtime register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the runtime register.
|
|
|
|
|
|
|
|
@return The register content read
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
XhcReadRuntimeReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->RTSOff != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Read (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->RTSOff + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcReadRuntimeReg: Pci Io Read error - %r at %d\n", Status, Offset));
|
|
|
|
Data = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Write the data to the XHCI runtime register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the runtime register.
|
|
|
|
@param Data The data to write.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcWriteRuntimeReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->RTSOff != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Write (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->RTSOff + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcWriteRuntimeReg: Pci Io Write error: %r at %d\n", Status, Offset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read XHCI extended capability register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the extended capability register.
|
|
|
|
|
|
|
|
@return The register content read
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
|
|
|
XhcReadExtCapReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->ExtCapRegBase != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Read (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->ExtCapRegBase + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcReadExtCapReg: Pci Io Read error - %r at %d\n", Status, Offset));
|
|
|
|
Data = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Write the data to the XHCI extended capability register.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the extended capability register.
|
|
|
|
@param Data The data to write.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcWriteExtCapReg (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Data
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Xhc->ExtCapRegBase != 0);
|
|
|
|
|
|
|
|
Status = Xhc->PciIo->Mem.Write (
|
|
|
|
Xhc->PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
XHC_BAR_INDEX,
|
|
|
|
(UINT64) (Xhc->ExtCapRegBase + Offset),
|
|
|
|
1,
|
|
|
|
&Data
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "XhcWriteExtCapReg: Pci Io Write error: %r at %d\n", Status, Offset));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set one bit of the runtime register while keeping other bits.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the runtime register.
|
|
|
|
@param Bit The bit mask of the register to set.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcSetRuntimeRegBit (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
|
|
|
|
Data = XhcReadRuntimeReg (Xhc, Offset);
|
|
|
|
Data |= Bit;
|
|
|
|
XhcWriteRuntimeReg (Xhc, Offset, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear one bit of the runtime register while keeping other bits.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the runtime register.
|
|
|
|
@param Bit The bit mask of the register to set.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcClearRuntimeRegBit (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
|
|
|
|
Data = XhcReadRuntimeReg (Xhc, Offset);
|
|
|
|
Data &= ~Bit;
|
|
|
|
XhcWriteRuntimeReg (Xhc, Offset, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set one bit of the operational register while keeping other bits.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the operational register.
|
|
|
|
@param Bit The bit mask of the register to set.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcSetOpRegBit (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
|
|
|
|
Data = XhcReadOpReg (Xhc, Offset);
|
|
|
|
Data |= Bit;
|
|
|
|
XhcWriteOpReg (Xhc, Offset, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear one bit of the operational register while keeping other bits.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the operational register.
|
|
|
|
@param Bit The bit mask of the register to clear.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcClearOpRegBit (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Data;
|
|
|
|
|
|
|
|
Data = XhcReadOpReg (Xhc, Offset);
|
|
|
|
Data &= ~Bit;
|
|
|
|
XhcWriteOpReg (Xhc, Offset, Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wait the operation register's bit as specified by Bit
|
|
|
|
to become set (or clear).
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
@param Offset The offset of the operation register.
|
|
|
|
@param Bit The bit of the register to wait for.
|
|
|
|
@param WaitToSet Wait the bit to set or clear.
|
2015-08-19 05:41:38 +02:00
|
|
|
@param Timeout The time to wait before abort (in millisecond, ms).
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The bit successfully changed by host controller.
|
|
|
|
@retval EFI_TIMEOUT The time out occurred.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
XhcWaitOpRegBit (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Offset,
|
|
|
|
IN UINT32 Bit,
|
|
|
|
IN BOOLEAN WaitToSet,
|
|
|
|
IN UINT32 Timeout
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Index;
|
2015-08-19 05:41:38 +02:00
|
|
|
UINT64 Loop;
|
2011-08-23 16:36:33 +02:00
|
|
|
|
2015-08-19 05:41:38 +02:00
|
|
|
Loop = Timeout * XHC_1_MILLISECOND;
|
2011-09-14 14:13:03 +02:00
|
|
|
|
|
|
|
for (Index = 0; Index < Loop; Index++) {
|
2011-08-23 16:36:33 +02:00
|
|
|
if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) == WaitToSet) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-08-19 05:41:38 +02:00
|
|
|
gBS->Stall (XHC_1_MICROSECOND);
|
2011-08-23 16:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set Bios Ownership
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcSetBiosOwnership (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc
|
2011-08-23 16:36:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Buffer;
|
|
|
|
|
2013-10-15 08:13:14 +02:00
|
|
|
if (Xhc->UsbLegSupOffset == 0xFFFFFFFF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "XhcSetBiosOwnership: called to set BIOS ownership\n"));
|
|
|
|
|
|
|
|
Buffer = XhcReadExtCapReg (Xhc, Xhc->UsbLegSupOffset);
|
|
|
|
Buffer = ((Buffer & (~USBLEGSP_OS_SEMAPHORE)) | USBLEGSP_BIOS_SEMAPHORE);
|
|
|
|
XhcWriteExtCapReg (Xhc, Xhc->UsbLegSupOffset, Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Clear Bios Ownership
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
XhcClearBiosOwnership (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc
|
2011-08-23 16:36:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Buffer;
|
|
|
|
|
2013-10-15 08:13:14 +02:00
|
|
|
if (Xhc->UsbLegSupOffset == 0xFFFFFFFF) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "XhcClearBiosOwnership: called to clear BIOS ownership\n"));
|
|
|
|
|
|
|
|
Buffer = XhcReadExtCapReg (Xhc, Xhc->UsbLegSupOffset);
|
|
|
|
Buffer = ((Buffer & (~USBLEGSP_BIOS_SEMAPHORE)) | USBLEGSP_OS_SEMAPHORE);
|
|
|
|
XhcWriteExtCapReg (Xhc, Xhc->UsbLegSupOffset, Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-10-09 10:30:59 +02:00
|
|
|
Calculate the offset of the XHCI capability.
|
2011-08-23 16:36:33 +02:00
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2013-10-09 10:30:59 +02:00
|
|
|
@param CapId The XHCI Capability ID.
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@return The offset of XHCI legacy support capability register.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UINT32
|
2013-10-09 10:30:59 +02:00
|
|
|
XhcGetCapabilityAddr (
|
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
|
|
|
IN UINT8 CapId
|
2011-08-23 16:36:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 ExtCapOffset;
|
|
|
|
UINT8 NextExtCapReg;
|
|
|
|
UINT32 Data;
|
|
|
|
|
|
|
|
ExtCapOffset = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
//
|
|
|
|
// Check if the extended capability register's capability id is USB Legacy Support.
|
|
|
|
//
|
|
|
|
Data = XhcReadExtCapReg (Xhc, ExtCapOffset);
|
2013-10-09 10:30:59 +02:00
|
|
|
if ((Data & 0xFF) == CapId) {
|
2011-08-23 16:36:33 +02:00
|
|
|
return ExtCapOffset;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// If not, then traverse all of the ext capability registers till finding out it.
|
|
|
|
//
|
2011-08-25 12:19:11 +02:00
|
|
|
NextExtCapReg = (UINT8)((Data >> 8) & 0xFF);
|
2011-08-23 16:36:33 +02:00
|
|
|
ExtCapOffset += (NextExtCapReg << 2);
|
|
|
|
} while (NextExtCapReg != 0);
|
|
|
|
|
2013-10-15 08:13:14 +02:00
|
|
|
return 0xFFFFFFFF;
|
2011-08-23 16:36:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Whether the XHCI host controller is halted.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@retval TRUE The controller is halted.
|
|
|
|
@retval FALSE It isn't halted.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
XhcIsHalt (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc
|
2011-08-23 16:36:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return XHC_REG_BIT_IS_SET (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HALT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Whether system error occurred.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@retval TRUE System error happened.
|
|
|
|
@retval FALSE No system error.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
XhcIsSysError (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc
|
2011-08-23 16:36:33 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return XHC_REG_BIT_IS_SET (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reset the XHCI host controller.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2015-08-19 05:41:38 +02:00
|
|
|
@param Timeout Time to wait before abort (in millisecond, ms).
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The XHCI host controller is reset.
|
|
|
|
@return Others Failed to reset the XHCI before Timeout.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
XhcResetHC (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Timeout
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2013-10-09 10:30:59 +02:00
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "XhcResetHC!\n"));
|
|
|
|
//
|
|
|
|
// Host can only be reset when it is halt. If not so, halt it
|
|
|
|
//
|
|
|
|
if (!XHC_REG_BIT_IS_SET (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HALT)) {
|
|
|
|
Status = XhcHaltHC (Xhc, Timeout);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-15 08:13:14 +02:00
|
|
|
if ((Xhc->DebugCapSupOffset == 0xFFFFFFFF) || ((XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset) & 0xFF) != XHC_CAP_USB_DEBUG) ||
|
2013-10-09 10:30:59 +02:00
|
|
|
((XhcReadExtCapReg (Xhc, Xhc->DebugCapSupOffset + XHC_DC_DCCTRL) & BIT0) == 0)) {
|
|
|
|
XhcSetOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RESET);
|
|
|
|
Status = XhcWaitOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RESET, FALSE, Timeout);
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:36:33 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Halt the XHCI host controller.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2015-08-19 05:41:38 +02:00
|
|
|
@param Timeout Time to wait before abort (in millisecond, ms).
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@return EFI_SUCCESS The XHCI host controller is halt.
|
|
|
|
@return EFI_TIMEOUT Failed to halt the XHCI before Timeout.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
XhcHaltHC (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Timeout
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
XhcClearOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RUN);
|
|
|
|
Status = XhcWaitOpRegBit (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HALT, TRUE, Timeout);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the XHCI host controller to run.
|
|
|
|
|
2011-09-14 14:13:03 +02:00
|
|
|
@param Xhc The XHCI Instance.
|
2015-08-19 05:41:38 +02:00
|
|
|
@param Timeout Time to wait before abort (in millisecond, ms).
|
2011-08-23 16:36:33 +02:00
|
|
|
|
|
|
|
@return EFI_SUCCESS The XHCI host controller is running.
|
|
|
|
@return EFI_TIMEOUT Failed to set the XHCI to run before Timeout.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
XhcRunHC (
|
2011-09-14 14:13:03 +02:00
|
|
|
IN USB_XHCI_INSTANCE *Xhc,
|
2011-08-23 16:36:33 +02:00
|
|
|
IN UINT32 Timeout
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
XhcSetOpRegBit (Xhc, XHC_USBCMD_OFFSET, XHC_USBCMD_RUN);
|
|
|
|
Status = XhcWaitOpRegBit (Xhc, XHC_USBSTS_OFFSET, XHC_USBSTS_HALT, FALSE, Timeout);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|