]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg/PrePi: replace set/way cache ops with by-VA ones
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
CommitLineData
cd872e40 1/** @file\r
2*\r
a63be426 3* Copyright (c) 2011-2017, ARM Limited. All rights reserved.\r
cd872e40 4*\r
f4dfad05 5* SPDX-License-Identifier: BSD-2-Clause-Patent\r
cd872e40 6*\r
7**/\r
8\r
9#include <PiPei.h>\r
10\r
492679a5 11#include <Library/CacheMaintenanceLib.h>\r
cd872e40 12#include <Library/DebugAgentLib.h>\r
13#include <Library/PrePiLib.h>\r
cd872e40 14#include <Library/PrintLib.h>\r
37573927 15#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 16#include <Library/TimerLib.h>\r
17#include <Library/PerformanceLib.h>\r
18\r
19#include <Ppi/GuidedSectionExtraction.h>\r
0dbbacdf 20#include <Ppi/ArmMpCoreInfo.h>\r
a63be426 21#include <Ppi/SecPerformance.h>\r
cd872e40 22\r
23#include "PrePi.h"\r
cd872e40 24\r
91673dfd 25#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \\r
d6607d8b 26 ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= FixedPcdGet64 (PcdSystemMemoryBase)))\r
8fc38a3f 27\r
4aae7419
AB
28UINT64 mSystemMemoryEnd = FixedPcdGet64(PcdSystemMemoryBase) +\r
29 FixedPcdGet64(PcdSystemMemorySize) - 1;\r
30\r
0dbbacdf 31EFI_STATUS\r
32GetPlatformPpi (\r
33 IN EFI_GUID *PpiGuid,\r
34 OUT VOID **Ppi\r
35 )\r
36{\r
37 UINTN PpiListSize;\r
38 UINTN PpiListCount;\r
39 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
40 UINTN Index;\r
41\r
42 PpiListSize = 0;\r
43 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
44 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
45 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
46 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r
47 *Ppi = PpiList->Ppi;\r
48 return EFI_SUCCESS;\r
49 }\r
50 }\r
51\r
52 return EFI_NOT_FOUND;\r
53}\r
54\r
cd872e40 55VOID\r
56PrePiMain (\r
57 IN UINTN UefiMemoryBase,\r
c524ffbb 58 IN UINTN StacksBase,\r
cd872e40 59 IN UINT64 StartTimeStamp\r
60 )\r
61{\r
37573927 62 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
0dbbacdf 63 ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi;\r
64 UINTN ArmCoreCount;\r
65 ARM_CORE_INFO* ArmCoreInfoTable;\r
cd872e40 66 EFI_STATUS Status;\r
67 CHAR8 Buffer[100];\r
68 UINTN CharCount;\r
d269095b 69 UINTN StacksSize;\r
a63be426 70 FIRMWARE_SEC_PERFORMANCE Performance;\r
cd872e40 71\r
8fc38a3f 72 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
3402aac7 73 ASSERT (IS_XIP() ||\r
91673dfd
LD
74 ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&\r
75 ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd)));\r
8fc38a3f 76\r
1bc83266
HL
77 // Initialize the architecture specific bits\r
78 ArchInitialize ();\r
cd872e40 79\r
80 // Initialize the Serial Port\r
81 SerialPortInitialize ();\r
37363dff 82 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
83 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
cd872e40 84 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
85\r
86 // Initialize the Debug Agent for Source Level Debugging\r
87 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
88 SaveAndSetDebugTimerInterrupt (TRUE);\r
3402aac7 89\r
d269095b 90 // Declare the PI/UEFI memory region\r
37573927 91 HobList = HobConstructor (\r
cd872e40 92 (VOID*)UefiMemoryBase,\r
93 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
94 (VOID*)UefiMemoryBase,\r
d269095b 95 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
96 );\r
37573927 97 PrePeiSetHobList (HobList);\r
cd872e40 98\r
99 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
100 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
101 ASSERT_EFI_ERROR (Status);\r
102\r
d269095b 103 // Create the Stacks HOB (reserve the memory for all stacks)\r
99565b88 104 if (ArmIsMpCore ()) {\r
81514a8a
OM
105 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +\r
106 ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));\r
99565b88 107 } else {\r
108 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
109 }\r
d269095b 110 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 111\r
44788bae 112 //TODO: Call CpuPei as a library\r
e0ec9a12 113 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));\r
44788bae 114\r
0dbbacdf 115 if (ArmIsMpCore ()) {\r
116 // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid\r
117 Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r
118\r
119 // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r
120 ASSERT_EFI_ERROR (Status);\r
121\r
122 // Build the MP Core Info Table\r
123 ArmCoreCount = 0;\r
124 Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r
125 if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) {\r
126 // Build MPCore Info HOB\r
127 BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);\r
128 }\r
129 }\r
130\r
a63be426
AF
131 // Store timer value logged at the beginning of firmware image execution\r
132 Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp);\r
133\r
134 // Build SEC Performance Data Hob\r
135 BuildGuidDataHob (&gEfiFirmwarePerformanceGuid, &Performance, sizeof (Performance));\r
136\r
cd872e40 137 // Set the Boot Mode\r
138 SetBootMode (ArmPlatformGetBootMode ());\r
139\r
140 // Initialize Platform HOBs (CpuHob and FvHob)\r
141 Status = PlatformPeim ();\r
142 ASSERT_EFI_ERROR (Status);\r
143\r
cd872e40 144 // Now, the HOB List has been initialized, we can register performance information\r
145 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
146\r
147 // SEC phase needs to run library constructors by hand.\r
6efd58aa 148 ProcessLibraryConstructorList ();\r
cd872e40 149\r
cd872e40 150 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
151 Status = DecompressFirstFv ();\r
152 ASSERT_EFI_ERROR (Status);\r
153\r
154 // Load the DXE Core and transfer control to it\r
155 Status = LoadDxeCoreFromFv (NULL, 0);\r
156 ASSERT_EFI_ERROR (Status);\r
157}\r
158\r
159VOID\r
160CEntryPoint (\r
0787bc61 161 IN UINTN MpId,\r
c524ffbb 162 IN UINTN UefiMemoryBase,\r
f2e17a07 163 IN UINTN StacksBase\r
cd872e40 164 )\r
165{\r
166 UINT64 StartTimeStamp;\r
3402aac7 167\r
f437141a 168 // Initialize the platform specific controllers\r
169 ArmPlatformInitialize (MpId);\r
170\r
bebda7ce 171 if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 172 // Initialize the Timer Library to setup the Timer HW controller\r
173 TimerConstructor ();\r
174 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
175 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 176 } else {\r
177 StartTimeStamp = 0;\r
cd872e40 178 }\r
179\r
6dafb303
OM
180 // Data Cache enabled on Primary core when MMU is enabled.\r
181 ArmDisableDataCache ();\r
d269095b 182 // Invalidate instruction cache\r
183 ArmInvalidateInstructionCache ();\r
6dafb303 184 // Enable Instruction Caches on all cores.\r
d269095b 185 ArmEnableInstructionCache ();\r
cd872e40 186\r
99565b88 187 // Define the Global Variable region when we are not running in XIP\r
188 if (!IS_XIP()) {\r
bebda7ce 189 if (ArmPlatformIsPrimaryCore (MpId)) {\r
1aa9860e 190 if (ArmIsMpCore()) {\r
b1d41be7 191 // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r
192 ArmCallSEV ();\r
1aa9860e 193 }\r
99565b88 194 } else {\r
16f3544d 195 // Wait the Primary core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r
b1d41be7 196 ArmCallWFE ();\r
99565b88 197 }\r
198 }\r
3402aac7 199\r
d269095b 200 // If not primary Jump to Secondary Main\r
bebda7ce 201 if (ArmPlatformIsPrimaryCore (MpId)) {\r
492679a5
AB
202\r
203 InvalidateDataCacheRange ((VOID *)UefiMemoryBase,\r
204 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
205\r
cd872e40 206 // Goto primary Main.\r
f2e17a07 207 PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r
cd872e40 208 } else {\r
0787bc61 209 SecondaryMain (MpId);\r
cd872e40 210 }\r
211\r
212 // DXE Core should always load and never return\r
213 ASSERT (FALSE);\r
214}\r