From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.2942.1607666210814379268 for ; Thu, 10 Dec 2020 21:56:51 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=i+D2nOAQ; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: hao.a.wu@intel.com) IronPort-SDR: UH2CvRznwaJQrHI2BkyEyD4kEE47KJVDaeN7jyWnmJdPjkHS2aVw4GQZCYKXwMAsGJUaNm8Oj8 kT+1zkAa+juw== X-IronPort-AV: E=McAfee;i="6000,8403,9831"; a="170878630" X-IronPort-AV: E=Sophos;i="5.78,410,1599548400"; d="scan'208";a="170878630" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2020 21:56:50 -0800 IronPort-SDR: a59i0r1ECXtYJG+nRl5Vv0Ch9iULxLMPoLRCloUs6tsDwdS1LXo/CGisxNpLbS37BmomxbDHn/ g44EfTfU5GSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,410,1599548400"; d="scan'208";a="553715443" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by orsmga005.jf.intel.com with ESMTP; 10 Dec 2020 21:56:50 -0800 Received: from orsmsx608.amr.corp.intel.com (10.22.229.21) by ORSMSX604.amr.corp.intel.com (10.22.229.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 10 Dec 2020 21:56:49 -0800 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX608.amr.corp.intel.com (10.22.229.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Thu, 10 Dec 2020 21:56:49 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Thu, 10 Dec 2020 21:56:49 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.49) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Thu, 10 Dec 2020 21:56:49 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KOAEGUZqYduJefCROHhqOINJvqHEnvd5qnd2cJQF5QLHgmywC8XR/1Gq6GO+HeL0ej7uwnqVMA55C36SDhGXOjpIR6Ibo6+m0wRQaqt3ayUuFRQBOHpdwpznhJHmMOGfrtz0ZTCOZkxsZWDa40hC4FHNcOkrKxbiG8lI9HLBURPHQNC6xk+yXTE0xqyCsUK8MIya1YASQoKwNrrxWYwtGF6mvy09B6vE6oi7glOXkbssRyxKBgVnyLKjupxCsd27QO140rywLPknrj+79qbulztSlaKovxjWybbBq2TMw4sj8z8k81VaCfo2X9FkhmX3vtCbdi9LhEAXBWyA8X7srg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fsNI6cUXuL7OIu+t6FwCYohuAvpQ7xFPhDBxYo4Lf1U=; b=QCo9BQqXDrx3kyihQTU7ctoGwO2zP/zz11aCeIOEsYXpZG8ki4ihHj5YUzEDypkrVAx5zQToKBlENUAE9mnGwKyKpiJzMlBpl+0j0MEtY5dEPsiiRDZLF2fZfNxXt7b+1+OuTTh0IDdXA/TnHq0+r/46cAW0Ejf/xyoG1nlgKX5S5/OOKGpd7a+2UMLXcahXZh9tGZbW/ikne1SSIneF/vtlfRqTlHyFDrkiWUyLlemYUh1VGUw7Mpyv2LhqZ1jqJHD3Fi11vDayi5vuEVt1zn0Ei/kD+2Xo81qN9I6iJKQIozclj7tDTEubNFQITaPbMxUOz2j43Y/dDkpyZGmpXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fsNI6cUXuL7OIu+t6FwCYohuAvpQ7xFPhDBxYo4Lf1U=; b=i+D2nOAQaTy1r92sUprTOvHNTnOQkMYuQqeljKMwayyy76EcOigQehXkd0FBTA68H/ShmULdCd4sRGGDifdJXbqEqv6dY3R9nj+75NTuJeuda9xNgGZuaexVW9hIscb+pECuu4vsF5gTb9bsPMGnRmKaP5h7lPlRVQv7HmoicTc= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB2036.namprd11.prod.outlook.com (2603:10b6:404:4a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.23; Fri, 11 Dec 2020 05:56:47 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::4cda:993f:ffc1:f169]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::4cda:993f:ffc1:f169%6]) with mapi id 15.20.3654.014; Fri, 11 Dec 2020 05:56:47 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Kinney, Michael D" CC: "Ni, Ray" Subject: Re: [edk2-devel] [Patch 1/1] MdeModulePkg/PciSioSerialDxe: Flush Tx before config change Thread-Topic: [edk2-devel] [Patch 1/1] MdeModulePkg/PciSioSerialDxe: Flush Tx before config change Thread-Index: AQHWz1VHFpxB8ov2SUiLYMEk5ShizqnxZiDA Date: Fri, 11 Dec 2020 05:56:47 +0000 Message-ID: References: <20201211003255.967-1-michael.d.kinney@intel.com> In-Reply-To: <20201211003255.967-1-michael.d.kinney@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.218] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 9adbb21e-2e55-42d1-6a92-08d89d998c1d x-ms-traffictypediagnostic: BN6PR11MB2036: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0Lw0QwsRcahgltR6ZXihnS5cLL9o3d+gr97zOXrcxljqIqtPmpfys4fsIOm5umXl5JGnTvOMYo9HZb8WMw+qCI5MSXdQBHK9+68Cbd5Ks33E+V9rMjSd3pL5nBVWXTL2lVWSYMZ8jAK90KjKzQ7SYWzvmYIvVP+53DMFRxfOSGPteoiK03fawItcsktYutYe3PBjz41BpLi9jf5eu6MszbDLooqTB4fZ1op6vdKxurYRHY2ShesSWs+tZUPzvZNt4rSfdBDM97+7icBJwskZNf/bS040XaHaaX/kkT4zNi1wmg5GQY7+SRuBxzUw1mSierbARdpNs0qrLJ7gKaID2h1x8PMtIUDJOASSrMIxZGLKU+7JnH42MiWkf25ODlwA4od2tGHM8MgxWxFeR/SscQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(346002)(376002)(366004)(86362001)(53546011)(66476007)(76116006)(2906002)(6506007)(186003)(8676002)(7696005)(8936002)(66446008)(26005)(107886003)(55016002)(5660300002)(6636002)(64756008)(9686003)(110136005)(4326008)(66556008)(508600001)(52536014)(71200400001)(83380400001)(66946007)(966005)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?FVcZ119q9tnO/jdX6jeZiF2kkwuUjYNb2v53wTcS1iNG5PLpINwq3B1BFYwc?= =?us-ascii?Q?3scWxTJUhRE5Jz5j0/CYo6mGczacgZfttZ2bhyuRKqR3vEbOGPexk5+BcJj2?= =?us-ascii?Q?19f3KTM+DQB+XQ5uqUsnli5UGTPDS3ZYe01SrgrnVDA+Svo5GrC/hmsGxICL?= =?us-ascii?Q?B0G2ZoggLVCbaacKdqHEnWR8IDrBsRRXV64bdM2qrCWfmIYqvdUOThx3Js7c?= =?us-ascii?Q?kEv5c+jMRBGqJdSBTlGV3WPUPL0z6ePi3XMAHbkrteVsYA/K4c4YlqTNW546?= =?us-ascii?Q?SHIRrHRW0t/MUQtfkVYpdhdxOZhs7FPKSYA3yzMkLwOt13Aoa+4NK37y4LyC?= =?us-ascii?Q?/6g0u5ati2DuSCo7PKM6bPPVbMFga/reYmg+QetxNDH2m8mp3cC+wODycc1o?= =?us-ascii?Q?ZNE2gIDH9i4Idp59GTg90zHBhDXrxy+Brngbilros8kcQjYuA4xur7ramdZs?= =?us-ascii?Q?RYuIfARLt617D2U86gCbaLIlfUcRmi/5VQ4Ckj8sVwOFlk/7l18pLb35UXMq?= =?us-ascii?Q?eCy0KwalaNSsUhph5naXPoEDSfJmHIoezsXnd2K5OYN0UE5aEWJBVN2/sneY?= =?us-ascii?Q?EhgCsAUSc+PPTxsixm3BB9teYHssHEWHUOfe3019ayKf7Lsy22SouCkantMx?= =?us-ascii?Q?MsK5NUaSOeNZirGLaSgNTmCs3Sx+ueYvXpgLK8ptBW6wgnuiuTlHEo9d2ylc?= =?us-ascii?Q?xtkcw8ydW4J84+Wvm4QV4RedMXR/o6esVKLZA2rNwSNFfZQVjAUJwvnjJdGi?= =?us-ascii?Q?QUJCAZUdnDIYwCX9wQYMB9OmmUluuA84l/POJLyqb5hG6grEtxN5OTiQ6M9+?= =?us-ascii?Q?AnnkkIUmmdI50n+LSD8IGvOezGVrWMH59RLpLrvgEimzaZYWzhL47RJx4Fh2?= =?us-ascii?Q?43yxsj7I64EhRwgkjx18BaXN/zJ25Ldi3+HXg6cwqcJ7n8v1HvUEkYAXlZPn?= =?us-ascii?Q?XXmXNZprtLggtWwvL/DtTw8Ne0juVSdSQxjRzqtcqjYbfxPBCNSuJUdkUxhH?= =?us-ascii?Q?sr6Q?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9adbb21e-2e55-42d1-6a92-08d89d998c1d X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Dec 2020 05:56:47.7951 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zY4q1SApggYlF7NU/xLhLNOI6PZ2p3wPcXdGJWf3PvCGKssakz6yc5xiRg9u1hWfyOdoJzcetxJ4+EGs66XPXg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB2036 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hao A Wu Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Michael > D Kinney > Sent: Friday, December 11, 2020 8:33 AM > To: devel@edk2.groups.io > Cc: Wu, Hao A ; Ni, Ray > Subject: [edk2-devel] [Patch 1/1] MdeModulePkg/PciSioSerialDxe: Flush Tx > before config change >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D3114 >=20 > Add logic to flush all UART transmit buffers if there is a config change= from > Reset(), SetAttributes() or SetControl(). > Use a timeout in the flush operation, so the system can continue to boot= if > the transmit buffers can not be flushed for any reason. >=20 > This change prevents lost characters on serial debug logs and serial con= soles > when a config change is made. It also prevents a UART from getting into= a > bad state or reporting error status due to characters being transmitted = at the > same time registers are updated with new communications settings. >=20 > Cc: Hao A Wu > Cc: Ray Ni > Signed-off-by: Michael D Kinney > --- > .../Bus/Pci/PciSioSerialDxe/SerialIo.c | 91 ++++++++++++++++++- > 1 file changed, 90 insertions(+), 1 deletion(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c > b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c > index 8377ffa13c7a..56c5faf5db1f 100644 > --- a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c > +++ b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c > @@ -1,7 +1,7 @@ > /** @file > SerialIo implementation for PCI or SIO UARTs. >=20 > -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -436,6 +436,68 @@ SerialReceiveTransmit ( > return EFI_SUCCESS; > } >=20 > +/** > + Flush the serial hardware transmit FIFO, holding register, and shift = register. > + > + @param SerialDevice The device to flush. > + > + @retval EFI_SUCCESS The transmit FIFO is completely flushed. > + @retval EFI_TIMEOUT A timeout occured waiting for the transmit FIFO= to > flush. > +**/ > +EFI_STATUS > +SerialFlushTransmitFifo ( > + SERIAL_DEV *SerialDevice > + ) > +{ > + SERIAL_PORT_LSR Lsr; > + UINTN Timeout; > + UINTN Elapsed; > + > + // > + // If this is the first time the UART is being configured, then the > + current // UART settings are not known, so compute a timeout to wait > + for the Tx FIFO // assuming the worst case current settings. > + // > + // Timeout =3D (Max Bits per Char) * (Max Pending Chars) / (Slowest B= aud > Rate) > + // Max Bits per Char =3D Start bit + 8 data bits + parity + 2 stop = bits =3D 12 > + // Max Pending Chars =3D Largest Tx FIFO + hold + shift =3D 64 + 1 = + 1 =3D 66 > + // Slowest Reasonable Baud Rate =3D 300 baud > + // Timeout =3D 12 * 66 / 300 =3D 2.64 seconds =3D 2,640,000 uS // T= imeout > + =3D 2640000; > + > + // > + // Use the largest of the computed timeout, the default timeout, and > + the // currently set timeout. > + // > + Timeout =3D MAX (Timeout, SERIAL_PORT_DEFAULT_TIMEOUT); Timeout =3D > MAX > + (Timeout, SerialDevice->SerialMode.Timeout); > + > + // > + // Wait for the shortest time possible for the serial port to be > + ready making // sure the transmit FIFO, holding register, and shift > + register are all // empty. The actual wait time is expected to be > + very small because the // number characters currently in the FIFO > + should be small when a // configuration change is requested. > + // > + // NOTE: Do not use any DEBUG() or REPORT_STATUS_CODE() or any other > + calls // in the rest of this function that may send additional > + characters to this // UART device invalidating the flush operation. > + // > + Elapsed =3D 0; > + Lsr.Data =3D READ_LSR (SerialDevice); > + while (Lsr.Bits.Temt =3D=3D 0 || Lsr.Bits.Thre =3D=3D 0) { > + if (Elapsed >=3D Timeout) { > + return EFI_TIMEOUT; > + } > + gBS->Stall (TIMEOUT_STALL_INTERVAL); > + Elapsed +=3D TIMEOUT_STALL_INTERVAL; > + Lsr.Data =3D READ_LSR (SerialDevice); } > + > + return EFI_SUCCESS; > +} > + > // > // Interface Functions > // > @@ -476,6 +538,15 @@ SerialReset ( >=20 > Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); >=20 > + // > + // Wait for all data to be transmitted before changing the UART > configuration. > + // > + // NOTE: Do not use any DEBUG() or REPORT_STATUS_CODE() or any other > + calls // that may send additional characters to this UART device > + until the UART // configuration change is complete. > + // > + SerialFlushTransmitFifo (SerialDevice); > + > // > // Make sure DLAB is 0. > // > @@ -654,6 +725,15 @@ SerialSetAttributes ( >=20 > Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); >=20 > + // > + // Wait for all data to be transmitted before changing the UART > configuration. > + // > + // NOTE: Do not use any DEBUG() or REPORT_STATUS_CODE() or any other > + calls // that may send additional characters to this UART device > + until the UART // configuration change is complete. > + // > + SerialFlushTransmitFifo (SerialDevice); > + > // > // Put serial port on Divisor Latch Mode > // > @@ -826,6 +906,15 @@ SerialSetControl ( >=20 > Tpl =3D gBS->RaiseTPL (TPL_NOTIFY); >=20 > + // > + // Wait for all data to be transmitted before changing the UART > configuration. > + // > + // NOTE: Do not use any DEBUG() or REPORT_STATUS_CODE() or any other > + calls // that may send additional characters to this UART device > + until the UART // configuration change is complete. > + // > + SerialFlushTransmitFifo (SerialDevice); > + > Mcr.Data =3D READ_MCR (SerialDevice); > Mcr.Bits.DtrC =3D 0; > Mcr.Bits.Rts =3D 0; > -- > 2.29.2.windows.2 >=20 >=20 >=20 >=20 >=20