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