]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg: Change the memory model for the ARM Platform components
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
index 98831ed1841b7a16d084720634a3708326e66559..5a88b47fe92d0d52c24a25a03a7e2f768a2ce20a 100755 (executable)
@@ -49,14 +49,16 @@ LzmaDecompressLibConstructor (
 VOID\r
 PrePiMain (\r
   IN  UINTN                     UefiMemoryBase,\r
-  IN  UINTN                     StackBase,\r
   IN  UINT64                    StartTimeStamp\r
   )\r
 {\r
-  EFI_HOB_HANDOFF_INFO_TABLE**   PrePiHobBase;\r
+  EFI_HOB_HANDOFF_INFO_TABLE**  PrePiHobBase;\r
   EFI_STATUS                    Status;\r
   CHAR8                         Buffer[100];\r
   UINTN                         CharCount;\r
+  UINTN                         UefiMemoryTop;\r
+  UINTN                         StacksSize;\r
+  UINTN                         StacksBase;\r
 \r
   // Enable program flow prediction, if supported.\r
   ArmEnableBranchPrediction ();\r
@@ -76,19 +78,24 @@ PrePiMain (
 \r
   PrePiHobBase = (EFI_HOB_HANDOFF_INFO_TABLE**)(PcdGet32 (PcdCPUCoresNonSecStackBase) + (PcdGet32 (PcdCPUCoresNonSecStackSize) / 2) - PcdGet32 (PcdHobListPtrGlobalOffset));\r
 \r
-  // We leave UINT32 at the top of UEFI memory for PcdPrePiHobBase\r
+  UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
+  StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores);\r
+  StacksBase = UefiMemoryTop - StacksSize;\r
+\r
+  // Declare the PI/UEFI memory region\r
   *PrePiHobBase = HobConstructor (\r
     (VOID*)UefiMemoryBase,\r
     FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
     (VOID*)UefiMemoryBase,\r
-    (VOID*)(UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) - sizeof(UINT32)));\r
+    (VOID*)StacksBase  // The top of the UEFI Memory is reserved for the stacks\r
+    );\r
 \r
   // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
   Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  // Create the Stack HOB\r
-  BuildStackHob (StackBase, FixedPcdGet32(PcdCPUCoresNonSecStackSize));\r
+  // Create the Stacks HOB (reserve the memory for all stacks)\r
+  BuildStackHob (StacksBase, StacksSize);\r
 \r
   // Set the Boot Mode\r
   SetBootMode (ArmPlatformGetBootMode ());\r
@@ -99,8 +106,8 @@ PrePiMain (
 \r
   BuildMemoryTypeInformationHob ();\r
 \r
-  //InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);\r
-  //SaveAndSetDebugTimerInterrupt (TRUE);\r
+  InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);\r
+  SaveAndSetDebugTimerInterrupt (TRUE);\r
 \r
   // Now, the HOB List has been initialized, we can register performance information\r
   PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
@@ -129,41 +136,38 @@ PrePiMain (
 VOID\r
 CEntryPoint (\r
   IN  UINTN                     CoreId,\r
-  IN  UINTN                     UefiMemoryBase,\r
-  IN  UINTN                     StackBase\r
+  IN  UINTN                     UefiMemoryBase\r
   )\r
 {\r
   UINT64   StartTimeStamp;\r
 \r
-  StartTimeStamp = 0;\r
-\r
-  if ((CoreId == 0) && PerformanceMeasurementEnabled ()) {\r
+  if ((CoreId == ARM_PRIMARY_CORE) && PerformanceMeasurementEnabled ()) {\r
     // Initialize the Timer Library to setup the Timer HW controller\r
     TimerConstructor ();\r
     // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
     StartTimeStamp = GetPerformanceCounter ();\r
   }\r
 \r
-  //Clean Data cache\r
-  ArmCleanInvalidateDataCache();\r
+  // Clean Data cache\r
+  ArmCleanInvalidateDataCache ();\r
 \r
-  //Invalidate instruction cache\r
-  ArmInvalidateInstructionCache();\r
+  // Invalidate instruction cache\r
+  ArmInvalidateInstructionCache ();\r
 \r
   //TODO:Drain Write Buffer\r
 \r
   // Enable Instruction & Data caches\r
-  ArmEnableDataCache();\r
-  ArmEnableInstructionCache();\r
+  ArmEnableDataCache ();\r
+  ArmEnableInstructionCache ();\r
 \r
   // Write VBAR - The Vector table must be 32-byte aligned\r
-  ASSERT(((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
-  ArmWriteVBar((UINT32)PrePiVectorTable);\r
+  ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
+  ArmWriteVBar ((UINT32)PrePiVectorTable);\r
 \r
-  //If not primary Jump to Secondary Main\r
-  if(0 == CoreId) {\r
+  // If not primary Jump to Secondary Main\r
+  if (CoreId == ARM_PRIMARY_CORE) {\r
     // Goto primary Main.\r
-    PrimaryMain (UefiMemoryBase, StackBase, StartTimeStamp);\r
+    PrimaryMain (UefiMemoryBase, StartTimeStamp);\r
   } else {\r
     SecondaryMain (CoreId);\r
   }\r