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};
23 EFI_MP_SERVICES_PROTOCOL
*mCpuFeaturesMpServices
= NULL
;
26 Worker function to get CPU_FEATURES_DATA pointer.
28 @return Pointer to CPU_FEATURES_DATA.
35 return &mCpuFeaturesData
;
39 Worker function to get EFI_MP_SERVICES_PROTOCOL pointer.
41 @return Pointer to EFI_MP_SERVICES_PROTOCOL.
43 EFI_MP_SERVICES_PROTOCOL
*
50 if (mCpuFeaturesMpServices
== NULL
) {
52 // Get MP Services Protocol
54 Status
= gBS
->LocateProtocol (
55 &gEfiMpServiceProtocolGuid
,
57 (VOID
**)&mCpuFeaturesMpServices
59 ASSERT_EFI_ERROR (Status
);
62 ASSERT (mCpuFeaturesMpServices
!= NULL
);
63 return mCpuFeaturesMpServices
;
67 Worker function to return processor index.
69 @return The processor index.
78 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
80 MpServices
= GetMpProtocol ();
81 Status
= MpServices
->WhoAmI(MpServices
, &ProcessorIndex
);
82 ASSERT_EFI_ERROR (Status
);
83 return ProcessorIndex
;
87 Gets detailed MP-related information on the requested processor at the
88 instant this call is made.
90 @param[in] ProcessorNumber The handle number of processor.
91 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
92 the requested processor is deposited.
94 @return Status of MpServices->GetProcessorInfo().
97 GetProcessorInformation (
98 IN UINTN ProcessorNumber
,
99 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
103 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
105 MpServices
= GetMpProtocol ();
106 Status
= MpServices
->GetProcessorInfo (
115 Worker function to execute a caller provided function on all enabled APs.
117 @param[in] Procedure A pointer to the function to be run on
118 enabled APs of the system.
119 @param[in] MpEvent A pointer to the event to be used later
120 to check whether procedure has done.
124 IN EFI_AP_PROCEDURE Procedure
,
129 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
130 CPU_FEATURES_DATA
*CpuFeaturesData
;
132 CpuFeaturesData
= GetCpuFeaturesData ();
134 MpServices
= GetMpProtocol ();
138 Status
= MpServices
->StartupAllAPs (
147 ASSERT_EFI_ERROR (Status
);
151 Worker function to switch the requested AP to be the BSP from that point onward.
153 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
157 IN UINTN ProcessorNumber
161 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
163 MpServices
= GetMpProtocol ();
167 Status
= MpServices
->SwitchBSP (
172 ASSERT_EFI_ERROR (Status
);
176 Worker function to retrieve the number of logical processor in the platform.
178 @param[out] NumberOfCpus Pointer to the total number of logical
179 processors in the system, including the BSP
181 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
182 processors that exist in system, including
186 GetNumberOfProcessor (
187 OUT UINTN
*NumberOfCpus
,
188 OUT UINTN
*NumberOfEnabledProcessors
192 EFI_MP_SERVICES_PROTOCOL
*MpServices
;
194 MpServices
= GetMpProtocol ();
197 // Get the number of CPUs
199 Status
= MpServices
->GetNumberOfProcessors (
202 NumberOfEnabledProcessors
204 ASSERT_EFI_ERROR (Status
);
208 Performs CPU features Initialization.
210 This service will invoke MP service to perform CPU features
211 initialization on BSP/APs per user configuration.
213 @note This service could be called by BSP only.
217 CpuFeaturesInitialize (
221 CPU_FEATURES_DATA
*CpuFeaturesData
;
226 CpuFeaturesData
= GetCpuFeaturesData ();
228 OldBspNumber
= GetProcessorIndex();
229 CpuFeaturesData
->BspNumber
= OldBspNumber
;
231 Status
= gBS
->CreateEvent (
234 EfiEventEmptyFunction
,
238 ASSERT_EFI_ERROR (Status
);
241 // Wakeup all APs for programming.
243 StartupAPsWorker (SetProcessorRegister
, MpEvent
);
247 SetProcessorRegister (CpuFeaturesData
);
250 // Wait all processors to finish the task.
253 Status
= gBS
->CheckEvent (MpEvent
);
254 } while (Status
== EFI_NOT_READY
);
255 ASSERT_EFI_ERROR (Status
);
258 // Switch to new BSP if required
260 if (CpuFeaturesData
->BspNumber
!= OldBspNumber
) {
261 SwitchNewBsp (CpuFeaturesData
->BspNumber
);