2011-02-01 06:41:42 +01:00
|
|
|
/** @file
|
|
|
|
* Main file supporting the transition to PEI Core in Normal World for Versatile Express
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
2011-07-06 18:07:54 +02:00
|
|
|
#include <Library/DebugAgentLib.h>
|
2011-06-11 14:10:19 +02:00
|
|
|
#include <Library/PrintLib.h>
|
2011-02-01 06:41:42 +01:00
|
|
|
#include <Library/ArmLib.h>
|
2011-06-11 14:10:19 +02:00
|
|
|
#include <Library/SerialPortLib.h>
|
2011-09-23 01:11:03 +02:00
|
|
|
|
|
|
|
#include <Ppi/ArmGlobalVariable.h>
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-06-11 14:10:19 +02:00
|
|
|
#include "PrePeiCore.h"
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-09-23 01:11:34 +02:00
|
|
|
EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };
|
2011-09-23 01:11:03 +02:00
|
|
|
ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi = { PrePeiCoreGetGlobalVariableMemory };
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-09-23 01:11:03 +02:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {
|
2011-02-01 06:41:42 +01:00
|
|
|
{
|
2011-09-23 01:11:03 +02:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR_PPI,
|
2011-02-01 06:41:42 +01:00
|
|
|
&gEfiTemporaryRamSupportPpiGuid,
|
2011-09-23 01:11:34 +02:00
|
|
|
&mTemporaryRamSupportPpi
|
2011-09-23 01:11:03 +02:00
|
|
|
},
|
|
|
|
{
|
2011-09-23 01:12:23 +02:00
|
|
|
EFI_PEI_PPI_DESCRIPTOR_PPI,
|
2011-09-23 01:11:03 +02:00
|
|
|
&gArmGlobalVariablePpiGuid,
|
|
|
|
&mGlobalVariablePpi
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-09-23 01:12:23 +02:00
|
|
|
VOID
|
|
|
|
CreatePpiList (
|
|
|
|
OUT UINTN *PpiListSize,
|
|
|
|
OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;
|
|
|
|
UINTN PlatformPpiListSize;
|
|
|
|
UINTN ListBase;
|
|
|
|
EFI_PEI_PPI_DESCRIPTOR *LastPpi;
|
|
|
|
|
|
|
|
// Get the Platform PPIs
|
|
|
|
PlatformPpiListSize = 0;
|
|
|
|
ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);
|
|
|
|
|
|
|
|
// Copy the Common and Platform PPis in Temporrary Memory
|
|
|
|
ListBase = PcdGet32 (PcdCPUCoresStackBase);
|
|
|
|
CopyMem ((VOID*)ListBase, gCommonPpiTable, sizeof(gCommonPpiTable));
|
|
|
|
CopyMem ((VOID*)(ListBase + sizeof(gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);
|
|
|
|
|
|
|
|
// Set the Terminate flag on the last PPI entry
|
|
|
|
LastPpi = (EFI_PEI_PPI_DESCRIPTOR*)ListBase + ((sizeof(gCommonPpiTable) + PlatformPpiListSize) / sizeof(EFI_PEI_PPI_DESCRIPTOR)) - 1;
|
|
|
|
LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
|
|
|
|
|
|
|
|
*PpiList = (EFI_PEI_PPI_DESCRIPTOR*)ListBase;
|
|
|
|
*PpiListSize = sizeof(gCommonPpiTable) + PlatformPpiListSize;
|
|
|
|
}
|
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
VOID
|
|
|
|
CEntryPoint (
|
2011-09-23 01:01:13 +02:00
|
|
|
IN UINTN MpId,
|
2011-02-01 06:41:42 +01:00
|
|
|
IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//Clean Data cache
|
|
|
|
ArmCleanInvalidateDataCache();
|
|
|
|
|
|
|
|
//Invalidate instruction cache
|
|
|
|
ArmInvalidateInstructionCache();
|
|
|
|
|
|
|
|
// Enable Instruction & Data caches
|
2011-06-11 14:10:19 +02:00
|
|
|
ArmEnableDataCache ();
|
|
|
|
ArmEnableInstructionCache ();
|
2011-02-01 06:41:42 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Note: Doesn't have to Enable CPU interface in non-secure world,
|
|
|
|
// as Non-secure interface is already enabled in Secure world.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Write VBAR - The Vector table must be 32-byte aligned
|
|
|
|
ASSERT(((UINT32)PeiVectorTable & ((1 << 5)-1)) == 0);
|
|
|
|
ArmWriteVBar((UINT32)PeiVectorTable);
|
|
|
|
|
|
|
|
//Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
|
|
|
|
|
2011-09-23 01:12:23 +02:00
|
|
|
// If not primary Jump to Secondary Main
|
2011-09-23 01:01:13 +02:00
|
|
|
if (IS_PRIMARY_CORE(MpId)) {
|
2011-07-06 18:07:54 +02:00
|
|
|
// Initialize the Debug Agent for Source Level Debugging
|
|
|
|
InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
|
|
|
|
SaveAndSetDebugTimerInterrupt (TRUE);
|
|
|
|
|
2012-05-02 21:49:35 +02:00
|
|
|
// Initialize the platform specific controllers
|
|
|
|
ArmPlatformInitialize (MpId);
|
|
|
|
|
2011-07-06 18:07:54 +02:00
|
|
|
// Goto primary Main.
|
2011-06-11 14:10:19 +02:00
|
|
|
PrimaryMain (PeiCoreEntryPoint);
|
2011-02-01 06:41:42 +01:00
|
|
|
} else {
|
2011-09-23 01:01:13 +02:00
|
|
|
SecondaryMain (MpId);
|
2011-02-01 06:41:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// PEI Core should always load and never return
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2011-09-23 01:11:34 +02:00
|
|
|
PrePeiCoreTemporaryRamSupport (
|
2011-02-01 06:41:42 +01:00
|
|
|
IN CONST EFI_PEI_SERVICES **PeiServices,
|
|
|
|
IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
|
|
|
|
IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
|
|
|
|
IN UINTN CopySize
|
|
|
|
)
|
|
|
|
{
|
2011-09-23 01:11:34 +02:00
|
|
|
VOID *OldHeap;
|
|
|
|
VOID *NewHeap;
|
|
|
|
VOID *OldStack;
|
|
|
|
VOID *NewStack;
|
|
|
|
|
|
|
|
OldHeap = (VOID*)(UINTN)TemporaryMemoryBase;
|
|
|
|
NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize >> 1));
|
|
|
|
|
|
|
|
OldStack = (VOID*)((UINTN)TemporaryMemoryBase + (CopySize >> 1));
|
|
|
|
NewStack = (VOID*)(UINTN)PermanentMemoryBase;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Migrate the temporary memory stack to permanent memory stack.
|
2011-02-01 06:41:42 +01:00
|
|
|
//
|
2011-09-23 01:11:34 +02:00
|
|
|
CopyMem (NewStack, OldStack, CopySize >> 1);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Migrate the temporary memory heap to permanent memory heap.
|
2011-06-11 14:10:19 +02:00
|
|
|
//
|
2011-09-23 01:11:34 +02:00
|
|
|
CopyMem (NewHeap, OldHeap, CopySize >> 1);
|
|
|
|
|
|
|
|
SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-09-23 01:11:34 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2011-02-01 06:41:42 +01:00
|
|
|
|
2011-09-23 01:11:03 +02:00
|
|
|
EFI_STATUS
|
|
|
|
PrePeiCoreGetGlobalVariableMemory (
|
|
|
|
OUT EFI_PHYSICAL_ADDRESS *GlobalVariableBase
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (GlobalVariableBase != NULL);
|
|
|
|
|
|
|
|
*GlobalVariableBase = (UINTN)PcdGet32 (PcdCPUCoresStackBase) +
|
|
|
|
(UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) -
|
|
|
|
(UINTN)PcdGet32 (PcdPeiGlobalVariableSize);
|
|
|
|
|
2011-02-01 06:41:42 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-03-31 14:09:31 +02:00
|
|
|
VOID
|
|
|
|
PeiCommonExceptionEntry (
|
|
|
|
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);
|
|
|
|
}
|