]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg SerialDxe: Process timeout consistently in SerialRead
authorStar Zeng <star.zeng@intel.com>
Tue, 18 Jul 2017 08:32:16 +0000 (16:32 +0800)
committerStar Zeng <star.zeng@intel.com>
Tue, 8 Aug 2017 06:16:28 +0000 (14:16 +0800)
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 <heyi.guo@linaro.org>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Universal/SerialDxe/SerialIo.c

index d2383e56dd8f04188d31bbfabbc657297108b9d8..43d33dba0c2ab5a2f9743465ca6d212417dae9d8 100644 (file)
@@ -465,11 +465,25 @@ SerialRead (
   )\r
 {\r
   UINTN Count;\r
+  UINTN TimeOut;\r
 \r
   Count = 0;\r
 \r
-  if (SerialPortPoll ()) {\r
-    Count = SerialPortRead (Buffer, *BufferSize);\r
+  while (Count < *BufferSize) {\r
+    TimeOut = 0;\r
+    while (TimeOut < mSerialIoMode.Timeout) {\r
+      if (SerialPortPoll ()) {\r
+        break;\r
+      }\r
+      gBS->Stall (10);\r
+      TimeOut += 10;\r
+    }\r
+    if (TimeOut >= mSerialIoMode.Timeout) {\r
+      break;\r
+    }\r
+    SerialPortRead (Buffer, 1);\r
+    Count++;\r
+    Buffer = (VOID *) ((UINT8 *) Buffer + 1);\r
   }\r
 \r
   if (Count != *BufferSize) {\r