]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.c
UefiCpuPkg/RegisterCpuFeaturesLib: Fix the function header issues
[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 static EFI_MP_SERVICES_PROTOCOL *mMpServices = 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 (mMpServices == NULL) {
50 //
51 // Get MP Services Protocol
52 //
53 Status = gBS->LocateProtocol (
54 &gEfiMpServiceProtocolGuid,
55 NULL,
56 (VOID **)&mMpServices
57 );
58 ASSERT_EFI_ERROR (Status);
59 }
60
61 ASSERT (mMpServices != NULL);
62 return mMpServices;
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
200 /**
201 Allocates ACPI NVS memory to save ACPI_CPU_DATA.
202
203 @return Pointer to allocated ACPI_CPU_DATA.
204 **/
205 ACPI_CPU_DATA *
206 AllocateAcpiCpuData (
207 VOID
208 )
209 {
210 //
211 // CpuS3DataDxe will do it.
212 //
213 ASSERT (FALSE);
214 return NULL;
215 }
216
217 /**
218 Enlarges CPU register table for each processor.
219
220 @param[in, out] RegisterTable Pointer processor's CPU register table
221 **/
222 VOID
223 EnlargeRegisterTable (
224 IN OUT CPU_REGISTER_TABLE *RegisterTable
225 )
226 {
227 EFI_STATUS Status;
228 EFI_PHYSICAL_ADDRESS Address;
229 UINTN AllocatePages;
230
231 Address = BASE_4GB - 1;
232 AllocatePages = RegisterTable->AllocatedSize / EFI_PAGE_SIZE;
233 Status = gBS->AllocatePages (
234 AllocateMaxAddress,
235 EfiACPIMemoryNVS,
236 AllocatePages + 1,
237 &Address
238 );
239 ASSERT_EFI_ERROR (Status);
240
241 //
242 // If there are records existing in the register table, then copy its contents
243 // to new region and free the old one.
244 //
245 if (RegisterTable->AllocatedSize > 0) {
246 CopyMem (
247 (VOID *) (UINTN) Address,
248 (VOID *) (UINTN) RegisterTable->RegisterTableEntry,
249 RegisterTable->AllocatedSize
250 );
251 //
252 // RegisterTableEntry is allocated by gBS->AllocatePages() service.
253 // So, gBS->FreePages() service is used to free it.
254 //
255 gBS->FreePages (
256 RegisterTable->RegisterTableEntry,
257 AllocatePages
258 );
259 }
260
261 //
262 // Adjust the allocated size and register table base address.
263 //
264 RegisterTable->AllocatedSize += EFI_PAGE_SIZE;
265 RegisterTable->RegisterTableEntry = Address;
266 }