]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c
UefiCpuPkg/RegisterCpuFeaturesLib: Combine implementation.
[mirror_edk2.git] / UefiCpuPkg / Library / RegisterCpuFeaturesLib / DxeRegisterCpuFeaturesLib.c
1 /** @file
2 CPU Register Table Library functions.
3
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
9
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.
12
13 **/
14
15 #include <PiDxe.h>
16
17 #include <Library/UefiBootServicesTableLib.h>
18
19 #include "RegisterCpuFeatures.h"
20
21 CPU_FEATURES_DATA mCpuFeaturesData = {0};
22 EFI_MP_SERVICES_PROTOCOL *mCpuFeaturesMpServices = NULL;
23
24 /**
25 Worker function to get CPU_FEATURES_DATA pointer.
26
27 @return Pointer to CPU_FEATURES_DATA.
28 **/
29 CPU_FEATURES_DATA *
30 GetCpuFeaturesData (
31 VOID
32 )
33 {
34 return &mCpuFeaturesData;
35 }
36
37 /**
38 Worker function to get EFI_MP_SERVICES_PROTOCOL pointer.
39
40 @return Pointer to EFI_MP_SERVICES_PROTOCOL.
41 **/
42 EFI_MP_SERVICES_PROTOCOL *
43 GetMpProtocol (
44 VOID
45 )
46 {
47 EFI_STATUS Status;
48
49 if (mCpuFeaturesMpServices == NULL) {
50 //
51 // Get MP Services Protocol
52 //
53 Status = gBS->LocateProtocol (
54 &gEfiMpServiceProtocolGuid,
55 NULL,
56 (VOID **)&mCpuFeaturesMpServices
57 );
58 ASSERT_EFI_ERROR (Status);
59 }
60
61 ASSERT (mCpuFeaturesMpServices != NULL);
62 return mCpuFeaturesMpServices;
63 }
64
65 /**
66 Worker function to return processor index.
67
68 @return The processor index.
69 **/
70 UINTN
71 GetProcessorIndex (
72 VOID
73 )
74 {
75 EFI_STATUS Status;
76 UINTN ProcessorIndex;
77 EFI_MP_SERVICES_PROTOCOL *MpServices;
78
79 MpServices = GetMpProtocol ();
80 Status = MpServices->WhoAmI(MpServices, &ProcessorIndex);
81 ASSERT_EFI_ERROR (Status);
82 return ProcessorIndex;
83 }
84
85 /**
86 Gets detailed MP-related information on the requested processor at the
87 instant this call is made.
88
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.
92
93 @return Status of MpServices->GetProcessorInfo().
94 **/
95 EFI_STATUS
96 GetProcessorInformation (
97 IN UINTN ProcessorNumber,
98 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
99 )
100 {
101 EFI_STATUS Status;
102 EFI_MP_SERVICES_PROTOCOL *MpServices;
103
104 MpServices = GetMpProtocol ();
105 Status = MpServices->GetProcessorInfo (
106 MpServices,
107 ProcessorNumber,
108 ProcessorInfoBuffer
109 );
110 return Status;
111 }
112
113 /**
114 Worker function to execute a caller provided function on all enabled APs.
115
116 @param[in] Procedure A pointer to the function to be run on
117 enabled APs of the system.
118 **/
119 VOID
120 StartupAPsWorker (
121 IN EFI_AP_PROCEDURE Procedure
122 )
123 {
124 EFI_STATUS Status;
125 EFI_MP_SERVICES_PROTOCOL *MpServices;
126
127 MpServices = GetMpProtocol ();
128 //
129 // Wakeup all APs
130 //
131 Status = MpServices->StartupAllAPs (
132 MpServices,
133 Procedure,
134 FALSE,
135 NULL,
136 0,
137 NULL,
138 NULL
139 );
140 ASSERT_EFI_ERROR (Status);
141 }
142
143 /**
144 Worker function to switch the requested AP to be the BSP from that point onward.
145
146 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
147 **/
148 VOID
149 SwitchNewBsp (
150 IN UINTN ProcessorNumber
151 )
152 {
153 EFI_STATUS Status;
154 EFI_MP_SERVICES_PROTOCOL *MpServices;
155
156 MpServices = GetMpProtocol ();
157 //
158 // Wakeup all APs
159 //
160 Status = MpServices->SwitchBSP (
161 MpServices,
162 ProcessorNumber,
163 TRUE
164 );
165 ASSERT_EFI_ERROR (Status);
166 }
167
168 /**
169 Worker function to retrieve the number of logical processor in the platform.
170
171 @param[out] NumberOfCpus Pointer to the total number of logical
172 processors in the system, including the BSP
173 and disabled APs.
174 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
175 processors that exist in system, including
176 the BSP.
177 **/
178 VOID
179 GetNumberOfProcessor (
180 OUT UINTN *NumberOfCpus,
181 OUT UINTN *NumberOfEnabledProcessors
182 )
183 {
184 EFI_STATUS Status;
185 EFI_MP_SERVICES_PROTOCOL *MpServices;
186
187 MpServices = GetMpProtocol ();
188
189 //
190 // Get the number of CPUs
191 //
192 Status = MpServices->GetNumberOfProcessors (
193 MpServices,
194 NumberOfCpus,
195 NumberOfEnabledProcessors
196 );
197 ASSERT_EFI_ERROR (Status);
198 }
199