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