From nobody Sat May 4 21:46:16 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1501835370090456.79363090445236; Fri, 4 Aug 2017 01:29:30 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2D06621D19956; Fri, 4 Aug 2017 01:27:15 -0700 (PDT) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0C04B2095D9CB for ; Fri, 4 Aug 2017 01:27:14 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2017 01:29:26 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by orsmga005.jf.intel.com with ESMTP; 04 Aug 2017 01:29:25 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,320,1498546800"; d="scan'208";a="133496053" From: Star Zeng To: edk2-devel@lists.01.org Date: Fri, 4 Aug 2017 16:29:23 +0800 Message-Id: <1501835363-61956-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg SerialDxe: Process timeout consistently in SerialRead X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Heyi Guo , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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/Uni= versal/SerialDxe/SerialIo.c index d2383e56dd8f..43d33dba0c2a 100644 --- a/MdeModulePkg/Universal/SerialDxe/SerialIo.c +++ b/MdeModulePkg/Universal/SerialDxe/SerialIo.c @@ -465,11 +465,25 @@ SerialRead ( ) { UINTN Count; + UINTN TimeOut; =20 Count =3D 0; =20 - if (SerialPortPoll ()) { - Count =3D SerialPortRead (Buffer, *BufferSize); + while (Count < *BufferSize) { + TimeOut =3D 0; + while (TimeOut < mSerialIoMode.Timeout) { + if (SerialPortPoll ()) { + break; + } + gBS->Stall (10); + TimeOut +=3D 10; + } + if (TimeOut >=3D mSerialIoMode.Timeout) { + break; + } + SerialPortRead (Buffer, 1); + Count++; + Buffer =3D (VOID *) ((UINT8 *) Buffer + 1); } =20 if (Count !=3D *BufferSize) { --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel