CpuMpPei.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /** @file
  2. Definitions to install Multiple Processor PPI.
  3. Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _CPU_MP_PEI_H_
  7. #define _CPU_MP_PEI_H_
  8. #include <PiPei.h>
  9. #include <Ppi/MpServices.h>
  10. #include <Ppi/SecPlatformInformation.h>
  11. #include <Ppi/SecPlatformInformation2.h>
  12. #include <Ppi/EndOfPeiPhase.h>
  13. #include <Ppi/MpServices2.h>
  14. #include <Library/BaseLib.h>
  15. #include <Library/DebugLib.h>
  16. #include <Library/HobLib.h>
  17. #include <Library/LocalApicLib.h>
  18. #include <Library/PeimEntryPoint.h>
  19. #include <Library/PeiServicesLib.h>
  20. #include <Library/ReportStatusCodeLib.h>
  21. #include <Library/CpuExceptionHandlerLib.h>
  22. #include <Library/MpInitLib.h>
  23. #include <Library/BaseMemoryLib.h>
  24. #include <Library/MemoryAllocationLib.h>
  25. extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;
  26. /**
  27. This service retrieves the number of logical processor in the platform
  28. and the number of those logical processors that are enabled on this boot.
  29. This service may only be called from the BSP.
  30. This function is used to retrieve the following information:
  31. - The number of logical processors that are present in the system.
  32. - The number of enabled logical processors in the system at the instant
  33. this call is made.
  34. Because MP Service Ppi provides services to enable and disable processors
  35. dynamically, the number of enabled logical processors may vary during the
  36. course of a boot session.
  37. If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
  38. If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
  39. EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
  40. is returned in NumberOfProcessors, the number of currently enabled processor
  41. is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
  42. @param[in] PeiServices An indirect pointer to the PEI Services Table
  43. published by the PEI Foundation.
  44. @param[in] This Pointer to this instance of the PPI.
  45. @param[out] NumberOfProcessors Pointer to the total number of logical processors in
  46. the system, including the BSP and disabled APs.
  47. @param[out] NumberOfEnabledProcessors
  48. Number of processors in the system that are enabled.
  49. @retval EFI_SUCCESS The number of logical processors and enabled
  50. logical processors was retrieved.
  51. @retval EFI_DEVICE_ERROR The calling processor is an AP.
  52. @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
  53. NumberOfEnabledProcessors is NULL.
  54. **/
  55. EFI_STATUS
  56. EFIAPI
  57. PeiGetNumberOfProcessors (
  58. IN CONST EFI_PEI_SERVICES **PeiServices,
  59. IN EFI_PEI_MP_SERVICES_PPI *This,
  60. OUT UINTN *NumberOfProcessors,
  61. OUT UINTN *NumberOfEnabledProcessors
  62. );
  63. /**
  64. Gets detailed MP-related information on the requested processor at the
  65. instant this call is made. This service may only be called from the BSP.
  66. This service retrieves detailed MP-related information about any processor
  67. on the platform. Note the following:
  68. - The processor information may change during the course of a boot session.
  69. - The information presented here is entirely MP related.
  70. Information regarding the number of caches and their sizes, frequency of operation,
  71. slot numbers is all considered platform-related information and is not provided
  72. by this service.
  73. @param[in] PeiServices An indirect pointer to the PEI Services Table
  74. published by the PEI Foundation.
  75. @param[in] This Pointer to this instance of the PPI.
  76. @param[in] ProcessorNumber Pointer to the total number of logical processors in
  77. the system, including the BSP and disabled APs.
  78. @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.
  79. @retval EFI_SUCCESS Processor information was returned.
  80. @retval EFI_DEVICE_ERROR The calling processor is an AP.
  81. @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
  82. @retval EFI_NOT_FOUND The processor with the handle specified by
  83. ProcessorNumber does not exist in the platform.
  84. **/
  85. EFI_STATUS
  86. EFIAPI
  87. PeiGetProcessorInfo (
  88. IN CONST EFI_PEI_SERVICES **PeiServices,
  89. IN EFI_PEI_MP_SERVICES_PPI *This,
  90. IN UINTN ProcessorNumber,
  91. OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
  92. );
  93. /**
  94. This service executes a caller provided function on all enabled APs. APs can
  95. run either simultaneously or one at a time in sequence. This service supports
  96. both blocking requests only. This service may only
  97. be called from the BSP.
  98. This function is used to dispatch all the enabled APs to the function specified
  99. by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
  100. immediately and Procedure is not started on any AP.
  101. If SingleThread is TRUE, all the enabled APs execute the function specified by
  102. Procedure one by one, in ascending order of processor handle number. Otherwise,
  103. all the enabled APs execute the function specified by Procedure simultaneously.
  104. If the timeout specified by TimeoutInMicroSeconds expires before all APs return
  105. from Procedure, then Procedure on the failed APs is terminated. All enabled APs
  106. are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
  107. and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its
  108. content points to the list of processor handle numbers in which Procedure was
  109. terminated.
  110. Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
  111. to make sure that the nature of the code that is executed on the BSP and the
  112. dispatched APs is well controlled. The MP Services Ppi does not guarantee
  113. that the Procedure function is MP-safe. Hence, the tasks that can be run in
  114. parallel are limited to certain independent tasks and well-controlled exclusive
  115. code. PEI services and Ppis may not be called by APs unless otherwise
  116. specified.
  117. In blocking execution mode, BSP waits until all APs finish or
  118. TimeoutInMicroSeconds expires.
  119. @param[in] PeiServices An indirect pointer to the PEI Services Table
  120. published by the PEI Foundation.
  121. @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
  122. @param[in] Procedure A pointer to the function to be run on enabled APs of
  123. the system.
  124. @param[in] SingleThread If TRUE, then all the enabled APs execute the function
  125. specified by Procedure one by one, in ascending order
  126. of processor handle number. If FALSE, then all the
  127. enabled APs execute the function specified by Procedure
  128. simultaneously.
  129. @param[in] TimeoutInMicroSeconds
  130. Indicates the time limit in microseconds for APs to
  131. return from Procedure, for blocking mode only. Zero
  132. means infinity. If the timeout expires before all APs
  133. return from Procedure, then Procedure on the failed APs
  134. is terminated. All enabled APs are available for next
  135. function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
  136. or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the
  137. timeout expires in blocking mode, BSP returns
  138. EFI_TIMEOUT.
  139. @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
  140. @retval EFI_SUCCESS In blocking mode, all APs have finished before the
  141. timeout expired.
  142. @retval EFI_DEVICE_ERROR Caller processor is AP.
  143. @retval EFI_NOT_STARTED No enabled APs exist in the system.
  144. @retval EFI_NOT_READY Any enabled APs are busy.
  145. @retval EFI_TIMEOUT In blocking mode, the timeout expired before all
  146. enabled APs have finished.
  147. @retval EFI_INVALID_PARAMETER Procedure is NULL.
  148. **/
  149. EFI_STATUS
  150. EFIAPI
  151. PeiStartupAllAPs (
  152. IN CONST EFI_PEI_SERVICES **PeiServices,
  153. IN EFI_PEI_MP_SERVICES_PPI *This,
  154. IN EFI_AP_PROCEDURE Procedure,
  155. IN BOOLEAN SingleThread,
  156. IN UINTN TimeoutInMicroSeconds,
  157. IN VOID *ProcedureArgument OPTIONAL
  158. );
  159. /**
  160. This service lets the caller get one enabled AP to execute a caller-provided
  161. function. The caller can request the BSP to wait for the completion
  162. of the AP. This service may only be called from the BSP.
  163. This function is used to dispatch one enabled AP to the function specified by
  164. Procedure passing in the argument specified by ProcedureArgument.
  165. The execution is in blocking mode. The BSP waits until the AP finishes or
  166. TimeoutInMicroSecondss expires.
  167. If the timeout specified by TimeoutInMicroseconds expires before the AP returns
  168. from Procedure, then execution of Procedure by the AP is terminated. The AP is
  169. available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and
  170. EFI_PEI_MP_SERVICES_PPI.StartupThisAP().
  171. @param[in] PeiServices An indirect pointer to the PEI Services Table
  172. published by the PEI Foundation.
  173. @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
  174. @param[in] Procedure A pointer to the function to be run on enabled APs of
  175. the system.
  176. @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
  177. total number of logical processors minus 1. The total
  178. number of logical processors can be retrieved by
  179. EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
  180. @param[in] TimeoutInMicroseconds
  181. Indicates the time limit in microseconds for APs to
  182. return from Procedure, for blocking mode only. Zero
  183. means infinity. If the timeout expires before all APs
  184. return from Procedure, then Procedure on the failed APs
  185. is terminated. All enabled APs are available for next
  186. function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
  187. or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the
  188. timeout expires in blocking mode, BSP returns
  189. EFI_TIMEOUT.
  190. @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
  191. @retval EFI_SUCCESS In blocking mode, specified AP finished before the
  192. timeout expires.
  193. @retval EFI_DEVICE_ERROR The calling processor is an AP.
  194. @retval EFI_TIMEOUT In blocking mode, the timeout expired before the
  195. specified AP has finished.
  196. @retval EFI_NOT_FOUND The processor with the handle specified by
  197. ProcessorNumber does not exist.
  198. @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
  199. @retval EFI_INVALID_PARAMETER Procedure is NULL.
  200. **/
  201. EFI_STATUS
  202. EFIAPI
  203. PeiStartupThisAP (
  204. IN CONST EFI_PEI_SERVICES **PeiServices,
  205. IN EFI_PEI_MP_SERVICES_PPI *This,
  206. IN EFI_AP_PROCEDURE Procedure,
  207. IN UINTN ProcessorNumber,
  208. IN UINTN TimeoutInMicroseconds,
  209. IN VOID *ProcedureArgument OPTIONAL
  210. );
  211. /**
  212. This service switches the requested AP to be the BSP from that point onward.
  213. This service changes the BSP for all purposes. This call can only be performed
  214. by the current BSP.
  215. This service switches the requested AP to be the BSP from that point onward.
  216. This service changes the BSP for all purposes. The new BSP can take over the
  217. execution of the old BSP and continue seamlessly from where the old one left
  218. off.
  219. If the BSP cannot be switched prior to the return from this service, then
  220. EFI_UNSUPPORTED must be returned.
  221. @param[in] PeiServices An indirect pointer to the PEI Services Table
  222. published by the PEI Foundation.
  223. @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
  224. @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
  225. total number of logical processors minus 1. The total
  226. number of logical processors can be retrieved by
  227. EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
  228. @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled
  229. AP. Otherwise, it will be disabled.
  230. @retval EFI_SUCCESS BSP successfully switched.
  231. @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this
  232. service returning.
  233. @retval EFI_UNSUPPORTED Switching the BSP is not supported.
  234. @retval EFI_DEVICE_ERROR The calling processor is an AP.
  235. @retval EFI_NOT_FOUND The processor with the handle specified by
  236. ProcessorNumber does not exist.
  237. @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled
  238. AP.
  239. @retval EFI_NOT_READY The specified AP is busy.
  240. **/
  241. EFI_STATUS
  242. EFIAPI
  243. PeiSwitchBSP (
  244. IN CONST EFI_PEI_SERVICES **PeiServices,
  245. IN EFI_PEI_MP_SERVICES_PPI *This,
  246. IN UINTN ProcessorNumber,
  247. IN BOOLEAN EnableOldBSP
  248. );
  249. /**
  250. This service lets the caller enable or disable an AP from this point onward.
  251. This service may only be called from the BSP.
  252. This service allows the caller enable or disable an AP from this point onward.
  253. The caller can optionally specify the health status of the AP by Health. If
  254. an AP is being disabled, then the state of the disabled AP is implementation
  255. dependent. If an AP is enabled, then the implementation must guarantee that a
  256. complete initialization sequence is performed on the AP, so the AP is in a state
  257. that is compatible with an MP operating system.
  258. If the enable or disable AP operation cannot be completed prior to the return
  259. from this service, then EFI_UNSUPPORTED must be returned.
  260. @param[in] PeiServices An indirect pointer to the PEI Services Table
  261. published by the PEI Foundation.
  262. @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
  263. @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
  264. total number of logical processors minus 1. The total
  265. number of logical processors can be retrieved by
  266. EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
  267. @param[in] EnableAP Specifies the new state for the processor for enabled,
  268. FALSE for disabled.
  269. @param[in] HealthFlag If not NULL, a pointer to a value that specifies the
  270. new health status of the AP. This flag corresponds to
  271. StatusFlag defined in EFI_PEI_MP_SERVICES_PPI.GetProcessorInfo().
  272. Only the PROCESSOR_HEALTH_STATUS_BIT is used. All other
  273. bits are ignored. If it is NULL, this parameter is
  274. ignored.
  275. @retval EFI_SUCCESS The specified AP was enabled or disabled successfully.
  276. @retval EFI_UNSUPPORTED Enabling or disabling an AP cannot be completed prior
  277. to this service returning.
  278. @retval EFI_UNSUPPORTED Enabling or disabling an AP is not supported.
  279. @retval EFI_DEVICE_ERROR The calling processor is an AP.
  280. @retval EFI_NOT_FOUND Processor with the handle specified by ProcessorNumber
  281. does not exist.
  282. @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP.
  283. **/
  284. EFI_STATUS
  285. EFIAPI
  286. PeiEnableDisableAP (
  287. IN CONST EFI_PEI_SERVICES **PeiServices,
  288. IN EFI_PEI_MP_SERVICES_PPI *This,
  289. IN UINTN ProcessorNumber,
  290. IN BOOLEAN EnableAP,
  291. IN UINT32 *HealthFlag OPTIONAL
  292. );
  293. /**
  294. This return the handle number for the calling processor. This service may be
  295. called from the BSP and APs.
  296. This service returns the processor handle number for the calling processor.
  297. The returned value is in the range from 0 to the total number of logical
  298. processors minus 1. The total number of logical processors can be retrieved
  299. with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be
  300. called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
  301. is returned. Otherwise, the current processors handle number is returned in
  302. ProcessorNumber, and EFI_SUCCESS is returned.
  303. @param[in] PeiServices An indirect pointer to the PEI Services Table
  304. published by the PEI Foundation.
  305. @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
  306. @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the
  307. total number of logical processors minus 1. The total
  308. number of logical processors can be retrieved by
  309. EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
  310. @retval EFI_SUCCESS The current processor handle number was returned in
  311. ProcessorNumber.
  312. @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
  313. **/
  314. EFI_STATUS
  315. EFIAPI
  316. PeiWhoAmI (
  317. IN CONST EFI_PEI_SERVICES **PeiServices,
  318. IN EFI_PEI_MP_SERVICES_PPI *This,
  319. OUT UINTN *ProcessorNumber
  320. );
  321. /**
  322. Collects BIST data from PPI.
  323. This function collects BIST data from Sec Platform Information2 PPI
  324. or SEC Platform Information PPI.
  325. @param PeiServices Pointer to PEI Services Table
  326. **/
  327. VOID
  328. CollectBistDataFromPpi (
  329. IN CONST EFI_PEI_SERVICES **PeiServices
  330. );
  331. /**
  332. Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.
  333. @param PeiServices The pointer to the PEI Services Table.
  334. @param StructureSize The pointer to the variable describing size of the input buffer.
  335. @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.
  336. @retval EFI_SUCCESS The data was successfully returned.
  337. @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to
  338. hold the record is returned in StructureSize.
  339. **/
  340. EFI_STATUS
  341. EFIAPI
  342. SecPlatformInformation2 (
  343. IN CONST EFI_PEI_SERVICES **PeiServices,
  344. IN OUT UINT64 *StructureSize,
  345. OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
  346. );
  347. /**
  348. Migrates the Global Descriptor Table (GDT) to permanent memory.
  349. @retval EFI_SUCCESS The GDT was migrated successfully.
  350. @retval EFI_OUT_OF_RESOURCES The GDT could not be migrated due to lack of available memory.
  351. **/
  352. EFI_STATUS
  353. MigrateGdt (
  354. VOID
  355. );
  356. /**
  357. Initializes MP and exceptions handlers.
  358. @param PeiServices The pointer to the PEI Services Table.
  359. @retval EFI_SUCCESS MP was successfully initialized.
  360. @retval others Error occurred in MP initialization.
  361. **/
  362. EFI_STATUS
  363. InitializeCpuMpWorker (
  364. IN CONST EFI_PEI_SERVICES **PeiServices
  365. );
  366. /**
  367. Enable/setup stack guard for each processor if PcdCpuStackGuard is set to TRUE.
  368. Doing this in the memory-discovered callback is to make sure the Stack Guard
  369. feature to cover as most PEI code as possible.
  370. @param[in] PeiServices General purpose services available to every PEIM.
  371. @param[in] NotifyDescriptor The notification structure this PEIM registered on install.
  372. @param[in] Ppi The memory discovered PPI. Not used.
  373. @retval EFI_SUCCESS The function completed successfully.
  374. @retval others There's error in MP initialization.
  375. **/
  376. EFI_STATUS
  377. EFIAPI
  378. MemoryDiscoveredPpiNotifyCallback (
  379. IN EFI_PEI_SERVICES **PeiServices,
  380. IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
  381. IN VOID *Ppi
  382. );
  383. extern EFI_PEI_NOTIFY_DESCRIPTOR mPostMemNotifyList[];
  384. #endif