2 CPU Register Table Library functions.
4 Copyright (c) 2017, 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.
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/UefiLib.h>
20 #include "RegisterCpuFeatures.h"
22 CPU_FEATURES_DATA mCpuFeaturesData
= {0};
25 Worker function to get CPU_FEATURES_DATA pointer.
27 @return Pointer to CPU_FEATURES_DATA.
34 return &mCpuFeaturesData
;
38 Worker function to get EFI_MP_SERVICES_PROTOCOL pointer.
40 @return MP_SERVICES variable.
48 MP_SERVICES MpService
;
51 // Get MP Services Protocol
53 Status
= gBS
->LocateProtocol (
54 &gEfiMpServiceProtocolGuid
,
56 (VOID
**)&MpService
.Protocol
58 ASSERT_EFI_ERROR (Status
);
64 Worker function to return processor index.
66 @param CpuFeaturesData Cpu Feature Data structure.
68 @return The processor index.
72 IN CPU_FEATURES_DATA
*CpuFeaturesData
77 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
79 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
80 Status
= MpServices
->WhoAmI(MpServices
, &ProcessorIndex
);
81 ASSERT_EFI_ERROR (Status
);
82 return ProcessorIndex
;
86 Gets detailed MP-related information on the requested processor at the
87 instant this call is made.
89 @param[in] ProcessorNumber The handle number of processor.
90 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
91 the requested processor is deposited.
93 @return Status of MpServices->GetProcessorInfo().
96 GetProcessorInformation (
97 IN UINTN ProcessorNumber
,
98 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
102 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
103 CPU_FEATURES_DATA
*CpuFeaturesData
;
105 CpuFeaturesData
= GetCpuFeaturesData ();
106 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
108 Status
= MpServices
->GetProcessorInfo (
117 Worker function to execute a caller provided function on all enabled APs.
119 @param[in] Procedure A pointer to the function to be run on
120 enabled APs of the system.
121 @param[in] MpEvent A pointer to the event to be used later
122 to check whether procedure has done.
126 IN EFI_AP_PROCEDURE Procedure
,
131 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
132 CPU_FEATURES_DATA
*CpuFeaturesData
;
134 CpuFeaturesData
= GetCpuFeaturesData ();
135 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
140 Status
= MpServices
->StartupAllAPs (
149 ASSERT_EFI_ERROR (Status
);
153 Worker function to switch the requested AP to be the BSP from that point onward.
155 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
159 IN UINTN ProcessorNumber
163 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
164 CPU_FEATURES_DATA
*CpuFeaturesData
;
166 CpuFeaturesData
= GetCpuFeaturesData ();
167 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
172 Status
= MpServices
->SwitchBSP (
177 ASSERT_EFI_ERROR (Status
);
181 Worker function to retrieve the number of logical processor in the platform.
183 @param[out] NumberOfCpus Pointer to the total number of logical
184 processors in the system, including the BSP
186 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
187 processors that exist in system, including
191 GetNumberOfProcessor (
192 OUT UINTN
*NumberOfCpus
,
193 OUT UINTN
*NumberOfEnabledProcessors
197 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
198 CPU_FEATURES_DATA
*CpuFeaturesData
;
200 CpuFeaturesData
= GetCpuFeaturesData ();
201 MpServices
= CpuFeaturesData
->MpService
.Protocol
;
204 // Get the number of CPUs
206 Status
= MpServices
->GetNumberOfProcessors (
209 NumberOfEnabledProcessors
211 ASSERT_EFI_ERROR (Status
);
215 Performs CPU features Initialization.
217 This service will invoke MP service to perform CPU features
218 initialization on BSP/APs per user configuration.
220 @note This service could be called by BSP only.
224 CpuFeaturesInitialize (
228 CPU_FEATURES_DATA
*CpuFeaturesData
;
233 CpuFeaturesData
= GetCpuFeaturesData ();
235 OldBspNumber
= GetProcessorIndex (CpuFeaturesData
);
236 CpuFeaturesData
->BspNumber
= OldBspNumber
;
238 Status
= gBS
->CreateEvent (
241 EfiEventEmptyFunction
,
245 ASSERT_EFI_ERROR (Status
);
248 // Wakeup all APs for programming.
250 StartupAPsWorker (SetProcessorRegister
, MpEvent
);
254 SetProcessorRegister (CpuFeaturesData
);
257 // Wait all processors to finish the task.
260 Status
= gBS
->CheckEvent (MpEvent
);
261 } while (Status
== EFI_NOT_READY
);
262 ASSERT_EFI_ERROR (Status
);
265 // Switch to new BSP if required
267 if (CpuFeaturesData
->BspNumber
!= OldBspNumber
) {
268 SwitchNewBsp (CpuFeaturesData
->BspNumber
);