summaryrefslogtreecommitdiffstats
path: root/UefiPayloadPkg/Library
diff options
context:
space:
mode:
authorKavya <k.kavyax.sravanthi@intel.com>2022-12-20 09:26:59 +0530
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2022-12-20 07:53:41 +0000
commit6937fc8338935a0fcfcaac08a99b229ba4ed17d6 (patch)
treec54947ea7587299ace1ccff5e2d14947f46fc285 /UefiPayloadPkg/Library
parent259e1e046273a3642df5152431a6806c3dc353d0 (diff)
downloadedk2-6937fc8338935a0fcfcaac08a99b229ba4ed17d6.tar.gz
edk2-6937fc8338935a0fcfcaac08a99b229ba4ed17d6.tar.bz2
edk2-6937fc8338935a0fcfcaac08a99b229ba4ed17d6.zip
UefiPayloadPkg/SerialPortLib: Enhance multi port behaviour
Add condition to return success if mUartCount is greater than zero in SerialPortInitialize() to avoid filling mUartInfo with the same hob data when SerialPortInitialize() is called multiple times. Also add proper conditions in SerialPortRead function to read the data properly from multiple UART's. Cc: Guo Dong <guo.dong@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: James Lu <james.lu@intel.com> Reviewed-by: Gua Guo <gua.guo@intel.com> Signed-off-by: Kavya <k.kavyax.sravanthi@intel.com>
Diffstat (limited to 'UefiPayloadPkg/Library')
-rw-r--r--UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 809fa2e9c9..8216195c62 100644
--- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
+++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
@@ -138,6 +138,10 @@ SerialPortInitialize (
BOOLEAN MmioEnable;
UINT8 Value;
+ if (mUartCount > 0) {
+ return RETURN_SUCCESS;
+ }
+
GuidHob = GetFirstGuidHob (&gUniversalPayloadSerialPortInfoGuid);
while (GuidHob != NULL) {
SerialPortInfo = (UNIVERSAL_PAYLOAD_SERIAL_PORT_INFO *)GET_GUID_HOB_DATA (GuidHob);
@@ -329,6 +333,7 @@ SerialPortRead (
{
UINTN BaseAddress;
BOOLEAN UseMmio;
+ BOOLEAN IsNextPort;
UINT8 *DataBuffer;
UINTN BytesLeft;
UINTN Result;
@@ -353,6 +358,7 @@ SerialPortRead (
DataBuffer = Buffer;
BytesLeft = NumberOfBytes;
+ IsNextPort = FALSE;
Mcr = (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio, Stride) & ~B_UART_MCR_RTS);
@@ -367,6 +373,13 @@ SerialPortRead (
//
SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(Mcr | B_UART_MCR_RTS), UseMmio, Stride);
}
+
+ IsNextPort = TRUE;
+ break;
+ }
+
+ if (IsNextPort) {
+ break;
}
if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
@@ -382,6 +395,10 @@ SerialPortRead (
*DataBuffer = SerialPortReadRegister (BaseAddress, R_UART_RXBUF, UseMmio, Stride);
}
+ if ((!IsNextPort) && (*(--DataBuffer) != '\0')) {
+ return Result;
+ }
+
Count++;
}
@@ -409,10 +426,9 @@ SerialPortPoll (
BOOLEAN UseMmio;
UINT8 Stride;
UINT8 Count;
- BOOLEAN Status;
+ BOOLEAN IsDataReady;
- Count = 0;
- Status = FALSE;
+ Count = 0;
while (Count < mUartCount) {
BaseAddress = mUartInfo[Count].BaseAddress;
UseMmio = mUartInfo[Count].UseMmio;
@@ -423,7 +439,7 @@ SerialPortPoll (
continue;
}
- Status = FALSE;
+ IsDataReady = FALSE;
//
// Read the serial port status
@@ -436,7 +452,7 @@ SerialPortPoll (
SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio, Stride) & ~B_UART_MCR_RTS), UseMmio, Stride);
}
- Status = TRUE;
+ IsDataReady = TRUE;
}
if (PcdGetBool (PcdSerialUseHardwareFlowControl)) {
@@ -446,10 +462,14 @@ SerialPortPoll (
SerialPortWriteRegister (BaseAddress, R_UART_MCR, (UINT8)(SerialPortReadRegister (BaseAddress, R_UART_MCR, UseMmio, Stride) | B_UART_MCR_RTS), UseMmio, Stride);
}
+ if (IsDataReady) {
+ return IsDataReady;
+ }
+
Count++;
}
- return Status;
+ return IsDataReady;
}
/**
@@ -603,6 +623,15 @@ SerialPortGetControl (
*Control |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
}
+ if ((((*Control & EFI_SERIAL_OUTPUT_BUFFER_EMPTY) == EFI_SERIAL_OUTPUT_BUFFER_EMPTY) &&
+ ((*Control & EFI_SERIAL_INPUT_BUFFER_EMPTY) != EFI_SERIAL_INPUT_BUFFER_EMPTY)) ||
+ ((*Control & (EFI_SERIAL_DATA_SET_READY | EFI_SERIAL_CLEAR_TO_SEND |
+ EFI_SERIAL_CARRIER_DETECT)) == (EFI_SERIAL_DATA_SET_READY | EFI_SERIAL_CLEAR_TO_SEND |
+ EFI_SERIAL_CARRIER_DETECT)))
+ {
+ return RETURN_SUCCESS;
+ }
+
Count++;
}