From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=V/hOsQEH; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: paytonx.hsieh@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682678810; x=1714214810; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=FPda6xLvFFRQgPZhCHz7W6roZYlDEwpnO2+POckvNp4=; b=V/hOsQEHgLDP9Vqh/jAx5ZnWJHIJpDPYC4OVsR42aJI2uv9Zr+Uetymq 4MNvjz8r4VYC7cOUv72M4jL9QLdIDfvxcvcK8Xqjzb0x/G1TEYNNGfp36 0BaJsKt9ZcNVEHir5uL9n21fr+YdTL1eHxQfTMeUkgYkZgCq5zyQllgFF mPCCoHDsmVtyOb2Wp/RIPaPsXN8BtfV72X8OFUX2k3MIVyVpWg4tEvM/L 2EycB3SypemPnNsBmdxVQrqCyQy0hsmkqrI4Fc0w7QgGBj7oFGegDoHeB CV6NgZPnjEiR3o86wej/zQWtAeRFdRFyGOwAiGd2qC2ooYSRatd1qFzoN g==; 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" 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" 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: [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> X-Mailer: git-send-email 2.39.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 { =0D UART_INFO mUartInfo[MAX_SIZE];=0D UINT8 mUartCount =3D 0;=0D +BOOLEAN mBaseSerialPortLibHobAtRuntime =3D FALSE;=0D =0D /**=0D Reads an 8-bit register. If UseMmio is TRUE, then the value is read from= =0D @@ -285,6 +286,11 @@ SerialPortWrite ( UseMmio =3D mUartInfo[Count].UseMmio;=0D Stride =3D mUartInfo[Count].RegisterStride;=0D =0D + if (UseMmio && mBaseSerialPortLibHobAtRuntime) {=0D + Count++;=0D + continue;=0D + }=0D +=0D if (BaseAddress =3D=3D 0) {=0D Count++;=0D continue;=0D @@ -294,6 +300,13 @@ SerialPortWrite ( BytesLeft =3D NumberOfBytes;=0D =0D while (BytesLeft !=3D 0) {=0D + //=0D + // Wait for the serial port to be ready, to make sure both the trans= mit FIFO=0D + // and shift register empty.=0D + //=0D + while ((SerialPortReadRegister (BaseAddress, R_UART_LSR, UseMmio, St= ride) & B_UART_LSR_TXRDY) =3D=3D 0) {=0D + }=0D +=0D //=0D // Fill the entire Tx FIFO=0D //=0D 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=0D + UART Serial Port library functions.=0D +=0D + Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +#include =0D +=0D +extern BOOLEAN mBaseSerialPortLibHobAtRuntime;=0D +=0D +/**=0D + Set mSerialIoUartLibAtRuntime flag as TRUE after ExitBootServices.=0D +=0D + @param[in] Event The Event that is being processed.=0D + @param[in] Context The Event Context.=0D +=0D +**/=0D +STATIC=0D +VOID=0D +EFIAPI=0D +BaseSerialPortLibHobExitBootServicesEvent (=0D + IN EFI_EVENT Event,=0D + IN VOID *Context=0D + )=0D +{=0D + mBaseSerialPortLibHobAtRuntime =3D TRUE;=0D +}=0D +=0D +/**=0D + The constructor function registers a callback for the ExitBootServices e= vent.=0D +=0D + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e.=0D + @param[in] SystemTable A pointer to the EFI System Table.=0D +=0D + @retval EFI_SUCCESS The operation completed successfully.=0D + @retval other Either the serial port failed to initialize or the= =0D + ExitBootServices event callback registration faile= d.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +DxeBaseSerialPortLibHobConstructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_EVENT SerialPortLibHobExitBootServicesEvent;=0D + return SystemTable->BootServices->CreateEvent (=0D + EVT_SIGNAL_EXIT_BOOT_SERVICES,=0D + TPL_NOTIFY,=0D + BaseSerialPortLibHobExitBootServices= Event,=0D + NULL,=0D + &SerialPortLibHobExitBootServicesEve= nt=0D + );=0D +}=0D 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=0D +# SerialPortLib instance for UART information retrieved from bootloader.= =0D +#=0D +# Copyright (c) 2023, Intel Corporation. All rights reserved.
=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D DxeBaseSerialPortLibHob=0D + FILE_GUID =3D c8def0c5-48e7-45b8-8299-485ea2e63b2c= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D SerialPortLib|DXE_CORE DXE_DRIVER DXE= _RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER=0D + CONSTRUCTOR =3D DxeBaseSerialPortLibHobConstructor=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D +=0D +[LibraryClasses]=0D + PcdLib=0D + IoLib=0D + HobLib=0D + TimerLib=0D +=0D +[Sources]=0D + DxeBaseSerialPortLibHob.c=0D + BaseSerialPortLibHob.c=0D +=0D +[Pcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl=0D +=0D +[Guids]=0D + gUniversalPayloadSerialPortInfoGuid=0D 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= =0D PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatfor= mHookLibNull.inf=0D !else=0D - SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort= Lib16550.inf=0D + !if $(MULTIPLE_DEBUG_PORT_SUPPORT) =3D=3D TRUE=0D + SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSeria= lPortLibHob.inf=0D + !else=0D + SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPo= rtLib16550.inf=0D + !endif=0D PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.i= nf=0D !endif=0D PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/Pla= tformBootManagerLib.inf=0D @@ -313,6 +317,9 @@ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf=0D DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull= .inf=0D DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.in= f=0D +!if $(MULTIPLE_DEBUG_PORT_SUPPORT) =3D=3D TRUE=0D + SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPort= LibHob.inf=0D +!endif=0D =0D [LibraryClasses.common.DXE_CORE]=0D DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull= .inf=0D @@ -617,7 +624,7 @@ =0D !if $(MULTIPLE_DEBUG_PORT_SUPPORT) =3D=3D TRUE=0D DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialP= ort.inf=0D - SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSeri= alPortLibHob.inf=0D + SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseS= erialPortLibHob.inf=0D !endif=0D NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompre= ssLib.inf=0D }=0D --=20 2.39.2.windows.1