From: "Pete Batard" <pete@akeo.ie>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org,
philmd@redhat.com, andrey.warkentin@gmail.com,
samer.el-haj-mahmoud@arm.com
Subject: [edk2-platforms][PATCH 1/5] Platform/RPi: Fix overlap of SoC registers and RAM
Date: Wed, 11 Dec 2019 11:25:48 +0000 [thread overview]
Message-ID: <20191211112552.15900-2-pete@akeo.ie> (raw)
In-Reply-To: <20191211112552.15900-1-pete@akeo.ie>
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Having RAM and SoC register regions overlap is problematic for MMIO,
since, at the very least, we don't want these regions to be declared
as cacheable.
Signed-off-by: Pete Batard <pete@akeo.ie>
---
Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 36 +++++++++++++-------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
index cc761bea1307..781cf78b83d3 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
+++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
@@ -60,7 +60,7 @@ ArmPlatformGetVirtualMemoryMap (
{
UINTN Index = 0;
UINTN GpuIndex;
- INT64 ExtendedMemorySize;
+ INT64 SystemMemorySize;
ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
// Early output of the info we got from VideoCore can prove valuable.
@@ -120,21 +120,21 @@ ArmPlatformGetVirtualMemoryMap (
VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION;
VirtualMemoryInfo[Index++].Name = L"GPU Reserved";
- // Compute the amount of extended RAM available on this platform
- ExtendedMemorySize = SIZE_256MB;
- ExtendedMemorySize <<= (mBoardRevision >> 20) & 0x07;
- ExtendedMemorySize -= SIZE_1GB;
- if (ExtendedMemorySize > 0) {
- VirtualMemoryTable[Index].PhysicalBase = FixedPcdGet64 (PcdExtendedMemoryBase);
- VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
- VirtualMemoryTable[Index].Length = ExtendedMemorySize;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
- VirtualMemoryInfo[Index].Type = RPI_MEM_BASIC_REGION;
- VirtualMemoryInfo[Index++].Name = L"Extended System RAM";
- }
+ // Compute the total RAM size available on this platform
+ SystemMemorySize = SIZE_256MB;
+ SystemMemorySize <<= (mBoardRevision >> 20) & 0x07;
+
+ //
+ // Ensure that what we declare as System Memory doesn't overlap with the
+ // Bcm2836 SoC registers. This can be achieved through a MIN () with the
+ // base address since SystemMemoryBase is 0 (we assert if it isn't).
+ //
+ SystemMemorySize = MIN(SystemMemorySize, BCM2836_SOC_REGISTERS);
// Extended SoC registers (PCIe, genet, ...)
if (BCM2711_SOC_REGISTERS > 0) {
+ // Same overlap protection as above for the Bcm2711 SoC registers
+ SystemMemorySize = MIN(SystemMemorySize, BCM2711_SOC_REGISTERS);
VirtualMemoryTable[Index].PhysicalBase = BCM2711_SOC_REGISTERS;
VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
VirtualMemoryTable[Index].Length = BCM2711_SOC_REGISTER_LENGTH;
@@ -155,6 +155,16 @@ ArmPlatformGetVirtualMemoryMap (
VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION;
VirtualMemoryInfo[Index++].Name = L"SoC Reserved (283x)";
+ // If we have RAM above the 1 GB mark, declare it
+ if (SystemMemorySize - SIZE_1GB > 0) {
+ VirtualMemoryTable[Index].PhysicalBase = FixedPcdGet64 (PcdExtendedMemoryBase);
+ VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase;
+ VirtualMemoryTable[Index].Length = SystemMemorySize - SIZE_1GB;
+ VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+ VirtualMemoryInfo[Index].Type = RPI_MEM_BASIC_REGION;
+ VirtualMemoryInfo[Index++].Name = L"Extended System RAM";
+ }
+
// End of Table
VirtualMemoryTable[Index].PhysicalBase = 0;
VirtualMemoryTable[Index].VirtualBase = 0;
--
2.21.0.windows.1
next prev parent reply other threads:[~2019-12-11 11:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-11 11:25 [edk2-platforms][PATCH 0/5] Add initial Raspberry Pi 4 platform Pete Batard
2019-12-11 11:25 ` Pete Batard [this message]
2019-12-11 12:21 ` [edk2-platforms][PATCH 1/5] Platform/RPi: Fix overlap of SoC registers and RAM Philippe Mathieu-Daudé
2019-12-11 12:39 ` Pete Batard
2019-12-11 11:25 ` [edk2-platforms][PATCH 2/5] Platform/RPi: Don't describe MMIO regions as memory Pete Batard
2019-12-11 12:22 ` Philippe Mathieu-Daudé
2019-12-11 11:25 ` [edk2-platforms][PATCH 3/5] Platform/RPi4: Add initial ACPI tables Pete Batard
2019-12-11 11:25 ` [edk2-platforms][PATCH 4/5] Platform/RPi4: Update ACPI tables for the new platform Pete Batard
2019-12-11 11:25 ` [edk2-platforms][PATCH 5/5] Platform/RPi4: Add base platform files Pete Batard
2019-12-11 16:21 ` [edk2-platforms][PATCH 0/5] Add initial Raspberry Pi 4 platform Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191211112552.15900-2-pete@akeo.ie \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox