public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Marcin Wojtas <mw@semihalf.com>
To: edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org,
	nadavh@marvell.com, mw@semihalf.com, jsd@semihalf.com,
	jaz@semihalf.com, kostap@marvell.com
Subject: [platforms: PATCH v3 1/5] Marvell/Armada7k8k: Refactor reserving memory regions
Date: Mon, 28 Jan 2019 10:45:11 +0100	[thread overview]
Message-ID: <1548668715-15042-2-git-send-email-mw@semihalf.com> (raw)
In-Reply-To: <1548668715-15042-1-git-send-email-mw@semihalf.com>

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 <mw@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



  reply	other threads:[~2019-01-28  9:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28  9:45 [platforms: PATCH v3 0/5] Armada7k8k memory handling update Marcin Wojtas
2019-01-28  9:45 ` Marcin Wojtas [this message]
2019-01-28  9:45 ` [platforms: PATCH v3 2/5] Marvell/Armada7k8k: Shift PEI stack base and extend memory reservation Marcin Wojtas
2019-01-28  9:45 ` [platforms: PATCH v3 3/5] Marvell/Library: Introduce common header for the SMC ID's Marcin Wojtas
2019-01-28  9:45 ` [platforms: PATCH v3 4/5] Marvell/Library: ArmadaSoCDescLib: Add North Bridge description Marcin Wojtas
2019-01-28  9:45 ` [platforms: PATCH v3 5/5] Marvell/Armada7k8k: Read DRAM settings from ARM-TF Marcin Wojtas
2019-01-30 16:47 ` [platforms: PATCH v3 0/5] Armada7k8k memory handling update Leif Lindholm
2019-01-31  7:01   ` Marcin Wojtas
2019-01-31 10:27     ` Leif Lindholm
2019-01-31 12:06       ` Marcin Wojtas
2019-01-31 12:12         ` Leif Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1548668715-15042-2-git-send-email-mw@semihalf.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox