From nobody Fri May 3 18:22:21 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+103784+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+103784+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1682698002; cv=none; d=zohomail.com; s=zohoarc; b=JEn5IKb1ENmvVmyuDUqsQVW4/L74DK08quDy4N9pIOLd/Ggar0RzuiEgbNfTdWXRMD1JqpOv4J5yrVOdkoMEMeyUJotnp73545OZ9s3ph7omQIdvn1qmCtr347hcoFTAOHD+DE1Z4zDVm+Ox9yN4vqx+HUa5By2famAgzzCW160= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682698002; 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=CaF6vNaVuR6eAQ2nasnWu0Z1SyhMmGRvIBdKGvmp1xE=; b=memKw6cjzPGxeyEyBEjvJTigygz8x57ulkNKQiQXeSoM6T9YP0ToAP/KtPH9RqTctLYuIl1wm0x4VF+SzG5SLoqEK3E0hvAi86KiuNCIyUvmjyU1JNdpy4LPDirfmWpwbyugyPl/9/BvUQm+PsHVNhRIVXFjDnnt2MGnZt0zhsE= 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+103784+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 1682698002672885.6970301527671; Fri, 28 Apr 2023 09:06:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XFqLYY1788612xGuSbjAw6qn; Fri, 28 Apr 2023 09:06:42 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.17146.1682682209277545089 for ; Fri, 28 Apr 2023 04:43:29 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10693"; a="328061914" X-IronPort-AV: E=Sophos;i="5.99,234,1677571200"; d="scan'208";a="328061914" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2023 04:41:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10693"; a="941067615" X-IronPort-AV: E=Sophos;i="5.99,234,1677571200"; d="scan'208";a="941067615" X-Received: from peijenhx-desk1.gar.corp.intel.com ([10.227.107.12]) by fmsmga006.fm.intel.com with ESMTP; 28 Apr 2023 04:41:03 -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 v3] UefiPayloadPkg: Fix issues when MULTIPLE_DEBUG_PORT_SUPPORT is true Date: Fri, 28 Apr 2023 19:41:01 +0800 Message-Id: <20230428114101.2483-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: SoELUJHP6r4rcBRvrmKBKIX0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1682698002; bh=3myJTZBiZYJooLNZ7p5Ip3/mXewcuHqwgS4ZVTXD/7Y=; h=Cc:Date:From:Reply-To:Subject:To; b=RbM83fC9SIrXCzLGUEiaGh+GYHj5pMlkSZrxlDEaMoknzOp5uXa38JskpAjCog/phOn l39iFeJkd8e00LmyYSIMzjCOwCpreNSQnWFo7i/khMfjDcRoYxwxYVbzvZwh8Y/UB++RS l1M4492LQtFFcVkJn95J7W+dHxkFtM5wMcw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1682698003923100009 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 Reviewed-by: Gua Guo --- UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c | = 15 +++++- UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c | = 56 ++++++++++++++++++++ UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf | = 41 ++++++++++++++ UefiPayloadPkg/UefiPayloadPkg.dsc | = 11 +++- 4 files changed, 120 insertions(+), 3 deletions(-) diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibH= ob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c index 8216195c62..82d0dd5855 100644 --- a/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c @@ -52,7 +52,8 @@ typedef struct { } UART_INFO; =20 UART_INFO mUartInfo[MAX_SIZE]; -UINT8 mUartCount =3D 0; +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..6106e9a933 --- /dev/null +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c @@ -0,0 +1,56 @@ +/** @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 (#103784): https://edk2.groups.io/g/devel/message/103784 Mute This Topic: https://groups.io/mt/98557876/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-