]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/MemoryInitPeiLib: reserve rather than remove FV memory
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 28 Feb 2018 15:31:34 +0000 (15:31 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Wed, 28 Feb 2018 16:10:58 +0000 (16:10 +0000)
Instead of completely removing the memory occupied by the primary PrePi
FV from the memory map, thereby making it inaccessible to the OS, mark
it as boot services data. This will ensure that the memory is left
untouched by the firmware, but will release it to the OS when it calls
ExitBootServices().

Note that for reasons that are not entirely clear, this only works as
desired if the memory allocation HOB and the resource descriptor HOB
that describe the region are identical in offset and size, and so we
still need to iterate over the descriptors and split them up.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c

index 2feb11f21d5d3fc1ead27a5434d3fc1e5da8d007..01fd028dbd55fc26b81c09a38e2c2281cc130f52 100644 (file)
@@ -129,7 +129,8 @@ MemoryPeim (
   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
+  // core to overwrite this area we must create a memory allocation HOB for the region,\r
+  // but this only works if we split off the underlying resource descriptor as well.\r
   if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {\r
     Found = FALSE;\r
 \r
@@ -145,12 +146,10 @@ MemoryPeim (
         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
+          if (SystemMemoryTop != FdTop) {\r
+            // Create the System Memory HOB for the firmware\r
             BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
-                                        ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r
+                                        ResourceAttributes,\r
                                         PcdGet64 (PcdFdBaseAddress),\r
                                         PcdGet32 (PcdFdSize));\r
 \r
@@ -159,9 +158,9 @@ MemoryPeim (
             NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize);\r
           }\r
         } else {\r
-          // Create the System Memory HOB for the firmware with the non-present attribute\r
+          // Create the System Memory HOB for the firmware\r
           BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
-                                      ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT,\r
+                                      ResourceAttributes,\r
                                       PcdGet64 (PcdFdBaseAddress),\r
                                       PcdGet32 (PcdFdSize));\r
 \r
@@ -177,6 +176,12 @@ MemoryPeim (
                                         ResourceTop - FdTop);\r
           }\r
         }\r
+\r
+        // Mark the memory covering the Firmware Device as boot services data\r
+        BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress),\r
+                                  PcdGet32 (PcdFdSize),\r
+                                  EfiBootServicesData);\r
+\r
         Found = TRUE;\r
         break;\r
       }\r