2011-02-01 06:41:42 +01:00
|
|
|
/** @file
|
|
|
|
*
|
2014-07-04 16:41:30 +02:00
|
|
|
* Copyright (c) 2011-2014, ARM Limited. All rights reserved.
|
2011-02-01 06:41:42 +01:00
|
|
|
*
|
|
|
|
* This program and the accompanying materials
|
|
|
|
* are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
* which accompanies this distribution. The full text of the license may be found at
|
|
|
|
* http://opensource.org/licenses/bsd-license.php
|
|
|
|
*
|
|
|
|
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2011-09-23 00:59:52 +02:00
|
|
|
#include <Library/ArmGicLib.h>
|
2011-09-23 01:14:01 +02:00
|
|
|
|
|
|
|
#include <Ppi/ArmMpCoreInfo.h>
|
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
#include "PrePeiCore.h"
|
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
/*
|
|
|
|
* This is the main function for secondary cores. They loop around until a non Null value is written to
|
|
|
|
* SYS_FLAGS register.The SYS_FLAGS register is platform specific.
|
|
|
|
* Note:The secondary cores, while executing secondary_main, assumes that:
|
|
|
|
* : SGI 0 is configured as Non-secure interrupt
|
|
|
|
* : Priority Mask is configured to allow SGI 0
|
|
|
|
* : Interrupt Distributor and CPU interfaces are enabled
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
2011-06-11 14:10:19 +02:00
|
|
|
SecondaryMain (
|
2011-09-23 01:01:13 +02:00
|
|
|
IN UINTN MpId
|
2011-06-11 14:10:19 +02:00
|
|
|
)
|
2011-02-01 06:41:42 +01:00
|
|
|
{
|
2011-09-23 01:14:01 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN PpiListSize;
|
|
|
|
UINTN PpiListCount;
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR *PpiList;
|
|
|
|
ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;
|
|
|
|
UINTN Index;
|
|
|
|
UINTN ArmCoreCount;
|
|
|
|
ARM_CORE_INFO *ArmCoreInfoTable;
|
|
|
|
UINT32 ClusterId;
|
|
|
|
UINT32 CoreId;
|
|
|
|
VOID (*SecondaryStart)(VOID);
|
|
|
|
UINTN SecondaryEntryAddr;
|
2014-07-04 16:41:30 +02:00
|
|
|
UINTN AcknowledgeInterrupt;
|
|
|
|
UINTN InterruptId;
|
2011-09-23 01:14:01 +02:00
|
|
|
|
|
|
|
ClusterId = GET_CLUSTER_ID(MpId);
|
|
|
|
CoreId = GET_CORE_ID(MpId);
|
|
|
|
|
|
|
|
// Get the gArmMpCoreInfoPpiGuid
|
|
|
|
PpiListSize = 0;
|
|
|
|
ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
|
|
|
|
PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);
|
|
|
|
for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
|
|
|
|
if (CompareGuid (PpiList->Guid, &gArmMpCoreInfoPpiGuid) == TRUE) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// On MP Core Platform we must implement the ARM MP Core Info PPI
|
|
|
|
ASSERT (Index != PpiListCount);
|
|
|
|
|
|
|
|
ArmMpCoreInfoPpi = PpiList->Ppi;
|
|
|
|
ArmCoreCount = 0;
|
|
|
|
Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
// Find the core in the ArmCoreTable
|
|
|
|
for (Index = 0; Index < ArmCoreCount; Index++) {
|
|
|
|
if ((ArmCoreInfoTable[Index].ClusterId == ClusterId) && (ArmCoreInfoTable[Index].CoreId == CoreId)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The ARM Core Info Table must define every core
|
|
|
|
ASSERT (Index != ArmCoreCount);
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
// Clear Secondary cores MailBox
|
2011-09-23 01:14:01 +02:00
|
|
|
MmioWrite32 (ArmCoreInfoTable[Index].MailboxClearAddress, ArmCoreInfoTable[Index].MailboxClearValue);
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2012-05-02 22:09:16 +02:00
|
|
|
do {
|
2011-09-23 01:14:01 +02:00
|
|
|
ArmCallWFI ();
|
2012-05-02 22:09:16 +02:00
|
|
|
|
|
|
|
// Read the Mailbox
|
|
|
|
SecondaryEntryAddr = MmioRead32 (ArmCoreInfoTable[Index].MailboxGetAddress);
|
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
// Acknowledge the interrupt and send End of Interrupt signal.
|
2016-09-05 13:38:20 +02:00
|
|
|
AcknowledgeInterrupt = ArmGicAcknowledgeInterrupt (PcdGet64 (PcdGicInterruptInterfaceBase), &InterruptId);
|
2014-07-04 13:13:27 +02:00
|
|
|
// Check if it is a valid interrupt ID
|
2016-09-05 13:38:20 +02:00
|
|
|
if (InterruptId < ArmGicGetMaxNumInterrupts (PcdGet64 (PcdGicDistributorBase))) {
|
2014-07-04 13:13:27 +02:00
|
|
|
// Got a valid SGI number hence signal End of Interrupt
|
2016-09-05 13:38:20 +02:00
|
|
|
ArmGicEndOfInterrupt (PcdGet64 (PcdGicInterruptInterfaceBase), AcknowledgeInterrupt);
|
2014-07-04 13:13:27 +02:00
|
|
|
}
|
2013-07-17 08:23:07 +02:00
|
|
|
} while (SecondaryEntryAddr == 0);
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
// Jump to secondary core entry point.
|
2011-09-23 01:14:01 +02:00
|
|
|
SecondaryStart = (VOID (*)())SecondaryEntryAddr;
|
|
|
|
SecondaryStart();
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
// The secondaries shouldn't reach here
|
|
|
|
ASSERT(FALSE);
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
PrimaryMain (
|
2011-02-01 06:41:42 +01:00
|
|
|
IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
|
|
|
|
)
|
|
|
|
{
|
2011-06-11 14:10:19 +02:00
|
|
|
EFI_SEC_PEI_HAND_OFF SecCoreData;
|
2011-09-23 01:12:23 +02:00
|
|
|
UINTN PpiListSize;
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR *PpiList;
|
|
|
|
UINTN TemporaryRamBase;
|
|
|
|
UINTN TemporaryRamSize;
|
|
|
|
|
|
|
|
CreatePpiList (&PpiListSize, &PpiList);
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-09-23 00:59:52 +02:00
|
|
|
// Enable the GIC Distributor
|
2016-09-05 13:38:20 +02:00
|
|
|
ArmGicEnableDistributor (PcdGet64(PcdGicDistributorBase));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
// If ArmVe has not been built as Standalone then we need to wake up the secondary cores
|
2011-09-23 00:59:52 +02:00
|
|
|
if (FeaturePcdGet (PcdSendSgiToBringUpSecondaryCores)) {
|
2011-06-11 14:10:19 +02:00
|
|
|
// Sending SGI to all the Secondary CPU interfaces
|
2016-09-05 13:38:20 +02:00
|
|
|
ArmGicSendSgiTo (PcdGet64(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));
|
2011-06-11 14:10:19 +02:00
|
|
|
}
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-09-23 01:12:23 +02:00
|
|
|
// Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
|
|
|
|
// the base of the primary core stack
|
2015-12-08 08:35:30 +01:00
|
|
|
PpiListSize = ALIGN_VALUE(PpiListSize, CPU_STACK_ALIGNMENT);
|
2014-11-11 01:43:03 +01:00
|
|
|
TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;
|
2011-09-23 01:12:23 +02:00
|
|
|
TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;
|
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
//
|
|
|
|
// Bind this information into the SEC hand-off state
|
|
|
|
// Note: this must be in sync with the stuff in the asm file
|
|
|
|
// Note also: HOBs (pei temp ram) MUST be above stack
|
|
|
|
//
|
|
|
|
SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF);
|
2014-11-11 01:43:03 +01:00
|
|
|
SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);
|
2011-09-23 01:06:31 +02:00
|
|
|
SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);
|
2011-09-23 01:12:23 +02:00
|
|
|
SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)
|
|
|
|
SecCoreData.TemporaryRamSize = TemporaryRamSize;
|
|
|
|
SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
|
2015-12-08 08:35:30 +01:00
|
|
|
SecCoreData.PeiTemporaryRamSize = ALIGN_VALUE (SecCoreData.TemporaryRamSize / 2, CPU_STACK_ALIGNMENT);
|
2015-12-08 15:15:14 +01:00
|
|
|
SecCoreData.StackBase = (VOID *)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);
|
2012-02-27 11:27:10 +01:00
|
|
|
SecCoreData.StackSize = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
// Jump to PEI core entry point
|
2013-03-12 01:45:29 +01:00
|
|
|
PeiCoreEntryPoint (&SecCoreData, PpiList);
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|