summaryrefslogtreecommitdiff
path: root/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
diff options
context:
space:
mode:
Diffstat (limited to 'SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c')
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c196
1 files changed, 11 insertions, 185 deletions
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
index 320998b32a..7c62bdadfb 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
@@ -187,58 +187,6 @@ ProgramXhciBaseAddress (
}
/**
- Check if the timer is timeout.
-
- @param[in] UsbDebugPortHandle Pointer to USB Debug port handle
- @param[in] Timer The start timer from the begin.
- @param[in] TimeoutTicker Ticker number need time out.
-
- @return TRUE Timer time out occurs.
- @retval FALSE Timer does not time out.
-
-**/
-BOOLEAN
-IsTimerTimeout (
- IN USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle,
- IN UINT64 Timer,
- IN UINT64 TimeoutTicker
- )
-{
- UINT64 CurrentTimer;
- UINT64 Delta;
-
- CurrentTimer = GetPerformanceCounter ();
-
- if (UsbDebugPortHandle->TimerCountDown) {
- //
- // The timer counter counts down. Check for roll over condition.
- //
- if (CurrentTimer < Timer) {
- Delta = Timer - CurrentTimer;
- } else {
- //
- // Handle one roll-over.
- //
- Delta = UsbDebugPortHandle->TimerCycle - (CurrentTimer - Timer);
- }
- } else {
- //
- // The timer counter counts up. Check for roll over condition.
- //
- if (CurrentTimer > Timer) {
- Delta = CurrentTimer - Timer;
- } else {
- //
- // Handle one roll-over.
- //
- Delta = UsbDebugPortHandle->TimerCycle - (Timer - CurrentTimer);
- }
- }
-
- return (BOOLEAN) (Delta >= TimeoutTicker);
-}
-
-/**
Update XHC MMIO base address when MMIO base address is changed.
@param Handle Debug port handle.
@@ -825,25 +773,13 @@ DebugPortReadBuffer (
{
USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
RETURN_STATUS Status;
- UINTN Received;
- UINTN Total;
- UINTN Remaining;
UINT8 Index;
- UINTN Length;
- UINT64 Begin;
- UINT64 TimeoutTicker;
- UINT64 TimerRound;
- EFI_PHYSICAL_ADDRESS XhciMmioBase;
UINT8 *Data;
- if (NumberOfBytes == 0 || Buffer == NULL) {
+ if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {
return 0;
}
- Received = 0;
- Total = 0;
- Remaining = 0;
-
//
// If Handle is NULL, it means memory is ready for use.
// Use global variable to store handle value.
@@ -858,9 +794,6 @@ DebugPortReadBuffer (
return 0;
}
- XhciMmioBase = ProgramXhciBaseAddress ();
- UpdateXhcResource (UsbDebugPortHandle, XhciMmioBase);
-
if (NeedReinitializeHardware(UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
if (RETURN_ERROR(Status)) {
@@ -871,114 +804,22 @@ DebugPortReadBuffer (
Data = (UINT8 *)(UINTN)UsbDebugPortHandle->Data;
//
- // First read data from buffer, then read debug port hw to get received data.
+ // Read data from buffer
//
- if (UsbDebugPortHandle->DataCount > 0) {
- if (NumberOfBytes <= UsbDebugPortHandle->DataCount) {
- Total = NumberOfBytes;
- } else {
- Total = UsbDebugPortHandle->DataCount;
- }
-
- for (Index = 0; Index < Total; Index++) {
- Buffer[Index] = Data[Index];
- }
+ if (UsbDebugPortHandle->DataCount < 1) {
+ return 0;
+ } else {
+ *Buffer = Data[0];
- for (Index = 0; Index < UsbDebugPortHandle->DataCount - Total; Index++) {
- if (Total + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
+ for (Index = 0; Index < UsbDebugPortHandle->DataCount - 1; Index++) {
+ if ((Index + 1) >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
return 0;
}
- Data[Index] = Data[Total + Index];
+ Data[Index] = Data[Index + 1];
}
- UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - (UINT8)Total);
+ UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
+ return 1;
}
-
- //
- // If Timeout is equal to 0, then it means it should always wait until all data required are received.
- //
- Begin = 0;
- TimeoutTicker = 0;
- TimerRound = 0;
- if (Timeout != 0) {
- Begin = GetPerformanceCounter ();
- TimeoutTicker = DivU64x32 (
- MultU64x64 (
- UsbDebugPortHandle->TimerFrequency,
- Timeout
- ),
- 1000000u
- );
- TimerRound = DivU64x64Remainder (
- TimeoutTicker,
- DivU64x32 (UsbDebugPortHandle->TimerCycle, 2),
- &TimeoutTicker
- );
- }
-
- //
- // Read remaining data by executing one or more usb debug transfer transactions at usb debug port hw.
- //
- while (Total < NumberOfBytes) {
- if (Timeout != 0) {
- if (TimerRound == 0) {
- if (IsTimerTimeout (UsbDebugPortHandle, Begin, TimeoutTicker)) {
- //
- // If time out occurs.
- //
- return 0;
- }
- } else {
- if (IsTimerTimeout (UsbDebugPortHandle, Begin, DivU64x32 (UsbDebugPortHandle->TimerCycle, 2))) {
- TimerRound --;
- }
- }
- }
- Remaining = NumberOfBytes - Total;
- if (Remaining >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
- Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
- Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, Buffer + Total, &Received, DATA_TRANSFER_READ_TIMEOUT);
- } else {
- Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
- Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, (VOID *)Data, &Received, DATA_TRANSFER_READ_TIMEOUT);
- UsbDebugPortHandle->DataCount = (UINT8) Received;
-
- if (Remaining <= Received) {
- //
- // The data received are more than required
- //
- Length = (UINT8)Remaining;
- } else {
- //
- // The data received are less than the remaining bytes
- //
- Length = (UINT8)Received;
- }
-
- //
- // Copy required data from the data buffer to user buffer.
- //
- for (Index = 0; Index < Length; Index++) {
- (Buffer + Total)[Index] = Data[Index];
- UsbDebugPortHandle->DataCount--;
- }
-
- //
- // reorder the data buffer to make available data arranged from the beginning of the data buffer.
- //
- for (Index = 0; Index < Received - Length; Index++) {
- if (Length + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
- return 0;
- }
- Data[Index] = Data[Length + Index];
- }
- //
- // fixup the real required length of data.
- //
- Received = Length;
- }
- Total += Received;
- }
- return Total;
}
/**
@@ -1179,8 +1020,6 @@ DebugPortInitialize (
RETURN_STATUS Status;
USB3_DEBUG_PORT_HANDLE Handle;
USB3_DEBUG_PORT_HANDLE *UsbDebugPortHandle;
- UINT64 TimerStartValue;
- UINT64 TimerEndValue;
//
// Validate the PCD PcdDebugPortHandleBufferSize value
@@ -1194,19 +1033,6 @@ DebugPortInitialize (
UsbDebugPortHandle = &Handle;
}
- UsbDebugPortHandle->TimerFrequency = GetPerformanceCounterProperties (
- &TimerStartValue,
- &TimerEndValue
- );
-
- if (TimerEndValue < TimerStartValue) {
- UsbDebugPortHandle->TimerCountDown = TRUE;
- UsbDebugPortHandle->TimerCycle = TimerStartValue - TimerEndValue;
- } else {
- UsbDebugPortHandle->TimerCountDown = FALSE;
- UsbDebugPortHandle->TimerCycle = TimerEndValue - TimerStartValue;
- }
-
if (Function == NULL && Context != NULL) {
return (DEBUG_PORT_HANDLE *) Context;
}