3 * Copyright (c) 2011-2012, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/ArmGicLib.h>
19 #include <Ppi/ArmMpCoreInfo.h>
29 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
33 ArmPlatformGetPlatformPpiList (&PpiListSize
, &PpiList
);
34 PpiListCount
= PpiListSize
/ sizeof(EFI_PEI_PPI_DESCRIPTOR
);
35 for (Index
= 0; Index
< PpiListCount
; Index
++, PpiList
++) {
36 if (CompareGuid (PpiList
->Guid
, PpiGuid
) == TRUE
) {
47 IN UINTN UefiMemoryBase
,
49 IN UINTN GlobalVariableBase
,
50 IN UINT64 StartTimeStamp
53 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
56 ARM_MP_CORE_INFO_PPI
*ArmMpCoreInfoPpi
;
58 Status
= GetPlatformPpi (&gArmMpCoreInfoPpiGuid
, (VOID
**)&ArmMpCoreInfoPpi
);
59 ASSERT_EFI_ERROR (Status
);
62 // Check PcdGicPrimaryCoreId has been set in case the Primary Core is not the core 0 of Cluster 0
64 if ((PcdGet32(PcdArmPrimaryCore
) != 0) && (PcdGet32 (PcdGicPrimaryCoreId
) == 0)) {
65 DEBUG((EFI_D_WARN
,"Warning: the PCD PcdGicPrimaryCoreId does not seem to be set up for the configuration.\n"));
69 // Enable the GIC Distributor
70 ArmGicEnableDistributor(PcdGet32(PcdGicDistributorBase
));
72 // In some cases, the secondary cores are waiting for an SGI from the next stage boot loader toresume their initialization
73 if (!FixedPcdGet32(PcdSendSgiToBringUpSecondaryCores
)) {
74 // Sending SGI to all the Secondary CPU interfaces
75 ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase
), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE
, 0x0E, PcdGet32 (PcdGicSgiIntId
));
78 PrePiMain (UefiMemoryBase
, StacksBase
, GlobalVariableBase
, StartTimeStamp
);
80 // We must never return
90 ARM_MP_CORE_INFO_PPI
*ArmMpCoreInfoPpi
;
93 ARM_CORE_INFO
*ArmCoreInfoTable
;
96 VOID (*SecondaryStart
)(VOID
);
97 UINTN SecondaryEntryAddr
;
98 UINTN AcknowledgedCoreId
;
100 ClusterId
= GET_CLUSTER_ID(MpId
);
101 CoreId
= GET_CORE_ID(MpId
);
103 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
104 Status
= GetPlatformPpi (&gArmMpCoreInfoPpiGuid
, (VOID
**)&ArmMpCoreInfoPpi
);
105 ASSERT_EFI_ERROR (Status
);
108 Status
= ArmMpCoreInfoPpi
->GetMpCoreInfo (&ArmCoreCount
, &ArmCoreInfoTable
);
109 ASSERT_EFI_ERROR (Status
);
111 // Find the core in the ArmCoreTable
112 for (Index
= 0; Index
< ArmCoreCount
; Index
++) {
113 if ((ArmCoreInfoTable
[Index
].ClusterId
== ClusterId
) && (ArmCoreInfoTable
[Index
].CoreId
== CoreId
)) {
118 // The ARM Core Info Table must define every core
119 ASSERT (Index
!= ArmCoreCount
);
121 // Clear Secondary cores MailBox
122 MmioWrite32 (ArmCoreInfoTable
[Index
].MailboxClearAddress
, ArmCoreInfoTable
[Index
].MailboxClearValue
);
128 SecondaryEntryAddr
= MmioRead32 (ArmCoreInfoTable
[Index
].MailboxGetAddress
);
130 // Acknowledge the interrupt and send End of Interrupt signal.
131 ArmGicAcknowledgeInterrupt (PcdGet32(PcdGicDistributorBase
), PcdGet32(PcdGicInterruptInterfaceBase
), &AcknowledgedCoreId
, NULL
);
132 } while ((SecondaryEntryAddr
== 0) && (AcknowledgedCoreId
!= PcdGet32 (PcdGicPrimaryCoreId
)));
134 // Jump to secondary core entry point.
135 SecondaryStart
= (VOID (*)())SecondaryEntryAddr
;
138 // The secondaries shouldn't reach here