Revert "DebugUsb3: Support IOMMU"

This reverts commit de8373fa07.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
This commit is contained in:
Star Zeng
2018-03-14 16:09:36 +08:00
parent 373b1d0ee3
commit 1f279e7a53
6 changed files with 130 additions and 843 deletions

View File

@ -14,6 +14,11 @@
#include "DebugCommunicationLibUsb3Internal.h"
//
// The global variable which can be used after memory is ready.
//
USB3_DEBUG_PORT_HANDLE mDebugCommunicationLibUsb3DebugPortHandle;
UINT16 mString0Desc[] = {
// String Descriptor Type + Length
( USB_DESC_TYPE_STRING << 8 ) + STRING0_DESC_LEN,
@ -80,7 +85,7 @@ XhcClearR32Bit(
Write the data to the XHCI debug register.
@param Handle Debug port handle.
@param Offset The offset of the debug register.
@param Offset The offset of the runtime register.
@param Data The data to write.
**/
@ -124,16 +129,16 @@ XhcReadDebugReg (
}
/**
Set one bit of the debug register while keeping other bits.
Set one bit of the runtime register while keeping other bits.
@param Handle Debug port handle.
@param Offset The offset of the debug register.
@param Offset The offset of the runtime register.
@param Bit The bit mask of the register to set.
**/
VOID
XhcSetDebugRegBit (
IN USB3_DEBUG_PORT_HANDLE *Handle,
IN USB3_DEBUG_PORT_HANDLE *Handle,
IN UINT32 Offset,
IN UINT32 Bit
)
@ -145,28 +150,6 @@ XhcSetDebugRegBit (
XhcWriteDebugReg (Handle, Offset, Data);
}
/**
Clear one bit of the debug register while keeping other bits.
@param Handle Debug port handle.
@param Offset The offset of the debug register.
@param Bit The bit mask of the register to clear.
**/
VOID
XhcClearDebugRegBit (
IN USB3_DEBUG_PORT_HANDLE *Handle,
IN UINT32 Offset,
IN UINT32 Bit
)
{
UINT32 Data;
Data = XhcReadDebugReg (Handle, Offset);
Data &= ~Bit;
XhcWriteDebugReg (Handle, Offset, Data);
}
/**
Program and eanble XHCI MMIO base address.
@ -216,7 +199,7 @@ UpdateXhcResource (
IN EFI_PHYSICAL_ADDRESS XhciMmioBase
)
{
if (Handle == NULL) {
if ((Handle == NULL) || (Handle->XhciMmioBase == XhciMmioBase)) {
return;
}
@ -233,7 +216,7 @@ UpdateXhcResource (
@param Handle Debug port handle.
@retval RETURN_UNSUPPORTED The usb host controller does not support usb debug port capability.
@retval RETURN_UNSUPPORTED The usb host controller does not supported usb debug port capability.
@retval RETURN_SUCCESS Get bar and offset successfully.
**/
@ -253,14 +236,6 @@ CalculateUsbDebugPortMmioBase (
EFI_PHYSICAL_ADDRESS CapabilityPointer;
UINT8 CapLength;
if (Handle->Initialized != USB3DBG_UNINITIALIZED) {
if (Handle->Initialized == USB3DBG_NO_DBG_CAB) {
return RETURN_UNSUPPORTED;
} else {
return RETURN_SUCCESS;
}
}
VendorId = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_VENDOR_ID_OFFSET);
DeviceId = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_DEVICE_ID_OFFSET);
@ -313,7 +288,6 @@ CalculateUsbDebugPortMmioBase (
Handle->DebugCapabilityBase = CapabilityPointer;
Handle->DebugCapabilityOffset = CapabilityPointer - Handle->XhciMmioBase;
Handle->XhciOpRegister = Handle->XhciMmioBase + CapLength;
Handle->DebugSupport = TRUE;
Handle->Initialized = USB3DBG_DBG_CAB;
return RETURN_SUCCESS;
@ -352,9 +326,6 @@ NeedReinitializeHardware(
Dcctrl = XhcReadDebugReg (Handle, XHC_DC_DCCTRL);
if ((Dcctrl & BIT0) == 0) {
Result = TRUE;
} else if (!Handle->Ready) {
Handle->Ready = TRUE;
Handle->Initialized = USB3DBG_ENABLED;
}
return Result;
@ -706,13 +677,6 @@ InitializeUsbDebugHardware (
MicroSecondDelay (10 * 1000);
}
//
// Clear DCE bit and LSE bit in DCCTRL
//
if ((XhcReadDebugReg (Handle, XHC_DC_DCCTRL) & (BIT1|BIT31)) == (BIT1|BIT31)) {
XhcClearDebugRegBit (Handle, XHC_DC_DCCTRL, BIT1|BIT31);
}
//
// Construct the buffer for read, poll and write.
//
@ -781,35 +745,6 @@ Enable:
return Status;
}
/**
Discover and initialize usb debug port.
@param Handle Debug port handle.
**/
VOID
DiscoverInitializeUsbDebugPort (
IN USB3_DEBUG_PORT_HANDLE *Handle
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS XhciMmioBase;
//
// Read 64-bit MMIO base address
//
XhciMmioBase = ProgramXhciBaseAddress ();
Handle->XhciMmioBase = XhciMmioBase;
Status = CalculateUsbDebugPortMmioBase (Handle);
if (!RETURN_ERROR (Status)) {
UpdateXhcResource (Handle, XhciMmioBase);
if (NeedReinitializeHardware (Handle)) {
InitializeUsbDebugHardware (Handle);
}
}
}
/**
Read data from debug device and save the data in buffer.
@ -837,6 +772,7 @@ DebugPortReadBuffer (
)
{
USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
RETURN_STATUS Status;
UINT8 Index;
UINT8 *Data;
@ -844,17 +780,25 @@ DebugPortReadBuffer (
return 0;
}
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
if (UsbDebugPortHandle == NULL) {
//
// If Handle is NULL, it means memory is ready for use.
// Use global variable to store handle value.
//
if (Handle == NULL) {
UsbDebugPortHandle = &mDebugCommunicationLibUsb3DebugPortHandle;
} else {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
}
if (UsbDebugPortHandle->Initialized == USB3DBG_NO_DBG_CAB) {
return 0;
}
if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
return 0;
}
if (UsbDebugPortHandle->InNotify) {
return 0;
if (NeedReinitializeHardware(UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
if (RETURN_ERROR(Status)) {
return 0;
}
}
Data = (UINT8 *)(UINTN)UsbDebugPortHandle->Data;
@ -904,8 +848,10 @@ DebugPortWriteBuffer (
)
{
USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
RETURN_STATUS Status;
UINTN Sent;
UINTN Total;
EFI_PHYSICAL_ADDRESS XhciMmioBase;
UINTN Index;
if (NumberOfBytes == 0 || Buffer == NULL) {
@ -915,24 +861,39 @@ DebugPortWriteBuffer (
Sent = 0;
Total = 0;
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
if (UsbDebugPortHandle == NULL) {
//
// If Handle is NULL, it means memory is ready for use.
// Use global variable to store handle value.
//
if (Handle == NULL) {
UsbDebugPortHandle = &mDebugCommunicationLibUsb3DebugPortHandle;
} else {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
}
if (UsbDebugPortHandle->Initialized == USB3DBG_NO_DBG_CAB) {
return 0;
}
if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
return 0;
}
//
// MMIO base address is possible to clear, set it if it is cleared. (XhciMemorySpaceClose in PchUsbCommon.c)
//
XhciMmioBase = ProgramXhciBaseAddress ();
if (UsbDebugPortHandle->InNotify) {
return 0;
UpdateXhcResource (UsbDebugPortHandle, XhciMmioBase);
if (NeedReinitializeHardware(UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
if (RETURN_ERROR(Status)) {
return 0;
}
}
//
// When host is trying to send data, write will be blocked.
// Poll to see if there is any data sent by host at first.
//
DebugPortPollBuffer (UsbDebugPortHandle);
DebugPortPollBuffer (Handle);
Index = 0;
while ((Total < NumberOfBytes)) {
@ -941,7 +902,7 @@ DebugPortWriteBuffer (
} else {
Sent = (UINT8)(NumberOfBytes - Total);
}
XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataOut, Buffer + Total, &Sent, DATA_TRANSFER_WRITE_TIMEOUT);
Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataOut, Buffer + Total, &Sent, DATA_TRANSFER_WRITE_TIMEOUT);
Total += Sent;
}
@ -969,20 +930,33 @@ DebugPortPollBuffer (
{
USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
UINTN Length;
RETURN_STATUS Status;
EFI_PHYSICAL_ADDRESS XhciMmioBase;
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
if (UsbDebugPortHandle == NULL) {
return FALSE;
//
// If Handle is NULL, it means memory is ready for use.
// Use global variable to store handle value.
//
if (Handle == NULL) {
UsbDebugPortHandle = &mDebugCommunicationLibUsb3DebugPortHandle;
} else {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
}
if (UsbDebugPortHandle->Initialized != USB3DBG_ENABLED) {
return FALSE;
if (UsbDebugPortHandle->Initialized == USB3DBG_NO_DBG_CAB) {
return 0;
}
if (UsbDebugPortHandle->InNotify) {
return FALSE;
XhciMmioBase = ProgramXhciBaseAddress ();
UpdateXhcResource (UsbDebugPortHandle, XhciMmioBase);
if (NeedReinitializeHardware(UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware(UsbDebugPortHandle);
if (RETURN_ERROR(Status)) {
return FALSE;
}
}
//
// If the data buffer is not empty, then return TRUE directly.
// Otherwise initialize a usb read transaction and read data to internal data buffer.
@ -995,7 +969,7 @@ DebugPortPollBuffer (
// Read data as much as we can
//
Length = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, (VOID *)(UINTN)UsbDebugPortHandle->Data, &Length, DATA_TRANSFER_POLL_TIMEOUT);
XhcDataTransfer (Handle, EfiUsbDataIn, (VOID *)(UINTN)UsbDebugPortHandle->Data, &Length, DATA_TRANSFER_POLL_TIMEOUT);
if (Length > XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
return FALSE;
@ -1043,16 +1017,50 @@ DebugPortInitialize (
IN DEBUG_PORT_CONTINUE Function
)
{
RETURN_STATUS Status;
USB3_DEBUG_PORT_HANDLE Handle;
USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
UsbDebugPortHandle = GetUsb3DebugPortInstance ();
if (UsbDebugPortHandle == NULL) {
return NULL;
//
// Validate the PCD PcdDebugPortHandleBufferSize value
//
ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB3_DEBUG_PORT_HANDLE));
if (Function == NULL && Context != NULL) {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Context;
} else {
ZeroMem(&Handle, sizeof (USB3_DEBUG_PORT_HANDLE));
UsbDebugPortHandle = &Handle;
}
if (Function == NULL && Context != NULL) {
return (DEBUG_PORT_HANDLE *) Context;
}
//
// Read 64-bit MMIO base address
//
UsbDebugPortHandle->XhciMmioBase = ProgramXhciBaseAddress ();
Status = CalculateUsbDebugPortMmioBase (UsbDebugPortHandle);
if (RETURN_ERROR (Status)) {
goto Exit;
}
if (NeedReinitializeHardware(&Handle)) {
Status = InitializeUsbDebugHardware (&Handle);
if (RETURN_ERROR(Status)) {
goto Exit;
}
}
Exit:
if (Function != NULL) {
Function (Context, UsbDebugPortHandle);
Function (Context, &Handle);
} else {
CopyMem(&mDebugCommunicationLibUsb3DebugPortHandle, &Handle, sizeof (USB3_DEBUG_PORT_HANDLE));
}
return (DEBUG_PORT_HANDLE)(UINTN)UsbDebugPortHandle;
return (DEBUG_PORT_HANDLE)(UINTN)&mDebugCommunicationLibUsb3DebugPortHandle;
}