]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmPlatformPkg/PrePi/PrePi.c
UefiCpuPkg/MtrrLib: Add PCD PcdCpuNumberOfReservedVariableMtrrs
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
... / ...
CommitLineData
1/** @file\r
2*\r
3* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
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
19#include <Library/PrintLib.h>\r
20#include <Library/PeCoffGetEntryPointLib.h>\r
21#include <Library/PrePiHobListPointerLib.h>\r
22#include <Library/TimerLib.h>\r
23#include <Library/PerformanceLib.h>\r
24\r
25#include <Ppi/GuidedSectionExtraction.h>\r
26#include <Ppi/ArmMpCoreInfo.h>\r
27#include <Guid/LzmaDecompress.h>\r
28\r
29#include "PrePi.h"\r
30#include "LzmaDecompress.h"\r
31\r
32#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > mSystemMemoryEnd) || \\r
33 ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))\r
34\r
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
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
71VOID\r
72PrePiMain (\r
73 IN UINTN UefiMemoryBase,\r
74 IN UINTN StacksBase,\r
75 IN UINT64 StartTimeStamp\r
76 )\r
77{\r
78 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
79 ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi;\r
80 UINTN ArmCoreCount;\r
81 ARM_CORE_INFO* ArmCoreInfoTable;\r
82 EFI_STATUS Status;\r
83 CHAR8 Buffer[100];\r
84 UINTN CharCount;\r
85 UINTN StacksSize;\r
86\r
87 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
88 ASSERT (IS_XIP() ||\r
89 ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&\r
90 ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)mSystemMemoryEnd)));\r
91\r
92 // Initialize the architecture specific bits\r
93 ArchInitialize ();\r
94\r
95 // Initialize the Serial Port\r
96 SerialPortInitialize ();\r
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
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
104\r
105 // Declare the PI/UEFI memory region\r
106 HobList = HobConstructor (\r
107 (VOID*)UefiMemoryBase,\r
108 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
109 (VOID*)UefiMemoryBase,\r
110 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
111 );\r
112 PrePeiSetHobList (HobList);\r
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
118 // Create the Stacks HOB (reserve the memory for all stacks)\r
119 if (ArmIsMpCore ()) {\r
120 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +\r
121 ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));\r
122 } else {\r
123 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
124 }\r
125 BuildStackHob (StacksBase, StacksSize);\r
126\r
127 //TODO: Call CpuPei as a library\r
128 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
129\r
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
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
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
179 IN UINTN MpId,\r
180 IN UINTN UefiMemoryBase,\r
181 IN UINTN StacksBase\r
182 )\r
183{\r
184 UINT64 StartTimeStamp;\r
185\r
186 ASSERT(!ArmIsMpCore() || (PcdGet32 (PcdCoreCount) > 1));\r
187\r
188 // Initialize the platform specific controllers\r
189 ArmPlatformInitialize (MpId);\r
190\r
191 if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {\r
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
196 } else {\r
197 StartTimeStamp = 0;\r
198 }\r
199\r
200 // Data Cache enabled on Primary core when MMU is enabled.\r
201 ArmDisableDataCache ();\r
202 // Invalidate Data cache\r
203 ArmInvalidateDataCache ();\r
204 // Invalidate instruction cache\r
205 ArmInvalidateInstructionCache ();\r
206 // Enable Instruction Caches on all cores.\r
207 ArmEnableInstructionCache ();\r
208\r
209 // Define the Global Variable region when we are not running in XIP\r
210 if (!IS_XIP()) {\r
211 if (ArmPlatformIsPrimaryCore (MpId)) {\r
212 if (ArmIsMpCore()) {\r
213 // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r
214 ArmCallSEV ();\r
215 }\r
216 } else {\r
217 // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r
218 ArmCallWFE ();\r
219 }\r
220 }\r
221\r
222 // If not primary Jump to Secondary Main\r
223 if (ArmPlatformIsPrimaryCore (MpId)) {\r
224 // Goto primary Main.\r
225 PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r
226 } else {\r
227 SecondaryMain (MpId);\r
228 }\r
229\r
230 // DXE Core should always load and never return\r
231 ASSERT (FALSE);\r
232}\r
233\r