3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/ArmGicLib.h>
13 #include <Ppi/ArmMpCoreInfo.h>
17 IN UINTN UefiMemoryBase
,
19 IN UINT64 StartTimeStamp
22 // Enable the GIC Distributor
23 ArmGicEnableDistributor(PcdGet64(PcdGicDistributorBase
));
25 // In some cases, the secondary cores are waiting for an SGI from the next stage boot loader to resume their initialization
26 if (!FixedPcdGet32(PcdSendSgiToBringUpSecondaryCores
)) {
27 // Sending SGI to all the Secondary CPU interfaces
28 ArmGicSendSgiTo (PcdGet64(PcdGicDistributorBase
), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE
, 0x0E, PcdGet32 (PcdGicSgiIntId
));
31 PrePiMain (UefiMemoryBase
, StacksBase
, StartTimeStamp
);
33 // We must never return
43 ARM_MP_CORE_INFO_PPI
*ArmMpCoreInfoPpi
;
46 ARM_CORE_INFO
*ArmCoreInfoTable
;
49 VOID (*SecondaryStart
)(VOID
);
50 UINTN SecondaryEntryAddr
;
51 UINTN AcknowledgeInterrupt
;
54 ClusterId
= GET_CLUSTER_ID(MpId
);
55 CoreId
= GET_CORE_ID(MpId
);
57 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
58 Status
= GetPlatformPpi (&gArmMpCoreInfoPpiGuid
, (VOID
**)&ArmMpCoreInfoPpi
);
59 ASSERT_EFI_ERROR (Status
);
62 Status
= ArmMpCoreInfoPpi
->GetMpCoreInfo (&ArmCoreCount
, &ArmCoreInfoTable
);
63 ASSERT_EFI_ERROR (Status
);
65 // Find the core in the ArmCoreTable
66 for (Index
= 0; Index
< ArmCoreCount
; Index
++) {
67 if ((ArmCoreInfoTable
[Index
].ClusterId
== ClusterId
) && (ArmCoreInfoTable
[Index
].CoreId
== CoreId
)) {
72 // The ARM Core Info Table must define every core
73 ASSERT (Index
!= ArmCoreCount
);
75 // Clear Secondary cores MailBox
76 MmioWrite32 (ArmCoreInfoTable
[Index
].MailboxClearAddress
, ArmCoreInfoTable
[Index
].MailboxClearValue
);
82 SecondaryEntryAddr
= MmioRead32 (ArmCoreInfoTable
[Index
].MailboxGetAddress
);
84 // Acknowledge the interrupt and send End of Interrupt signal.
85 AcknowledgeInterrupt
= ArmGicAcknowledgeInterrupt (PcdGet64 (PcdGicInterruptInterfaceBase
), &InterruptId
);
86 // Check if it is a valid interrupt ID
87 if (InterruptId
< ArmGicGetMaxNumInterrupts (PcdGet64 (PcdGicDistributorBase
))) {
88 // Got a valid SGI number hence signal End of Interrupt
89 ArmGicEndOfInterrupt (PcdGet64 (PcdGicInterruptInterfaceBase
), AcknowledgeInterrupt
);
91 } while (SecondaryEntryAddr
== 0);
93 // Jump to secondary core entry point.
94 SecondaryStart
= (VOID (*)())SecondaryEntryAddr
;
97 // The secondaries shouldn't reach here