2 Implementation of Multiple Processor PPI services.
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PeiMpServices.h"
19 Get CPU Package/Core/Thread location information.
21 @param InitialApicId CPU APIC ID
22 @param Location Pointer to CPU location information
25 ExtractProcessorLocation (
26 IN UINT32 InitialApicId
,
27 OUT EFI_CPU_PHYSICAL_LOCATION
*Location
30 BOOLEAN TopologyLeafSupported
;
40 UINT32 MaxLogicProcessorsPerPackage
;
41 UINT32 MaxCoresPerPackage
;
44 // Check if the processor is capable of supporting more than one logical processor.
46 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, NULL
, &RegEdx
);
47 if ((RegEdx
& BIT28
) == 0) {
50 Location
->Package
= 0;
58 // Assume three-level mapping of APIC ID: Package:Core:SMT.
61 TopologyLeafSupported
= FALSE
;
63 // Get the max index of basic CPUID
65 AsmCpuid (CPUID_SIGNATURE
, &MaxCpuIdIndex
, NULL
, NULL
, NULL
);
68 // If the extended topology enumeration leaf is available, it
69 // is the preferred mechanism for enumerating topology.
71 if (MaxCpuIdIndex
>= CPUID_EXTENDED_TOPOLOGY
) {
72 AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY
, 0, &RegEax
, &RegEbx
, &RegEcx
, NULL
);
74 // If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for
75 // basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not
76 // supported on that processor.
79 TopologyLeafSupported
= TRUE
;
82 // Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to extract
83 // the SMT sub-field of x2APIC ID.
85 LevelType
= (RegEcx
>> 8) & 0xff;
86 ASSERT (LevelType
== CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_SMT
);
87 ThreadBits
= RegEax
& 0x1f;
90 // Software must not assume any "level type" encoding
91 // value to be related to any sub-leaf index, except sub-leaf 0.
95 AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY
, SubIndex
, &RegEax
, NULL
, &RegEcx
, NULL
);
96 LevelType
= (RegEcx
>> 8) & 0xff;
97 if (LevelType
== CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_CORE
) {
98 CoreBits
= (RegEax
& 0x1f) - ThreadBits
;
102 } while (LevelType
!= CPUID_EXTENDED_TOPOLOGY_LEVEL_TYPE_INVALID
);
106 if (!TopologyLeafSupported
) {
107 AsmCpuid (CPUID_VERSION_INFO
, NULL
, &RegEbx
, NULL
, NULL
);
108 MaxLogicProcessorsPerPackage
= (RegEbx
>> 16) & 0xff;
109 if (MaxCpuIdIndex
>= CPUID_CACHE_PARAMS
) {
110 AsmCpuidEx (CPUID_CACHE_PARAMS
, 0, &RegEax
, NULL
, NULL
, NULL
);
111 MaxCoresPerPackage
= (RegEax
>> 26) + 1;
114 // Must be a single-core processor.
116 MaxCoresPerPackage
= 1;
119 ThreadBits
= (UINTN
) (HighBitSet32 (MaxLogicProcessorsPerPackage
/ MaxCoresPerPackage
- 1) + 1);
120 CoreBits
= (UINTN
) (HighBitSet32 (MaxCoresPerPackage
- 1) + 1);
123 Location
->Thread
= InitialApicId
& ~((-1) << ThreadBits
);
124 Location
->Core
= (InitialApicId
>> ThreadBits
) & ~((-1) << CoreBits
);
125 Location
->Package
= (InitialApicId
>> (ThreadBits
+ CoreBits
));
129 Find the current Processor number by APIC ID.
131 @param PeiCpuMpData Pointer to PEI CPU MP Data
132 @param ProcessorNumber Return the pocessor number found
134 @retval EFI_SUCCESS ProcessorNumber is found and returned.
135 @retval EFI_NOT_FOUND ProcessorNumber is not found.
139 IN PEI_CPU_MP_DATA
*PeiCpuMpData
,
140 OUT UINTN
*ProcessorNumber
143 UINTN TotalProcessorNumber
;
146 TotalProcessorNumber
= PeiCpuMpData
->CpuCount
;
147 for (Index
= 0; Index
< TotalProcessorNumber
; Index
++) {
148 if (PeiCpuMpData
->CpuData
[Index
].ApicId
== GetInitialApicId ()) {
149 *ProcessorNumber
= Index
;
153 return EFI_NOT_FOUND
;
157 Worker function for SwitchBSP().
159 Worker function for SwitchBSP(), assigned to the AP which is intended to become BSP.
161 @param Buffer Pointer to CPU MP Data
169 PEI_CPU_MP_DATA
*DataInHob
;
171 DataInHob
= (PEI_CPU_MP_DATA
*) Buffer
;
172 AsmExchangeRole (&DataInHob
->APInfo
, &DataInHob
->BSPInfo
);
176 This service retrieves the number of logical processor in the platform
177 and the number of those logical processors that are enabled on this boot.
178 This service may only be called from the BSP.
180 This function is used to retrieve the following information:
181 - The number of logical processors that are present in the system.
182 - The number of enabled logical processors in the system at the instant
185 Because MP Service Ppi provides services to enable and disable processors
186 dynamically, the number of enabled logical processors may vary during the
187 course of a boot session.
189 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
190 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
191 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
192 is returned in NumberOfProcessors, the number of currently enabled processor
193 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
195 @param[in] PeiServices An indirect pointer to the PEI Services Table
196 published by the PEI Foundation.
197 @param[in] This Pointer to this instance of the PPI.
198 @param[out] NumberOfProcessors Pointer to the total number of logical processors in
199 the system, including the BSP and disabled APs.
200 @param[out] NumberOfEnabledProcessors
201 Number of processors in the system that are enabled.
203 @retval EFI_SUCCESS The number of logical processors and enabled
204 logical processors was retrieved.
205 @retval EFI_DEVICE_ERROR The calling processor is an AP.
206 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
207 NumberOfEnabledProcessors is NULL.
211 PeiGetNumberOfProcessors (
212 IN CONST EFI_PEI_SERVICES
**PeiServices
,
213 IN EFI_PEI_MP_SERVICES_PPI
*This
,
214 OUT UINTN
*NumberOfProcessors
,
215 OUT UINTN
*NumberOfEnabledProcessors
218 PEI_CPU_MP_DATA
*PeiCpuMpData
;
220 UINTN ProcessorNumber
;
221 UINTN EnabledProcessorNumber
;
224 PeiCpuMpData
= GetMpHobData ();
225 if (PeiCpuMpData
== NULL
) {
226 return EFI_NOT_FOUND
;
229 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
230 return EFI_INVALID_PARAMETER
;
234 // Check whether caller processor is BSP
236 PeiWhoAmI (PeiServices
, This
, &CallerNumber
);
237 if (CallerNumber
!= PeiCpuMpData
->BspNumber
) {
238 return EFI_DEVICE_ERROR
;
241 ProcessorNumber
= PeiCpuMpData
->CpuCount
;
242 EnabledProcessorNumber
= 0;
243 for (Index
= 0; Index
< ProcessorNumber
; Index
++) {
244 if (PeiCpuMpData
->CpuData
[Index
].State
!= CpuStateDisabled
) {
245 EnabledProcessorNumber
++;
249 *NumberOfProcessors
= ProcessorNumber
;
250 *NumberOfEnabledProcessors
= EnabledProcessorNumber
;
256 Gets detailed MP-related information on the requested processor at the
257 instant this call is made. This service may only be called from the BSP.
259 This service retrieves detailed MP-related information about any processor
260 on the platform. Note the following:
261 - The processor information may change during the course of a boot session.
262 - The information presented here is entirely MP related.
264 Information regarding the number of caches and their sizes, frequency of operation,
265 slot numbers is all considered platform-related information and is not provided
268 @param[in] PeiServices An indirect pointer to the PEI Services Table
269 published by the PEI Foundation.
270 @param[in] This Pointer to this instance of the PPI.
271 @param[in] ProcessorNumber Pointer to the total number of logical processors in
272 the system, including the BSP and disabled APs.
273 @param[out] ProcessorInfoBuffer Number of processors in the system that are enabled.
275 @retval EFI_SUCCESS Processor information was returned.
276 @retval EFI_DEVICE_ERROR The calling processor is an AP.
277 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
278 @retval EFI_NOT_FOUND The processor with the handle specified by
279 ProcessorNumber does not exist in the platform.
283 PeiGetProcessorInfo (
284 IN CONST EFI_PEI_SERVICES
**PeiServices
,
285 IN EFI_PEI_MP_SERVICES_PPI
*This
,
286 IN UINTN ProcessorNumber
,
287 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
290 PEI_CPU_MP_DATA
*PeiCpuMpData
;
293 PeiCpuMpData
= GetMpHobData ();
294 if (PeiCpuMpData
== NULL
) {
295 return EFI_NOT_FOUND
;
299 // Check whether caller processor is BSP
301 PeiWhoAmI (PeiServices
, This
, &CallerNumber
);
302 if (CallerNumber
!= PeiCpuMpData
->BspNumber
) {
303 return EFI_DEVICE_ERROR
;
306 if (ProcessorInfoBuffer
== NULL
) {
307 return EFI_INVALID_PARAMETER
;
310 if (ProcessorNumber
>= PeiCpuMpData
->CpuCount
) {
311 return EFI_NOT_FOUND
;
314 ProcessorInfoBuffer
->ProcessorId
= (UINT64
) PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
;
315 ProcessorInfoBuffer
->StatusFlag
= 0;
316 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
== GetInitialApicId()) {
317 ProcessorInfoBuffer
->StatusFlag
|= PROCESSOR_AS_BSP_BIT
;
319 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].Health
.Uint32
== 0) {
320 ProcessorInfoBuffer
->StatusFlag
|= PROCESSOR_HEALTH_STATUS_BIT
;
322 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].State
== CpuStateDisabled
) {
323 ProcessorInfoBuffer
->StatusFlag
&= ~PROCESSOR_ENABLED_BIT
;
325 ProcessorInfoBuffer
->StatusFlag
|= PROCESSOR_ENABLED_BIT
;
329 // Get processor location information
331 ExtractProcessorLocation (PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
, &ProcessorInfoBuffer
->Location
);
337 This service executes a caller provided function on all enabled APs. APs can
338 run either simultaneously or one at a time in sequence. This service supports
339 both blocking requests only. This service may only
340 be called from the BSP.
342 This function is used to dispatch all the enabled APs to the function specified
343 by Procedure. If any enabled AP is busy, then EFI_NOT_READY is returned
344 immediately and Procedure is not started on any AP.
346 If SingleThread is TRUE, all the enabled APs execute the function specified by
347 Procedure one by one, in ascending order of processor handle number. Otherwise,
348 all the enabled APs execute the function specified by Procedure simultaneously.
350 If the timeout specified by TimeoutInMicroSeconds expires before all APs return
351 from Procedure, then Procedure on the failed APs is terminated. All enabled APs
352 are always available for further calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
353 and EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If FailedCpuList is not NULL, its
354 content points to the list of processor handle numbers in which Procedure was
357 Note: It is the responsibility of the consumer of the EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
358 to make sure that the nature of the code that is executed on the BSP and the
359 dispatched APs is well controlled. The MP Services Ppi does not guarantee
360 that the Procedure function is MP-safe. Hence, the tasks that can be run in
361 parallel are limited to certain independent tasks and well-controlled exclusive
362 code. PEI services and Ppis may not be called by APs unless otherwise
365 In blocking execution mode, BSP waits until all APs finish or
366 TimeoutInMicroSeconds expires.
368 @param[in] PeiServices An indirect pointer to the PEI Services Table
369 published by the PEI Foundation.
370 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
371 @param[in] Procedure A pointer to the function to be run on enabled APs of
373 @param[in] SingleThread If TRUE, then all the enabled APs execute the function
374 specified by Procedure one by one, in ascending order
375 of processor handle number. If FALSE, then all the
376 enabled APs execute the function specified by Procedure
378 @param[in] TimeoutInMicroSeconds
379 Indicates the time limit in microseconds for APs to
380 return from Procedure, for blocking mode only. Zero
381 means infinity. If the timeout expires before all APs
382 return from Procedure, then Procedure on the failed APs
383 is terminated. All enabled APs are available for next
384 function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
385 or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the
386 timeout expires in blocking mode, BSP returns
388 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
390 @retval EFI_SUCCESS In blocking mode, all APs have finished before the
392 @retval EFI_DEVICE_ERROR Caller processor is AP.
393 @retval EFI_NOT_STARTED No enabled APs exist in the system.
394 @retval EFI_NOT_READY Any enabled APs are busy.
395 @retval EFI_TIMEOUT In blocking mode, the timeout expired before all
396 enabled APs have finished.
397 @retval EFI_INVALID_PARAMETER Procedure is NULL.
402 IN CONST EFI_PEI_SERVICES
**PeiServices
,
403 IN EFI_PEI_MP_SERVICES_PPI
*This
,
404 IN EFI_AP_PROCEDURE Procedure
,
405 IN BOOLEAN SingleThread
,
406 IN UINTN TimeoutInMicroSeconds
,
407 IN VOID
*ProcedureArgument OPTIONAL
410 PEI_CPU_MP_DATA
*PeiCpuMpData
;
411 UINTN ProcessorNumber
;
414 BOOLEAN HasEnabledAp
;
415 BOOLEAN HasEnabledIdleAp
;
416 volatile UINT32
*FinishedCount
;
418 UINTN WaitCountIndex
;
419 UINTN WaitCountNumber
;
421 PeiCpuMpData
= GetMpHobData ();
422 if (PeiCpuMpData
== NULL
) {
423 return EFI_NOT_FOUND
;
427 // Check whether caller processor is BSP
429 PeiWhoAmI (PeiServices
, This
, &CallerNumber
);
430 if (CallerNumber
!= PeiCpuMpData
->BspNumber
) {
431 return EFI_DEVICE_ERROR
;
434 ProcessorNumber
= PeiCpuMpData
->CpuCount
;
436 HasEnabledAp
= FALSE
;
437 HasEnabledIdleAp
= FALSE
;
438 for (Index
= 0; Index
< ProcessorNumber
; Index
++) {
439 if (Index
== CallerNumber
) {
445 if (PeiCpuMpData
->CpuData
[Index
].State
!= CpuStateDisabled
) {
447 if (PeiCpuMpData
->CpuData
[Index
].State
!= CpuStateBusy
) {
448 HasEnabledIdleAp
= TRUE
;
454 // If no enabled AP exists, return EFI_NOT_STARTED.
456 return EFI_NOT_STARTED
;
458 if (!HasEnabledIdleAp
) {
460 // If any enabled APs are busy, return EFI_NOT_READY.
462 return EFI_NOT_READY
;
465 WaitCountNumber
= TimeoutInMicroSeconds
/ CPU_CHECK_AP_INTERVAL
+ 1;
467 FinishedCount
= &PeiCpuMpData
->FinishedCount
;
469 WakeUpAP (PeiCpuMpData
, TRUE
, 0, Procedure
, ProcedureArgument
);
473 if (TimeoutInMicroSeconds
== 0) {
474 while (*FinishedCount
< ProcessorNumber
- 1) {
477 Status
= EFI_SUCCESS
;
479 Status
= EFI_TIMEOUT
;
480 for (WaitCountIndex
= 0; WaitCountIndex
< WaitCountNumber
; WaitCountIndex
++) {
481 MicroSecondDelay (CPU_CHECK_AP_INTERVAL
);
482 if (*FinishedCount
>= ProcessorNumber
- 1) {
483 Status
= EFI_SUCCESS
;
489 Status
= EFI_SUCCESS
;
490 for (Index
= 0; Index
< ProcessorNumber
; Index
++) {
491 if (Index
== CallerNumber
) {
494 WakeUpAP (PeiCpuMpData
, FALSE
, PeiCpuMpData
->CpuData
[Index
].ApicId
, Procedure
, ProcedureArgument
);
498 if (TimeoutInMicroSeconds
== 0) {
499 while (*FinishedCount
< 1) {
503 for (WaitCountIndex
= 0; WaitCountIndex
< WaitCountNumber
; WaitCountIndex
++) {
504 MicroSecondDelay (CPU_CHECK_AP_INTERVAL
);
505 if (*FinishedCount
>= 1) {
509 if (WaitCountIndex
== WaitCountNumber
) {
510 Status
= EFI_TIMEOUT
;
520 This service lets the caller get one enabled AP to execute a caller-provided
521 function. The caller can request the BSP to wait for the completion
522 of the AP. This service may only be called from the BSP.
524 This function is used to dispatch one enabled AP to the function specified by
525 Procedure passing in the argument specified by ProcedureArgument.
526 The execution is in blocking mode. The BSP waits until the AP finishes or
527 TimeoutInMicroSecondss expires.
529 If the timeout specified by TimeoutInMicroseconds expires before the AP returns
530 from Procedure, then execution of Procedure by the AP is terminated. The AP is
531 available for subsequent calls to EFI_PEI_MP_SERVICES_PPI.StartupAllAPs() and
532 EFI_PEI_MP_SERVICES_PPI.StartupThisAP().
534 @param[in] PeiServices An indirect pointer to the PEI Services Table
535 published by the PEI Foundation.
536 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
537 @param[in] Procedure A pointer to the function to be run on enabled APs of
539 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
540 total number of logical processors minus 1. The total
541 number of logical processors can be retrieved by
542 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
543 @param[in] TimeoutInMicroseconds
544 Indicates the time limit in microseconds for APs to
545 return from Procedure, for blocking mode only. Zero
546 means infinity. If the timeout expires before all APs
547 return from Procedure, then Procedure on the failed APs
548 is terminated. All enabled APs are available for next
549 function assigned by EFI_PEI_MP_SERVICES_PPI.StartupAllAPs()
550 or EFI_PEI_MP_SERVICES_PPI.StartupThisAP(). If the
551 timeout expires in blocking mode, BSP returns
553 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
555 @retval EFI_SUCCESS In blocking mode, specified AP finished before the
557 @retval EFI_DEVICE_ERROR The calling processor is an AP.
558 @retval EFI_TIMEOUT In blocking mode, the timeout expired before the
559 specified AP has finished.
560 @retval EFI_NOT_FOUND The processor with the handle specified by
561 ProcessorNumber does not exist.
562 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the BSP or disabled AP.
563 @retval EFI_INVALID_PARAMETER Procedure is NULL.
568 IN CONST EFI_PEI_SERVICES
**PeiServices
,
569 IN EFI_PEI_MP_SERVICES_PPI
*This
,
570 IN EFI_AP_PROCEDURE Procedure
,
571 IN UINTN ProcessorNumber
,
572 IN UINTN TimeoutInMicroseconds
,
573 IN VOID
*ProcedureArgument OPTIONAL
576 PEI_CPU_MP_DATA
*PeiCpuMpData
;
578 volatile UINT32
*FinishedCount
;
580 UINTN WaitCountIndex
;
581 UINTN WaitCountNumber
;
583 PeiCpuMpData
= GetMpHobData ();
584 if (PeiCpuMpData
== NULL
) {
585 return EFI_NOT_FOUND
;
589 // Check whether caller processor is BSP
591 PeiWhoAmI (PeiServices
, This
, &CallerNumber
);
592 if (CallerNumber
!= PeiCpuMpData
->BspNumber
) {
593 return EFI_DEVICE_ERROR
;
596 if (ProcessorNumber
>= PeiCpuMpData
->CpuCount
) {
597 return EFI_NOT_FOUND
;
600 if (ProcessorNumber
== PeiCpuMpData
->BspNumber
|| Procedure
== NULL
) {
601 return EFI_INVALID_PARAMETER
;
605 // Check whether specified AP is disabled
607 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].State
== CpuStateDisabled
) {
608 return EFI_INVALID_PARAMETER
;
611 WaitCountNumber
= TimeoutInMicroseconds
/ CPU_CHECK_AP_INTERVAL
+ 1;
613 FinishedCount
= &PeiCpuMpData
->FinishedCount
;
615 WakeUpAP (PeiCpuMpData
, FALSE
, PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
, Procedure
, ProcedureArgument
);
620 if (TimeoutInMicroseconds
== 0) {
621 while (*FinishedCount
< 1) {
624 Status
= EFI_SUCCESS
;
626 Status
= EFI_TIMEOUT
;
627 for (WaitCountIndex
= 0; WaitCountIndex
< WaitCountNumber
; WaitCountIndex
++) {
628 MicroSecondDelay (CPU_CHECK_AP_INTERVAL
);
629 if (*FinishedCount
>= 1) {
630 Status
= EFI_SUCCESS
;
640 This service switches the requested AP to be the BSP from that point onward.
641 This service changes the BSP for all purposes. This call can only be performed
644 This service switches the requested AP to be the BSP from that point onward.
645 This service changes the BSP for all purposes. The new BSP can take over the
646 execution of the old BSP and continue seamlessly from where the old one left
649 If the BSP cannot be switched prior to the return from this service, then
650 EFI_UNSUPPORTED must be returned.
652 @param[in] PeiServices An indirect pointer to the PEI Services Table
653 published by the PEI Foundation.
654 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
655 @param[in] ProcessorNumber The handle number of the AP. The range is from 0 to the
656 total number of logical processors minus 1. The total
657 number of logical processors can be retrieved by
658 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
659 @param[in] EnableOldBSP If TRUE, then the old BSP will be listed as an enabled
660 AP. Otherwise, it will be disabled.
662 @retval EFI_SUCCESS BSP successfully switched.
663 @retval EFI_UNSUPPORTED Switching the BSP cannot be completed prior to this
665 @retval EFI_UNSUPPORTED Switching the BSP is not supported.
666 @retval EFI_SUCCESS The calling processor is an AP.
667 @retval EFI_NOT_FOUND The processor with the handle specified by
668 ProcessorNumber does not exist.
669 @retval EFI_INVALID_PARAMETER ProcessorNumber specifies the current BSP or a disabled
671 @retval EFI_NOT_READY The specified AP is busy.
676 IN CONST EFI_PEI_SERVICES
**PeiServices
,
677 IN EFI_PEI_MP_SERVICES_PPI
*This
,
678 IN UINTN ProcessorNumber
,
679 IN BOOLEAN EnableOldBSP
682 PEI_CPU_MP_DATA
*PeiCpuMpData
;
684 MSR_IA32_APIC_BASE ApicBaseMsr
;
686 PeiCpuMpData
= GetMpHobData ();
687 if (PeiCpuMpData
== NULL
) {
688 return EFI_NOT_FOUND
;
692 // Check whether caller processor is BSP
694 PeiWhoAmI (PeiServices
, This
, &CallerNumber
);
695 if (CallerNumber
!= PeiCpuMpData
->BspNumber
) {
699 if (ProcessorNumber
>= PeiCpuMpData
->CpuCount
) {
700 return EFI_NOT_FOUND
;
704 // Check whether specified AP is disabled
706 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].State
== CpuStateDisabled
) {
707 return EFI_INVALID_PARAMETER
;
711 // Check whether ProcessorNumber specifies the current BSP
713 if (ProcessorNumber
== PeiCpuMpData
->BspNumber
) {
714 return EFI_INVALID_PARAMETER
;
718 // Check whether specified AP is busy
720 if (PeiCpuMpData
->CpuData
[ProcessorNumber
].State
== CpuStateBusy
) {
721 return EFI_NOT_READY
;
725 // Clear the BSP bit of MSR_IA32_APIC_BASE
727 ApicBaseMsr
.Uint64
= AsmReadMsr64 (MSR_IA32_APIC_BASE_ADDRESS
);
728 ApicBaseMsr
.Bits
.Bsp
= 0;
729 AsmWriteMsr64 (MSR_IA32_APIC_BASE_ADDRESS
, ApicBaseMsr
.Uint64
);
731 PeiCpuMpData
->BSPInfo
.State
= CPU_SWITCH_STATE_IDLE
;
732 PeiCpuMpData
->APInfo
.State
= CPU_SWITCH_STATE_IDLE
;
735 // Need to wakeUp AP (future BSP).
737 WakeUpAP (PeiCpuMpData
, FALSE
, PeiCpuMpData
->CpuData
[ProcessorNumber
].ApicId
, FutureBSPProc
, PeiCpuMpData
);
739 AsmExchangeRole (&PeiCpuMpData
->BSPInfo
, &PeiCpuMpData
->APInfo
);
742 // Set the BSP bit of MSR_IA32_APIC_BASE on new BSP
744 ApicBaseMsr
.Uint64
= AsmReadMsr64 (MSR_IA32_APIC_BASE_ADDRESS
);
745 ApicBaseMsr
.Bits
.Bsp
= 1;
746 AsmWriteMsr64 (MSR_IA32_APIC_BASE_ADDRESS
, ApicBaseMsr
.Uint64
);
753 This return the handle number for the calling processor. This service may be
754 called from the BSP and APs.
756 This service returns the processor handle number for the calling processor.
757 The returned value is in the range from 0 to the total number of logical
758 processors minus 1. The total number of logical processors can be retrieved
759 with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be
760 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
761 is returned. Otherwise, the current processors handle number is returned in
762 ProcessorNumber, and EFI_SUCCESS is returned.
764 @param[in] PeiServices An indirect pointer to the PEI Services Table
765 published by the PEI Foundation.
766 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
767 @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the
768 total number of logical processors minus 1. The total
769 number of logical processors can be retrieved by
770 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
772 @retval EFI_SUCCESS The current processor handle number was returned in
774 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
779 IN CONST EFI_PEI_SERVICES
**PeiServices
,
780 IN EFI_PEI_MP_SERVICES_PPI
*This
,
781 OUT UINTN
*ProcessorNumber
784 PEI_CPU_MP_DATA
*PeiCpuMpData
;
786 PeiCpuMpData
= GetMpHobData ();
787 if (PeiCpuMpData
== NULL
) {
788 return EFI_NOT_FOUND
;
791 if (ProcessorNumber
== NULL
) {
792 return EFI_INVALID_PARAMETER
;
795 return GetProcessorNumber (PeiCpuMpData
, ProcessorNumber
);