]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/MainMPCore.c
ArmPlatformPkg/ArmPlatformLib: Added support for ArmPlatformIsPrimaryCore()
[mirror_edk2.git] / ArmPlatformPkg / PrePi / MainMPCore.c
CommitLineData
cd872e40 1/** @file\r
2*\r
4c19ece3 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
cd872e40 4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include "PrePi.h"\r
16\r
55a0d64b 17#include <Library/ArmGicLib.h>\r
cd872e40 18\r
99565b88 19#include <Ppi/ArmMpCoreInfo.h>\r
20\r
cd872e40 21VOID\r
22PrimaryMain (\r
23 IN UINTN UefiMemoryBase,\r
c524ffbb 24 IN UINTN StacksBase,\r
25 IN UINTN GlobalVariableBase,\r
cd872e40 26 IN UINT64 StartTimeStamp\r
27 )\r
28{\r
315649cd 29 // Check PcdGicPrimaryCoreId has been set in case the Primary Core is not the core 0 of Cluster 0\r
30 DEBUG_CODE_BEGIN();\r
31 if ((PcdGet32(PcdArmPrimaryCore) != 0) && (PcdGet32 (PcdGicPrimaryCoreId) == 0)) {\r
32 DEBUG((EFI_D_WARN,"Warning: the PCD PcdGicPrimaryCoreId does not seem to be set up for the configuration.\n"));\r
33 }\r
34 DEBUG_CODE_END();\r
35\r
55a0d64b 36 // Enable the GIC Distributor\r
37 ArmGicEnableDistributor(PcdGet32(PcdGicDistributorBase));\r
cd872e40 38\r
0dbbacdf 39 // In some cases, the secondary cores are waiting for an SGI from the next stage boot loader to resume their initialization\r
d269095b 40 if (!FixedPcdGet32(PcdSendSgiToBringUpSecondaryCores)) {\r
cd872e40 41 // Sending SGI to all the Secondary CPU interfaces\r
4c19ece3 42 ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));\r
cd872e40 43 }\r
44\r
c524ffbb 45 PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
cd872e40 46\r
47 // We must never return\r
48 ASSERT(FALSE);\r
49}\r
50\r
51VOID\r
52SecondaryMain (\r
0787bc61 53 IN UINTN MpId\r
cd872e40 54 )\r
55{\r
99565b88 56 EFI_STATUS Status;\r
57 ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;\r
58 UINTN Index;\r
59 UINTN ArmCoreCount;\r
60 ARM_CORE_INFO *ArmCoreInfoTable;\r
61 UINT32 ClusterId;\r
62 UINT32 CoreId;\r
63 VOID (*SecondaryStart)(VOID);\r
64 UINTN SecondaryEntryAddr;\r
315649cd 65 UINTN AcknowledgedCoreId;\r
99565b88 66\r
67 ClusterId = GET_CLUSTER_ID(MpId);\r
68 CoreId = GET_CORE_ID(MpId);\r
69\r
70 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r
71 Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r
72 ASSERT_EFI_ERROR (Status);\r
73\r
74 ArmCoreCount = 0;\r
75 Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r
76 ASSERT_EFI_ERROR (Status);\r
77\r
78 // Find the core in the ArmCoreTable\r
79 for (Index = 0; Index < ArmCoreCount; Index++) {\r
80 if ((ArmCoreInfoTable[Index].ClusterId == ClusterId) && (ArmCoreInfoTable[Index].CoreId == CoreId)) {\r
81 break;\r
82 }\r
83 }\r
84\r
85 // The ARM Core Info Table must define every core\r
86 ASSERT (Index != ArmCoreCount);\r
cd872e40 87\r
88 // Clear Secondary cores MailBox\r
99565b88 89 MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);\r
cd872e40 90\r
315649cd 91 do {\r
99565b88 92 ArmCallWFI ();\r
315649cd 93\r
94 // Read the Mailbox\r
95 SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress);\r
96\r
cd872e40 97 // Acknowledge the interrupt and send End of Interrupt signal.\r
315649cd 98 ArmGicAcknowledgeInterrupt (PcdGet32(PcdGicDistributorBase), PcdGet32(PcdGicInterruptInterfaceBase), &AcknowledgedCoreId, NULL);\r
99 } while ((SecondaryEntryAddr == 0) && (AcknowledgedCoreId != PcdGet32 (PcdGicPrimaryCoreId)));\r
cd872e40 100\r
cd872e40 101 // Jump to secondary core entry point.\r
99565b88 102 SecondaryStart = (VOID (*)())SecondaryEntryAddr;\r
103 SecondaryStart();\r
cd872e40 104\r
105 // The secondaries shouldn't reach here\r
106 ASSERT(FALSE);\r
107}\r