2 Main file supporting the transition to PEI Core in Normal World for Versatile Express
4 Copyright (c) 2011 - 2022, ARM Limited. All rights reserved.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/CacheMaintenanceLib.h>
12 #include <Library/DebugAgentLib.h>
13 #include <Library/ArmLib.h>
14 #include <Library/PrintLib.h>
15 #include <Library/SerialPortLib.h>
17 #include "PrePeiCore.h"
19 CONST EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi
= { PrePeiCoreTemporaryRamSupport
};
21 CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable
[] = {
23 EFI_PEI_PPI_DESCRIPTOR_PPI
,
24 &gEfiTemporaryRamSupportPpiGuid
,
25 (VOID
*)&mTemporaryRamSupportPpi
31 OUT UINTN
*PpiListSize
,
32 OUT EFI_PEI_PPI_DESCRIPTOR
**PpiList
35 EFI_PEI_PPI_DESCRIPTOR
*PlatformPpiList
;
36 UINTN PlatformPpiListSize
;
38 EFI_PEI_PPI_DESCRIPTOR
*LastPpi
;
40 // Get the Platform PPIs
41 PlatformPpiListSize
= 0;
42 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize
, &PlatformPpiList
);
44 // Copy the Common and Platform PPis in Temporary Memory
45 ListBase
= PcdGet64 (PcdCPUCoresStackBase
);
46 CopyMem ((VOID
*)ListBase
, gCommonPpiTable
, sizeof (gCommonPpiTable
));
47 CopyMem ((VOID
*)(ListBase
+ sizeof (gCommonPpiTable
)), PlatformPpiList
, PlatformPpiListSize
);
49 // Set the Terminate flag on the last PPI entry
50 LastPpi
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
+ ((sizeof (gCommonPpiTable
) + PlatformPpiListSize
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
)) - 1;
51 LastPpi
->Flags
|= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
53 *PpiList
= (EFI_PEI_PPI_DESCRIPTOR
*)ListBase
;
54 *PpiListSize
= sizeof (gCommonPpiTable
) + PlatformPpiListSize
;
59 Prints firmware version and build time to serial console.
64 PrintFirmwareVersion (
71 CharCount
= AsciiSPrint (
74 "UEFI firmware (version %s built at %a on %a)\n\r",
75 (CHAR16
*)PcdGetPtr (PcdFirmwareVersionString
),
79 SerialPortWrite ((UINT8
*)Buffer
, CharCount
);
85 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
88 if (!ArmMmuEnabled ()) {
89 // Data Cache enabled on Primary core when MMU is enabled.
90 ArmDisableDataCache ();
91 // Invalidate instruction cache
92 ArmInvalidateInstructionCache ();
93 // Enable Instruction Caches on all cores.
94 ArmEnableInstructionCache ();
96 InvalidateDataCacheRange (
97 (VOID
*)(UINTN
)PcdGet64 (PcdCPUCoresStackBase
),
98 PcdGet32 (PcdCPUCorePrimaryStackSize
)
103 // Note: Doesn't have to Enable CPU interface in non-secure world,
104 // as Non-secure interface is already enabled in Secure world.
107 // Write VBAR - The Exception Vector table must be aligned to its requirement
108 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure
109 // 'Align=4K' is defined into your FDF for this module.
110 ASSERT (((UINTN
)PeiVectorTable
& ARM_VECTOR_TABLE_ALIGNMENT
) == 0);
111 ArmWriteVBar ((UINTN
)PeiVectorTable
);
113 // Enable Floating Point
114 if (FixedPcdGet32 (PcdVFPEnabled
)) {
118 // Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
120 // If not primary Jump to Secondary Main
121 if (ArmPlatformIsPrimaryCore (MpId
)) {
122 // Invoke "ProcessLibraryConstructorList" to have all library constructors
124 ProcessLibraryConstructorList ();
126 PrintFirmwareVersion ();
128 // Initialize the Debug Agent for Source Level Debugging
129 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
130 SaveAndSetDebugTimerInterrupt (TRUE
);
132 // Initialize the platform specific controllers
133 ArmPlatformInitialize (MpId
);
135 // Goto primary Main.
136 PrimaryMain (PeiCoreEntryPoint
);
138 SecondaryMain (MpId
);
141 // PEI Core should always load and never return
147 PrePeiCoreTemporaryRamSupport (
148 IN CONST EFI_PEI_SERVICES
**PeiServices
,
149 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
150 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
160 HeapSize
= ALIGN_VALUE (CopySize
/ 2, CPU_STACK_ALIGNMENT
);
162 OldHeap
= (VOID
*)(UINTN
)TemporaryMemoryBase
;
163 NewHeap
= (VOID
*)((UINTN
)PermanentMemoryBase
+ (CopySize
- HeapSize
));
165 OldStack
= (VOID
*)((UINTN
)TemporaryMemoryBase
+ HeapSize
);
166 NewStack
= (VOID
*)(UINTN
)PermanentMemoryBase
;
169 // Migrate the temporary memory stack to permanent memory stack.
171 CopyMem (NewStack
, OldStack
, CopySize
- HeapSize
);
174 // Migrate the temporary memory heap to permanent memory heap.
176 CopyMem (NewHeap
, OldHeap
, HeapSize
);
178 SecSwitchStack ((UINTN
)NewStack
- (UINTN
)OldStack
);