]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePeiCore/PrePeiCore.c
ArmPlatformPkg/PrePeiCore: permit entry with the MMU enabled
[mirror_edk2.git] / ArmPlatformPkg / PrePeiCore / PrePeiCore.c
CommitLineData
1d5d0ae9 1/** @file\r
5a5440d0
PG
2 Main file supporting the transition to PEI Core in Normal World for Versatile Express\r
3\r
22c45b7c 4 Copyright (c) 2011 - 2022, ARM Limited. All rights reserved.\r
5a5440d0
PG
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
1d5d0ae9 8**/\r
9\r
1d5d0ae9 10#include <Library/BaseLib.h>\r
6c9a3d42 11#include <Library/CacheMaintenanceLib.h>\r
a6caee65 12#include <Library/DebugAgentLib.h>\r
1d5d0ae9 13#include <Library/ArmLib.h>\r
8fc38a3f 14\r
f598bf12 15#include "PrePeiCore.h"\r
1d5d0ae9 16\r
40b0b23e 17CONST EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI mTemporaryRamSupportPpi = { PrePeiCoreTemporaryRamSupport };\r
1d5d0ae9 18\r
40b0b23e 19CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {\r
1d5d0ae9 20 {\r
8fc38a3f 21 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
1d5d0ae9 22 &gEfiTemporaryRamSupportPpiGuid,\r
40b0b23e 23 (VOID *)&mTemporaryRamSupportPpi\r
1d5d0ae9 24 }\r
25};\r
26\r
77de7e53 27VOID\r
28CreatePpiList (\r
29 OUT UINTN *PpiListSize,\r
30 OUT EFI_PEI_PPI_DESCRIPTOR **PpiList\r
31 )\r
32{\r
40b0b23e 33 EFI_PEI_PPI_DESCRIPTOR *PlatformPpiList;\r
77de7e53 34 UINTN PlatformPpiListSize;\r
35 UINTN ListBase;\r
40b0b23e 36 EFI_PEI_PPI_DESCRIPTOR *LastPpi;\r
77de7e53 37\r
38 // Get the Platform PPIs\r
39 PlatformPpiListSize = 0;\r
40 ArmPlatformGetPlatformPpiList (&PlatformPpiListSize, &PlatformPpiList);\r
41\r
16f3544d 42 // Copy the Common and Platform PPis in Temporary Memory\r
bb5420bb 43 ListBase = PcdGet64 (PcdCPUCoresStackBase);\r
40b0b23e
MK
44 CopyMem ((VOID *)ListBase, gCommonPpiTable, sizeof (gCommonPpiTable));\r
45 CopyMem ((VOID *)(ListBase + sizeof (gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);\r
77de7e53 46\r
47 // Set the Terminate flag on the last PPI entry\r
40b0b23e 48 LastPpi = (EFI_PEI_PPI_DESCRIPTOR *)ListBase + ((sizeof (gCommonPpiTable) + PlatformPpiListSize) / sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;\r
77de7e53 49 LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;\r
50\r
40b0b23e
MK
51 *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;\r
52 *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;\r
77de7e53 53}\r
54\r
1d5d0ae9 55VOID\r
56CEntryPoint (\r
0787bc61 57 IN UINTN MpId,\r
1d5d0ae9 58 IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint\r
59 )\r
60{\r
fb493ac8
AB
61 if (!ArmMmuEnabled ()) {\r
62 // Data Cache enabled on Primary core when MMU is enabled.\r
63 ArmDisableDataCache ();\r
64 // Invalidate instruction cache\r
65 ArmInvalidateInstructionCache ();\r
66 // Enable Instruction Caches on all cores.\r
67 ArmEnableInstructionCache ();\r
68\r
69 InvalidateDataCacheRange (\r
70 (VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase),\r
71 PcdGet32 (PcdCPUCorePrimaryStackSize)\r
72 );\r
73 }\r
6c9a3d42 74\r
1d5d0ae9 75 //\r
76 // Note: Doesn't have to Enable CPU interface in non-secure world,\r
77 // as Non-secure interface is already enabled in Secure world.\r
78 //\r
79\r
a9d7090f 80 // Write VBAR - The Exception Vector table must be aligned to its requirement\r
6d0ca257
OM
81 // Note: The AArch64 Vector table must be 2k-byte aligned - if this assertion fails ensure\r
82 // 'Align=4K' is defined into your FDF for this module.\r
83 ASSERT (((UINTN)PeiVectorTable & ARM_VECTOR_TABLE_ALIGNMENT) == 0);\r
a9d7090f 84 ArmWriteVBar ((UINTN)PeiVectorTable);\r
1d5d0ae9 85\r
a6a835bd
AB
86 // Enable Floating Point\r
87 if (FixedPcdGet32 (PcdVFPEnabled)) {\r
88 ArmEnableVFP ();\r
89 }\r
90\r
40b0b23e 91 // Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.\r
1d5d0ae9 92\r
77de7e53 93 // If not primary Jump to Secondary Main\r
bebda7ce 94 if (ArmPlatformIsPrimaryCore (MpId)) {\r
22c45b7c
RM
95 // Invoke "ProcessLibraryConstructorList" to have all library constructors\r
96 // called.\r
97 ProcessLibraryConstructorList ();\r
98\r
a6caee65 99 // Initialize the Debug Agent for Source Level Debugging\r
100 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
101 SaveAndSetDebugTimerInterrupt (TRUE);\r
102\r
f437141a 103 // Initialize the platform specific controllers\r
104 ArmPlatformInitialize (MpId);\r
105\r
a6caee65 106 // Goto primary Main.\r
f598bf12 107 PrimaryMain (PeiCoreEntryPoint);\r
1d5d0ae9 108 } else {\r
0787bc61 109 SecondaryMain (MpId);\r
1d5d0ae9 110 }\r
111\r
112 // PEI Core should always load and never return\r
113 ASSERT (FALSE);\r
114}\r
115\r
116EFI_STATUS\r
117EFIAPI\r
93d451c6 118PrePeiCoreTemporaryRamSupport (\r
40b0b23e
MK
119 IN CONST EFI_PEI_SERVICES **PeiServices,\r
120 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
121 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
122 IN UINTN CopySize\r
1d5d0ae9 123 )\r
124{\r
40b0b23e
MK
125 VOID *OldHeap;\r
126 VOID *NewHeap;\r
127 VOID *OldStack;\r
128 VOID *NewStack;\r
129 UINTN HeapSize;\r
4960d8e0
HG
130\r
131 HeapSize = ALIGN_VALUE (CopySize / 2, CPU_STACK_ALIGNMENT);\r
93d451c6 132\r
40b0b23e
MK
133 OldHeap = (VOID *)(UINTN)TemporaryMemoryBase;\r
134 NewHeap = (VOID *)((UINTN)PermanentMemoryBase + (CopySize - HeapSize));\r
93d451c6 135\r
40b0b23e
MK
136 OldStack = (VOID *)((UINTN)TemporaryMemoryBase + HeapSize);\r
137 NewStack = (VOID *)(UINTN)PermanentMemoryBase;\r
93d451c6 138\r
139 //\r
140 // Migrate the temporary memory stack to permanent memory stack.\r
1d5d0ae9 141 //\r
4960d8e0 142 CopyMem (NewStack, OldStack, CopySize - HeapSize);\r
93d451c6 143\r
144 //\r
145 // Migrate the temporary memory heap to permanent memory heap.\r
f598bf12 146 //\r
4960d8e0 147 CopyMem (NewHeap, OldHeap, HeapSize);\r
3402aac7 148\r
93d451c6 149 SecSwitchStack ((UINTN)NewStack - (UINTN)OldStack);\r
1d5d0ae9 150\r
93d451c6 151 return EFI_SUCCESS;\r
152}\r