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-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/SerialPortLib.h>
|
2011-09-23 00:59:52 +02:00
|
|
|
#include <Library/ArmGicLib.h>
|
2011-09-27 18:22:09 +02:00
|
|
|
#include <Library/ArmCpuLib.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-09-27 18:22:09 +02:00
|
|
|
ArmCpuSetup (MpId);
|
|
|
|
|
|
|
|
if (ArmIsMpCore()) {
|
|
|
|
ArmCpuSynchronizeSignal (ARM_CPU_EVENT_BOOT_MEM_INIT);
|
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);
|
2011-09-27 18:22:09 +02:00
|
|
|
|
|
|
|
// Enable the GIC distributor and CPU Interface
|
|
|
|
// - no other Interrupts are enabled, doesn't have to worry about the priority.
|
|
|
|
// - all the cores are in secure state, use secure SGI's
|
|
|
|
ArmGicEnableDistributor (PcdGet32(PcdGicDistributorBase));
|
|
|
|
ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
|
|
|
|
} else {
|
|
|
|
// Enable the GIC CPU Interface
|
|
|
|
ArmGicEnableInterruptInterface (PcdGet32(PcdGicInterruptInterfaceBase));
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2011-09-27 18:22:09 +02:00
|
|
|
if (FixedPcdGet32 (PcdVFPEnabled)) {
|
2011-02-01 06:41:42 +01:00
|
|
|
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-09-27 18:22:09 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if Trustzone is supported on this platform
|
2011-09-27 18:29:07 +02:00
|
|
|
if (FixedPcdGetBool (PcdTrustzoneSupport)) {
|
2011-09-23 01:07:06 +02:00
|
|
|
// Ensure the Monitor Stack Base & Size have been set
|
|
|
|
ASSERT(PcdGet32(PcdCPUCoresSecMonStackBase) != 0);
|
|
|
|
ASSERT(PcdGet32(PcdCPUCoreSecMonStackSize) != 0);
|
|
|
|
|
2011-09-27 18:22:09 +02:00
|
|
|
if (ArmIsMpCore()) {
|
2011-02-01 06:41:42 +01:00
|
|
|
// Setup SMP in Non Secure world
|
2011-09-27 18:22:09 +02:00
|
|
|
ArmCpuSetupSmpNonSecure (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
|
|
|
|
2011-09-27 18:22:09 +02:00
|
|
|
// Waiting for the Primary Core to have finished to initialize the Secure World
|
|
|
|
ArmCpuSynchronizeSignal (ARM_CPU_EVENT_SECURE_INIT);
|
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
|
|
|
|
2011-09-27 18:22:09 +02:00
|
|
|
// Waiting for the Primary Core to have finished to initialize the Secure World
|
|
|
|
ArmCpuSynchronizeWait (ARM_CPU_EVENT_SECURE_INIT);
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Transfer the interrupt to Non-secure World
|
2011-09-27 18:22:09 +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
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|