From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.1633.1607656956521594261 for ; Thu, 10 Dec 2020 19:22:37 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=IQDdWmst; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ray.ni@intel.com) IronPort-SDR: TEKfv2ujTDTLpXDabH7xg52sBrfHO5u45KgRL5vNku+pBS41SrqKlGEWJEaLv2nucv7rCEyHKF fmSr9c3TqEnQ== X-IronPort-AV: E=McAfee;i="6000,8403,9831"; a="235968406" X-IronPort-AV: E=Sophos;i="5.78,409,1599548400"; d="scan'208";a="235968406" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Dec 2020 19:22:35 -0800 IronPort-SDR: SG8aHBkc6S6Qy9CGWaNjWxU4KUDNLpC8NtEutFpOL++C7tkMrb5gzRrjM0buLvZy1K7OK9MkhQ XJUp2tN1poOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,409,1599548400"; d="scan'208";a="376262635" Received: from orsmsx604.amr.corp.intel.com ([10.22.229.17]) by orsmga007.jf.intel.com with ESMTP; 10 Dec 2020 19:22:35 -0800 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) 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 19:22:35 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx612.amr.corp.intel.com (10.22.229.25) 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 19:22:35 -0800 Received: from NAM04-CO1-obe.outbound.protection.outlook.com (104.47.45.54) 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 19:22:35 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=beK7/w5eyiGVuO+EF9BpzvTXfHwlmrPMB9PkH+fGJRviTyc42V/QXOzu5QCqzFe2Rb2n9T86DV/mDk6DFadVBwuxy2LSAVEU1dvmUowPSnbIPMePh6ibKzfuxnBaNRJzzOp6AUykNlawEiywN0d9h2pUdKpq5EKhvr0s8d4Si5ou4I9JL89uxj4pXH0CsomNoQSIgJbWVu1mQX4Mxu+iBCrutzIMI13cxWnfHpiwO+17nXPWxV1fFU7DQMzq+9B+ABryMpXQL5pjr5a/2LZQq7XDXuNTTqWiouL5R4iAWQLzkjqjD3oWHOeOVUmj7WD9CcxamXwkWsHFaX72e6bEiA== 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=LWorAowr0PpLQjTP0i1O+jId3y8VLoPTFn6zutO2aMw=; b=V1MiJ3QgNXvoOsJfZgaPtkk96evPFPZLj/BV2dTv+dY0hSOS0PBIWlNBj6VPXAj/Hi8qZsjydCQsh6kXsqXWUBU4XbS9j73dpWWLMVfCFK/lOhUhlP02uNbUBlbiVxs5zn+HPExs/gvuYgoMYrW9lrKCVVMdEArLwCspc5Tw2n5dPPCUlOmpBeTyyfIqGudJifpxo4wlbl/qYXOX3JGylum51GNbG2hUx1weXLHlQ9WsFRJTSMfk9MzUCsQwIHROozp0MKKgN9Fp44fvqfq4ljOKpARUUsCCwQLAsSQeWoyMsi5eHQLAFPJFSfa+rua0uCW3USIZqpL7uy4wFE/iew== 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=LWorAowr0PpLQjTP0i1O+jId3y8VLoPTFn6zutO2aMw=; b=IQDdWmstiJiemJBiPfnkLx8MdunA625p8R1JHZ/VNoBOQhKum1YjRRLqTzM0jYimyxAAJe2RZ7lj6rXgGrr9js5dTvXVFgbftxoJ7LqQM4euRqjguyHZm9soZU+UEMpMKWndp5/LNRdop0eJK7RsqObLTHRKCwaFD8Xkgq+YGDg= Received: from CO1PR11MB4930.namprd11.prod.outlook.com (2603:10b6:303:9b::11) by MWHPR1101MB2367.namprd11.prod.outlook.com (2603:10b6:300:79::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.19; Fri, 11 Dec 2020 03:22:33 +0000 Received: from CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::d18:1234:c1d6:5936]) by CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::d18:1234:c1d6:5936%7]) with mapi id 15.20.3654.017; Fri, 11 Dec 2020 03:22:33 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "Kinney, Michael D" CC: "Wu, Hao A" 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: AQHWz1VGS3jkLappl0KKGAwJ/tb25KnxOr9Q Date: Fri, 11 Dec 2020 03:22:33 +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 X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-reaction: no-action dlp-product: dlpe-windows 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.216] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3437c112-ad85-41e0-77eb-08d89d840019 x-ms-traffictypediagnostic: MWHPR1101MB2367: 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: dE4VGd//YBRX2BXgLetcAzeJVhzLOgRn5qiVYnfY5TFtLfkcE+VUHIfNZCScSICM3K/lxGK6m7Re+USAlCAQQDVSwE85fxOwXuncO6xiNVeHpbCz9Ej1LWPB1bavqiWtmyHZrODqSOo6VZI1F6KNSEjXrHuA8cQ5/h/aaMq/ubSqlK7U6RJDMQ4FS/8zH3EoWjwlG4NrUM9cI4880fbwsSHpQsAqv5v8/pp059nAI+88I1oWSTsmQm/aEuaUpyxEAorrVX8uT0ec+cChz0X9W2FT0+7v7p4nfTGybEfZF1JiOsWIywZz/luY0TCgdhp8CQ5skHb+Rghuk2v5hu6kLPCTXvVRmDtY3bfmDS8d+54g+v8xoXMIqHgDaYm4XjUCXqpoW9U/0c6zFT8YQP2dDg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4930.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(136003)(376002)(346002)(366004)(53546011)(52536014)(2906002)(86362001)(55016002)(4326008)(71200400001)(5660300002)(186003)(8676002)(64756008)(76116006)(966005)(6506007)(8936002)(508600001)(66556008)(66476007)(66946007)(7696005)(107886003)(110136005)(83380400001)(9686003)(26005)(6636002)(33656002)(66446008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?6j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wD3OG?= =?us-ascii?Q?g0tKI27CweflQ/u2uodzGqje0OSCTsNfl1KnZhkHYWzI+yzwgPizuomrMTrL?= =?us-ascii?Q?YfcDGNKGW8NthPeVplYGgQqP1UtaUSAJsKpxPThzUWE=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4930.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3437c112-ad85-41e0-77eb-08d89d840019 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Dec 2020 03:22:33.4543 (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: 8O1iFN0T/der/SUIi07NyMoqrw/uaEKOzT5gFs+K6v/0YFzaU8kbN3EcJIu79xH1/BZj/KO37aMBSVP96+uK8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1101MB2367 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----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 consoles 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/MdeModule= Pkg/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 c= urrent > + // 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 > + // > + Timeout =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 read= y making > + // sure the transmit FIFO, holding register, and shift register are a= ll > + // 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 t= o 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 confi= guration. > + // > + // 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 confi= guration. > + // > + // 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 confi= guration. > + // > + // 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