]> xenbits.xensource.com Git - ovmf.git/commitdiff
UefiPayloadPkg: Fix issues when MULTIPLE_DEBUG_PORT_SUPPORT is true
authorPaytonX Hsieh <paytonx.hsieh@intel.com>
Wed, 26 Apr 2023 12:36:56 +0000 (20:36 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 2 May 2023 07:11:21 +0000 (07:11 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4427

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 <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Sean Rhodes <sean@starlabs.systems>
Cc: James Lu <james.lu@intel.com>
Reviewed-by: Gua Guo <gua.guo@intel.com>
Signed-off-by: PaytonX Hsieh <paytonx.hsieh@intel.com>
UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.c
UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c [new file with mode: 0644]
UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf [new file with mode: 0644]
UefiPayloadPkg/UefiPayloadPkg.dsc

index 8216195c62bc660f534d05871489b77a9afa0c6a..82d0dd58550811827c970cd46e1418d6dc3390bc 100644 (file)
@@ -52,7 +52,8 @@ typedef struct {
 } UART_INFO;\r
 \r
 UART_INFO  mUartInfo[MAX_SIZE];\r
-UINT8      mUartCount = 0;\r
+UINT8      mUartCount                     = 0;\r
+BOOLEAN    mBaseSerialPortLibHobAtRuntime = FALSE;\r
 \r
 /**\r
   Reads an 8-bit register. If UseMmio is TRUE, then the value is read from\r
@@ -285,6 +286,11 @@ SerialPortWrite (
     UseMmio     = mUartInfo[Count].UseMmio;\r
     Stride      = mUartInfo[Count].RegisterStride;\r
 \r
+    if (UseMmio && mBaseSerialPortLibHobAtRuntime) {\r
+      Count++;\r
+      continue;\r
+    }\r
+\r
     if (BaseAddress == 0) {\r
       Count++;\r
       continue;\r
@@ -294,6 +300,13 @@ SerialPortWrite (
     BytesLeft  = NumberOfBytes;\r
 \r
     while (BytesLeft != 0) {\r
+      //\r
+      // Wait for the serial port to be ready, to make sure both the transmit FIFO\r
+      // and shift register empty.\r
+      //\r
+      while ((SerialPortReadRegister (BaseAddress, R_UART_LSR, UseMmio, Stride) & B_UART_LSR_TXRDY) == 0) {\r
+      }\r
+\r
       //\r
       // Fill the entire Tx FIFO\r
       //\r
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.c
new file mode 100644 (file)
index 0000000..6106e9a
--- /dev/null
@@ -0,0 +1,56 @@
+/** @file\r
+  UART Serial Port library functions.\r
+\r
+  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+#include <Uefi.h>\r
+\r
+extern BOOLEAN  mBaseSerialPortLibHobAtRuntime;\r
+\r
+/**\r
+  Set mSerialIoUartLibAtRuntime flag as TRUE after ExitBootServices.\r
+\r
+  @param[in]  Event   The Event that is being processed.\r
+  @param[in]  Context The Event Context.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+BaseSerialPortLibHobExitBootServicesEvent (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  mBaseSerialPortLibHobAtRuntime = TRUE;\r
+}\r
+\r
+/**\r
+  The constructor function registers a callback for the ExitBootServices event.\r
+\r
+  @param[in]  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param[in]  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The operation completed successfully.\r
+  @retval other         Either the serial port failed to initialize or the\r
+                        ExitBootServices event callback registration failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeBaseSerialPortLibHobConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_EVENT  SerialPortLibHobExitBootServicesEvent;\r
+\r
+  return SystemTable->BootServices->CreateEvent (\r
+                                      EVT_SIGNAL_EXIT_BOOT_SERVICES,\r
+                                      TPL_NOTIFY,\r
+                                      BaseSerialPortLibHobExitBootServicesEvent,\r
+                                      NULL,\r
+                                      &SerialPortLibHobExitBootServicesEvent\r
+                                      );\r
+}\r
diff --git a/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf b/UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf
new file mode 100644 (file)
index 0000000..7bb3a6a
--- /dev/null
@@ -0,0 +1,41 @@
+## @file\r
+#  SerialPortLib instance for UART information retrieved from bootloader.\r
+#\r
+#  Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeBaseSerialPortLibHob\r
+  FILE_GUID                      = c8def0c5-48e7-45b8-8299-485ea2e63b2c\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = SerialPortLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
+  CONSTRUCTOR                    = DxeBaseSerialPortLibHobConstructor\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  IoLib\r
+  HobLib\r
+  TimerLib\r
+\r
+[Sources]\r
+  DxeBaseSerialPortLibHob.c\r
+  BaseSerialPortLibHob.c\r
+\r
+[Pcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl\r
+\r
+[Guids]\r
+  gUniversalPayloadSerialPortInfoGuid\r
index 9847f189fff509d7b352804457a2f0c90e632419..998d222909223ef36c9fb0bc3e108b721f5b71f4 100644 (file)
   SerialPortLib|UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf\r
   PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf\r
 !else\r
-  SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf\r
+  !if $(MULTIPLE_DEBUG_PORT_SUPPORT) == TRUE\r
+    SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf\r
+  !else\r
+    SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf\r
+  !endif\r
   PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf\r
 !endif\r
   PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf\r
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
   DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull.inf\r
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
+!if $(MULTIPLE_DEBUG_PORT_SUPPORT) == TRUE\r
+  SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf\r
+!endif\r
 \r
 [LibraryClasses.common.DXE_CORE]\r
   DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull.inf\r
     <LibraryClasses>\r
       !if $(MULTIPLE_DEBUG_PORT_SUPPORT) == TRUE\r
         DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf\r
-        SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/BaseSerialPortLibHob.inf\r
+        SerialPortLib|UefiPayloadPkg/Library/BaseSerialPortLibHob/DxeBaseSerialPortLibHob.inf\r
       !endif\r
       NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf\r
   }\r