]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BeagleBoardPkg: clone MemoryInitPeiLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 30 Nov 2017 15:00:23 +0000 (15:00 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 30 Nov 2017 17:08:41 +0000 (17:08 +0000)
The common MemoryInitPeiLib implementation preserves the primary FV
holding the PrePi module and the compressed secondary FV, and removes
the memory it occupies from the memory map, hiding it from the OS.

The only platform that actual requires this is BeagleBoardPkg, since
it exposes the PeCoff and LZMA libraries in PrePi to DXE core via
special HOBs. So let's give BeagleBoard its own MemoryInitPeiLib, so
that we can clean up the generic version.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
BeagleBoardPkg/BeagleBoardPkg.dsc
BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.c [new file with mode: 0644]
BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf [new file with mode: 0644]

index a1715593770a0404fb884fba5f441e77e41bc26c..5d87ee389124ef3e1b49069723eb72a094e6a3cc 100644 (file)
   MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf\r
   PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf\r
   PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf\r
-  MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf\r
+  MemoryInitPeiLib|BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf\r
 \r
   # 1/123 faster than Stm or Vstm version\r
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
diff --git a/BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.c b/BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.c
new file mode 100644 (file)
index 0000000..2feb11f
--- /dev/null
@@ -0,0 +1,198 @@
+/** @file\r
+*\r
+*  Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
+*\r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this 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 <PiPei.h>\r
+\r
+#include <Library/ArmMmuLib.h>\r
+#include <Library/ArmPlatformLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+VOID\r
+BuildMemoryTypeInformationHob (\r
+  VOID\r
+  );\r
+\r
+STATIC\r
+VOID\r
+InitMmu (\r
+  IN ARM_MEMORY_REGION_DESCRIPTOR  *MemoryTable\r
+  )\r
+{\r
+\r
+  VOID                          *TranslationTableBase;\r
+  UINTN                         TranslationTableSize;\r
+  RETURN_STATUS                 Status;\r
+\r
+  //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
+  //      DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
+  Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r
+  }\r
+}\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+\r
+Arguments:\r
+\r
+  FileHandle  - Handle of the file being invoked.\r
+  PeiServices - Describes the list of possible PEI Services.\r
+\r
+Returns:\r
+\r
+  Status -  EFI_SUCCESS if the boot mode could be set\r
+\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+MemoryPeim (\r
+  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,\r
+  IN UINT64                             UefiMemorySize\r
+  )\r
+{\r
+  ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;\r
+  UINT64                       ResourceLength;\r
+  EFI_PEI_HOB_POINTERS         NextHob;\r
+  EFI_PHYSICAL_ADDRESS         FdTop;\r
+  EFI_PHYSICAL_ADDRESS         SystemMemoryTop;\r
+  EFI_PHYSICAL_ADDRESS         ResourceTop;\r
+  BOOLEAN                      Found;\r
+\r
+  // Get Virtual Memory Map from the Platform Library\r
+  ArmPlatformGetVirtualMemoryMap (&MemoryTable);\r
+\r
+  // Ensure PcdSystemMemorySize has been set\r
+  ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
+\r
+  //\r
+  // Now, the permanent memory has been installed, we can call AllocatePages()\r
+  //\r
+  ResourceAttributes = (\r
+      EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
+      EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+      EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
+      EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
+      EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r
+      EFI_RESOURCE_ATTRIBUTE_TESTED\r
+  );\r
+\r
+  //\r
+  // Check if the resource for the main system memory has been declared\r
+  //\r
+  Found = FALSE;\r
+  NextHob.Raw = GetHobList ();\r
+  while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
+    if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r
+        (PcdGet64 (PcdSystemMemoryBase) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r
+        (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))\r
+    {\r
+      Found = TRUE;\r
+      break;\r
+    }\r
+    NextHob.Raw = GET_NEXT_HOB (NextHob);\r
+  }\r
+\r
+  if (!Found) {\r
+    // Reserved the memory space occupied by the firmware volume\r
+    BuildResourceDescriptorHob (\r
+        EFI_RESOURCE_SYSTEM_MEMORY,\r
+        ResourceAttributes,\r
+        PcdGet64 (PcdSystemMemoryBase),\r
+        PcdGet64 (PcdSystemMemorySize)\r
+    );\r
+  }\r
+\r
+  //\r
+  // Reserved the memory space occupied by the firmware volume\r
+  //\r
+\r
+  SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize);\r
+  FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize);\r
+\r
+  // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE\r
+  // core to overwrite this area we must mark the region with the attribute non-present\r
+  if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {\r
+    Found = FALSE;\r
+\r
+    // Search for System Memory Hob that contains the firmware\r
+    NextHob.Raw = GetHobList ();\r
+    while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
+      if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r
+          (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r
+          (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength))\r
+      {\r
+        ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;\r
+        ResourceLength = NextHob.ResourceDescriptor->ResourceLength;\r
+        ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;\r
+\r
+        if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {\r
+          if (SystemMemoryTop == FdTop) {\r
+            NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT;\r
+          } else {\r
+            // Create the System Memory HOB for the firmware with the non-present attribute\r
+            BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
+                                        ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r
+                                        PcdGet64 (PcdFdBaseAddress),\r
+                                        PcdGet32 (PcdFdSize));\r
+\r
+            // Top of the FD is system memory available for UEFI\r
+            NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize);\r
+            NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize);\r
+          }\r
+        } else {\r
+          // Create the System Memory HOB for the firmware with the non-present attribute\r
+          BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
+                                      ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r
+                                      PcdGet64 (PcdFdBaseAddress),\r
+                                      PcdGet32 (PcdFdSize));\r
+\r
+          // Update the HOB\r
+          NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;\r
+\r
+          // If there is some memory available on the top of the FD then create a HOB\r
+          if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {\r
+            // Create the System Memory HOB for the remaining region (top of the FD)\r
+            BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
+                                        ResourceAttributes,\r
+                                        FdTop,\r
+                                        ResourceTop - FdTop);\r
+          }\r
+        }\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      NextHob.Raw = GET_NEXT_HOB (NextHob);\r
+    }\r
+\r
+    ASSERT(Found);\r
+  }\r
+\r
+  // Build Memory Allocation Hob\r
+  InitMmu (MemoryTable);\r
+\r
+  if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
+    // Optional feature that helps prevent EFI memory map fragmentation.\r
+    BuildMemoryTypeInformationHob ();\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf b/BeagleBoardPkg/Library/MemoryInitPeiLib/MemoryInitPeiLib.inf
new file mode 100644 (file)
index 0000000..0e8c42f
--- /dev/null
@@ -0,0 +1,64 @@
+#/** @file\r
+#\r
+#  Copyright (c) 2011-2014, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this 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                      = BeagleBoardMemoryInitPeiLib\r
+  FILE_GUID                      = e489db0a-d847-4d67-910b-48a833f6fef5\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = MemoryInitPeiLib|SEC PEIM\r
+\r
+[Sources]\r
+  MemoryInitPeiLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+  ArmPlatformPkg/ArmPlatformPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+  ArmMmuLib\r
+  ArmPlatformLib\r
+\r
+[Guids]\r
+  gEfiMemoryTypeInformationGuid\r
+\r
+[FeaturePcd]\r
+  gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob\r
+\r
+[FixedPcd]\r
+  gArmTokenSpaceGuid.PcdFdBaseAddress\r
+  gArmTokenSpaceGuid.PcdFdSize\r
+\r
+  gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize\r
+\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode\r
+  gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData\r
+\r
+[Pcd]\r
+  gArmTokenSpaceGuid.PcdSystemMemoryBase\r
+  gArmTokenSpaceGuid.PcdSystemMemorySize\r
+\r