]>
Commit | Line | Data |
---|---|---|
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 | |
91673dfd LD |
32 | #define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \\r |
33 | ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))\r | |
8fc38a3f | 34 | \r |
cd872e40 | 35 | EFI_STATUS\r |
36 | EFIAPI\r | |
37 | ExtractGuidedSectionLibConstructor (\r | |
38 | VOID\r | |
39 | );\r | |
40 | \r | |
41 | EFI_STATUS\r | |
42 | EFIAPI\r | |
43 | LzmaDecompressLibConstructor (\r | |
44 | VOID\r | |
45 | );\r | |
46 | \r | |
0dbbacdf | 47 | EFI_STATUS\r |
48 | GetPlatformPpi (\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 | 71 | VOID\r |
72 | PrePiMain (\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 |
91673dfd LD |
89 | ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&\r |
90 | ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)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 | |
177 | VOID\r | |
178 | CEntryPoint (\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 |
f437141a | 186 | // Initialize the platform specific controllers\r |
187 | ArmPlatformInitialize (MpId);\r | |
188 | \r | |
bebda7ce | 189 | if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {\r |
cd872e40 | 190 | // Initialize the Timer Library to setup the Timer HW controller\r |
191 | TimerConstructor ();\r | |
192 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
193 | StartTimeStamp = GetPerformanceCounter ();\r | |
2ee85366 | 194 | } else {\r |
195 | StartTimeStamp = 0;\r | |
cd872e40 | 196 | }\r |
197 | \r | |
6dafb303 OM |
198 | // Data Cache enabled on Primary core when MMU is enabled.\r |
199 | ArmDisableDataCache ();\r | |
200 | // Invalidate Data cache\r | |
201 | ArmInvalidateDataCache ();\r | |
d269095b | 202 | // Invalidate instruction cache\r |
203 | ArmInvalidateInstructionCache ();\r | |
6dafb303 | 204 | // Enable Instruction Caches on all cores.\r |
d269095b | 205 | ArmEnableInstructionCache ();\r |
cd872e40 | 206 | \r |
99565b88 | 207 | // Define the Global Variable region when we are not running in XIP\r |
208 | if (!IS_XIP()) {\r | |
bebda7ce | 209 | if (ArmPlatformIsPrimaryCore (MpId)) {\r |
1aa9860e | 210 | if (ArmIsMpCore()) {\r |
b1d41be7 | 211 | // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r |
212 | ArmCallSEV ();\r | |
1aa9860e | 213 | }\r |
99565b88 | 214 | } else {\r |
b1d41be7 | 215 | // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r |
216 | ArmCallWFE ();\r | |
99565b88 | 217 | }\r |
218 | }\r | |
3402aac7 | 219 | \r |
d269095b | 220 | // If not primary Jump to Secondary Main\r |
bebda7ce | 221 | if (ArmPlatformIsPrimaryCore (MpId)) {\r |
cd872e40 | 222 | // Goto primary Main.\r |
f2e17a07 | 223 | PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r |
cd872e40 | 224 | } else {\r |
0787bc61 | 225 | SecondaryMain (MpId);\r |
cd872e40 | 226 | }\r |
227 | \r | |
228 | // DXE Core should always load and never return\r | |
229 | ASSERT (FALSE);\r | |
230 | }\r | |
231 | \r |