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