2011-07-06 18:07:54 +02:00
|
|
|
/** @file
|
|
|
|
*
|
2012-05-02 22:08:03 +02:00
|
|
|
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
|
2011-07-06 18:07:54 +02: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.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
2011-09-23 01:01:13 +02:00
|
|
|
#include <Library/ArmLib.h>
|
2011-09-23 00:59:52 +02:00
|
|
|
#include <Library/ArmGicLib.h>
|
2013-05-10 14:41:27 +02:00
|
|
|
#include <Library/ArmPlatformLib.h>
|
2012-07-04 22:06:23 +02:00
|
|
|
#include <Library/ArmPlatformSecLib.h>
|
2011-07-06 18:07:54 +02:00
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <Library/PrintLib.h>
|
|
|
|
#include <Library/SerialPortLib.h>
|
|
|
|
|
|
|
|
// When the firmware is built as not Standalone, the secondary cores need to wait the firmware
|
|
|
|
// entirely written into DRAM. It is the firmware from DRAM which will wake up the secondary cores.
|
|
|
|
VOID
|
|
|
|
NonSecureWaitForFirmware (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VOID (*secondary_start)(VOID);
|
|
|
|
|
|
|
|
// The secondary cores will execute the firmware once wake from WFI.
|
2011-09-23 01:06:31 +02:00
|
|
|
secondary_start = (VOID (*)())PcdGet32(PcdFvBaseAddress);
|
2011-07-06 18:07:54 +02:00
|
|
|
|
|
|
|
ArmCallWFI();
|
|
|
|
|
|
|
|
// Acknowledge the interrupt and send End of Interrupt signal.
|
2012-05-02 22:09:16 +02:00
|
|
|
ArmGicAcknowledgeInterrupt (PcdGet32(PcdGicDistributorBase), PcdGet32(PcdGicInterruptInterfaceBase), NULL, NULL);
|
2011-07-06 18:07:54 +02:00
|
|
|
|
|
|
|
// Jump to secondary core entry point.
|
|
|
|
secondary_start ();
|
|
|
|
|
|
|
|
// PEI Core should always load and never return
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Call before jumping to Normal World
|
|
|
|
|
|
|
|
This function allows the firmware platform to do extra actions before
|
|
|
|
jumping to the Normal World
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
ArmPlatformSecExtraAction (
|
2011-09-23 01:01:13 +02:00
|
|
|
IN UINTN MpId,
|
2011-07-06 18:07:54 +02:00
|
|
|
OUT UINTN* JumpAddress
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR8 Buffer[100];
|
|
|
|
UINTN CharCount;
|
|
|
|
|
|
|
|
if (FeaturePcdGet (PcdStandalone) == FALSE) {
|
2012-05-02 22:15:49 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Warning: This code assumes the DRAM has already been initialized by ArmPlatformSecLib
|
|
|
|
//
|
|
|
|
|
2013-05-10 14:41:27 +02:00
|
|
|
if (ArmPlatformIsPrimaryCore (MpId)) {
|
2011-09-23 01:06:31 +02:00
|
|
|
UINTN* StartAddress = (UINTN*)PcdGet32(PcdFvBaseAddress);
|
2011-07-06 18:07:54 +02:00
|
|
|
|
|
|
|
// Patch the DRAM to make an infinite loop at the start address
|
|
|
|
*StartAddress = 0xEAFFFFFE; // opcode for while(1)
|
|
|
|
|
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Waiting for firmware at 0x%08X ...\n\r",StartAddress);
|
|
|
|
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
|
|
|
|
2011-09-23 01:06:31 +02:00
|
|
|
*JumpAddress = PcdGet32(PcdFvBaseAddress);
|
2011-07-06 18:07:54 +02:00
|
|
|
} else {
|
|
|
|
// When the primary core is stopped by the hardware debugger to copy the firmware
|
|
|
|
// into DRAM. The secondary cores are still running. As soon as the first bytes of
|
|
|
|
// the firmware are written into DRAM, the secondary cores will start to execute the
|
|
|
|
// code even if the firmware is not entirely written into the memory.
|
|
|
|
// That's why the secondary cores need to be parked in WFI and wake up once the
|
|
|
|
// firmware is ready.
|
|
|
|
|
|
|
|
*JumpAddress = (UINTN)NonSecureWaitForFirmware;
|
|
|
|
}
|
|
|
|
} else if (FeaturePcdGet (PcdSystemMemoryInitializeInSec)) {
|
2012-05-02 22:15:49 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Warning: This code assumes the DRAM has already been initialized by ArmPlatformSecLib
|
|
|
|
//
|
|
|
|
|
2013-05-10 14:41:27 +02:00
|
|
|
if (ArmPlatformIsPrimaryCore (MpId)) {
|
2011-07-06 18:07:54 +02:00
|
|
|
// Signal the secondary cores they can jump to PEI phase
|
2012-05-02 22:08:03 +02:00
|
|
|
ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));
|
2011-07-06 18:07:54 +02:00
|
|
|
|
|
|
|
// To enter into Non Secure state, we need to make a return from exception
|
2011-09-23 01:06:31 +02:00
|
|
|
*JumpAddress = PcdGet32(PcdFvBaseAddress);
|
2011-07-06 18:07:54 +02:00
|
|
|
} else {
|
|
|
|
// We wait for the primary core to finish to initialize the System Memory. Otherwise the secondary
|
|
|
|
// cores would make crash the system by setting their stacks in DRAM before the primary core has not
|
|
|
|
// finished to initialize the system memory.
|
|
|
|
*JumpAddress = (UINTN)NonSecureWaitForFirmware;
|
|
|
|
}
|
|
|
|
} else {
|
2011-09-23 01:06:31 +02:00
|
|
|
*JumpAddress = PcdGet32(PcdFvBaseAddress);
|
2011-07-06 18:07:54 +02:00
|
|
|
}
|
|
|
|
}
|