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