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