]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuMpPei/CpuMpPei.h
UefiCpuPkg: Add Cpuid.h include files for CPUID related defines
[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
75#pragma pack()\r
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
98//\r
99typedef struct {\r
100 UINTN Lock;\r
101 UINTN StackStart;\r
102 UINTN StackSize;\r
103 UINTN CFunction;\r
104 IA32_DESCRIPTOR GdtrProfile;\r
105 IA32_DESCRIPTOR IdtrProfile;\r
106 UINTN BufferStart;\r
107 UINTN PmodeOffset;\r
108 UINTN NumApsExecuting;\r
109 UINTN LmodeOffset;\r
110 UINTN Cr3;\r
111 PEI_CPU_MP_DATA *PeiCpuMpData;\r
112} MP_CPU_EXCHANGE_INFO;\r
113\r
114#pragma pack()\r
115\r
116typedef struct {\r
117 UINT32 ApicId;\r
118 EFI_HEALTH_FLAGS Health;\r
119 CPU_STATE State;\r
120 BOOLEAN CpuHealthy;\r
121} PEI_CPU_DATA;\r
122\r
123//\r
124// PEI CPU MP Data save in memory\r
125//\r
126struct _PEI_CPU_MP_DATA {\r
127 UINT32 CpuCount;\r
128 UINT32 BspNumber;\r
129 UINTN Buffer;\r
130 UINTN CpuApStackSize;\r
131 MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r
132 UINTN WakeupBuffer;\r
133 UINTN BackupBuffer;\r
134 UINTN BackupBufferSize;\r
135 UINTN ApFunction;\r
136 UINTN ApFunctionArgument;\r
137 volatile UINT32 FinishedCount;\r
138 BOOLEAN EndOfPeiFlag;\r
139 BOOLEAN InitFlag;\r
140 CPU_EXCHANGE_ROLE_INFO BSPInfo;\r
141 CPU_EXCHANGE_ROLE_INFO APInfo;\r
142 MTRR_SETTINGS MtrrTable;\r
143 PEI_CPU_DATA *CpuData;\r
144 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;\r
145};\r
146extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;\r
147\r
148\r
149/**\r
150 Assembly code to get starting address and size of the rendezvous entry for APs.\r
151 Information for fixing a jump instruction in the code is also returned.\r
152\r
153 @param AddressMap Output buffer for address map information.\r
154**/\r
155VOID\r
156EFIAPI\r
157AsmGetAddressMap (\r
158 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap\r
159 );\r
160\r
161/**\r
162 Assembly code to load GDT table and update segment accordingly.\r
163\r
164 @param Gdtr Pointer to GDT descriptor\r
165**/\r
166VOID\r
167EFIAPI\r
168AsmInitializeGdt (\r
169 IN IA32_DESCRIPTOR *Gdtr\r
170 );\r
171\r
172/**\r
173 Assembly code to do CLI-HALT loop.\r
174\r
175**/\r
176VOID\r
177EFIAPI\r
178AsmCliHltLoop (\r
179 VOID\r
180 );\r
181\r
182/**\r
183 Get available system memory below 1MB by specified size.\r
184\r
185 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
186**/\r
187VOID\r
188BackupAndPrepareWakeupBuffer(\r
189 IN PEI_CPU_MP_DATA *PeiCpuMpData\r
190 );\r
191\r
192/**\r
193 Restore wakeup buffer data.\r
194\r
195 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
196**/\r
197VOID\r
198RestoreWakeupBuffer(\r
199 IN PEI_CPU_MP_DATA *PeiCpuMpData\r
200 );\r
201\r
202/**\r
203 Notify function on End Of Pei PPI.\r
204\r
205 On S3 boot, this function will restore wakeup buffer data.\r
206 On normal boot, this function will flag wakeup buffer to be un-used type.\r
207\r
208 @param PeiServices The pointer to the PEI Services Table.\r
209 @param NotifyDescriptor Address of the notification descriptor data structure.\r
210 @param Ppi Address of the PPI that was installed.\r
211\r
212 @retval EFI_SUCCESS When everything is OK.\r
213\r
214**/\r
215EFI_STATUS\r
216EFIAPI\r
217CpuMpEndOfPeiCallback (\r
218 IN EFI_PEI_SERVICES **PeiServices,\r
219 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
220 IN VOID *Ppi\r
221 );\r
222\r
223/**\r
224 This function will be called by BSP to wakeup AP.\r
225\r
226 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
227 @param Broadcast TRUE: Send broadcast IPI to all APs\r
228 FALSE: Send IPI to AP by ApicId\r
229 @param ApicId Apic ID for the processor to be waked\r
230 @param Procedure The function to be invoked by AP\r
231 @param ProcedureArgument The argument to be passed into AP function\r
232**/\r
233VOID\r
234WakeUpAP (\r
235 IN PEI_CPU_MP_DATA *PeiCpuMpData,\r
236 IN BOOLEAN Broadcast,\r
237 IN UINT32 ApicId,\r
238 IN EFI_AP_PROCEDURE Procedure, OPTIONAL\r
239 IN VOID *ProcedureArgument OPTIONAL\r
240 );\r
241\r
242/**\r
243 Get CPU MP Data pointer from the Guided HOB.\r
244\r
245 @return Pointer to Pointer to PEI CPU MP Data\r
246**/\r
247PEI_CPU_MP_DATA *\r
248GetMpHobData (\r
249 VOID\r
250 );\r
251\r
252/**\r
253 Find the current Processor number by APIC ID.\r
254\r
255 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
256 @param ProcessorNumber Return the pocessor number found\r
257\r
258 @retval EFI_SUCCESS ProcessorNumber is found and returned.\r
259 @retval EFI_NOT_FOUND ProcessorNumber is not found.\r
260**/\r
261EFI_STATUS\r
262GetProcessorNumber (\r
263 IN PEI_CPU_MP_DATA *PeiCpuMpData,\r
264 OUT UINTN *ProcessorNumber\r
265 );\r
266\r
267/**\r
268 Collects BIST data from PPI.\r
269\r
270 This function collects BIST data from Sec Platform Information2 PPI\r
271 or SEC Platform Information PPI.\r
272\r
273 @param PeiServices Pointer to PEI Services Table\r
274 @param PeiCpuMpData Pointer to PEI CPU MP Data\r
275\r
276**/\r
277VOID\r
278CollectBistDataFromPpi (\r
279 IN CONST EFI_PEI_SERVICES **PeiServices,\r
280 IN PEI_CPU_MP_DATA *PeiCpuMpData\r
281 );\r
282\r
283/**\r
284 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
285\r
286 @param PeiServices The pointer to the PEI Services Table.\r
287 @param StructureSize The pointer to the variable describing size of the input buffer.\r
288 @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
289\r
290 @retval EFI_SUCCESS The data was successfully returned.\r
291 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to\r
292 hold the record is returned in StructureSize.\r
293\r
294**/\r
295EFI_STATUS\r
296EFIAPI\r
297SecPlatformInformation2 (\r
298 IN CONST EFI_PEI_SERVICES **PeiServices,\r
299 IN OUT UINT64 *StructureSize,\r
300 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
301 );\r
302\r
303#endif\r