MpLib.h 23 KB

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