2011-02-01 06:41:42 +01:00
|
|
|
/** @file
|
2011-09-23 01:07:06 +02:00
|
|
|
* Main file supporting the SEC Phase on ARM Platforms
|
2011-02-01 06:41:42 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2011, ARM Limited. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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-07-06 18:07:54 +02:00
|
|
|
#include <Library/DebugAgentLib.h>
|
2011-02-01 06:41:42 +01:00
|
|
|
#include <Library/PcdLib.h>
|
2011-03-31 14:09:31 +02:00
|
|
|
#include <Library/PrintLib.h>
|
2011-02-01 06:41:42 +01:00
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/ArmLib.h>
|
|
|
|
#include <Library/SerialPortLib.h>
|
|
|
|
#include <Library/ArmPlatformLib.h>
|
2011-09-23 00:59:52 +02:00
|
|
|
#include <Library/ArmGicLib.h>
|
2011-04-26 19:05:05 +02:00
|
|
|
|
2011-09-23 01:07:06 +02:00
|
|
|
#include "SecInternal.h"
|
|
|
|
|
2011-06-15 21:53:15 +02:00
|
|
|
#define SerialPrint(txt) SerialPortWrite ((UINT8*)txt, AsciiStrLen(txt)+1);
|
2011-03-31 14:09:31 +02:00
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
extern VOID *monitor_vector_table;
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CEntryPoint (
|
2011-09-23 01:01:13 +02:00
|
|
|
IN UINTN MpId
|
2011-02-01 06:41:42 +01:00
|
|
|
)
|
|
|
|
{
|
2011-03-31 14:09:31 +02:00
|
|
|
CHAR8 Buffer[100];
|
|
|
|
UINTN CharCount;
|
2011-07-06 18:07:54 +02:00
|
|
|
UINTN JumpAddress;
|
2011-03-31 14:09:31 +02:00
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
// Primary CPU clears out the SCU tag RAMs, secondaries wait
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-02-01 06:41:42 +01:00
|
|
|
if (FixedPcdGet32(PcdMPCoreSupport)) {
|
2011-09-23 01:07:06 +02:00
|
|
|
ArmInvalidScu ();
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SEC phase needs to run library constructors by hand. This assumes we are linked against the SerialLib
|
|
|
|
// In non SEC modules the init call is in autogenerated code.
|
|
|
|
SerialPortInitialize ();
|
2011-03-31 14:09:31 +02:00
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
// Start talking
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);
|
|
|
|
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-07-06 18:07:54 +02:00
|
|
|
// Initialize the Debug Agent for Source Level Debugging
|
|
|
|
InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);
|
|
|
|
SaveAndSetDebugTimerInterrupt (TRUE);
|
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
// Now we've got UART, make the check:
|
|
|
|
// - The Vector table must be 32-byte aligned
|
|
|
|
ASSERT(((UINT32)SecVectorTable & ((1 << 5)-1)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalidate the data cache. Doesn't have to do the Data cache clean.
|
|
|
|
ArmInvalidateDataCache();
|
|
|
|
|
2011-09-23 01:07:06 +02:00
|
|
|
// Invalidate Instruction Cache
|
2011-02-01 06:41:42 +01:00
|
|
|
ArmInvalidateInstructionCache();
|
|
|
|
|
2011-09-23 01:07:06 +02:00
|
|
|
// Invalidate I & D TLBs
|
2011-02-01 06:41:42 +01:00
|
|
|
ArmInvalidateInstructionAndDataTlb();
|
|
|
|
|
|
|
|
// Enable Full Access to CoProcessors
|
|
|
|
ArmWriteCPACR (CPACR_CP_FULL_ACCESS);
|
|
|
|
|
|
|
|
// Enable SWP instructions
|
2011-09-23 01:07:06 +02:00
|
|
|
ArmEnableSWPInstruction ();
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// Enable program flow prediction, if supported.
|
2011-09-23 01:07:06 +02:00
|
|
|
ArmEnableBranchPrediction ();
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
if (FixedPcdGet32(PcdVFPEnabled)) {
|
|
|
|
ArmEnableVFP();
|
|
|
|
}
|
|
|
|
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-03-31 14:12:58 +02:00
|
|
|
// Initialize peripherals that must be done at the early stage
|
|
|
|
// Example: Some L2x0 controllers must be initialized in Secure World
|
2011-04-26 20:27:15 +02:00
|
|
|
ArmPlatformSecInitialize ();
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// If we skip the PEI Core we could want to initialize the DRAM in the SEC phase.
|
|
|
|
// If we are in standalone, we need the initialization to copy the UEFI firmware into DRAM
|
2011-07-06 18:07:54 +02:00
|
|
|
if (FeaturePcdGet(PcdSystemMemoryInitializeInSec)) {
|
2011-02-01 06:41:42 +01:00
|
|
|
// Initialize system memory (DRAM)
|
2011-06-11 14:06:59 +02:00
|
|
|
ArmPlatformInitializeSystemMemory ();
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
2011-04-26 19:05:05 +02:00
|
|
|
// Some platform can change their physical memory mapping
|
2011-06-11 14:06:59 +02:00
|
|
|
ArmPlatformBootRemapping ();
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test if Trustzone is supported on this platform
|
2011-09-23 01:07:06 +02:00
|
|
|
if (ArmPlatformTrustzoneSupported ()) {
|
|
|
|
// Ensure the Monitor Stack Base & Size have been set
|
|
|
|
ASSERT(PcdGet32(PcdCPUCoresSecMonStackBase) != 0);
|
|
|
|
ASSERT(PcdGet32(PcdCPUCoreSecMonStackSize) != 0);
|
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
if (FixedPcdGet32(PcdMPCoreSupport)) {
|
|
|
|
// Setup SMP in Non Secure world
|
2011-09-23 01:01:13 +02:00
|
|
|
ArmSetupSmpNonSecure (GET_CORE_ID(MpId));
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enter Monitor Mode
|
2011-09-23 01:01:13 +02:00
|
|
|
enter_monitor_mode ((VOID*)(PcdGet32(PcdCPUCoresSecMonStackBase) + (PcdGet32(PcdCPUCoreSecMonStackSize) * GET_CORE_POS(MpId))));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
//Write the monitor mode vector table address
|
|
|
|
ArmWriteVMBar((UINT32) &monitor_vector_table);
|
|
|
|
|
|
|
|
//-------------------- Monitor Mode ---------------------
|
2011-04-26 19:05:05 +02:00
|
|
|
// Setup the Trustzone Chipsets
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-09-23 01:07:06 +02:00
|
|
|
ArmPlatformTrustzoneInit ();
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// Wake up the secondary cores by sending a interrupt to everyone else
|
|
|
|
// NOTE 1: The Software Generated Interrupts are always enabled on Cortex-A9
|
|
|
|
// MPcore test chip on Versatile Express board, So the Software doesn't have to
|
|
|
|
// enable SGI's explicitly.
|
|
|
|
// 2: As no other Interrupts are enabled, doesn't have to worry about the priority.
|
|
|
|
// 3: As all the cores are in secure state, use secure SGI's
|
|
|
|
//
|
|
|
|
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));
|
|
|
|
ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// Send SGI to all Secondary core to wake them up from WFI state.
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicSendSgiTo (PcdGet32(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E);
|
2011-02-01 06:41:42 +01:00
|
|
|
} else {
|
|
|
|
// The secondary cores need to wait until the Trustzone chipsets configuration is done
|
2011-04-26 19:05:05 +02:00
|
|
|
// before switching to Non Secure World
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// Enabled GIC CPU Interface
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// Waiting for the SGI from the primary core
|
|
|
|
ArmCallWFI();
|
|
|
|
|
2011-04-26 19:05:05 +02:00
|
|
|
// Acknowledge the interrupt and send End of Interrupt signal.
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicAcknowledgeSgiFrom (PcdGet32(PcdGicInterruptInterfaceBase), PRIMARY_CORE_ID);
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transfer the interrupt to Non-secure World
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicSetupNonSecure (PcdGet32(PcdGicDistributorBase),PcdGet32(PcdGicInterruptInterfaceBase));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// Write to CP15 Non-secure Access Control Register :
|
|
|
|
// - Enable CP10 and CP11 accesses in NS World
|
|
|
|
// - Enable Access to Preload Engine in NS World
|
|
|
|
// - Enable lockable TLB entries allocation in NS world
|
|
|
|
// - Enable R/W access to SMP bit of Auxiliary Control Register in NS world
|
2011-09-23 01:07:06 +02:00
|
|
|
ArmWriteNsacr (NSACR_NS_SMP | NSACR_TL | NSACR_PLE | NSACR_CP(10) | NSACR_CP(11));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// CP15 Secure Configuration Register with Non Secure bit (SCR_NS), CPSR.A modified in any
|
|
|
|
// security state (SCR_AW), CPSR.F modified in any security state (SCR_FW)
|
2011-09-23 01:07:06 +02:00
|
|
|
ArmWriteScr (SCR_NS | SCR_FW | SCR_AW);
|
2011-02-01 06:41:42 +01:00
|
|
|
} else {
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-03-31 14:09:31 +02:00
|
|
|
SerialPrint ("Trust Zone Configuration is disabled\n\r");
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
2011-04-26 19:05:05 +02:00
|
|
|
// Trustzone is not enabled, just enable the Distributor and CPU interface
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));
|
2011-04-26 19:07:23 +02:00
|
|
|
}
|
2011-09-23 00:59:52 +02:00
|
|
|
ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
// With Trustzone support the transition from Sec to Normal world is done by return_from_exception().
|
|
|
|
// If we want to keep this function call we need to ensure the SVC's SPSR point to the same Program
|
|
|
|
// Status Register as the the current one (CPSR).
|
2011-07-06 18:07:54 +02:00
|
|
|
copy_cpsr_into_spsr ();
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
2011-09-23 01:06:31 +02:00
|
|
|
JumpAddress = PcdGet32 (PcdFvBaseAddress);
|
2011-09-23 01:01:13 +02:00
|
|
|
ArmPlatformSecExtraAction (MpId, &JumpAddress);
|
2011-07-01 16:33:26 +02:00
|
|
|
|
2011-07-06 18:07:54 +02:00
|
|
|
return_from_exception (JumpAddress);
|
2011-02-01 06:41:42 +01:00
|
|
|
//-------------------- Non Secure Mode ---------------------
|
|
|
|
|
|
|
|
// PEI Core should always load and never return
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
|
|
|
|
2011-03-31 14:09:31 +02:00
|
|
|
VOID
|
|
|
|
SecCommonExceptionEntry (
|
|
|
|
IN UINT32 Entry,
|
|
|
|
IN UINT32 LR
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR8 Buffer[100];
|
|
|
|
UINTN CharCount;
|
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
switch (Entry) {
|
|
|
|
case 0:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
default:
|
2011-03-31 14:09:31 +02:00
|
|
|
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);
|
2011-02-01 06:41:42 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-03-31 14:09:31 +02:00
|
|
|
SerialPortWrite ((UINT8 *) Buffer, CharCount);
|
2011-02-01 06:41:42 +01:00
|
|
|
while(1);
|
|
|
|
}
|