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