From 2adf8dc56d1036eb9f8c00a11620f68d71bf277b Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Mon, 15 Jun 2026 16:24:28 +0100 Subject: [PATCH] ArmVirtPkg: Add early FDT 16550 serial port probe library Fdt16550SerialPortHookLib does not provide a constructor and expects SerialPortLib to call PlatformHookSerialPortInitialize(). Add an early FDT 16550 serial port probe library that invokes the platform serial hook from its constructor. This allows the FDT to be parsed early, the 16550 serial port base address to be extracted, and the serial port PCD to be populated. It is needed during early boot so the serial port memory map can be set up using the populated serial port PCD. The probe library wraps the hook call in its constructor instead of reusing PlatformHookSerialPortInitialize() directly. This avoids duplicate global definitions in modules that already link against the PlatformHookLib instance. Signed-off-by: Sami Mujawar --- .../EarlyFdt16550SerialPortProbeLib.c | 31 +++++++++++++++++++ .../EarlyFdt16550SerialPortProbeLib.inf | 29 +++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c create mode 100644 ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c new file mode 100644 index 0000000000..17d919eb79 --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.c @@ -0,0 +1,31 @@ +/** @file + Early FDT 16550 serial port probe constructor. + + Copyright (c) 2026, ARM Ltd. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +/** + Early constructor to probe the FDT for the 16550 UART base address. + + This constructor invokes the platform serial hook so early boot code can + populate PcdSerialRegisterBase before it is used. + + @retval RETURN_SUCCESS The serial port base address was already + configured or was found and stored. + @retval RETURN_INVALID_PARAMETER A parameter was invalid. + @retval RETURN_NOT_FOUND Serial port information was not found. + @retval RETURN_PROTOCOL_ERROR Invalid serial port information was found + in the device tree. +**/ +RETURN_STATUS +EFIAPI +EarlyFdt16550SerialPortProbeLibConstructor ( + VOID + ) +{ + return PlatformHookSerialPortInitialize (); +} diff --git a/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf new file mode 100644 index 0000000000..bc57ecf921 --- /dev/null +++ b/ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt16550SerialPortProbeLib.inf @@ -0,0 +1,29 @@ +## @file +# Early Platform Probe Library instance for 16550 Uart. +# +# Copyright (c) 2026, ARM Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = EarlyFdt16550SerialPortProbeLib + MODULE_UNI_FILE = Fdt16550SerialPortHookLib.uni + FILE_GUID = 07a000d5-7de7-485f-ab59-a2ce4da5e488 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = NULL|SEC PEI_CORE PEIM + CONSTRUCTOR = EarlyFdt16550SerialPortProbeLibConstructor + +[Sources] + EarlyFdt16550SerialPortProbeLib.c + +[LibraryClasses] + PlatformHookLib + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec