2 * Main file supporting the transition to PEI Core in Normal World for Versatile Express
4 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/DebugAgentLib.h>
18 #include <Library/ArmLib.h>
20 #include <Ppi/ArmGlobalVariable.h>
22 #include "PrePeiCore.h"
24 CONST EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi
= { PrePeiCoreTemporaryRamSupport
};
25 CONST ARM_GLOBAL_VARIABLE_PPI mGlobalVariablePpi
= { PrePeiCoreGetGlobalVariableMemory
};
27 CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable
[] = {
29 EFI_PEI_PPI_DESCRIPTOR_PPI
,
30 &gEfiTemporaryRamSupportPpiGuid
,
31 (VOID
*) &mTemporaryRamSupportPpi
34 EFI_PEI_PPI_DESCRIPTOR_PPI
,
35 &gArmGlobalVariablePpiGuid
,
36 (VOID
*) &mGlobalVariablePpi
42 OUT UINTN
*PpiListSize
,
43 OUT EFI_PEI_PPI_DESCRIPTOR
**PpiList
46 EFI_PEI_PPI_DESCRIPTOR
*PlatformPpiList
;
47 UINTN PlatformPpiListSize
;
49 EFI_PEI_PPI_DESCRIPTOR
*LastPpi
;
51 // Get the Platform PPIs
52 PlatformPpiListSize
= 0;
53 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize
, &PlatformPpiList
);
55 // Copy the Common and Platform PPis in Temporrary Memory
56 ListBase
= PcdGet64 (PcdCPUCoresStackBase
);
57 CopyMem ((VOID
*)ListBase
, gCommonPpiTable
, sizeof(gCommonPpiTable
));
58 CopyMem ((VOID
*)(ListBase
+ sizeof(gCommonPpiTable
)), PlatformPpiList
, PlatformPpiListSize
);
60 // Set the Terminate flag on the last PPI entry
61 LastPpi
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
+ ((sizeof(gCommonPpiTable
) + PlatformPpiListSize
) / sizeof(EFI_PEI_PPI_DESCRIPTOR
)) - 1;
62 LastPpi
->Flags
|= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
64 *PpiList
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
;
65 *PpiListSize
= sizeof(gCommonPpiTable
) + PlatformPpiListSize
;
71 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
74 // Data Cache enabled on Primary core when MMU is enabled.
75 ArmDisableDataCache ();
76 // Invalidate Data cache
77 ArmInvalidateDataCache ();
78 // Invalidate instruction cache
79 ArmInvalidateInstructionCache ();
80 // Enable Instruction Caches on all cores.
81 ArmEnableInstructionCache ();
84 // Note: Doesn't have to Enable CPU interface in non-secure world,
85 // as Non-secure interface is already enabled in Secure world.
88 // Write VBAR - The Exception Vector table must be aligned to its requirement
89 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure
90 // 'Align=4K' is defined into your FDF for this module.
91 ASSERT (((UINTN
)PeiVectorTable
& ARM_VECTOR_TABLE_ALIGNMENT
) == 0);
92 ArmWriteVBar ((UINTN
)PeiVectorTable
);
94 //Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
96 // If not primary Jump to Secondary Main
97 if (ArmPlatformIsPrimaryCore (MpId
)) {
98 // Initialize the Debug Agent for Source Level Debugging
99 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
100 SaveAndSetDebugTimerInterrupt (TRUE
);
102 // Initialize the platform specific controllers
103 ArmPlatformInitialize (MpId
);
105 // Goto primary Main.
106 PrimaryMain (PeiCoreEntryPoint
);
108 SecondaryMain (MpId
);
111 // PEI Core should always load and never return
117 PrePeiCoreTemporaryRamSupport (
118 IN CONST EFI_PEI_SERVICES
**PeiServices
,
119 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
120 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
129 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
130 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ (CopySize
>> 1));
132 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ (CopySize
>> 1));
133 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
136 // Migrate the temporary memory stack to permanent memory stack.
138 CopyMem (NewStack
, OldStack
, CopySize
>> 1);
141 // Migrate the temporary memory heap to permanent memory heap.
143 CopyMem (NewHeap
, OldHeap
, CopySize
>> 1);
145 SecSwitchStack ((UINTN
)NewStack
- (UINTN
)OldStack
);
151 PrePeiCoreGetGlobalVariableMemory (
152 OUT EFI_PHYSICAL_ADDRESS
*GlobalVariableBase
155 ASSERT (GlobalVariableBase
!= NULL
);
157 *GlobalVariableBase
= (UINTN
)PcdGet64 (PcdCPUCoresStackBase
) +
158 (UINTN
)PcdGet32 (PcdCPUCorePrimaryStackSize
) -
159 (UINTN
)PcdGet32 (PcdPeiGlobalVariableSize
);