]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/PrePi/PrePi.c
ArmPlatformPkg: remove all ArmPlatformGlobalVariableLib implementations
[mirror_edk2.git] / ArmVirtPkg / PrePi / PrePi.c
CommitLineData
f9a9d2dc
AB
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/PrePiLib.h>\r
18#include <Library/PrintLib.h>\r
19#include <Library/PeCoffGetEntryPointLib.h>\r
20#include <Library/PrePiHobListPointerLib.h>\r
21#include <Library/TimerLib.h>\r
22#include <Library/PerformanceLib.h>\r
c9e5618f 23#include <Library/CacheMaintenanceLib.h>\r
f9a9d2dc
AB
24\r
25#include <Ppi/GuidedSectionExtraction.h>\r
26#include <Ppi/ArmMpCoreInfo.h>\r
27#include <Guid/LzmaDecompress.h>\r
28#include <Guid/ArmGlobalVariableHob.h>\r
29\r
30#include "PrePi.h"\r
31#include "LzmaDecompress.h"\r
32\r
33// Not used when PrePi in run in XIP mode\r
34UINTN mGlobalVariableBase = 0;\r
35\r
36EFI_STATUS\r
37EFIAPI\r
38ExtractGuidedSectionLibConstructor (\r
39 VOID\r
40 );\r
41\r
42EFI_STATUS\r
43EFIAPI\r
44LzmaDecompressLibConstructor (\r
45 VOID\r
46 );\r
47\r
48VOID\r
49EFIAPI\r
50BuildGlobalVariableHob (\r
51 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r
52 IN UINT32 GlobalVariableSize\r
53 )\r
54{\r
55 ARM_HOB_GLOBAL_VARIABLE *Hob;\r
56\r
57 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
58 ASSERT(Hob != NULL);\r
59\r
60 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
61 Hob->GlobalVariableBase = GlobalVariableBase;\r
62 Hob->GlobalVariableSize = GlobalVariableSize;\r
63}\r
64\r
65EFI_STATUS\r
66GetPlatformPpi (\r
67 IN EFI_GUID *PpiGuid,\r
68 OUT VOID **Ppi\r
69 )\r
70{\r
71 UINTN PpiListSize;\r
72 UINTN PpiListCount;\r
73 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
74 UINTN Index;\r
75\r
76 PpiListSize = 0;\r
77 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r
78 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r
79 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r
80 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r
81 *Ppi = PpiList->Ppi;\r
82 return EFI_SUCCESS;\r
83 }\r
84 }\r
85\r
86 return EFI_NOT_FOUND;\r
87}\r
88\r
89VOID\r
90PrePiMain (\r
91 IN UINTN UefiMemoryBase,\r
92 IN UINTN StacksBase,\r
93 IN UINTN GlobalVariableBase,\r
94 IN UINT64 StartTimeStamp\r
95 )\r
96{\r
97 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
98 EFI_STATUS Status;\r
99 CHAR8 Buffer[100];\r
100 UINTN CharCount;\r
101 UINTN StacksSize;\r
102\r
103 // Initialize the architecture specific bits\r
104 ArchInitialize ();\r
105\r
f9a9d2dc
AB
106 // Declare the PI/UEFI memory region\r
107 HobList = HobConstructor (\r
108 (VOID*)UefiMemoryBase,\r
109 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
110 (VOID*)UefiMemoryBase,\r
111 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
112 );\r
113 PrePeiSetHobList (HobList);\r
114\r
c9e5618f
AB
115 //\r
116 // Ensure that the loaded image is invalidated in the caches, so that any\r
117 // modifications we made with the caches and MMU off (such as the applied\r
118 // relocations) don't become invisible once we turn them on.\r
119 //\r
120 InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
121\r
f9a9d2dc
AB
122 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
123 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
124 ASSERT_EFI_ERROR (Status);\r
125\r
c9e5618f
AB
126 // Initialize the Serial Port\r
127 SerialPortInitialize ();\r
128 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
129 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
130 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
131\r
f9a9d2dc
AB
132 // Create the Stacks HOB (reserve the memory for all stacks)\r
133 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
134 BuildStackHob (StacksBase, StacksSize);\r
135\r
136 // Declare the Global Variable HOB\r
137 BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r
138\r
139 //TODO: Call CpuPei as a library\r
140 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
141\r
142 // Set the Boot Mode\r
143 SetBootMode (ArmPlatformGetBootMode ());\r
144\r
145 // Initialize Platform HOBs (CpuHob and FvHob)\r
146 Status = PlatformPeim ();\r
147 ASSERT_EFI_ERROR (Status);\r
148\r
149 // Now, the HOB List has been initialized, we can register performance information\r
150 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
151\r
152 // SEC phase needs to run library constructors by hand.\r
153 ExtractGuidedSectionLibConstructor ();\r
154 LzmaDecompressLibConstructor ();\r
155\r
156 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
157 BuildPeCoffLoaderHob ();\r
158 BuildExtractSectionHob (\r
159 &gLzmaCustomDecompressGuid,\r
160 LzmaGuidedSectionGetInfo,\r
161 LzmaGuidedSectionExtraction\r
162 );\r
163\r
164 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
165 Status = DecompressFirstFv ();\r
166 ASSERT_EFI_ERROR (Status);\r
167\r
168 // Load the DXE Core and transfer control to it\r
169 Status = LoadDxeCoreFromFv (NULL, 0);\r
170 ASSERT_EFI_ERROR (Status);\r
171}\r
172\r
173VOID\r
174CEntryPoint (\r
175 IN UINTN MpId,\r
176 IN UINTN UefiMemoryBase,\r
177 IN UINTN StacksBase,\r
178 IN UINTN GlobalVariableBase\r
179 )\r
180{\r
181 UINT64 StartTimeStamp;\r
182\r
183 // Initialize the platform specific controllers\r
184 ArmPlatformInitialize (MpId);\r
185\r
186 if (PerformanceMeasurementEnabled ()) {\r
187 // Initialize the Timer Library to setup the Timer HW controller\r
188 TimerConstructor ();\r
189 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
190 StartTimeStamp = GetPerformanceCounter ();\r
191 } else {\r
192 StartTimeStamp = 0;\r
193 }\r
194\r
195 // Data Cache enabled on Primary core when MMU is enabled.\r
196 ArmDisableDataCache ();\r
f9a9d2dc
AB
197 // Invalidate instruction cache\r
198 ArmInvalidateInstructionCache ();\r
199 // Enable Instruction Caches on all cores.\r
200 ArmEnableInstructionCache ();\r
201\r
202 // Define the Global Variable region\r
203 mGlobalVariableBase = GlobalVariableBase;\r
204\r
205 PrePiMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
206\r
207 // DXE Core should always load and never return\r
208 ASSERT (FALSE);\r
209}\r