From nobody Mon Apr 29 11:01:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+103783+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+103783+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1682698001; cv=none; d=zohomail.com; s=zohoarc; b=KmjUrMKUpuVLJDUeU2Atj2maLmAGa0iBipVdCtG8BS/IXWFMCIGN4hmbfVFPkVYmZ4G7+Neb9ma6MqMOKXs5zsN0jK/Idt+/aGbXiJG8QPDMlrrDWTdHO+aeLmQ9h284N26VxcuwXUO4E/iccARKk5QqS0s/82GyC04mpSZd7Kg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682698001; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Zplat3+fGw9sVkEWos0t7srjIexeiR3YfxTCBimjPrE=; b=nLLzYmIVOoRUdqHc4t/bJSMCT9yEPacBvx+wkvdTIEQ0rYV4kNbJPV7HgOidkDATDmZFr4nIdlH5/3T7lvb+b/6tMzndSunxEvmdNJP96hxy2I1Sr6U3uG3Oh6m345p84KcTEOodqHkkJN3mnWMwggTlWoNIGV1VXQCA2CMkFWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+103783+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168269800152699.39833584082783; Fri, 28 Apr 2023 09:06:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WWCFYY1788612xAj9GyN9c1q; Fri, 28 Apr 2023 09:06:41 -0700 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.16291.1682678810954877365 for ; Fri, 28 Apr 2023 03:46:51 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10693"; a="434002417" X-IronPort-AV: E=Sophos;i="5.99,234,1677571200"; d="scan'208";a="434002417" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2023 03:46:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10693"; a="838808995" X-IronPort-AV: E=Sophos;i="5.99,234,1677571200"; d="scan'208";a="838808995" X-Received: from peijenhx-desk1.gar.corp.intel.com ([10.227.107.12]) by fmsmga001.fm.intel.com with ESMTP; 28 Apr 2023 03:46:48 -0700 From: paytonx.hsieh@intel.com To: devel@edk2.groups.io Cc: PaytonX Hsieh , Guo Dong , Ray Ni , Sean Rhodes , James Lu , Gua Guo Subject: [edk2-devel] [PATCH v2] UefiPayloadPkg: Fix issues when MULTIPLE_DEBUG_PORT_SUPPORT is true Date: Fri, 28 Apr 2023 18:46:45 +0800 Message-Id: <20230428104645.2274-1-paytonx.hsieh@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,paytonx.hsieh@intel.com X-Gm-Message-State: OPJatGClLoBR1XfgQXIPUlwSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1682698001; bh=1oEoibMSSv/GNqvmcwardnwqDhbFZNuDJ+8a3OAZ2vI=; h=Cc:Date:From:Reply-To:Subject:To; b=VYv/7KweAKsui6vOb9N/dE6fQFmpkSi6blHpWJu/jb8BSasK2Ov/X1q53s+BA0ntgEk TH808AGo2wyYy6uaOiFq0kar/Z17rxqHVvhXaGqEgbxOFmHX2WXHRKvTRPgrsjUXR+aL9 QJTtMoS7PCkJohiV8sRK8IFA8jWmTo4lmOQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1682698003561100007 Content-Type: text/plain; charset="utf-8" From: PaytonX Hsieh REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4427 1. Since UART speed is slower than CPU, BIOS need to check the write buffer is empty, to avoid overwrite the buffer content. 2. LPSS UART might disable MMIO space for Windows debug usage during ExitBootServices event. BIOS need to avoid access the MMIO space after ExitBootServices. Cc: Guo Dong Cc: Ray Ni Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Signed-off-by: PaytonX Hsieh --- UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | = 13 +++++ UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c | = 55 ++++++++++++++++++++ UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf | = 41 +++++++++++++++ UefiPayloadPkg/UefiPayloadPkg.dsc | = 11 +++- 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibH= ob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c index 8216195c62..88981a0863 100644 --- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c @@ -53,6 +53,7 @@ typedef struct { =20 UART_INFO mUartInfo[MAX_SIZE]; UINT8 mUartCount =3D 0; +BOOLEAN mBaseSerialPortLibHobAtRuntime =3D FALSE; =20 /** Reads an 8-bit register. If UseMmio is TRUE, then the value is read from @@ -285,6 +286,11 @@ SerialPortWrite ( UseMmio =3D mUartInfo[Count].UseMmio; Stride =3D mUartInfo[Count].RegisterStride; =20 + if (UseMmio && mBaseSerialPortLibHobAtRuntime) { + Count++; + continue; + } + if (BaseAddress =3D=3D 0) { Count++; continue; @@ -294,6 +300,13 @@ SerialPortWrite ( BytesLeft =3D NumberOfBytes; =20 while (BytesLeft !=3D 0) { + // + // Wait for the serial port to be ready, to make sure both the trans= mit FIFO + // and shift register empty. + // + while ((SerialPortReadRegister (BaseAddress, R_UART_LSR, UseMmio, St= ride) & B_UART_LSR_TXRDY) =3D=3D 0) { + } + // // Fill the entire Tx FIFO // diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortL= ibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibH= ob.c new file mode 100644 index 0000000000..dbbc02dcee --- /dev/null +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c @@ -0,0 +1,55 @@ +/** @file + UART Serial Port library functions. + + Copyright (c) 2023, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#include + +extern BOOLEAN mBaseSerialPortLibHobAtRuntime; + +/** + Set mSerialIoUartLibAtRuntime flag as TRUE after ExitBootServices. + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +STATIC +VOID +EFIAPI +BaseSerialPortLibHobExitBootServicesEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + mBaseSerialPortLibHobAtRuntime =3D TRUE; +} + +/** + The constructor function registers a callback for the ExitBootServices e= vent. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval other Either the serial port failed to initialize or the + ExitBootServices event callback registration faile= d. +**/ +EFI_STATUS +EFIAPI +DxeBaseSerialPortLibHobConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_EVENT SerialPortLibHobExitBootServicesEvent; + return SystemTable->BootServices->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, + TPL_NOTIFY, + BaseSerialPortLibHobExitBootServices= Event, + NULL, + &SerialPortLibHobExitBootServicesEve= nt + ); +} diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortL= ibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLi= bHob.inf new file mode 100644 index 0000000000..7bb3a6ae96 --- /dev/null +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.i= nf @@ -0,0 +1,41 @@ +## @file +# SerialPortLib instance for UART information retrieved from bootloader. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeBaseSerialPortLibHob + FILE_GUID =3D c8def0c5-48e7-45b8-8299-485ea2e63b2c + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialPortLib|DXE_CORE DXE_DRIVER DXE= _RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + CONSTRUCTOR =3D DxeBaseSerialPortLibHobConstructor + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + PcdLib + IoLib + HobLib + TimerLib + +[Sources] + DxeBaseSerialPortLibHob.c + BaseSerialPortLibHob.c + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl + +[Guids] + gUniversalPayloadSerialPortInfoGuid diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index 9847f189ff..998d222909 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -256,7 +256,11 @@ SerialPortLib|UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatfor= mHookLibNull.inf !else - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf + !if $(MULTIPLE_DEBUG_PORT_SUPPORT) =3D=3D TRUE + SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSeria= lPortLibHob.inf + !else + SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPo= rtLib16550.inf + !endif PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.i= nf !endif PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/Pla= tformBootManagerLib.inf @@ -313,6 +317,9 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull= .inf DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf +!if $(MULTIPLE_DEBUG_PORT_SUPPORT) =3D=3D TRUE + SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPort= LibHob.inf +!endif =20 [LibraryClasses.common.DXE_CORE] DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull= .inf @@ -617,7 +624,7 @@ !if $(MULTIPLE_DEBUG_PORT_SUPPORT) =3D=3D TRUE DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialP= ort.inf - SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSeri= alPortLibHob.inf + SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseS= erialPortLibHob.inf !endif NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompre= ssLib.inf } --=20 2.39.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#103783): https://edk2.groups.io/g/devel/message/103783 Mute This Topic: https://groups.io/mt/98561852/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-