[Linaro-uefi,05/14] Platforms/AMD/Styx: separate trusted FW region from primary memory HOB

Message ID 1462882313-7637-6-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel May 10, 2016, 12:11 p.m.
The GCD layer in DXE core claims the HOB that covers the PHIT memory
allocation fully, even if this single HOB covers system memory completely.
This means the memory allocation HOBs that are declared next have no effect,
since they conflict with the allocation performed by DXE core, and are
dropped silently.

Instead, describe system memory as two separate regions, one of which can
be used to host the EfiReservedMemory allocation.

The EfiRuntimeServicesData allocation of the FD region also had no effect,
but since it is unnecessary, let's just remove it.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 Platforms/AMD/Styx/Library/MemoryInitPei/MemoryInitPeiLib.c | 56 +++++++++++++-------
 1 file changed, 38 insertions(+), 18 deletions(-)

Patch

diff --git a/Platforms/AMD/Styx/Library/MemoryInitPei/MemoryInitPeiLib.c b/Platforms/AMD/Styx/Library/MemoryInitPei/MemoryInitPeiLib.c
index fd3b36ea45a1..ac172fa526c5 100644
--- a/Platforms/AMD/Styx/Library/MemoryInitPei/MemoryInitPeiLib.c
+++ b/Platforms/AMD/Styx/Library/MemoryInitPei/MemoryInitPeiLib.c
@@ -79,6 +79,8 @@  MemoryPeim (
   IN UINT64                             UefiMemorySize
   )
 {
+  UINT64  Base, Size;
+
   // Ensure PcdSystemMemorySize has been set
   ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
 
@@ -86,6 +88,40 @@  MemoryPeim (
   // Now, the permanent memory has been installed, we can call AllocatePages()
   //
 
+  Base = PcdGet64 (PcdSystemMemoryBase);
+  Size = PcdGet64 (PcdSystemMemorySize);
+  if (FixedPcdGetBool (PcdTrustedFWSupport)) {
+
+    //
+    // For now, we assume that the trusted firmware region is at the base of
+    // system memory, since that is much easier to deal with.
+    //
+    ASSERT (Base == PcdGet64 (PcdTrustedFWMemoryBase));
+
+    Base += PcdGet64 (PcdTrustedFWMemorySize);
+    Size -= PcdGet64 (PcdTrustedFWMemorySize);
+
+    // Reserved Trusted Firmware region
+    BuildResourceDescriptorHob (
+        EFI_RESOURCE_SYSTEM_MEMORY,
+      ( EFI_RESOURCE_ATTRIBUTE_PRESENT |
+        EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+        EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+        EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+        EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+        EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
+        EFI_RESOURCE_ATTRIBUTE_TESTED ),
+        PcdGet64 (PcdTrustedFWMemoryBase),
+        PcdGet64 (PcdTrustedFWMemorySize)
+      );
+
+      BuildMemoryAllocationHob (
+        PcdGet64 (PcdTrustedFWMemoryBase),
+        PcdGet64 (PcdTrustedFWMemorySize),
+        EfiReservedMemoryType
+      );
+  }
+
   // Declare system memory
   BuildResourceDescriptorHob (
       EFI_RESOURCE_SYSTEM_MEMORY,
@@ -96,26 +132,10 @@  MemoryPeim (
       EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
       EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
       EFI_RESOURCE_ATTRIBUTE_TESTED ),
-      PcdGet64 (PcdSystemMemoryBase),
-      PcdGet64 (PcdSystemMemorySize) 
+      Base,
+      Size
   );
 
-  // Reserve firmware
-  BuildMemoryAllocationHob (
-    PcdGet64 (PcdFdBaseAddress),
-    PcdGet32 (PcdFdSize),
-    EfiRuntimeServicesData
-  );
-
-  // Reserved Trusted Firmware region
-  if (FixedPcdGetBool (PcdTrustedFWSupport)) {
-    BuildMemoryAllocationHob (
-      PcdGet64 (PcdTrustedFWMemoryBase),
-      PcdGet64 (PcdTrustedFWMemorySize),
-      EfiReservedMemoryType
-    );
-  }
-
   // Build Memory Allocation Hob
   InitMmu ();