--- /dev/null
+#/* @file\r
+#\r
+# Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
+# Copyright (c) 2014-2017, Linaro Limited. 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 IMPLIED.\r
+#\r
+#*/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x0001001A\r
+ BASE_NAME = QemuVirtMemInfoPeiLib\r
+ FILE_GUID = 0c4d10cf-d949-49b4-bd13-47a4ae22efce\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = ArmVirtMemInfoLib|PEIM\r
+ CONSTRUCTOR = QemuVirtMemInfoPeiLibConstructor\r
+\r
+[Sources]\r
+ QemuVirtMemInfoLib.c\r
+ QemuVirtMemInfoPeiLibConstructor.c\r
+\r
+[Sources.ARM]\r
+ Arm/PhysAddrTop.S\r
+\r
+[Sources.AARCH64]\r
+ AArch64/PhysAddrTop.S\r
+\r
+[Packages]\r
+ ArmPkg/ArmPkg.dec\r
+ ArmVirtPkg/ArmVirtPkg.dec\r
+ EmbeddedPkg/EmbeddedPkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+ MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+ ArmLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ FdtLib\r
+ PcdLib\r
+ MemoryAllocationLib\r
+\r
+[Pcd]\r
+ gArmTokenSpaceGuid.PcdFdBaseAddress\r
+ gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+ gArmTokenSpaceGuid.PcdSystemMemorySize\r
+\r
+[FixedPcd]\r
+ gArmTokenSpaceGuid.PcdFdSize\r
+ gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress\r
+ gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize\r
--- /dev/null
+/** @file\r
+\r
+ Copyright (c) 2014-2017, Linaro Limited. 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 IMPLIED.\r
+\r
+**/\r
+\r
+#include <Base.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <libfdt.h>\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+QemuVirtMemInfoPeiLibConstructor (\r
+ VOID\r
+ )\r
+{\r
+ VOID *DeviceTreeBase;\r
+ INT32 Node, Prev;\r
+ UINT64 NewBase, CurBase;\r
+ UINT64 NewSize, CurSize;\r
+ CONST CHAR8 *Type;\r
+ INT32 Len;\r
+ CONST UINT64 *RegProp;\r
+ RETURN_STATUS PcdStatus;\r
+\r
+ NewBase = 0;\r
+ NewSize = 0;\r
+\r
+ DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);\r
+ ASSERT (DeviceTreeBase != NULL);\r
+\r
+ //\r
+ // Make sure we have a valid device tree blob\r
+ //\r
+ ASSERT (fdt_check_header (DeviceTreeBase) == 0);\r
+\r
+ //\r
+ // Look for the lowest memory node\r
+ //\r
+ for (Prev = 0;; Prev = Node) {\r
+ Node = fdt_next_node (DeviceTreeBase, Prev, NULL);\r
+ if (Node < 0) {\r
+ break;\r
+ }\r
+\r
+ //\r
+ // Check for memory node\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 != 0 && Len == (2 * sizeof (UINT64))) {\r
+\r
+ CurBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));\r
+ CurSize = fdt64_to_cpu (ReadUnaligned64 (RegProp + 1));\r
+\r
+ DEBUG ((DEBUG_INFO, "%a: System RAM @ 0x%lx - 0x%lx\n",\r
+ __FUNCTION__, CurBase, CurBase + CurSize - 1));\r
+\r
+ if (NewBase > CurBase || NewBase == 0) {\r
+ NewBase = CurBase;\r
+ NewSize = CurSize;\r
+ }\r
+ } else {\r
+ DEBUG ((DEBUG_ERROR, "%a: Failed to parse FDT memory node\n",\r
+ __FUNCTION__));\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // Make sure the start of DRAM matches our expectation\r
+ //\r
+ ASSERT (FixedPcdGet64 (PcdSystemMemoryBase) == NewBase);\r
+ PcdStatus = PcdSet64S (PcdSystemMemorySize, NewSize);\r
+ ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+ //\r
+ // We need to make sure that the machine we are running on has at least\r
+ // 128 MB of memory configured, and is currently executing this binary from\r
+ // NOR flash. This prevents a device tree image in DRAM from getting\r
+ // clobbered when our caller installs permanent PEI RAM, before we have a\r
+ // chance of marking its location as reserved or copy it to a freshly\r
+ // allocated block in the permanent PEI RAM in the platform PEIM.\r
+ //\r
+ ASSERT (NewSize >= SIZE_128MB);\r
+ ASSERT (\r
+ (((UINT64)PcdGet64 (PcdFdBaseAddress) +\r
+ (UINT64)PcdGet32 (PcdFdSize)) <= NewBase) ||\r
+ ((UINT64)PcdGet64 (PcdFdBaseAddress) >= (NewBase + NewSize)));\r
+\r
+ return RETURN_SUCCESS;\r
+}\r