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