#include <Library/BaseMemoryLib.h>
#include <Library/PcdLib.h>
-#define IS_XIP() ((PcdGet32 (PcdFdBaseAddress) > (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
+#define IS_XIP() (((UINT32)PcdGet32 (PcdFdBaseAddress) > (UINT32)(PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize))) || \
((PcdGet32 (PcdFdBaseAddress) + PcdGet32 (PcdFdSize)) < PcdGet32 (PcdSystemMemoryBase)))
// Declared by ArmPlatformPkg/PrePi Module
if (IS_XIP()) {
// In Case of XIP, we expect the Primary Stack at the top of the System Memory
- GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - PcdGet32 (PcdPeiGlobalVariableSize);
+ // The size must be 64bit aligned to allow 64bit variable to be aligned
+ GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
} else {
GlobalVariableBase = mGlobalVariableBase;
}
if (IS_XIP()) {
// In Case of XIP, we expect the Primary Stack at the top of the System Memory
- GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - PcdGet32 (PcdPeiGlobalVariableSize);
+ // The size must be 64bit aligned to allow 64bit variable to be aligned
+ GlobalVariableBase = PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemorySize) - ALIGN_VALUE(PcdGet32 (PcdPeiGlobalVariableSize),0x8);
} else {
GlobalVariableBase = mGlobalVariableBase;
}
\r
#include <Library/ArmGicLib.h>\r
\r
+#include <Ppi/ArmMpCoreInfo.h>\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
PrimaryMain (\r
IN UINTN UefiMemoryBase,\r
IN UINT64 StartTimeStamp\r
)\r
{\r
+ // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r
+ DEBUG_CODE_BEGIN();\r
+ EFI_STATUS Status;\r
+ ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;\r
+\r
+ Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r
+ ASSERT_EFI_ERROR (Status);\r
+ DEBUG_CODE_END();\r
+\r
// Enable the GIC Distributor\r
ArmGicEnableDistributor(PcdGet32(PcdGicDistributorBase));\r
\r
IN UINTN MpId\r
)\r
{\r
- // Function pointer to Secondary Core entry point\r
- VOID (*secondary_start)(VOID);\r
- UINTN secondary_entry_addr=0;\r
+ EFI_STATUS Status;\r
+ ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;\r
+ UINTN Index;\r
+ UINTN ArmCoreCount;\r
+ ARM_CORE_INFO *ArmCoreInfoTable;\r
+ UINT32 ClusterId;\r
+ UINT32 CoreId;\r
+ VOID (*SecondaryStart)(VOID);\r
+ UINTN SecondaryEntryAddr;\r
+\r
+ ClusterId = GET_CLUSTER_ID(MpId);\r
+ CoreId = GET_CORE_ID(MpId);\r
+\r
+ // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r
+ Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ ArmCoreCount = 0;\r
+ Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ // Find the core in the ArmCoreTable\r
+ for (Index = 0; Index < ArmCoreCount; Index++) {\r
+ if ((ArmCoreInfoTable[Index].ClusterId == ClusterId) && (ArmCoreInfoTable[Index].CoreId == CoreId)) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ // The ARM Core Info Table must define every core\r
+ ASSERT (Index != ArmCoreCount);\r
\r
// Clear Secondary cores MailBox\r
- ArmClearMPCoreMailbox();\r
+ MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);\r
\r
- while (secondary_entry_addr = ArmGetMPCoreMailbox(), secondary_entry_addr == 0) {\r
- ArmCallWFI();\r
+ SecondaryEntryAddr = 0;\r
+ while (SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress), SecondaryEntryAddr == 0) {\r
+ ArmCallWFI ();\r
// Acknowledge the interrupt and send End of Interrupt signal.\r
ArmGicAcknowledgeSgiFrom (PcdGet32(PcdGicInterruptInterfaceBase), PRIMARY_CORE_ID);\r
}\r
\r
- secondary_start = (VOID (*)())secondary_entry_addr;\r
-\r
// Jump to secondary core entry point.\r
- secondary_start();\r
+ SecondaryStart = (VOID (*)())SecondaryEntryAddr;\r
+ SecondaryStart();\r
\r
// The secondaries shouldn't reach here\r
ASSERT(FALSE);\r
IN UINT64 StartTimeStamp\r
)\r
{\r
+ DEBUG_CODE_BEGIN();\r
+ // On MPCore system, PeiMpCore.inf should be used instead of PeiUniCore.inf\r
+ ASSERT(ArmIsMpCore() == 0);\r
+ DEBUG_CODE_END();\r
+\r
PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
\r
// We must never return\r
and r5, r0, r1\r
\r
_SetSVCMode:\r
- // Enter SVC mode\r
+ // Enter SVC mode, Disable FIQ and IRQ\r
mov r1, #0x13|0x80|0x40\r
msr CPSR_c, r1\r
\r
\r
// Is it the Primary Core ?\r
LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)\r
- cmp r0, r4\r
+ cmp r5, r4\r
beq _SetupPrimaryCoreStack\r
\r
_SetupSecondaryCoreStack:\r
and r5, r0, r1\r
\r
_SetSVCMode\r
- // Enter SVC mode\r
+ // Enter SVC mode, Disable FIQ and IRQ\r
mov r1, #0x13|0x80|0x40\r
msr CPSR_c, r1\r
\r
\r
// Is it the Primary Core ?\r
LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)\r
- cmp r0, r4\r
+ cmp r5, r4\r
beq _SetupPrimaryCoreStack\r
\r
_SetupSecondaryCoreStack\r
BaseLib\r
DebugLib\r
DebugAgentLib\r
+ ArmCpuLib\r
ArmLib\r
ArmGicLib\r
IoLib\r
PlatformPeiLib\r
MemoryInitPeiLib\r
\r
+[Ppis]\r
+ gArmMpCoreInfoPpiGuid\r
+\r
[Guids]\r
gArmGlobalVariableGuid\r
\r
BaseLib\r
DebugLib\r
DebugAgentLib\r
+ ArmCpuLib\r
ArmLib\r
IoLib\r
TimerLib\r
[Guids]\r
gArmGlobalVariableGuid\r
\r
+[Guids]\r
+ gArmGlobalVariableGuid\r
+\r
[FeaturePcd] \r
gEmbeddedTokenSpaceGuid.PcdCacheEnable\r
gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob\r
\r
#include <PiPei.h>\r
\r
+#include <Library/ArmCpuLib.h>\r
#include <Library/DebugAgentLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
#include <Library/PrePiLib.h>\r
-#include <Library/IoLib.h>\r
#include <Library/PrintLib.h>\r
#include <Library/PeCoffGetEntryPointLib.h>\r
#include <Library/PrePiHobListPointerLib.h>\r
#include "PrePi.h"\r
#include "LzmaDecompress.h"\r
\r
-#define IS_XIP() ((FixedPcdGet32 (PcdFdBaseAddress) > (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
+#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
\r
// Not used when PrePi in run in XIP mode\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
- ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
+ ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
\r
// Enable program flow prediction, if supported.\r
ArmEnableBranchPrediction ();\r
// Initialize the Debug Agent for Source Level Debugging\r
InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
SaveAndSetDebugTimerInterrupt (TRUE);\r
-\r
- if (!IS_XIP()) {\r
- mGlobalVariableBase = GlobalVariableBase;\r
- }\r
\r
// Declare the PI/UEFI memory region\r
HobList = HobConstructor (\r
ASSERT_EFI_ERROR (Status);\r
\r
// Create the Stacks HOB (reserve the memory for all stacks)\r
- StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
+ if (ArmIsMpCore ()) {\r
+ StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
+ } else {\r
+ StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
+ }\r
BuildStackHob (StacksBase, StacksSize);\r
\r
// Declare the Global Variable HOB\r
ArmEnableDataCache ();\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
+ mGlobalVariableBase = GlobalVariableBase;\r
+ ArmCpuSynchronizeSignal (ARM_CPU_EVENT_DEFAULT);\r
+ } else {\r
+ // Wait the Primay core has defined the address of the Global Variable region\r
+ ArmCpuSynchronizeWait (ARM_CPU_EVENT_DEFAULT);\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
#include <Library/PcdLib.h>\r
#include <Library/ArmLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
#include <Library/DebugLib.h>\r
+#include <Library/IoLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/HobLib.h>\r
#include <Library/SerialPortLib.h>\r