]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/MpInitLib/MpLib.h
SecurityPkg/SecureBootConfigDxe: Handle lack of STR_SIGNATURE_* tokens
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.h
CommitLineData
3e8ad6bd
JF
1/** @file\r
2 Common header file for MP Initialize Library.\r
3\r
c934a0a5 4 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
3e8ad6bd
JF
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#ifndef _MP_LIB_H_\r
16#define _MP_LIB_H_\r
17\r
18#include <PiPei.h>\r
19\r
20#include <Register/Cpuid.h>\r
21#include <Register/Msr.h>\r
22#include <Register/LocalApic.h>\r
23#include <Register/Microcode.h>\r
24\r
25#include <Library/MpInitLib.h>\r
26#include <Library/BaseLib.h>\r
27#include <Library/BaseMemoryLib.h>\r
28#include <Library/MemoryAllocationLib.h>\r
29#include <Library/DebugLib.h>\r
30#include <Library/LocalApicLib.h>\r
31#include <Library/CpuLib.h>\r
32#include <Library/UefiCpuLib.h>\r
33#include <Library/TimerLib.h>\r
34#include <Library/SynchronizationLib.h>\r
35#include <Library/MtrrLib.h>\r
36#include <Library/HobLib.h>\r
37\r
b8b04307
JF
38#define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')\r
39\r
93ca4c0f
JF
40#define CPU_INIT_MP_LIB_HOB_GUID \\r
41 { \\r
42 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \\r
43 }\r
44\r
41be0da5
JF
45//\r
46// The MP data for switch BSP\r
47//\r
48#define CPU_SWITCH_STATE_IDLE 0\r
49#define CPU_SWITCH_STATE_STORED 1\r
50#define CPU_SWITCH_STATE_LOADED 2\r
51\r
52//\r
53// CPU exchange information for switch BSP\r
54//\r
55typedef struct {\r
56 UINT8 State; // offset 0\r
57 UINTN StackPointer; // offset 4 / 8\r
58 IA32_DESCRIPTOR Gdtr; // offset 8 / 16\r
59 IA32_DESCRIPTOR Idtr; // offset 14 / 26\r
60} CPU_EXCHANGE_ROLE_INFO;\r
61\r
9ebcf0f4
JF
62//\r
63// AP loop state when APs are in idle state\r
64// It's value is the same with PcdCpuApLoopMode\r
65//\r
66typedef enum {\r
67 ApInHltLoop = 1,\r
68 ApInMwaitLoop = 2,\r
69 ApInRunLoop = 3\r
70} AP_LOOP_MODE;\r
71\r
e59f8f6b
JF
72//\r
73// AP initialization state during APs wakeup\r
74//\r
75typedef enum {\r
76 ApInitConfig = 1,\r
77 ApInitReconfig = 2,\r
78 ApInitDone = 3\r
79} AP_INIT_STATE;\r
80\r
03a1a925
JF
81//\r
82// AP state\r
83//\r
84typedef enum {\r
85 CpuStateIdle,\r
86 CpuStateReady,\r
87 CpuStateBusy,\r
88 CpuStateFinished,\r
89 CpuStateDisabled\r
90} CPU_STATE;\r
91\r
68cb9330
JF
92//\r
93// CPU volatile registers around INIT-SIPI-SIPI\r
94//\r
95typedef struct {\r
96 UINTN Cr0;\r
97 UINTN Cr3;\r
98 UINTN Cr4;\r
99 UINTN Dr0;\r
100 UINTN Dr1;\r
101 UINTN Dr2;\r
102 UINTN Dr3;\r
103 UINTN Dr6;\r
104 UINTN Dr7;\r
105} CPU_VOLATILE_REGISTERS;\r
106\r
e59f8f6b
JF
107//\r
108// AP related data\r
109//\r
110typedef struct {\r
111 SPIN_LOCK ApLock;\r
112 volatile UINT32 *StartupApSignal;\r
113 volatile UINTN ApFunction;\r
114 volatile UINTN ApFunctionArgument;\r
e59f8f6b 115 BOOLEAN CpuHealthy;\r
03a1a925 116 volatile CPU_STATE State;\r
68cb9330 117 CPU_VOLATILE_REGISTERS VolatileRegisters;\r
e59f8f6b
JF
118 BOOLEAN Waiting;\r
119 BOOLEAN *Finished;\r
120 UINT64 ExpectedTime;\r
121 UINT64 CurrentTime;\r
122 UINT64 TotalTime;\r
123 EFI_EVENT WaitEvent;\r
124} CPU_AP_DATA;\r
125\r
126//\r
127// Basic CPU information saved in Guided HOB.\r
128// Because the contents will be shard between PEI and DXE,\r
129// we need to make sure the each fields offset same in different\r
130// architecture.\r
131//\r
dd3fa0cd 132#pragma pack (1)\r
e59f8f6b
JF
133typedef struct {\r
134 UINT32 InitialApicId;\r
135 UINT32 ApicId;\r
136 UINT32 Health;\r
dd3fa0cd 137 UINT64 ApTopOfStack;\r
e59f8f6b 138} CPU_INFO_IN_HOB;\r
dd3fa0cd 139#pragma pack ()\r
e59f8f6b 140\r
f7f85d83
JF
141//\r
142// AP reset code information including code address and size,\r
143// this structure will be shared be C code and assembly code.\r
144// It is natural aligned by design.\r
145//\r
146typedef struct {\r
147 UINT8 *RendezvousFunnelAddress;\r
148 UINTN ModeEntryOffset;\r
149 UINTN RendezvousFunnelSize;\r
150 UINT8 *RelocateApLoopFuncAddress;\r
151 UINTN RelocateApLoopFuncSize;\r
152} MP_ASSEMBLY_ADDRESS_MAP;\r
3e8ad6bd 153\r
e59f8f6b
JF
154typedef struct _CPU_MP_DATA CPU_MP_DATA;\r
155\r
d94e5f67
JF
156#pragma pack(1)\r
157\r
158//\r
159// MP CPU exchange information for AP reset code\r
160// This structure is required to be packed because fixed field offsets\r
161// into this structure are used in assembly code in this module\r
162//\r
163typedef struct {\r
164 UINTN Lock;\r
165 UINTN StackStart;\r
166 UINTN StackSize;\r
167 UINTN CFunction;\r
168 IA32_DESCRIPTOR GdtrProfile;\r
169 IA32_DESCRIPTOR IdtrProfile;\r
170 UINTN BufferStart;\r
171 UINTN ModeOffset;\r
172 UINTN NumApsExecuting;\r
173 UINTN CodeSegment;\r
174 UINTN DataSegment;\r
5c66d125 175 UINTN EnableExecuteDisable;\r
d94e5f67 176 UINTN Cr3;\r
46d4b885
JF
177 UINTN InitFlag;\r
178 CPU_INFO_IN_HOB *CpuInfo;\r
e59f8f6b 179 CPU_MP_DATA *CpuMpData;\r
3b2928b4 180 UINTN InitializeFloatingPointUnitsAddress;\r
d94e5f67
JF
181} MP_CPU_EXCHANGE_INFO;\r
182\r
183#pragma pack()\r
e59f8f6b
JF
184\r
185//\r
186// CPU MP Data save in memory\r
187//\r
188struct _CPU_MP_DATA {\r
189 UINT64 CpuInfoInHob;\r
190 UINT32 CpuCount;\r
191 UINT32 BspNumber;\r
192 //\r
193 // The above fields data will be passed from PEI to DXE\r
194 // Please make sure the fields offset same in the different\r
195 // architecture.\r
196 //\r
197 SPIN_LOCK MpLock;\r
198 UINTN Buffer;\r
199 UINTN CpuApStackSize;\r
200 MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r
201 UINTN WakeupBuffer;\r
202 UINTN BackupBuffer;\r
203 UINTN BackupBufferSize;\r
e59f8f6b
JF
204\r
205 volatile UINT32 StartCount;\r
206 volatile UINT32 FinishedCount;\r
207 volatile UINT32 RunningCount;\r
208 BOOLEAN SingleThread;\r
209 EFI_AP_PROCEDURE Procedure;\r
210 VOID *ProcArguments;\r
211 BOOLEAN *Finished;\r
212 UINT64 ExpectedTime;\r
213 UINT64 CurrentTime;\r
214 UINT64 TotalTime;\r
215 EFI_EVENT WaitEvent;\r
216 UINTN **FailedCpuList;\r
217\r
218 AP_INIT_STATE InitFlag;\r
219 BOOLEAN X2ApicEnable;\r
41be0da5 220 BOOLEAN SwitchBspFlag;\r
b3775af2 221 UINTN NewBspNumber;\r
41be0da5
JF
222 CPU_EXCHANGE_ROLE_INFO BSPInfo;\r
223 CPU_EXCHANGE_ROLE_INFO APInfo;\r
e59f8f6b
JF
224 MTRR_SETTINGS MtrrTable;\r
225 UINT8 ApLoopMode;\r
226 UINT8 ApTargetCState;\r
227 UINT16 PmCodeSegment;\r
228 CPU_AP_DATA *CpuData;\r
229 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;\r
ffab2442
JF
230\r
231 UINT32 CurrentTimerCount;\r
232 UINTN DivideValue;\r
233 UINT8 Vector;\r
234 BOOLEAN PeriodicMode;\r
235 BOOLEAN TimerInterruptState;\r
e59f8f6b 236};\r
93ca4c0f
JF
237\r
238extern EFI_GUID mCpuInitMpLibHobGuid;\r
239\r
76157021
JF
240/**\r
241 Assembly code to place AP into safe loop mode.\r
242\r
243 Place AP into targeted C-State if MONITOR is supported, otherwise\r
244 place AP into hlt state.\r
245 Place AP in protected mode if the current is long mode. Due to AP maybe\r
246 wakeup by some hardware event. It could avoid accessing page table that\r
247 may not available during booting to OS.\r
248\r
249 @param[in] MwaitSupport TRUE indicates MONITOR is supported.\r
250 FALSE indicates MONITOR is not supported.\r
251 @param[in] ApTargetCState Target C-State value.\r
252 @param[in] PmCodeSegment Protected mode code segment value.\r
253**/\r
254typedef\r
255VOID\r
256(EFIAPI * ASM_RELOCATE_AP_LOOP) (\r
257 IN BOOLEAN MwaitSupport,\r
258 IN UINTN ApTargetCState,\r
bf2786dc 259 IN UINTN PmCodeSegment,\r
9f91cb01
JF
260 IN UINTN TopOfApStack,\r
261 IN UINTN NumberToFinish\r
76157021 262 );\r
f7f85d83
JF
263\r
264/**\r
265 Assembly code to get starting address and size of the rendezvous entry for APs.\r
266 Information for fixing a jump instruction in the code is also returned.\r
267\r
268 @param[out] AddressMap Output buffer for address map information.\r
269**/\r
270VOID\r
271EFIAPI\r
272AsmGetAddressMap (\r
273 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap\r
274 );\r
275\r
41be0da5
JF
276/**\r
277 This function is called by both the BSP and the AP which is to become the BSP to\r
278 Exchange execution context including stack between them. After return from this\r
279 function, the BSP becomes AP and the AP becomes the BSP.\r
280\r
281 @param[in] MyInfo Pointer to buffer holding the exchanging information for the executing processor.\r
282 @param[in] OthersInfo Pointer to buffer holding the exchanging information for the peer.\r
283\r
284**/\r
285VOID\r
286EFIAPI\r
287AsmExchangeRole (\r
288 IN CPU_EXCHANGE_ROLE_INFO *MyInfo,\r
289 IN CPU_EXCHANGE_ROLE_INFO *OthersInfo\r
290 );\r
291\r
93ca4c0f
JF
292/**\r
293 Get the pointer to CPU MP Data structure.\r
294\r
295 @return The pointer to CPU MP Data structure.\r
296**/\r
297CPU_MP_DATA *\r
298GetCpuMpData (\r
299 VOID\r
300 );\r
301\r
302/**\r
303 Save the pointer to CPU MP Data structure.\r
304\r
305 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.\r
306**/\r
307VOID\r
308SaveCpuMpData (\r
309 IN CPU_MP_DATA *CpuMpData\r
310 );\r
311\r
ed66e0e3
JF
312\r
313/**\r
a6b3d753 314 Get available system memory below 1MB by specified size.\r
ed66e0e3 315\r
a6b3d753
SZ
316 @param[in] WakeupBufferSize Wakeup buffer size required\r
317\r
318 @retval other Return wakeup buffer address below 1MB.\r
319 @retval -1 Cannot find free memory below 1MB.\r
ed66e0e3 320**/\r
a6b3d753
SZ
321UINTN\r
322GetWakeupBuffer (\r
323 IN UINTN WakeupBufferSize\r
ed66e0e3
JF
324 );\r
325\r
96f5920d
JF
326/**\r
327 This function will be called by BSP to wakeup AP.\r
328\r
329 @param[in] CpuMpData Pointer to CPU MP Data\r
330 @param[in] Broadcast TRUE: Send broadcast IPI to all APs\r
331 FALSE: Send IPI to AP by ApicId\r
332 @param[in] ProcessorNumber The handle number of specified processor\r
333 @param[in] Procedure The function to be invoked by AP\r
334 @param[in] ProcedureArgument The argument to be passed into AP function\r
335**/\r
336VOID\r
337WakeUpAP (\r
338 IN CPU_MP_DATA *CpuMpData,\r
339 IN BOOLEAN Broadcast,\r
340 IN UINTN ProcessorNumber,\r
341 IN EFI_AP_PROCEDURE Procedure, OPTIONAL\r
342 IN VOID *ProcedureArgument OPTIONAL\r
343 );\r
344\r
93ca4c0f
JF
345/**\r
346 Initialize global data for MP support.\r
347\r
348 @param[in] CpuMpData The pointer to CPU MP Data structure.\r
349**/\r
350VOID\r
351InitMpGlobalData (\r
352 IN CPU_MP_DATA *CpuMpData\r
353 );\r
354\r
86efe976
JF
355/**\r
356 Worker function to execute a caller provided function on all enabled APs.\r
357\r
358 @param[in] Procedure A pointer to the function to be run on\r
359 enabled APs of the system.\r
360 @param[in] SingleThread If TRUE, then all the enabled APs execute\r
361 the function specified by Procedure one by\r
362 one, in ascending order of processor handle\r
363 number. If FALSE, then all the enabled APs\r
364 execute the function specified by Procedure\r
365 simultaneously.\r
366 @param[in] WaitEvent The event created by the caller with CreateEvent()\r
367 service.\r
367284e7 368 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
86efe976
JF
369 APs to return from Procedure, either for\r
370 blocking or non-blocking mode.\r
371 @param[in] ProcedureArgument The parameter passed into Procedure for\r
372 all APs.\r
373 @param[out] FailedCpuList If all APs finish successfully, then its\r
374 content is set to NULL. If not all APs\r
375 finish before timeout expires, then its\r
376 content is set to address of the buffer\r
377 holding handle numbers of the failed APs.\r
378\r
379 @retval EFI_SUCCESS In blocking mode, all APs have finished before\r
380 the timeout expired.\r
381 @retval EFI_SUCCESS In non-blocking mode, function has been dispatched\r
382 to all enabled APs.\r
383 @retval others Failed to Startup all APs.\r
384\r
385**/\r
386EFI_STATUS\r
387StartupAllAPsWorker (\r
388 IN EFI_AP_PROCEDURE Procedure,\r
389 IN BOOLEAN SingleThread,\r
390 IN EFI_EVENT WaitEvent OPTIONAL,\r
391 IN UINTN TimeoutInMicroseconds,\r
392 IN VOID *ProcedureArgument OPTIONAL,\r
393 OUT UINTN **FailedCpuList OPTIONAL\r
394 );\r
395\r
20ae5774
JF
396/**\r
397 Worker function to let the caller get one enabled AP to execute a caller-provided\r
398 function.\r
399\r
400 @param[in] Procedure A pointer to the function to be run on\r
401 enabled APs of the system.\r
402 @param[in] ProcessorNumber The handle number of the AP.\r
403 @param[in] WaitEvent The event created by the caller with CreateEvent()\r
404 service.\r
367284e7 405 @param[in] TimeoutInMicroseconds Indicates the time limit in microseconds for\r
20ae5774
JF
406 APs to return from Procedure, either for\r
407 blocking or non-blocking mode.\r
408 @param[in] ProcedureArgument The parameter passed into Procedure for\r
409 all APs.\r
410 @param[out] Finished If AP returns from Procedure before the\r
411 timeout expires, its content is set to TRUE.\r
412 Otherwise, the value is set to FALSE.\r
413\r
414 @retval EFI_SUCCESS In blocking mode, specified AP finished before\r
415 the timeout expires.\r
416 @retval others Failed to Startup AP.\r
417\r
418**/\r
419EFI_STATUS\r
420StartupThisAPWorker (\r
421 IN EFI_AP_PROCEDURE Procedure,\r
422 IN UINTN ProcessorNumber,\r
423 IN EFI_EVENT WaitEvent OPTIONAL,\r
424 IN UINTN TimeoutInMicroseconds,\r
425 IN VOID *ProcedureArgument OPTIONAL,\r
426 OUT BOOLEAN *Finished OPTIONAL\r
427 );\r
428\r
41be0da5
JF
429/**\r
430 Worker function to switch the requested AP to be the BSP from that point onward.\r
431\r
432 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.\r
433 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an\r
434 enabled AP. Otherwise, it will be disabled.\r
435\r
436 @retval EFI_SUCCESS BSP successfully switched.\r
437 @retval others Failed to switch BSP. \r
438\r
439**/\r
440EFI_STATUS\r
441SwitchBSPWorker (\r
442 IN UINTN ProcessorNumber,\r
443 IN BOOLEAN EnableOldBSP\r
444 );\r
445\r
e37109bc
JF
446/**\r
447 Worker function to let the caller enable or disable an AP from this point onward.\r
448 This service may only be called from the BSP.\r
449\r
450 @param[in] ProcessorNumber The handle number of AP.\r
451 @param[in] EnableAP Specifies the new state for the processor for\r
452 enabled, FALSE for disabled.\r
453 @param[in] HealthFlag If not NULL, a pointer to a value that specifies\r
454 the new health status of the AP.\r
455\r
456 @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.\r
457 @retval others Failed to Enable/Disable AP.\r
458\r
459**/\r
460EFI_STATUS\r
461EnableDisableApWorker (\r
462 IN UINTN ProcessorNumber,\r
463 IN BOOLEAN EnableAP,\r
464 IN UINT32 *HealthFlag OPTIONAL\r
465 );\r
466\r
93ca4c0f
JF
467/**\r
468 Get pointer to CPU MP Data structure from GUIDed HOB.\r
469\r
470 @return The pointer to CPU MP Data structure.\r
471**/\r
472CPU_MP_DATA *\r
473GetCpuMpDataFromGuidedHob (\r
474 VOID\r
475 );\r
08085f08
JF
476\r
477/** Checks status of specified AP.\r
478\r
479 This function checks whether the specified AP has finished the task assigned\r
480 by StartupThisAP(), and whether timeout expires.\r
481\r
482 @param[in] ProcessorNumber The handle number of processor.\r
483\r
484 @retval EFI_SUCCESS Specified AP has finished task assigned by StartupThisAPs().\r
485 @retval EFI_TIMEOUT The timeout expires.\r
486 @retval EFI_NOT_READY Specified AP has not finished task and timeout has not expired.\r
487**/\r
488EFI_STATUS\r
489CheckThisAP (\r
490 IN UINTN ProcessorNumber\r
491 );\r
492\r
493/**\r
494 Checks status of all APs.\r
495\r
496 This function checks whether all APs have finished task assigned by StartupAllAPs(),\r
497 and whether timeout expires.\r
498\r
499 @retval EFI_SUCCESS All APs have finished task assigned by StartupAllAPs().\r
500 @retval EFI_TIMEOUT The timeout expires.\r
501 @retval EFI_NOT_READY APs have not finished task and timeout has not expired.\r
502**/\r
503EFI_STATUS\r
504CheckAllAPs (\r
505 VOID\r
506 );\r
507\r
508/**\r
509 Checks APs status and updates APs status if needed.\r
510\r
511**/\r
512VOID\r
513CheckAndUpdateApsStatus (\r
514 VOID\r
515 );\r
516\r
94f63c76
JF
517/**\r
518 Detect whether specified processor can find matching microcode patch and load it.\r
519\r
b31c1ad1 520 @param[in] CpuMpData The pointer to CPU MP Data structure.\r
94f63c76
JF
521**/\r
522VOID\r
523MicrocodeDetect (\r
524 IN CPU_MP_DATA *CpuMpData\r
525 );\r
526\r
4d3314f6
JF
527/**\r
528 Detect whether Mwait-monitor feature is supported.\r
529\r
530 @retval TRUE Mwait-monitor feature is supported.\r
531 @retval FALSE Mwait-monitor feature is not supported.\r
532**/\r
533BOOLEAN\r
534IsMwaitSupport (\r
535 VOID\r
536 );\r
537\r
43c9fdcc
JF
538/**\r
539 Enable Debug Agent to support source debugging on AP function.\r
540\r
541**/\r
542VOID\r
543EnableDebugAgent (\r
544 VOID\r
545 );\r
546\r
3e8ad6bd
JF
547#endif\r
548\r