X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=SourceLevelDebugPkg%2FLibrary%2FDebugCommunicationLibUsb3%2FDebugCommunicationLibUsb3Common.c;h=37f49ad822f56fb6668bb17d4794db0481e9568d;hp=320998b32a12f68ec385f61f7363da854870acdc;hb=f0c562761f397733e2294c8725512e31c352cb72;hpb=5d6507a14687f133d2ab8643ad274b22e578a907 diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c index 320998b32a..37f49ad822 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c @@ -1,7 +1,7 @@ /** @file Debug Port Library implementation based on usb3 debug port. - Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2014 - 2018, 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 @@ -85,15 +85,15 @@ XhcClearR32Bit( Write the data to the XHCI debug register. @param Handle Debug port handle. - @param Offset The offset of the runtime register. + @param Offset The offset of the debug register. @param Data The data to write. **/ VOID XhcWriteDebugReg ( IN USB3_DEBUG_PORT_HANDLE *Handle, - IN UINT32 Offset, - IN UINT32 Data + IN UINT32 Offset, + IN UINT32 Data ) { EFI_PHYSICAL_ADDRESS DebugCapabilityBase; @@ -116,7 +116,7 @@ XhcWriteDebugReg ( UINT32 XhcReadDebugReg ( IN USB3_DEBUG_PORT_HANDLE *Handle, - IN UINT32 Offset + IN UINT32 Offset ) { UINT32 Data; @@ -129,16 +129,16 @@ XhcReadDebugReg ( } /** - Set one bit of the runtime register while keeping other bits. + Set one bit of the debug register while keeping other bits. @param Handle Debug port handle. - @param Offset The offset of the runtime register. + @param Offset The offset of the debug 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 ) @@ -186,58 +186,6 @@ ProgramXhciBaseAddress ( return XhciMmioBase; } -/** - 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. @@ -268,7 +216,7 @@ UpdateXhcResource ( @param Handle Debug port handle. - @retval RETURN_UNSUPPORTED The usb host controller does not supported usb debug port capability. + @retval RETURN_UNSUPPORTED The usb host controller does not support usb debug port capability. @retval RETURN_SUCCESS Get bar and offset successfully. **/ @@ -352,7 +300,7 @@ Done: Check if it needs to re-initialize usb debug port hardware. During different phases switch, such as SEC to PEI or PEI to DXE or DXE to SMM, we should check - whether the usb debug port hardware configuration is changed. Such case can be triggerred by + whether the usb debug port hardware configuration is changed. Such case can be triggered by Pci bus resource allocation and so on. @param Handle Debug port handle. @@ -808,7 +756,7 @@ Enable: @param Handle Debug port handle. @param Buffer Pointer to the data buffer to store the data read from the debug device. @param NumberOfBytes Number of bytes which will be read. - @param Timeout Timeout value for reading from debug device. It unit is Microsecond. + @param Timeout Timeout value for reading from debug device. Its unit is Microsecond. @retval 0 Read data failed, no data is to be read. @retval >0 Actual number of bytes read from debug device. @@ -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]; - } - UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - (UINT8)Total); - } - - // - // 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 --; - } - } + Data[Index] = Data[Index + 1]; } - 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; + UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1); + return 1; } - return Total; } /** @@ -995,7 +836,7 @@ DebugPortReadBuffer ( @retval 0 NumberOfBytes is 0. @retval >0 The number of bytes written to the debug device. - If this value is less than NumberOfBytes, then the read operation failed. + If this value is less than NumberOfBytes, then the write operation failed. **/ UINTN @@ -1011,7 +852,6 @@ DebugPortWriteBuffer ( UINTN Sent; UINTN Total; EFI_PHYSICAL_ADDRESS XhciMmioBase; - UINTN Index; if (NumberOfBytes == 0 || Buffer == NULL) { return 0; @@ -1054,7 +894,6 @@ DebugPortWriteBuffer ( // DebugPortPollBuffer (Handle); - Index = 0; while ((Total < NumberOfBytes)) { if (NumberOfBytes - Total > USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE) { Sent = USB3_DEBUG_PORT_WRITE_MAX_PACKET_SIZE; @@ -1078,7 +917,7 @@ DebugPortWriteBuffer ( @param Handle Debug port handle. @retval TRUE Data is waiting to be read from the debug device. - @retval FALSE There is no data waiting to be read from the serial device. + @retval FALSE There is no data waiting to be read from the debug device. **/ BOOLEAN @@ -1148,7 +987,7 @@ DebugPortPollBuffer ( /** Initialize the debug port. - If Function is not NULL, Debug Communication Libary will call this function + If Function is not NULL, Debug Communication Library will call this function by passing in the Context to be the first parameter. If needed, Debug Communication Library will create one debug port handle to be the second argument passing in calling the Function, otherwise it will pass NULL to be the second argument of @@ -1156,7 +995,7 @@ DebugPortPollBuffer ( If Function is NULL, and Context is not NULL, the Debug Communication Library could a) Return the same handle as passed in (as Context parameter). - b) Ignore the input Context parameter and create new hanlde to be returned. + b) Ignore the input Context parameter and create new handle to be returned. If parameter Function is NULL and Context is NULL, Debug Communication Library could created a new handle if needed and return it, otherwise it will return NULL. @@ -1179,8 +1018,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 +1031,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; }