summaryrefslogtreecommitdiff
path: root/ArmVirtPkg/Library
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2023-10-08 17:39:08 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-10-26 18:55:43 +0000
commit115b59d9c60fffb22eeab2ed467b888e4b24c1dc (patch)
treeb1f405bda5493afce4122c793113d193b405b82a /ArmVirtPkg/Library
parent66046aeb6dfab48122944ae6f8bcc9ddcdc065ff (diff)
downloadedk2-115b59d9c60fffb22eeab2ed467b888e4b24c1dc.zip
edk2-115b59d9c60fffb22eeab2ed467b888e4b24c1dc.tar.gz
edk2-115b59d9c60fffb22eeab2ed467b888e4b24c1dc.tar.bz2
ArmVirtPkg: store separate console and debug PL011 addresses in GUID HOB
PlatformPeiLib produces the EarlyPL011BaseAddress GUID HOB, and FdtPL011SerialPortLib consumes it. Extend the HOB such that it also carry the base address of the PL011 UART meant for DebugLib usage -- namely the first UART that is *not* designated by the /chosen node's "stdout-path" property. Implement this policy in PlatformPeiLib. Note that as far as the SerialPortLib+console UART is concerned, this patch makes no difference. That selection remains consistent with the pre-patch state, and therefore consistent with EarlyFdtPL011SerialPortLib. 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-6-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]
Diffstat (limited to 'ArmVirtPkg/Library')
-rw-r--r--ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c4
-rw-r--r--ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c60
-rw-r--r--ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf1
3 files changed, 49 insertions, 16 deletions
diff --git a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
index 5718b02..20e29e3 100644
--- a/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
+++ b/ArmVirtPkg/Library/FdtPL011SerialPortLib/FdtPL011SerialPortLib.c
@@ -46,7 +46,7 @@ SerialPortInitialize (
{
VOID *Hob;
RETURN_STATUS Status;
- CONST UINT64 *UartBase;
+ CONST EARLY_PL011_BASE_ADDRESS *UartBase;
UINTN SerialBaseAddress;
UINT64 BaudRate;
UINT32 ReceiveFifoDepth;
@@ -70,7 +70,7 @@ SerialPortInitialize (
UartBase = GET_GUID_HOB_DATA (Hob);
- SerialBaseAddress = (UINTN)*UartBase;
+ SerialBaseAddress = (UINTN)UartBase->ConsoleAddress;
if (SerialBaseAddress == 0) {
Status = RETURN_NOT_FOUND;
goto Failed;
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
index d5dcc7c..7ab4aa2 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.c
@@ -9,6 +9,7 @@
#include <PiPei.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
@@ -43,7 +44,7 @@ PlatformPeim (
UINTN FdtSize;
UINTN FdtPages;
UINT64 *FdtHobData;
- UINT64 *UartHobData;
+ EARLY_PL011_BASE_ADDRESS *UartHobData;
FDT_SERIAL_PORTS Ports;
INT32 Node, Prev;
INT32 Parent, Depth;
@@ -72,24 +73,55 @@ PlatformPeim (
UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *UartHobData);
ASSERT (UartHobData != NULL);
- *UartHobData = 0;
+ SetMem (UartHobData, sizeof *UartHobData, 0);
Status = FdtSerialGetPorts (Base, "arm,pl011", &Ports);
if (!EFI_ERROR (Status)) {
- UINT64 UartBase;
-
- //
- // Default to the first port found, but (if there are multiple ports) allow
- // the "/chosen" node to override it. Note that if FdtSerialGetConsolePort()
- // fails, it does not modify UartBase.
- //
- UartBase = Ports.BaseAddress[0];
- if (Ports.NumberOfPorts > 1) {
- FdtSerialGetConsolePort (Base, &UartBase);
+ if (Ports.NumberOfPorts == 1) {
+ //
+ // Just one UART; direct both SerialPortLib+console and DebugLib to it.
+ //
+ UartHobData->ConsoleAddress = Ports.BaseAddress[0];
+ UartHobData->DebugAddress = Ports.BaseAddress[0];
+ } else {
+ UINT64 ConsoleAddress;
+
+ Status = FdtSerialGetConsolePort (Base, &ConsoleAddress);
+ if (EFI_ERROR (Status)) {
+ //
+ // At least two UARTs; but failed to get the console preference. Use the
+ // first UART for SerialPortLib+console, and the second one for
+ // DebugLib.
+ //
+ UartHobData->ConsoleAddress = Ports.BaseAddress[0];
+ UartHobData->DebugAddress = Ports.BaseAddress[1];
+ } else {
+ //
+ // At least two UARTs; and console preference available. Use the
+ // preferred UART for SerialPortLib+console, and *another* UART for
+ // DebugLib.
+ //
+ UartHobData->ConsoleAddress = ConsoleAddress;
+ if (ConsoleAddress == Ports.BaseAddress[0]) {
+ UartHobData->DebugAddress = Ports.BaseAddress[1];
+ } else {
+ UartHobData->DebugAddress = Ports.BaseAddress[0];
+ }
+ }
}
- DEBUG ((DEBUG_INFO, "%a: PL011 UART @ 0x%lx\n", __func__, UartBase));
- *UartHobData = UartBase;
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: PL011 UART (console) @ 0x%lx\n",
+ __func__,
+ UartHobData->ConsoleAddress
+ ));
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: PL011 UART (debug) @ 0x%lx\n",
+ __func__,
+ UartHobData->DebugAddress
+ ));
}
TpmBase = 0;
diff --git a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
index 08a8f23..b867d8b 100644
--- a/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
+++ b/ArmVirtPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
@@ -31,6 +31,7 @@
gArmVirtTokenSpaceGuid.PcdTpm2SupportEnabled
[LibraryClasses]
+ BaseMemoryLib
DebugLib
HobLib
FdtLib