CpuMp2Pei.c 20 KB

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