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