]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011-2017, 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/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 <Ppi/SecPerformance.h>\r | |
27 | \r | |
28 | #include "PrePi.h"\r | |
29 | \r | |
30 | #define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \\r | |
31 | ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))\r | |
32 | \r | |
33 | UINT64 mSystemMemoryEnd = FixedPcdGet64(PcdSystemMemoryBase) +\r | |
34 | FixedPcdGet64(PcdSystemMemorySize) - 1;\r | |
35 | \r | |
36 | EFI_STATUS\r | |
37 | GetPlatformPpi (\r | |
38 | IN EFI_GUID *PpiGuid,\r | |
39 | OUT VOID **Ppi\r | |
40 | )\r | |
41 | {\r | |
42 | UINTN PpiListSize;\r | |
43 | UINTN PpiListCount;\r | |
44 | EFI_PEI_PPI_DESCRIPTOR *PpiList;\r | |
45 | UINTN Index;\r | |
46 | \r | |
47 | PpiListSize = 0;\r | |
48 | ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);\r | |
49 | PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);\r | |
50 | for (Index = 0; Index < PpiListCount; Index++, PpiList++) {\r | |
51 | if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {\r | |
52 | *Ppi = PpiList->Ppi;\r | |
53 | return EFI_SUCCESS;\r | |
54 | }\r | |
55 | }\r | |
56 | \r | |
57 | return EFI_NOT_FOUND;\r | |
58 | }\r | |
59 | \r | |
60 | VOID\r | |
61 | PrePiMain (\r | |
62 | IN UINTN UefiMemoryBase,\r | |
63 | IN UINTN StacksBase,\r | |
64 | IN UINT64 StartTimeStamp\r | |
65 | )\r | |
66 | {\r | |
67 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r | |
68 | ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi;\r | |
69 | UINTN ArmCoreCount;\r | |
70 | ARM_CORE_INFO* ArmCoreInfoTable;\r | |
71 | EFI_STATUS Status;\r | |
72 | CHAR8 Buffer[100];\r | |
73 | UINTN CharCount;\r | |
74 | UINTN StacksSize;\r | |
75 | FIRMWARE_SEC_PERFORMANCE Performance;\r | |
76 | \r | |
77 | // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r | |
78 | ASSERT (IS_XIP() ||\r | |
79 | ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&\r | |
80 | ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd)));\r | |
81 | \r | |
82 | // Initialize the architecture specific bits\r | |
83 | ArchInitialize ();\r | |
84 | \r | |
85 | // Initialize the Serial Port\r | |
86 | SerialPortInitialize ();\r | |
87 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r | |
88 | (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r | |
89 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
90 | \r | |
91 | // Initialize the Debug Agent for Source Level Debugging\r | |
92 | InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r | |
93 | SaveAndSetDebugTimerInterrupt (TRUE);\r | |
94 | \r | |
95 | // Declare the PI/UEFI memory region\r | |
96 | HobList = HobConstructor (\r | |
97 | (VOID*)UefiMemoryBase,\r | |
98 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r | |
99 | (VOID*)UefiMemoryBase,\r | |
100 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r | |
101 | );\r | |
102 | PrePeiSetHobList (HobList);\r | |
103 | \r | |
104 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r | |
105 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
106 | ASSERT_EFI_ERROR (Status);\r | |
107 | \r | |
108 | // Create the Stacks HOB (reserve the memory for all stacks)\r | |
109 | if (ArmIsMpCore ()) {\r | |
110 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) +\r | |
111 | ((FixedPcdGet32 (PcdCoreCount) - 1) * FixedPcdGet32 (PcdCPUCoreSecondaryStackSize));\r | |
112 | } else {\r | |
113 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r | |
114 | }\r | |
115 | BuildStackHob (StacksBase, StacksSize);\r | |
116 | \r | |
117 | //TODO: Call CpuPei as a library\r | |
118 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r | |
119 | \r | |
120 | if (ArmIsMpCore ()) {\r | |
121 | // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid\r | |
122 | Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi);\r | |
123 | \r | |
124 | // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)\r | |
125 | ASSERT_EFI_ERROR (Status);\r | |
126 | \r | |
127 | // Build the MP Core Info Table\r | |
128 | ArmCoreCount = 0;\r | |
129 | Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);\r | |
130 | if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) {\r | |
131 | // Build MPCore Info HOB\r | |
132 | BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);\r | |
133 | }\r | |
134 | }\r | |
135 | \r | |
136 | // Store timer value logged at the beginning of firmware image execution\r | |
137 | Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp);\r | |
138 | \r | |
139 | // Build SEC Performance Data Hob\r | |
140 | BuildGuidDataHob (&gEfiFirmwarePerformanceGuid, &Performance, sizeof (Performance));\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 | ProcessLibraryConstructorList ();\r | |
154 | \r | |
155 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r | |
156 | Status = DecompressFirstFv ();\r | |
157 | ASSERT_EFI_ERROR (Status);\r | |
158 | \r | |
159 | // Load the DXE Core and transfer control to it\r | |
160 | Status = LoadDxeCoreFromFv (NULL, 0);\r | |
161 | ASSERT_EFI_ERROR (Status);\r | |
162 | }\r | |
163 | \r | |
164 | VOID\r | |
165 | CEntryPoint (\r | |
166 | IN UINTN MpId,\r | |
167 | IN UINTN UefiMemoryBase,\r | |
168 | IN UINTN StacksBase\r | |
169 | )\r | |
170 | {\r | |
171 | UINT64 StartTimeStamp;\r | |
172 | \r | |
173 | // Initialize the platform specific controllers\r | |
174 | ArmPlatformInitialize (MpId);\r | |
175 | \r | |
176 | if (ArmPlatformIsPrimaryCore (MpId) && PerformanceMeasurementEnabled ()) {\r | |
177 | // Initialize the Timer Library to setup the Timer HW controller\r | |
178 | TimerConstructor ();\r | |
179 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
180 | StartTimeStamp = GetPerformanceCounter ();\r | |
181 | } else {\r | |
182 | StartTimeStamp = 0;\r | |
183 | }\r | |
184 | \r | |
185 | // Data Cache enabled on Primary core when MMU is enabled.\r | |
186 | ArmDisableDataCache ();\r | |
187 | // Invalidate Data cache\r | |
188 | ArmInvalidateDataCache ();\r | |
189 | // Invalidate instruction cache\r | |
190 | ArmInvalidateInstructionCache ();\r | |
191 | // Enable Instruction Caches on all cores.\r | |
192 | ArmEnableInstructionCache ();\r | |
193 | \r | |
194 | // Define the Global Variable region when we are not running in XIP\r | |
195 | if (!IS_XIP()) {\r | |
196 | if (ArmPlatformIsPrimaryCore (MpId)) {\r | |
197 | if (ArmIsMpCore()) {\r | |
198 | // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r | |
199 | ArmCallSEV ();\r | |
200 | }\r | |
201 | } else {\r | |
202 | // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r | |
203 | ArmCallWFE ();\r | |
204 | }\r | |
205 | }\r | |
206 | \r | |
207 | // If not primary Jump to Secondary Main\r | |
208 | if (ArmPlatformIsPrimaryCore (MpId)) {\r | |
209 | // Goto primary Main.\r | |
210 | PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r | |
211 | } else {\r | |
212 | SecondaryMain (MpId);\r | |
213 | }\r | |
214 | \r | |
215 | // DXE Core should always load and never return\r | |
216 | ASSERT (FALSE);\r | |
217 | }\r | |
218 | \r |