Extract reserving memory region in the Hob list
into a separate routine. It is a preparation for adding
multiple of such regions in a following patch.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <m...@semihalf.com>
---
 
Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c
 | 95 +++++++++++++-------
 1 file changed, 61 insertions(+), 34 deletions(-)

diff --git 
a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c
 
b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c
index 53119f4..3e7902f 100644
--- 
a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c
+++ 
b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c
@@ -49,40 +49,31 @@ InitMmu (
 
 Routine Description:
 
-
+  Remove the reserved region from a System Memory Hob that covers it.
 
 Arguments:
 
   FileHandle  - Handle of the file being invoked.
   PeiServices - Describes the list of possible PEI Services.
 
-Returns:
-
-  Status -  EFI_SUCCESS if the boot mode could be set
-
 --*/
-EFI_STATUS
-EFIAPI
-MemoryPeim (
-  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,
-  IN UINT64                             UefiMemorySize
+STATIC
+VOID
+ReserveMemoryRegion (
+  IN EFI_PHYSICAL_ADDRESS      ReservedRegionBase,
+  IN UINT32                    ReservedRegionSize
   )
 {
-  ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
   EFI_RESOURCE_ATTRIBUTE_TYPE  ResourceAttributes;
-  UINT64                       ResourceLength;
-  EFI_PEI_HOB_POINTERS         NextHob;
-  EFI_PHYSICAL_ADDRESS         SecureTop;
+  EFI_PHYSICAL_ADDRESS         ReservedRegionTop;
   EFI_PHYSICAL_ADDRESS         ResourceTop;
+  EFI_PEI_HOB_POINTERS         NextHob;
+  UINT64                       ResourceLength;
 
-  // Get Virtual Memory Map from the Platform Library
-  ArmPlatformGetVirtualMemoryMap (&MemoryTable);
-
-  SecureTop = (EFI_PHYSICAL_ADDRESS)FixedPcdGet64 (PcdSecureRegionBase) +
-              FixedPcdGet32 (PcdSecureRegionSize);
+  ReservedRegionTop = ReservedRegionBase + ReservedRegionSize;
 
   //
-  // Search for System Memory Hob that covers the secure firmware,
+  // Search for System Memory Hob that covers the reserved region,
   // and punch a hole in it
   //
   for (NextHob.Raw = GetHobList ();
@@ -91,31 +82,32 @@ MemoryPeim (
                                  NextHob.Raw)) {
 
     if ((NextHob.ResourceDescriptor->ResourceType == 
EFI_RESOURCE_SYSTEM_MEMORY) &&
-        (FixedPcdGet64 (PcdSecureRegionBase) >= 
NextHob.ResourceDescriptor->PhysicalStart) &&
-        (SecureTop <= NextHob.ResourceDescriptor->PhysicalStart +
+        (ReservedRegionBase >= NextHob.ResourceDescriptor->PhysicalStart) &&
+        (ReservedRegionTop <= NextHob.ResourceDescriptor->PhysicalStart +
                       NextHob.ResourceDescriptor->ResourceLength))
     {
       ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;
       ResourceLength = NextHob.ResourceDescriptor->ResourceLength;
       ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;
 
-      if (FixedPcdGet64 (PcdSecureRegionBase) == 
NextHob.ResourceDescriptor->PhysicalStart) {
+      if (ReservedRegionBase == NextHob.ResourceDescriptor->PhysicalStart) {
         //
         // This region starts right at the start of the reserved region, so we
         // can simply move its start pointer and reduce its length by the same
         // value
         //
-        NextHob.ResourceDescriptor->PhysicalStart += FixedPcdGet32 
(PcdSecureRegionSize);
-        NextHob.ResourceDescriptor->ResourceLength -= FixedPcdGet32 
(PcdSecureRegionSize);
+        NextHob.ResourceDescriptor->PhysicalStart += ReservedRegionSize;
+        NextHob.ResourceDescriptor->ResourceLength -= ReservedRegionSize;
 
       } else if ((NextHob.ResourceDescriptor->PhysicalStart +
-                  NextHob.ResourceDescriptor->ResourceLength) == SecureTop) {
+                  NextHob.ResourceDescriptor->ResourceLength) ==
+                  ReservedRegionTop) {
 
         //
         // This region ends right at the end of the reserved region, so we
         // can simply reduce its length by the size of the region.
         //
-        NextHob.ResourceDescriptor->ResourceLength -= FixedPcdGet32 
(PcdSecureRegionSize);
+        NextHob.ResourceDescriptor->ResourceLength -= ReservedRegionSize;
 
       } else {
         //
@@ -123,28 +115,63 @@ MemoryPeim (
         // each one touching the reserved region at either end, but not 
covering
         // it.
         //
-        NextHob.ResourceDescriptor->ResourceLength = FixedPcdGet64 
(PcdSecureRegionBase) -
-                                                     
NextHob.ResourceDescriptor->PhysicalStart;
+        NextHob.ResourceDescriptor->ResourceLength =
+                 ReservedRegionBase - 
NextHob.ResourceDescriptor->PhysicalStart;
 
         // Create the System Memory HOB for the remaining region (top of the 
FD)
         BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,
                                     ResourceAttributes,
-                                    SecureTop,
-                                    ResourceTop - SecureTop);
+                                    ReservedRegionTop,
+                                    ResourceTop - ReservedRegionTop);
       }
 
       //
-      // Reserve the memory space occupied by the secure firmware
+      // Reserve the memory space.
       //
       BuildResourceDescriptorHob (EFI_RESOURCE_MEMORY_RESERVED,
         0,
-        FixedPcdGet64 (PcdSecureRegionBase),
-        FixedPcdGet32 (PcdSecureRegionSize));
+        ReservedRegionBase,
+        ReservedRegionSize);
 
       break;
     }
     NextHob.Raw = GET_NEXT_HOB (NextHob);
   }
+}
+
+/*++
+
+Routine Description:
+
+
+
+Arguments:
+
+  FileHandle  - Handle of the file being invoked.
+  PeiServices - Describes the list of possible PEI Services.
+
+Returns:
+
+  Status -  EFI_SUCCESS if the boot mode could be set
+
+--*/
+EFI_STATUS
+EFIAPI
+MemoryPeim (
+  IN EFI_PHYSICAL_ADDRESS               UefiMemoryBase,
+  IN UINT64                             UefiMemorySize
+  )
+{
+  ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
+
+  // Get Virtual Memory Map from the Platform Library
+  ArmPlatformGetVirtualMemoryMap (&MemoryTable);
+
+  // Reserve memory region for secure firmware
+  ReserveMemoryRegion (
+    (EFI_PHYSICAL_ADDRESS)FixedPcdGet64 (PcdSecureRegionBase),
+    FixedPcdGet32 (PcdSecureRegionSize)
+    );
 
   // Build Memory Allocation Hob
   InitMmu (MemoryTable);
-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to