From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ZKeSrJWb; spf=pass (domain: intel.com, ip: 192.55.52.151, 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=1682682209; x=1714218209; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=3gEDM8c6Ve9rS9IxzuZQEWpCDRe9QEq+sQsgpXUYnec=; b=ZKeSrJWbisFlCG7Ej8iVlRxJczUdiOp3XyP/tw0cbGttbpSD0FOuWPlO nAuFOQAQBZx8z+1NhPltYtsAu6rgpurJ8ftPPXY9ibt0E1pP0RdSiHj9M fvbgbdj3djTfDLZsuQOvAdGHKUktWmWjqkoQZ8RnPIM0y6hUbjdzYFU3r 8bi1I2o4QxC8t4EUjt4to5KcIqpF0hygUEC1AyaoHICMWBNyb9IkSEU6K 87H/YpdHtNfiD30XGJPVbmxpbTmN29atB4oMHkxBV33uR8o/ELaF9H0ky YL88L7Kc40uIdPhWKMSebdKr3HovZAWjz2EK9Dq/2cMZXSPcS6/Dwfl2G A==; 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" 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" 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: [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> 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 | = 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;=0D =0D UART_INFO mUartInfo[MAX_SIZE];=0D -UINT8 mUartCount =3D 0;=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..6106e9a933 --- /dev/null +++ b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c @@ -0,0 +1,56 @@ +/** @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 +=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