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