]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h
UefiCpuPkg: Replace BSD License with BSD+Patent License
[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 ConsoleLogLock; // Spinlock used to control console.
62 volatile UINTN MemoryMappedLock; // Spinlock used to program mmio
63 volatile UINT32 *CoreSemaphoreCount; // Semaphore containers used to program Core semaphore.
64 volatile UINT32 *PackageSemaphoreCount; // Semaphore containers used to program Package semaphore.
65 } PROGRAM_CPU_REGISTER_FLAGS;
66
67 typedef union {
68 EFI_MP_SERVICES_PROTOCOL *Protocol;
69 EFI_PEI_MP_SERVICES_PPI *Ppi;
70 } MP_SERVICES;
71
72 typedef struct {
73 UINTN FeaturesCount;
74 UINT32 BitMaskSize;
75 LIST_ENTRY FeatureList;
76
77 CPU_FEATURES_INIT_ORDER *InitOrder;
78 UINT8 *CapabilityPcd;
79 UINT8 *SettingPcd;
80
81 UINT32 NumberOfCpus;
82 ACPI_CPU_DATA *AcpiCpuData;
83
84 CPU_REGISTER_TABLE *RegisterTable;
85 CPU_REGISTER_TABLE *PreSmmRegisterTable;
86 UINTN BspNumber;
87
88 PROGRAM_CPU_REGISTER_FLAGS CpuFlags;
89
90 MP_SERVICES MpService;
91 } CPU_FEATURES_DATA;
92
93 #define CPU_FEATURE_ENTRY_FROM_LINK(a) \
94 CR ( \
95 (a), \
96 CPU_FEATURES_ENTRY, \
97 Link, \
98 CPU_FEATURE_ENTRY_SIGNATURE \
99 )
100
101 /**
102 Worker function to get CPU_FEATURES_DATA pointer.
103
104 @return Pointer to CPU_FEATURES_DATA.
105 **/
106 CPU_FEATURES_DATA *
107 GetCpuFeaturesData (
108 VOID
109 );
110
111 /**
112 Worker function to return processor index.
113
114 @param CpuFeaturesData Cpu Feature Data structure.
115
116 @return The processor index.
117 **/
118 UINTN
119 GetProcessorIndex (
120 IN CPU_FEATURES_DATA *CpuFeaturesData
121 );
122
123 /**
124 Gets detailed MP-related information on the requested processor at the
125 instant this call is made.
126
127 @param[in] ProcessorNumber The handle number of processor.
128 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
129 the requested processor is deposited.
130
131 @return Status of MpServices->GetProcessorInfo().
132 **/
133 EFI_STATUS
134 GetProcessorInformation (
135 IN UINTN ProcessorNumber,
136 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
137 );
138
139 /**
140 Worker function to execute a caller provided function on all enabled APs.
141
142 @param[in] Procedure A pointer to the function to be run on
143 enabled APs of the system.
144 @param[in] MpEvent A pointer to the event to be used later
145 to check whether procedure has done.
146 **/
147 VOID
148 StartupAPsWorker (
149 IN EFI_AP_PROCEDURE Procedure,
150 IN EFI_EVENT MpEvent
151 );
152
153 /**
154 Worker function to retrieve the number of logical processor in the platform.
155
156 @param[out] NumberOfCpus Pointer to the total number of logical
157 processors in the system, including the BSP
158 and disabled APs.
159 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
160 processors that exist in system, including
161 the BSP.
162 **/
163 VOID
164 GetNumberOfProcessor (
165 OUT UINTN *NumberOfCpus,
166 OUT UINTN *NumberOfEnabledProcessors
167 );
168
169 /**
170 Worker function to switch the requested AP to be the BSP from that point onward.
171
172 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
173 **/
174 VOID
175 SwitchNewBsp (
176 IN UINTN ProcessorNumber
177 );
178
179 /**
180 Function that uses DEBUG() macros to display the contents of a a CPU feature bit mask.
181
182 @param[in] FeatureMask A pointer to the CPU feature bit mask.
183 **/
184 VOID
185 DumpCpuFeatureMask (
186 IN UINT8 *FeatureMask
187 );
188
189 /**
190 Dump CPU feature name or CPU feature bit mask.
191
192 @param[in] CpuFeature Pointer to CPU_FEATURES_ENTRY
193 **/
194 VOID
195 DumpCpuFeature (
196 IN CPU_FEATURES_ENTRY *CpuFeature
197 );
198
199 /**
200 Return feature dependence result.
201
202 @param[in] CpuFeature Pointer to CPU feature.
203 @param[in] Before Check before dependence or after.
204 @param[in] NextCpuFeatureMask Pointer to next CPU feature Mask.
205
206 @retval return the dependence result.
207 **/
208 CPU_FEATURE_DEPENDENCE_TYPE
209 DetectFeatureScope (
210 IN CPU_FEATURES_ENTRY *CpuFeature,
211 IN BOOLEAN Before,
212 IN UINT8 *NextCpuFeatureMask
213 );
214
215 /**
216 Return feature dependence result.
217
218 @param[in] CpuFeature Pointer to CPU feature.
219 @param[in] Before Check before dependence or after.
220 @param[in] FeatureList Pointer to CPU feature list.
221
222 @retval return the dependence result.
223 **/
224 CPU_FEATURE_DEPENDENCE_TYPE
225 DetectNoneNeighborhoodFeatureScope (
226 IN CPU_FEATURES_ENTRY *CpuFeature,
227 IN BOOLEAN Before,
228 IN LIST_ENTRY *FeatureList
229 );
230
231 /**
232 Programs registers for the calling processor.
233
234 @param[in,out] Buffer The pointer to private data buffer.
235
236 **/
237 VOID
238 EFIAPI
239 SetProcessorRegister (
240 IN OUT VOID *Buffer
241 );
242
243 /**
244 Return ACPI_CPU_DATA data.
245
246 @return Pointer to ACPI_CPU_DATA data.
247 **/
248 ACPI_CPU_DATA *
249 GetAcpiCpuData (
250 VOID
251 );
252
253 /**
254 Worker function to get MP service pointer.
255
256 @return MP_SERVICES variable.
257 **/
258 MP_SERVICES
259 GetMpService (
260 VOID
261 );
262
263 #endif