]>
Commit | Line | Data |
---|---|---|
3e8ad6bd JF |
1 | /** @file\r |
2 | Common header file for MP Initialize Library.\r | |
3 | \r | |
8c61f193 | 4 | Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.<BR>\r |
4c0f6e34 LD |
5 | Copyright (c) 2020, AMD Inc. All rights reserved.<BR>\r |
6 | \r | |
0acd8697 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
3e8ad6bd JF |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #ifndef _MP_LIB_H_\r | |
12 | #define _MP_LIB_H_\r | |
13 | \r | |
14 | #include <PiPei.h>\r | |
15 | \r | |
01acb06c | 16 | #include <Register/Intel/Cpuid.h>\r |
4c0f6e34 | 17 | #include <Register/Amd/Cpuid.h>\r |
01acb06c RN |
18 | #include <Register/Intel/Msr.h>\r |
19 | #include <Register/Intel/LocalApic.h>\r | |
20 | #include <Register/Intel/Microcode.h>\r | |
3e8ad6bd JF |
21 | \r |
22 | #include <Library/MpInitLib.h>\r | |
23 | #include <Library/BaseLib.h>\r | |
24 | #include <Library/BaseMemoryLib.h>\r | |
25 | #include <Library/MemoryAllocationLib.h>\r | |
26 | #include <Library/DebugLib.h>\r | |
27 | #include <Library/LocalApicLib.h>\r | |
28 | #include <Library/CpuLib.h>\r | |
29 | #include <Library/UefiCpuLib.h>\r | |
30 | #include <Library/TimerLib.h>\r | |
31 | #include <Library/SynchronizationLib.h>\r | |
32 | #include <Library/MtrrLib.h>\r | |
33 | #include <Library/HobLib.h>\r | |
d5339c04 | 34 | #include <Library/PcdLib.h>\r |
bce03284 | 35 | #include <Library/MicrocodeLib.h>\r |
b95908e0 | 36 | #include <ConfidentialComputingGuestAttr.h>\r |
3e8ad6bd | 37 | \r |
e2289d19 BS |
38 | #include <Register/Amd/Fam17Msr.h>\r |
39 | #include <Register/Amd/Ghcb.h>\r | |
40 | \r | |
348a34d9 HW |
41 | #include <Guid/MicrocodePatchHob.h>\r |
42 | \r | |
053e878b | 43 | #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')\r |
b8b04307 | 44 | \r |
93ca4c0f JF |
45 | #define CPU_INIT_MP_LIB_HOB_GUID \\r |
46 | { \\r | |
47 | 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \\r | |
48 | }\r | |
49 | \r | |
41be0da5 JF |
50 | //\r |
51 | // The MP data for switch BSP\r | |
52 | //\r | |
053e878b MK |
53 | #define CPU_SWITCH_STATE_IDLE 0\r |
54 | #define CPU_SWITCH_STATE_STORED 1\r | |
55 | #define CPU_SWITCH_STATE_LOADED 2\r | |
41be0da5 | 56 | \r |
d786a172 HW |
57 | //\r |
58 | // Default maximum number of entries to store the microcode patches information\r | |
59 | //\r | |
053e878b | 60 | #define DEFAULT_MAX_MICROCODE_PATCH_NUM 8\r |
d786a172 HW |
61 | \r |
62 | //\r | |
63 | // Data structure for microcode patch information\r | |
64 | //\r | |
65 | typedef struct {\r | |
66 | UINTN Address;\r | |
67 | UINTN Size;\r | |
d786a172 HW |
68 | } MICROCODE_PATCH_INFO;\r |
69 | \r | |
41be0da5 JF |
70 | //\r |
71 | // CPU exchange information for switch BSP\r | |
72 | //\r | |
73 | typedef struct {\r | |
053e878b MK |
74 | UINT8 State; // offset 0\r |
75 | UINTN StackPointer; // offset 4 / 8\r | |
76 | IA32_DESCRIPTOR Gdtr; // offset 8 / 16\r | |
77 | IA32_DESCRIPTOR Idtr; // offset 14 / 26\r | |
41be0da5 JF |
78 | } CPU_EXCHANGE_ROLE_INFO;\r |
79 | \r | |
9ebcf0f4 JF |
80 | //\r |
81 | // AP loop state when APs are in idle state\r | |
82 | // It's value is the same with PcdCpuApLoopMode\r | |
83 | //\r | |
84 | typedef enum {\r | |
85 | ApInHltLoop = 1,\r | |
86 | ApInMwaitLoop = 2,\r | |
87 | ApInRunLoop = 3\r | |
88 | } AP_LOOP_MODE;\r | |
89 | \r | |
e59f8f6b JF |
90 | //\r |
91 | // AP initialization state during APs wakeup\r | |
92 | //\r | |
93 | typedef enum {\r | |
94 | ApInitConfig = 1,\r | |
95 | ApInitReconfig = 2,\r | |
96 | ApInitDone = 3\r | |
97 | } AP_INIT_STATE;\r | |
98 | \r | |
03a1a925 JF |
99 | //\r |
100 | // AP state\r | |
101 | //\r | |
2a5997f8 ED |
102 | // The state transitions for an AP when it process a procedure are:\r |
103 | // Idle ----> Ready ----> Busy ----> Idle\r | |
104 | // [BSP] [AP] [AP]\r | |
105 | //\r | |
03a1a925 JF |
106 | typedef enum {\r |
107 | CpuStateIdle,\r | |
108 | CpuStateReady,\r | |
109 | CpuStateBusy,\r | |
e048ce88 | 110 | CpuStateFinished,\r |
03a1a925 JF |
111 | CpuStateDisabled\r |
112 | } CPU_STATE;\r | |
113 | \r | |
68cb9330 JF |
114 | //\r |
115 | // CPU volatile registers around INIT-SIPI-SIPI\r | |
116 | //\r | |
117 | typedef struct {\r | |
053e878b MK |
118 | UINTN Cr0;\r |
119 | UINTN Cr3;\r | |
120 | UINTN Cr4;\r | |
121 | UINTN Dr0;\r | |
122 | UINTN Dr1;\r | |
123 | UINTN Dr2;\r | |
124 | UINTN Dr3;\r | |
125 | UINTN Dr6;\r | |
126 | UINTN Dr7;\r | |
127 | IA32_DESCRIPTOR Gdtr;\r | |
128 | IA32_DESCRIPTOR Idtr;\r | |
129 | UINT16 Tr;\r | |
68cb9330 JF |
130 | } CPU_VOLATILE_REGISTERS;\r |
131 | \r | |
e59f8f6b JF |
132 | //\r |
133 | // AP related data\r | |
134 | //\r | |
135 | typedef struct {\r | |
053e878b MK |
136 | SPIN_LOCK ApLock;\r |
137 | volatile UINT32 *StartupApSignal;\r | |
138 | volatile UINTN ApFunction;\r | |
139 | volatile UINTN ApFunctionArgument;\r | |
140 | BOOLEAN CpuHealthy;\r | |
141 | volatile CPU_STATE State;\r | |
142 | CPU_VOLATILE_REGISTERS VolatileRegisters;\r | |
143 | BOOLEAN Waiting;\r | |
144 | BOOLEAN *Finished;\r | |
145 | UINT64 ExpectedTime;\r | |
146 | UINT64 CurrentTime;\r | |
147 | UINT64 TotalTime;\r | |
148 | EFI_EVENT WaitEvent;\r | |
149 | UINT32 ProcessorSignature;\r | |
150 | UINT8 PlatformId;\r | |
151 | UINT64 MicrocodeEntryAddr;\r | |
152 | UINT32 MicrocodeRevision;\r | |
e59f8f6b JF |
153 | } CPU_AP_DATA;\r |
154 | \r | |
155 | //\r | |
156 | // Basic CPU information saved in Guided HOB.\r | |
157 | // Because the contents will be shard between PEI and DXE,\r | |
158 | // we need to make sure the each fields offset same in different\r | |
159 | // architecture.\r | |
160 | //\r | |
dd3fa0cd | 161 | #pragma pack (1)\r |
e59f8f6b | 162 | typedef struct {\r |
053e878b MK |
163 | UINT32 InitialApicId;\r |
164 | UINT32 ApicId;\r | |
165 | UINT32 Health;\r | |
166 | UINT64 ApTopOfStack;\r | |
e59f8f6b | 167 | } CPU_INFO_IN_HOB;\r |
dd3fa0cd | 168 | #pragma pack ()\r |
e59f8f6b | 169 | \r |
f7f85d83 JF |
170 | //\r |
171 | // AP reset code information including code address and size,\r | |
172 | // this structure will be shared be C code and assembly code.\r | |
173 | // It is natural aligned by design.\r | |
174 | //\r | |
175 | typedef struct {\r | |
053e878b MK |
176 | UINT8 *RendezvousFunnelAddress;\r |
177 | UINTN ModeEntryOffset;\r | |
178 | UINTN RendezvousFunnelSize;\r | |
179 | UINT8 *RelocateApLoopFuncAddress;\r | |
180 | UINTN RelocateApLoopFuncSize;\r | |
181 | UINTN ModeTransitionOffset;\r | |
182 | UINTN SwitchToRealSize;\r | |
183 | UINTN SwitchToRealOffset;\r | |
184 | UINTN SwitchToRealNoNxOffset;\r | |
185 | UINTN SwitchToRealPM16ModeOffset;\r | |
186 | UINTN SwitchToRealPM16ModeSize;\r | |
f7f85d83 | 187 | } MP_ASSEMBLY_ADDRESS_MAP;\r |
3e8ad6bd | 188 | \r |
053e878b | 189 | typedef struct _CPU_MP_DATA CPU_MP_DATA;\r |
e59f8f6b | 190 | \r |
d94e5f67 JF |
191 | #pragma pack(1)\r |
192 | \r | |
193 | //\r | |
194 | // MP CPU exchange information for AP reset code\r | |
195 | // This structure is required to be packed because fixed field offsets\r | |
196 | // into this structure are used in assembly code in this module\r | |
197 | //\r | |
198 | typedef struct {\r | |
053e878b MK |
199 | UINTN StackStart;\r |
200 | UINTN StackSize;\r | |
201 | UINTN CFunction;\r | |
202 | IA32_DESCRIPTOR GdtrProfile;\r | |
203 | IA32_DESCRIPTOR IdtrProfile;\r | |
204 | UINTN BufferStart;\r | |
205 | UINTN ModeOffset;\r | |
206 | UINTN ApIndex;\r | |
207 | UINTN CodeSegment;\r | |
208 | UINTN DataSegment;\r | |
209 | UINTN EnableExecuteDisable;\r | |
210 | UINTN Cr3;\r | |
211 | UINTN InitFlag;\r | |
212 | CPU_INFO_IN_HOB *CpuInfo;\r | |
213 | UINTN NumApsExecuting;\r | |
214 | CPU_MP_DATA *CpuMpData;\r | |
215 | UINTN InitializeFloatingPointUnitsAddress;\r | |
216 | UINT32 ModeTransitionMemory;\r | |
217 | UINT16 ModeTransitionSegment;\r | |
218 | UINT32 ModeHighMemory;\r | |
219 | UINT16 ModeHighSegment;\r | |
09f69a87 RN |
220 | //\r |
221 | // Enable5LevelPaging indicates whether 5-level paging is enabled in long mode.\r | |
222 | //\r | |
053e878b MK |
223 | BOOLEAN Enable5LevelPaging;\r |
224 | BOOLEAN SevEsIsEnabled;\r | |
9c703bc0 | 225 | BOOLEAN SevSnpIsEnabled;\r |
053e878b | 226 | UINTN GhcbBase;\r |
d4d7c9ad | 227 | BOOLEAN ExtTopoAvail;\r |
d94e5f67 JF |
228 | } MP_CPU_EXCHANGE_INFO;\r |
229 | \r | |
230 | #pragma pack()\r | |
e59f8f6b JF |
231 | \r |
232 | //\r | |
233 | // CPU MP Data save in memory\r | |
234 | //\r | |
235 | struct _CPU_MP_DATA {\r | |
053e878b MK |
236 | UINT64 CpuInfoInHob;\r |
237 | UINT32 CpuCount;\r | |
238 | UINT32 BspNumber;\r | |
e59f8f6b JF |
239 | //\r |
240 | // The above fields data will be passed from PEI to DXE\r | |
241 | // Please make sure the fields offset same in the different\r | |
242 | // architecture.\r | |
243 | //\r | |
053e878b MK |
244 | SPIN_LOCK MpLock;\r |
245 | UINTN Buffer;\r | |
246 | UINTN CpuApStackSize;\r | |
247 | MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r | |
248 | UINTN WakeupBuffer;\r | |
249 | UINTN WakeupBufferHigh;\r | |
250 | UINTN BackupBuffer;\r | |
251 | UINTN BackupBufferSize;\r | |
252 | \r | |
253 | volatile UINT32 FinishedCount;\r | |
254 | UINT32 RunningCount;\r | |
255 | BOOLEAN SingleThread;\r | |
256 | EFI_AP_PROCEDURE Procedure;\r | |
257 | VOID *ProcArguments;\r | |
258 | BOOLEAN *Finished;\r | |
259 | UINT64 ExpectedTime;\r | |
260 | UINT64 CurrentTime;\r | |
261 | UINT64 TotalTime;\r | |
262 | EFI_EVENT WaitEvent;\r | |
263 | UINTN **FailedCpuList;\r | |
264 | \r | |
265 | AP_INIT_STATE InitFlag;\r | |
266 | BOOLEAN SwitchBspFlag;\r | |
267 | UINTN NewBspNumber;\r | |
268 | CPU_EXCHANGE_ROLE_INFO BSPInfo;\r | |
269 | CPU_EXCHANGE_ROLE_INFO APInfo;\r | |
270 | MTRR_SETTINGS MtrrTable;\r | |
271 | UINT8 ApLoopMode;\r | |
272 | UINT8 ApTargetCState;\r | |
273 | UINT16 PmCodeSegment;\r | |
274 | UINT16 Pm16CodeSegment;\r | |
275 | CPU_AP_DATA *CpuData;\r | |
276 | volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;\r | |
277 | \r | |
278 | UINT32 CurrentTimerCount;\r | |
279 | UINTN DivideValue;\r | |
280 | UINT8 Vector;\r | |
281 | BOOLEAN PeriodicMode;\r | |
282 | BOOLEAN TimerInterruptState;\r | |
283 | UINT64 MicrocodePatchAddress;\r | |
284 | UINT64 MicrocodePatchRegionSize;\r | |
2a089134 | 285 | \r |
58942277 ED |
286 | //\r |
287 | // Whether need to use Init-Sipi-Sipi to wake up the APs.\r | |
288 | // Two cases need to set this value to TRUE. One is in HLT\r | |
289 | // loop mode, the other is resume from S3 which loop mode\r | |
e23d9c3e | 290 | // will be hardcode change to HLT mode by PiSmmCpuDxeSmm\r |
58942277 ED |
291 | // driver.\r |
292 | //\r | |
053e878b | 293 | BOOLEAN WakeUpByInitSipiSipi;\r |
e88a5b98 | 294 | \r |
053e878b | 295 | BOOLEAN SevEsIsEnabled;\r |
9c703bc0 | 296 | BOOLEAN SevSnpIsEnabled;\r |
053e878b MK |
297 | UINTN SevEsAPBuffer;\r |
298 | UINTN SevEsAPResetStackStart;\r | |
299 | CPU_MP_DATA *NewCpuMpData;\r | |
7b7508ad | 300 | \r |
053e878b | 301 | UINT64 GhcbBase;\r |
e59f8f6b | 302 | };\r |
93ca4c0f | 303 | \r |
053e878b MK |
304 | #define AP_SAFE_STACK_SIZE 128\r |
305 | #define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE\r | |
7b7508ad TL |
306 | \r |
307 | #pragma pack(1)\r | |
308 | \r | |
309 | typedef struct {\r | |
053e878b MK |
310 | UINT8 InsnBuffer[8];\r |
311 | UINT16 Rip;\r | |
312 | UINT16 Segment;\r | |
7b7508ad TL |
313 | } SEV_ES_AP_JMP_FAR;\r |
314 | \r | |
315 | #pragma pack()\r | |
316 | \r | |
317 | /**\r | |
318 | Assembly code to move an AP from long mode to real mode.\r | |
319 | \r | |
320 | Move an AP from long mode to real mode in preparation to invoking\r | |
321 | the reset vector. This is used for SEV-ES guests where a hypervisor\r | |
322 | is not allowed to set the CS and RIP to point to the reset vector.\r | |
323 | \r | |
324 | @param[in] BufferStart The reset vector target.\r | |
325 | @param[in] Code16 16-bit protected mode code segment value.\r | |
326 | @param[in] Code32 32-bit protected mode code segment value.\r | |
327 | @param[in] StackStart The start of a stack to be used for transitioning\r | |
328 | from long mode to real mode.\r | |
329 | **/\r | |
330 | typedef\r | |
e2289d19 | 331 | VOID\r |
053e878b | 332 | (EFIAPI AP_RESET)(\r |
7b7508ad TL |
333 | IN UINTN BufferStart,\r |
334 | IN UINT16 Code16,\r | |
335 | IN UINT16 Code32,\r | |
336 | IN UINTN StackStart\r | |
337 | );\r | |
338 | \r | |
053e878b | 339 | extern EFI_GUID mCpuInitMpLibHobGuid;\r |
93ca4c0f | 340 | \r |
76157021 JF |
341 | /**\r |
342 | Assembly code to place AP into safe loop mode.\r | |
343 | \r | |
344 | Place AP into targeted C-State if MONITOR is supported, otherwise\r | |
345 | place AP into hlt state.\r | |
346 | Place AP in protected mode if the current is long mode. Due to AP maybe\r | |
347 | wakeup by some hardware event. It could avoid accessing page table that\r | |
348 | may not available during booting to OS.\r | |
349 | \r | |
350 | @param[in] MwaitSupport TRUE indicates MONITOR is supported.\r | |
351 | FALSE indicates MONITOR is not supported.\r | |
352 | @param[in] ApTargetCState Target C-State value.\r | |
353 | @param[in] PmCodeSegment Protected mode code segment value.\r | |
354 | **/\r | |
355 | typedef\r | |
e2289d19 | 356 | VOID\r |
053e878b | 357 | (EFIAPI *ASM_RELOCATE_AP_LOOP)(\r |
76157021 JF |
358 | IN BOOLEAN MwaitSupport,\r |
359 | IN UINTN ApTargetCState,\r | |
bf2786dc | 360 | IN UINTN PmCodeSegment,\r |
9f91cb01 | 361 | IN UINTN TopOfApStack,\r |
20da7ca4 TL |
362 | IN UINTN NumberToFinish,\r |
363 | IN UINTN Pm16CodeSegment,\r | |
364 | IN UINTN SevEsAPJumpTable,\r | |
365 | IN UINTN WakeupBuffer\r | |
76157021 | 366 | );\r |
f7f85d83 JF |
367 | \r |
368 | /**\r | |
369 | Assembly code to get starting address and size of the rendezvous entry for APs.\r | |
370 | Information for fixing a jump instruction in the code is also returned.\r | |
371 | \r | |
372 | @param[out] AddressMap Output buffer for address map information.\r | |
373 | **/\r | |
374 | VOID\r | |
375 | EFIAPI\r | |
376 | AsmGetAddressMap (\r | |
053e878b | 377 | OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap\r |
f7f85d83 JF |
378 | );\r |
379 | \r | |
41be0da5 JF |
380 | /**\r |
381 | This function is called by both the BSP and the AP which is to become the BSP to\r | |
382 | Exchange execution context including stack between them. After return from this\r | |
383 | function, the BSP becomes AP and the AP becomes the BSP.\r | |
384 | \r | |
385 | @param[in] MyInfo Pointer to buffer holding the exchanging information for the executing processor.\r | |
386 | @param[in] OthersInfo Pointer to buffer holding the exchanging information for the peer.\r | |
387 | \r | |
388 | **/\r | |
389 | VOID\r | |
390 | EFIAPI\r | |
391 | AsmExchangeRole (\r | |
053e878b MK |
392 | IN CPU_EXCHANGE_ROLE_INFO *MyInfo,\r |
393 | IN CPU_EXCHANGE_ROLE_INFO *OthersInfo\r | |
41be0da5 JF |
394 | );\r |
395 | \r | |
93ca4c0f JF |
396 | /**\r |
397 | Get the pointer to CPU MP Data structure.\r | |
398 | \r | |
399 | @return The pointer to CPU MP Data structure.\r | |
400 | **/\r | |
401 | CPU_MP_DATA *\r | |
402 | GetCpuMpData (\r | |
403 | VOID\r | |
404 | );\r | |
405 | \r | |
406 | /**\r | |
407 | Save the pointer to CPU MP Data structure.\r | |
408 | \r | |
409 | @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.\r | |
410 | **/\r | |
411 | VOID\r | |
412 | SaveCpuMpData (\r | |
053e878b | 413 | IN CPU_MP_DATA *CpuMpData\r |
93ca4c0f JF |
414 | );\r |
415 | \r | |
ed66e0e3 | 416 | /**\r |
a6b3d753 | 417 | Get available system memory below 1MB by specified size.\r |
ed66e0e3 | 418 | \r |
a6b3d753 SZ |
419 | @param[in] WakeupBufferSize Wakeup buffer size required\r |
420 | \r | |
421 | @retval other Return wakeup buffer address below 1MB.\r | |
422 | @retval -1 Cannot find free memory below 1MB.\r | |
ed66e0e3 | 423 | **/\r |
a6b3d753 SZ |
424 | UINTN\r |
425 | GetWakeupBuffer (\r | |
053e878b | 426 | IN UINTN WakeupBufferSize\r |
ed66e0e3 JF |
427 | );\r |
428 | \r | |
f32bfe6d JW |
429 | /**\r |
430 | Get available EfiBootServicesCode memory below 4GB by specified size.\r | |
431 | \r | |
432 | This buffer is required to safely transfer AP from real address mode to\r | |
433 | protected mode or long mode, due to the fact that the buffer returned by\r | |
434 | GetWakeupBuffer() may be marked as non-executable.\r | |
435 | \r | |
436 | @param[in] BufferSize Wakeup transition buffer size.\r | |
437 | \r | |
438 | @retval other Return wakeup transition buffer address below 4GB.\r | |
439 | @retval 0 Cannot find free memory below 4GB.\r | |
440 | **/\r | |
441 | UINTN\r | |
442 | GetModeTransitionBuffer (\r | |
053e878b | 443 | IN UINTN BufferSize\r |
f32bfe6d JW |
444 | );\r |
445 | \r | |
7b7508ad TL |
446 | /**\r |
447 | Return the address of the SEV-ES AP jump table.\r | |
448 | \r | |
449 | This buffer is required in order for an SEV-ES guest to transition from\r | |
450 | UEFI into an OS.\r | |
451 | \r | |
452 | @return Return SEV-ES AP jump table buffer\r | |
453 | **/\r | |
454 | UINTN\r | |
455 | GetSevEsAPMemory (\r | |
456 | VOID\r | |
457 | );\r | |
458 | \r | |
96f5920d JF |
459 | /**\r |
460 | This function will be called by BSP to wakeup AP.\r | |
461 | \r | |
462 | @param[in] CpuMpData Pointer to CPU MP Data\r | |
463 | @param[in] Broadcast TRUE: Send broadcast IPI to all APs\r | |
464 | FALSE: Send IPI to AP by ApicId\r | |
465 | @param[in] ProcessorNumber The handle number of specified processor\r | |
466 | @param[in] Procedure The function to be invoked by AP\r | |
467 | @param[in] ProcedureArgument The argument to be passed into AP function\r | |
cf4e79e4 | 468 | @param[in] WakeUpDisabledAps Whether need to wake up disabled APs in broadcast mode.\r |
96f5920d JF |
469 | **/\r |
470 | VOID\r | |
471 | WakeUpAP (\r | |
053e878b MK |
472 | IN CPU_MP_DATA *CpuMpData,\r |
473 | IN BOOLEAN Broadcast,\r | |
474 | IN UINTN ProcessorNumber,\r | |
475 | IN EFI_AP_PROCEDURE Procedure OPTIONAL,\r | |
476 | IN VOID *ProcedureArgument OPTIONAL,\r | |
477 | IN BOOLEAN WakeUpDisabledAps OPTIONAL\r | |
96f5920d JF |
478 | );\r |
479 | \r | |
93ca4c0f JF |
480 | /**\r |
481 | Initialize global data for MP support.\r | |
482 | \r | |
483 | @param[in] CpuMpData The pointer to CPU MP Data structure.\r | |
484 | **/\r | |
485 | VOID\r | |
486 | InitMpGlobalData (\r | |
053e878b | 487 | IN CPU_MP_DATA *CpuMpData\r |
93ca4c0f JF |
488 | );\r |
489 | \r | |
86efe976 JF |
490 | /**\r |
491 | Worker function to execute a caller provided function on all enabled APs.\r | |
492 | \r | |
493 | @param[in] Procedure A pointer to the function to be run on\r | |
494 | enabled APs of the system.\r | |
495 | @param[in] SingleThread If TRUE, then all the enabled APs execute\r | |
496 | the function specified by Procedure one by\r | |
497 | one, in ascending order of processor handle\r | |
498 | number. If FALSE, then all the enabled APs\r | |
499 | execute the function specified by Procedure\r | |
500 | simultaneously.\r | |
ee0c39fa | 501 | @param[in] ExcludeBsp Whether let BSP also trig this task.\r |
86efe976 JF |
502 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r |
503 | service.\r | |
367284e7 | 504 | @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r |
86efe976 JF |
505 | APs to return from Procedure, either for\r |
506 | blocking or non-blocking mode.\r | |
507 | @param[in] ProcedureArgument The parameter passed into Procedure for\r | |
508 | all APs.\r | |
509 | @param[out] FailedCpuList If all APs finish successfully, then its\r | |
510 | content is set to NULL. If not all APs\r | |
511 | finish before timeout expires, then its\r | |
512 | content is set to address of the buffer\r | |
513 | holding handle numbers of the failed APs.\r | |
514 | \r | |
515 | @retval EFI_SUCCESS In blocking mode, all APs have finished before\r | |
516 | the timeout expired.\r | |
517 | @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r | |
518 | to all enabled APs.\r | |
519 | @retval others Failed to Startup all APs.\r | |
520 | \r | |
521 | **/\r | |
522 | EFI_STATUS\r | |
ee0c39fa | 523 | StartupAllCPUsWorker (\r |
053e878b MK |
524 | IN EFI_AP_PROCEDURE Procedure,\r |
525 | IN BOOLEAN SingleThread,\r | |
526 | IN BOOLEAN ExcludeBsp,\r | |
527 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
528 | IN UINTN TimeoutInMicroseconds,\r | |
529 | IN VOID *ProcedureArgument OPTIONAL,\r | |
530 | OUT UINTN **FailedCpuList OPTIONAL\r | |
86efe976 JF |
531 | );\r |
532 | \r | |
20ae5774 JF |
533 | /**\r |
534 | Worker function to let the caller get one enabled AP to execute a caller-provided\r | |
535 | function.\r | |
536 | \r | |
537 | @param[in] Procedure A pointer to the function to be run on\r | |
538 | enabled APs of the system.\r | |
539 | @param[in] ProcessorNumber The handle number of the AP.\r | |
540 | @param[in] WaitEvent The event created by the caller with CreateEvent()\r | |
541 | service.\r | |
367284e7 | 542 | @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r |
20ae5774 JF |
543 | APs to return from Procedure, either for\r |
544 | blocking or non-blocking mode.\r | |
545 | @param[in] ProcedureArgument The parameter passed into Procedure for\r | |
546 | all APs.\r | |
547 | @param[out] Finished If AP returns from Procedure before the\r | |
548 | timeout expires, its content is set to TRUE.\r | |
549 | Otherwise, the value is set to FALSE.\r | |
550 | \r | |
551 | @retval EFI_SUCCESS In blocking mode, specified AP finished before\r | |
552 | the timeout expires.\r | |
553 | @retval others Failed to Startup AP.\r | |
554 | \r | |
555 | **/\r | |
556 | EFI_STATUS\r | |
557 | StartupThisAPWorker (\r | |
053e878b MK |
558 | IN EFI_AP_PROCEDURE Procedure,\r |
559 | IN UINTN ProcessorNumber,\r | |
560 | IN EFI_EVENT WaitEvent OPTIONAL,\r | |
561 | IN UINTN TimeoutInMicroseconds,\r | |
562 | IN VOID *ProcedureArgument OPTIONAL,\r | |
563 | OUT BOOLEAN *Finished OPTIONAL\r | |
20ae5774 JF |
564 | );\r |
565 | \r | |
41be0da5 JF |
566 | /**\r |
567 | Worker function to switch the requested AP to be the BSP from that point onward.\r | |
568 | \r | |
569 | @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.\r | |
570 | @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r | |
571 | enabled AP. Otherwise, it will be disabled.\r | |
572 | \r | |
573 | @retval EFI_SUCCESS BSP successfully switched.\r | |
7367cc6c | 574 | @retval others Failed to switch BSP.\r |
41be0da5 JF |
575 | \r |
576 | **/\r | |
577 | EFI_STATUS\r | |
578 | SwitchBSPWorker (\r | |
053e878b MK |
579 | IN UINTN ProcessorNumber,\r |
580 | IN BOOLEAN EnableOldBSP\r | |
41be0da5 JF |
581 | );\r |
582 | \r | |
e37109bc JF |
583 | /**\r |
584 | Worker function to let the caller enable or disable an AP from this point onward.\r | |
585 | This service may only be called from the BSP.\r | |
586 | \r | |
587 | @param[in] ProcessorNumber The handle number of AP.\r | |
588 | @param[in] EnableAP Specifies the new state for the processor for\r | |
589 | enabled, FALSE for disabled.\r | |
590 | @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r | |
591 | the new health status of the AP.\r | |
592 | \r | |
593 | @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r | |
594 | @retval others Failed to Enable/Disable AP.\r | |
595 | \r | |
596 | **/\r | |
597 | EFI_STATUS\r | |
598 | EnableDisableApWorker (\r | |
053e878b MK |
599 | IN UINTN ProcessorNumber,\r |
600 | IN BOOLEAN EnableAP,\r | |
601 | IN UINT32 *HealthFlag OPTIONAL\r | |
e37109bc JF |
602 | );\r |
603 | \r | |
93ca4c0f JF |
604 | /**\r |
605 | Get pointer to CPU MP Data structure from GUIDed HOB.\r | |
606 | \r | |
607 | @return The pointer to CPU MP Data structure.\r | |
608 | **/\r | |
609 | CPU_MP_DATA *\r | |
610 | GetCpuMpDataFromGuidedHob (\r | |
611 | VOID\r | |
612 | );\r | |
08085f08 JF |
613 | \r |
614 | /** Checks status of specified AP.\r | |
615 | \r | |
616 | This function checks whether the specified AP has finished the task assigned\r | |
617 | by StartupThisAP(), and whether timeout expires.\r | |
618 | \r | |
619 | @param[in] ProcessorNumber The handle number of processor.\r | |
620 | \r | |
621 | @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().\r | |
622 | @retval EFI_TIMEOUT The timeout expires.\r | |
623 | @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.\r | |
624 | **/\r | |
625 | EFI_STATUS\r | |
626 | CheckThisAP (\r | |
053e878b | 627 | IN UINTN ProcessorNumber\r |
08085f08 JF |
628 | );\r |
629 | \r | |
630 | /**\r | |
631 | Checks status of all APs.\r | |
632 | \r | |
633 | This function checks whether all APs have finished task assigned by StartupAllAPs(),\r | |
634 | and whether timeout expires.\r | |
635 | \r | |
636 | @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().\r | |
637 | @retval EFI_TIMEOUT The timeout expires.\r | |
638 | @retval EFI_NOT_READY APs have not finished task and timeout has not expired.\r | |
639 | **/\r | |
640 | EFI_STATUS\r | |
641 | CheckAllAPs (\r | |
642 | VOID\r | |
643 | );\r | |
644 | \r | |
645 | /**\r | |
646 | Checks APs status and updates APs status if needed.\r | |
647 | \r | |
648 | **/\r | |
649 | VOID\r | |
650 | CheckAndUpdateApsStatus (\r | |
651 | VOID\r | |
652 | );\r | |
653 | \r | |
94f63c76 JF |
654 | /**\r |
655 | Detect whether specified processor can find matching microcode patch and load it.\r | |
656 | \r | |
e1ed5573 HW |
657 | @param[in] CpuMpData The pointer to CPU MP Data structure.\r |
658 | @param[in] ProcessorNumber The handle number of the processor. The range is\r | |
659 | from 0 to the total number of logical processors\r | |
660 | minus 1.\r | |
94f63c76 JF |
661 | **/\r |
662 | VOID\r | |
663 | MicrocodeDetect (\r | |
053e878b MK |
664 | IN CPU_MP_DATA *CpuMpData,\r |
665 | IN UINTN ProcessorNumber\r | |
94f63c76 JF |
666 | );\r |
667 | \r | |
d786a172 | 668 | /**\r |
dd017041 | 669 | Shadow the required microcode patches data into memory.\r |
d786a172 HW |
670 | \r |
671 | @param[in, out] CpuMpData The pointer to CPU MP Data structure.\r | |
672 | **/\r | |
673 | VOID\r | |
dd017041 | 674 | ShadowMicrocodeUpdatePatch (\r |
053e878b | 675 | IN OUT CPU_MP_DATA *CpuMpData\r |
d786a172 HW |
676 | );\r |
677 | \r | |
348a34d9 HW |
678 | /**\r |
679 | Get the cached microcode patch base address and size from the microcode patch\r | |
680 | information cache HOB.\r | |
681 | \r | |
682 | @param[out] Address Base address of the microcode patches data.\r | |
683 | It will be updated if the microcode patch\r | |
684 | information cache HOB is found.\r | |
685 | @param[out] RegionSize Size of the microcode patches data.\r | |
686 | It will be updated if the microcode patch\r | |
687 | information cache HOB is found.\r | |
688 | \r | |
689 | @retval TRUE The microcode patch information cache HOB is found.\r | |
690 | @retval FALSE The microcode patch information cache HOB is not found.\r | |
691 | \r | |
692 | **/\r | |
693 | BOOLEAN\r | |
694 | GetMicrocodePatchInfoFromHob (\r | |
053e878b MK |
695 | UINT64 *Address,\r |
696 | UINT64 *RegionSize\r | |
348a34d9 HW |
697 | );\r |
698 | \r | |
4d3314f6 JF |
699 | /**\r |
700 | Detect whether Mwait-monitor feature is supported.\r | |
701 | \r | |
702 | @retval TRUE Mwait-monitor feature is supported.\r | |
703 | @retval FALSE Mwait-monitor feature is not supported.\r | |
704 | **/\r | |
705 | BOOLEAN\r | |
706 | IsMwaitSupport (\r | |
707 | VOID\r | |
708 | );\r | |
709 | \r | |
43c9fdcc JF |
710 | /**\r |
711 | Enable Debug Agent to support source debugging on AP function.\r | |
712 | \r | |
713 | **/\r | |
714 | VOID\r | |
715 | EnableDebugAgent (\r | |
716 | VOID\r | |
717 | );\r | |
718 | \r | |
e1ed5573 HW |
719 | /**\r |
720 | Find the current Processor number by APIC ID.\r | |
721 | \r | |
722 | @param[in] CpuMpData Pointer to PEI CPU MP Data\r | |
723 | @param[out] ProcessorNumber Return the pocessor number found\r | |
724 | \r | |
725 | @retval EFI_SUCCESS ProcessorNumber is found and returned.\r | |
726 | @retval EFI_NOT_FOUND ProcessorNumber is not found.\r | |
727 | **/\r | |
728 | EFI_STATUS\r | |
729 | GetProcessorNumber (\r | |
053e878b MK |
730 | IN CPU_MP_DATA *CpuMpData,\r |
731 | OUT UINTN *ProcessorNumber\r | |
e1ed5573 HW |
732 | );\r |
733 | \r | |
c788c2b1 SF |
734 | /**\r |
735 | This funtion will try to invoke platform specific microcode shadow logic to\r | |
736 | relocate microcode update patches into memory.\r | |
737 | \r | |
4ac82ea1 | 738 | @param[in, out] CpuMpData The pointer to CPU MP Data structure.\r |
c788c2b1 SF |
739 | \r |
740 | @retval EFI_SUCCESS Shadow microcode success.\r | |
741 | @retval EFI_OUT_OF_RESOURCES No enough resource to complete the operation.\r | |
742 | @retval EFI_UNSUPPORTED Can't find platform specific microcode shadow\r | |
743 | PPI/Protocol.\r | |
744 | **/\r | |
745 | EFI_STATUS\r | |
746 | PlatformShadowMicrocode (\r | |
053e878b | 747 | IN OUT CPU_MP_DATA *CpuMpData\r |
c788c2b1 SF |
748 | );\r |
749 | \r | |
e2289d19 BS |
750 | /**\r |
751 | Allocate the SEV-ES AP jump table buffer.\r | |
752 | \r | |
753 | @param[in, out] CpuMpData The pointer to CPU MP Data structure.\r | |
754 | **/\r | |
755 | VOID\r | |
756 | AllocateSevEsAPMemory (\r | |
757 | IN OUT CPU_MP_DATA *CpuMpData\r | |
758 | );\r | |
759 | \r | |
760 | /**\r | |
761 | Program the SEV-ES AP jump table buffer.\r | |
762 | \r | |
763 | @param[in] SipiVector The SIPI vector used for the AP Reset\r | |
764 | **/\r | |
765 | VOID\r | |
766 | SetSevEsJumpTable (\r | |
767 | IN UINTN SipiVector\r | |
768 | );\r | |
769 | \r | |
770 | /**\r | |
771 | The function puts the AP in halt loop.\r | |
772 | \r | |
773 | @param[in] CpuMpData The pointer to CPU MP Data structure.\r | |
774 | **/\r | |
775 | VOID\r | |
776 | SevEsPlaceApHlt (\r | |
777 | CPU_MP_DATA *CpuMpData\r | |
778 | );\r | |
779 | \r | |
b95908e0 BS |
780 | /**\r |
781 | Check if the specified confidential computing attribute is active.\r | |
782 | \r | |
783 | @retval TRUE The specified Attr is active.\r | |
784 | @retval FALSE The specified Attr is not active.\r | |
785 | **/\r | |
786 | BOOLEAN\r | |
787 | EFIAPI\r | |
788 | ConfidentialComputingGuestHas (\r | |
789 | CONFIDENTIAL_COMPUTING_GUEST_ATTR Attr\r | |
790 | );\r | |
791 | \r | |
d4d7c9ad MR |
792 | /**\r |
793 | The function fills the exchange data for the AP.\r | |
794 | \r | |
795 | @param[in] ExchangeInfo The pointer to CPU Exchange Data structure\r | |
796 | **/\r | |
797 | VOID\r | |
798 | FillExchangeInfoDataSevEs (\r | |
799 | IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo\r | |
800 | );\r | |
801 | \r | |
3e8ad6bd | 802 | #endif\r |