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