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