]>
Commit | Line | Data |
---|---|---|
1 | /** @file | |
2 | Definitions to install Multiple Processor PPI. | |
3 | ||
4 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> | |
5 | This program and the accompanying materials | |
6 | are licensed and made available under the terms and conditions of the BSD License | |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
12 | ||
13 | **/ | |
14 | ||
15 | #ifndef _CPU_MP_PEI_H_ | |
16 | #define _CPU_MP_PEI_H_ | |
17 | ||
18 | #include <PiPei.h> | |
19 | ||
20 | #include <Ppi/MpServices.h> | |
21 | #include <Ppi/SecPlatformInformation.h> | |
22 | #include <Ppi/SecPlatformInformation2.h> | |
23 | #include <Ppi/EndOfPeiPhase.h> | |
24 | ||
25 | #include <Register/LocalApic.h> | |
26 | ||
27 | #include <Library/BaseLib.h> | |
28 | #include <Library/BaseMemoryLib.h> | |
29 | #include <Library/DebugLib.h> | |
30 | #include <Library/HobLib.h> | |
31 | #include <Library/LocalApicLib.h> | |
32 | #include <Library/MtrrLib.h> | |
33 | #include <Library/PcdLib.h> | |
34 | #include <Library/PeimEntryPoint.h> | |
35 | #include <Library/PeiServicesLib.h> | |
36 | #include <Library/ReportStatusCodeLib.h> | |
37 | #include <Library/SynchronizationLib.h> | |
38 | #include <Library/TimerLib.h> | |
39 | #include <Library/UefiCpuLib.h> | |
40 | ||
41 | #include "Microcode.h" | |
42 | ||
43 | // | |
44 | // AP state | |
45 | // | |
46 | typedef enum { | |
47 | CpuStateIdle, | |
48 | CpuStateBusy, | |
49 | CpuStateDisabled | |
50 | } CPU_STATE; | |
51 | ||
52 | // | |
53 | // AP reset code information | |
54 | // | |
55 | typedef struct { | |
56 | UINT8 *RendezvousFunnelAddress; | |
57 | UINTN PModeEntryOffset; | |
58 | UINTN LModeEntryOffset; | |
59 | UINTN RendezvousFunnelSize; | |
60 | } MP_ASSEMBLY_ADDRESS_MAP; | |
61 | ||
62 | // | |
63 | // CPU exchange information for switch BSP | |
64 | // | |
65 | typedef struct { | |
66 | UINT8 State; // offset 0 | |
67 | UINTN StackPointer; // offset 4 / 8 | |
68 | IA32_DESCRIPTOR Gdtr; // offset 8 / 16 | |
69 | IA32_DESCRIPTOR Idtr; // offset 14 / 26 | |
70 | } CPU_EXCHANGE_ROLE_INFO; | |
71 | ||
72 | typedef struct _PEI_CPU_MP_DATA PEI_CPU_MP_DATA; | |
73 | ||
74 | #pragma pack() | |
75 | ||
76 | typedef union { | |
77 | struct { | |
78 | UINT32 LimitLow : 16; | |
79 | UINT32 BaseLow : 16; | |
80 | UINT32 BaseMid : 8; | |
81 | UINT32 Type : 4; | |
82 | UINT32 System : 1; | |
83 | UINT32 Dpl : 2; | |
84 | UINT32 Present : 1; | |
85 | UINT32 LimitHigh : 4; | |
86 | UINT32 Software : 1; | |
87 | UINT32 Reserved : 1; | |
88 | UINT32 DefaultSize : 1; | |
89 | UINT32 Granularity : 1; | |
90 | UINT32 BaseHigh : 8; | |
91 | } Bits; | |
92 | UINT64 Uint64; | |
93 | } IA32_GDT; | |
94 | ||
95 | // | |
96 | // MP CPU exchange information for AP reset code | |
97 | // | |
98 | typedef struct { | |
99 | UINTN Lock; | |
100 | UINTN StackStart; | |
101 | UINTN StackSize; | |
102 | UINTN CFunction; | |
103 | IA32_DESCRIPTOR GdtrProfile; | |
104 | IA32_DESCRIPTOR IdtrProfile; | |
105 | UINTN BufferStart; | |
106 | UINTN PmodeOffset; | |
107 | UINTN NumApsExecuting; | |
108 | UINTN LmodeOffset; | |
109 | UINTN Cr3; | |
110 | PEI_CPU_MP_DATA *PeiCpuMpData; | |
111 | } MP_CPU_EXCHANGE_INFO; | |
112 | ||
113 | #pragma pack() | |
114 | ||
115 | typedef struct { | |
116 | UINT32 ApicId; | |
117 | EFI_HEALTH_FLAGS Health; | |
118 | CPU_STATE State; | |
119 | BOOLEAN CpuHealthy; | |
120 | } PEI_CPU_DATA; | |
121 | ||
122 | // | |
123 | // PEI CPU MP Data save in memory | |
124 | // | |
125 | struct _PEI_CPU_MP_DATA { | |
126 | UINT32 CpuCount; | |
127 | UINT32 BspNumber; | |
128 | UINTN Buffer; | |
129 | UINTN CpuApStackSize; | |
130 | MP_ASSEMBLY_ADDRESS_MAP AddressMap; | |
131 | UINTN WakeupBuffer; | |
132 | UINTN BackupBuffer; | |
133 | UINTN BackupBufferSize; | |
134 | UINTN ApFunction; | |
135 | UINTN ApFunctionArgument; | |
136 | volatile UINT32 FinishedCount; | |
137 | BOOLEAN EndOfPeiFlag; | |
138 | BOOLEAN InitFlag; | |
139 | CPU_EXCHANGE_ROLE_INFO BSPInfo; | |
140 | CPU_EXCHANGE_ROLE_INFO APInfo; | |
141 | MTRR_SETTINGS MtrrTable; | |
142 | PEI_CPU_DATA *CpuData; | |
143 | volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo; | |
144 | }; | |
145 | extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc; | |
146 | ||
147 | ||
148 | /** | |
149 | Assembly code to get starting address and size of the rendezvous entry for APs. | |
150 | Information for fixing a jump instruction in the code is also returned. | |
151 | ||
152 | @param AddressMap Output buffer for address map information. | |
153 | **/ | |
154 | VOID | |
155 | EFIAPI | |
156 | AsmGetAddressMap ( | |
157 | OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap | |
158 | ); | |
159 | ||
160 | /** | |
161 | Assembly code to load GDT table and update segment accordingly. | |
162 | ||
163 | @param Gdtr Pointer to GDT descriptor | |
164 | **/ | |
165 | VOID | |
166 | EFIAPI | |
167 | AsmInitializeGdt ( | |
168 | IN IA32_DESCRIPTOR *Gdtr | |
169 | ); | |
170 | ||
171 | /** | |
172 | Assembly code to do CLI-HALT loop. | |
173 | ||
174 | **/ | |
175 | VOID | |
176 | EFIAPI | |
177 | AsmCliHltLoop ( | |
178 | VOID | |
179 | ); | |
180 | ||
181 | /** | |
182 | Get available system memory below 1MB by specified size. | |
183 | ||
184 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
185 | **/ | |
186 | VOID | |
187 | BackupAndPrepareWakeupBuffer( | |
188 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
189 | ); | |
190 | ||
191 | /** | |
192 | Restore wakeup buffer data. | |
193 | ||
194 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
195 | **/ | |
196 | VOID | |
197 | RestoreWakeupBuffer( | |
198 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
199 | ); | |
200 | ||
201 | /** | |
202 | Notify function on End Of Pei PPI. | |
203 | ||
204 | On S3 boot, this function will restore wakeup buffer data. | |
205 | On normal boot, this function will flag wakeup buffer to be un-used type. | |
206 | ||
207 | @param PeiServices The pointer to the PEI Services Table. | |
208 | @param NotifyDescriptor Address of the notification descriptor data structure. | |
209 | @param Ppi Address of the PPI that was installed. | |
210 | ||
211 | @retval EFI_SUCCESS When everything is OK. | |
212 | ||
213 | **/ | |
214 | EFI_STATUS | |
215 | EFIAPI | |
216 | CpuMpEndOfPeiCallback ( | |
217 | IN EFI_PEI_SERVICES **PeiServices, | |
218 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor, | |
219 | IN VOID *Ppi | |
220 | ); | |
221 | ||
222 | /** | |
223 | This function will be called by BSP to wakeup AP. | |
224 | ||
225 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
226 | @param Broadcast TRUE: Send broadcast IPI to all APs | |
227 | FALSE: Send IPI to AP by ApicId | |
228 | @param ApicId Apic ID for the processor to be waked | |
229 | @param Procedure The function to be invoked by AP | |
230 | @param ProcedureArgument The argument to be passed into AP function | |
231 | **/ | |
232 | VOID | |
233 | WakeUpAP ( | |
234 | IN PEI_CPU_MP_DATA *PeiCpuMpData, | |
235 | IN BOOLEAN Broadcast, | |
236 | IN UINT32 ApicId, | |
237 | IN EFI_AP_PROCEDURE Procedure, OPTIONAL | |
238 | IN VOID *ProcedureArgument OPTIONAL | |
239 | ); | |
240 | ||
241 | /** | |
242 | Get CPU MP Data pointer from the Guided HOB. | |
243 | ||
244 | @return Pointer to Pointer to PEI CPU MP Data | |
245 | **/ | |
246 | PEI_CPU_MP_DATA * | |
247 | GetMpHobData ( | |
248 | VOID | |
249 | ); | |
250 | ||
251 | /** | |
252 | Find the current Processor number by APIC ID. | |
253 | ||
254 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
255 | @param ProcessorNumber Return the pocessor number found | |
256 | ||
257 | @retval EFI_SUCCESS ProcessorNumber is found and returned. | |
258 | @retval EFI_NOT_FOUND ProcessorNumber is not found. | |
259 | **/ | |
260 | EFI_STATUS | |
261 | GetProcessorNumber ( | |
262 | IN PEI_CPU_MP_DATA *PeiCpuMpData, | |
263 | OUT UINTN *ProcessorNumber | |
264 | ); | |
265 | ||
266 | /** | |
267 | Collects BIST data from PPI. | |
268 | ||
269 | This function collects BIST data from Sec Platform Information2 PPI | |
270 | or SEC Platform Information PPI. | |
271 | ||
272 | @param PeiServices Pointer to PEI Services Table | |
273 | @param PeiCpuMpData Pointer to PEI CPU MP Data | |
274 | ||
275 | **/ | |
276 | VOID | |
277 | CollectBistDataFromPpi ( | |
278 | IN CONST EFI_PEI_SERVICES **PeiServices, | |
279 | IN PEI_CPU_MP_DATA *PeiCpuMpData | |
280 | ); | |
281 | ||
282 | /** | |
283 | Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI. | |
284 | ||
285 | @param PeiServices The pointer to the PEI Services Table. | |
286 | @param StructureSize The pointer to the variable describing size of the input buffer. | |
287 | @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2. | |
288 | ||
289 | @retval EFI_SUCCESS The data was successfully returned. | |
290 | @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to | |
291 | hold the record is returned in StructureSize. | |
292 | ||
293 | **/ | |
294 | EFI_STATUS | |
295 | EFIAPI | |
296 | SecPlatformInformation2 ( | |
297 | IN CONST EFI_PEI_SERVICES **PeiServices, | |
298 | IN OUT UINT64 *StructureSize, | |
299 | OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2 | |
300 | ); | |
301 | ||
302 | #endif |