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