public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork
@ 2019-11-14 16:07 Pete Batard
  2019-11-14 16:07 ` [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection Pete Batard
                   ` (7 more replies)
  0 siblings, 8 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

The following set of patches lay some of the groundwork needed for the
addition of the Raspberry Pi 4 as a platform.

They are mostly designed at making the common RPi code more generic, by
introducing new PCDs for the elements that are going to vary between Pi
models, as well as introducing early support for the new Bcm2711 SoC in
Silicon.

Some cleanup of the memory init is also applied to make that part more
generic as well as improve long term maintainability.

Regards,

/Pete

Pete Batard (3):
  Silicon/Broadcom: Add Bcm2711 header
  Platform/RPi: Read more variables from VideoCore during early init
  Platform/RPi: Clean up and improve early memory init

Samer El-Haj-Mahmoud (5):
  Platform/RPi: Add model family detection
  Platform/RPi: Replace Bcm283x SoC base register address with a PCD
  Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs
  Platform/RPi: Replace MMCHS1BASE define with a PCD
  Platform/RPi: Replace DW2_USB_BASE_ADDRESS define with a PCD

 Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf   |   3 +
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf                 |   2 +
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf           |   5 +
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwcHw.h                    |   4 +-
 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c         |  64 +++++
 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf       |   6 +-
 Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf                 |   2 +
 Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h              |   1 +
 Platform/RaspberryPi/Include/Library/RPiMem.h                        |  26 ++
 Platform/RaspberryPi/Include/Protocol/RpiFirmware.h                  |   8 +
 Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c     |  94 ++++---
 Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf   |   1 +
 Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S |  75 +++++-
 Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf             |   7 +-
 Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c            | 256 +++++++++++---------
 Platform/RaspberryPi/RPi3/RPi3.dsc                                   |  11 +-
 Platform/RaspberryPi/RaspberryPi.dec                                 |   2 +
 Silicon/Broadcom/Bcm27xx/Bcm27xx.dec                                 |  22 ++
 Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h          |  15 ++
 Silicon/Broadcom/Bcm283x/Bcm283x.dec                                 |  10 +
 Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf       |   4 +-
 Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf                   |   5 +
 Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h          |   7 +-
 Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Sdio.h      |   3 +-
 Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf                 |   4 +
 25 files changed, 464 insertions(+), 173 deletions(-)
 create mode 100644 Platform/RaspberryPi/Include/Library/RPiMem.h
 create mode 100644 Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
 create mode 100644 Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h

-- 
2.21.0.windows.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-14 16:36   ` [edk2-devel] " Michael Brown
  2019-11-18 17:51   ` Leif Lindholm
  2019-11-14 16:07 ` [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD Pete Batard
                   ` (6 subsequent siblings)
  7 siblings, 2 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>

Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.

This uses the board revision to return a numeric value representing
the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).

Knowing the Pi family will help us set the SD card routing when we
introduce support for the Pi 4 and should also be easier to maintain
than if using individual model detection.

Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
RpiFirmwareGetModelName ().

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 64 ++++++++++++++++++++
 Platform/RaspberryPi/Include/Protocol/RpiFirmware.h          |  8 +++
 2 files changed, 72 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
index 9b4aa068857c..dd61ef089ca7 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
  *  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
  *
@@ -595,6 +596,8 @@ RpiFirmwareGetModelName (
     return "Raspberry Pi 3 Model B+";
   case 0x0E:
     return "Raspberry Pi 3 Model A+";
+  case 0x10:
+    return "Raspberry Pi Compute Module 3+";
   case 0x11:
     return "Raspberry Pi 4 Model B";
   default:
@@ -602,6 +605,66 @@ RpiFirmwareGetModelName (
   }
 }
 
+STATIC
+EFI_STATUS
+EFIAPI
+RPiFirmwareGetModelFamily (
+  OUT   UINT32 *ModelFamily
+  )
+{
+  EFI_STATUS                  Status;
+  UINT32                      Revision;
+  UINT32                      ModelId;
+
+  Status = RpiFirmwareGetModelRevision(&Revision);
+  if (EFI_ERROR(Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Could not get the board revision: Status == %r\n",
+      __FUNCTION__, Status));
+    return EFI_DEVICE_ERROR;
+  } else {
+    ModelId = (Revision >> 4) & 0xFF;
+  }
+
+  switch (ModelId) {
+  // www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
+  case 0x00:          // Raspberry Pi Model A
+  case 0x01:          // Raspberry Pi Model B
+  case 0x02:          // Raspberry Pi Model A+
+  case 0x03:          // Raspberry Pi Model B+
+  case 0x06:          // Raspberry Pi Compute Module 1
+  case 0x09:          // Raspberry Pi Zero
+  case 0x0C:          // Raspberry Pi Zero W
+      *ModelFamily = 1;
+      break;
+  case 0x04:          // Raspberry Pi 2 Model B
+      *ModelFamily = 2;
+      break;
+  case 0x08:          // Raspberry Pi 3 Model B
+  case 0x0A:          // Raspberry Pi Compute Module 3
+  case 0x0D:          // Raspberry Pi 3 Model B+
+  case 0x0E:          // Raspberry Pi 3 Model A+
+  case 0x10:          // Raspberry Pi Compute Module 3+
+      *ModelFamily = 3;
+      break;
+  case 0x11:          // Raspberry Pi 4 Model B
+      *ModelFamily = 4;
+      break;
+  default:
+      *ModelFamily = 0;
+      break;
+  }
+
+  if (*ModelFamily == 0) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Unknown Raspberry Pi model family : ModelId == 0x%x\n",
+      __FUNCTION__, ModelId));
+    return EFI_UNSUPPORTED;
+    }
+
+  return EFI_SUCCESS;
+}
+
 STATIC
 CHAR8*
 EFIAPI
@@ -1168,6 +1231,7 @@ STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL mRpiFirmwareProtocol = {
   RpiFirmwareGetModel,
   RpiFirmwareGetModelRevision,
   RpiFirmwareGetModelName,
+  RPiFirmwareGetModelFamily,
   RpiFirmwareGetFirmwareRevision,
   RpiFirmwareGetManufacturerName,
   RpiFirmwareGetCpuName,
diff --git a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h
index e49d6e6132d9..e3287e3c040f 100644
--- a/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h
+++ b/Platform/RaspberryPi/Include/Protocol/RpiFirmware.h
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
  *  Copyright (c) 2016, Linaro Limited. All rights reserved.
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -102,6 +103,12 @@ CHAR8*
   INTN ModelId
   );
 
+typedef
+EFI_STATUS
+(EFIAPI *GET_MODEL_FAMILY) (
+  UINT32 *ModelFamily
+  );
+
 typedef
 EFI_STATUS
 (EFIAPI *GET_FIRMWARE_REVISION) (
@@ -143,6 +150,7 @@ typedef struct {
   GET_MODEL             GetModel;
   GET_MODEL_REVISION    GetModelRevision;
   GET_MODEL_NAME        GetModelName;
+  GET_MODEL_FAMILY      GetModelFamily;
   GET_FIRMWARE_REVISION GetFirmwareRevision;
   GET_MANUFACTURER_NAME GetManufacturerName;
   GET_CPU_NAME          GetCpuName;
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
  2019-11-14 16:07 ` [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-18 16:48   ` Leif Lindholm
  2019-11-14 16:07 ` [edk2-platforms][PATCH 3/8] Silicon/Broadcom: Add Bcm2711 header Pete Batard
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>

Define BCM2836_SOC_REGISTERS from PcdBcm283xRegistersAddress. This is
needed in preparation for adding Raspberry Pi 4 support, since the two
Pi's have a different base addresses for the Bcm283x specific registers.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf | 2 ++
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf               | 2 ++
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf         | 4 ++++
 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf     | 5 ++++-
 Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf               | 2 ++
 Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           | 3 ++-
 Platform/RaspberryPi/RPi3/RPi3.dsc                                 | 6 +++++-
 Silicon/Broadcom/Bcm283x/Bcm283x.dec                               | 7 +++++++
 Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf     | 4 +++-
 Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf                 | 5 +++++
 Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h        | 3 ++-
 Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf               | 4 ++++
 12 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
index 3f0d7b6b9e9d..034c8c449f00 100644
--- a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
@@ -1,5 +1,6 @@
 #/** @file
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) Microsoft Corporation. All rights reserved.
 #
@@ -42,6 +43,7 @@ [Protocols]
 
 [Pcd]
   gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
 
 [Depex]
   gRaspberryPiFirmwareProtocolGuid AND gRaspberryPiConfigAppliedProtocolGuid
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
index 28fc2682b585..4f4fdef4e003 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
@@ -1,5 +1,6 @@
 #/** @file
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -66,6 +67,7 @@ [Pcd]
   gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
   gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes
   gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
 
 [FeaturePcd]
 
diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
index e880c2fb0261..8817f20622d6 100644
--- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
+++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
@@ -1,5 +1,6 @@
 #/** @file
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
 #
@@ -51,5 +52,8 @@ [Protocols]
   gEfiUsb2HcProtocolGuid
   gRaspberryPiFirmwareProtocolGuid
 
+[FixedPcd]
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+
 [Depex]
   gRaspberryPiFirmwareProtocolGuid
diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
index 87bca98fec28..a3fc0fa49a3c 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
@@ -1,5 +1,5 @@
 #/** @file
-#
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
 #
@@ -40,5 +40,8 @@ [LibraryClasses]
 [Protocols]
   gRaspberryPiFirmwareProtocolGuid    ## PRODUCES
 
+[FixedPcd]
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+
 [Depex]
   TRUE
diff --git a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
index 7386ff251864..b99f197bb007 100644
--- a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
+++ b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
@@ -1,5 +1,6 @@
 #/** @file
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) Microsoft Corporation. All rights reserved.
 #
@@ -44,6 +45,7 @@ [Protocols]
 
 [Pcd]
   gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
 
 [Depex]
   gRaspberryPiFirmwareProtocolGuid AND gRaspberryPiConfigAppliedProtocolGuid
diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
index ed986034b957..85462febdd8d 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
+++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
@@ -2,7 +2,7 @@
 #
 #  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
-#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
+#  Copyright (c) 2011-2019, ARM Limited. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -54,6 +54,7 @@ [FixedPcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
 
 [Ppis]
   gArmMpCoreInfoPpiGuid
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
index a0365c5cf606..4e5a9f0b05e6 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -1,6 +1,6 @@
 # @file
 #
-#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
+#  Copyright (c) 2011 - 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2014, Linaro Limited. All rights reserved.
 #  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
 #  Copyright (c) 2017 - 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
@@ -372,6 +372,10 @@ [PcdsFixedAtBuild.common]
   gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00400000
   gArmTokenSpaceGuid.PcdSystemMemorySize|0x3FC00000
 
+  #
+  # Device specific addresses
+  #
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
   ## NS16550 compatible UART
   gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
   gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
index ec62ff27fbb3..5b839b00d286 100644
--- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
+++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
@@ -1,5 +1,6 @@
 ## @file
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,3 +15,9 @@ [Defines]
 
 [Includes]
   Include
+
+[Guids]
+  gBcm283xTokenSpaceGuid = {0x82f36a92, 0xfb7e, 0x43a1, {0xb9, 0x9e, 0x49, 0x13, 0x3f, 0xc7, 0xa4, 0x2e}}
+
+[PcdsFixedAtBuild.common]
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
diff --git a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
index cdce11a51e14..6c58df5c3285 100644
--- a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
+++ b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
@@ -1,5 +1,5 @@
 #/** @file
-#
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
 #  Copyright (c) 2016 Linaro, Ltd. All rights reserved.
 #
@@ -30,6 +30,7 @@ [LibraryClasses]
   UefiBootServicesTableLib
   UefiLib
   UefiDriverEntryPoint
+  PcdLib
 
 [Protocols]
   gHardwareInterruptProtocolGuid  ## PRODUCES
@@ -37,6 +38,7 @@ [Protocols]
 
 [FixedPcd]
   gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
 
 [Depex]
   TRUE
diff --git a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
index cb1695bd2dfc..4481d71aaff0 100644
--- a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
+++ b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
@@ -1,5 +1,6 @@
 #/** @file
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2019 Linaro, Ltd. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -28,6 +29,7 @@ [LibraryClasses]
   IoLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
+  PcdLib
 
 [Protocols]
   gEfiRngProtocolGuid              ## PRODUCES
@@ -35,5 +37,8 @@ [Protocols]
 [Guids]
   gEfiRngAlgorithmRaw
 
+[FixedPcd]
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+
 [Depex]
   TRUE
diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
index 4007301228be..8bd68c234bfd 100644
--- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
+++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
  *  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) 2016, Linaro Limited. All rights reserved.
  *
@@ -13,7 +14,7 @@
 /*
  * Both "core" and SoC perpherals (1M each).
  */
-#define BCM2836_SOC_REGISTERS                               0x3f000000
+#define BCM2836_SOC_REGISTERS                               (FixedPcdGet64 (PcdBcm283xRegistersAddress))
 #define BCM2836_SOC_REGISTER_LENGTH                         0x02000000
 
 /*
diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
index 50da4eb771f3..ff1b5af6db6e 100644
--- a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
+++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
@@ -2,6 +2,7 @@
 #
 #  Manipulate GPIOs.
 #
+#  Copyright (c) 2019, ARM Limited. All rights reserved.
 #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -30,4 +31,7 @@ [LibraryClasses]
   DebugLib
   IoLib
 
+[FixedPcd]
+  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+
 [Guids]
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 3/8] Silicon/Broadcom: Add Bcm2711 header
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
  2019-11-14 16:07 ` [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection Pete Batard
  2019-11-14 16:07 ` [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-18 16:50   ` Leif Lindholm
  2019-11-14 16:07 ` [edk2-platforms][PATCH 4/8] Platform/RPi: Read more variables from VideoCore during early init Pete Batard
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

Bcm2711 is the SoC used by the Raspberry Pi 4. For the most part it
is backward compatible with the Bcm283x SoC used by older models but
some new Bcm2711 registers have been introduced such as the ones for
PCIe.

We therefore introduce a new Bcm27xx module, which contains only the
base address for the new registers for now (set from a PCD as is the
case for Bcm283x) but which should get populated further as we add
support for the Raspberry Pi 4.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Silicon/Broadcom/Bcm27xx/Bcm27xx.dec                        | 22 ++++++++++++++++++++
 Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h | 15 +++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/Silicon/Broadcom/Bcm27xx/Bcm27xx.dec b/Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
new file mode 100644
index 000000000000..815302f6d209
--- /dev/null
+++ b/Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
@@ -0,0 +1,22 @@
+## @file
+#
+#  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  DEC_SPECIFICATION              = 0x0001001A
+  PACKAGE_NAME                   = Bcm27xxPkg
+  PACKAGE_GUID                   = D4B585C5-EBCA-4779-B974-05A3CF2F10C4
+  PACKAGE_VERSION                = 1.0
+
+[Includes]
+  Include
+
+[Guids]
+  gBcm27xxTokenSpaceGuid = {0x44045e56, 0x7056, 0x4be6, {0x88, 0xc0, 0x49, 0x0c, 0x67, 0x90, 0x2f, 0xba}}
+
+[PcdsFixedAtBuild.common]
+  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress|0x0|UINT32|0x00000001
diff --git a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
new file mode 100644
index 000000000000..389667714214
--- /dev/null
+++ b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
@@ -0,0 +1,15 @@
+/** @file
+ *
+ *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>.
+ *
+ *  SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#ifndef __BCM2711_H__
+#define __BCM2711_H__
+
+#define BCM2711_SOC_REGISTERS               (FixedPcdGet64 (PcdBcm27xxRegistersAddress))
+#define BCM2711_SOC_REGISTER_LENGTH         0x02000000
+
+#endif /*__BCM2711_H__ */
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 4/8] Platform/RPi: Read more variables from VideoCore during early init
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
                   ` (2 preceding siblings ...)
  2019-11-14 16:07 ` [edk2-platforms][PATCH 3/8] Silicon/Broadcom: Add Bcm2711 header Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-18 17:11   ` Leif Lindholm
  2019-11-14 16:07 ` [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init Pete Batard
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

Besides the base memory size, we can read the GPU/VideoCore base as
well as the model during early init, which we'll need for improving
the memory mapping.

This patch adds the retrieval of these variables, as well as some
early debug display of their values (which can be useful) and also
removes unused variables such as mGPUMemoryBase and mGPUMemoryLength.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h              |  1 +
 Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 75 ++++++++++++++++++--
 Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c            | 14 +++-
 3 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h
index d3b6f117cfdf..584786a61dfd 100644
--- a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h
+++ b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h
@@ -34,6 +34,7 @@
 #define RPI_MBOX_GET_MAC_ADDRESS                              0x00010003
 #define RPI_MBOX_GET_BOARD_SERIAL                             0x00010004
 #define RPI_MBOX_GET_ARM_MEMSIZE                              0x00010005
+#define RPI_MBOX_GET_VC_MEMSIZE                               0x00010006
 
 #define RPI_MBOX_SET_POWER_STATE                              0x00028001
 
diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
index 36af208d12d8..49a132c722f1 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
+++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
  *  Copyright (c) 2016, Linaro Limited. All rights reserved.
  *  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
  *
@@ -52,24 +53,90 @@ ASM_FUNC (ArmPlatformPeiBootAction)
     ldr     wzr, [x4, #BCM2836_MBOX_READ_OFFSET]
     dmb     ld
 
+    ldr     w0, .Lmembase
+    adr     x2, mSystemMemoryBase
+    str     x0, [x2]
+
     ldr     w0, .Lmemsize
     sub     x0, x0, #1
-    adr     x1, mSystemMemoryEnd
-    str     x0, [x1]
+    adr     x2, mSystemMemoryEnd
+    str     x0, [x2]
+
+    adr     x0, .Lvcinfo_buffer
+    orr     x0, x0, #RPI_MBOX_VC_CHANNEL
+    add     x0, x0, x1
+
+    poll    BCM2836_MBOX_STATUS_FULL
+    str     w0, [x4, #BCM2836_MBOX_WRITE_OFFSET]
+    dmb     sy
+    poll    BCM2836_MBOX_STATUS_EMPTY
+    dmb     sy
+    ldr     wzr, [x4, #BCM2836_MBOX_READ_OFFSET]
+    dmb     ld
+
+    ldr     w0, .Lvcbase
+    adr     x2, mVideoCoreBase
+    str     x0, [x2]
+
+    ldr     w0, .Lvcsize
+    adr     x2, mVideoCoreSize
+    str     x0, [x2]
+
+    adr     x0, .Lrevinfo_buffer
+    orr     x0, x0, #RPI_MBOX_VC_CHANNEL
+    add     x0, x0, x1
+
+    poll    BCM2836_MBOX_STATUS_FULL
+    str     w0, [x4, #BCM2836_MBOX_WRITE_OFFSET]
+    dmb     sy
+    poll    BCM2836_MBOX_STATUS_EMPTY
+    dmb     sy
+    ldr     wzr, [x4, #BCM2836_MBOX_READ_OFFSET]
+    dmb     ld
+
+    ldr     w0, .Lrevision
+    adr     x2, mBoardRevision
+    str     w0, [x2]
+
     ret
 
     .align  4
 .Lmeminfo_buffer:
-    .long   .Lbuffer_size
+    .long   .Lmeminfo_size
     .long   0x0
     .long   RPI_MBOX_GET_ARM_MEMSIZE
     .long   8                           // buf size
     .long   0                           // input len
+.Lmembase:
     .long   0                           // mem base
 .Lmemsize:
     .long   0                           // mem size
     .long   0                           // end tag
-    .set    .Lbuffer_size, . - .Lmeminfo_buffer
+    .set    .Lmeminfo_size, . - .Lmeminfo_buffer
+
+.Lvcinfo_buffer:
+    .long   .Lvcinfo_size
+    .long   0x0
+    .long   RPI_MBOX_GET_VC_MEMSIZE
+    .long   8                           // buf size
+    .long   0                           // input len
+.Lvcbase:
+    .long   0                           // videocore base
+.Lvcsize:
+    .long   0                           // videocore size
+    .long   0                           // end tag
+    .set    .Lvcinfo_size, . - .Lvcinfo_buffer
+
+.Lrevinfo_buffer:
+    .long   .Lrevinfo_size
+    .long   0x0
+    .long   RPI_MBOX_GET_BOARD_REVISION
+    .long   4                           // buf size
+    .long   0                           // input len
+.Lrevision:
+    .long   0                           // revision
+    .long   0                           // end tag
+    .set    .Lrevinfo_size, . - .Lrevinfo_buffer
 
 //UINTN
 //ArmPlatformGetPrimaryCoreMpId (
diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
index 97d5af5260c6..2bfd3f020a6e 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
+++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
@@ -12,9 +12,11 @@
 #include <IndustryStandard/Bcm2836.h>
 #include <Library/PcdLib.h>
 
+UINT64 mSystemMemoryBase;
 extern UINT64 mSystemMemoryEnd;
-extern UINT64 mGPUMemoryBase;
-extern UINT64 mGPUMemoryLength;
+UINT64 mVideoCoreBase;
+UINT64 mVideoCoreSize;
+UINT32 mBoardRevision;
 
 #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
                        FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
@@ -87,6 +89,14 @@ ArmPlatformGetVirtualMemoryMap (
   IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
   )
 {
+  // Early output of the info we got from VideoCore can prove valuable.
+  DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
+  DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
+  DEBUG ((DEBUG_INFO, "VideoCore: 0x%ll08X (Size 0x%ll08X)\n", mVideoCoreBase, mVideoCoreSize));
+
+  ASSERT (mSystemMemoryBase == 0);
+  ASSERT (VirtualMemoryMap != NULL);
+
   RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
     FixedPcdGet64 (PcdSystemMemoryBase);
 
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
                   ` (3 preceding siblings ...)
  2019-11-14 16:07 ` [edk2-platforms][PATCH 4/8] Platform/RPi: Read more variables from VideoCore during early init Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-18 17:20   ` Leif Lindholm
  2019-11-14 16:07 ` [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs Pete Batard
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

This patch improves memory initialization for the Raspberry Pi Platform by:

Using VideoCore mailbox data to reserve only the regions that are actually
mapped. Especially, besides the base RAM size, which was already set using
VideoCore data, we can set the GPU/VideoCore base address as well as the
extended RAM, which is the memory beyond 1 GB that is available on models
such as the Raspberry Pi 4 (for the 2GB or 4GB versions).

Introducing a new PcdExtendedMemoryBase PCD for the base address of the
extended memory region, which currently cannot be retrieved from VideoCore
(MBOX_GET_ARM_MEMSIZE still only returns a single region on Bcm2711).

Introducing a new RpiPlatformGetVirtualMemoryInfo() companion call to
ArmPlatformGetVirtualMemoryMap() that allows us greatly simplify the
registration of each segment in MemoryPeim() as well as making it easier
to maintain for future models.

We also fix SoC register space that should have been marked as reserved
but wasn't until now and remove the unreferenced mSystemMemoryEnd extern
in MemoryInitPeiLib.c.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Include/Library/RPiMem.h                      |  26 +++
 Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c   |  94 ++++----
 Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf |   1 +
 Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           |   3 +
 Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c          | 242 +++++++++++---------
 Platform/RaspberryPi/RaspberryPi.dec                               |   1 +
 6 files changed, 210 insertions(+), 157 deletions(-)

diff --git a/Platform/RaspberryPi/Include/Library/RPiMem.h b/Platform/RaspberryPi/Include/Library/RPiMem.h
new file mode 100644
index 000000000000..0bfc697ed094
--- /dev/null
+++ b/Platform/RaspberryPi/Include/Library/RPiMem.h
@@ -0,0 +1,26 @@
+/** @file
+ *
+ *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
+ *
+ *  SPDX-License-Identifier: BSD-2-Clause-Patent
+ *
+ **/
+
+#ifndef __RPI_MEM_H__
+#define __RPI_MEM_H__
+
+#define RPI_MEM_BASIC_REGION    0
+#define RPI_MEM_RUNTIME_REGION  1
+#define RPI_MEM_RESERVED_REGION 2
+
+typedef struct {
+  CONST CHAR16*                 Name;
+  UINTN                         Type;
+} RPI_MEMORY_REGION_INFO;
+
+VOID
+RpiPlatformGetVirtualMemoryInfo (
+  IN RPI_MEMORY_REGION_INFO** MemoryInfo
+  );
+
+#endif /* __RPI_MEM_H__ */
diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
index 60cf397f8baa..3a0f7e19e993 100644
--- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
+++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
@@ -15,8 +15,7 @@
 #include <Library/HobLib.h>
 #include <Library/MemoryAllocationLib.h>
 #include <Library/PcdLib.h>
-
-extern UINT64 mSystemMemoryEnd;
+#include <Library/RPiMem.h>
 
 VOID
 BuildMemoryTypeInformationHob (
@@ -39,23 +38,32 @@ InitMmu (
   }
 }
 
+STATIC
+VOID
+AddBasicMemoryRegion (
+  IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
+)
+{
+  BuildResourceDescriptorHob (
+    EFI_RESOURCE_SYSTEM_MEMORY,
+    EFI_RESOURCE_ATTRIBUTE_PRESENT |
+    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
+    EFI_RESOURCE_ATTRIBUTE_TESTED,
+    Desc->PhysicalBase,
+    Desc->Length
+  );
+}
+
 STATIC
 VOID
 AddRuntimeServicesRegion (
   IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
 )
 {
-  BuildResourceDescriptorHob (
-    EFI_RESOURCE_SYSTEM_MEMORY,
-    EFI_RESOURCE_ATTRIBUTE_PRESENT |
-    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_TESTED,
-    Desc->PhysicalBase,
-    Desc->Length
-  );
+  AddBasicMemoryRegion (Desc);
 
   BuildMemoryAllocationHob (
     Desc->PhysicalBase,
@@ -70,17 +78,7 @@ AddReservedMemoryRegion (
   IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
   )
 {
-  BuildResourceDescriptorHob (
-    EFI_RESOURCE_SYSTEM_MEMORY,
-    EFI_RESOURCE_ATTRIBUTE_PRESENT |
-    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_TESTED,
-    Desc->PhysicalBase,
-    Desc->Length
-  );
+  AddBasicMemoryRegion (Desc);
 
   BuildMemoryAllocationHob (
     Desc->PhysicalBase,
@@ -89,6 +87,12 @@ AddReservedMemoryRegion (
   );
 }
 
+void (*AddRegion[]) (IN ARM_MEMORY_REGION_DESCRIPTOR *Desc) = {
+  AddBasicMemoryRegion,
+  AddRuntimeServicesRegion,
+  AddReservedMemoryRegion,
+  };
+
 /*++
 
 Routine Description:
@@ -113,36 +117,28 @@ MemoryPeim (
   )
 {
   ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
+  RPI_MEMORY_REGION_INFO       *MemoryInfo;
+  UINTN                        Index;
 
   // Get Virtual Memory Map from the Platform Library
   ArmPlatformGetVirtualMemoryMap (&MemoryTable);
 
-  // Ensure PcdSystemMemorySize has been set
-  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
+  // Get additional info not provided by MemoryTable
+  RpiPlatformGetVirtualMemoryInfo (&MemoryInfo);
 
-  // FD without variable store
-  AddReservedMemoryRegion (&MemoryTable[0]);
-
-  // Variable store.
-  AddRuntimeServicesRegion (&MemoryTable[1]);
-
-  // Trusted Firmware region
-  AddReservedMemoryRegion (&MemoryTable[2]);
-
-  // Usable memory.
-  BuildResourceDescriptorHob (
-    EFI_RESOURCE_SYSTEM_MEMORY,
-    EFI_RESOURCE_ATTRIBUTE_PRESENT |
-    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
-    EFI_RESOURCE_ATTRIBUTE_TESTED,
-    MemoryTable[3].PhysicalBase,
-    MemoryTable[3].Length
-  );
-
-  AddReservedMemoryRegion (&MemoryTable[4]);
+  // Register each memory region
+  for (Index = 0; MemoryTable[Index].Length != 0; Index++) {
+    ASSERT (MemoryInfo[Index].Type < ARRAY_SIZE (AddRegion));
+    DEBUG ((DEBUG_INFO, "%s:\n"
+      "\tPhysicalBase: 0x%lX\n"
+      "\tVirtualBase: 0x%lX\n"
+      "\tLength: 0x%lX\n",
+      MemoryInfo[Index].Name,
+      MemoryTable[Index].PhysicalBase,
+      MemoryTable[Index].VirtualBase,
+      MemoryTable[Index].Length));
+    AddRegion[MemoryInfo[Index].Type] (&MemoryTable[Index]);
+  }
 
   // Build Memory Allocation Hob
   InitMmu (MemoryTable);
diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
index 0084c010936d..d39210c7a4f1 100644
--- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
+++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
@@ -24,6 +24,7 @@ [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
+  Platform/RaspberryPi/RaspberryPi.dec
 
 [LibraryClasses]
   DebugLib
diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
index 85462febdd8d..c0e2a75451c3 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
+++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
@@ -22,6 +22,7 @@ [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
+  Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
   Silicon/Broadcom/Bcm283x/Bcm283x.dec
   Platform/RaspberryPi/RaspberryPi.dec
 
@@ -50,10 +51,12 @@ [FixedPcd]
   gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
   gArmTokenSpaceGuid.PcdSystemMemoryBase
   gArmTokenSpaceGuid.PcdSystemMemorySize
+  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase
   gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
 
 [Ppis]
diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
index 2bfd3f020a6e..1a6a13b9591b 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
+++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
@@ -1,7 +1,9 @@
 /** @file
  *
+ *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
  *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) 2014, Linaro Limited. All rights reserved.
+ *  Copyright (c) 2013-2018, ARM Limited. All rights reserved.
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
  *
@@ -9,8 +11,11 @@
 
 #include <Library/ArmPlatformLib.h>
 #include <Library/DebugLib.h>
-#include <IndustryStandard/Bcm2836.h>
 #include <Library/PcdLib.h>
+#include <Library/RPiMem.h>
+#include <Library/MemoryAllocationLib.h>
+#include <IndustryStandard/Bcm2711.h>
+#include <IndustryStandard/Bcm2836.h>
 
 UINT64 mSystemMemoryBase;
 extern UINT64 mSystemMemoryEnd;
@@ -18,6 +23,13 @@ UINT64 mVideoCoreBase;
 UINT64 mVideoCoreSize;
 UINT32 mBoardRevision;
 
+
+// The total number of descriptors, including the final "end-of-table" descriptor.
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 10
+
+STATIC BOOLEAN                  VirtualMemoryInfoInitialized = FALSE;
+STATIC RPI_MEMORY_REGION_INFO   VirtualMemoryInfo[MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS];
+
 #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
                        FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
                        FixedPcdGet32(PcdFlashNvStorageFtwSpareSize) +  \
@@ -29,49 +41,6 @@ UINT32 mBoardRevision;
 
 #define ATFBase (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize))
 
-STATIC ARM_MEMORY_REGION_DESCRIPTOR RaspberryPiMemoryRegionDescriptor[] = {
-  {
-    /* Firmware Volume. */
-    FixedPcdGet64 (PcdFdBaseAddress), FixedPcdGet64 (PcdFdBaseAddress),
-    FixedPcdGet32 (PcdFdSize) - VariablesSize,
-    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-  },
-  {
-    /* Variables Volume. */
-    VariablesBase, VariablesBase,
-    VariablesSize,
-    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-  },
-  {
-    /* ATF reserved RAM. */
-    ATFBase, ATFBase,
-    FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase,
-    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-  },
-  {
-    /* System RAM. */
-    FixedPcdGet64 (PcdSystemMemoryBase), FixedPcdGet64 (PcdSystemMemoryBase),
-    0,
-    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
-  },
-  {
-    /* Reserved GPU RAM. */
-    0,
-    0,
-    0,
-    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
-  },
-  {
-    /* SOC registers. */
-    BCM2836_SOC_REGISTERS,
-    BCM2836_SOC_REGISTERS,
-    BCM2836_SOC_REGISTER_LENGTH,
-    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
-  },
-  {
-  }
-};
-
 /**
   Return the Virtual Memory Map of your platform
 
@@ -89,6 +58,11 @@ ArmPlatformGetVirtualMemoryMap (
   IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
   )
 {
+  UINTN                         Index = 0;
+  UINTN                         GpuIndex;
+  INT64                         ExtendedMemorySize;
+  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
+
   // Early output of the info we got from VideoCore can prove valuable.
   DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
   DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
@@ -97,68 +71,120 @@ ArmPlatformGetVirtualMemoryMap (
   ASSERT (mSystemMemoryBase == 0);
   ASSERT (VirtualMemoryMap != NULL);
 
-  RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
-    FixedPcdGet64 (PcdSystemMemoryBase);
-
-  RaspberryPiMemoryRegionDescriptor[4].PhysicalBase =
-    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase +
-    RaspberryPiMemoryRegionDescriptor[3].Length;
-
-  RaspberryPiMemoryRegionDescriptor[4].VirtualBase =
-    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
-
-  RaspberryPiMemoryRegionDescriptor[4].Length =
-    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase -
-    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
-
-  DEBUG ((DEBUG_INFO, "FD:\n"
-    "\tPhysicalBase: 0x%lX\n"
-    "\tVirtualBase: 0x%lX\n"
-    "\tLength: 0x%lX\n",
-    RaspberryPiMemoryRegionDescriptor[0].PhysicalBase,
-    RaspberryPiMemoryRegionDescriptor[0].VirtualBase,
-    RaspberryPiMemoryRegionDescriptor[0].Length +
-    RaspberryPiMemoryRegionDescriptor[1].Length));
-
-  DEBUG ((DEBUG_INFO, "Variables (part of FD):\n"
-    "\tPhysicalBase: 0x%lX\n"
-    "\tVirtualBase: 0x%lX\n"
-    "\tLength: 0x%lX\n",
-    RaspberryPiMemoryRegionDescriptor[1].PhysicalBase,
-    RaspberryPiMemoryRegionDescriptor[1].VirtualBase,
-    RaspberryPiMemoryRegionDescriptor[1].Length));
-
-  DEBUG ((DEBUG_INFO, "ATF RAM:\n"
-    "\tPhysicalBase: 0x%lX\n"
-    "\tVirtualBase: 0x%lX\n"
-    "\tLength: 0x%lX\n",
-    RaspberryPiMemoryRegionDescriptor[2].PhysicalBase,
-    RaspberryPiMemoryRegionDescriptor[2].VirtualBase,
-    RaspberryPiMemoryRegionDescriptor[2].Length));
-
-  DEBUG ((DEBUG_INFO, "System RAM:\n"
-    "\tPhysicalBase: 0x%lX\n"
-    "\tVirtualBase: 0x%lX\n"
-    "\tLength: 0x%lX\n",
-    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase,
-    RaspberryPiMemoryRegionDescriptor[3].VirtualBase,
-    RaspberryPiMemoryRegionDescriptor[3].Length));
-
-  DEBUG ((DEBUG_INFO, "GPU Reserved:\n"
-    "\tPhysicalBase: 0x%lX\n"
-    "\tVirtualBase: 0x%lX\n"
-    "\tLength: 0x%lX\n",
-    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase,
-    RaspberryPiMemoryRegionDescriptor[4].VirtualBase,
-    RaspberryPiMemoryRegionDescriptor[4].Length));
-
-  DEBUG ((DEBUG_INFO, "SoC reserved:\n"
-    "\tPhysicalBase: 0x%lX\n"
-    "\tVirtualBase: 0x%lX\n"
-    "\tLength: 0x%lX\n",
-    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase,
-    RaspberryPiMemoryRegionDescriptor[5].VirtualBase,
-    RaspberryPiMemoryRegionDescriptor[5].Length));
-
-  *VirtualMemoryMap = RaspberryPiMemoryRegionDescriptor;
+  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages
+                       (EFI_SIZE_TO_PAGES (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
+                       MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
+  if (VirtualMemoryTable == NULL) {
+    return;
+  }
+
+
+  // Firmware Volume
+  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdFdBaseAddress);
+  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length          = FixedPcdGet32 (PcdFdSize) - VariablesSize;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
+  VirtualMemoryInfo[Index++].Name           = L"FD";
+
+  // Variable Volume
+  VirtualMemoryTable[Index].PhysicalBase    = VariablesBase;
+  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length          = VariablesSize;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+  VirtualMemoryInfo[Index].Type             = RPI_MEM_RUNTIME_REGION;
+  VirtualMemoryInfo[Index++].Name           = L"FD Variables";
+
+  // TF-A reserved RAM
+  VirtualMemoryTable[Index].PhysicalBase    = ATFBase;
+  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length          = FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
+  VirtualMemoryInfo[Index++].Name           = L"TF-A RAM";
+
+  // Base System RAM
+  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdSystemMemoryBase);
+  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length          = mSystemMemoryEnd + 1 - FixedPcdGet64 (PcdSystemMemoryBase);
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
+  VirtualMemoryInfo[Index].Type             = RPI_MEM_BASIC_REGION;
+  VirtualMemoryInfo[Index++].Name           = L"Base System RAM";
+
+  // GPU Reserved
+  GpuIndex = Index;
+  VirtualMemoryTable[Index].PhysicalBase    = mVideoCoreBase;
+  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length          = mVideoCoreSize;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+  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";
+  }
+
+  // Extended SoC registers (PCIe, genet, ...)
+  if (BCM2711_SOC_REGISTERS > 0) {
+    VirtualMemoryTable[Index].PhysicalBase  = BCM2711_SOC_REGISTERS;
+    VirtualMemoryTable[Index].VirtualBase   = VirtualMemoryTable[Index].PhysicalBase;
+    VirtualMemoryTable[Index].Length        = BCM2711_SOC_REGISTER_LENGTH;
+    VirtualMemoryTable[Index].Attributes    = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+    VirtualMemoryInfo[Index].Type           = RPI_MEM_RESERVED_REGION;
+    VirtualMemoryInfo[Index++].Name         = L"SoC Reserved (27xx)";
+  }
+
+  // Base SoC registers
+  VirtualMemoryTable[Index].PhysicalBase    = BCM2836_SOC_REGISTERS;
+  // On the Pi 3 the SoC registers may overlap VideoCore => fix this
+  if (VirtualMemoryTable[GpuIndex].PhysicalBase + VirtualMemoryTable[GpuIndex].Length > VirtualMemoryTable[Index].PhysicalBase) {
+    VirtualMemoryTable[GpuIndex].Length = VirtualMemoryTable[Index].PhysicalBase - VirtualMemoryTable[GpuIndex].PhysicalBase;
+  }
+  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
+  VirtualMemoryTable[Index].Length          = BCM2836_SOC_REGISTER_LENGTH;
+  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
+  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
+  VirtualMemoryInfo[Index++].Name           = L"SoC Reserved (283x)";
+
+  // End of Table
+  VirtualMemoryTable[Index].PhysicalBase    = 0;
+  VirtualMemoryTable[Index].VirtualBase     = 0;
+  VirtualMemoryTable[Index].Length          = 0;
+  VirtualMemoryTable[Index++].Attributes    = (ARM_MEMORY_REGION_ATTRIBUTES)0;
+
+  ASSERT(Index <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
+
+  *VirtualMemoryMap = VirtualMemoryTable;
+  VirtualMemoryInfoInitialized = TRUE;
+}
+
+/**
+  Return additional memory info not populated by the above call.
+
+  This call should follow the one to ArmPlatformGetVirtualMemoryMap ().
+
+**/
+VOID
+RpiPlatformGetVirtualMemoryInfo (
+  IN RPI_MEMORY_REGION_INFO** MemoryInfo
+  )
+{
+  ASSERT (VirtualMemoryInfo != NULL);
+
+  if (!VirtualMemoryInfoInitialized) {
+    DEBUG ((DEBUG_ERROR,
+      "ArmPlatformGetVirtualMemoryMap must be called before RpiPlatformGetVirtualMemoryInfo.\n"));
+    return;
+  }
+
+  *MemoryInfo = VirtualMemoryInfo;
 }
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
index 3e9171eccb13..c7e17350544a 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -42,6 +42,7 @@ [PcdsFixedAtBuild.common]
   gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000005
   gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
   gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
+  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
 
 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
   gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
                   ` (4 preceding siblings ...)
  2019-11-14 16:07 ` [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-18 11:13   ` Philippe Mathieu-Daudé
  2019-11-14 16:07 ` [edk2-platforms][PATCH 7/8] Platform/RPi: Replace MMCHS1BASE define with a PCD Pete Batard
  2019-11-14 16:07 ` [edk2-platforms][PATCH 8/8] Platform/RPi: Replace DW2_USB_BASE_ADDRESS " Pete Batard
  7 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>

Set BCM2836_WDOG_BASE_ADDRESS and BCM2836_MBOX_BASE_ADDRESS to
using PCDs instead of hard-coded addresses. This is needed in
preparation for adding Raspberry Pi 4 support.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf | 1 +
 Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf       | 1 +
 Platform/RaspberryPi/RPi3/RPi3.dsc                             | 3 +++
 Silicon/Broadcom/Bcm283x/Bcm283x.dec                           | 2 ++
 Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h    | 4 ++--
 5 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
index a3fc0fa49a3c..527cee8bacc1 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
@@ -42,6 +42,7 @@ [Protocols]
 
 [FixedPcd]
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress
 
 [Depex]
   TRUE
diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
index c0e2a75451c3..f627fca2e406 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
+++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
@@ -58,6 +58,7 @@ [FixedPcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
   gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress
 
 [Ppis]
   gArmMpCoreInfoPpiGuid
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
index 4e5a9f0b05e6..88af37e6edaa 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -376,6 +376,9 @@ [PcdsFixedAtBuild.common]
   # Device specific addresses
   #
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
+  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x3f00b880
+  gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x3f100000
+
   ## NS16550 compatible UART
   gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
   gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
index 5b839b00d286..fe1907cb8cf1 100644
--- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
+++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
@@ -21,3 +21,5 @@ [Guids]
 
 [PcdsFixedAtBuild.common]
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
+  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x0|UINT32|0x00000002
+  gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x0|UINT32|0x00000003
diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
index 8bd68c234bfd..6bc21f0ddcf8 100644
--- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
+++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
@@ -23,7 +23,7 @@
 #define BCM2836_DMA_DEVICE_OFFSET                           0xc0000000
 
 /* watchdog constants */
-#define BCM2836_WDOG_BASE_ADDRESS                           0x3f100000
+#define BCM2836_WDOG_BASE_ADDRESS                           (FixedPcdGet64 (PcdWdogBaseAddress))
 #define BCM2836_WDOG_PASSWORD                               0x5a000000
 #define BCM2836_WDOG_RSTC_OFFSET                            0x0000001c
 #define BCM2836_WDOG_WDOG_OFFSET                            0x00000024
@@ -31,7 +31,7 @@
 #define BCM2836_WDOG_RSTC_WRCFG_FULL_RESET                  0x00000020
 
 /* mailbox interface constants */
-#define BCM2836_MBOX_BASE_ADDRESS                           0x3f00b880
+#define BCM2836_MBOX_BASE_ADDRESS                           (FixedPcdGet64 (PcdMboxBaseAddress))
 #define BCM2836_MBOX_READ_OFFSET                            0x00000000
 #define BCM2836_MBOX_STATUS_OFFSET                          0x00000018
 #define BCM2836_MBOX_CONFIG_OFFSET                          0x0000001c
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 7/8] Platform/RPi: Replace MMCHS1BASE define with a PCD
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
                   ` (5 preceding siblings ...)
  2019-11-14 16:07 ` [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  2019-11-14 16:07 ` [edk2-platforms][PATCH 8/8] Platform/RPi: Replace DW2_USB_BASE_ADDRESS " Pete Batard
  7 siblings, 0 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>

Replace MMCHS1BASE with PcdMmcHs1BaseAddress. This is
needed in preparation for adding Raspberry Pi 4 support

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf | 1 +
 Platform/RaspberryPi/RPi3/RPi3.dsc                                 | 1 +
 Silicon/Broadcom/Bcm283x/Bcm283x.dec                               | 1 +
 Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Sdio.h    | 3 ++-
 4 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
index 034c8c449f00..0d7c57152107 100644
--- a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
@@ -44,6 +44,7 @@ [Protocols]
 [Pcd]
   gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+  gBcm283xTokenSpaceGuid.PcdMmcHs1BaseAddress
 
 [Depex]
   gRaspberryPiFirmwareProtocolGuid AND gRaspberryPiConfigAppliedProtocolGuid
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
index 88af37e6edaa..059549068e02 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -378,6 +378,7 @@ [PcdsFixedAtBuild.common]
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
   gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x3f00b880
   gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x3f100000
+  gBcm283xTokenSpaceGuid.PcdMmcHs1BaseAddress|0x3f300000
 
   ## NS16550 compatible UART
   gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
index fe1907cb8cf1..5053077e6448 100644
--- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
+++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
@@ -23,3 +23,4 @@ [PcdsFixedAtBuild.common]
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
   gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x0|UINT32|0x00000002
   gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x0|UINT32|0x00000003
+  gBcm283xTokenSpaceGuid.PcdMmcHs1BaseAddress|0x0|UINT32|0x00000004
diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Sdio.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Sdio.h
index fb0d02904156..ac2581d4cb64 100644
--- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Sdio.h
+++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836Sdio.h
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
  *  Copyright (c) Microsoft Corporation. All rights reserved.
  *
  *  SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -10,7 +11,7 @@
 #define __BCM2836_SDIO_H__
 
 //MMC/SD/SDIO1 register definitions.
-#define MMCHS1BASE        0x3F300000
+#define MMCHS1BASE        (FixedPcdGet64 (PcdMmcHs1BaseAddress))
 
 #define MMCHS_BLK         (MMCHS1BASE + 0x4)
 #define BLEN_512BYTES     (0x200UL << 0)
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [edk2-platforms][PATCH 8/8] Platform/RPi: Replace DW2_USB_BASE_ADDRESS define with a PCD
  2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
                   ` (6 preceding siblings ...)
  2019-11-14 16:07 ` [edk2-platforms][PATCH 7/8] Platform/RPi: Replace MMCHS1BASE define with a PCD Pete Batard
@ 2019-11-14 16:07 ` Pete Batard
  7 siblings, 0 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:07 UTC (permalink / raw)
  To: devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>

Replace DW2_USB_BASE_ADDRESS with PcdDw2UsbBaseAddress. This is
needed in preparation for adding Raspberry Pi 4 support.

Signed-off-by: Pete Batard <pete@akeo.ie>
---
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf | 1 +
 Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwcHw.h          | 4 ++--
 Platform/RaspberryPi/RPi3/RPi3.dsc                         | 1 +
 Platform/RaspberryPi/RaspberryPi.dec                       | 1 +
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
index 8817f20622d6..dc50f955f2fb 100644
--- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
+++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
@@ -54,6 +54,7 @@ [Protocols]
 
 [FixedPcd]
   gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
+  gRaspberryPiTokenSpaceGuid.PcdDw2UsbBaseAddress
 
 [Depex]
   gRaspberryPiFirmwareProtocolGuid
diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwcHw.h b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwcHw.h
index 88fd93934fd3..17daef60f967 100644
--- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwcHw.h
+++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwcHw.h
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
  *  Copyright (c) 2017, Andrey Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
  *
@@ -10,8 +11,7 @@
 #ifndef __DWCHW_H__
 #define __DWCHW_H__
 
-#define DW2_USB_BASE_ADDRESS            0x3f980000
-
+#define DW2_USB_BASE_ADDRESS            (FixedPcdGet64 (PcdDw2UsbBaseAddress))
 #define HSOTG_REG(x)    (x)
 
 #define HCCHAR(_ch)                     HSOTG_REG(0x0500 + 0x20 * (_ch))
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
index 059549068e02..d7450d857bd5 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -379,6 +379,7 @@ [PcdsFixedAtBuild.common]
   gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x3f00b880
   gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x3f100000
   gBcm283xTokenSpaceGuid.PcdMmcHs1BaseAddress|0x3f300000
+  gRaspberryPiTokenSpaceGuid.PcdDw2UsbBaseAddress|0x3f980000
 
   ## NS16550 compatible UART
   gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
index c7e17350544a..aa0c6e826866 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -43,6 +43,7 @@ [PcdsFixedAtBuild.common]
   gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
   gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
   gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
+  gRaspberryPiTokenSpaceGuid.PcdDw2UsbBaseAddress|0x0|UINT32|0x00000009
 
 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
   gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
-- 
2.21.0.windows.1


^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-14 16:07 ` [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection Pete Batard
@ 2019-11-14 16:36   ` Michael Brown
  2019-11-14 16:55     ` Pete Batard
  2019-11-18 17:51   ` Leif Lindholm
  1 sibling, 1 reply; 33+ messages in thread
From: Michael Brown @ 2019-11-14 16:36 UTC (permalink / raw)
  To: devel, pete; +Cc: ard.biesheuvel, leif.lindholm, philmd

On 14/11/2019 16:07, Pete Batard wrote:
> +typedef
> +EFI_STATUS
> +(EFIAPI *GET_MODEL_FAMILY) (
> +  UINT32 *ModelFamily
> +  );
> +
>   typedef
>   EFI_STATUS
>   (EFIAPI *GET_FIRMWARE_REVISION) (
> @@ -143,6 +150,7 @@ typedef struct {
>     GET_MODEL             GetModel;
>     GET_MODEL_REVISION    GetModelRevision;
>     GET_MODEL_NAME        GetModelName;
> +  GET_MODEL_FAMILY      GetModelFamily;
>     GET_FIRMWARE_REVISION GetFirmwareRevision;
>     GET_MANUFACTURER_NAME GetManufacturerName;
>     GET_CPU_NAME          GetCpuName;

Is the RASPBERRY_PI_FIRMWARE_PROTOCOL structure expected to be 
externally consumed at any point?  If so, then adding a field in the 
middle of the structure without changing the associated GUID would break 
the ABI.

It's great to see the Pi 4 heading towards having UEFI support; I'm 
looking forward to trying it out as soon as it's ready.

Thanks,

Michael

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-14 16:36   ` [edk2-devel] " Michael Brown
@ 2019-11-14 16:55     ` Pete Batard
  0 siblings, 0 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-14 16:55 UTC (permalink / raw)
  To: Michael Brown, devel; +Cc: ard.biesheuvel, leif.lindholm, philmd

Hi Michael,

On 2019.11.14 16:36, Michael Brown wrote:
> On 14/11/2019 16:07, Pete Batard wrote:
>> +typedef
>> +EFI_STATUS
>> +(EFIAPI *GET_MODEL_FAMILY) (
>> +  UINT32 *ModelFamily
>> +  );
>> +
>>   typedef
>>   EFI_STATUS
>>   (EFIAPI *GET_FIRMWARE_REVISION) (
>> @@ -143,6 +150,7 @@ typedef struct {
>>     GET_MODEL             GetModel;
>>     GET_MODEL_REVISION    GetModelRevision;
>>     GET_MODEL_NAME        GetModelName;
>> +  GET_MODEL_FAMILY      GetModelFamily;
>>     GET_FIRMWARE_REVISION GetFirmwareRevision;
>>     GET_MANUFACTURER_NAME GetManufacturerName;
>>     GET_CPU_NAME          GetCpuName;
> 
> Is the RASPBERRY_PI_FIRMWARE_PROTOCOL structure expected to be 
> externally consumed at any point?

I don't really expect so. And even if that becomes the case, I think the 
platform is still new enough at this stage not to expect anyone to run 
afoul of ABI breakage.

> If so, then adding a field in the 
> middle of the structure without changing the associated GUID would break 
> the ABI.

I guess we'll take that into consideration if we modify this structure 
again, so thanks for pointing it out. But for now, I would say that this 
concern is mostly irrelevant.

> It's great to see the Pi 4 heading towards having UEFI support; I'm 
> looking forward to trying it out as soon as it's ready.

Well, if you are that eager to look into it, you can already play with 
the 'pi4_dev1' branches we have for edk2-platforms and edk2-non-osi at 
https://github.com/pftf which is what we are currently working with (and 
what this patch series is based on).

Right now, you should get video and you should also be able to run the 
UEFI Shell, but since we don't have xHCI, there's no USB support, so the 
only means of interacting with the firmware is through serial...

Oh, and you must have the official Device Tree on your SD card when 
booting if you want the serial baudrate to be properly set to the 
expected 115200 bauds. On RPI4, it appears that the new VideoCore does 
read the Device Tree behind the scenes to perform some of its own init...

If you build the firmware, a basic config.txt with the following should 
get you sorted:

arm_64bit=1
enable_uart=1
core_freq=250
enable_gic=1
armstub=RPI_EFI.fd
disable_commandline_tags=1

If you need more info, feel free to contact me off-list.

Regards,

/Pete

> 
> Thanks,
> 
> Michael


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs
  2019-11-14 16:07 ` [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs Pete Batard
@ 2019-11-18 11:13   ` Philippe Mathieu-Daudé
  2019-11-18 13:32     ` Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-11-18 11:13 UTC (permalink / raw)
  To: Pete Batard, devel, Samer El-Haj-Mahmoud; +Cc: ard.biesheuvel, leif.lindholm

Hi Pete, Samer,

On 11/14/19 5:07 PM, Pete Batard wrote:
> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> 
> Set BCM2836_WDOG_BASE_ADDRESS and BCM2836_MBOX_BASE_ADDRESS to
> using PCDs instead of hard-coded addresses. This is needed in
> preparation for adding Raspberry Pi 4 support.
> 
> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>   Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf | 1 +
>   Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf       | 1 +
>   Platform/RaspberryPi/RPi3/RPi3.dsc                             | 3 +++
>   Silicon/Broadcom/Bcm283x/Bcm283x.dec                           | 2 ++
>   Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h    | 4 ++--
>   5 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> index a3fc0fa49a3c..527cee8bacc1 100644
> --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> @@ -42,6 +42,7 @@ [Protocols]
>   
>   [FixedPcd]
>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress
>   
>   [Depex]
>     TRUE
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> index c0e2a75451c3..f627fca2e406 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> @@ -58,6 +58,7 @@ [FixedPcd]
>     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
>     gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress
>   
>   [Ppis]
>     gArmMpCoreInfoPpiGuid
> diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
> index 4e5a9f0b05e6..88af37e6edaa 100644
> --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
> +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
> @@ -376,6 +376,9 @@ [PcdsFixedAtBuild.common]
>     # Device specific addresses
>     #
>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000

The RegistersAddress 'base' changes in the 2711,

> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x3f00b880
> +  gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x3f100000

but the BaseAddress 'offset' stay constant.

Why not use this approach instead?

#define BCM2836_WDOG_OFFSET          0x00100000
#define BCM2836_WDOG_BASE_ADDRESS \
     (FixedPcdGet64 (PcdBcm283xRegistersAddress) \
      + BCM2836_WDOG_OFFSET)

(and similarly with other devices).

>     ## NS16550 compatible UART
>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> index 5b839b00d286..fe1907cb8cf1 100644
> --- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> @@ -21,3 +21,5 @@ [Guids]
>   
>   [PcdsFixedAtBuild.common]
>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x0|UINT32|0x00000002
> +  gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x0|UINT32|0x00000003
> diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> index 8bd68c234bfd..6bc21f0ddcf8 100644
> --- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> +++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> @@ -23,7 +23,7 @@
>   #define BCM2836_DMA_DEVICE_OFFSET                           0xc0000000
>   
>   /* watchdog constants */
> -#define BCM2836_WDOG_BASE_ADDRESS                           0x3f100000
> +#define BCM2836_WDOG_BASE_ADDRESS                           (FixedPcdGet64 (PcdWdogBaseAddress))
>   #define BCM2836_WDOG_PASSWORD                               0x5a000000
>   #define BCM2836_WDOG_RSTC_OFFSET                            0x0000001c
>   #define BCM2836_WDOG_WDOG_OFFSET                            0x00000024
> @@ -31,7 +31,7 @@
>   #define BCM2836_WDOG_RSTC_WRCFG_FULL_RESET                  0x00000020
>   
>   /* mailbox interface constants */
> -#define BCM2836_MBOX_BASE_ADDRESS                           0x3f00b880
> +#define BCM2836_MBOX_BASE_ADDRESS                           (FixedPcdGet64 (PcdMboxBaseAddress))
>   #define BCM2836_MBOX_READ_OFFSET                            0x00000000
>   #define BCM2836_MBOX_STATUS_OFFSET                          0x00000018
>   #define BCM2836_MBOX_CONFIG_OFFSET                          0x0000001c
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs
  2019-11-18 11:13   ` Philippe Mathieu-Daudé
@ 2019-11-18 13:32     ` Pete Batard
  0 siblings, 0 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-18 13:32 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, devel, Samer El-Haj-Mahmoud
  Cc: ard.biesheuvel, leif.lindholm

Hi Philippe,

On 2019.11.18 11:13, Philippe Mathieu-Daudé wrote:
> Hi Pete, Samer,
> 
> On 11/14/19 5:07 PM, Pete Batard wrote:
>> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
>>
>> Set BCM2836_WDOG_BASE_ADDRESS and BCM2836_MBOX_BASE_ADDRESS to
>> using PCDs instead of hard-coded addresses. This is needed in
>> preparation for adding Raspberry Pi 4 support.
>>
>> Signed-off-by: Pete Batard <pete@akeo.ie>
>> ---
>>   Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf | 1 +
>>   Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf       | 1 +
>>   Platform/RaspberryPi/RPi3/RPi3.dsc                             | 3 +++
>>   Silicon/Broadcom/Bcm283x/Bcm283x.dec                           | 2 ++
>>   Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h    | 4 ++--
>>   5 files changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git 
>> a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf 
>> b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
>> index a3fc0fa49a3c..527cee8bacc1 100644
>> --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
>> +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
>> @@ -42,6 +42,7 @@ [Protocols]
>>   [FixedPcd]
>>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
>> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress
>>   [Depex]
>>     TRUE
>> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf 
>> b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>> index c0e2a75451c3..f627fca2e406 100644
>> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>> @@ -58,6 +58,7 @@ [FixedPcd]
>>     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
>>     gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
>>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
>> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress
>>   [Ppis]
>>     gArmMpCoreInfoPpiGuid
>> diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc 
>> b/Platform/RaspberryPi/RPi3/RPi3.dsc
>> index 4e5a9f0b05e6..88af37e6edaa 100644
>> --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
>> +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
>> @@ -376,6 +376,9 @@ [PcdsFixedAtBuild.common]
>>     # Device specific addresses
>>     #
>>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
> 
> The RegistersAddress 'base' changes in the 2711,
> 
>> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x3f00b880
>> +  gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x3f100000
> 
> but the BaseAddress 'offset' stay constant.
> 
> Why not use this approach instead?
> 
> #define BCM2836_WDOG_OFFSET          0x00100000
> #define BCM2836_WDOG_BASE_ADDRESS \
>      (FixedPcdGet64 (PcdBcm283xRegistersAddress) \
>       + BCM2836_WDOG_OFFSET)
> 
> (and similarly with other devices).

I guess we might have been initially worried that some of the offsets 
might not be the same between Bcm2386 and Bcm2711 (which I agree is 
unlikely... but you never know what a SoC manufacturer might do).

I have however confirmed that the offsets are the same for the registers 
we use. I will therefore send a v2 with the change you suggest.

Regards,

/Pete

> 
>>     ## NS16550 compatible UART
>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
>>     gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
>> diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec 
>> b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
>> index 5b839b00d286..fe1907cb8cf1 100644
>> --- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
>> +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
>> @@ -21,3 +21,5 @@ [Guids]
>>   [PcdsFixedAtBuild.common]
>>     
>> gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
>> +  gBcm283xTokenSpaceGuid.PcdMboxBaseAddress|0x0|UINT32|0x00000002
>> +  gBcm283xTokenSpaceGuid.PcdWdogBaseAddress|0x0|UINT32|0x00000003
>> diff --git 
>> a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h 
>> b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
>> index 8bd68c234bfd..6bc21f0ddcf8 100644
>> --- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
>> +++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
>> @@ -23,7 +23,7 @@
>>   #define BCM2836_DMA_DEVICE_OFFSET                           0xc0000000
>>   /* watchdog constants */
>> -#define BCM2836_WDOG_BASE_ADDRESS                           0x3f100000
>> +#define BCM2836_WDOG_BASE_ADDRESS                           
>> (FixedPcdGet64 (PcdWdogBaseAddress))
>>   #define BCM2836_WDOG_PASSWORD                               0x5a000000
>>   #define BCM2836_WDOG_RSTC_OFFSET                            0x0000001c
>>   #define BCM2836_WDOG_WDOG_OFFSET                            0x00000024
>> @@ -31,7 +31,7 @@
>>   #define BCM2836_WDOG_RSTC_WRCFG_FULL_RESET                  0x00000020
>>   /* mailbox interface constants */
>> -#define BCM2836_MBOX_BASE_ADDRESS                           0x3f00b880
>> +#define BCM2836_MBOX_BASE_ADDRESS                           
>> (FixedPcdGet64 (PcdMboxBaseAddress))
>>   #define BCM2836_MBOX_READ_OFFSET                            0x00000000
>>   #define BCM2836_MBOX_STATUS_OFFSET                          0x00000018
>>   #define BCM2836_MBOX_CONFIG_OFFSET                          0x0000001c
>>
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD
  2019-11-14 16:07 ` [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD Pete Batard
@ 2019-11-18 16:48   ` Leif Lindholm
  2019-11-18 17:19     ` [edk2-devel] " samer.el-haj-mahmoud
  0 siblings, 1 reply; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 16:48 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd, Samer El-Haj-Mahmoud

On Thu, Nov 14, 2019 at 04:07:34PM +0000, Pete Batard wrote:
> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> 
> Define BCM2836_SOC_REGISTERS from PcdBcm283xRegistersAddress. This is
> needed in preparation for adding Raspberry Pi 4 support, since the two
> Pi's have a different base addresses for the Bcm283x specific registers.

Minor style comments below, would be nice if you could fold into any
v2 coming based on Phil's comments. (Although from my reading the
discussion, most of these intances may in fact fall out in a v2.)

Also adding Samer to cc on this reply so he sees the feedback.

> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>  Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf | 2 ++
>  Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf               | 2 ++
>  Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf         | 4 ++++
>  Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf     | 5 ++++-
>  Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf               | 2 ++
>  Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           | 3 ++-
>  Platform/RaspberryPi/RPi3/RPi3.dsc                                 | 6 +++++-
>  Silicon/Broadcom/Bcm283x/Bcm283x.dec                               | 7 +++++++
>  Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf     | 4 +++-
>  Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf                 | 5 +++++
>  Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h        | 3 ++-
>  Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf               | 4 ++++
>  12 files changed, 42 insertions(+), 5 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> index 3f0d7b6b9e9d..034c8c449f00 100644
> --- a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.

I don't actually have a strong opinion here, but would appreciate an
explicit statement that the code is being submitted as copyright ARM
with author @elhajmahmoud.com and not @arm.com?

>  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) Microsoft Corporation. All rights reserved.
>  #
> @@ -42,6 +43,7 @@ [Protocols]
>  
>  [Pcd]
>    gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

When inserting new items like this, please do so alphabetically.

>  
>  [Depex]
>    gRaspberryPiFirmwareProtocolGuid AND gRaspberryPiConfigAppliedProtocolGuid
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> index 28fc2682b585..4f4fdef4e003 100644
> --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -66,6 +67,7 @@ [Pcd]
>    gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
>    gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes
>    gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>  
>  [FeaturePcd]
>  
> diff --git a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> index e880c2fb0261..8817f20622d6 100644
> --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
>  #
> @@ -51,5 +52,8 @@ [Protocols]
>    gEfiUsb2HcProtocolGuid
>    gRaspberryPiFirmwareProtocolGuid
>  
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Depex]
>    gRaspberryPiFirmwareProtocolGuid
> diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> index 87bca98fec28..a3fc0fa49a3c 100644
> --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> @@ -1,5 +1,5 @@
>  #/** @file
> -#
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
>  #
> @@ -40,5 +40,8 @@ [LibraryClasses]
>  [Protocols]
>    gRaspberryPiFirmwareProtocolGuid    ## PRODUCES
>  
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Depex]
>    TRUE
> diff --git a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> index 7386ff251864..b99f197bb007 100644
> --- a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) Microsoft Corporation. All rights reserved.
>  #
> @@ -44,6 +45,7 @@ [Protocols]
>  
>  [Pcd]
>    gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>  
>  [Depex]
>    gRaspberryPiFirmwareProtocolGuid AND gRaspberryPiConfigAppliedProtocolGuid
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> index ed986034b957..85462febdd8d 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> @@ -2,7 +2,7 @@
>  #
>  #  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
> -#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
> +#  Copyright (c) 2011-2019, ARM Limited. All rights reserved.
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> @@ -54,6 +54,7 @@ [FixedPcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>  
>  [Ppis]
>    gArmMpCoreInfoPpiGuid
> diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
> index a0365c5cf606..4e5a9f0b05e6 100644
> --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
> +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
> @@ -1,6 +1,6 @@
>  # @file
>  #
> -#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2011 - 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2014, Linaro Limited. All rights reserved.
>  #  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
>  #  Copyright (c) 2017 - 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> @@ -372,6 +372,10 @@ [PcdsFixedAtBuild.common]
>    gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00400000
>    gArmTokenSpaceGuid.PcdSystemMemorySize|0x3FC00000
>  
> +  #
> +  # Device specific addresses
> +  #
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
>    ## NS16550 compatible UART
>    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
>    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> index ec62ff27fbb3..5b839b00d286 100644
> --- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> @@ -1,5 +1,6 @@
>  ## @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -14,3 +15,9 @@ [Defines]
>  
>  [Includes]
>    Include
> +
> +[Guids]
> +  gBcm283xTokenSpaceGuid = {0x82f36a92, 0xfb7e, 0x43a1, {0xb9, 0x9e, 0x49, 0x13, 0x3f, 0xc7, 0xa4, 0x2e}}
> +
> +[PcdsFixedAtBuild.common]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
> diff --git a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> index cdce11a51e14..6c58df5c3285 100644
> --- a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> +++ b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> @@ -1,5 +1,5 @@
>  #/** @file
> -#
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) 2016 Linaro, Ltd. All rights reserved.
>  #
> @@ -30,6 +30,7 @@ [LibraryClasses]
>    UefiBootServicesTableLib
>    UefiLib
>    UefiDriverEntryPoint
> +  PcdLib

Also here.

>  
>  [Protocols]
>    gHardwareInterruptProtocolGuid  ## PRODUCES
> @@ -37,6 +38,7 @@ [Protocols]
>  
>  [FixedPcd]
>    gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>  
>  [Depex]
>    TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> index cb1695bd2dfc..4481d71aaff0 100644
> --- a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> +++ b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2019 Linaro, Ltd. All rights reserved.
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -28,6 +29,7 @@ [LibraryClasses]
>    IoLib
>    UefiBootServicesTableLib
>    UefiDriverEntryPoint
> +  PcdLib

Also here.

/
    Leif

>  
>  [Protocols]
>    gEfiRngProtocolGuid              ## PRODUCES
> @@ -35,5 +37,8 @@ [Protocols]
>  [Guids]
>    gEfiRngAlgorithmRaw
>  
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Depex]
>    TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> index 4007301228be..8bd68c234bfd 100644
> --- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> +++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> @@ -1,5 +1,6 @@
>  /** @file
>   *
> + *  Copyright (c) 2019, ARM Limited. All rights reserved.
>   *  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
>   *  Copyright (c) 2016, Linaro Limited. All rights reserved.
>   *
> @@ -13,7 +14,7 @@
>  /*
>   * Both "core" and SoC perpherals (1M each).
>   */
> -#define BCM2836_SOC_REGISTERS                               0x3f000000
> +#define BCM2836_SOC_REGISTERS                               (FixedPcdGet64 (PcdBcm283xRegistersAddress))
>  #define BCM2836_SOC_REGISTER_LENGTH                         0x02000000
>  
>  /*
> diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> index 50da4eb771f3..ff1b5af6db6e 100644
> --- a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> @@ -2,6 +2,7 @@
>  #
>  #  Manipulate GPIOs.
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -30,4 +31,7 @@ [LibraryClasses]
>    DebugLib
>    IoLib
>  
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Guids]
> -- 
> 2.21.0.windows.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 3/8] Silicon/Broadcom: Add Bcm2711 header
  2019-11-14 16:07 ` [edk2-platforms][PATCH 3/8] Silicon/Broadcom: Add Bcm2711 header Pete Batard
@ 2019-11-18 16:50   ` Leif Lindholm
  0 siblings, 0 replies; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 16:50 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd

On Thu, Nov 14, 2019 at 04:07:35PM +0000, Pete Batard wrote:
> Bcm2711 is the SoC used by the Raspberry Pi 4. For the most part it
> is backward compatible with the Bcm283x SoC used by older models but
> some new Bcm2711 registers have been introduced such as the ones for
> PCIe.
> 
> We therefore introduce a new Bcm27xx module, which contains only the
> base address for the new registers for now (set from a PCD as is the
> case for Bcm283x) but which should get populated further as we add
> support for the Raspberry Pi 4.
> 
> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>  Silicon/Broadcom/Bcm27xx/Bcm27xx.dec                        | 22 ++++++++++++++++++++
>  Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h | 15 +++++++++++++
>  2 files changed, 37 insertions(+)
> 
> diff --git a/Silicon/Broadcom/Bcm27xx/Bcm27xx.dec b/Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
> new file mode 100644
> index 000000000000..815302f6d209
> --- /dev/null
> +++ b/Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
> @@ -0,0 +1,22 @@
> +## @file
> +#
> +#  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  DEC_SPECIFICATION              = 0x0001001A
> +  PACKAGE_NAME                   = Bcm27xxPkg
> +  PACKAGE_GUID                   = D4B585C5-EBCA-4779-B974-05A3CF2F10C4
> +  PACKAGE_VERSION                = 1.0
> +
> +[Includes]
> +  Include
> +
> +[Guids]
> +  gBcm27xxTokenSpaceGuid = {0x44045e56, 0x7056, 0x4be6, {0x88, 0xc0, 0x49, 0x0c, 0x67, 0x90, 0x2f, 0xba}}
> +
> +[PcdsFixedAtBuild.common]
> +  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress|0x0|UINT32|0x00000001
> diff --git a/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
> new file mode 100644
> index 000000000000..389667714214
> --- /dev/null
> +++ b/Silicon/Broadcom/Bcm27xx/Include/IndustryStandard/Bcm2711.h
> @@ -0,0 +1,15 @@
> +/** @file
> + *
> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>.
> + *
> + *  SPDX-License-Identifier: BSD-2-Clause-Patent
> + *
> + **/
> +
> +#ifndef __BCM2711_H__
> +#define __BCM2711_H__

Nit: Could you drop leading __ for macros? 
With that:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

/
    Leif

> +
> +#define BCM2711_SOC_REGISTERS               (FixedPcdGet64 (PcdBcm27xxRegistersAddress))
> +#define BCM2711_SOC_REGISTER_LENGTH         0x02000000
> +
> +#endif /*__BCM2711_H__ */
> -- 
> 2.21.0.windows.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 4/8] Platform/RPi: Read more variables from VideoCore during early init
  2019-11-14 16:07 ` [edk2-platforms][PATCH 4/8] Platform/RPi: Read more variables from VideoCore during early init Pete Batard
@ 2019-11-18 17:11   ` Leif Lindholm
  0 siblings, 0 replies; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 17:11 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd

On Thu, Nov 14, 2019 at 04:07:36PM +0000, Pete Batard wrote:
> Besides the base memory size, we can read the GPU/VideoCore base as
> well as the model during early init, which we'll need for improving
> the memory mapping.
> 
> This patch adds the retrieval of these variables, as well as some
> early debug display of their values (which can be useful) and also
> removes unused variables such as mGPUMemoryBase and mGPUMemoryLength.
> 
> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>  Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h              |  1 +
>  Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 75 ++++++++++++++++++--
>  Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c            | 14 +++-
>  3 files changed, 84 insertions(+), 6 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h
> index d3b6f117cfdf..584786a61dfd 100644
> --- a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h
> +++ b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h
> @@ -34,6 +34,7 @@
>  #define RPI_MBOX_GET_MAC_ADDRESS                              0x00010003
>  #define RPI_MBOX_GET_BOARD_SERIAL                             0x00010004
>  #define RPI_MBOX_GET_ARM_MEMSIZE                              0x00010005
> +#define RPI_MBOX_GET_VC_MEMSIZE                               0x00010006
>  
>  #define RPI_MBOX_SET_POWER_STATE                              0x00028001
>  
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
> index 36af208d12d8..49a132c722f1 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
> +++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S
> @@ -1,5 +1,6 @@
>  /** @file
>   *
> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>   *  Copyright (c) 2016, Linaro Limited. All rights reserved.
>   *  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
>   *
> @@ -52,24 +53,90 @@ ASM_FUNC (ArmPlatformPeiBootAction)

Before this change, x1 is initialized once, used immediately, and later
corrupted. After this change it becomes effectively a variable, used
several times throughout the function.

This is all fine, but I think it deserves adding a comment to the
assignment along the lines of
  // x1 holds the value of PcdDmaDeviceOffset throughout the function

/
    Leif

>      ldr     wzr, [x4, #BCM2836_MBOX_READ_OFFSET]
>      dmb     ld
>  
> +    ldr     w0, .Lmembase
> +    adr     x2, mSystemMemoryBase
> +    str     x0, [x2]
> +
>      ldr     w0, .Lmemsize
>      sub     x0, x0, #1
> -    adr     x1, mSystemMemoryEnd
> -    str     x0, [x1]
> +    adr     x2, mSystemMemoryEnd
> +    str     x0, [x2]
> +
> +    adr     x0, .Lvcinfo_buffer
> +    orr     x0, x0, #RPI_MBOX_VC_CHANNEL
> +    add     x0, x0, x1
> +
> +    poll    BCM2836_MBOX_STATUS_FULL
> +    str     w0, [x4, #BCM2836_MBOX_WRITE_OFFSET]
> +    dmb     sy
> +    poll    BCM2836_MBOX_STATUS_EMPTY
> +    dmb     sy
> +    ldr     wzr, [x4, #BCM2836_MBOX_READ_OFFSET]
> +    dmb     ld
> +
> +    ldr     w0, .Lvcbase
> +    adr     x2, mVideoCoreBase
> +    str     x0, [x2]
> +
> +    ldr     w0, .Lvcsize
> +    adr     x2, mVideoCoreSize
> +    str     x0, [x2]
> +
> +    adr     x0, .Lrevinfo_buffer
> +    orr     x0, x0, #RPI_MBOX_VC_CHANNEL
> +    add     x0, x0, x1
> +
> +    poll    BCM2836_MBOX_STATUS_FULL
> +    str     w0, [x4, #BCM2836_MBOX_WRITE_OFFSET]
> +    dmb     sy
> +    poll    BCM2836_MBOX_STATUS_EMPTY
> +    dmb     sy
> +    ldr     wzr, [x4, #BCM2836_MBOX_READ_OFFSET]
> +    dmb     ld
> +
> +    ldr     w0, .Lrevision
> +    adr     x2, mBoardRevision
> +    str     w0, [x2]
> +
>      ret
>  
>      .align  4
>  .Lmeminfo_buffer:
> -    .long   .Lbuffer_size
> +    .long   .Lmeminfo_size
>      .long   0x0
>      .long   RPI_MBOX_GET_ARM_MEMSIZE
>      .long   8                           // buf size
>      .long   0                           // input len
> +.Lmembase:
>      .long   0                           // mem base
>  .Lmemsize:
>      .long   0                           // mem size
>      .long   0                           // end tag
> -    .set    .Lbuffer_size, . - .Lmeminfo_buffer
> +    .set    .Lmeminfo_size, . - .Lmeminfo_buffer
> +
> +.Lvcinfo_buffer:
> +    .long   .Lvcinfo_size
> +    .long   0x0
> +    .long   RPI_MBOX_GET_VC_MEMSIZE
> +    .long   8                           // buf size
> +    .long   0                           // input len
> +.Lvcbase:
> +    .long   0                           // videocore base
> +.Lvcsize:
> +    .long   0                           // videocore size
> +    .long   0                           // end tag
> +    .set    .Lvcinfo_size, . - .Lvcinfo_buffer
> +
> +.Lrevinfo_buffer:
> +    .long   .Lrevinfo_size
> +    .long   0x0
> +    .long   RPI_MBOX_GET_BOARD_REVISION
> +    .long   4                           // buf size
> +    .long   0                           // input len
> +.Lrevision:
> +    .long   0                           // revision
> +    .long   0                           // end tag
> +    .set    .Lrevinfo_size, . - .Lrevinfo_buffer
>  
>  //UINTN
>  //ArmPlatformGetPrimaryCoreMpId (
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> index 97d5af5260c6..2bfd3f020a6e 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> @@ -12,9 +12,11 @@
>  #include <IndustryStandard/Bcm2836.h>
>  #include <Library/PcdLib.h>
>  
> +UINT64 mSystemMemoryBase;
>  extern UINT64 mSystemMemoryEnd;
> -extern UINT64 mGPUMemoryBase;
> -extern UINT64 mGPUMemoryLength;
> +UINT64 mVideoCoreBase;
> +UINT64 mVideoCoreSize;
> +UINT32 mBoardRevision;
>  
>  #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
>                         FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
> @@ -87,6 +89,14 @@ ArmPlatformGetVirtualMemoryMap (
>    IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
>    )
>  {
> +  // Early output of the info we got from VideoCore can prove valuable.
> +  DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
> +  DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
> +  DEBUG ((DEBUG_INFO, "VideoCore: 0x%ll08X (Size 0x%ll08X)\n", mVideoCoreBase, mVideoCoreSize));
> +
> +  ASSERT (mSystemMemoryBase == 0);
> +  ASSERT (VirtualMemoryMap != NULL);
> +
>    RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
>      FixedPcdGet64 (PcdSystemMemoryBase);
>  
> -- 
> 2.21.0.windows.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD
  2019-11-18 16:48   ` Leif Lindholm
@ 2019-11-18 17:19     ` samer.el-haj-mahmoud
  2019-11-18 17:26       ` Leif Lindholm
  0 siblings, 1 reply; 33+ messages in thread
From: samer.el-haj-mahmoud @ 2019-11-18 17:19 UTC (permalink / raw)
  To: devel@edk2.groups.io, leif.lindholm@linaro.org, Pete Batard
  Cc: ard.biesheuvel@linaro.org, philmd@redhat.com,
	Samer El-Haj-Mahmoud

> I don't actually have a strong opinion here, but would appreciate an explicit statement that the code is being submitted
> as copyright ARM with author @elhajmahmoud.com and not @arm.com?

Leif, I use @elhajmahmoud.com for Github. But the code is Arm copyrighted (since I am doing this for work). Please let me know if you have any concerns .

Thanks for your review!

--Samer

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Leif Lindholm via Groups.Io
Sent: Monday, November 18, 2019 10:49 AM
To: Pete Batard <pete@akeo.ie>
Cc: devel@edk2.groups.io; ard.biesheuvel@linaro.org; philmd@redhat.com; Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
Subject: Re: [edk2-devel] [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD

On Thu, Nov 14, 2019 at 04:07:34PM +0000, Pete Batard wrote:
> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
>
> Define BCM2836_SOC_REGISTERS from PcdBcm283xRegistersAddress. This is
> needed in preparation for adding Raspberry Pi 4 support, since the two
> Pi's have a different base addresses for the Bcm283x specific registers.

Minor style comments below, would be nice if you could fold into any
v2 coming based on Phil's comments. (Although from my reading the discussion, most of these intances may in fact fall out in a v2.)

Also adding Samer to cc on this reply so he sees the feedback.

> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>  Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf | 2 ++
>  Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf               | 2 ++
>  Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf         | 4 ++++
>  Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf     | 5 ++++-
>  Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf               | 2 ++
>  Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           | 3 ++-
>  Platform/RaspberryPi/RPi3/RPi3.dsc                                 | 6 +++++-
>  Silicon/Broadcom/Bcm283x/Bcm283x.dec                               | 7 +++++++
>  Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf     | 4 +++-
>  Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf                 | 5 +++++
>  Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h        | 3 ++-
>  Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf               | 4 ++++
>  12 files changed, 42 insertions(+), 5 deletions(-)
>
> diff --git
> a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> index 3f0d7b6b9e9d..034c8c449f00 100644
> ---
> a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.i
> +++ nf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.

I don't actually have a strong opinion here, but would appreciate an explicit statement that the code is being submitted as copyright ARM with author @elhajmahmoud.com and not @arm.com?

>  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
> #  Copyright (c) Microsoft Corporation. All rights reserved.
>  #
> @@ -42,6 +43,7 @@ [Protocols]
>
>  [Pcd]
>    gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

When inserting new items like this, please do so alphabetically.

>
>  [Depex]
>    gRaspberryPiFirmwareProtocolGuid AND
> gRaspberryPiConfigAppliedProtocolGuid
> diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> index 28fc2682b585..4f4fdef4e003 100644
> --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> #  #  SPDX-License-Identifier: BSD-2-Clause-Patent @@ -66,6 +67,7 @@
> [Pcd]
>    gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
>    gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes
>    gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>
>  [FeaturePcd]
>
> diff --git
> a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> index e880c2fb0261..8817f20622d6 100644
> --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017-2018, Andrei Warkentin
> <andrey.warkentin@gmail.com>  #  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
>  #
> @@ -51,5 +52,8 @@ [Protocols]
>    gEfiUsb2HcProtocolGuid
>    gRaspberryPiFirmwareProtocolGuid
>
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Depex]
>    gRaspberryPiFirmwareProtocolGuid
> diff --git
> a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> index 87bca98fec28..a3fc0fa49a3c 100644
> --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> @@ -1,5 +1,5 @@
>  #/** @file
> -#
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017-2018, Andrei Warkentin
> <andrey.warkentin@gmail.com>  #  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
>  #
> @@ -40,5 +40,8 @@ [LibraryClasses]
>  [Protocols]
>    gRaspberryPiFirmwareProtocolGuid    ## PRODUCES
>
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Depex]
>    TRUE
> diff --git a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> index 7386ff251864..b99f197bb007 100644
> --- a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> +++ b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
> #  Copyright (c) Microsoft Corporation. All rights reserved.
>  #
> @@ -44,6 +45,7 @@ [Protocols]
>
>  [Pcd]
>    gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>
>  [Depex]
>    gRaspberryPiFirmwareProtocolGuid AND
> gRaspberryPiConfigAppliedProtocolGuid
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> index ed986034b957..85462febdd8d 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> @@ -2,7 +2,7 @@
>  #
>  #  Copyright (c) 2017-2018, Andrei Warkentin
> <andrey.warkentin@gmail.com>  #  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
> -#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
> +#  Copyright (c) 2011-2019, ARM Limited. All rights reserved.
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent  # @@ -54,6 +54,7 @@
> [FixedPcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>
>  [Ppis]
>    gArmMpCoreInfoPpiGuid
> diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
> index a0365c5cf606..4e5a9f0b05e6 100644
> --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
> +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
> @@ -1,6 +1,6 @@
>  # @file
>  #
> -#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> +#  Copyright (c) 2011 - 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2014, Linaro Limited. All rights reserved.
>  #  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
>  #  Copyright (c) 2017 - 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> @@ -372,6 +372,10 @@ [PcdsFixedAtBuild.common]
>    gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00400000
>    gArmTokenSpaceGuid.PcdSystemMemorySize|0x3FC00000
>
> +  #
> +  # Device specific addresses
> +  #
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
>    ## NS16550 compatible UART
>    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
>    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> index ec62ff27fbb3..5b839b00d286 100644
> --- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> @@ -1,5 +1,6 @@
>  ## @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -14,3 +15,9 @@ [Defines]
>
>  [Includes]
>    Include
> +
> +[Guids]
> +  gBcm283xTokenSpaceGuid = {0x82f36a92, 0xfb7e, 0x43a1, {0xb9, 0x9e, 0x49, 0x13, 0x3f, 0xc7, 0xa4, 0x2e}}
> +
> +[PcdsFixedAtBuild.common]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
> diff --git a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> index cdce11a51e14..6c58df5c3285 100644
> --- a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> +++ b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> @@ -1,5 +1,5 @@
>  #/** @file
> -#
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #  Copyright (c) 2016 Linaro, Ltd. All rights reserved.
>  #
> @@ -30,6 +30,7 @@ [LibraryClasses]
>    UefiBootServicesTableLib
>    UefiLib
>    UefiDriverEntryPoint
> +  PcdLib

Also here.

>
>  [Protocols]
>    gHardwareInterruptProtocolGuid  ## PRODUCES
> @@ -37,6 +38,7 @@ [Protocols]
>
>  [FixedPcd]
>    gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress

Also here.

>
>  [Depex]
>    TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> index cb1695bd2dfc..4481d71aaff0 100644
> --- a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> +++ b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> @@ -1,5 +1,6 @@
>  #/** @file
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2019 Linaro, Ltd. All rights reserved.
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -28,6 +29,7 @@ [LibraryClasses]
>    IoLib
>    UefiBootServicesTableLib
>    UefiDriverEntryPoint
> +  PcdLib

Also here.

/
    Leif

>
>  [Protocols]
>    gEfiRngProtocolGuid              ## PRODUCES
> @@ -35,5 +37,8 @@ [Protocols]
>  [Guids]
>    gEfiRngAlgorithmRaw
>
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Depex]
>    TRUE
> diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> index 4007301228be..8bd68c234bfd 100644
> --- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> +++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> @@ -1,5 +1,6 @@
>  /** @file
>   *
> + *  Copyright (c) 2019, ARM Limited. All rights reserved.
>   *  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
>   *  Copyright (c) 2016, Linaro Limited. All rights reserved.
>   *
> @@ -13,7 +14,7 @@
>  /*
>   * Both "core" and SoC perpherals (1M each).
>   */
> -#define BCM2836_SOC_REGISTERS                               0x3f000000
> +#define BCM2836_SOC_REGISTERS                               (FixedPcdGet64 (PcdBcm283xRegistersAddress))
>  #define BCM2836_SOC_REGISTER_LENGTH                         0x02000000
>
>  /*
> diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> index 50da4eb771f3..ff1b5af6db6e 100644
> --- a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> @@ -2,6 +2,7 @@
>  #
>  #  Manipulate GPIOs.
>  #
> +#  Copyright (c) 2019, ARM Limited. All rights reserved.
>  #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>  #
>  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> @@ -30,4 +31,7 @@ [LibraryClasses]
>    DebugLib
>    IoLib
>
> +[FixedPcd]
> +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> +
>  [Guids]
> --
> 2.21.0.windows.1
>



IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init
  2019-11-14 16:07 ` [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init Pete Batard
@ 2019-11-18 17:20   ` Leif Lindholm
  2019-11-18 17:34     ` Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 17:20 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd

On Thu, Nov 14, 2019 at 04:07:37PM +0000, Pete Batard wrote:
> This patch improves memory initialization for the Raspberry Pi Platform by:
> 
> Using VideoCore mailbox data to reserve only the regions that are actually
> mapped. Especially, besides the base RAM size, which was already set using
> VideoCore data, we can set the GPU/VideoCore base address as well as the
> extended RAM, which is the memory beyond 1 GB that is available on models
> such as the Raspberry Pi 4 (for the 2GB or 4GB versions).
> 
> Introducing a new PcdExtendedMemoryBase PCD for the base address of the
> extended memory region, which currently cannot be retrieved from VideoCore
> (MBOX_GET_ARM_MEMSIZE still only returns a single region on Bcm2711).
> 
> Introducing a new RpiPlatformGetVirtualMemoryInfo() companion call to
> ArmPlatformGetVirtualMemoryMap() that allows us greatly simplify the
> registration of each segment in MemoryPeim() as well as making it easier
> to maintain for future models.
> 
> We also fix SoC register space that should have been marked as reserved
> but wasn't until now and remove the unreferenced mSystemMemoryEnd extern
> in MemoryInitPeiLib.c.

Minor style comments and one copyright question below.

> Signed-off-by: Pete Batard <pete@akeo.ie>
> ---
>  Platform/RaspberryPi/Include/Library/RPiMem.h                      |  26 +++
>  Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c   |  94 ++++----
>  Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf |   1 +
>  Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           |   3 +
>  Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c          | 242 +++++++++++---------
>  Platform/RaspberryPi/RaspberryPi.dec                               |   1 +
>  6 files changed, 210 insertions(+), 157 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Include/Library/RPiMem.h b/Platform/RaspberryPi/Include/Library/RPiMem.h
> new file mode 100644
> index 000000000000..0bfc697ed094
> --- /dev/null
> +++ b/Platform/RaspberryPi/Include/Library/RPiMem.h
> @@ -0,0 +1,26 @@
> +/** @file
> + *
> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
> + *
> + *  SPDX-License-Identifier: BSD-2-Clause-Patent
> + *
> + **/
> +
> +#ifndef __RPI_MEM_H__
> +#define __RPI_MEM_H__

As mentioned for earlier patch, please drop leading __.

> +
> +#define RPI_MEM_BASIC_REGION    0
> +#define RPI_MEM_RUNTIME_REGION  1
> +#define RPI_MEM_RESERVED_REGION 2
> +
> +typedef struct {
> +  CONST CHAR16*                 Name;
> +  UINTN                         Type;
> +} RPI_MEMORY_REGION_INFO;
> +
> +VOID
> +RpiPlatformGetVirtualMemoryInfo (
> +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
> +  );
> +
> +#endif /* __RPI_MEM_H__ */
> diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
> index 60cf397f8baa..3a0f7e19e993 100644
> --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
> +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
> @@ -15,8 +15,7 @@
>  #include <Library/HobLib.h>
>  #include <Library/MemoryAllocationLib.h>
>  #include <Library/PcdLib.h>
> -
> -extern UINT64 mSystemMemoryEnd;
> +#include <Library/RPiMem.h>
>  
>  VOID
>  BuildMemoryTypeInformationHob (
> @@ -39,23 +38,32 @@ InitMmu (
>    }
>  }
>  
> +STATIC
> +VOID
> +AddBasicMemoryRegion (
> +  IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
> +)
> +{
> +  BuildResourceDescriptorHob (
> +    EFI_RESOURCE_SYSTEM_MEMORY,
> +    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> +    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> +    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> +    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> +    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> +    EFI_RESOURCE_ATTRIBUTE_TESTED,
> +    Desc->PhysicalBase,
> +    Desc->Length
> +  );
> +}
> +
>  STATIC
>  VOID
>  AddRuntimeServicesRegion (
>    IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>  )
>  {
> -  BuildResourceDescriptorHob (
> -    EFI_RESOURCE_SYSTEM_MEMORY,
> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
> -    Desc->PhysicalBase,
> -    Desc->Length
> -  );
> +  AddBasicMemoryRegion (Desc);
>  
>    BuildMemoryAllocationHob (
>      Desc->PhysicalBase,
> @@ -70,17 +78,7 @@ AddReservedMemoryRegion (
>    IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>    )
>  {
> -  BuildResourceDescriptorHob (
> -    EFI_RESOURCE_SYSTEM_MEMORY,
> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
> -    Desc->PhysicalBase,
> -    Desc->Length
> -  );
> +  AddBasicMemoryRegion (Desc);
>  
>    BuildMemoryAllocationHob (
>      Desc->PhysicalBase,
> @@ -89,6 +87,12 @@ AddReservedMemoryRegion (
>    );
>  }
>  
> +void (*AddRegion[]) (IN ARM_MEMORY_REGION_DESCRIPTOR *Desc) = {
> +  AddBasicMemoryRegion,
> +  AddRuntimeServicesRegion,
> +  AddReservedMemoryRegion,
> +  };
> +
>  /*++
>  
>  Routine Description:
> @@ -113,36 +117,28 @@ MemoryPeim (
>    )
>  {
>    ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
> +  RPI_MEMORY_REGION_INFO       *MemoryInfo;
> +  UINTN                        Index;
>  
>    // Get Virtual Memory Map from the Platform Library
>    ArmPlatformGetVirtualMemoryMap (&MemoryTable);
>  
> -  // Ensure PcdSystemMemorySize has been set
> -  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
> +  // Get additional info not provided by MemoryTable
> +  RpiPlatformGetVirtualMemoryInfo (&MemoryInfo);
>  
> -  // FD without variable store
> -  AddReservedMemoryRegion (&MemoryTable[0]);
> -
> -  // Variable store.
> -  AddRuntimeServicesRegion (&MemoryTable[1]);
> -
> -  // Trusted Firmware region
> -  AddReservedMemoryRegion (&MemoryTable[2]);
> -
> -  // Usable memory.
> -  BuildResourceDescriptorHob (
> -    EFI_RESOURCE_SYSTEM_MEMORY,
> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
> -    MemoryTable[3].PhysicalBase,
> -    MemoryTable[3].Length
> -  );
> -
> -  AddReservedMemoryRegion (&MemoryTable[4]);
> +  // Register each memory region
> +  for (Index = 0; MemoryTable[Index].Length != 0; Index++) {
> +    ASSERT (MemoryInfo[Index].Type < ARRAY_SIZE (AddRegion));
> +    DEBUG ((DEBUG_INFO, "%s:\n"
> +      "\tPhysicalBase: 0x%lX\n"
> +      "\tVirtualBase: 0x%lX\n"
> +      "\tLength: 0x%lX\n",
> +      MemoryInfo[Index].Name,
> +      MemoryTable[Index].PhysicalBase,
> +      MemoryTable[Index].VirtualBase,
> +      MemoryTable[Index].Length));
> +    AddRegion[MemoryInfo[Index].Type] (&MemoryTable[Index]);
> +  }
>  
>    // Build Memory Allocation Hob
>    InitMmu (MemoryTable);
> diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> index 0084c010936d..d39210c7a4f1 100644
> --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> @@ -24,6 +24,7 @@ [Packages]
>    EmbeddedPkg/EmbeddedPkg.dec
>    ArmPkg/ArmPkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
> +  Platform/RaspberryPi/RaspberryPi.dec
>  
>  [LibraryClasses]
>    DebugLib
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> index 85462febdd8d..c0e2a75451c3 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> @@ -22,6 +22,7 @@ [Packages]
>    EmbeddedPkg/EmbeddedPkg.dec
>    ArmPkg/ArmPkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
> +  Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
>    Silicon/Broadcom/Bcm283x/Bcm283x.dec
>    Platform/RaspberryPi/RaspberryPi.dec
>  
> @@ -50,10 +51,12 @@ [FixedPcd]
>    gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
>    gArmTokenSpaceGuid.PcdSystemMemoryBase
>    gArmTokenSpaceGuid.PcdSystemMemorySize
> +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase
>    gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
> +  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
>    gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
>  
>  [Ppis]
> diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> index 2bfd3f020a6e..1a6a13b9591b 100644
> --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> @@ -1,7 +1,9 @@
>  /** @file
>   *
> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>   *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
>   *  Copyright (c) 2014, Linaro Limited. All rights reserved.
> + *  Copyright (c) 2013-2018, ARM Limited. All rights reserved.

This confuses me slightly - is it an indication that some code has
been copied from a file including this copyright?

>   *
>   *  SPDX-License-Identifier: BSD-2-Clause-Patent
>   *
> @@ -9,8 +11,11 @@
>  
>  #include <Library/ArmPlatformLib.h>
>  #include <Library/DebugLib.h>
> -#include <IndustryStandard/Bcm2836.h>
>  #include <Library/PcdLib.h>
> +#include <Library/RPiMem.h>
> +#include <Library/MemoryAllocationLib.h>

Could you move MemoryAllocationLib.h above PcdLib.h?

/
    Leif

> +#include <IndustryStandard/Bcm2711.h>
> +#include <IndustryStandard/Bcm2836.h>
>  
>  UINT64 mSystemMemoryBase;
>  extern UINT64 mSystemMemoryEnd;
> @@ -18,6 +23,13 @@ UINT64 mVideoCoreBase;
>  UINT64 mVideoCoreSize;
>  UINT32 mBoardRevision;
>  
> +
> +// The total number of descriptors, including the final "end-of-table" descriptor.
> +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 10
> +
> +STATIC BOOLEAN                  VirtualMemoryInfoInitialized = FALSE;
> +STATIC RPI_MEMORY_REGION_INFO   VirtualMemoryInfo[MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS];
> +
>  #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
>                         FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
>                         FixedPcdGet32(PcdFlashNvStorageFtwSpareSize) +  \
> @@ -29,49 +41,6 @@ UINT32 mBoardRevision;
>  
>  #define ATFBase (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize))
>  
> -STATIC ARM_MEMORY_REGION_DESCRIPTOR RaspberryPiMemoryRegionDescriptor[] = {
> -  {
> -    /* Firmware Volume. */
> -    FixedPcdGet64 (PcdFdBaseAddress), FixedPcdGet64 (PcdFdBaseAddress),
> -    FixedPcdGet32 (PcdFdSize) - VariablesSize,
> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> -  },
> -  {
> -    /* Variables Volume. */
> -    VariablesBase, VariablesBase,
> -    VariablesSize,
> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> -  },
> -  {
> -    /* ATF reserved RAM. */
> -    ATFBase, ATFBase,
> -    FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase,
> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> -  },
> -  {
> -    /* System RAM. */
> -    FixedPcdGet64 (PcdSystemMemoryBase), FixedPcdGet64 (PcdSystemMemoryBase),
> -    0,
> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> -  },
> -  {
> -    /* Reserved GPU RAM. */
> -    0,
> -    0,
> -    0,
> -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
> -  },
> -  {
> -    /* SOC registers. */
> -    BCM2836_SOC_REGISTERS,
> -    BCM2836_SOC_REGISTERS,
> -    BCM2836_SOC_REGISTER_LENGTH,
> -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
> -  },
> -  {
> -  }
> -};
> -
>  /**
>    Return the Virtual Memory Map of your platform
>  
> @@ -89,6 +58,11 @@ ArmPlatformGetVirtualMemoryMap (
>    IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
>    )
>  {
> +  UINTN                         Index = 0;
> +  UINTN                         GpuIndex;
> +  INT64                         ExtendedMemorySize;
> +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
> +
>    // Early output of the info we got from VideoCore can prove valuable.
>    DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
>    DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
> @@ -97,68 +71,120 @@ ArmPlatformGetVirtualMemoryMap (
>    ASSERT (mSystemMemoryBase == 0);
>    ASSERT (VirtualMemoryMap != NULL);
>  
> -  RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
> -    FixedPcdGet64 (PcdSystemMemoryBase);
> -
> -  RaspberryPiMemoryRegionDescriptor[4].PhysicalBase =
> -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase +
> -    RaspberryPiMemoryRegionDescriptor[3].Length;
> -
> -  RaspberryPiMemoryRegionDescriptor[4].VirtualBase =
> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
> -
> -  RaspberryPiMemoryRegionDescriptor[4].Length =
> -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase -
> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
> -
> -  DEBUG ((DEBUG_INFO, "FD:\n"
> -    "\tPhysicalBase: 0x%lX\n"
> -    "\tVirtualBase: 0x%lX\n"
> -    "\tLength: 0x%lX\n",
> -    RaspberryPiMemoryRegionDescriptor[0].PhysicalBase,
> -    RaspberryPiMemoryRegionDescriptor[0].VirtualBase,
> -    RaspberryPiMemoryRegionDescriptor[0].Length +
> -    RaspberryPiMemoryRegionDescriptor[1].Length));
> -
> -  DEBUG ((DEBUG_INFO, "Variables (part of FD):\n"
> -    "\tPhysicalBase: 0x%lX\n"
> -    "\tVirtualBase: 0x%lX\n"
> -    "\tLength: 0x%lX\n",
> -    RaspberryPiMemoryRegionDescriptor[1].PhysicalBase,
> -    RaspberryPiMemoryRegionDescriptor[1].VirtualBase,
> -    RaspberryPiMemoryRegionDescriptor[1].Length));
> -
> -  DEBUG ((DEBUG_INFO, "ATF RAM:\n"
> -    "\tPhysicalBase: 0x%lX\n"
> -    "\tVirtualBase: 0x%lX\n"
> -    "\tLength: 0x%lX\n",
> -    RaspberryPiMemoryRegionDescriptor[2].PhysicalBase,
> -    RaspberryPiMemoryRegionDescriptor[2].VirtualBase,
> -    RaspberryPiMemoryRegionDescriptor[2].Length));
> -
> -  DEBUG ((DEBUG_INFO, "System RAM:\n"
> -    "\tPhysicalBase: 0x%lX\n"
> -    "\tVirtualBase: 0x%lX\n"
> -    "\tLength: 0x%lX\n",
> -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase,
> -    RaspberryPiMemoryRegionDescriptor[3].VirtualBase,
> -    RaspberryPiMemoryRegionDescriptor[3].Length));
> -
> -  DEBUG ((DEBUG_INFO, "GPU Reserved:\n"
> -    "\tPhysicalBase: 0x%lX\n"
> -    "\tVirtualBase: 0x%lX\n"
> -    "\tLength: 0x%lX\n",
> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase,
> -    RaspberryPiMemoryRegionDescriptor[4].VirtualBase,
> -    RaspberryPiMemoryRegionDescriptor[4].Length));
> -
> -  DEBUG ((DEBUG_INFO, "SoC reserved:\n"
> -    "\tPhysicalBase: 0x%lX\n"
> -    "\tVirtualBase: 0x%lX\n"
> -    "\tLength: 0x%lX\n",
> -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase,
> -    RaspberryPiMemoryRegionDescriptor[5].VirtualBase,
> -    RaspberryPiMemoryRegionDescriptor[5].Length));
> -
> -  *VirtualMemoryMap = RaspberryPiMemoryRegionDescriptor;
> +  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages
> +                       (EFI_SIZE_TO_PAGES (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
> +                       MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
> +  if (VirtualMemoryTable == NULL) {
> +    return;
> +  }
> +
> +
> +  // Firmware Volume
> +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdFdBaseAddress);
> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length          = FixedPcdGet32 (PcdFdSize) - VariablesSize;
> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
> +  VirtualMemoryInfo[Index++].Name           = L"FD";
> +
> +  // Variable Volume
> +  VirtualMemoryTable[Index].PhysicalBase    = VariablesBase;
> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length          = VariablesSize;
> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RUNTIME_REGION;
> +  VirtualMemoryInfo[Index++].Name           = L"FD Variables";
> +
> +  // TF-A reserved RAM
> +  VirtualMemoryTable[Index].PhysicalBase    = ATFBase;
> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length          = FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase;
> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
> +  VirtualMemoryInfo[Index++].Name           = L"TF-A RAM";
> +
> +  // Base System RAM
> +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdSystemMemoryBase);
> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length          = mSystemMemoryEnd + 1 - FixedPcdGet64 (PcdSystemMemoryBase);
> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_BASIC_REGION;
> +  VirtualMemoryInfo[Index++].Name           = L"Base System RAM";
> +
> +  // GPU Reserved
> +  GpuIndex = Index;
> +  VirtualMemoryTable[Index].PhysicalBase    = mVideoCoreBase;
> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length          = mVideoCoreSize;
> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +  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";
> +  }
> +
> +  // Extended SoC registers (PCIe, genet, ...)
> +  if (BCM2711_SOC_REGISTERS > 0) {
> +    VirtualMemoryTable[Index].PhysicalBase  = BCM2711_SOC_REGISTERS;
> +    VirtualMemoryTable[Index].VirtualBase   = VirtualMemoryTable[Index].PhysicalBase;
> +    VirtualMemoryTable[Index].Length        = BCM2711_SOC_REGISTER_LENGTH;
> +    VirtualMemoryTable[Index].Attributes    = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +    VirtualMemoryInfo[Index].Type           = RPI_MEM_RESERVED_REGION;
> +    VirtualMemoryInfo[Index++].Name         = L"SoC Reserved (27xx)";
> +  }
> +
> +  // Base SoC registers
> +  VirtualMemoryTable[Index].PhysicalBase    = BCM2836_SOC_REGISTERS;
> +  // On the Pi 3 the SoC registers may overlap VideoCore => fix this
> +  if (VirtualMemoryTable[GpuIndex].PhysicalBase + VirtualMemoryTable[GpuIndex].Length > VirtualMemoryTable[Index].PhysicalBase) {
> +    VirtualMemoryTable[GpuIndex].Length = VirtualMemoryTable[Index].PhysicalBase - VirtualMemoryTable[GpuIndex].PhysicalBase;
> +  }
> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> +  VirtualMemoryTable[Index].Length          = BCM2836_SOC_REGISTER_LENGTH;
> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
> +  VirtualMemoryInfo[Index++].Name           = L"SoC Reserved (283x)";
> +
> +  // End of Table
> +  VirtualMemoryTable[Index].PhysicalBase    = 0;
> +  VirtualMemoryTable[Index].VirtualBase     = 0;
> +  VirtualMemoryTable[Index].Length          = 0;
> +  VirtualMemoryTable[Index++].Attributes    = (ARM_MEMORY_REGION_ATTRIBUTES)0;
> +
> +  ASSERT(Index <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
> +
> +  *VirtualMemoryMap = VirtualMemoryTable;
> +  VirtualMemoryInfoInitialized = TRUE;
> +}
> +
> +/**
> +  Return additional memory info not populated by the above call.
> +
> +  This call should follow the one to ArmPlatformGetVirtualMemoryMap ().
> +
> +**/
> +VOID
> +RpiPlatformGetVirtualMemoryInfo (
> +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
> +  )
> +{
> +  ASSERT (VirtualMemoryInfo != NULL);
> +
> +  if (!VirtualMemoryInfoInitialized) {
> +    DEBUG ((DEBUG_ERROR,
> +      "ArmPlatformGetVirtualMemoryMap must be called before RpiPlatformGetVirtualMemoryInfo.\n"));
> +    return;
> +  }
> +
> +  *MemoryInfo = VirtualMemoryInfo;
>  }
> diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
> index 3e9171eccb13..c7e17350544a 100644
> --- a/Platform/RaspberryPi/RaspberryPi.dec
> +++ b/Platform/RaspberryPi/RaspberryPi.dec
> @@ -42,6 +42,7 @@ [PcdsFixedAtBuild.common]
>    gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000005
>    gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
>    gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
> +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
>  
>  [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
>    gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
> -- 
> 2.21.0.windows.1
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD
  2019-11-18 17:19     ` [edk2-devel] " samer.el-haj-mahmoud
@ 2019-11-18 17:26       ` Leif Lindholm
  0 siblings, 0 replies; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 17:26 UTC (permalink / raw)
  To: Samer El-Haj-Mahmoud
  Cc: devel@edk2.groups.io, Pete Batard, ard.biesheuvel@linaro.org,
	philmd@redhat.com, Samer El-Haj-Mahmoud

On Mon, Nov 18, 2019 at 05:19:32PM +0000, Samer El-Haj-Mahmoud wrote:
> > I don't actually have a strong opinion here, but would appreciate
> an explicit statement that the code is being submitted
> > as copyright ARM with author @elhajmahmoud.com and not @arm.com?
> 
> Leif, I use @elhajmahmoud.com for Github. But the code is Arm
> copyrighted (since I am doing this for work). Please let me know if
> you have any concerns .

I don't have any concerns really, given the above statement is now in
the public archive :)

> Thanks for your review!

Thanks for your contribution!

/
    Leif

> --Samer
> 
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Leif Lindholm via Groups.Io
> Sent: Monday, November 18, 2019 10:49 AM
> To: Pete Batard <pete@akeo.ie>
> Cc: devel@edk2.groups.io; ard.biesheuvel@linaro.org; philmd@redhat.com; Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> Subject: Re: [edk2-devel] [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD
> 
> On Thu, Nov 14, 2019 at 04:07:34PM +0000, Pete Batard wrote:
> > From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> >
> > Define BCM2836_SOC_REGISTERS from PcdBcm283xRegistersAddress. This is
> > needed in preparation for adding Raspberry Pi 4 support, since the two
> > Pi's have a different base addresses for the Bcm283x specific registers.
> 
> Minor style comments below, would be nice if you could fold into any
> v2 coming based on Phil's comments. (Although from my reading the discussion, most of these intances may in fact fall out in a v2.)
> 
> Also adding Samer to cc on this reply so he sees the feedback.
> 
> > Signed-off-by: Pete Batard <pete@akeo.ie>
> > ---
> >  Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf | 2 ++
> >  Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf               | 2 ++
> >  Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf         | 4 ++++
> >  Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf     | 5 ++++-
> >  Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf               | 2 ++
> >  Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           | 3 ++-
> >  Platform/RaspberryPi/RPi3/RPi3.dsc                                 | 6 +++++-
> >  Silicon/Broadcom/Bcm283x/Bcm283x.dec                               | 7 +++++++
> >  Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf     | 4 +++-
> >  Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf                 | 5 +++++
> >  Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h        | 3 ++-
> >  Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf               | 4 ++++
> >  12 files changed, 42 insertions(+), 5 deletions(-)
> >
> > diff --git
> > a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> > b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> > index 3f0d7b6b9e9d..034c8c449f00 100644
> > ---
> > a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.inf
> > +++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.i
> > +++ nf
> > @@ -1,5 +1,6 @@
> >  #/** @file
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> 
> I don't actually have a strong opinion here, but would appreciate an explicit statement that the code is being submitted as copyright ARM with author @elhajmahmoud.com and not @arm.com?
> 
> >  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
> > #  Copyright (c) Microsoft Corporation. All rights reserved.
> >  #
> > @@ -42,6 +43,7 @@ [Protocols]
> >
> >  [Pcd]
> >    gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> 
> When inserting new items like this, please do so alphabetically.
> 
> >
> >  [Depex]
> >    gRaspberryPiFirmwareProtocolGuid AND
> > gRaspberryPiConfigAppliedProtocolGuid
> > diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> > b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> > index 28fc2682b585..4f4fdef4e003 100644
> > --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> > +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
> > @@ -1,5 +1,6 @@
> >  #/** @file
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> > #  #  SPDX-License-Identifier: BSD-2-Clause-Patent @@ -66,6 +67,7 @@
> > [Pcd]
> >    gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
> >    gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes
> >    gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> 
> Also here.
> 
> >
> >  [FeaturePcd]
> >
> > diff --git
> > a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> > b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> > index e880c2fb0261..8817f20622d6 100644
> > --- a/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> > +++ b/Platform/RaspberryPi/Drivers/DwUsbHostDxe/DwUsbHostDxe.inf
> > @@ -1,5 +1,6 @@
> >  #/** @file
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2017-2018, Andrei Warkentin
> > <andrey.warkentin@gmail.com>  #  Copyright (c) 2015-2016, Linaro Limited. All rights reserved.
> >  #
> > @@ -51,5 +52,8 @@ [Protocols]
> >    gEfiUsb2HcProtocolGuid
> >    gRaspberryPiFirmwareProtocolGuid
> >
> > +[FixedPcd]
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> > +
> >  [Depex]
> >    gRaspberryPiFirmwareProtocolGuid
> > diff --git
> > a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> > b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> > index 87bca98fec28..a3fc0fa49a3c 100644
> > --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> > +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.inf
> > @@ -1,5 +1,5 @@
> >  #/** @file
> > -#
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2017-2018, Andrei Warkentin
> > <andrey.warkentin@gmail.com>  #  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
> >  #
> > @@ -40,5 +40,8 @@ [LibraryClasses]
> >  [Protocols]
> >    gRaspberryPiFirmwareProtocolGuid    ## PRODUCES
> >
> > +[FixedPcd]
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> > +
> >  [Depex]
> >    TRUE
> > diff --git a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> > b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> > index 7386ff251864..b99f197bb007 100644
> > --- a/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> > +++ b/Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.inf
> > @@ -1,5 +1,6 @@
> >  #/** @file
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
> > #  Copyright (c) Microsoft Corporation. All rights reserved.
> >  #
> > @@ -44,6 +45,7 @@ [Protocols]
> >
> >  [Pcd]
> >    gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> 
> Also here.
> 
> >
> >  [Depex]
> >    gRaspberryPiFirmwareProtocolGuid AND
> > gRaspberryPiConfigAppliedProtocolGuid
> > diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > index ed986034b957..85462febdd8d 100644
> > --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > @@ -2,7 +2,7 @@
> >  #
> >  #  Copyright (c) 2017-2018, Andrei Warkentin
> > <andrey.warkentin@gmail.com>  #  Copyright (c) 2014-2016, Linaro Limited. All rights reserved.
> > -#  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
> > +#  Copyright (c) 2011-2019, ARM Limited. All rights reserved.
> >  #
> >  #  SPDX-License-Identifier: BSD-2-Clause-Patent  # @@ -54,6 +54,7 @@
> > [FixedPcd]
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> 
> Also here.
> 
> >
> >  [Ppis]
> >    gArmMpCoreInfoPpiGuid
> > diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc
> > index a0365c5cf606..4e5a9f0b05e6 100644
> > --- a/Platform/RaspberryPi/RPi3/RPi3.dsc
> > +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
> > @@ -1,6 +1,6 @@
> >  # @file
> >  #
> > -#  Copyright (c) 2011-2015, ARM Limited. All rights reserved.
> > +#  Copyright (c) 2011 - 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2014, Linaro Limited. All rights reserved.
> >  #  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
> >  #  Copyright (c) 2017 - 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> > @@ -372,6 +372,10 @@ [PcdsFixedAtBuild.common]
> >    gArmTokenSpaceGuid.PcdSystemMemoryBase|0x00400000
> >    gArmTokenSpaceGuid.PcdSystemMemorySize|0x3FC00000
> >
> > +  #
> > +  # Device specific addresses
> > +  #
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x3f000000
> >    ## NS16550 compatible UART
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x3f215040
> >    gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio|TRUE
> > diff --git a/Silicon/Broadcom/Bcm283x/Bcm283x.dec b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> > index ec62ff27fbb3..5b839b00d286 100644
> > --- a/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> > +++ b/Silicon/Broadcom/Bcm283x/Bcm283x.dec
> > @@ -1,5 +1,6 @@
> >  ## @file
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
> >  #
> >  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> > @@ -14,3 +15,9 @@ [Defines]
> >
> >  [Includes]
> >    Include
> > +
> > +[Guids]
> > +  gBcm283xTokenSpaceGuid = {0x82f36a92, 0xfb7e, 0x43a1, {0xb9, 0x9e, 0x49, 0x13, 0x3f, 0xc7, 0xa4, 0x2e}}
> > +
> > +[PcdsFixedAtBuild.common]
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress|0x0|UINT32|0x00000001
> > diff --git a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> > index cdce11a51e14..6c58df5c3285 100644
> > --- a/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> > +++ b/Silicon/Broadcom/Bcm283x/Drivers/InterruptDxe/InterruptDxe.inf
> > @@ -1,5 +1,5 @@
> >  #/** @file
> > -#
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
> >  #  Copyright (c) 2016 Linaro, Ltd. All rights reserved.
> >  #
> > @@ -30,6 +30,7 @@ [LibraryClasses]
> >    UefiBootServicesTableLib
> >    UefiLib
> >    UefiDriverEntryPoint
> > +  PcdLib
> 
> Also here.
> 
> >
> >  [Protocols]
> >    gHardwareInterruptProtocolGuid  ## PRODUCES
> > @@ -37,6 +38,7 @@ [Protocols]
> >
> >  [FixedPcd]
> >    gEmbeddedTokenSpaceGuid.PcdInterruptBaseAddress
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> 
> Also here.
> 
> >
> >  [Depex]
> >    TRUE
> > diff --git a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> > index cb1695bd2dfc..4481d71aaff0 100644
> > --- a/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> > +++ b/Silicon/Broadcom/Bcm283x/Drivers/RngDxe/RngDxe.inf
> > @@ -1,5 +1,6 @@
> >  #/** @file
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2019 Linaro, Ltd. All rights reserved.
> >  #
> >  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> > @@ -28,6 +29,7 @@ [LibraryClasses]
> >    IoLib
> >    UefiBootServicesTableLib
> >    UefiDriverEntryPoint
> > +  PcdLib
> 
> Also here.
> 
> /
>     Leif
> 
> >
> >  [Protocols]
> >    gEfiRngProtocolGuid              ## PRODUCES
> > @@ -35,5 +37,8 @@ [Protocols]
> >  [Guids]
> >    gEfiRngAlgorithmRaw
> >
> > +[FixedPcd]
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> > +
> >  [Depex]
> >    TRUE
> > diff --git a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> > index 4007301228be..8bd68c234bfd 100644
> > --- a/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> > +++ b/Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h
> > @@ -1,5 +1,6 @@
> >  /** @file
> >   *
> > + *  Copyright (c) 2019, ARM Limited. All rights reserved.
> >   *  Copyright (c) 2017, Andrei Warkentin <andrey.warkentin@gmail.com>
> >   *  Copyright (c) 2016, Linaro Limited. All rights reserved.
> >   *
> > @@ -13,7 +14,7 @@
> >  /*
> >   * Both "core" and SoC perpherals (1M each).
> >   */
> > -#define BCM2836_SOC_REGISTERS                               0x3f000000
> > +#define BCM2836_SOC_REGISTERS                               (FixedPcdGet64 (PcdBcm283xRegistersAddress))
> >  #define BCM2836_SOC_REGISTER_LENGTH                         0x02000000
> >
> >  /*
> > diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> > index 50da4eb771f3..ff1b5af6db6e 100644
> > --- a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> > +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf
> > @@ -2,6 +2,7 @@
> >  #
> >  #  Manipulate GPIOs.
> >  #
> > +#  Copyright (c) 2019, ARM Limited. All rights reserved.
> >  #  Copyright (c) 2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> >  #
> >  #  SPDX-License-Identifier: BSD-2-Clause-Patent
> > @@ -30,4 +31,7 @@ [LibraryClasses]
> >    DebugLib
> >    IoLib
> >
> > +[FixedPcd]
> > +  gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> > +
> >  [Guids]
> > --
> > 2.21.0.windows.1
> >
> 
> 
> 
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init
  2019-11-18 17:20   ` Leif Lindholm
@ 2019-11-18 17:34     ` Pete Batard
  2019-11-18 17:38       ` Leif Lindholm
  0 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-18 17:34 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: devel, ard.biesheuvel, philmd

Hi Leif,

On 2019.11.18 17:20, Leif Lindholm wrote:
> On Thu, Nov 14, 2019 at 04:07:37PM +0000, Pete Batard wrote:
>> This patch improves memory initialization for the Raspberry Pi Platform by:
>>
>> Using VideoCore mailbox data to reserve only the regions that are actually
>> mapped. Especially, besides the base RAM size, which was already set using
>> VideoCore data, we can set the GPU/VideoCore base address as well as the
>> extended RAM, which is the memory beyond 1 GB that is available on models
>> such as the Raspberry Pi 4 (for the 2GB or 4GB versions).
>>
>> Introducing a new PcdExtendedMemoryBase PCD for the base address of the
>> extended memory region, which currently cannot be retrieved from VideoCore
>> (MBOX_GET_ARM_MEMSIZE still only returns a single region on Bcm2711).
>>
>> Introducing a new RpiPlatformGetVirtualMemoryInfo() companion call to
>> ArmPlatformGetVirtualMemoryMap() that allows us greatly simplify the
>> registration of each segment in MemoryPeim() as well as making it easier
>> to maintain for future models.
>>
>> We also fix SoC register space that should have been marked as reserved
>> but wasn't until now and remove the unreferenced mSystemMemoryEnd extern
>> in MemoryInitPeiLib.c.
> 
> Minor style comments and one copyright question below.
> 
>> Signed-off-by: Pete Batard <pete@akeo.ie>
>> ---
>>   Platform/RaspberryPi/Include/Library/RPiMem.h                      |  26 +++
>>   Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c   |  94 ++++----
>>   Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf |   1 +
>>   Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           |   3 +
>>   Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c          | 242 +++++++++++---------
>>   Platform/RaspberryPi/RaspberryPi.dec                               |   1 +
>>   6 files changed, 210 insertions(+), 157 deletions(-)
>>
>> diff --git a/Platform/RaspberryPi/Include/Library/RPiMem.h b/Platform/RaspberryPi/Include/Library/RPiMem.h
>> new file mode 100644
>> index 000000000000..0bfc697ed094
>> --- /dev/null
>> +++ b/Platform/RaspberryPi/Include/Library/RPiMem.h
>> @@ -0,0 +1,26 @@
>> +/** @file
>> + *
>> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>> + *
>> + *  SPDX-License-Identifier: BSD-2-Clause-Patent
>> + *
>> + **/
>> +
>> +#ifndef __RPI_MEM_H__
>> +#define __RPI_MEM_H__
> 
> As mentioned for earlier patch, please drop leading __.

Will do. I assume this applies to trailing __ as well.

>> +
>> +#define RPI_MEM_BASIC_REGION    0
>> +#define RPI_MEM_RUNTIME_REGION  1
>> +#define RPI_MEM_RESERVED_REGION 2
>> +
>> +typedef struct {
>> +  CONST CHAR16*                 Name;
>> +  UINTN                         Type;
>> +} RPI_MEMORY_REGION_INFO;
>> +
>> +VOID
>> +RpiPlatformGetVirtualMemoryInfo (
>> +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
>> +  );
>> +
>> +#endif /* __RPI_MEM_H__ */
>> diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
>> index 60cf397f8baa..3a0f7e19e993 100644
>> --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
>> +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
>> @@ -15,8 +15,7 @@
>>   #include <Library/HobLib.h>
>>   #include <Library/MemoryAllocationLib.h>
>>   #include <Library/PcdLib.h>
>> -
>> -extern UINT64 mSystemMemoryEnd;
>> +#include <Library/RPiMem.h>
>>   
>>   VOID
>>   BuildMemoryTypeInformationHob (
>> @@ -39,23 +38,32 @@ InitMmu (
>>     }
>>   }
>>   
>> +STATIC
>> +VOID
>> +AddBasicMemoryRegion (
>> +  IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>> +)
>> +{
>> +  BuildResourceDescriptorHob (
>> +    EFI_RESOURCE_SYSTEM_MEMORY,
>> +    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>> +    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>> +    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>> +    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>> +    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>> +    EFI_RESOURCE_ATTRIBUTE_TESTED,
>> +    Desc->PhysicalBase,
>> +    Desc->Length
>> +  );
>> +}
>> +
>>   STATIC
>>   VOID
>>   AddRuntimeServicesRegion (
>>     IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>>   )
>>   {
>> -  BuildResourceDescriptorHob (
>> -    EFI_RESOURCE_SYSTEM_MEMORY,
>> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
>> -    Desc->PhysicalBase,
>> -    Desc->Length
>> -  );
>> +  AddBasicMemoryRegion (Desc);
>>   
>>     BuildMemoryAllocationHob (
>>       Desc->PhysicalBase,
>> @@ -70,17 +78,7 @@ AddReservedMemoryRegion (
>>     IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>>     )
>>   {
>> -  BuildResourceDescriptorHob (
>> -    EFI_RESOURCE_SYSTEM_MEMORY,
>> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
>> -    Desc->PhysicalBase,
>> -    Desc->Length
>> -  );
>> +  AddBasicMemoryRegion (Desc);
>>   
>>     BuildMemoryAllocationHob (
>>       Desc->PhysicalBase,
>> @@ -89,6 +87,12 @@ AddReservedMemoryRegion (
>>     );
>>   }
>>   
>> +void (*AddRegion[]) (IN ARM_MEMORY_REGION_DESCRIPTOR *Desc) = {
>> +  AddBasicMemoryRegion,
>> +  AddRuntimeServicesRegion,
>> +  AddReservedMemoryRegion,
>> +  };
>> +
>>   /*++
>>   
>>   Routine Description:
>> @@ -113,36 +117,28 @@ MemoryPeim (
>>     )
>>   {
>>     ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
>> +  RPI_MEMORY_REGION_INFO       *MemoryInfo;
>> +  UINTN                        Index;
>>   
>>     // Get Virtual Memory Map from the Platform Library
>>     ArmPlatformGetVirtualMemoryMap (&MemoryTable);
>>   
>> -  // Ensure PcdSystemMemorySize has been set
>> -  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
>> +  // Get additional info not provided by MemoryTable
>> +  RpiPlatformGetVirtualMemoryInfo (&MemoryInfo);
>>   
>> -  // FD without variable store
>> -  AddReservedMemoryRegion (&MemoryTable[0]);
>> -
>> -  // Variable store.
>> -  AddRuntimeServicesRegion (&MemoryTable[1]);
>> -
>> -  // Trusted Firmware region
>> -  AddReservedMemoryRegion (&MemoryTable[2]);
>> -
>> -  // Usable memory.
>> -  BuildResourceDescriptorHob (
>> -    EFI_RESOURCE_SYSTEM_MEMORY,
>> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
>> -    MemoryTable[3].PhysicalBase,
>> -    MemoryTable[3].Length
>> -  );
>> -
>> -  AddReservedMemoryRegion (&MemoryTable[4]);
>> +  // Register each memory region
>> +  for (Index = 0; MemoryTable[Index].Length != 0; Index++) {
>> +    ASSERT (MemoryInfo[Index].Type < ARRAY_SIZE (AddRegion));
>> +    DEBUG ((DEBUG_INFO, "%s:\n"
>> +      "\tPhysicalBase: 0x%lX\n"
>> +      "\tVirtualBase: 0x%lX\n"
>> +      "\tLength: 0x%lX\n",
>> +      MemoryInfo[Index].Name,
>> +      MemoryTable[Index].PhysicalBase,
>> +      MemoryTable[Index].VirtualBase,
>> +      MemoryTable[Index].Length));
>> +    AddRegion[MemoryInfo[Index].Type] (&MemoryTable[Index]);
>> +  }
>>   
>>     // Build Memory Allocation Hob
>>     InitMmu (MemoryTable);
>> diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
>> index 0084c010936d..d39210c7a4f1 100644
>> --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
>> +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
>> @@ -24,6 +24,7 @@ [Packages]
>>     EmbeddedPkg/EmbeddedPkg.dec
>>     ArmPkg/ArmPkg.dec
>>     ArmPlatformPkg/ArmPlatformPkg.dec
>> +  Platform/RaspberryPi/RaspberryPi.dec
>>   
>>   [LibraryClasses]
>>     DebugLib
>> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>> index 85462febdd8d..c0e2a75451c3 100644
>> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>> @@ -22,6 +22,7 @@ [Packages]
>>     EmbeddedPkg/EmbeddedPkg.dec
>>     ArmPkg/ArmPkg.dec
>>     ArmPlatformPkg/ArmPlatformPkg.dec
>> +  Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
>>     Silicon/Broadcom/Bcm283x/Bcm283x.dec
>>     Platform/RaspberryPi/RaspberryPi.dec
>>   
>> @@ -50,10 +51,12 @@ [FixedPcd]
>>     gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
>>     gArmTokenSpaceGuid.PcdSystemMemoryBase
>>     gArmTokenSpaceGuid.PcdSystemMemorySize
>> +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase
>>     gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize
>>     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
>>     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
>>     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
>> +  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
>>     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
>>   
>>   [Ppis]
>> diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
>> index 2bfd3f020a6e..1a6a13b9591b 100644
>> --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
>> +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
>> @@ -1,7 +1,9 @@
>>   /** @file
>>    *
>> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>>    *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
>>    *  Copyright (c) 2014, Linaro Limited. All rights reserved.
>> + *  Copyright (c) 2013-2018, ARM Limited. All rights reserved.
> 
> This confuses me slightly - is it an indication that some code has
> been copied from a file including this copyright?

It is. I copy/pasted some code from ArmJunoMem.c that had this 
copyright, which I then proceeded to modify. Hence the reason why you 
find the copyright notice.

> 
>>    *
>>    *  SPDX-License-Identifier: BSD-2-Clause-Patent
>>    *
>> @@ -9,8 +11,11 @@
>>   
>>   #include <Library/ArmPlatformLib.h>
>>   #include <Library/DebugLib.h>
>> -#include <IndustryStandard/Bcm2836.h>
>>   #include <Library/PcdLib.h>
>> +#include <Library/RPiMem.h>
>> +#include <Library/MemoryAllocationLib.h>
> 
> Could you move MemoryAllocationLib.h above PcdLib.h?

Will do.

I will also take into account comments for the other patches wrt to 
alphabetical order for the PCDs as well as the additional comment for x1 
in the assembly before submitting a v2.

Regards,

/Pete

> 
> /
>      Leif
> 
>> +#include <IndustryStandard/Bcm2711.h>
>> +#include <IndustryStandard/Bcm2836.h>
>>   
>>   UINT64 mSystemMemoryBase;
>>   extern UINT64 mSystemMemoryEnd;
>> @@ -18,6 +23,13 @@ UINT64 mVideoCoreBase;
>>   UINT64 mVideoCoreSize;
>>   UINT32 mBoardRevision;
>>   
>> +
>> +// The total number of descriptors, including the final "end-of-table" descriptor.
>> +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 10
>> +
>> +STATIC BOOLEAN                  VirtualMemoryInfoInitialized = FALSE;
>> +STATIC RPI_MEMORY_REGION_INFO   VirtualMemoryInfo[MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS];
>> +
>>   #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
>>                          FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
>>                          FixedPcdGet32(PcdFlashNvStorageFtwSpareSize) +  \
>> @@ -29,49 +41,6 @@ UINT32 mBoardRevision;
>>   
>>   #define ATFBase (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize))
>>   
>> -STATIC ARM_MEMORY_REGION_DESCRIPTOR RaspberryPiMemoryRegionDescriptor[] = {
>> -  {
>> -    /* Firmware Volume. */
>> -    FixedPcdGet64 (PcdFdBaseAddress), FixedPcdGet64 (PcdFdBaseAddress),
>> -    FixedPcdGet32 (PcdFdSize) - VariablesSize,
>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>> -  },
>> -  {
>> -    /* Variables Volume. */
>> -    VariablesBase, VariablesBase,
>> -    VariablesSize,
>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>> -  },
>> -  {
>> -    /* ATF reserved RAM. */
>> -    ATFBase, ATFBase,
>> -    FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase,
>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>> -  },
>> -  {
>> -    /* System RAM. */
>> -    FixedPcdGet64 (PcdSystemMemoryBase), FixedPcdGet64 (PcdSystemMemoryBase),
>> -    0,
>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>> -  },
>> -  {
>> -    /* Reserved GPU RAM. */
>> -    0,
>> -    0,
>> -    0,
>> -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
>> -  },
>> -  {
>> -    /* SOC registers. */
>> -    BCM2836_SOC_REGISTERS,
>> -    BCM2836_SOC_REGISTERS,
>> -    BCM2836_SOC_REGISTER_LENGTH,
>> -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
>> -  },
>> -  {
>> -  }
>> -};
>> -
>>   /**
>>     Return the Virtual Memory Map of your platform
>>   
>> @@ -89,6 +58,11 @@ ArmPlatformGetVirtualMemoryMap (
>>     IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
>>     )
>>   {
>> +  UINTN                         Index = 0;
>> +  UINTN                         GpuIndex;
>> +  INT64                         ExtendedMemorySize;
>> +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
>> +
>>     // Early output of the info we got from VideoCore can prove valuable.
>>     DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
>>     DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
>> @@ -97,68 +71,120 @@ ArmPlatformGetVirtualMemoryMap (
>>     ASSERT (mSystemMemoryBase == 0);
>>     ASSERT (VirtualMemoryMap != NULL);
>>   
>> -  RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
>> -    FixedPcdGet64 (PcdSystemMemoryBase);
>> -
>> -  RaspberryPiMemoryRegionDescriptor[4].PhysicalBase =
>> -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase +
>> -    RaspberryPiMemoryRegionDescriptor[3].Length;
>> -
>> -  RaspberryPiMemoryRegionDescriptor[4].VirtualBase =
>> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
>> -
>> -  RaspberryPiMemoryRegionDescriptor[4].Length =
>> -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase -
>> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
>> -
>> -  DEBUG ((DEBUG_INFO, "FD:\n"
>> -    "\tPhysicalBase: 0x%lX\n"
>> -    "\tVirtualBase: 0x%lX\n"
>> -    "\tLength: 0x%lX\n",
>> -    RaspberryPiMemoryRegionDescriptor[0].PhysicalBase,
>> -    RaspberryPiMemoryRegionDescriptor[0].VirtualBase,
>> -    RaspberryPiMemoryRegionDescriptor[0].Length +
>> -    RaspberryPiMemoryRegionDescriptor[1].Length));
>> -
>> -  DEBUG ((DEBUG_INFO, "Variables (part of FD):\n"
>> -    "\tPhysicalBase: 0x%lX\n"
>> -    "\tVirtualBase: 0x%lX\n"
>> -    "\tLength: 0x%lX\n",
>> -    RaspberryPiMemoryRegionDescriptor[1].PhysicalBase,
>> -    RaspberryPiMemoryRegionDescriptor[1].VirtualBase,
>> -    RaspberryPiMemoryRegionDescriptor[1].Length));
>> -
>> -  DEBUG ((DEBUG_INFO, "ATF RAM:\n"
>> -    "\tPhysicalBase: 0x%lX\n"
>> -    "\tVirtualBase: 0x%lX\n"
>> -    "\tLength: 0x%lX\n",
>> -    RaspberryPiMemoryRegionDescriptor[2].PhysicalBase,
>> -    RaspberryPiMemoryRegionDescriptor[2].VirtualBase,
>> -    RaspberryPiMemoryRegionDescriptor[2].Length));
>> -
>> -  DEBUG ((DEBUG_INFO, "System RAM:\n"
>> -    "\tPhysicalBase: 0x%lX\n"
>> -    "\tVirtualBase: 0x%lX\n"
>> -    "\tLength: 0x%lX\n",
>> -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase,
>> -    RaspberryPiMemoryRegionDescriptor[3].VirtualBase,
>> -    RaspberryPiMemoryRegionDescriptor[3].Length));
>> -
>> -  DEBUG ((DEBUG_INFO, "GPU Reserved:\n"
>> -    "\tPhysicalBase: 0x%lX\n"
>> -    "\tVirtualBase: 0x%lX\n"
>> -    "\tLength: 0x%lX\n",
>> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase,
>> -    RaspberryPiMemoryRegionDescriptor[4].VirtualBase,
>> -    RaspberryPiMemoryRegionDescriptor[4].Length));
>> -
>> -  DEBUG ((DEBUG_INFO, "SoC reserved:\n"
>> -    "\tPhysicalBase: 0x%lX\n"
>> -    "\tVirtualBase: 0x%lX\n"
>> -    "\tLength: 0x%lX\n",
>> -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase,
>> -    RaspberryPiMemoryRegionDescriptor[5].VirtualBase,
>> -    RaspberryPiMemoryRegionDescriptor[5].Length));
>> -
>> -  *VirtualMemoryMap = RaspberryPiMemoryRegionDescriptor;
>> +  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages
>> +                       (EFI_SIZE_TO_PAGES (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
>> +                       MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
>> +  if (VirtualMemoryTable == NULL) {
>> +    return;
>> +  }
>> +
>> +
>> +  // Firmware Volume
>> +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdFdBaseAddress);
>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>> +  VirtualMemoryTable[Index].Length          = FixedPcdGet32 (PcdFdSize) - VariablesSize;
>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
>> +  VirtualMemoryInfo[Index++].Name           = L"FD";
>> +
>> +  // Variable Volume
>> +  VirtualMemoryTable[Index].PhysicalBase    = VariablesBase;
>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>> +  VirtualMemoryTable[Index].Length          = VariablesSize;
>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RUNTIME_REGION;
>> +  VirtualMemoryInfo[Index++].Name           = L"FD Variables";
>> +
>> +  // TF-A reserved RAM
>> +  VirtualMemoryTable[Index].PhysicalBase    = ATFBase;
>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>> +  VirtualMemoryTable[Index].Length          = FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase;
>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
>> +  VirtualMemoryInfo[Index++].Name           = L"TF-A RAM";
>> +
>> +  // Base System RAM
>> +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdSystemMemoryBase);
>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>> +  VirtualMemoryTable[Index].Length          = mSystemMemoryEnd + 1 - FixedPcdGet64 (PcdSystemMemoryBase);
>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_BASIC_REGION;
>> +  VirtualMemoryInfo[Index++].Name           = L"Base System RAM";
>> +
>> +  // GPU Reserved
>> +  GpuIndex = Index;
>> +  VirtualMemoryTable[Index].PhysicalBase    = mVideoCoreBase;
>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>> +  VirtualMemoryTable[Index].Length          = mVideoCoreSize;
>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
>> +  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";
>> +  }
>> +
>> +  // Extended SoC registers (PCIe, genet, ...)
>> +  if (BCM2711_SOC_REGISTERS > 0) {
>> +    VirtualMemoryTable[Index].PhysicalBase  = BCM2711_SOC_REGISTERS;
>> +    VirtualMemoryTable[Index].VirtualBase   = VirtualMemoryTable[Index].PhysicalBase;
>> +    VirtualMemoryTable[Index].Length        = BCM2711_SOC_REGISTER_LENGTH;
>> +    VirtualMemoryTable[Index].Attributes    = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
>> +    VirtualMemoryInfo[Index].Type           = RPI_MEM_RESERVED_REGION;
>> +    VirtualMemoryInfo[Index++].Name         = L"SoC Reserved (27xx)";
>> +  }
>> +
>> +  // Base SoC registers
>> +  VirtualMemoryTable[Index].PhysicalBase    = BCM2836_SOC_REGISTERS;
>> +  // On the Pi 3 the SoC registers may overlap VideoCore => fix this
>> +  if (VirtualMemoryTable[GpuIndex].PhysicalBase + VirtualMemoryTable[GpuIndex].Length > VirtualMemoryTable[Index].PhysicalBase) {
>> +    VirtualMemoryTable[GpuIndex].Length = VirtualMemoryTable[Index].PhysicalBase - VirtualMemoryTable[GpuIndex].PhysicalBase;
>> +  }
>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>> +  VirtualMemoryTable[Index].Length          = BCM2836_SOC_REGISTER_LENGTH;
>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
>> +  VirtualMemoryInfo[Index++].Name           = L"SoC Reserved (283x)";
>> +
>> +  // End of Table
>> +  VirtualMemoryTable[Index].PhysicalBase    = 0;
>> +  VirtualMemoryTable[Index].VirtualBase     = 0;
>> +  VirtualMemoryTable[Index].Length          = 0;
>> +  VirtualMemoryTable[Index++].Attributes    = (ARM_MEMORY_REGION_ATTRIBUTES)0;
>> +
>> +  ASSERT(Index <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
>> +
>> +  *VirtualMemoryMap = VirtualMemoryTable;
>> +  VirtualMemoryInfoInitialized = TRUE;
>> +}
>> +
>> +/**
>> +  Return additional memory info not populated by the above call.
>> +
>> +  This call should follow the one to ArmPlatformGetVirtualMemoryMap ().
>> +
>> +**/
>> +VOID
>> +RpiPlatformGetVirtualMemoryInfo (
>> +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
>> +  )
>> +{
>> +  ASSERT (VirtualMemoryInfo != NULL);
>> +
>> +  if (!VirtualMemoryInfoInitialized) {
>> +    DEBUG ((DEBUG_ERROR,
>> +      "ArmPlatformGetVirtualMemoryMap must be called before RpiPlatformGetVirtualMemoryInfo.\n"));
>> +    return;
>> +  }
>> +
>> +  *MemoryInfo = VirtualMemoryInfo;
>>   }
>> diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
>> index 3e9171eccb13..c7e17350544a 100644
>> --- a/Platform/RaspberryPi/RaspberryPi.dec
>> +++ b/Platform/RaspberryPi/RaspberryPi.dec
>> @@ -42,6 +42,7 @@ [PcdsFixedAtBuild.common]
>>     gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000005
>>     gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
>>     gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
>> +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
>>   
>>   [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
>>     gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
>> -- 
>> 2.21.0.windows.1
>>


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init
  2019-11-18 17:34     ` Pete Batard
@ 2019-11-18 17:38       ` Leif Lindholm
  2019-11-18 17:40         ` Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 17:38 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd

On Mon, Nov 18, 2019 at 05:34:25PM +0000, Pete Batard wrote:
> Hi Leif,
> 
> On 2019.11.18 17:20, Leif Lindholm wrote:
> > On Thu, Nov 14, 2019 at 04:07:37PM +0000, Pete Batard wrote:
> > > This patch improves memory initialization for the Raspberry Pi Platform by:
> > > 
> > > Using VideoCore mailbox data to reserve only the regions that are actually
> > > mapped. Especially, besides the base RAM size, which was already set using
> > > VideoCore data, we can set the GPU/VideoCore base address as well as the
> > > extended RAM, which is the memory beyond 1 GB that is available on models
> > > such as the Raspberry Pi 4 (for the 2GB or 4GB versions).
> > > 
> > > Introducing a new PcdExtendedMemoryBase PCD for the base address of the
> > > extended memory region, which currently cannot be retrieved from VideoCore
> > > (MBOX_GET_ARM_MEMSIZE still only returns a single region on Bcm2711).
> > > 
> > > Introducing a new RpiPlatformGetVirtualMemoryInfo() companion call to
> > > ArmPlatformGetVirtualMemoryMap() that allows us greatly simplify the
> > > registration of each segment in MemoryPeim() as well as making it easier
> > > to maintain for future models.
> > > 
> > > We also fix SoC register space that should have been marked as reserved
> > > but wasn't until now and remove the unreferenced mSystemMemoryEnd extern
> > > in MemoryInitPeiLib.c.
> > 
> > Minor style comments and one copyright question below.
> > 
> > > Signed-off-by: Pete Batard <pete@akeo.ie>
> > > ---
> > >   Platform/RaspberryPi/Include/Library/RPiMem.h                      |  26 +++
> > >   Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c   |  94 ++++----
> > >   Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf |   1 +
> > >   Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           |   3 +
> > >   Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c          | 242 +++++++++++---------
> > >   Platform/RaspberryPi/RaspberryPi.dec                               |   1 +
> > >   6 files changed, 210 insertions(+), 157 deletions(-)
> > > 
> > > diff --git a/Platform/RaspberryPi/Include/Library/RPiMem.h b/Platform/RaspberryPi/Include/Library/RPiMem.h
> > > new file mode 100644
> > > index 000000000000..0bfc697ed094
> > > --- /dev/null
> > > +++ b/Platform/RaspberryPi/Include/Library/RPiMem.h
> > > @@ -0,0 +1,26 @@
> > > +/** @file
> > > + *
> > > + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
> > > + *
> > > + *  SPDX-License-Identifier: BSD-2-Clause-Patent
> > > + *
> > > + **/
> > > +
> > > +#ifndef __RPI_MEM_H__
> > > +#define __RPI_MEM_H__
> > 
> > As mentioned for earlier patch, please drop leading __.
> 
> Will do. I assume this applies to trailing __ as well.

Thanks!
Amusingly not.
There are some toolchains that complain about leading __, but none I
am aware of that complain about trailing ones. I think they may even
be mandated by the coding style :)

/
    Leif

> 
> > > +
> > > +#define RPI_MEM_BASIC_REGION    0
> > > +#define RPI_MEM_RUNTIME_REGION  1
> > > +#define RPI_MEM_RESERVED_REGION 2
> > > +
> > > +typedef struct {
> > > +  CONST CHAR16*                 Name;
> > > +  UINTN                         Type;
> > > +} RPI_MEMORY_REGION_INFO;
> > > +
> > > +VOID
> > > +RpiPlatformGetVirtualMemoryInfo (
> > > +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
> > > +  );
> > > +
> > > +#endif /* __RPI_MEM_H__ */
> > > diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
> > > index 60cf397f8baa..3a0f7e19e993 100644
> > > --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
> > > +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
> > > @@ -15,8 +15,7 @@
> > >   #include <Library/HobLib.h>
> > >   #include <Library/MemoryAllocationLib.h>
> > >   #include <Library/PcdLib.h>
> > > -
> > > -extern UINT64 mSystemMemoryEnd;
> > > +#include <Library/RPiMem.h>
> > >   VOID
> > >   BuildMemoryTypeInformationHob (
> > > @@ -39,23 +38,32 @@ InitMmu (
> > >     }
> > >   }
> > > +STATIC
> > > +VOID
> > > +AddBasicMemoryRegion (
> > > +  IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
> > > +)
> > > +{
> > > +  BuildResourceDescriptorHob (
> > > +    EFI_RESOURCE_SYSTEM_MEMORY,
> > > +    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> > > +    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> > > +    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> > > +    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> > > +    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> > > +    EFI_RESOURCE_ATTRIBUTE_TESTED,
> > > +    Desc->PhysicalBase,
> > > +    Desc->Length
> > > +  );
> > > +}
> > > +
> > >   STATIC
> > >   VOID
> > >   AddRuntimeServicesRegion (
> > >     IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
> > >   )
> > >   {
> > > -  BuildResourceDescriptorHob (
> > > -    EFI_RESOURCE_SYSTEM_MEMORY,
> > > -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> > > -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_TESTED,
> > > -    Desc->PhysicalBase,
> > > -    Desc->Length
> > > -  );
> > > +  AddBasicMemoryRegion (Desc);
> > >     BuildMemoryAllocationHob (
> > >       Desc->PhysicalBase,
> > > @@ -70,17 +78,7 @@ AddReservedMemoryRegion (
> > >     IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
> > >     )
> > >   {
> > > -  BuildResourceDescriptorHob (
> > > -    EFI_RESOURCE_SYSTEM_MEMORY,
> > > -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> > > -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_TESTED,
> > > -    Desc->PhysicalBase,
> > > -    Desc->Length
> > > -  );
> > > +  AddBasicMemoryRegion (Desc);
> > >     BuildMemoryAllocationHob (
> > >       Desc->PhysicalBase,
> > > @@ -89,6 +87,12 @@ AddReservedMemoryRegion (
> > >     );
> > >   }
> > > +void (*AddRegion[]) (IN ARM_MEMORY_REGION_DESCRIPTOR *Desc) = {
> > > +  AddBasicMemoryRegion,
> > > +  AddRuntimeServicesRegion,
> > > +  AddReservedMemoryRegion,
> > > +  };
> > > +
> > >   /*++
> > >   Routine Description:
> > > @@ -113,36 +117,28 @@ MemoryPeim (
> > >     )
> > >   {
> > >     ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
> > > +  RPI_MEMORY_REGION_INFO       *MemoryInfo;
> > > +  UINTN                        Index;
> > >     // Get Virtual Memory Map from the Platform Library
> > >     ArmPlatformGetVirtualMemoryMap (&MemoryTable);
> > > -  // Ensure PcdSystemMemorySize has been set
> > > -  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
> > > +  // Get additional info not provided by MemoryTable
> > > +  RpiPlatformGetVirtualMemoryInfo (&MemoryInfo);
> > > -  // FD without variable store
> > > -  AddReservedMemoryRegion (&MemoryTable[0]);
> > > -
> > > -  // Variable store.
> > > -  AddRuntimeServicesRegion (&MemoryTable[1]);
> > > -
> > > -  // Trusted Firmware region
> > > -  AddReservedMemoryRegion (&MemoryTable[2]);
> > > -
> > > -  // Usable memory.
> > > -  BuildResourceDescriptorHob (
> > > -    EFI_RESOURCE_SYSTEM_MEMORY,
> > > -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
> > > -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
> > > -    EFI_RESOURCE_ATTRIBUTE_TESTED,
> > > -    MemoryTable[3].PhysicalBase,
> > > -    MemoryTable[3].Length
> > > -  );
> > > -
> > > -  AddReservedMemoryRegion (&MemoryTable[4]);
> > > +  // Register each memory region
> > > +  for (Index = 0; MemoryTable[Index].Length != 0; Index++) {
> > > +    ASSERT (MemoryInfo[Index].Type < ARRAY_SIZE (AddRegion));
> > > +    DEBUG ((DEBUG_INFO, "%s:\n"
> > > +      "\tPhysicalBase: 0x%lX\n"
> > > +      "\tVirtualBase: 0x%lX\n"
> > > +      "\tLength: 0x%lX\n",
> > > +      MemoryInfo[Index].Name,
> > > +      MemoryTable[Index].PhysicalBase,
> > > +      MemoryTable[Index].VirtualBase,
> > > +      MemoryTable[Index].Length));
> > > +    AddRegion[MemoryInfo[Index].Type] (&MemoryTable[Index]);
> > > +  }
> > >     // Build Memory Allocation Hob
> > >     InitMmu (MemoryTable);
> > > diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> > > index 0084c010936d..d39210c7a4f1 100644
> > > --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> > > +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
> > > @@ -24,6 +24,7 @@ [Packages]
> > >     EmbeddedPkg/EmbeddedPkg.dec
> > >     ArmPkg/ArmPkg.dec
> > >     ArmPlatformPkg/ArmPlatformPkg.dec
> > > +  Platform/RaspberryPi/RaspberryPi.dec
> > >   [LibraryClasses]
> > >     DebugLib
> > > diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > > index 85462febdd8d..c0e2a75451c3 100644
> > > --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > > +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
> > > @@ -22,6 +22,7 @@ [Packages]
> > >     EmbeddedPkg/EmbeddedPkg.dec
> > >     ArmPkg/ArmPkg.dec
> > >     ArmPlatformPkg/ArmPlatformPkg.dec
> > > +  Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
> > >     Silicon/Broadcom/Bcm283x/Bcm283x.dec
> > >     Platform/RaspberryPi/RaspberryPi.dec
> > > @@ -50,10 +51,12 @@ [FixedPcd]
> > >     gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
> > >     gArmTokenSpaceGuid.PcdSystemMemoryBase
> > >     gArmTokenSpaceGuid.PcdSystemMemorySize
> > > +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase
> > >     gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize
> > >     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
> > >     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
> > >     gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
> > > +  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
> > >     gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
> > >   [Ppis]
> > > diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> > > index 2bfd3f020a6e..1a6a13b9591b 100644
> > > --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> > > +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> > > @@ -1,7 +1,9 @@
> > >   /** @file
> > >    *
> > > + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
> > >    *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
> > >    *  Copyright (c) 2014, Linaro Limited. All rights reserved.
> > > + *  Copyright (c) 2013-2018, ARM Limited. All rights reserved.
> > 
> > This confuses me slightly - is it an indication that some code has
> > been copied from a file including this copyright?
> 
> It is. I copy/pasted some code from ArmJunoMem.c that had this copyright,
> which I then proceeded to modify. Hence the reason why you find the
> copyright notice.

Sure, that's fine. Could you add a line about that in commit message
though? (Literally just "incorporates some code from ArmJunoMem.c"
would suffice.)

> > 
> > >    *
> > >    *  SPDX-License-Identifier: BSD-2-Clause-Patent
> > >    *
> > > @@ -9,8 +11,11 @@
> > >   #include <Library/ArmPlatformLib.h>
> > >   #include <Library/DebugLib.h>
> > > -#include <IndustryStandard/Bcm2836.h>
> > >   #include <Library/PcdLib.h>
> > > +#include <Library/RPiMem.h>
> > > +#include <Library/MemoryAllocationLib.h>
> > 
> > Could you move MemoryAllocationLib.h above PcdLib.h?
> 
> Will do.
> 
> I will also take into account comments for the other patches wrt to
> alphabetical order for the PCDs as well as the additional comment for x1 in
> the assembly before submitting a v2.

Thanks!

/
   LEif

> Regards,
> 
> /Pete
> 
> > 
> > /
> >      Leif
> > 
> > > +#include <IndustryStandard/Bcm2711.h>
> > > +#include <IndustryStandard/Bcm2836.h>
> > >   UINT64 mSystemMemoryBase;
> > >   extern UINT64 mSystemMemoryEnd;
> > > @@ -18,6 +23,13 @@ UINT64 mVideoCoreBase;
> > >   UINT64 mVideoCoreSize;
> > >   UINT32 mBoardRevision;
> > > +
> > > +// The total number of descriptors, including the final "end-of-table" descriptor.
> > > +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 10
> > > +
> > > +STATIC BOOLEAN                  VirtualMemoryInfoInitialized = FALSE;
> > > +STATIC RPI_MEMORY_REGION_INFO   VirtualMemoryInfo[MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS];
> > > +
> > >   #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
> > >                          FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
> > >                          FixedPcdGet32(PcdFlashNvStorageFtwSpareSize) +  \
> > > @@ -29,49 +41,6 @@ UINT32 mBoardRevision;
> > >   #define ATFBase (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize))
> > > -STATIC ARM_MEMORY_REGION_DESCRIPTOR RaspberryPiMemoryRegionDescriptor[] = {
> > > -  {
> > > -    /* Firmware Volume. */
> > > -    FixedPcdGet64 (PcdFdBaseAddress), FixedPcdGet64 (PcdFdBaseAddress),
> > > -    FixedPcdGet32 (PcdFdSize) - VariablesSize,
> > > -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> > > -  },
> > > -  {
> > > -    /* Variables Volume. */
> > > -    VariablesBase, VariablesBase,
> > > -    VariablesSize,
> > > -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> > > -  },
> > > -  {
> > > -    /* ATF reserved RAM. */
> > > -    ATFBase, ATFBase,
> > > -    FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase,
> > > -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> > > -  },
> > > -  {
> > > -    /* System RAM. */
> > > -    FixedPcdGet64 (PcdSystemMemoryBase), FixedPcdGet64 (PcdSystemMemoryBase),
> > > -    0,
> > > -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
> > > -  },
> > > -  {
> > > -    /* Reserved GPU RAM. */
> > > -    0,
> > > -    0,
> > > -    0,
> > > -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
> > > -  },
> > > -  {
> > > -    /* SOC registers. */
> > > -    BCM2836_SOC_REGISTERS,
> > > -    BCM2836_SOC_REGISTERS,
> > > -    BCM2836_SOC_REGISTER_LENGTH,
> > > -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
> > > -  },
> > > -  {
> > > -  }
> > > -};
> > > -
> > >   /**
> > >     Return the Virtual Memory Map of your platform
> > > @@ -89,6 +58,11 @@ ArmPlatformGetVirtualMemoryMap (
> > >     IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
> > >     )
> > >   {
> > > +  UINTN                         Index = 0;
> > > +  UINTN                         GpuIndex;
> > > +  INT64                         ExtendedMemorySize;
> > > +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
> > > +
> > >     // Early output of the info we got from VideoCore can prove valuable.
> > >     DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
> > >     DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
> > > @@ -97,68 +71,120 @@ ArmPlatformGetVirtualMemoryMap (
> > >     ASSERT (mSystemMemoryBase == 0);
> > >     ASSERT (VirtualMemoryMap != NULL);
> > > -  RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
> > > -    FixedPcdGet64 (PcdSystemMemoryBase);
> > > -
> > > -  RaspberryPiMemoryRegionDescriptor[4].PhysicalBase =
> > > -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase +
> > > -    RaspberryPiMemoryRegionDescriptor[3].Length;
> > > -
> > > -  RaspberryPiMemoryRegionDescriptor[4].VirtualBase =
> > > -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
> > > -
> > > -  RaspberryPiMemoryRegionDescriptor[4].Length =
> > > -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase -
> > > -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
> > > -
> > > -  DEBUG ((DEBUG_INFO, "FD:\n"
> > > -    "\tPhysicalBase: 0x%lX\n"
> > > -    "\tVirtualBase: 0x%lX\n"
> > > -    "\tLength: 0x%lX\n",
> > > -    RaspberryPiMemoryRegionDescriptor[0].PhysicalBase,
> > > -    RaspberryPiMemoryRegionDescriptor[0].VirtualBase,
> > > -    RaspberryPiMemoryRegionDescriptor[0].Length +
> > > -    RaspberryPiMemoryRegionDescriptor[1].Length));
> > > -
> > > -  DEBUG ((DEBUG_INFO, "Variables (part of FD):\n"
> > > -    "\tPhysicalBase: 0x%lX\n"
> > > -    "\tVirtualBase: 0x%lX\n"
> > > -    "\tLength: 0x%lX\n",
> > > -    RaspberryPiMemoryRegionDescriptor[1].PhysicalBase,
> > > -    RaspberryPiMemoryRegionDescriptor[1].VirtualBase,
> > > -    RaspberryPiMemoryRegionDescriptor[1].Length));
> > > -
> > > -  DEBUG ((DEBUG_INFO, "ATF RAM:\n"
> > > -    "\tPhysicalBase: 0x%lX\n"
> > > -    "\tVirtualBase: 0x%lX\n"
> > > -    "\tLength: 0x%lX\n",
> > > -    RaspberryPiMemoryRegionDescriptor[2].PhysicalBase,
> > > -    RaspberryPiMemoryRegionDescriptor[2].VirtualBase,
> > > -    RaspberryPiMemoryRegionDescriptor[2].Length));
> > > -
> > > -  DEBUG ((DEBUG_INFO, "System RAM:\n"
> > > -    "\tPhysicalBase: 0x%lX\n"
> > > -    "\tVirtualBase: 0x%lX\n"
> > > -    "\tLength: 0x%lX\n",
> > > -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase,
> > > -    RaspberryPiMemoryRegionDescriptor[3].VirtualBase,
> > > -    RaspberryPiMemoryRegionDescriptor[3].Length));
> > > -
> > > -  DEBUG ((DEBUG_INFO, "GPU Reserved:\n"
> > > -    "\tPhysicalBase: 0x%lX\n"
> > > -    "\tVirtualBase: 0x%lX\n"
> > > -    "\tLength: 0x%lX\n",
> > > -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase,
> > > -    RaspberryPiMemoryRegionDescriptor[4].VirtualBase,
> > > -    RaspberryPiMemoryRegionDescriptor[4].Length));
> > > -
> > > -  DEBUG ((DEBUG_INFO, "SoC reserved:\n"
> > > -    "\tPhysicalBase: 0x%lX\n"
> > > -    "\tVirtualBase: 0x%lX\n"
> > > -    "\tLength: 0x%lX\n",
> > > -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase,
> > > -    RaspberryPiMemoryRegionDescriptor[5].VirtualBase,
> > > -    RaspberryPiMemoryRegionDescriptor[5].Length));
> > > -
> > > -  *VirtualMemoryMap = RaspberryPiMemoryRegionDescriptor;
> > > +  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages
> > > +                       (EFI_SIZE_TO_PAGES (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
> > > +                       MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
> > > +  if (VirtualMemoryTable == NULL) {
> > > +    return;
> > > +  }
> > > +
> > > +
> > > +  // Firmware Volume
> > > +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdFdBaseAddress);
> > > +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> > > +  VirtualMemoryTable[Index].Length          = FixedPcdGet32 (PcdFdSize) - VariablesSize;
> > > +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> > > +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
> > > +  VirtualMemoryInfo[Index++].Name           = L"FD";
> > > +
> > > +  // Variable Volume
> > > +  VirtualMemoryTable[Index].PhysicalBase    = VariablesBase;
> > > +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> > > +  VirtualMemoryTable[Index].Length          = VariablesSize;
> > > +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> > > +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RUNTIME_REGION;
> > > +  VirtualMemoryInfo[Index++].Name           = L"FD Variables";
> > > +
> > > +  // TF-A reserved RAM
> > > +  VirtualMemoryTable[Index].PhysicalBase    = ATFBase;
> > > +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> > > +  VirtualMemoryTable[Index].Length          = FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase;
> > > +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> > > +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
> > > +  VirtualMemoryInfo[Index++].Name           = L"TF-A RAM";
> > > +
> > > +  // Base System RAM
> > > +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdSystemMemoryBase);
> > > +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> > > +  VirtualMemoryTable[Index].Length          = mSystemMemoryEnd + 1 - FixedPcdGet64 (PcdSystemMemoryBase);
> > > +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
> > > +  VirtualMemoryInfo[Index].Type             = RPI_MEM_BASIC_REGION;
> > > +  VirtualMemoryInfo[Index++].Name           = L"Base System RAM";
> > > +
> > > +  // GPU Reserved
> > > +  GpuIndex = Index;
> > > +  VirtualMemoryTable[Index].PhysicalBase    = mVideoCoreBase;
> > > +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> > > +  VirtualMemoryTable[Index].Length          = mVideoCoreSize;
> > > +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> > > +  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";
> > > +  }
> > > +
> > > +  // Extended SoC registers (PCIe, genet, ...)
> > > +  if (BCM2711_SOC_REGISTERS > 0) {
> > > +    VirtualMemoryTable[Index].PhysicalBase  = BCM2711_SOC_REGISTERS;
> > > +    VirtualMemoryTable[Index].VirtualBase   = VirtualMemoryTable[Index].PhysicalBase;
> > > +    VirtualMemoryTable[Index].Length        = BCM2711_SOC_REGISTER_LENGTH;
> > > +    VirtualMemoryTable[Index].Attributes    = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> > > +    VirtualMemoryInfo[Index].Type           = RPI_MEM_RESERVED_REGION;
> > > +    VirtualMemoryInfo[Index++].Name         = L"SoC Reserved (27xx)";
> > > +  }
> > > +
> > > +  // Base SoC registers
> > > +  VirtualMemoryTable[Index].PhysicalBase    = BCM2836_SOC_REGISTERS;
> > > +  // On the Pi 3 the SoC registers may overlap VideoCore => fix this
> > > +  if (VirtualMemoryTable[GpuIndex].PhysicalBase + VirtualMemoryTable[GpuIndex].Length > VirtualMemoryTable[Index].PhysicalBase) {
> > > +    VirtualMemoryTable[GpuIndex].Length = VirtualMemoryTable[Index].PhysicalBase - VirtualMemoryTable[GpuIndex].PhysicalBase;
> > > +  }
> > > +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
> > > +  VirtualMemoryTable[Index].Length          = BCM2836_SOC_REGISTER_LENGTH;
> > > +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
> > > +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
> > > +  VirtualMemoryInfo[Index++].Name           = L"SoC Reserved (283x)";
> > > +
> > > +  // End of Table
> > > +  VirtualMemoryTable[Index].PhysicalBase    = 0;
> > > +  VirtualMemoryTable[Index].VirtualBase     = 0;
> > > +  VirtualMemoryTable[Index].Length          = 0;
> > > +  VirtualMemoryTable[Index++].Attributes    = (ARM_MEMORY_REGION_ATTRIBUTES)0;
> > > +
> > > +  ASSERT(Index <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
> > > +
> > > +  *VirtualMemoryMap = VirtualMemoryTable;
> > > +  VirtualMemoryInfoInitialized = TRUE;
> > > +}
> > > +
> > > +/**
> > > +  Return additional memory info not populated by the above call.
> > > +
> > > +  This call should follow the one to ArmPlatformGetVirtualMemoryMap ().
> > > +
> > > +**/
> > > +VOID
> > > +RpiPlatformGetVirtualMemoryInfo (
> > > +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
> > > +  )
> > > +{
> > > +  ASSERT (VirtualMemoryInfo != NULL);
> > > +
> > > +  if (!VirtualMemoryInfoInitialized) {
> > > +    DEBUG ((DEBUG_ERROR,
> > > +      "ArmPlatformGetVirtualMemoryMap must be called before RpiPlatformGetVirtualMemoryInfo.\n"));
> > > +    return;
> > > +  }
> > > +
> > > +  *MemoryInfo = VirtualMemoryInfo;
> > >   }
> > > diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
> > > index 3e9171eccb13..c7e17350544a 100644
> > > --- a/Platform/RaspberryPi/RaspberryPi.dec
> > > +++ b/Platform/RaspberryPi/RaspberryPi.dec
> > > @@ -42,6 +42,7 @@ [PcdsFixedAtBuild.common]
> > >     gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000005
> > >     gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
> > >     gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
> > > +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
> > >   [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
> > >     gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
> > > -- 
> > > 2.21.0.windows.1
> > > 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init
  2019-11-18 17:38       ` Leif Lindholm
@ 2019-11-18 17:40         ` Pete Batard
  0 siblings, 0 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-18 17:40 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: devel, ard.biesheuvel, philmd

On 2019.11.18 17:38, Leif Lindholm wrote:
> On Mon, Nov 18, 2019 at 05:34:25PM +0000, Pete Batard wrote:
>> Hi Leif,
>>
>> On 2019.11.18 17:20, Leif Lindholm wrote:
>>> On Thu, Nov 14, 2019 at 04:07:37PM +0000, Pete Batard wrote:
>>>> This patch improves memory initialization for the Raspberry Pi Platform by:
>>>>
>>>> Using VideoCore mailbox data to reserve only the regions that are actually
>>>> mapped. Especially, besides the base RAM size, which was already set using
>>>> VideoCore data, we can set the GPU/VideoCore base address as well as the
>>>> extended RAM, which is the memory beyond 1 GB that is available on models
>>>> such as the Raspberry Pi 4 (for the 2GB or 4GB versions).
>>>>
>>>> Introducing a new PcdExtendedMemoryBase PCD for the base address of the
>>>> extended memory region, which currently cannot be retrieved from VideoCore
>>>> (MBOX_GET_ARM_MEMSIZE still only returns a single region on Bcm2711).
>>>>
>>>> Introducing a new RpiPlatformGetVirtualMemoryInfo() companion call to
>>>> ArmPlatformGetVirtualMemoryMap() that allows us greatly simplify the
>>>> registration of each segment in MemoryPeim() as well as making it easier
>>>> to maintain for future models.
>>>>
>>>> We also fix SoC register space that should have been marked as reserved
>>>> but wasn't until now and remove the unreferenced mSystemMemoryEnd extern
>>>> in MemoryInitPeiLib.c.
>>>
>>> Minor style comments and one copyright question below.
>>>
>>>> Signed-off-by: Pete Batard <pete@akeo.ie>
>>>> ---
>>>>    Platform/RaspberryPi/Include/Library/RPiMem.h                      |  26 +++
>>>>    Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c   |  94 ++++----
>>>>    Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf |   1 +
>>>>    Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf           |   3 +
>>>>    Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c          | 242 +++++++++++---------
>>>>    Platform/RaspberryPi/RaspberryPi.dec                               |   1 +
>>>>    6 files changed, 210 insertions(+), 157 deletions(-)
>>>>
>>>> diff --git a/Platform/RaspberryPi/Include/Library/RPiMem.h b/Platform/RaspberryPi/Include/Library/RPiMem.h
>>>> new file mode 100644
>>>> index 000000000000..0bfc697ed094
>>>> --- /dev/null
>>>> +++ b/Platform/RaspberryPi/Include/Library/RPiMem.h
>>>> @@ -0,0 +1,26 @@
>>>> +/** @file
>>>> + *
>>>> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>>>> + *
>>>> + *  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>> + *
>>>> + **/
>>>> +
>>>> +#ifndef __RPI_MEM_H__
>>>> +#define __RPI_MEM_H__
>>>
>>> As mentioned for earlier patch, please drop leading __.
>>
>> Will do. I assume this applies to trailing __ as well.
> 
> Thanks!
> Amusingly not.
> There are some toolchains that complain about leading __, but none I
> am aware of that complain about trailing ones. I think they may even
> be mandated by the coding style :)

Okay. I'll keep the trailing __ then.

/Pete

> 
> /
>      Leif
> 
>>
>>>> +
>>>> +#define RPI_MEM_BASIC_REGION    0
>>>> +#define RPI_MEM_RUNTIME_REGION  1
>>>> +#define RPI_MEM_RESERVED_REGION 2
>>>> +
>>>> +typedef struct {
>>>> +  CONST CHAR16*                 Name;
>>>> +  UINTN                         Type;
>>>> +} RPI_MEMORY_REGION_INFO;
>>>> +
>>>> +VOID
>>>> +RpiPlatformGetVirtualMemoryInfo (
>>>> +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
>>>> +  );
>>>> +
>>>> +#endif /* __RPI_MEM_H__ */
>>>> diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
>>>> index 60cf397f8baa..3a0f7e19e993 100644
>>>> --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
>>>> +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
>>>> @@ -15,8 +15,7 @@
>>>>    #include <Library/HobLib.h>
>>>>    #include <Library/MemoryAllocationLib.h>
>>>>    #include <Library/PcdLib.h>
>>>> -
>>>> -extern UINT64 mSystemMemoryEnd;
>>>> +#include <Library/RPiMem.h>
>>>>    VOID
>>>>    BuildMemoryTypeInformationHob (
>>>> @@ -39,23 +38,32 @@ InitMmu (
>>>>      }
>>>>    }
>>>> +STATIC
>>>> +VOID
>>>> +AddBasicMemoryRegion (
>>>> +  IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>>>> +)
>>>> +{
>>>> +  BuildResourceDescriptorHob (
>>>> +    EFI_RESOURCE_SYSTEM_MEMORY,
>>>> +    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>>>> +    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>>>> +    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>>>> +    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>>>> +    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>>>> +    EFI_RESOURCE_ATTRIBUTE_TESTED,
>>>> +    Desc->PhysicalBase,
>>>> +    Desc->Length
>>>> +  );
>>>> +}
>>>> +
>>>>    STATIC
>>>>    VOID
>>>>    AddRuntimeServicesRegion (
>>>>      IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>>>>    )
>>>>    {
>>>> -  BuildResourceDescriptorHob (
>>>> -    EFI_RESOURCE_SYSTEM_MEMORY,
>>>> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>>>> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
>>>> -    Desc->PhysicalBase,
>>>> -    Desc->Length
>>>> -  );
>>>> +  AddBasicMemoryRegion (Desc);
>>>>      BuildMemoryAllocationHob (
>>>>        Desc->PhysicalBase,
>>>> @@ -70,17 +78,7 @@ AddReservedMemoryRegion (
>>>>      IN ARM_MEMORY_REGION_DESCRIPTOR *Desc
>>>>      )
>>>>    {
>>>> -  BuildResourceDescriptorHob (
>>>> -    EFI_RESOURCE_SYSTEM_MEMORY,
>>>> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>>>> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
>>>> -    Desc->PhysicalBase,
>>>> -    Desc->Length
>>>> -  );
>>>> +  AddBasicMemoryRegion (Desc);
>>>>      BuildMemoryAllocationHob (
>>>>        Desc->PhysicalBase,
>>>> @@ -89,6 +87,12 @@ AddReservedMemoryRegion (
>>>>      );
>>>>    }
>>>> +void (*AddRegion[]) (IN ARM_MEMORY_REGION_DESCRIPTOR *Desc) = {
>>>> +  AddBasicMemoryRegion,
>>>> +  AddRuntimeServicesRegion,
>>>> +  AddReservedMemoryRegion,
>>>> +  };
>>>> +
>>>>    /*++
>>>>    Routine Description:
>>>> @@ -113,36 +117,28 @@ MemoryPeim (
>>>>      )
>>>>    {
>>>>      ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
>>>> +  RPI_MEMORY_REGION_INFO       *MemoryInfo;
>>>> +  UINTN                        Index;
>>>>      // Get Virtual Memory Map from the Platform Library
>>>>      ArmPlatformGetVirtualMemoryMap (&MemoryTable);
>>>> -  // Ensure PcdSystemMemorySize has been set
>>>> -  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
>>>> +  // Get additional info not provided by MemoryTable
>>>> +  RpiPlatformGetVirtualMemoryInfo (&MemoryInfo);
>>>> -  // FD without variable store
>>>> -  AddReservedMemoryRegion (&MemoryTable[0]);
>>>> -
>>>> -  // Variable store.
>>>> -  AddRuntimeServicesRegion (&MemoryTable[1]);
>>>> -
>>>> -  // Trusted Firmware region
>>>> -  AddReservedMemoryRegion (&MemoryTable[2]);
>>>> -
>>>> -  // Usable memory.
>>>> -  BuildResourceDescriptorHob (
>>>> -    EFI_RESOURCE_SYSTEM_MEMORY,
>>>> -    EFI_RESOURCE_ATTRIBUTE_PRESENT |
>>>> -    EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
>>>> -    EFI_RESOURCE_ATTRIBUTE_TESTED,
>>>> -    MemoryTable[3].PhysicalBase,
>>>> -    MemoryTable[3].Length
>>>> -  );
>>>> -
>>>> -  AddReservedMemoryRegion (&MemoryTable[4]);
>>>> +  // Register each memory region
>>>> +  for (Index = 0; MemoryTable[Index].Length != 0; Index++) {
>>>> +    ASSERT (MemoryInfo[Index].Type < ARRAY_SIZE (AddRegion));
>>>> +    DEBUG ((DEBUG_INFO, "%s:\n"
>>>> +      "\tPhysicalBase: 0x%lX\n"
>>>> +      "\tVirtualBase: 0x%lX\n"
>>>> +      "\tLength: 0x%lX\n",
>>>> +      MemoryInfo[Index].Name,
>>>> +      MemoryTable[Index].PhysicalBase,
>>>> +      MemoryTable[Index].VirtualBase,
>>>> +      MemoryTable[Index].Length));
>>>> +    AddRegion[MemoryInfo[Index].Type] (&MemoryTable[Index]);
>>>> +  }
>>>>      // Build Memory Allocation Hob
>>>>      InitMmu (MemoryTable);
>>>> diff --git a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
>>>> index 0084c010936d..d39210c7a4f1 100644
>>>> --- a/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
>>>> +++ b/Platform/RaspberryPi/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
>>>> @@ -24,6 +24,7 @@ [Packages]
>>>>      EmbeddedPkg/EmbeddedPkg.dec
>>>>      ArmPkg/ArmPkg.dec
>>>>      ArmPlatformPkg/ArmPlatformPkg.dec
>>>> +  Platform/RaspberryPi/RaspberryPi.dec
>>>>    [LibraryClasses]
>>>>      DebugLib
>>>> diff --git a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>>>> index 85462febdd8d..c0e2a75451c3 100644
>>>> --- a/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>>>> +++ b/Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf
>>>> @@ -22,6 +22,7 @@ [Packages]
>>>>      EmbeddedPkg/EmbeddedPkg.dec
>>>>      ArmPkg/ArmPkg.dec
>>>>      ArmPlatformPkg/ArmPlatformPkg.dec
>>>> +  Silicon/Broadcom/Bcm27xx/Bcm27xx.dec
>>>>      Silicon/Broadcom/Bcm283x/Bcm283x.dec
>>>>      Platform/RaspberryPi/RaspberryPi.dec
>>>> @@ -50,10 +51,12 @@ [FixedPcd]
>>>>      gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset
>>>>      gArmTokenSpaceGuid.PcdSystemMemoryBase
>>>>      gArmTokenSpaceGuid.PcdSystemMemorySize
>>>> +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase
>>>>      gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize
>>>>      gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
>>>>      gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
>>>>      gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
>>>> +  gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress
>>>>      gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress
>>>>    [Ppis]
>>>> diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
>>>> index 2bfd3f020a6e..1a6a13b9591b 100644
>>>> --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
>>>> +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
>>>> @@ -1,7 +1,9 @@
>>>>    /** @file
>>>>     *
>>>> + *  Copyright (c) 2019, Pete Batard <pete@akeo.ie>
>>>>     *  Copyright (c) 2017-2018, Andrey Warkentin <andrey.warkentin@gmail.com>
>>>>     *  Copyright (c) 2014, Linaro Limited. All rights reserved.
>>>> + *  Copyright (c) 2013-2018, ARM Limited. All rights reserved.
>>>
>>> This confuses me slightly - is it an indication that some code has
>>> been copied from a file including this copyright?
>>
>> It is. I copy/pasted some code from ArmJunoMem.c that had this copyright,
>> which I then proceeded to modify. Hence the reason why you find the
>> copyright notice.
> 
> Sure, that's fine. Could you add a line about that in commit message
> though? (Literally just "incorporates some code from ArmJunoMem.c"
> would suffice.)
> 
>>>
>>>>     *
>>>>     *  SPDX-License-Identifier: BSD-2-Clause-Patent
>>>>     *
>>>> @@ -9,8 +11,11 @@
>>>>    #include <Library/ArmPlatformLib.h>
>>>>    #include <Library/DebugLib.h>
>>>> -#include <IndustryStandard/Bcm2836.h>
>>>>    #include <Library/PcdLib.h>
>>>> +#include <Library/RPiMem.h>
>>>> +#include <Library/MemoryAllocationLib.h>
>>>
>>> Could you move MemoryAllocationLib.h above PcdLib.h?
>>
>> Will do.
>>
>> I will also take into account comments for the other patches wrt to
>> alphabetical order for the PCDs as well as the additional comment for x1 in
>> the assembly before submitting a v2.
> 
> Thanks!
> 
> /
>     LEif
> 
>> Regards,
>>
>> /Pete
>>
>>>
>>> /
>>>       Leif
>>>
>>>> +#include <IndustryStandard/Bcm2711.h>
>>>> +#include <IndustryStandard/Bcm2836.h>
>>>>    UINT64 mSystemMemoryBase;
>>>>    extern UINT64 mSystemMemoryEnd;
>>>> @@ -18,6 +23,13 @@ UINT64 mVideoCoreBase;
>>>>    UINT64 mVideoCoreSize;
>>>>    UINT32 mBoardRevision;
>>>> +
>>>> +// The total number of descriptors, including the final "end-of-table" descriptor.
>>>> +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 10
>>>> +
>>>> +STATIC BOOLEAN                  VirtualMemoryInfoInitialized = FALSE;
>>>> +STATIC RPI_MEMORY_REGION_INFO   VirtualMemoryInfo[MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS];
>>>> +
>>>>    #define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) +   \
>>>>                           FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \
>>>>                           FixedPcdGet32(PcdFlashNvStorageFtwSpareSize) +  \
>>>> @@ -29,49 +41,6 @@ UINT32 mBoardRevision;
>>>>    #define ATFBase (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize))
>>>> -STATIC ARM_MEMORY_REGION_DESCRIPTOR RaspberryPiMemoryRegionDescriptor[] = {
>>>> -  {
>>>> -    /* Firmware Volume. */
>>>> -    FixedPcdGet64 (PcdFdBaseAddress), FixedPcdGet64 (PcdFdBaseAddress),
>>>> -    FixedPcdGet32 (PcdFdSize) - VariablesSize,
>>>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>>>> -  },
>>>> -  {
>>>> -    /* Variables Volume. */
>>>> -    VariablesBase, VariablesBase,
>>>> -    VariablesSize,
>>>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>>>> -  },
>>>> -  {
>>>> -    /* ATF reserved RAM. */
>>>> -    ATFBase, ATFBase,
>>>> -    FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase,
>>>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>>>> -  },
>>>> -  {
>>>> -    /* System RAM. */
>>>> -    FixedPcdGet64 (PcdSystemMemoryBase), FixedPcdGet64 (PcdSystemMemoryBase),
>>>> -    0,
>>>> -    ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
>>>> -  },
>>>> -  {
>>>> -    /* Reserved GPU RAM. */
>>>> -    0,
>>>> -    0,
>>>> -    0,
>>>> -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
>>>> -  },
>>>> -  {
>>>> -    /* SOC registers. */
>>>> -    BCM2836_SOC_REGISTERS,
>>>> -    BCM2836_SOC_REGISTERS,
>>>> -    BCM2836_SOC_REGISTER_LENGTH,
>>>> -    ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
>>>> -  },
>>>> -  {
>>>> -  }
>>>> -};
>>>> -
>>>>    /**
>>>>      Return the Virtual Memory Map of your platform
>>>> @@ -89,6 +58,11 @@ ArmPlatformGetVirtualMemoryMap (
>>>>      IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
>>>>      )
>>>>    {
>>>> +  UINTN                         Index = 0;
>>>> +  UINTN                         GpuIndex;
>>>> +  INT64                         ExtendedMemorySize;
>>>> +  ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
>>>> +
>>>>      // Early output of the info we got from VideoCore can prove valuable.
>>>>      DEBUG ((DEBUG_INFO, "Board Rev: 0x%lX\n", mBoardRevision));
>>>>      DEBUG ((DEBUG_INFO, "Base RAM : 0x%ll08X (Size 0x%ll08X)\n", mSystemMemoryBase, mSystemMemoryEnd + 1));
>>>> @@ -97,68 +71,120 @@ ArmPlatformGetVirtualMemoryMap (
>>>>      ASSERT (mSystemMemoryBase == 0);
>>>>      ASSERT (VirtualMemoryMap != NULL);
>>>> -  RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 -
>>>> -    FixedPcdGet64 (PcdSystemMemoryBase);
>>>> -
>>>> -  RaspberryPiMemoryRegionDescriptor[4].PhysicalBase =
>>>> -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase +
>>>> -    RaspberryPiMemoryRegionDescriptor[3].Length;
>>>> -
>>>> -  RaspberryPiMemoryRegionDescriptor[4].VirtualBase =
>>>> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
>>>> -
>>>> -  RaspberryPiMemoryRegionDescriptor[4].Length =
>>>> -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase -
>>>> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase;
>>>> -
>>>> -  DEBUG ((DEBUG_INFO, "FD:\n"
>>>> -    "\tPhysicalBase: 0x%lX\n"
>>>> -    "\tVirtualBase: 0x%lX\n"
>>>> -    "\tLength: 0x%lX\n",
>>>> -    RaspberryPiMemoryRegionDescriptor[0].PhysicalBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[0].VirtualBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[0].Length +
>>>> -    RaspberryPiMemoryRegionDescriptor[1].Length));
>>>> -
>>>> -  DEBUG ((DEBUG_INFO, "Variables (part of FD):\n"
>>>> -    "\tPhysicalBase: 0x%lX\n"
>>>> -    "\tVirtualBase: 0x%lX\n"
>>>> -    "\tLength: 0x%lX\n",
>>>> -    RaspberryPiMemoryRegionDescriptor[1].PhysicalBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[1].VirtualBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[1].Length));
>>>> -
>>>> -  DEBUG ((DEBUG_INFO, "ATF RAM:\n"
>>>> -    "\tPhysicalBase: 0x%lX\n"
>>>> -    "\tVirtualBase: 0x%lX\n"
>>>> -    "\tLength: 0x%lX\n",
>>>> -    RaspberryPiMemoryRegionDescriptor[2].PhysicalBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[2].VirtualBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[2].Length));
>>>> -
>>>> -  DEBUG ((DEBUG_INFO, "System RAM:\n"
>>>> -    "\tPhysicalBase: 0x%lX\n"
>>>> -    "\tVirtualBase: 0x%lX\n"
>>>> -    "\tLength: 0x%lX\n",
>>>> -    RaspberryPiMemoryRegionDescriptor[3].PhysicalBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[3].VirtualBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[3].Length));
>>>> -
>>>> -  DEBUG ((DEBUG_INFO, "GPU Reserved:\n"
>>>> -    "\tPhysicalBase: 0x%lX\n"
>>>> -    "\tVirtualBase: 0x%lX\n"
>>>> -    "\tLength: 0x%lX\n",
>>>> -    RaspberryPiMemoryRegionDescriptor[4].PhysicalBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[4].VirtualBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[4].Length));
>>>> -
>>>> -  DEBUG ((DEBUG_INFO, "SoC reserved:\n"
>>>> -    "\tPhysicalBase: 0x%lX\n"
>>>> -    "\tVirtualBase: 0x%lX\n"
>>>> -    "\tLength: 0x%lX\n",
>>>> -    RaspberryPiMemoryRegionDescriptor[5].PhysicalBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[5].VirtualBase,
>>>> -    RaspberryPiMemoryRegionDescriptor[5].Length));
>>>> -
>>>> -  *VirtualMemoryMap = RaspberryPiMemoryRegionDescriptor;
>>>> +  VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages
>>>> +                       (EFI_SIZE_TO_PAGES (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
>>>> +                       MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
>>>> +  if (VirtualMemoryTable == NULL) {
>>>> +    return;
>>>> +  }
>>>> +
>>>> +
>>>> +  // Firmware Volume
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdFdBaseAddress);
>>>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>>>> +  VirtualMemoryTable[Index].Length          = FixedPcdGet32 (PcdFdSize) - VariablesSize;
>>>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>>>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
>>>> +  VirtualMemoryInfo[Index++].Name           = L"FD";
>>>> +
>>>> +  // Variable Volume
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = VariablesBase;
>>>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>>>> +  VirtualMemoryTable[Index].Length          = VariablesSize;
>>>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>>>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RUNTIME_REGION;
>>>> +  VirtualMemoryInfo[Index++].Name           = L"FD Variables";
>>>> +
>>>> +  // TF-A reserved RAM
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = ATFBase;
>>>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>>>> +  VirtualMemoryTable[Index].Length          = FixedPcdGet64 (PcdSystemMemoryBase) - ATFBase;
>>>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>>>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
>>>> +  VirtualMemoryInfo[Index++].Name           = L"TF-A RAM";
>>>> +
>>>> +  // Base System RAM
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = FixedPcdGet64 (PcdSystemMemoryBase);
>>>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>>>> +  VirtualMemoryTable[Index].Length          = mSystemMemoryEnd + 1 - FixedPcdGet64 (PcdSystemMemoryBase);
>>>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
>>>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_BASIC_REGION;
>>>> +  VirtualMemoryInfo[Index++].Name           = L"Base System RAM";
>>>> +
>>>> +  // GPU Reserved
>>>> +  GpuIndex = Index;
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = mVideoCoreBase;
>>>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>>>> +  VirtualMemoryTable[Index].Length          = mVideoCoreSize;
>>>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
>>>> +  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";
>>>> +  }
>>>> +
>>>> +  // Extended SoC registers (PCIe, genet, ...)
>>>> +  if (BCM2711_SOC_REGISTERS > 0) {
>>>> +    VirtualMemoryTable[Index].PhysicalBase  = BCM2711_SOC_REGISTERS;
>>>> +    VirtualMemoryTable[Index].VirtualBase   = VirtualMemoryTable[Index].PhysicalBase;
>>>> +    VirtualMemoryTable[Index].Length        = BCM2711_SOC_REGISTER_LENGTH;
>>>> +    VirtualMemoryTable[Index].Attributes    = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
>>>> +    VirtualMemoryInfo[Index].Type           = RPI_MEM_RESERVED_REGION;
>>>> +    VirtualMemoryInfo[Index++].Name         = L"SoC Reserved (27xx)";
>>>> +  }
>>>> +
>>>> +  // Base SoC registers
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = BCM2836_SOC_REGISTERS;
>>>> +  // On the Pi 3 the SoC registers may overlap VideoCore => fix this
>>>> +  if (VirtualMemoryTable[GpuIndex].PhysicalBase + VirtualMemoryTable[GpuIndex].Length > VirtualMemoryTable[Index].PhysicalBase) {
>>>> +    VirtualMemoryTable[GpuIndex].Length = VirtualMemoryTable[Index].PhysicalBase - VirtualMemoryTable[GpuIndex].PhysicalBase;
>>>> +  }
>>>> +  VirtualMemoryTable[Index].VirtualBase     = VirtualMemoryTable[Index].PhysicalBase;
>>>> +  VirtualMemoryTable[Index].Length          = BCM2836_SOC_REGISTER_LENGTH;
>>>> +  VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
>>>> +  VirtualMemoryInfo[Index].Type             = RPI_MEM_RESERVED_REGION;
>>>> +  VirtualMemoryInfo[Index++].Name           = L"SoC Reserved (283x)";
>>>> +
>>>> +  // End of Table
>>>> +  VirtualMemoryTable[Index].PhysicalBase    = 0;
>>>> +  VirtualMemoryTable[Index].VirtualBase     = 0;
>>>> +  VirtualMemoryTable[Index].Length          = 0;
>>>> +  VirtualMemoryTable[Index++].Attributes    = (ARM_MEMORY_REGION_ATTRIBUTES)0;
>>>> +
>>>> +  ASSERT(Index <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
>>>> +
>>>> +  *VirtualMemoryMap = VirtualMemoryTable;
>>>> +  VirtualMemoryInfoInitialized = TRUE;
>>>> +}
>>>> +
>>>> +/**
>>>> +  Return additional memory info not populated by the above call.
>>>> +
>>>> +  This call should follow the one to ArmPlatformGetVirtualMemoryMap ().
>>>> +
>>>> +**/
>>>> +VOID
>>>> +RpiPlatformGetVirtualMemoryInfo (
>>>> +  IN RPI_MEMORY_REGION_INFO** MemoryInfo
>>>> +  )
>>>> +{
>>>> +  ASSERT (VirtualMemoryInfo != NULL);
>>>> +
>>>> +  if (!VirtualMemoryInfoInitialized) {
>>>> +    DEBUG ((DEBUG_ERROR,
>>>> +      "ArmPlatformGetVirtualMemoryMap must be called before RpiPlatformGetVirtualMemoryInfo.\n"));
>>>> +    return;
>>>> +  }
>>>> +
>>>> +  *MemoryInfo = VirtualMemoryInfo;
>>>>    }
>>>> diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec
>>>> index 3e9171eccb13..c7e17350544a 100644
>>>> --- a/Platform/RaspberryPi/RaspberryPi.dec
>>>> +++ b/Platform/RaspberryPi/RaspberryPi.dec
>>>> @@ -42,6 +42,7 @@ [PcdsFixedAtBuild.common]
>>>>      gRaspberryPiTokenSpaceGuid.PcdNvStorageVariableBase|0x0|UINT32|0x00000005
>>>>      gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwSpareBase|0x0|UINT32|0x00000006
>>>>      gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007
>>>> +  gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008
>>>>    [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
>>>>      gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
>>>> -- 
>>>> 2.21.0.windows.1
>>>>
>>


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-14 16:07 ` [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection Pete Batard
  2019-11-14 16:36   ` [edk2-devel] " Michael Brown
@ 2019-11-18 17:51   ` Leif Lindholm
  2019-11-18 17:58     ` Pete Batard
  1 sibling, 1 reply; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 17:51 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd

On Thu, Nov 14, 2019 at 04:07:33PM +0000, Pete Batard wrote:
> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> 
> Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.
> 
> This uses the board revision to return a numeric value representing
> the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).
> 
> Knowing the Pi family will help us set the SD card routing when we
> introduce support for the Pi 4 and should also be easier to maintain
> than if using individual model detection.
> 
> Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
> RpiFirmwareGetModelName ().

Can you drop the above line and include the below as 1/? in v2?

/
    Leif

>From 59f01ff36ac7918e9ce166acbd3e963f638ab4b1 Mon Sep 17 00:00:00 2001
From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
Date: Mon, 18 Nov 2019 17:47:06 +0000
Subject: [PATCH edk2-platforms 1/1] Platform/RPi: Add missing model name

add a missing entry for the "Raspberry Pi Compute Module 3+" in
RpiFirmwareGetModelName ().

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
index 9b4aa068857c..dcb434fabefe 100644
--- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
+++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
@@ -1,5 +1,6 @@
 /** @file
  *
+ *  Copyright (c) 2019, ARM Limited. All rights reserved.
  *  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
  *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
  *
@@ -595,6 +596,8 @@ RpiFirmwareGetModelName (
     return "Raspberry Pi 3 Model B+";
   case 0x0E:
     return "Raspberry Pi 3 Model A+";
+  case 0x10:
+    return "Raspberry Pi Compute Module 3+";
   case 0x11:
     return "Raspberry Pi 4 Model B";
   default:
-- 
2.20.1




^ permalink raw reply related	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-18 17:51   ` Leif Lindholm
@ 2019-11-18 17:58     ` Pete Batard
  2019-11-18 18:05       ` Leif Lindholm
  0 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-18 17:58 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: devel, ard.biesheuvel, philmd

On 2019.11.18 17:51, Leif Lindholm wrote:
> On Thu, Nov 14, 2019 at 04:07:33PM +0000, Pete Batard wrote:
>> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
>>
>> Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.
>>
>> This uses the board revision to return a numeric value representing
>> the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).
>>
>> Knowing the Pi family will help us set the SD card routing when we
>> introduce support for the Pi 4 and should also be easier to maintain
>> than if using individual model detection.
>>
>> Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
>> RpiFirmwareGetModelName ().
> 
> Can you drop the above line and include the below as 1/? in v2?

Okay.

Note that since you requested alphabetical for PCDs, I'm going to have 
an "Also" in 2/ (now 3/) since the existing PCDs in 
Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf are out of 
alphabetical order.

I sure hope you're not going to ask me to split this extra reordering 
into a separate commit...

Regards,

/Pete

> 
> /
>      Leif
> 
>  From 59f01ff36ac7918e9ce166acbd3e963f638ab4b1 Mon Sep 17 00:00:00 2001
> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> Date: Mon, 18 Nov 2019 17:47:06 +0000
> Subject: [PATCH edk2-platforms 1/1] Platform/RPi: Add missing model name
> 
> add a missing entry for the "Raspberry Pi Compute Module 3+" in
> RpiFirmwareGetModelName ().
> 
> Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
> ---
>   Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
> index 9b4aa068857c..dcb434fabefe 100644
> --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
> +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
> @@ -1,5 +1,6 @@
>   /** @file
>    *
> + *  Copyright (c) 2019, ARM Limited. All rights reserved.
>    *  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>    *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
>    *
> @@ -595,6 +596,8 @@ RpiFirmwareGetModelName (
>       return "Raspberry Pi 3 Model B+";
>     case 0x0E:
>       return "Raspberry Pi 3 Model A+";
> +  case 0x10:
> +    return "Raspberry Pi Compute Module 3+";
>     case 0x11:
>       return "Raspberry Pi 4 Model B";
>     default:
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-18 17:58     ` Pete Batard
@ 2019-11-18 18:05       ` Leif Lindholm
  2019-11-18 18:32         ` Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Leif Lindholm @ 2019-11-18 18:05 UTC (permalink / raw)
  To: Pete Batard; +Cc: devel, ard.biesheuvel, philmd

On Mon, Nov 18, 2019 at 05:58:05PM +0000, Pete Batard wrote:
> On 2019.11.18 17:51, Leif Lindholm wrote:
> > On Thu, Nov 14, 2019 at 04:07:33PM +0000, Pete Batard wrote:
> > > From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> > > 
> > > Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.
> > > 
> > > This uses the board revision to return a numeric value representing
> > > the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).
> > > 
> > > Knowing the Pi family will help us set the SD card routing when we
> > > introduce support for the Pi 4 and should also be easier to maintain
> > > than if using individual model detection.
> > > 
> > > Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
> > > RpiFirmwareGetModelName ().
> > 
> > Can you drop the above line and include the below as 1/? in v2?
> 
> Okay.
> 
> Note that since you requested alphabetical for PCDs, I'm going to have an
> "Also" in 2/ (now 3/) since the existing PCDs in
> Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf are out of
> alphabetical order.

Actually, I try to never request reordering of existing lines, so I
would be quite happy for you to skip the changes that would motivate
the use of the "also".

I tend to apply a rule of trying to insert *new* (or moved) lines in a
way that will improve the existing order - or in messy cases at least
not make it worse.

I have had it pointed out to me that this is maybe not entirely
obvious...

Regards,

Leif

> I sure hope you're not going to ask me to split this extra reordering into a
> separate commit...
> 
> Regards,
> 
> /Pete
> 
> > 
> > /
> >      Leif
> > 
> >  From 59f01ff36ac7918e9ce166acbd3e963f638ab4b1 Mon Sep 17 00:00:00 2001
> > From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> > Date: Mon, 18 Nov 2019 17:47:06 +0000
> > Subject: [PATCH edk2-platforms 1/1] Platform/RPi: Add missing model name
> > 
> > add a missing entry for the "Raspberry Pi Compute Module 3+" in
> > RpiFirmwareGetModelName ().
> > 
> > Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
> > ---
> >   Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 3 +++
> >   1 file changed, 3 insertions(+)
> > 
> > diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
> > index 9b4aa068857c..dcb434fabefe 100644
> > --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
> > +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
> > @@ -1,5 +1,6 @@
> >   /** @file
> >    *
> > + *  Copyright (c) 2019, ARM Limited. All rights reserved.
> >    *  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
> >    *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
> >    *
> > @@ -595,6 +596,8 @@ RpiFirmwareGetModelName (
> >       return "Raspberry Pi 3 Model B+";
> >     case 0x0E:
> >       return "Raspberry Pi 3 Model A+";
> > +  case 0x10:
> > +    return "Raspberry Pi Compute Module 3+";
> >     case 0x11:
> >       return "Raspberry Pi 4 Model B";
> >     default:
> > 
> 

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-18 18:05       ` Leif Lindholm
@ 2019-11-18 18:32         ` Pete Batard
  2019-11-19 15:07           ` Ard Biesheuvel
  0 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-18 18:32 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: devel, ard.biesheuvel, philmd

On 2019.11.18 18:05, Leif Lindholm wrote:
> On Mon, Nov 18, 2019 at 05:58:05PM +0000, Pete Batard wrote:
>> On 2019.11.18 17:51, Leif Lindholm wrote:
>>> On Thu, Nov 14, 2019 at 04:07:33PM +0000, Pete Batard wrote:
>>>> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
>>>>
>>>> Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.
>>>>
>>>> This uses the board revision to return a numeric value representing
>>>> the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).
>>>>
>>>> Knowing the Pi family will help us set the SD card routing when we
>>>> introduce support for the Pi 4 and should also be easier to maintain
>>>> than if using individual model detection.
>>>>
>>>> Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
>>>> RpiFirmwareGetModelName ().
>>>
>>> Can you drop the above line and include the below as 1/? in v2?
>>
>> Okay.
>>
>> Note that since you requested alphabetical for PCDs, I'm going to have an
>> "Also" in 2/ (now 3/) since the existing PCDs in
>> Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf are out of
>> alphabetical order.
> 
> Actually, I try to never request reordering of existing lines, so I
> would be quite happy for you to skip the changes that would motivate
> the use of the "also".
> 
> I tend to apply a rule of trying to insert *new* (or moved) lines in a
> way that will improve the existing order - or in messy cases at least
> not make it worse.
> 
> I have had it pointed out to me that this is maybe not entirely
> obvious...

Well, this is exactly what I would point out as an example of the strive 
for commit atomicity getting in the way of a more readable codebase as 
well as overall user experience (the users here being the developers who 
are dealing with the code). The reason I'm pointing this out is that, in 
the past, I have been dealing with projects that seemed to care more 
about keeping a squeaky clean commit history than they seemed to care 
about making the underlying code as good as it could possibly get, which 
resulted in increased pain for the developers having to contend with 
said codebase and ultimately end-users of the software produced from 
that codebase.

Again, I would assert that there has to exist a middle ground between 
keeping a super-clean commit history and improving the source where it 
can indeed be improved at little cost, by not always defaulting to 
people having to devote extra time splitting patches.

But I understand this is not my choice to make here. Thus I'll stay away 
from reordering that doesn't have to do with new PCDs being introduced.

Regards,

/Pete

> 
> Regards,
> 
> Leif
> 
>> I sure hope you're not going to ask me to split this extra reordering into a
>> separate commit...
>>
>> Regards,
>>
>> /Pete
>>
>>>
>>> /
>>>       Leif
>>>
>>>   From 59f01ff36ac7918e9ce166acbd3e963f638ab4b1 Mon Sep 17 00:00:00 2001
>>> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
>>> Date: Mon, 18 Nov 2019 17:47:06 +0000
>>> Subject: [PATCH edk2-platforms 1/1] Platform/RPi: Add missing model name
>>>
>>> add a missing entry for the "Raspberry Pi Compute Module 3+" in
>>> RpiFirmwareGetModelName ().
>>>
>>> Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
>>> ---
>>>    Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 3 +++
>>>    1 file changed, 3 insertions(+)
>>>
>>> diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
>>> index 9b4aa068857c..dcb434fabefe 100644
>>> --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
>>> +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
>>> @@ -1,5 +1,6 @@
>>>    /** @file
>>>     *
>>> + *  Copyright (c) 2019, ARM Limited. All rights reserved.
>>>     *  Copyright (c) 2017-2018, Andrei Warkentin <andrey.warkentin@gmail.com>
>>>     *  Copyright (c) 2016, Linaro, Ltd. All rights reserved.
>>>     *
>>> @@ -595,6 +596,8 @@ RpiFirmwareGetModelName (
>>>        return "Raspberry Pi 3 Model B+";
>>>      case 0x0E:
>>>        return "Raspberry Pi 3 Model A+";
>>> +  case 0x10:
>>> +    return "Raspberry Pi Compute Module 3+";
>>>      case 0x11:
>>>        return "Raspberry Pi 4 Model B";
>>>      default:
>>>
>>


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-18 18:32         ` Pete Batard
@ 2019-11-19 15:07           ` Ard Biesheuvel
  2019-11-19 16:30             ` [edk2-devel] " Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Ard Biesheuvel @ 2019-11-19 15:07 UTC (permalink / raw)
  To: Pete Batard
  Cc: Leif Lindholm, edk2-devel-groups-io, Philippe Mathieu-Daudé

On Mon, 18 Nov 2019 at 19:32, Pete Batard <pete@akeo.ie> wrote:
>
> On 2019.11.18 18:05, Leif Lindholm wrote:
> > On Mon, Nov 18, 2019 at 05:58:05PM +0000, Pete Batard wrote:
> >> On 2019.11.18 17:51, Leif Lindholm wrote:
> >>> On Thu, Nov 14, 2019 at 04:07:33PM +0000, Pete Batard wrote:
> >>>> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
> >>>>
> >>>> Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.
> >>>>
> >>>> This uses the board revision to return a numeric value representing
> >>>> the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).
> >>>>
> >>>> Knowing the Pi family will help us set the SD card routing when we
> >>>> introduce support for the Pi 4 and should also be easier to maintain
> >>>> than if using individual model detection.
> >>>>
> >>>> Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
> >>>> RpiFirmwareGetModelName ().
> >>>
> >>> Can you drop the above line and include the below as 1/? in v2?
> >>
> >> Okay.
> >>
> >> Note that since you requested alphabetical for PCDs, I'm going to have an
> >> "Also" in 2/ (now 3/) since the existing PCDs in
> >> Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf are out of
> >> alphabetical order.
> >
> > Actually, I try to never request reordering of existing lines, so I
> > would be quite happy for you to skip the changes that would motivate
> > the use of the "also".
> >
> > I tend to apply a rule of trying to insert *new* (or moved) lines in a
> > way that will improve the existing order - or in messy cases at least
> > not make it worse.
> >
> > I have had it pointed out to me that this is maybe not entirely
> > obvious...
>
> Well, this is exactly what I would point out as an example of the strive
> for commit atomicity getting in the way of a more readable codebase as
> well as overall user experience (the users here being the developers who
> are dealing with the code). The reason I'm pointing this out is that, in
> the past, I have been dealing with projects that seemed to care more
> about keeping a squeaky clean commit history than they seemed to care
> about making the underlying code as good as it could possibly get, which
> resulted in increased pain for the developers having to contend with
> said codebase and ultimately end-users of the software produced from
> that codebase.
>
> Again, I would assert that there has to exist a middle ground between
> keeping a super-clean commit history and improving the source where it
> can indeed be improved at little cost, by not always defaulting to
> people having to devote extra time splitting patches.
>
> But I understand this is not my choice to make here. Thus I'll stay away
> from reordering that doesn't have to do with new PCDs being introduced.
>

Please keep in mind that when open source maintainers take ownership
of your code, they assume the responsibility to ensure that it doesn't
get broken by future updates elsewhere in the codebase, often way
beyond the commercial lifetime of the product that is supported by
that code. This is a sizable effort, and an important part of managing
that effort is ensuring that the code is in an acceptable shape to
begin with, and what 'acceptable' means differs between different
maintainers. Not being able to revert a patch easily because it
touches unrelated code may make our lives more difficult years after
you have stopped caring about this platform entirely.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-19 15:07           ` Ard Biesheuvel
@ 2019-11-19 16:30             ` Pete Batard
  2019-11-20 10:27               ` Leif Lindholm
  0 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-19 16:30 UTC (permalink / raw)
  To: devel, ard.biesheuvel; +Cc: Leif Lindholm, Philippe Mathieu-Daudé

On 2019.11.19 15:07, Ard Biesheuvel wrote:
> On Mon, 18 Nov 2019 at 19:32, Pete Batard <pete@akeo.ie> wrote:
>>
>> On 2019.11.18 18:05, Leif Lindholm wrote:
>>> On Mon, Nov 18, 2019 at 05:58:05PM +0000, Pete Batard wrote:
>>>> On 2019.11.18 17:51, Leif Lindholm wrote:
>>>>> On Thu, Nov 14, 2019 at 04:07:33PM +0000, Pete Batard wrote:
>>>>>> From: Samer El-Haj-Mahmoud <samer@elhajmahmoud.com>
>>>>>>
>>>>>> Add GetModelFamily to RASPBERRY_PI_FIRMWARE_PROTOCOL.
>>>>>>
>>>>>> This uses the board revision to return a numeric value representing
>>>>>> the RPi family (1=RPi, 2=RPi2, 3=RPi3 and 4=RPi4).
>>>>>>
>>>>>> Knowing the Pi family will help us set the SD card routing when we
>>>>>> introduce support for the Pi 4 and should also be easier to maintain
>>>>>> than if using individual model detection.
>>>>>>
>>>>>> Also add a missing entry for the "Raspberry Pi Compute Module 3+" in
>>>>>> RpiFirmwareGetModelName ().
>>>>>
>>>>> Can you drop the above line and include the below as 1/? in v2?
>>>>
>>>> Okay.
>>>>
>>>> Note that since you requested alphabetical for PCDs, I'm going to have an
>>>> "Also" in 2/ (now 3/) since the existing PCDs in
>>>> Platform/RaspberryPi/Library/PlatformLib/PlatformLib.inf are out of
>>>> alphabetical order.
>>>
>>> Actually, I try to never request reordering of existing lines, so I
>>> would be quite happy for you to skip the changes that would motivate
>>> the use of the "also".
>>>
>>> I tend to apply a rule of trying to insert *new* (or moved) lines in a
>>> way that will improve the existing order - or in messy cases at least
>>> not make it worse.
>>>
>>> I have had it pointed out to me that this is maybe not entirely
>>> obvious...
>>
>> Well, this is exactly what I would point out as an example of the strive
>> for commit atomicity getting in the way of a more readable codebase as
>> well as overall user experience (the users here being the developers who
>> are dealing with the code). The reason I'm pointing this out is that, in
>> the past, I have been dealing with projects that seemed to care more
>> about keeping a squeaky clean commit history than they seemed to care
>> about making the underlying code as good as it could possibly get, which
>> resulted in increased pain for the developers having to contend with
>> said codebase and ultimately end-users of the software produced from
>> that codebase.
>>
>> Again, I would assert that there has to exist a middle ground between
>> keeping a super-clean commit history and improving the source where it
>> can indeed be improved at little cost, by not always defaulting to
>> people having to devote extra time splitting patches.
>>
>> But I understand this is not my choice to make here. Thus I'll stay away
>> from reordering that doesn't have to do with new PCDs being introduced.
>>
> 
> Please keep in mind that when open source maintainers take ownership
> of your code, they assume the responsibility to ensure that it doesn't
> get broken by future updates elsewhere in the codebase, often way
> beyond the commercial lifetime of the product that is supported by
> that code. This is a sizable effort, and an important part of managing
> that effort is ensuring that the code is in an acceptable shape to
> begin with, and what 'acceptable' means differs between different
> maintainers. Not being able to revert a patch easily because it
> touches unrelated code may make our lives more difficult years after
> you have stopped caring about this platform entirely.

I think you are actually exposing the root of the problem without 
realizing it here.

Elements that may make a maintainer's life more difficult years after 
the contributor stopped working on it can actually be elements that 
makes, and will continue to make, a whole lot of developers' lives much 
easier right now.

For instance, someone today or tomorrow (rather than 2 or 5 years down 
the line) can very well copy from code that got rejected as an "Also" 
(say, the one instance I found in the Pi source where a %s was used 
instead of a %a, which is an easy thing to miss if you're not paying 
attention) and find out they are wasting time on an issue that they 
would never have had to contend with, had the EDK2 maintainership been 
flexible with regards to what might be acceptable to piggyback on a 
patch that pertains to a specific file (IMO, fixing typos or style 
should always be acceptable as a piggyback, and I'd really like to hear 
how including such changes is effectively going to make the maintainers' 
job that harder down the line).

And though this is a not directly related issue, I could also speak 
volumes on how myself, and I assume many, many other developers, have 
wasted countless hours (my current estimate puts that to around 4 to 5 
hours in my case) on the current CRLF enforcing situation with the EDK2 
codebase.

All this to re-state that I wish there existed a balance between the 
well established needs of the maintainers, and what they envision might 
emerge as issues in the long run (which I assert tends to encourage them 
to preserve an existing status-quo), and the possibly not so well 
publicized pain points and time wastage that consumers of the codebase 
encounter, who, of course (and, depending on how this discussion goes, I 
might come to see as perhaps the wisest choice) generally tend to avoid 
venting their frustration on a mailing list that aims at concerning 
itself solely with technical discussions...

In other words, if you are willing to consider how much more painful 
allowing the piggybacking of low-hanging "Also"'s onto existing patch 
may make your life as a maintainer down the line, please also be willing 
to envision the scenarios in which not allowing the same thing might 
actually be making the life of people who work with the codebase, and 
I'd really like to stress out that I'm really not talking only about 
myself here, harder right now.

Regards,

/Pete

> 
> 
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-19 16:30             ` [edk2-devel] " Pete Batard
@ 2019-11-20 10:27               ` Leif Lindholm
  2019-11-20 21:50                 ` Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Leif Lindholm @ 2019-11-20 10:27 UTC (permalink / raw)
  To: Pete Batard; +Cc: edk2-devel-groups-io, Ard Biesheuvel

On Tue, Nov 19, 2019 at 04:30:05PM +0000, Pete Batard wrote:
> > Please keep in mind that when open source maintainers take ownership
> > of your code, they assume the responsibility to ensure that it doesn't
> > get broken by future updates elsewhere in the codebase, often way
> > beyond the commercial lifetime of the product that is supported by
> > that code. This is a sizable effort, and an important part of managing
> > that effort is ensuring that the code is in an acceptable shape to
> > begin with, and what 'acceptable' means differs between different
> > maintainers. Not being able to revert a patch easily because it
> > touches unrelated code may make our lives more difficult years after
> > you have stopped caring about this platform entirely.
>
> I think you are actually exposing the root of the problem without realizing
> it here.

That is quite a condescending thing to say.

> Elements that may make a maintainer's life more difficult years after the
> contributor stopped working on it can actually be elements that makes, and
> will continue to make, a whole lot of developers' lives much easier right
> now.

Much easier than occasionally using git add --patch or git-gui to
stage individual hunks?

Splitting occasional minor changes out into separate patches should be
< 1min effort.

> For instance, someone today or tomorrow (rather than 2 or 5 years down the
> line) can very well copy from code that got rejected as an "Also" (say, the
> one instance I found in the Pi source where a %s was used instead of a %a,
> which is an easy thing to miss if you're not paying attention) and find out
> they are wasting time on an issue that they would never have had to contend
> with, had the EDK2 maintainership been flexible with regards to what might
> be acceptable to piggyback on a patch that pertains to a specific file (IMO,
> fixing typos or style should always be acceptable as a piggyback, and I'd
> really like to hear how including such changes is effectively going to make
> the maintainers' job that harder down the line).

Ard gave a very specific example in the email you are replying to.

I can give (and have given) you others, but since those have seen no
reaction (either acknowledgment or detraction) from you, there seems
to be little point in adding more.

> And though this is a not directly related issue, I could also speak volumes
> on how myself, and I assume many, many other developers, have wasted
> countless hours (my current estimate puts that to around 4 to 5 hours in my
> case) on the current CRLF enforcing situation with the EDK2 codebase.

That is a completely unrelated issue, which I have certainly also
wasted spectacular amounts of time on. And am working towards getting
rid of.

> All this to re-state that I wish there existed a balance between the well
> established needs of the maintainers, and what they envision might emerge as
> issues in the long run (which I assert tends to encourage them to preserve
> an existing status-quo), and the possibly not so well publicized pain points
> and time wastage that consumers of the codebase encounter, who, of course
> (and, depending on how this discussion goes, I might come to see as perhaps
> the wisest choice) generally tend to avoid venting their frustration on a
> mailing list that aims at concerning itself solely with technical
> discussions...

This isn't a balance discussion. Either you believe that open source
development happens in changesets or you do not. Either you see the
value in that for debugging, or you do not.

If what you care about is the ability to go back to what the tree
looked like at a given point in time, then sure, a lot of this will
seem very tedious to you.

This does not mean that any amount of debating the topic will convince
anyone who relies on the fundamentality of changesets for their
workflow.

> In other words, if you are willing to consider how much more painful
> allowing the piggybacking of low-hanging "Also"'s onto existing patch may
> make your life as a maintainer down the line, please also be willing to
> envision the scenarios in which not allowing the same thing might actually
> be making the life of people who work with the codebase, and I'd really like
> to stress out that I'm really not talking only about myself here, harder
> right now.

You do realise that apart from reviewing patches, we also write and
contribute code ourselves - including to several other projects?
All which follow the exact same rule.

Suffice to say, this aspect of TianoCore is no more negotiable than
the same aspect of linux, u-boot or QEMU.

I will be sorry to see you stop contributing to TianoCore if that is
the effect, but I am not willing to continue to rehash the very
fundamentals of open source development.

/

    Leif

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-20 10:27               ` Leif Lindholm
@ 2019-11-20 21:50                 ` Pete Batard
  2019-11-21  8:55                   ` Laszlo Ersek
  0 siblings, 1 reply; 33+ messages in thread
From: Pete Batard @ 2019-11-20 21:50 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: edk2-devel-groups-io, Ard Biesheuvel

Hi Leif,

On 2019.11.20 10:27, Leif Lindholm wrote:
> On Tue, Nov 19, 2019 at 04:30:05PM +0000, Pete Batard wrote:
>>> Please keep in mind that when open source maintainers take ownership
>>> of your code, they assume the responsibility to ensure that it doesn't
>>> get broken by future updates elsewhere in the codebase, often way
>>> beyond the commercial lifetime of the product that is supported by
>>> that code. This is a sizable effort, and an important part of managing
>>> that effort is ensuring that the code is in an acceptable shape to
>>> begin with, and what 'acceptable' means differs between different
>>> maintainers. Not being able to revert a patch easily because it
>>> touches unrelated code may make our lives more difficult years after
>>> you have stopped caring about this platform entirely.
>>
>> I think you are actually exposing the root of the problem without realizing
>> it here.
> 
> That is quite a condescending thing to say.
> 
>> Elements that may make a maintainer's life more difficult years after the
>> contributor stopped working on it can actually be elements that makes, and
>> will continue to make, a whole lot of developers' lives much easier right
>> now.
> 
> Much easier than occasionally using git add --patch or git-gui to
> stage individual hunks?
> 
> Splitting occasional minor changes out into separate patches should be
> < 1min effort.

That "should" *is* the exact issue.

That is the very core of what I am trying to raise here: additional time 
that is being incurred on contributors (as well as maintainers), which, 
I will continue to assert, if a project was less striving for academia 
excellence and more for the real life preservation of everyone's limited 
resources, it should be acceptable to spare when my own experience with 
both contributing and maintaining Open Source projects (yes, most of 
them not as large as EDK2, but also most of them not as small as a a 
single person's side project) has repeatedly demonstrated that 
flexibility rather than intractability with regards to rules, when they 
happen to save everybody's time, is one of the greatest factor in 
attracting quality contributions.

The root of the matter is that, more than often, I have found that what 
"should" be a <1 min effort, turns into a 15 mins or in the worst case 
up to a 1 hour endeavour due to side issues stepping in. And yes, that 
applies even to splitting the occasional minor changes for one-liner 
typos (and please don't be tempted to construe these as unfamiliarity 
with the tools being used), though I will agree that, in most cases, it 
*shouldn't* be that bad. But I will firmly dispute the idea that even 
the most straightforward typo fix effectively takes less than a minute 
to accomplish when you are considering the whole picture (rather than 
the amount of time one may effectively be spending invoking git commands).

Or are you under the impression that someone who is advocating for patch 
piggybacking is not concerned enough with the quality of what they 
submit, to actually want to validate that what they are splitting is up 
to good standards? Even for a one liner, ensuring that a split commit 
does comply to the expected standards of a project like EDK2 is more 
than a one minute affair. And everybody who has enough experience is 
familiar with a "Surely this simple one liner shouldn't break anything" 
that turned into a more dramatic affair than wanted. And yes, I am also 
considering the case where one would be doing the split from the get go 
rather than the one where one submitted a patchset and then a maintainer 
asked them to further split part of it.

Therefore, if you are thinking the earlier statement you pointed to 
above was condescending, then I'd like to present another contender for 
that prize. This <1 min effort is not the reality I have been observing, 
or the one I am expecting anyone else to be observing, which is what is 
actually prompting me to want to go over these matters.

Instead, I will assert that spending less than a minute splitting minor 
changes into a patch series is the exception rather than the rule for 
any contributor who does take the quality of what they submit seriously.

And that is the very core of the issue, because it then becomes a matter 
of having to deallocate time from other endeavours, which is what I 
would like to see at least acknowledged instead of being dismissed as a 
"non issue", because, IMO, this is a matter that I think Open Source 
project maintainers also need to keep on their radar.

>> For instance, someone today or tomorrow (rather than 2 or 5 years down the
>> line) can very well copy from code that got rejected as an "Also" (say, the
>> one instance I found in the Pi source where a %s was used instead of a %a,
>> which is an easy thing to miss if you're not paying attention) and find out
>> they are wasting time on an issue that they would never have had to contend
>> with, had the EDK2 maintainership been flexible with regards to what might
>> be acceptable to piggyback on a patch that pertains to a specific file (IMO,
>> fixing typos or style should always be acceptable as a piggyback, and I'd
>> really like to hear how including such changes is effectively going to make
>> the maintainers' job that harder down the line).
> 
> Ard gave a very specific example in the email you are replying to.

I believe Ard gave a conditional example of what he thinks may happen 
down the line.

I tried to counter with the idea that, if you try to look at the big 
picture, maybe the time possibly being spent that far down the line is 
going to be more than compensated by the time having already been saved 
by others.

> I can give (and have given) you others, but since those have seen no
> reaction (either acknowledgment or detraction) from you, there seems
> to be little point in adding more.
> 
>> And though this is a not directly related issue, I could also speak volumes
>> on how myself, and I assume many, many other developers, have wasted
>> countless hours (my current estimate puts that to around 4 to 5 hours in my
>> case) on the current CRLF enforcing situation with the EDK2 codebase.
> 
> That is a completely unrelated issue, which I have certainly also
> wasted spectacular amounts of time on.

I wouldn't say completely unrelated. Though I am of course not aware of 
the full specifics of it, which might justify some of the delayed action 
that is being taken. Instead, I was trying to use it as an example of a 
project seemingly deciding that it should be acceptable for contributors 
to collectively waste what I will assert is an exceedingly large amount 
of time, rather than just bite the bullet and state "We're gonna pause 
everything and take how many number of days we need to fix that now, so 
that our contributors stop having to waste hours on a matter that no 
other major Open Source project has to make them contend with".

Considering that you are happy to cite the Linux kernel as an example, 
let me posit the following: Do you believe that Linus would have just 
acknowledged that the CRLF issue as something that it is acceptable to 
fix years down the line and that contributors should just have to learn 
to accept for however long it may remain unaddressed?

And that is precisely my point: How far does a project see it as 
acceptable to push time wastage onto contributors, be it for having to 
contend with CRLF issues or spending an extra 5, 10, 15 minutes here and 
there (sometimes more) to split couple-liners into separate patches.

This, IMO, makes the CRLF matter related to this whole discussion. As a 
matter of fact, it is in part not seeing the matter of CRLF having been 
addressed a long time ago that lead me to worry enough about the 
direction this project wants to take to want to post about patch 
piggybacking for typos and style. Had EDK2 sorted CRLF, I probably would 
have kept this reflection to myself...

> And am working towards getting rid of.

That's good to hear. It genuinely can't happen fast enough as I've 
literally just wasted about another hour on this today...

>> All this to re-state that I wish there existed a balance between the well
>> established needs of the maintainers, and what they envision might emerge as
>> issues in the long run (which I assert tends to encourage them to preserve
>> an existing status-quo), and the possibly not so well publicized pain points
>> and time wastage that consumers of the codebase encounter, who, of course
>> (and, depending on how this discussion goes, I might come to see as perhaps
>> the wisest choice) generally tend to avoid venting their frustration on a
>> mailing list that aims at concerning itself solely with technical
>> discussions...
> 
> This isn't a balance discussion. Either you believe that open source
> development happens in changesets or you do not.

I'm just trying to share my experience, stemmed from participating in 
(as well as maintaining) multiple Open Source projects, some of which 
worked well and others which I would qualify as more dysfunctional, 
where I have found that intractability in changeset rules, and the 
inability of maintainers to acknowledge collective "time wastage" (by 
insisting that rules are not there to be flexible or even debated) 
eventually became a deterrent to attracting contributions and, in some 
case, resulted in the project being left struggling.

And please understand that I'm not pushing for maintainership to just 
accept whatever (for instance, I'm not going to state that a patch that 
contains 4 lines of effective code change and 4 of fixing typos/style, 
even super obvious one, should not be split). Just that there should be 
some form of balance with regards to how flexible patchset rules should 
be when one can expect that the collective amount of time wasted by both 
maintainership and contributorship can be reduced in the long run 
(which, in the absolute, may indeed very well incur additional time 
being spent by maintainership, but which, and this is my point, 
maintainership should understand is part of the collective effort to 
ensure that one of the prime resource they need to concern themselves 
with, i.e. the time that needs to be devoted to achieve a desired 
standard of code quality, is minimized for everyone rather than just a 
single party).

> Either you see the
> value in that for debugging, or you do not.
> 
> If what you care about is the ability to go back to what the tree
> looked like at a given point in time, then sure, a lot of this will
> seem very tedious to you.
> 
> This does not mean that any amount of debating the topic will convince
> anyone who relies on the fundamentality of changesets for their
> workflow.
> 
>> In other words, if you are willing to consider how much more painful
>> allowing the piggybacking of low-hanging "Also"'s onto existing patch may
>> make your life as a maintainer down the line, please also be willing to
>> envision the scenarios in which not allowing the same thing might actually
>> be making the life of people who work with the codebase, and I'd really like
>> to stress out that I'm really not talking only about myself here, harder
>> right now.
> 
> You do realise that apart from reviewing patches, we also write and
> contribute code ourselves - including to several other projects?
> All which follow the exact same rule.

Yes. And I am trying to make a point for the collective, which includes 
not just you, but everyone involved in the project.

> Suffice to say, this aspect of TianoCore is no more negotiable than
> the same aspect of linux, u-boot or QEMU.

Yes, that is entirely the choice of the maintainership of a project.

Which is why I am trying to invite them to consider one aspect that I 
believe is often overlooked: trying to treat time as the 3d most 
valuable resource a project needs to concern itself with (end-user 
experience being first and overall code/software quality second), and 
applying flexibility to what some might be a bit too eager to treat as 
non-negotiable rules as a result of that. Rules should be made to serve 
and foster those resources rather than the opposite.

Still I don't expect the project, or more exactly, individual attitudes 
with regards to what one sees as beneficial to the project, to change 
overnight, especially for a behemoth like EDK2. But I want to leave that 
point in the open so that people like you can at least reflect on it 
when they are confronted with various aspects of the project's life, 
which *may* eventually lead them to rethink, as it happened to me, 
whether *some* amount of flexibility can actually be more beneficial to 
a project than over reliance on intractable rules.

> I will be sorry to see you stop contributing to TianoCore if that is
> the effect,

I'm not planning to. As a matter of fact, some years ago, I might have 
made the same arguments you are making to dismiss my very own point, as 
it's only from participating in multiple projects that I have come to 
realize the importance of minimizing time wastage when it comes to 
keeping a project attractive. So I don't consider this discussion, 
regardless of its outcome, as something that would ever lead me to quit 
wanting to contribute to EDK2 altogether. And I also certainly hope that 
this discussion does not come across as as me berating maintainership of 
the project, which, when compared to other projects, I think is actually 
doing a very fine job overall (even if I may come to disagree with some 
the more minute aspects of what is for best when it comes to maintaining 
a project).

It will however limit my willingness to fix low-hanging fruits, as I 
can't recall instances where ones I've tried to fix in the past were the 
<1 min effort you talk about. Even the patch you sent where you 
effectively did the splitting ended up being a 10-15 mins job to 
integrate and resulted in me having to manually edit stuff. And that is 
not even taking into account the time incurred by having to rework the 
second patch in the series or work needed to get the repo to a state 
where said patch should have been applicable.

> but I am not willing to continue to rehash the very
> fundamentals of open source development.

Open Source is what we make it. I believe it is still new enough to 
still be trying to figure out the "rules" that work best. I certainly 
wouldn't say we have figured everything yet to be sure that some of the 
rules we currently apply don't warrant further tweaking...

Regards,

/Pete

PS: If folks start to think that discussion is becoming too distracting 
for the list, then I have no problem taking it off-list, tough I would 
assert that I've pretty much covered everything I wanted to expose with 
regards to my position at this stage.

^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-20 21:50                 ` Pete Batard
@ 2019-11-21  8:55                   ` Laszlo Ersek
  2019-11-21  9:04                     ` Laszlo Ersek
  0 siblings, 1 reply; 33+ messages in thread
From: Laszlo Ersek @ 2019-11-21  8:55 UTC (permalink / raw)
  To: devel, pete, Leif Lindholm; +Cc: Ard Biesheuvel

On 11/20/19 22:50, Pete Batard wrote:

> [...]
> 
> Which is why I am trying to invite them to consider one aspect that I
> believe is often overlooked: trying to treat time as the 3d most
> valuable resource a project needs to concern itself with (end-user
> experience being first and overall code/software quality second), and
> applying flexibility to what some might be a bit too eager to treat as
> non-negotiable rules as a result of that. Rules should be made to serve
> and foster those resources rather than the opposite.

Contribution rules are already made to prioritize time and effort --
*maintainer* time and effort.

- There are fewer maintainers than contributors.

- Maintainers tend to stick around for long, contributors may or may not
(it varies).

- Maintainers generally take more responsibility for the codebase, as a
whole, than contributors do.

- In most cases, reading code is more difficult than writing code.

All of the above turn maintainership and patch review into a permanent
bottleneck at the project level. Unclogging that bottleneck is what
project rules prioritize.

Nobody doubts that strict contribution rules create bottlenecks on the
contributor side. That's the lesser wrong. "Moving fast" leads to
regressions. In a halfway mature project, which users have grown to rely
on, regressions destroy end-user experience (which you put as first
priority).

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-21  8:55                   ` Laszlo Ersek
@ 2019-11-21  9:04                     ` Laszlo Ersek
  2019-11-21 20:02                       ` Pete Batard
  0 siblings, 1 reply; 33+ messages in thread
From: Laszlo Ersek @ 2019-11-21  9:04 UTC (permalink / raw)
  To: devel, pete, Leif Lindholm; +Cc: Ard Biesheuvel

On 11/21/19 09:55, Laszlo Ersek wrote:
> On 11/20/19 22:50, Pete Batard wrote:
> 
>> [...]
>>
>> Which is why I am trying to invite them to consider one aspect that I
>> believe is often overlooked: trying to treat time as the 3d most
>> valuable resource a project needs to concern itself with (end-user
>> experience being first and overall code/software quality second), and
>> applying flexibility to what some might be a bit too eager to treat as
>> non-negotiable rules as a result of that. Rules should be made to serve
>> and foster those resources rather than the opposite.
> 
> Contribution rules are already made to prioritize time and effort --
> *maintainer* time and effort.
> 
> - There are fewer maintainers than contributors.
> 
> - Maintainers tend to stick around for long, contributors may or may not
> (it varies).
> 
> - Maintainers generally take more responsibility for the codebase, as a
> whole, than contributors do.
> 
> - In most cases, reading code is more difficult than writing code.
> 
> All of the above turn maintainership and patch review into a permanent
> bottleneck at the project level. Unclogging that bottleneck is what
> project rules prioritize.
> 
> Nobody doubts that strict contribution rules create bottlenecks on the
> contributor side. That's the lesser wrong. "Moving fast" leads to
> regressions. In a halfway mature project, which users have grown to rely
> on, regressions destroy end-user experience (which you put as first
> priority).

BTW I don't claim that "strict rules" are the only way to keep
regressions out.

Many projects that "move fast" justify moving fast, and justify easing
up on patch review, with having thorough CI. "Thorough CI" is also not
easy though (in particular integration tests) -- keeping the test suite
up-to-date, reviewing patches for the tests (incl. test infrastructure),
plus operating the test environment, also require time and effort.

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [edk2-devel] [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection
  2019-11-21  9:04                     ` Laszlo Ersek
@ 2019-11-21 20:02                       ` Pete Batard
  0 siblings, 0 replies; 33+ messages in thread
From: Pete Batard @ 2019-11-21 20:02 UTC (permalink / raw)
  To: Laszlo Ersek, devel, Leif Lindholm; +Cc: Ard Biesheuvel

Hi Laszlo,

I appreciate your input on this.

However, I find it unfortunate that you seem to be equating my concern 
about minimizing time wastage to "moving fast", as those are two very 
different matters, and "moving fast" isn't what I have been trying to 
advocate for at all.

None of the points I tried to raise are borne from what you might 
perhaps have perceived as a contributor's frustration about a project 
not moving fast enough in their eye. Especially, considering that I've 
literally had to deal with Open Source projects where integration of 
some patches became a multi-year affair (and where this extended delay 
had nothing to do with the usual review/rework/resubmit process) then I 
have to state that there is little to be frustrated about when it comes 
to how fast one is able to get things reviewed and integrated in the EDK2.

Yet, one can move fast or slow, and still waste time.

I guess if I wanted to address some of the points you raise, I could 
mention that lack of flexibility with regards to some rules can come as 
a deterrent to contributors, especially new ones if they have to spend 
what they perceive as an unwarranted amount of their time on elements 
that they'll be hard pressed to see actual tangible benefits of for the 
project as a whole, and how this may ultimately play into contributors 
not wanting to stick around (with the end result of increased work and 
wasted time for maintainers).

But I feel like I would mostly be a re-hashing of what I have already 
tried to point out. Therefore, with the clarification above having been 
made, I am planning to leave the matter at that.

Regards,

/Pete

On 2019.11.21 09:04, Laszlo Ersek wrote:
> On 11/21/19 09:55, Laszlo Ersek wrote:
>> On 11/20/19 22:50, Pete Batard wrote:
>>
>>> [...]
>>>
>>> Which is why I am trying to invite them to consider one aspect that I
>>> believe is often overlooked: trying to treat time as the 3d most
>>> valuable resource a project needs to concern itself with (end-user
>>> experience being first and overall code/software quality second), and
>>> applying flexibility to what some might be a bit too eager to treat as
>>> non-negotiable rules as a result of that. Rules should be made to serve
>>> and foster those resources rather than the opposite.
>>
>> Contribution rules are already made to prioritize time and effort --
>> *maintainer* time and effort.
>>
>> - There are fewer maintainers than contributors.
>>
>> - Maintainers tend to stick around for long, contributors may or may not
>> (it varies).
>>
>> - Maintainers generally take more responsibility for the codebase, as a
>> whole, than contributors do.
>>
>> - In most cases, reading code is more difficult than writing code.
>>
>> All of the above turn maintainership and patch review into a permanent
>> bottleneck at the project level. Unclogging that bottleneck is what
>> project rules prioritize.
>>
>> Nobody doubts that strict contribution rules create bottlenecks on the
>> contributor side. That's the lesser wrong. "Moving fast" leads to
>> regressions. In a halfway mature project, which users have grown to rely
>> on, regressions destroy end-user experience (which you put as first
>> priority).
> 
> BTW I don't claim that "strict rules" are the only way to keep
> regressions out.
> 
> Many projects that "move fast" justify moving fast, and justify easing
> up on patch review, with having thorough CI. "Thorough CI" is also not
> easy though (in particular integration tests) -- keeping the test suite
> up-to-date, reviewing patches for the tests (incl. test infrastructure),
> plus operating the test environment, also require time and effort.
> 
> Thanks
> Laszlo
> 


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2019-11-21 20:02 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-14 16:07 [edk2-platforms][PATCH 0/8] Platform/RPi: Early Raspberry Pi 4 groundwork Pete Batard
2019-11-14 16:07 ` [edk2-platforms][PATCH 1/8] Platform/RPi: Add model family detection Pete Batard
2019-11-14 16:36   ` [edk2-devel] " Michael Brown
2019-11-14 16:55     ` Pete Batard
2019-11-18 17:51   ` Leif Lindholm
2019-11-18 17:58     ` Pete Batard
2019-11-18 18:05       ` Leif Lindholm
2019-11-18 18:32         ` Pete Batard
2019-11-19 15:07           ` Ard Biesheuvel
2019-11-19 16:30             ` [edk2-devel] " Pete Batard
2019-11-20 10:27               ` Leif Lindholm
2019-11-20 21:50                 ` Pete Batard
2019-11-21  8:55                   ` Laszlo Ersek
2019-11-21  9:04                     ` Laszlo Ersek
2019-11-21 20:02                       ` Pete Batard
2019-11-14 16:07 ` [edk2-platforms][PATCH 2/8] Platform/RPi: Replace Bcm283x SoC base register address with a PCD Pete Batard
2019-11-18 16:48   ` Leif Lindholm
2019-11-18 17:19     ` [edk2-devel] " samer.el-haj-mahmoud
2019-11-18 17:26       ` Leif Lindholm
2019-11-14 16:07 ` [edk2-platforms][PATCH 3/8] Silicon/Broadcom: Add Bcm2711 header Pete Batard
2019-11-18 16:50   ` Leif Lindholm
2019-11-14 16:07 ` [edk2-platforms][PATCH 4/8] Platform/RPi: Read more variables from VideoCore during early init Pete Batard
2019-11-18 17:11   ` Leif Lindholm
2019-11-14 16:07 ` [edk2-platforms][PATCH 5/8] Platform/RPi: Clean up and improve early memory init Pete Batard
2019-11-18 17:20   ` Leif Lindholm
2019-11-18 17:34     ` Pete Batard
2019-11-18 17:38       ` Leif Lindholm
2019-11-18 17:40         ` Pete Batard
2019-11-14 16:07 ` [edk2-platforms][PATCH 6/8] Platform/RPi: Replace Mailbox and Watchdog addresses with PCDs Pete Batard
2019-11-18 11:13   ` Philippe Mathieu-Daudé
2019-11-18 13:32     ` Pete Batard
2019-11-14 16:07 ` [edk2-platforms][PATCH 7/8] Platform/RPi: Replace MMCHS1BASE define with a PCD Pete Batard
2019-11-14 16:07 ` [edk2-platforms][PATCH 8/8] Platform/RPi: Replace DW2_USB_BASE_ADDRESS " Pete Batard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox