2 CPU Register Table Library functions.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/UefiBootServicesTableLib.h>
12 #include <Library/UefiLib.h>
14 #include "RegisterCpuFeatures.h"
16 CPU_FEATURES_DATA mCpuFeaturesData
= {0};
19 Worker function to get CPU_FEATURES_DATA pointer.
21 @return Pointer to CPU_FEATURES_DATA.
28 return &mCpuFeaturesData
;
32 Worker function to get EFI_MP_SERVICES_PROTOCOL pointer.
34 @return MP_SERVICES variable.
42 MP_SERVICES MpService
;
45 // Get MP Services Protocol
47 Status
= gBS
->LocateProtocol (
48 &gEfiMpServiceProtocolGuid
,
50 (VOID
**)&MpService
.Protocol
52 ASSERT_EFI_ERROR (Status
);
58 Worker function to return processor index.
60 @param CpuFeaturesData Cpu Feature Data structure.
62 @return The processor index.
66 IN CPU_FEATURES_DATA
*CpuFeaturesData
71 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
73 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
74 Status
= MpServices
->WhoAmI(MpServices
, &ProcessorIndex
);
75 ASSERT_EFI_ERROR (Status
);
76 return ProcessorIndex
;
80 Gets detailed MP-related information on the requested processor at the
81 instant this call is made.
83 @param[in] ProcessorNumber The handle number of processor.
84 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
85 the requested processor is deposited.
87 @return Status of MpServices->GetProcessorInfo().
90 GetProcessorInformation (
91 IN UINTN ProcessorNumber
,
92 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
96 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
97 CPU_FEATURES_DATA
*CpuFeaturesData
;
99 CpuFeaturesData
= GetCpuFeaturesData ();
100 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
102 Status
= MpServices
->GetProcessorInfo (
111 Worker function to execute a caller provided function on all enabled APs.
113 @param[in] Procedure A pointer to the function to be run on
114 enabled APs of the system.
115 @param[in] MpEvent A pointer to the event to be used later
116 to check whether procedure has done.
120 IN EFI_AP_PROCEDURE Procedure
,
125 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
126 CPU_FEATURES_DATA
*CpuFeaturesData
;
128 CpuFeaturesData
= GetCpuFeaturesData ();
129 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
134 Status
= MpServices
->StartupAllAPs (
143 ASSERT_EFI_ERROR (Status
);
147 Worker function to switch the requested AP to be the BSP from that point onward.
149 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
153 IN UINTN ProcessorNumber
157 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
158 CPU_FEATURES_DATA
*CpuFeaturesData
;
160 CpuFeaturesData
= GetCpuFeaturesData ();
161 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
166 Status
= MpServices
->SwitchBSP (
171 ASSERT_EFI_ERROR (Status
);
175 Worker function to retrieve the number of logical processor in the platform.
177 @param[out] NumberOfCpus Pointer to the total number of logical
178 processors in the system, including the BSP
180 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
181 processors that exist in system, including
185 GetNumberOfProcessor (
186 OUT UINTN
*NumberOfCpus
,
187 OUT UINTN
*NumberOfEnabledProcessors
191 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
192 CPU_FEATURES_DATA
*CpuFeaturesData
;
194 CpuFeaturesData
= GetCpuFeaturesData ();
195 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
198 // Get the number of CPUs
200 Status
= MpServices
->GetNumberOfProcessors (
203 NumberOfEnabledProcessors
205 ASSERT_EFI_ERROR (Status
);
209 Performs CPU features Initialization.
211 This service will invoke MP service to perform CPU features
212 initialization on BSP/APs per user configuration.
214 @note This service could be called by BSP only.
218 CpuFeaturesInitialize (
222 CPU_FEATURES_DATA
*CpuFeaturesData
;
227 CpuFeaturesData
= GetCpuFeaturesData ();
229 OldBspNumber
= GetProcessorIndex (CpuFeaturesData
);
230 CpuFeaturesData
->BspNumber
= OldBspNumber
;
232 Status
= gBS
->CreateEvent (
235 EfiEventEmptyFunction
,
239 ASSERT_EFI_ERROR (Status
);
242 // Wakeup all APs for programming.
244 StartupAPsWorker (SetProcessorRegister
, MpEvent
);
248 SetProcessorRegister (CpuFeaturesData
);
251 // Wait all processors to finish the task.
254 Status
= gBS
->CheckEvent (MpEvent
);
255 } while (Status
== EFI_NOT_READY
);
256 ASSERT_EFI_ERROR (Status
);
259 // Switch to new BSP if required
261 if (CpuFeaturesData
->BspNumber
!= OldBspNumber
) {
262 SwitchNewBsp (CpuFeaturesData
->BspNumber
);