summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2023-10-08 17:39:11 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-10-26 18:55:43 +0000
commit601abf5d50ca7e797bf0e3e9f3398cd7225aa30b (patch)
treef231ab6f560a615e2fa8d86c606a36c7c5d57286
parentba5d955e2505e963eaf91f7ba7d7d5db534372ad (diff)
downloadedk2-601abf5d50ca7e797bf0e3e9f3398cd7225aa30b.tar.gz
edk2-601abf5d50ca7e797bf0e3e9f3398cd7225aa30b.tar.bz2
edk2-601abf5d50ca7e797bf0e3e9f3398cd7225aa30b.zip
ArmVirtPkg: introduce DebugLibFdtPL011Uart DXE Runtime instance
Introduce three new DebugLib instances, forked from MdePkg/Library/BaseDebugLibSerialPort. All three instances rely on PL011UartLib rather than SerialPortLib so that they can customize the PL011 UART that the debug messages are written to. All three instances direct the debug output to the first such PL011 UART that *differs* from the one specified in the Device Tree's /chosen node's "stdout-path" property. From these, DxeRuntimeDebugLibFdtPL011Uart is identical to DebugLibFdtPL011UartRam, with the addition that UART access is permanently disabled when the containing DXE_RUNTIME_DRIVER module is notified about exiting boot services. The contexts in which these DebugLib instances run are identical to those in which the corresponding SerialPortLib instances run. The particular original dependency chain is DxeRuntimeDebugLibSerialPort (DXE_RUNTIME_DRIVER) FdtPL011SerialPortLib gEarlyPL011BaseAddressGuid HobLib PL011UartLib and the new dependency chain is DxeRuntimeDebugLibFdtPL011Uart (DXE_RUNTIME_DRIVER) gEarlyPL011BaseAddressGuid HobLib PL011UartLib The ArmVirtPkg DSC files will be switched to the new library instances in a separate patch. This patch is worth viewing with "git show --find-copies-harder". Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Cc: Sami Mujawar <sami.mujawar@arm.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20231008153912.175941-9-lersek@redhat.com> Acked-by: Ard Biesheuvel <ardb@kernel.org> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4577 [lersek@redhat.com: add TianoCore BZ reference]
-rw-r--r--ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf61
-rw-r--r--ArmVirtPkg/Library/DebugLibFdtPL011Uart/Runtime.c88
2 files changed, 149 insertions, 0 deletions
diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf
new file mode 100644
index 0000000000..84e9dbae22
--- /dev/null
+++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf
@@ -0,0 +1,61 @@
+## @file
+# DebugLib instance that produces debug output directly via PL011UartLib.
+#
+# If there are at least two PL011 UARTs in the device tree, and the /chosen
+# node's "stdout-path" property references one PL011 UART, then both raw
+# SerialPortLib IO, and -- via SerialDxe -- UEFI console IO, will occur on that
+# UART; and this DebugLib instance will produce output on a *different* UART.
+#
+# This instance is suitable for DXE_RUNTIME_DRIVER modules. When exiting boot
+# services, UART access is stopped.
+#
+# Copyright (C) Red Hat
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 1.27
+ BASE_NAME = DxeRuntimeDebugLibFdtPL011Uart
+ FILE_GUID = 8A6E0972-81B5-4FF4-BB24-A07748415947
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DebugLib|DXE_RUNTIME_DRIVER
+ CONSTRUCTOR = DxeRuntimeDebugLibFdtPL011UartConstructor
+ DESTRUCTOR = DxeRuntimeDebugLibFdtPL011UartDestructor
+
+[Sources]
+ DebugLib.c
+ Ram.c
+ Ram.h
+ Runtime.c
+ Write.h
+
+[Packages]
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ ArmVirtPkg/ArmVirtPkg.dec
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugPrintErrorLevelLib
+ HobLib # Ram.c
+ PL011UartLib
+ PcdLib
+ PrintLib
+
+[Pcd]
+ gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
+ gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel
+
+[FixedPcd]
+ gArmPlatformTokenSpaceGuid.PL011UartClkInHz
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
+
+[Guids]
+ gEarlyPL011BaseAddressGuid # Ram.c
diff --git a/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Runtime.c b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Runtime.c
new file mode 100644
index 0000000000..de7144739c
--- /dev/null
+++ b/ArmVirtPkg/Library/DebugLibFdtPL011Uart/Runtime.c
@@ -0,0 +1,88 @@
+/** @file
+ Permanently disable the library instance in DXE_RUNTIME_DRIVER modules when
+ exiting boot services.
+
+ Copyright (C) Red Hat
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi/UefiSpec.h>
+
+#include "Ram.h"
+
+STATIC EFI_EVENT mExitBootServicesEvent;
+
+/**
+ Notification function that is triggered when the boot service
+ ExitBootServices() is called.
+
+ @param[in] Event Event whose notification function is being invoked. Here,
+ unused.
+
+ @param[in] Context The pointer to the notification function's context, which
+ is implementation-dependent. Here, unused.
+**/
+STATIC
+VOID
+EFIAPI
+ExitBootServicesNotify (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ mDebugLibFdtPL011UartAddress = 0;
+ mDebugLibFdtPL011UartPermanentStatus = RETURN_ABORTED;
+}
+
+/**
+ Library instance constructor, registering ExitBootServicesNotify().
+
+ @param[in] ImageHandle The firmware-allocated handle for the EFI image.
+
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The operation completed successfully.
+
+ @return Error codes propagated from CreateEvent(); the
+ registration of ExitBootServicesNotify() failed.
+**/
+EFI_STATUS
+EFIAPI
+DxeRuntimeDebugLibFdtPL011UartConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return SystemTable->BootServices->CreateEvent (
+ EVT_SIGNAL_EXIT_BOOT_SERVICES,
+ TPL_CALLBACK,
+ ExitBootServicesNotify,
+ NULL /* NotifyContext */,
+ &mExitBootServicesEvent
+ );
+}
+
+/**
+ Library instance destructor, deregistering ExitBootServicesNotify().
+
+ @param[in] ImageHandle The firmware-allocated handle for the EFI image.
+
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS Library instance tear-down complete.
+
+ @return Error codes propagated from CloseEvent(); the
+ deregistration of ExitBootServicesNotify() failed.
+**/
+EFI_STATUS
+EFIAPI
+DxeRuntimeDebugLibFdtPL011UartDestructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return SystemTable->BootServices->CloseEvent (mExitBootServicesEvent);
+}