diff mbox

[edk2,v1,07/21] ArmPlatformPkg/PrePi: factor out FixedPcdGetXX() and ArmIsMpCore()

Message ID 1422025390-8036-8-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel Jan. 23, 2015, 3:02 p.m. UTC
As a prepatory step towards introduction of a relocatable PrePi
instance, this patch makes some code changes that should not
affect operation, but will allow the relocable PrePi to work
correctly.

First of all, instances of FixedPcdGetXX() are replaced by their
PcdGetXX() counterparts. This will ensure all code uses the variables
and not the immediate constants, which allows us to poke alternate
values when running from RAM.

Also, the result of ArmIsMpCore() is passed into PrePiMain() as an
argument, so that the new PrePi can pass FALSE explicitly, allowing
the same build to run on both unicore and multicore platforms.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S | 24 ++++++++++++------------
 ArmPlatformPkg/PrePi/MainMPCore.c               |  5 +++--
 ArmPlatformPkg/PrePi/MainUniCore.c              |  2 +-
 ArmPlatformPkg/PrePi/PrePi.c                    | 25 ++++++++++++-------------
 ArmPlatformPkg/PrePi/PrePi.h                    |  3 ++-
 5 files changed, 30 insertions(+), 29 deletions(-)
diff mbox

Patch

diff --git a/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S b/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
index fcea9496cbd5..45983b8d51cc 100644
--- a/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
+++ b/ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
@@ -42,19 +42,19 @@  _SetSVCMode:
 // at the top of the DRAM)
 _SetupStackPosition:
   // Compute Top of System Memory
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemoryBase), x1)
-  LoadConstantToReg (FixedPcdGet64 (PcdSystemMemorySize), x2)
+  ldr   x1, PcdGet64 (PcdSystemMemoryBase)
+  ldr   x2, PcdGet64 (PcdSystemMemorySize)
   sub   x2, x2, #1
   add   x1, x1, x2      // x1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
 
   // Calculate Top of the Firmware Device
-  LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), x2)
-  LoadConstantToReg (FixedPcdGet32(PcdFdSize), x3)
+  ldr   x2, PcdGet64 (PcdFdBaseAddress)
+  ldr   w3, PcdGet32 (PcdFdSize)
   sub   x3, x3, #1
   add   x3, x3, x2      // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
 
   // UEFI Memory Size (stacks are allocated in this region)
-  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), x4)
+  ldr   w4, PcdGet32 (PcdSystemMemoryUefiRegionSize)
 
   //
   // Reserve the memory for the UEFI region (contain stacks on its top)
@@ -85,7 +85,7 @@  _SetupAlignedStack:
 _SetupOverflowStack:
   // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
   // aligned (4KB)
-  LoadConstantToReg (EFI_PAGE_MASK, x11)
+  mov   x11, #EFI_PAGE_MASK
   and   x11, x11, x1
   sub   x1, x1, x11
 
@@ -96,13 +96,13 @@  _GetBaseUefiMemory:
 _GetStackBase:
   // r1 = The top of the Mpcore Stacks
   // Stack for the primary core = PrimaryCoreStack
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
+  ldr   w2, PcdGet32 (PcdCPUCorePrimaryStackSize)
   sub   x12, x1, x2
 
   // Stack for the secondary core = Number of Cores - 1
-  LoadConstantToReg (FixedPcdGet32(PcdCoreCount), x0)
+  ldr   w0, PcdGet32 (PcdCoreCount)
   sub   x0, x0, #1
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x1)
+  ldr   w1, PcdGet32 (PcdCPUCoreSecondaryStackSize)
   mul   x1, x1, x0
   sub   x12, x12, x1
 
@@ -110,8 +110,8 @@  _GetStackBase:
   mov   x0, x12
   mov   x1, x10
   //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), x2)
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoreSecondaryStackSize), x3)
+  ldr   w2, PcdGet32 (PcdCPUCorePrimaryStackSize)
+  ldr   w3, PcdGet32 (PcdCPUCoreSecondaryStackSize)
   bl    ASM_PFX(ArmPlatformStackSet)
 
   // Is it the Primary Core ?
@@ -121,7 +121,7 @@  _GetStackBase:
   bne   _PrepareArguments
 
 _ReserveGlobalVariable:
-  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), x0)
+  ldr   w0, PcdGet32(PcdPeiGlobalVariableSize)
   // InitializePrimaryStack($GlobalVariableSize, $Tmp1, $Tmp2)
   InitializePrimaryStack(x0, x1, x2)
 
diff --git a/ArmPlatformPkg/PrePi/MainMPCore.c b/ArmPlatformPkg/PrePi/MainMPCore.c
index bf813730d341..673d6adc8269 100644
--- a/ArmPlatformPkg/PrePi/MainMPCore.c
+++ b/ArmPlatformPkg/PrePi/MainMPCore.c
@@ -15,6 +15,7 @@ 
 #include "PrePi.h"
 
 #include <Library/ArmGicLib.h>
+#include <Library/PcdLib.h>
 
 #include <Ppi/ArmMpCoreInfo.h>
 
@@ -30,12 +31,12 @@  PrimaryMain (
   ArmGicEnableDistributor(PcdGet32(PcdGicDistributorBase));
 
   // In some cases, the secondary cores are waiting for an SGI from the next stage boot loader to resume their initialization
-  if (!FixedPcdGet32(PcdSendSgiToBringUpSecondaryCores)) {
+  if (!PcdGetBool (PcdSendSgiToBringUpSecondaryCores)) {
     // Sending SGI to all the Secondary CPU interfaces
     ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));
   }
 
-  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp, ArmIsMpCore());
 
   // We must never return
   ASSERT(FALSE);
diff --git a/ArmPlatformPkg/PrePi/MainUniCore.c b/ArmPlatformPkg/PrePi/MainUniCore.c
index 43588a50ddb5..918ea4dcdf7b 100644
--- a/ArmPlatformPkg/PrePi/MainUniCore.c
+++ b/ArmPlatformPkg/PrePi/MainUniCore.c
@@ -27,7 +27,7 @@  PrimaryMain (
     ASSERT(ArmIsMpCore() == 0);
   DEBUG_CODE_END();
 
-  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);
+  PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp, ArmIsMpCore());
 
   // We must never return
   ASSERT(FALSE);
diff --git a/ArmPlatformPkg/PrePi/PrePi.c b/ArmPlatformPkg/PrePi/PrePi.c
index 9a5e067ef537..9c669280be01 100755
--- a/ArmPlatformPkg/PrePi/PrePi.c
+++ b/ArmPlatformPkg/PrePi/PrePi.c
@@ -30,8 +30,8 @@ 
 #include "PrePi.h"
 #include "LzmaDecompress.h"
 
-#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \
-                  ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))
+#define IS_XIP() (((UINT32)PcdGet64 (PcdFdBaseAddress) > (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize))) || \
+                  ((PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet64 (PcdSystemMemoryBase)))
 
 // Not used when PrePi in run in XIP mode
 UINTN mGlobalVariableBase = 0;
@@ -94,7 +94,8 @@  PrePiMain (
   IN  UINTN                     UefiMemoryBase,
   IN  UINTN                     StacksBase,
   IN  UINTN                     GlobalVariableBase,
-  IN  UINT64                    StartTimeStamp
+  IN  UINT64                    StartTimeStamp,
+  IN  BOOLEAN                   IsMpCore
   )
 {
   EFI_HOB_HANDOFF_INFO_TABLE*   HobList;
@@ -108,8 +109,8 @@  PrePiMain (
 
   // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
   ASSERT (IS_XIP() ||
-          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&
-           ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize)))));
+          ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) &&
+           ((UINT32)(PcdGet64 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) <= (UINT32)(PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))));
 
   // Initialize the architecture specific bits
   ArchInitialize ();
@@ -127,32 +128,32 @@  PrePiMain (
   // Declare the PI/UEFI memory region
   HobList = HobConstructor (
     (VOID*)UefiMemoryBase,
-    FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
+    PcdGet32 (PcdSystemMemoryUefiRegionSize),
     (VOID*)UefiMemoryBase,
     (VOID*)StacksBase  // The top of the UEFI Memory is reserved for the stacks
     );
   PrePeiSetHobList (HobList);
 
   // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
-  Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
+  Status = MemoryPeim (UefiMemoryBase, PcdGet32 (PcdSystemMemoryUefiRegionSize));
   ASSERT_EFI_ERROR (Status);
 
   // Create the Stacks HOB (reserve the memory for all stacks)
-  if (ArmIsMpCore ()) {
+  if (IsMpCore) {
     StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +
-                 ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));
+                 ((PcdGet32 (PcdCoreCount) - 1) * PcdGet32 (PcdCPUCoreSecondaryStackSize));
   } else {
     StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
   }
   BuildStackHob (StacksBase, StacksSize);
 
   // Declare the Global Variable HOB
-  BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));
+  BuildGlobalVariableHob (GlobalVariableBase, PcdGet32 (PcdPeiGlobalVariableSize));
 
   //TODO: Call CpuPei as a library
   BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
 
-  if (ArmIsMpCore ()) {
+  if (IsMpCore) {
     // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
     Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);
 
@@ -209,8 +210,6 @@  CEntryPoint (
 {
   UINT64   StartTimeStamp;
 
-  ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));
-
   // Initialize the platform specific controllers
   ArmPlatformInitialize (MpId);
 
diff --git a/ArmPlatformPkg/PrePi/PrePi.h b/ArmPlatformPkg/PrePi/PrePi.h
index e67795f4490a..468569b3a28b 100644
--- a/ArmPlatformPkg/PrePi/PrePi.h
+++ b/ArmPlatformPkg/PrePi/PrePi.h
@@ -40,7 +40,8 @@  PrePiMain (
   IN  UINTN                     UefiMemoryBase,
   IN  UINTN                     StacksBase,
   IN  UINTN                     GlobalVariableBase,
-  IN  UINT64                    StartTimeStamp
+  IN  UINT64                    StartTimeStamp,
+  IN  BOOLEAN                   IsMpCore
   );
 
 EFI_STATUS