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"
20 Find the current Processor number by APIC ID.
22 @param PeiCpuMpData Pointer to PEI CPU MP Data
23 @param ProcessorNumber Return the pocessor number found
25 @retval EFI_SUCCESS ProcessorNumber is found and returned.
26 @retval EFI_NOT_FOUND ProcessorNumber is not found.
30 IN PEI_CPU_MP_DATA
*PeiCpuMpData
,
31 OUT UINTN
*ProcessorNumber
34 UINTN TotalProcessorNumber
;
37 TotalProcessorNumber
= PeiCpuMpData
->CpuCount
;
38 for (Index
= 0; Index
< TotalProcessorNumber
; Index
++) {
39 if (PeiCpuMpData
->CpuData
[Index
].ApicId
== GetInitialApicId ()) {
40 *ProcessorNumber
= Index
;
48 This service retrieves the number of logical processor in the platform
49 and the number of those logical processors that are enabled on this boot.
50 This service may only be called from the BSP.
52 This function is used to retrieve the following information:
53 - The number of logical processors that are present in the system.
54 - The number of enabled logical processors in the system at the instant
57 Because MP Service Ppi provides services to enable and disable processors
58 dynamically, the number of enabled logical processors may vary during the
59 course of a boot session.
61 If this service is called from an AP, then EFI_DEVICE_ERROR is returned.
62 If NumberOfProcessors or NumberOfEnabledProcessors is NULL, then
63 EFI_INVALID_PARAMETER is returned. Otherwise, the total number of processors
64 is returned in NumberOfProcessors, the number of currently enabled processor
65 is returned in NumberOfEnabledProcessors, and EFI_SUCCESS is returned.
67 @param[in] PeiServices An indirect pointer to the PEI Services Table
68 published by the PEI Foundation.
69 @param[in] This Pointer to this instance of the PPI.
70 @param[out] NumberOfProcessors Pointer to the total number of logical processors in
71 the system, including the BSP and disabled APs.
72 @param[out] NumberOfEnabledProcessors
73 Number of processors in the system that are enabled.
75 @retval EFI_SUCCESS The number of logical processors and enabled
76 logical processors was retrieved.
77 @retval EFI_DEVICE_ERROR The calling processor is an AP.
78 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL.
79 NumberOfEnabledProcessors is NULL.
83 PeiGetNumberOfProcessors (
84 IN CONST EFI_PEI_SERVICES
**PeiServices
,
85 IN EFI_PEI_MP_SERVICES_PPI
*This
,
86 OUT UINTN
*NumberOfProcessors
,
87 OUT UINTN
*NumberOfEnabledProcessors
90 PEI_CPU_MP_DATA
*PeiCpuMpData
;
92 UINTN ProcessorNumber
;
93 UINTN EnabledProcessorNumber
;
96 PeiCpuMpData
= GetMpHobData ();
97 if (PeiCpuMpData
== NULL
) {
101 if ((NumberOfProcessors
== NULL
) || (NumberOfEnabledProcessors
== NULL
)) {
102 return EFI_INVALID_PARAMETER
;
106 // Check whether caller processor is BSP
108 PeiWhoAmI (PeiServices
, This
, &CallerNumber
);
109 if (CallerNumber
!= PeiCpuMpData
->BspNumber
) {
110 return EFI_DEVICE_ERROR
;
113 ProcessorNumber
= PeiCpuMpData
->CpuCount
;
114 EnabledProcessorNumber
= 0;
115 for (Index
= 0; Index
< ProcessorNumber
; Index
++) {
116 if (PeiCpuMpData
->CpuData
[Index
].State
!= CpuStateDisabled
) {
117 EnabledProcessorNumber
++;
121 *NumberOfProcessors
= ProcessorNumber
;
122 *NumberOfEnabledProcessors
= EnabledProcessorNumber
;
128 This return the handle number for the calling processor. This service may be
129 called from the BSP and APs.
131 This service returns the processor handle number for the calling processor.
132 The returned value is in the range from 0 to the total number of logical
133 processors minus 1. The total number of logical processors can be retrieved
134 with EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors(). This service may be
135 called from the BSP and APs. If ProcessorNumber is NULL, then EFI_INVALID_PARAMETER
136 is returned. Otherwise, the current processors handle number is returned in
137 ProcessorNumber, and EFI_SUCCESS is returned.
139 @param[in] PeiServices An indirect pointer to the PEI Services Table
140 published by the PEI Foundation.
141 @param[in] This A pointer to the EFI_PEI_MP_SERVICES_PPI instance.
142 @param[out] ProcessorNumber The handle number of the AP. The range is from 0 to the
143 total number of logical processors minus 1. The total
144 number of logical processors can be retrieved by
145 EFI_PEI_MP_SERVICES_PPI.GetNumberOfProcessors().
147 @retval EFI_SUCCESS The current processor handle number was returned in
149 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
154 IN CONST EFI_PEI_SERVICES
**PeiServices
,
155 IN EFI_PEI_MP_SERVICES_PPI
*This
,
156 OUT UINTN
*ProcessorNumber
159 PEI_CPU_MP_DATA
*PeiCpuMpData
;
161 PeiCpuMpData
= GetMpHobData ();
162 if (PeiCpuMpData
== NULL
) {
163 return EFI_NOT_FOUND
;
166 if (ProcessorNumber
== NULL
) {
167 return EFI_INVALID_PARAMETER
;
170 return GetProcessorNumber (PeiCpuMpData
, ProcessorNumber
);