Files
nix-config/packages/edk2/patches/platforms/0001-Platform-RaspberryPi-Use-PCDs-for-base-addresses-in-.patch
2026-01-07 21:28:20 -06:00

223 lines
8.7 KiB
Diff

From 46b642a3280d98a5db55226295c4e0371dc9dd4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mario=20B=C4=83l=C4=83nic=C4=83?=
<mariobalanica02@gmail.com>
Date: Mon, 11 Dec 2023 06:39:02 +0200
Subject: [PATCH 01/16] Platform/RaspberryPi: Use PCDs for base addresses in
RpiFirmwareDxe
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
All peripheral offsets defined in Bcm2836.h have changed with BCM2712.
Therefore, start moving drivers that we plan on reusing for Pi 5 to
plain PCDs, but keep the old definitions in place as they're still being
used by Pi3/4 ACPI code.
Signed-off-by: Mario Bălănică <mariobalanica02@gmail.com>
---
.../Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 16 +++++++------
.../Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf | 3 ++-
.../PlatformLib/AArch64/RaspberryPiHelper.S | 1 +
Platform/RaspberryPi/RPi3/RPi3.dsc | 5 ++++
Platform/RaspberryPi/RPi4/RPi4.dsc | 5 ++++
Platform/RaspberryPi/RaspberryPi.dec | 1 +
.../Include/IndustryStandard/Bcm2836.h | 9 -------
.../Include/IndustryStandard/Bcm2836Mbox.h | 24 +++++++++++++++++++
8 files changed, 47 insertions(+), 17 deletions(-)
create mode 100644 Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Mbox.h
diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
index 4edec0ad..6fe76e1d 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
@@ -21,11 +21,13 @@
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
-#include <IndustryStandard/Bcm2836.h>
+#include <IndustryStandard/Bcm2836Mbox.h>
#include <IndustryStandard/RpiMbox.h>
#include <Protocol/RpiFirmware.h>
+#define MBOX_BASE_ADDRESS PcdGet64 (PcdFwMailboxBaseAddress)
+
//
// The number of statically allocated buffer pages
//
@@ -51,12 +53,12 @@ DrainMailbox (
//
Tries = 0;
do {
- Val = MmioRead32 (BCM2836_MBOX_BASE_ADDRESS + BCM2836_MBOX_STATUS_OFFSET);
+ Val = MmioRead32 (MBOX_BASE_ADDRESS + BCM2836_MBOX_STATUS_OFFSET);
if (Val & (1U << BCM2836_MBOX_STATUS_EMPTY)) {
return TRUE;
}
ArmDataSynchronizationBarrier ();
- MmioRead32 (BCM2836_MBOX_BASE_ADDRESS + BCM2836_MBOX_READ_OFFSET);
+ MmioRead32 (MBOX_BASE_ADDRESS + BCM2836_MBOX_READ_OFFSET);
} while (++Tries < RPI_MBOX_MAX_TRIES);
return FALSE;
@@ -76,7 +78,7 @@ MailboxWaitForStatusCleared (
//
Tries = 0;
do {
- Val = MmioRead32 (BCM2836_MBOX_BASE_ADDRESS + BCM2836_MBOX_STATUS_OFFSET);
+ Val = MmioRead32 (MBOX_BASE_ADDRESS + BCM2836_MBOX_STATUS_OFFSET);
if ((Val & StatusMask) == 0) {
return TRUE;
}
@@ -121,7 +123,7 @@ MailboxTransaction (
//
// Start the mailbox transaction
//
- MmioWrite32 (BCM2836_MBOX_BASE_ADDRESS + BCM2836_MBOX_WRITE_OFFSET,
+ MmioWrite32 (MBOX_BASE_ADDRESS + BCM2836_MBOX_WRITE_OFFSET,
(UINT32)((UINTN)mDmaBufferBusAddress | Channel));
ArmDataSynchronizationBarrier ();
@@ -139,7 +141,7 @@ MailboxTransaction (
// Read back the result
//
ArmDataSynchronizationBarrier ();
- *Result = MmioRead32 (BCM2836_MBOX_BASE_ADDRESS + BCM2836_MBOX_READ_OFFSET);
+ *Result = MmioRead32 (MBOX_BASE_ADDRESS + BCM2836_MBOX_READ_OFFSET);
ArmDataSynchronizationBarrier ();
return EFI_SUCCESS;
@@ -954,7 +956,7 @@ RpiFirmwareAllocFb (
}
*Pitch = Cmd->Pitch.Pitch;
- *FbBase = Cmd->AllocFb.AlignmentBase - BCM2836_DMA_DEVICE_OFFSET;
+ *FbBase = Cmd->AllocFb.AlignmentBase - PcdGet64 (PcdDmaDeviceOffset);
*FbSize = Cmd->AllocFb.Size;
ReleaseSpinLock (&mMailboxLock);
diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
index a3fc0fa4..08acc4b3 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
@@ -41,7 +41,8 @@
gRaspberryPiFirmwareProtocolGuid ## PRODUCES
[FixedPcd]
- gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+ gRaspberryPiTokenSpaceGuid.PcdFwMailboxBaseAddress
+ gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
[Depex]
TRUE
diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
index 7008aaf8..d3c77be2 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
+++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
@@ -12,6 +12,7 @@
#include <AsmMacroIoLibV8.h>
#include <Library/ArmLib.h>
#include <IndustryStandard/Bcm2836.h>
+#include <IndustryStandard/Bcm2836Mbox.h>
#include <IndustryStandard/RpiMbox.h>
.macro drain
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
index f5361ab9..5e90f421 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -446,6 +446,11 @@
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq2|0x09
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq3|0x09
+ #
+ # Mailbox
+ #
+ gRaspberryPiTokenSpaceGuid.PcdFwMailboxBaseAddress|0x3f00b880
+
## Default Terminal Type
## 0-PCANSI, 1-VT100, 2-VT00+, 3-UTF8, 4-TTYTERM
gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4
diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc
index 4e91eb9a..4ab6a819 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -452,6 +452,11 @@
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq2|0x32
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq3|0x33
+ #
+ # Mailbox
+ #
+ gRaspberryPiTokenSpaceGuid.PcdFwMailboxBaseAddress|0xfe00b880
+
#
# Fixed CPU settings.
#
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
index 6bd16a5a..d0025cf6 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -50,6 +50,7 @@
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq1|0x0|UINT32|0x00000034
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq2|0x0|UINT32|0x00000035
gRaspberryPiTokenSpaceGuid.PcdGicPmuIrq3|0x0|UINT32|0x00000036
+ gRaspberryPiTokenSpaceGuid.PcdFwMailboxBaseAddress|0x0|UINT64|0x00000037
[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
index a930c64a..93d5eee9 100644
--- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
+++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
@@ -57,15 +57,6 @@
#define BCM2836_MBOX_OFFSET 0x0000b880
#define BCM2836_MBOX_BASE_ADDRESS (BCM2836_SOC_REGISTERS + BCM2836_MBOX_OFFSET)
#define BCM2836_MBOX_LENGTH 0x00000024
-#define BCM2836_MBOX_READ_OFFSET 0x00000000
-#define BCM2836_MBOX_STATUS_OFFSET 0x00000018
-#define BCM2836_MBOX_CONFIG_OFFSET 0x0000001c
-#define BCM2836_MBOX_WRITE_OFFSET 0x00000020
-
-#define BCM2836_MBOX_STATUS_FULL 0x1f
-#define BCM2836_MBOX_STATUS_EMPTY 0x1e
-
-#define BCM2836_MBOX_NUM_CHANNELS 16
/* interrupt controller constants */
#define BCM2836_INTC_TIMER_CONTROL_OFFSET 0x00000040
diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Mbox.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Mbox.h
new file mode 100644
index 00000000..f9096548
--- /dev/null
+++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Mbox.h
@@ -0,0 +1,24 @@
+/** @file
+ *
+ * Copyright (c) 2020, Pete Batard <pete@akeo.ie>
+ * Copyright (c) 2023, Mario Bălănică <mariobalanica02@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#ifndef __BCM2836_MBOX_H__
+#define __BCM2836_MBOX_H__
+
+/* Mailbox registers */
+#define BCM2836_MBOX_READ_OFFSET 0x00000000
+#define BCM2836_MBOX_STATUS_OFFSET 0x00000018
+#define BCM2836_MBOX_CONFIG_OFFSET 0x0000001c
+#define BCM2836_MBOX_WRITE_OFFSET 0x00000020
+
+#define BCM2836_MBOX_STATUS_FULL 0x1f
+#define BCM2836_MBOX_STATUS_EMPTY 0x1e
+
+#define BCM2836_MBOX_NUM_CHANNELS 16
+
+#endif /* __BCM2836_MBOX_H__ */
--
2.51.2