]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.h
f56023786fd9064e7d5efdc761b830be8a22c04e
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.h
1 /** @file
2 Common header file for MP Initialize Library.
3
4 Copyright (c) 2016, 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 #ifndef _MP_LIB_H_
16 #define _MP_LIB_H_
17
18 #include <PiPei.h>
19
20 #include <Register/Cpuid.h>
21 #include <Register/Msr.h>
22 #include <Register/LocalApic.h>
23 #include <Register/Microcode.h>
24
25 #include <Library/MpInitLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/LocalApicLib.h>
31 #include <Library/CpuLib.h>
32 #include <Library/UefiCpuLib.h>
33 #include <Library/TimerLib.h>
34 #include <Library/SynchronizationLib.h>
35 #include <Library/MtrrLib.h>
36 #include <Library/HobLib.h>
37
38 #define CPU_INIT_MP_LIB_HOB_GUID \
39 { \
40 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \
41 }
42
43 //
44 // AP loop state when APs are in idle state
45 // It's value is the same with PcdCpuApLoopMode
46 //
47 typedef enum {
48 ApInHltLoop = 1,
49 ApInMwaitLoop = 2,
50 ApInRunLoop = 3
51 } AP_LOOP_MODE;
52
53 //
54 // AP initialization state during APs wakeup
55 //
56 typedef enum {
57 ApInitConfig = 1,
58 ApInitReconfig = 2,
59 ApInitDone = 3
60 } AP_INIT_STATE;
61
62 //
63 // AP state
64 //
65 typedef enum {
66 CpuStateIdle,
67 CpuStateReady,
68 CpuStateBusy,
69 CpuStateFinished,
70 CpuStateDisabled
71 } CPU_STATE;
72
73 //
74 // CPU volatile registers around INIT-SIPI-SIPI
75 //
76 typedef struct {
77 UINTN Cr0;
78 UINTN Cr3;
79 UINTN Cr4;
80 UINTN Dr0;
81 UINTN Dr1;
82 UINTN Dr2;
83 UINTN Dr3;
84 UINTN Dr6;
85 UINTN Dr7;
86 } CPU_VOLATILE_REGISTERS;
87
88 //
89 // AP related data
90 //
91 typedef struct {
92 SPIN_LOCK ApLock;
93 volatile UINT32 *StartupApSignal;
94 volatile UINTN ApFunction;
95 volatile UINTN ApFunctionArgument;
96 UINT32 InitialApicId;
97 UINT32 ApicId;
98 UINT32 Health;
99 BOOLEAN CpuHealthy;
100 volatile CPU_STATE State;
101 CPU_VOLATILE_REGISTERS VolatileRegisters;
102 BOOLEAN Waiting;
103 BOOLEAN *Finished;
104 UINT64 ExpectedTime;
105 UINT64 CurrentTime;
106 UINT64 TotalTime;
107 EFI_EVENT WaitEvent;
108 } CPU_AP_DATA;
109
110 //
111 // Basic CPU information saved in Guided HOB.
112 // Because the contents will be shard between PEI and DXE,
113 // we need to make sure the each fields offset same in different
114 // architecture.
115 //
116 typedef struct {
117 UINT32 InitialApicId;
118 UINT32 ApicId;
119 UINT32 Health;
120 } CPU_INFO_IN_HOB;
121
122 //
123 // AP reset code information including code address and size,
124 // this structure will be shared be C code and assembly code.
125 // It is natural aligned by design.
126 //
127 typedef struct {
128 UINT8 *RendezvousFunnelAddress;
129 UINTN ModeEntryOffset;
130 UINTN RendezvousFunnelSize;
131 UINT8 *RelocateApLoopFuncAddress;
132 UINTN RelocateApLoopFuncSize;
133 } MP_ASSEMBLY_ADDRESS_MAP;
134
135 typedef struct _CPU_MP_DATA CPU_MP_DATA;
136
137 #pragma pack(1)
138
139 //
140 // MP CPU exchange information for AP reset code
141 // This structure is required to be packed because fixed field offsets
142 // into this structure are used in assembly code in this module
143 //
144 typedef struct {
145 UINTN Lock;
146 UINTN StackStart;
147 UINTN StackSize;
148 UINTN CFunction;
149 IA32_DESCRIPTOR GdtrProfile;
150 IA32_DESCRIPTOR IdtrProfile;
151 UINTN BufferStart;
152 UINTN ModeOffset;
153 UINTN NumApsExecuting;
154 UINTN CodeSegment;
155 UINTN DataSegment;
156 UINTN EnableExecuteDisable;
157 UINTN Cr3;
158 CPU_MP_DATA *CpuMpData;
159 } MP_CPU_EXCHANGE_INFO;
160
161 #pragma pack()
162
163 //
164 // CPU MP Data save in memory
165 //
166 struct _CPU_MP_DATA {
167 UINT64 CpuInfoInHob;
168 UINT32 CpuCount;
169 UINT32 BspNumber;
170 //
171 // The above fields data will be passed from PEI to DXE
172 // Please make sure the fields offset same in the different
173 // architecture.
174 //
175 SPIN_LOCK MpLock;
176 UINTN Buffer;
177 UINTN CpuApStackSize;
178 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
179 UINTN WakeupBuffer;
180 UINTN BackupBuffer;
181 UINTN BackupBufferSize;
182 BOOLEAN EndOfPeiFlag;
183
184 volatile UINT32 StartCount;
185 volatile UINT32 FinishedCount;
186 volatile UINT32 RunningCount;
187 BOOLEAN SingleThread;
188 EFI_AP_PROCEDURE Procedure;
189 VOID *ProcArguments;
190 BOOLEAN *Finished;
191 UINT64 ExpectedTime;
192 UINT64 CurrentTime;
193 UINT64 TotalTime;
194 EFI_EVENT WaitEvent;
195 UINTN **FailedCpuList;
196
197 AP_INIT_STATE InitFlag;
198 BOOLEAN X2ApicEnable;
199 MTRR_SETTINGS MtrrTable;
200 UINT8 ApLoopMode;
201 UINT8 ApTargetCState;
202 UINT16 PmCodeSegment;
203 CPU_AP_DATA *CpuData;
204 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
205 };
206
207 extern EFI_GUID mCpuInitMpLibHobGuid;
208
209 /**
210 Assembly code to place AP into safe loop mode.
211
212 Place AP into targeted C-State if MONITOR is supported, otherwise
213 place AP into hlt state.
214 Place AP in protected mode if the current is long mode. Due to AP maybe
215 wakeup by some hardware event. It could avoid accessing page table that
216 may not available during booting to OS.
217
218 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
219 FALSE indicates MONITOR is not supported.
220 @param[in] ApTargetCState Target C-State value.
221 @param[in] PmCodeSegment Protected mode code segment value.
222 **/
223 typedef
224 VOID
225 (EFIAPI * ASM_RELOCATE_AP_LOOP) (
226 IN BOOLEAN MwaitSupport,
227 IN UINTN ApTargetCState,
228 IN UINTN PmCodeSegment
229 );
230
231 /**
232 Assembly code to get starting address and size of the rendezvous entry for APs.
233 Information for fixing a jump instruction in the code is also returned.
234
235 @param[out] AddressMap Output buffer for address map information.
236 **/
237 VOID
238 EFIAPI
239 AsmGetAddressMap (
240 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
241 );
242
243 /**
244 Get the pointer to CPU MP Data structure.
245
246 @return The pointer to CPU MP Data structure.
247 **/
248 CPU_MP_DATA *
249 GetCpuMpData (
250 VOID
251 );
252
253 /**
254 Save the pointer to CPU MP Data structure.
255
256 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
257 **/
258 VOID
259 SaveCpuMpData (
260 IN CPU_MP_DATA *CpuMpData
261 );
262
263 /**
264 Initialize global data for MP support.
265
266 @param[in] CpuMpData The pointer to CPU MP Data structure.
267 **/
268 VOID
269 InitMpGlobalData (
270 IN CPU_MP_DATA *CpuMpData
271 );
272
273 /**
274 Get pointer to CPU MP Data structure from GUIDed HOB.
275
276 @return The pointer to CPU MP Data structure.
277 **/
278 CPU_MP_DATA *
279 GetCpuMpDataFromGuidedHob (
280 VOID
281 );
282
283 /**
284 Detect whether specified processor can find matching microcode patch and load it.
285
286 @param[in] PeiCpuMpData Pointer to PEI CPU MP Data
287 **/
288 VOID
289 MicrocodeDetect (
290 IN CPU_MP_DATA *CpuMpData
291 );
292
293 /**
294 Notify function on End Of PEI PPI.
295
296 On S3 boot, this function will restore wakeup buffer data.
297 On normal boot, this function will flag wakeup buffer to be un-used type.
298
299 @param[in] PeiServices The pointer to the PEI Services Table.
300 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
301 @param[in] Ppi Address of the PPI that was installed.
302
303 @retval EFI_SUCCESS When everything is OK.
304 **/
305 EFI_STATUS
306 EFIAPI
307 CpuMpEndOfPeiCallback (
308 IN EFI_PEI_SERVICES **PeiServices,
309 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
310 IN VOID *Ppi
311 );
312
313 #endif
314