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