From 4cf3f37c87ba1f9d58072444bd735e40e4779e70 Mon Sep 17 00:00:00 2001 From: Star Zeng Date: Tue, 18 Jul 2017 16:32:16 +0800 Subject: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently in SerialRead https://lists.01.org/pipermail/edk2-devel/2017-July/012385.html reported the timeout processing in SerialRead is not consistent. Since SerialPortPoll only checks the status of serial port and returns immediately, and SerialPortRead does not really implement a time out mechanism and will always wait for enough input, it will cause below results: 1. If there is no serial input at all, this interface will return timeout immediately without any waiting; 2. If there is A characters in serial port FIFO, and caller requires A+1 characters, it will wait until a new input is coming and timeout will not really occur. This patch is to update SerialRead() to check SerialPortPoll() and read data through SerialPortRead() one byte by one byte, and check timeout against mSerialIoMode.Timeout if no input. Cc: Heyi Guo Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Ruiyu Ni --- MdeModulePkg/Universal/SerialDxe/SerialIo.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/SerialDxe/SerialIo.c b/MdeModulePkg/Universal/SerialDxe/SerialIo.c index d2383e56dd..43d33dba0c 100644 --- a/MdeModulePkg/Universal/SerialDxe/SerialIo.c +++ b/MdeModulePkg/Universal/SerialDxe/SerialIo.c @@ -465,11 +465,25 @@ SerialRead ( ) { UINTN Count; + UINTN TimeOut; Count = 0; - if (SerialPortPoll ()) { - Count = SerialPortRead (Buffer, *BufferSize); + while (Count < *BufferSize) { + TimeOut = 0; + while (TimeOut < mSerialIoMode.Timeout) { + if (SerialPortPoll ()) { + break; + } + gBS->Stall (10); + TimeOut += 10; + } + if (TimeOut >= mSerialIoMode.Timeout) { + break; + } + SerialPortRead (Buffer, 1); + Count++; + Buffer = (VOID *) ((UINT8 *) Buffer + 1); } if (Count != *BufferSize) {