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