MpLib.h 26 KB

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