]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/PrePi/PrePi.c
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
index f3cb3a121f90b657ccc452ab96c1a51dd944be5f..9a5e067ef537aeaf8fc26341989427bf431139b2 100755 (executable)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD License\r
@@ -14,7 +14,6 @@
 \r
 #include <PiPei.h>\r
 \r
-#include <Library/ArmCpuLib.h>\r
 #include <Library/DebugAgentLib.h>\r
 #include <Library/PrePiLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/PerformanceLib.h>\r
 \r
 #include <Ppi/GuidedSectionExtraction.h>\r
+#include <Ppi/ArmMpCoreInfo.h>\r
 #include <Guid/LzmaDecompress.h>\r
 #include <Guid/ArmGlobalVariableHob.h>\r
 \r
 #include "PrePi.h"\r
 #include "LzmaDecompress.h"\r
 \r
-#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
-                  ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
+#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
+                  ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))\r
 \r
 // Not used when PrePi in run in XIP mode\r
 UINTN mGlobalVariableBase = 0;\r
 \r
-VOID\r
-PrePiCommonExceptionEntry (\r
-  IN UINT32 Entry,\r
-  IN UINT32 LR\r
-  );\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 ExtractGuidedSectionLibConstructor (\r
@@ -71,6 +65,30 @@ BuildGlobalVariableHob (
   Hob->GlobalVariableSize = GlobalVariableSize;\r
 }\r
 \r
+EFI_STATUS\r
+GetPlatformPpi (\r
+  IN  EFI_GUID  *PpiGuid,\r
+  OUT VOID      **Ppi\r
+  )\r
+{\r
+  UINTN                   PpiListSize;\r
+  UINTN                   PpiListCount;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiList;\r
+  UINTN                   Index;\r
+\r
+  PpiListSize = 0;\r
+  ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
+  PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
+  for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
+    if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r
+      *Ppi = PpiList->Ppi;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
 VOID\r
 PrePiMain (\r
   IN  UINTN                     UefiMemoryBase,\r
@@ -80,22 +98,21 @@ PrePiMain (
   )\r
 {\r
   EFI_HOB_HANDOFF_INFO_TABLE*   HobList;\r
+  ARM_MP_CORE_INFO_PPI*         ArmMpCoreInfoPpi;\r
+  UINTN                         ArmCoreCount;\r
+  ARM_CORE_INFO*                ArmCoreInfoTable;\r
   EFI_STATUS                    Status;\r
   CHAR8                         Buffer[100];\r
   UINTN                         CharCount;\r
   UINTN                         StacksSize;\r
 \r
   // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
-  ASSERT (IS_XIP() || \r
-          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
-           ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
+  ASSERT (IS_XIP() ||\r
+          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&\r
+           ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet64 (PcdSystemMemoryBase) + FixedPcdGet64 (PcdSystemMemorySize)))));\r
 \r
-  // Enable program flow prediction, if supported.\r
-  ArmEnableBranchPrediction ();\r
-\r
-  if (FixedPcdGet32(PcdVFPEnabled)) {\r
-    ArmEnableVFP();\r
-  }\r
+  // Initialize the architecture specific bits\r
+  ArchInitialize ();\r
 \r
   // Initialize the Serial Port\r
   SerialPortInitialize ();\r
@@ -106,7 +123,7 @@ PrePiMain (
   // Initialize the Debug Agent for Source Level Debugging\r
   InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
   SaveAndSetDebugTimerInterrupt (TRUE);\r
-  \r
+\r
   // Declare the PI/UEFI memory region\r
   HobList = HobConstructor (\r
     (VOID*)UefiMemoryBase,\r
@@ -122,7 +139,8 @@ PrePiMain (
 \r
   // Create the Stacks HOB (reserve the memory for all stacks)\r
   if (ArmIsMpCore ()) {\r
-    StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
+    StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +\r
+                 ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));\r
   } else {\r
     StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
   }\r
@@ -134,6 +152,22 @@ PrePiMain (
   //TODO: Call CpuPei as a library\r
   BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
 \r
+  if (ArmIsMpCore ()) {\r
+    // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid\r
+    Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r
+\r
+    // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    // Build the MP Core Info Table\r
+    ArmCoreCount = 0;\r
+    Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r
+    if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) {\r
+      // Build MPCore Info HOB\r
+      BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);\r
+    }\r
+  }\r
+\r
   // Set the Boot Mode\r
   SetBootMode (ArmPlatformGetBootMode ());\r
 \r
@@ -174,11 +208,13 @@ CEntryPoint (
   )\r
 {\r
   UINT64   StartTimeStamp;\r
\r
+\r
+  ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));\r
+\r
   // Initialize the platform specific controllers\r
   ArmPlatformInitialize (MpId);\r
 \r
-  if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
+  if (ArmPlatformIsPrimaryCore (MpId) && 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
@@ -187,37 +223,31 @@ CEntryPoint (
     StartTimeStamp = 0;\r
   }\r
 \r
-  // Clean Data cache\r
-  ArmCleanInvalidateDataCache ();\r
-\r
+  // Data Cache enabled on Primary core when MMU is enabled.\r
+  ArmDisableDataCache ();\r
+  // Invalidate Data cache\r
+  ArmInvalidateDataCache ();\r
   // Invalidate instruction cache\r
   ArmInvalidateInstructionCache ();\r
-\r
-  //TODO:Drain Write Buffer\r
-\r
-  // Enable Instruction & Data caches\r
-  ArmEnableDataCache ();\r
+  // Enable Instruction Caches on all cores.\r
   ArmEnableInstructionCache ();\r
 \r
   // Define the Global Variable region when we are not running in XIP\r
   if (!IS_XIP()) {\r
-    if (IS_PRIMARY_CORE(MpId)) {\r
+    if (ArmPlatformIsPrimaryCore (MpId)) {\r
       mGlobalVariableBase = GlobalVariableBase;\r
       if (ArmIsMpCore()) {\r
-        ArmCpuSynchronizeSignal (ARM_CPU_EVENT_DEFAULT);\r
+        // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r
+        ArmCallSEV ();\r
       }\r
     } else {\r
-      // Wait the Primay core has defined the address of the Global Variable region\r
-      ArmCpuSynchronizeWait (ARM_CPU_EVENT_DEFAULT);\r
+      // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r
+      ArmCallWFE ();\r
     }\r
   }\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
 \r
   // If not primary Jump to Secondary Main\r
-  if (IS_PRIMARY_CORE(MpId)) {\r
+  if (ArmPlatformIsPrimaryCore (MpId)) {\r
     // Goto primary Main.\r
     PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
   } else {\r
@@ -228,44 +258,3 @@ CEntryPoint (
   ASSERT (FALSE);\r
 }\r
 \r
-VOID\r
-PrePiCommonExceptionEntry (\r
-  IN UINT32 Entry,\r
-  IN UINT32 LR\r
-  )\r
-{\r
-  CHAR8           Buffer[100];\r
-  UINTN           CharCount;\r
-\r
-  switch (Entry) {\r
-  case 0:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 1:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 2:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 3:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 4:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 5:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 6:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
-    break;\r
-  case 7:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
-    break;\r
-  default:\r
-    CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
-    break;\r
-  }\r
-  SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
-  while(1);\r
-}\r