]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h
7c48b0a645106c87a8be0e691c8392449212fb5b
[mirror_edk2.git] / UefiCpuPkg / Library / RegisterCpuFeaturesLib / RegisterCpuFeatures.h
1 /** @file
2 CPU Register Table Library definitions.
3
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _REGISTER_CPU_FEATURES_H_
10 #define _REGISTER_CPU_FEATURES_H_
11 #include <PiPei.h>
12 #include <PiDxe.h>
13 #include <Ppi/MpServices.h>
14 #include <Protocol/MpService.h>
15
16 #include <Library/BaseLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/RegisterCpuFeaturesLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/SynchronizationLib.h>
23 #include <Library/IoLib.h>
24 #include <Library/LocalApicLib.h>
25
26 #include <AcpiCpuData.h>
27
28 #define CPU_FEATURE_ENTRY_SIGNATURE SIGNATURE_32 ('C', 'F', 'E', 'S')
29
30 #define CPU_FEATURE_NAME_SIZE 128
31
32 typedef struct {
33 REGISTER_CPU_FEATURE_INFORMATION CpuInfo;
34 UINT8 *FeaturesSupportedMask;
35 LIST_ENTRY OrderList;
36 } CPU_FEATURES_INIT_ORDER;
37
38 typedef struct {
39 UINT32 Signature;
40 LIST_ENTRY Link;
41 UINT8 *FeatureMask;
42 CHAR8 *FeatureName;
43 CPU_FEATURE_GET_CONFIG_DATA GetConfigDataFunc;
44 CPU_FEATURE_SUPPORT SupportFunc;
45 CPU_FEATURE_INITIALIZE InitializeFunc;
46 UINT8 *BeforeFeatureBitMask;
47 UINT8 *AfterFeatureBitMask;
48 UINT8 *CoreBeforeFeatureBitMask;
49 UINT8 *CoreAfterFeatureBitMask;
50 UINT8 *PackageBeforeFeatureBitMask;
51 UINT8 *PackageAfterFeatureBitMask;
52 VOID *ConfigData;
53 BOOLEAN BeforeAll;
54 BOOLEAN AfterAll;
55 } CPU_FEATURES_ENTRY;
56
57 //
58 // Flags used when program the register.
59 //
60 typedef struct {
61 volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
62 volatile UINT32 *CoreSemaphoreCount; // Semaphore containers used to program Core semaphore.
63 volatile UINT32 *PackageSemaphoreCount; // Semaphore containers used to program Package semaphore.
64 } PROGRAM_CPU_REGISTER_FLAGS;
65
66 typedef union {
67 EFI_MP_SERVICES_PROTOCOL *Protocol;
68 EFI_PEI_MP_SERVICES_PPI *Ppi;
69 } MP_SERVICES;
70
71 typedef struct {
72 UINTN FeaturesCount;
73 UINT32 BitMaskSize;
74 LIST_ENTRY FeatureList;
75
76 CPU_FEATURES_INIT_ORDER *InitOrder;
77 UINT8 *CapabilityPcd;
78 UINT8 *SettingPcd;
79
80 UINT32 NumberOfCpus;
81 ACPI_CPU_DATA *AcpiCpuData;
82
83 CPU_REGISTER_TABLE *RegisterTable;
84 CPU_REGISTER_TABLE *PreSmmRegisterTable;
85 UINTN BspNumber;
86
87 PROGRAM_CPU_REGISTER_FLAGS CpuFlags;
88
89 MP_SERVICES MpService;
90 } CPU_FEATURES_DATA;
91
92 #define CPU_FEATURE_ENTRY_FROM_LINK(a) \
93 CR ( \
94 (a), \
95 CPU_FEATURES_ENTRY, \
96 Link, \
97 CPU_FEATURE_ENTRY_SIGNATURE \
98 )
99
100 /**
101 Worker function to get CPU_FEATURES_DATA pointer.
102
103 @return Pointer to CPU_FEATURES_DATA.
104 **/
105 CPU_FEATURES_DATA *
106 GetCpuFeaturesData (
107 VOID
108 );
109
110 /**
111 Worker function to return processor index.
112
113 @param CpuFeaturesData Cpu Feature Data structure.
114
115 @return The processor index.
116 **/
117 UINTN
118 GetProcessorIndex (
119 IN CPU_FEATURES_DATA *CpuFeaturesData
120 );
121
122 /**
123 Gets detailed MP-related information on the requested processor at the
124 instant this call is made.
125
126 @param[in] ProcessorNumber The handle number of processor.
127 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
128 the requested processor is deposited.
129
130 @return Status of MpServices->GetProcessorInfo().
131 **/
132 EFI_STATUS
133 GetProcessorInformation (
134 IN UINTN ProcessorNumber,
135 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
136 );
137
138 /**
139 Worker function to execute a caller provided function on all enabled APs.
140
141 @param[in] Procedure A pointer to the function to be run on
142 enabled APs of the system.
143 @param[in] MpEvent A pointer to the event to be used later
144 to check whether procedure has done.
145 **/
146 VOID
147 StartupAllAPsWorker (
148 IN EFI_AP_PROCEDURE Procedure,
149 IN EFI_EVENT MpEvent
150 );
151
152 /**
153 Worker function to retrieve the number of logical processor in the platform.
154
155 @param[out] NumberOfCpus Pointer to the total number of logical
156 processors in the system, including the BSP
157 and disabled APs.
158 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
159 processors that exist in system, including
160 the BSP.
161 **/
162 VOID
163 GetNumberOfProcessor (
164 OUT UINTN *NumberOfCpus,
165 OUT UINTN *NumberOfEnabledProcessors
166 );
167
168 /**
169 Worker function to switch the requested AP to be the BSP from that point onward.
170
171 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
172 **/
173 VOID
174 SwitchNewBsp (
175 IN UINTN ProcessorNumber
176 );
177
178 /**
179 Function that uses DEBUG() macros to display the contents of a a CPU feature bit mask.
180
181 @param[in] FeatureMask A pointer to the CPU feature bit mask.
182 @param[in] BitMaskSize CPU feature bits mask buffer size.
183
184 **/
185 VOID
186 DumpCpuFeatureMask (
187 IN UINT8 *FeatureMask,
188 IN UINT32 BitMaskSize
189 );
190
191 /**
192 Dump CPU feature name or CPU feature bit mask.
193
194 @param[in] CpuFeature Pointer to CPU_FEATURES_ENTRY
195 @param[in] BitMaskSize CPU feature bits mask buffer size.
196
197 **/
198 VOID
199 DumpCpuFeature (
200 IN CPU_FEATURES_ENTRY *CpuFeature,
201 IN UINT32 BitMaskSize
202 );
203
204 /**
205 Return feature dependence result.
206
207 @param[in] CpuFeature Pointer to CPU feature.
208 @param[in] Before Check before dependence or after.
209 @param[in] NextCpuFeatureMask Pointer to next CPU feature Mask.
210
211 @retval return the dependence result.
212 **/
213 CPU_FEATURE_DEPENDENCE_TYPE
214 DetectFeatureScope (
215 IN CPU_FEATURES_ENTRY *CpuFeature,
216 IN BOOLEAN Before,
217 IN UINT8 *NextCpuFeatureMask
218 );
219
220 /**
221 Return feature dependence result.
222
223 @param[in] CpuFeature Pointer to CPU feature.
224 @param[in] Before Check before dependence or after.
225 @param[in] FeatureList Pointer to CPU feature list.
226
227 @retval return the dependence result.
228 **/
229 CPU_FEATURE_DEPENDENCE_TYPE
230 DetectNoneNeighborhoodFeatureScope (
231 IN CPU_FEATURES_ENTRY *CpuFeature,
232 IN BOOLEAN Before,
233 IN LIST_ENTRY *FeatureList
234 );
235
236 /**
237 Programs registers for the calling processor.
238
239 @param[in,out] Buffer The pointer to private data buffer.
240
241 **/
242 VOID
243 EFIAPI
244 SetProcessorRegister (
245 IN OUT VOID *Buffer
246 );
247
248 /**
249 Return ACPI_CPU_DATA data.
250
251 @return Pointer to ACPI_CPU_DATA data.
252 **/
253 ACPI_CPU_DATA *
254 GetAcpiCpuData (
255 VOID
256 );
257
258 /**
259 Worker function to get MP service pointer.
260
261 @return MP_SERVICES variable.
262 **/
263 MP_SERVICES
264 GetMpService (
265 VOID
266 );
267
268 #endif