]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg: HighMemDxe: add memory space for the high memory nodes
authorShannon Zhao <shannon.zhao@linaro.org>
Fri, 4 Dec 2015 16:17:17 +0000 (16:17 +0000)
committerlersek <lersek@Edk2>
Fri, 4 Dec 2015 16:17:17 +0000 (16:17 +0000)
Here we add the memory space for the high 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 <shannon.zhao@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
[lersek@redhat.com: rewrap at 79 chars, use NULL, print Status]

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19124 6f19259b-4bc3-4df7-8a09-765794883524

ArmVirtPkg/ArmVirtQemu.dsc
ArmVirtPkg/ArmVirtQemu.fdf
ArmVirtPkg/HighMemDxe/HighMemDxe.c [new file with mode: 0644]
ArmVirtPkg/HighMemDxe/HighMemDxe.inf [new file with mode: 0644]

index b0d1d08c50406d1213e39f699767ad745a538b8b..e6440ec5da32d618c535d654863076a1a58f6ca6 100644 (file)
   # Platform Driver\r
   #\r
   ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf\r
+  ArmVirtPkg/HighMemDxe/HighMemDxe.inf\r
   OvmfPkg/VirtioBlkDxe/VirtioBlk.inf\r
   OvmfPkg/VirtioScsiDxe/VirtioScsi.inf\r
   OvmfPkg/VirtioNetDxe/VirtioNet.inf\r
index 738e3db57045697e8362ae0d2ef887da19b6b458..f5e6cbd5a11f8db13b245eba5886913a46d68974 100644 (file)
@@ -108,6 +108,7 @@ READ_LOCK_STATUS   = TRUE
   INF MdeModulePkg/Core/Dxe/DxeMain.inf\r
   INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
   INF ArmVirtPkg/VirtFdtDxe/VirtFdtDxe.inf\r
+  INF ArmVirtPkg/HighMemDxe/HighMemDxe.inf\r
 \r
   #\r
   # PI DXE Drivers producing Architectural Protocols (EFI Services)\r
diff --git a/ArmVirtPkg/HighMemDxe/HighMemDxe.c b/ArmVirtPkg/HighMemDxe/HighMemDxe.c
new file mode 100644 (file)
index 0000000..4963164
--- /dev/null
@@ -0,0 +1,109 @@
+/** @file\r
+*  High memory node enumeration DXE driver for ARM Virtual Machines\r
+*\r
+*  Copyright (c) 2015, Linaro Ltd. All rights reserved.\r
+*\r
+*  This program and the accompanying materials are licensed and made available\r
+*  under the terms and conditions of the BSD License which accompanies this\r
+*  distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR\r
+*  IMPLIED.\r
+*\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/HobLib.h>\r
+#include <libfdt.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeHighMemDxe (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  VOID             *Hob;\r
+  VOID             *DeviceTreeBase;\r
+  INT32            Node, Prev;\r
+  EFI_STATUS       Status;\r
+  CONST CHAR8      *Type;\r
+  INT32            Len;\r
+  CONST VOID       *RegProp;\r
+  UINT64           CurBase;\r
+  UINT64           CurSize;\r
+\r
+  Hob = GetFirstGuidHob(&gFdtHobGuid);\r
+  if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);\r
+\r
+  if (fdt_check_header (DeviceTreeBase) != 0) {\r
+    DEBUG ((EFI_D_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__,\r
+      DeviceTreeBase));\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, DeviceTreeBase));\r
+\r
+  //\r
+  // Check for memory node and add the memory spaces expect the lowest one\r
+  //\r
+  for (Prev = 0;; Prev = Node) {\r
+    Node = fdt_next_node (DeviceTreeBase, Prev, NULL);\r
+    if (Node < 0) {\r
+      break;\r
+    }\r
+\r
+    Type = fdt_getprop (DeviceTreeBase, Node, "device_type", &Len);\r
+    if (Type && AsciiStrnCmp (Type, "memory", Len) == 0) {\r
+      //\r
+      // Get the 'reg' property of this node. For now, we will assume\r
+      // two 8 byte quantities for base and size, respectively.\r
+      //\r
+      RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);\r
+      if (RegProp != NULL && Len == (2 * sizeof (UINT64))) {\r
+\r
+        CurBase = fdt64_to_cpu (((UINT64 *)RegProp)[0]);\r
+        CurSize = fdt64_to_cpu (((UINT64 *)RegProp)[1]);\r
+\r
+        if (FixedPcdGet64 (PcdSystemMemoryBase) != CurBase) {\r
+          Status = gDS->AddMemorySpace (\r
+                          EfiGcdMemoryTypeSystemMemory,\r
+                          CurBase, CurSize,\r
+                          EFI_MEMORY_WB | EFI_MEMORY_WC |\r
+                          EFI_MEMORY_WT | EFI_MEMORY_UC);\r
+\r
+          if (EFI_ERROR (Status)) {\r
+            DEBUG ((EFI_D_ERROR,\r
+              "%a: Failed to add System RAM @ 0x%lx - 0x%lx (%r)\n",\r
+              __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r
+            continue;\r
+          }\r
+\r
+          Status = gDS->SetMemorySpaceAttributes (\r
+                          CurBase, CurSize,\r
+                          EFI_MEMORY_WB);\r
+\r
+          if (EFI_ERROR (Status)) {\r
+            DEBUG ((EFI_D_ERROR,\r
+              "%a: Failed to set System RAM @ 0x%lx - 0x%lx attribute (%r)\n",\r
+              __FUNCTION__, CurBase, CurBase + CurSize - 1, Status));\r
+          } else {\r
+            DEBUG ((EFI_D_INFO, "%a: Add System RAM @ 0x%lx - 0x%lx\n",\r
+              __FUNCTION__, CurBase, CurBase + CurSize - 1));\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/ArmVirtPkg/HighMemDxe/HighMemDxe.inf b/ArmVirtPkg/HighMemDxe/HighMemDxe.inf
new file mode 100644 (file)
index 0000000..2b39762
--- /dev/null
@@ -0,0 +1,52 @@
+## @file\r
+#  High memory node enumeration DXE driver for ARM Virtual Machines\r
+#\r
+#  Copyright (c) 2015, Linaro Ltd. All rights reserved.\r
+#\r
+#  This program and the accompanying materials are licensed and made available\r
+#  under the terms and conditions of the BSD License which accompanies this\r
+#  distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR\r
+#  IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = HighMemDxe\r
+  FILE_GUID                      = 63EA1463-FBFA-428A-B97F-E222755852D7\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+\r
+  ENTRY_POINT                    = InitializeHighMemDxe\r
+\r
+[Sources]\r
+  HighMemDxe.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+  ArmVirtPkg/ArmVirtPkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  PcdLib\r
+  UefiDriverEntryPoint\r
+  FdtLib\r
+  HobLib\r
+  DxeServicesTableLib\r
+\r
+[Guids]\r
+  gFdtHobGuid\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid\r