]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuMpPei/CpuMpPei.h
UefiCpuPkg/CpuMpPei: Prepare for monitor buffer
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuMpPei.h
CommitLineData
ea0f431c
JF
1/** @file\r
2 Definitions to install Multiple Processor PPI.\r
3\r
4 Copyright (c) 2015, 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 _CPU_MP_PEI_H_\r
16#define _CPU_MP_PEI_H_\r
17\r
18#include <PiPei.h>\r
19\r
20#include <Ppi/MpServices.h>\r
21#include <Ppi/SecPlatformInformation.h>\r
22#include <Ppi/SecPlatformInformation2.h>\r
23#include <Ppi/EndOfPeiPhase.h>\r
24\r
28a7ddf0 25#include <Register/Cpuid.h>\r
ea0f431c
JF
26#include <Register/LocalApic.h>\r
27\r
28#include <Library/BaseLib.h>\r
29#include <Library/BaseMemoryLib.h>\r
30#include <Library/DebugLib.h>\r
31#include <Library/HobLib.h>\r
32#include <Library/LocalApicLib.h>\r
33#include <Library/MtrrLib.h>\r
34#include <Library/PcdLib.h>\r
35#include <Library/PeimEntryPoint.h>\r
36#include <Library/PeiServicesLib.h>\r
37#include <Library/ReportStatusCodeLib.h>\r
38#include <Library/SynchronizationLib.h>\r
39#include <Library/TimerLib.h>\r
40#include <Library/UefiCpuLib.h>\r
41\r
42#include "Microcode.h"\r
43\r
44//\r
45// AP state\r
46//\r
47typedef enum {\r
48 CpuStateIdle,\r
49 CpuStateBusy,\r
50 CpuStateDisabled\r
51} CPU_STATE;\r
52\r
4de216c0
JF
53typedef enum {\r
54 ApInHltLoop = 1,\r
55 ApInMwaitLoop = 2,\r
56 ApInRunLoop = 3\r
57} AP_LOOP_MODE;\r
58\r
ea0f431c
JF
59//\r
60// AP reset code information\r
61//\r
62typedef struct {\r
63 UINT8 *RendezvousFunnelAddress;\r
64 UINTN PModeEntryOffset;\r
65 UINTN LModeEntryOffset;\r
66 UINTN RendezvousFunnelSize;\r
67} MP_ASSEMBLY_ADDRESS_MAP;\r
68\r
69//\r
70// CPU exchange information for switch BSP\r
71//\r
72typedef struct {\r
73 UINT8 State; // offset 0\r
74 UINTN StackPointer; // offset 4 / 8\r
75 IA32_DESCRIPTOR Gdtr; // offset 8 / 16\r
76 IA32_DESCRIPTOR Idtr; // offset 14 / 26\r
77} CPU_EXCHANGE_ROLE_INFO;\r
78\r
79typedef struct _PEI_CPU_MP_DATA PEI_CPU_MP_DATA;\r
80\r
d603b115 81#pragma pack(1)\r
ea0f431c
JF
82\r
83typedef union {\r
84 struct {\r
85 UINT32 LimitLow : 16;\r
86 UINT32 BaseLow : 16;\r
87 UINT32 BaseMid : 8;\r
88 UINT32 Type : 4;\r
89 UINT32 System : 1;\r
90 UINT32 Dpl : 2;\r
91 UINT32 Present : 1;\r
92 UINT32 LimitHigh : 4;\r
93 UINT32 Software : 1;\r
94 UINT32 Reserved : 1;\r
95 UINT32 DefaultSize : 1;\r
96 UINT32 Granularity : 1;\r
97 UINT32 BaseHigh : 8;\r
98 } Bits;\r
99 UINT64 Uint64;\r
100} IA32_GDT;\r
101\r
102//\r
103// MP CPU exchange information for AP reset code\r
d603b115
JF
104// This structure is required to be packed because fixed field offsets\r
105// into this structure are used in assembly code in this module\r
ea0f431c
JF
106//\r
107typedef struct {\r
108 UINTN Lock;\r
109 UINTN StackStart;\r
110 UINTN StackSize;\r
111 UINTN CFunction;\r
112 IA32_DESCRIPTOR GdtrProfile;\r
113 IA32_DESCRIPTOR IdtrProfile;\r
114 UINTN BufferStart;\r
115 UINTN PmodeOffset;\r
116 UINTN NumApsExecuting;\r
117 UINTN LmodeOffset;\r
118 UINTN Cr3;\r
119 PEI_CPU_MP_DATA *PeiCpuMpData;\r
120} MP_CPU_EXCHANGE_INFO;\r
121\r
122#pragma pack()\r
123\r
ef1fdb80
JF
124typedef struct {\r
125 UINTN Cr0;\r
126 UINTN Cr3;\r
127 UINTN Cr4;\r
128 UINTN Dr0;\r
129 UINTN Dr1;\r
130 UINTN Dr2;\r
131 UINTN Dr3;\r
132 UINTN Dr6;\r
133 UINTN Dr7;\r
134} CPU_VOLATILE_REGISTERS;\r
135\r
ea0f431c 136typedef struct {\r
e001e11f 137 volatile UINT32 *StartupApSignal;\r
ea0f431c
JF
138 UINT32 ApicId;\r
139 EFI_HEALTH_FLAGS Health;\r
140 CPU_STATE State;\r
141 BOOLEAN CpuHealthy;\r
ef1fdb80 142 CPU_VOLATILE_REGISTERS VolatileRegisters;\r
ea0f431c
JF
143} PEI_CPU_DATA;\r
144\r
145//\r
146// PEI CPU MP Data save in memory\r
147//\r
148struct _PEI_CPU_MP_DATA {\r
2f0261b7 149 SPIN_LOCK MpLock;\r
ea0f431c
JF
150 UINT32 CpuCount;\r
151 UINT32 BspNumber;\r
152 UINTN Buffer;\r
153 UINTN CpuApStackSize;\r
154 MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r
155 UINTN WakeupBuffer;\r
156 UINTN BackupBuffer;\r
157 UINTN BackupBufferSize;\r
158 UINTN ApFunction;\r
159 UINTN ApFunctionArgument;\r
160 volatile UINT32 FinishedCount;\r
161 BOOLEAN EndOfPeiFlag;\r
162 BOOLEAN InitFlag;\r
2f0261b7 163 BOOLEAN X2ApicEnable;\r
ea0f431c
JF
164 CPU_EXCHANGE_ROLE_INFO BSPInfo;\r
165 CPU_EXCHANGE_ROLE_INFO APInfo;\r
166 MTRR_SETTINGS MtrrTable;\r
e001e11f
JF
167 UINT8 ApLoopMode;\r
168 UINT8 ApTargetCState;\r
ea0f431c
JF
169 PEI_CPU_DATA *CpuData;\r
170 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;\r
171};\r
172extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;\r
173\r
174\r
175/**\r
176 Assembly code to get starting address and size of the rendezvous entry for APs.\r
177 Information for fixing a jump instruction in the code is also returned.\r
178\r
179 @param AddressMap Output buffer for address map information.\r
180**/\r
181VOID\r
182EFIAPI\r
183AsmGetAddressMap (\r
184 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap\r
185 );\r
186\r
187/**\r
188 Assembly code to load GDT table and update segment accordingly.\r
189\r
190 @param Gdtr Pointer to GDT descriptor\r
191**/\r
192VOID\r
193EFIAPI\r
194AsmInitializeGdt (\r
195 IN IA32_DESCRIPTOR *Gdtr\r
196 );\r
197\r
198/**\r
199 Assembly code to do CLI-HALT loop.\r
200\r
201**/\r
202VOID\r
203EFIAPI\r
204AsmCliHltLoop (\r
205 VOID\r
206 );\r
207\r
208/**\r
209 Get available system memory below 1MB by specified size.\r
210\r
211 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
212**/\r
213VOID\r
214BackupAndPrepareWakeupBuffer(\r
215 IN PEI_CPU_MP_DATA *PeiCpuMpData\r
216 );\r
217\r
218/**\r
219 Restore wakeup buffer data.\r
220\r
221 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
222**/\r
223VOID\r
224RestoreWakeupBuffer(\r
225 IN PEI_CPU_MP_DATA *PeiCpuMpData\r
226 );\r
227\r
228/**\r
229 Notify function on End Of Pei PPI.\r
230\r
231 On S3 boot, this function will restore wakeup buffer data.\r
232 On normal boot, this function will flag wakeup buffer to be un-used type.\r
233\r
234 @param PeiServices The pointer to the PEI Services Table.\r
235 @param NotifyDescriptor Address of the notification descriptor data structure.\r
236 @param Ppi Address of the PPI that was installed.\r
237\r
238 @retval EFI_SUCCESS When everything is OK.\r
239\r
240**/\r
241EFI_STATUS\r
242EFIAPI\r
243CpuMpEndOfPeiCallback (\r
244 IN EFI_PEI_SERVICES **PeiServices,\r
245 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
246 IN VOID *Ppi\r
247 );\r
248\r
249/**\r
250 This function will be called by BSP to wakeup AP.\r
251\r
252 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
253 @param Broadcast TRUE: Send broadcast IPI to all APs\r
254 FALSE: Send IPI to AP by ApicId\r
255 @param ApicId Apic ID for the processor to be waked\r
256 @param Procedure The function to be invoked by AP\r
257 @param ProcedureArgument The argument to be passed into AP function\r
258**/\r
259VOID\r
260WakeUpAP (\r
261 IN PEI_CPU_MP_DATA *PeiCpuMpData,\r
262 IN BOOLEAN Broadcast,\r
263 IN UINT32 ApicId,\r
264 IN EFI_AP_PROCEDURE Procedure, OPTIONAL\r
265 IN VOID *ProcedureArgument OPTIONAL\r
266 );\r
267\r
268/**\r
269 Get CPU MP Data pointer from the Guided HOB.\r
270\r
271 @return Pointer to Pointer to PEI CPU MP Data\r
272**/\r
273PEI_CPU_MP_DATA *\r
274GetMpHobData (\r
275 VOID\r
276 );\r
277\r
278/**\r
279 Find the current Processor number by APIC ID.\r
280\r
281 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
282 @param ProcessorNumber Return the pocessor number found\r
283\r
284 @retval EFI_SUCCESS ProcessorNumber is found and returned.\r
285 @retval EFI_NOT_FOUND ProcessorNumber is not found.\r
286**/\r
287EFI_STATUS\r
288GetProcessorNumber (\r
289 IN PEI_CPU_MP_DATA *PeiCpuMpData,\r
290 OUT UINTN *ProcessorNumber\r
291 );\r
292\r
293/**\r
294 Collects BIST data from PPI.\r
295\r
296 This function collects BIST data from Sec Platform Information2 PPI\r
297 or SEC Platform Information PPI.\r
298\r
299 @param PeiServices Pointer to PEI Services Table\r
300 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
301\r
302**/\r
303VOID\r
304CollectBistDataFromPpi (\r
305 IN CONST EFI_PEI_SERVICES **PeiServices,\r
306 IN PEI_CPU_MP_DATA *PeiCpuMpData\r
307 );\r
308\r
309/**\r
310 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
311\r
312 @param PeiServices The pointer to the PEI Services Table.\r
313 @param StructureSize The pointer to the variable describing size of the input buffer.\r
314 @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
315\r
316 @retval EFI_SUCCESS The data was successfully returned.\r
317 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to\r
318 hold the record is returned in StructureSize.\r
319\r
320**/\r
321EFI_STATUS\r
322EFIAPI\r
323SecPlatformInformation2 (\r
324 IN CONST EFI_PEI_SERVICES **PeiServices,\r
325 IN OUT UINT64 *StructureSize,\r
326 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
327 );\r
328\r
329#endif\r