From: Shannon Zhao <[email protected]>

Here we add the memory space for the memory nodes except the lowest one
in FDT. So these spaces will show up in the UEFI memory map.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Shannon Zhao <[email protected]>
---
 ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.c   | 34 ++++++++++++++++++++++++++++++++++
 ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf |  4 ++++
 2 files changed, 38 insertions(+)

diff --git a/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.c 
b/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.c
index 74f80d1..2c8d785 100644
--- a/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.c
+++ b/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.c
@@ -27,6 +27,7 @@
 #include <Library/HobLib.h>
 #include <libfdt.h>
 #include <Library/XenIoMmioLib.h>
+#include <Library/DxeServicesTableLib.h>
 
 #include <Guid/Fdt.h>
 #include <Guid/VirtioMmioTransport.h>
@@ -304,6 +305,8 @@ InitializeVirtFdtDxe (
   UINT64                         FwCfgDataSize;
   UINT64                         FwCfgDmaAddress;
   UINT64                         FwCfgDmaSize;
+  UINT64                         CurBase;
+  UINT64                         CurSize;
 
   Hob = GetFirstGuidHob(&gFdtHobGuid);
   if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {
@@ -332,6 +335,37 @@ InitializeVirtFdtDxe (
       break;
     }
 
+    //
+    // Check for memory node and add the memory spaces expect the lowest one
+    //
+    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);
+    if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {
+      //
+      // Get the 'reg' property of this node. For now, we will assume
+      // two 8 byte quantities for base and size, respectively.
+      //
+      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
+      if (RegProp != 0 && Len == (2 * sizeof (UINT64))) {
+
+        CurBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);
+        CurSize = fdt64_to_cpu (((UINT64 *)RegProp)[1]);
+
+        if (FixedPcdGet64 (PcdSystemMemoryBase) != CurBase) {
+          Status = gDS->AddMemorySpace(EfiGcdMemoryTypeSystemMemory,
+                                       CurBase, CurSize,
+                                       EFI_MEMORY_WB | EFI_MEMORY_RUNTIME);
+          if (EFI_ERROR(Status)) {
+            ASSERT_EFI_ERROR(Status);
+          }
+         DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n",
+                 __FUNCTION__, CurBase, CurBase + CurSize - 1));
+        }
+      } else {
+        DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",
+               __FUNCTION__));
+      }
+    }
+
     Type = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);
     if (Type == NULL) {
       continue;
diff --git a/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf 
b/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf
index ee2503a..0e6927b 100644
--- a/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf
+++ b/ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf
@@ -43,12 +43,16 @@
   VirtioMmioDeviceLib
   HobLib
   XenIoMmioLib
+  DxeServicesTableLib
 
 [Guids]
   gFdtTableGuid
   gVirtioMmioTransportGuid
   gFdtHobGuid
 
+[FixedPcd]
+  gArmTokenSpaceGuid.PcdSystemMemoryBase
+
 [Pcd]
   gArmVirtTokenSpaceGuid.PcdArmPsciMethod
   gArmVirtTokenSpaceGuid.PcdFwCfgSelectorAddress
-- 
2.0.4


_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to