* [PATCH] UefiPayloadPkg/SerialPortLib: Enhance multi port behaviour
@ 2022-12-14 7:20 Kavya
2022-12-14 7:21 ` Guo, Gua
0 siblings, 1 reply; 2+ messages in thread
From: Kavya @ 2022-12-14 7:20 UTC (permalink / raw)
To: devel; +Cc: Kavya, Guo Dong, Ray Ni, James Lu, Gua Guo
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>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Kavya <k.kavyax.sravanthi@intel.com>
---
UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | 37 ++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 809fa2e9c9..84c56bd24d 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,12 @@ 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 +394,10 @@ SerialPortRead (
*DataBuffer = SerialPortReadRegister (BaseAddress, R_UART_RXBUF, UseMmio, Stride);
}
+ if ((!IsNextPort) && (*(--DataBuffer) != '\0')) {
+ return Result;
+ }
+
Count++;
}
@@ -409,10 +425,9 @@ SerialPortPoll (
BOOLEAN UseMmio;
UINT8 Stride;
UINT8 Count;
- BOOLEAN Status;
+ BOOLEAN IsDataReady;
Count = 0;
- Status = FALSE;
while (Count < mUartCount) {
BaseAddress = mUartInfo[Count].BaseAddress;
UseMmio = mUartInfo[Count].UseMmio;
@@ -423,7 +438,7 @@ SerialPortPoll (
continue;
}
- Status = FALSE;
+ IsDataReady = FALSE;
//
// Read the serial port status
@@ -436,7 +451,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 +461,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 +622,14 @@ 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++;
}
--
2.30.2.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] UefiPayloadPkg/SerialPortLib: Enhance multi port behaviour
2022-12-14 7:20 [PATCH] UefiPayloadPkg/SerialPortLib: Enhance multi port behaviour Kavya
@ 2022-12-14 7:21 ` Guo, Gua
0 siblings, 0 replies; 2+ messages in thread
From: Guo, Gua @ 2022-12-14 7:21 UTC (permalink / raw)
To: Sravanthi, K KavyaX, devel@edk2.groups.io; +Cc: Dong, Guo, Ni, Ray, Lu, James
Reviewed-by: Gua Guo <gua.guo@intel.com>
-----Original Message-----
From: Sravanthi, K KavyaX <k.kavyax.sravanthi@intel.com>
Sent: Wednesday, December 14, 2022 3:20 PM
To: devel@edk2.groups.io
Cc: Sravanthi, K KavyaX <k.kavyax.sravanthi@intel.com>; Dong, Guo <guo.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Lu, James <james.lu@intel.com>; Guo, Gua <gua.guo@intel.com>
Subject: [PATCH] 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>
Cc: Gua Guo <gua.guo@intel.com>
Signed-off-by: Kavya <k.kavyax.sravanthi@intel.com>
---
UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | 37 ++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
index 809fa2e9c9..84c56bd24d 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,12 @@ 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 +394,10 @@ SerialPortRead (
*DataBuffer = SerialPortReadRegister (BaseAddress, R_UART_RXBUF, UseMmio, Stride);
}
+ if ((!IsNextPort) && (*(--DataBuffer) != '\0')) {
+ return Result;
+ }
+
Count++;
}
@@ -409,10 +425,9 @@ SerialPortPoll (
BOOLEAN UseMmio;
UINT8 Stride;
UINT8 Count;
- BOOLEAN Status;
+ BOOLEAN IsDataReady;
Count = 0;
- Status = FALSE;
while (Count < mUartCount) {
BaseAddress = mUartInfo[Count].BaseAddress;
UseMmio = mUartInfo[Count].UseMmio;
@@ -423,7 +438,7 @@ SerialPortPoll (
continue;
}
- Status = FALSE;
+ IsDataReady = FALSE;
//
// Read the serial port status
@@ -436,7 +451,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 +461,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 +622,14 @@ 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++;
}
--
2.30.2.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-14 7:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-14 7:20 [PATCH] UefiPayloadPkg/SerialPortLib: Enhance multi port behaviour Kavya
2022-12-14 7:21 ` Guo, Gua
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox