]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuMpPei/CpuMpPei.h
UefiCpuPkg/CpuMpPei: Add meta data description
[mirror_edk2.git] / UefiCpuPkg / CpuMpPei / CpuMpPei.h
CommitLineData
65e79f93
JF
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
887810c8 20#include <Ppi/MpServices.h>
e66d675d 21#include <Ppi/SecPlatformInformation.h>
a21fe428 22#include <Ppi/SecPlatformInformation2.h>
8f7b315b 23#include <Ppi/EndOfPeiPhase.h>
65e79f93 24
d1cf9333
JF
25#include <Register/LocalApic.h>
26
65e79f93 27#include <Library/BaseLib.h>
e66d675d
JF
28#include <Library/BaseMemoryLib.h>
29#include <Library/DebugLib.h>
05e107f8 30#include <Library/HobLib.h>
e66d675d 31#include <Library/LocalApicLib.h>
b4cd9f78 32#include <Library/MtrrLib.h>
e66d675d 33#include <Library/PcdLib.h>
65e79f93 34#include <Library/PeimEntryPoint.h>
e66d675d 35#include <Library/PeiServicesLib.h>
a21fe428 36#include <Library/ReportStatusCodeLib.h>
7d51bf5c
JF
37#include <Library/SynchronizationLib.h>
38#include <Library/TimerLib.h>
46ba0f63 39#include <Library/UefiCpuLib.h>
d1cf9333
JF
40
41#include "Microcode.h"
42
e66d675d
JF
43//
44// AP state
45//
46typedef enum {
47 CpuStateIdle,
48 CpuStateBusy,
49 CpuStateDisabled
50} CPU_STATE;
65e79f93 51
8018cb15
JF
52//
53// AP reset code information
54//
55typedef struct {
56 UINT8 *RendezvousFunnelAddress;
57 UINTN PModeEntryOffset;
58 UINTN LModeEntryOffset;
59 UINTN RendezvousFunnelSize;
60} MP_ASSEMBLY_ADDRESS_MAP;
61
3798f351
JF
62//
63// CPU exchange information for switch BSP
64//
65typedef struct {
66 UINT8 State; // offset 0
67 UINTN StackPointer; // offset 4 / 8
68 IA32_DESCRIPTOR Gdtr; // offset 8 / 16
69 IA32_DESCRIPTOR Idtr; // offset 14 / 26
70} CPU_EXCHANGE_ROLE_INFO;
71
e66d675d
JF
72typedef struct _PEI_CPU_MP_DATA PEI_CPU_MP_DATA;
73
74#pragma pack()
a56f6f45 75
f9d30595
JF
76typedef union {
77 struct {
78 UINT32 LimitLow : 16;
79 UINT32 BaseLow : 16;
80 UINT32 BaseMid : 8;
81 UINT32 Type : 4;
82 UINT32 System : 1;
83 UINT32 Dpl : 2;
84 UINT32 Present : 1;
85 UINT32 LimitHigh : 4;
86 UINT32 Software : 1;
87 UINT32 Reserved : 1;
88 UINT32 DefaultSize : 1;
89 UINT32 Granularity : 1;
90 UINT32 BaseHigh : 8;
91 } Bits;
92 UINT64 Uint64;
93} IA32_GDT;
a56f6f45
JF
94
95//
96// MP CPU exchange information for AP reset code
97//
98typedef struct {
99 UINTN Lock;
100 UINTN StackStart;
101 UINTN StackSize;
102 UINTN CFunction;
103 IA32_DESCRIPTOR GdtrProfile;
104 IA32_DESCRIPTOR IdtrProfile;
105 UINTN BufferStart;
106 UINTN PmodeOffset;
107 UINTN NumApsExecuting;
108 UINTN LmodeOffset;
109 UINTN Cr3;
7d51bf5c 110 PEI_CPU_MP_DATA *PeiCpuMpData;
a56f6f45
JF
111} MP_CPU_EXCHANGE_INFO;
112
f9d30595 113#pragma pack()
8018cb15 114
e66d675d
JF
115typedef struct {
116 UINT32 ApicId;
117 EFI_HEALTH_FLAGS Health;
118 CPU_STATE State;
119 BOOLEAN CpuHealthy;
120} PEI_CPU_DATA;
121
122//
123// PEI CPU MP Data save in memory
124//
125struct _PEI_CPU_MP_DATA {
126 UINT32 CpuCount;
127 UINT32 BspNumber;
128 UINTN Buffer;
129 UINTN CpuApStackSize;
130 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
131 UINTN WakeupBuffer;
132 UINTN BackupBuffer;
133 UINTN BackupBufferSize;
7d51bf5c
JF
134 UINTN ApFunction;
135 UINTN ApFunctionArgument;
136 volatile UINT32 FinishedCount;
8f7b315b 137 BOOLEAN EndOfPeiFlag;
7d51bf5c 138 BOOLEAN InitFlag;
3798f351
JF
139 CPU_EXCHANGE_ROLE_INFO BSPInfo;
140 CPU_EXCHANGE_ROLE_INFO APInfo;
b4cd9f78 141 MTRR_SETTINGS MtrrTable;
e66d675d
JF
142 PEI_CPU_DATA *CpuData;
143 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
144};
e35d0347
JF
145extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;
146
e66d675d 147
8018cb15
JF
148/**
149 Assembly code to get starting address and size of the rendezvous entry for APs.
150 Information for fixing a jump instruction in the code is also returned.
151
152 @param AddressMap Output buffer for address map information.
153**/
154VOID
155EFIAPI
156AsmGetAddressMap (
157 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
158 );
159
f9d30595
JF
160/**
161 Assembly code to load GDT table and update segment accordingly.
162
163 @param Gdtr Pointer to GDT descriptor
164**/
165VOID
166EFIAPI
167AsmInitializeGdt (
168 IN IA32_DESCRIPTOR *Gdtr
169 );
65e79f93 170
fcc82734
JF
171/**
172 Assembly code to do CLI-HALT loop.
173
174**/
175VOID
176EFIAPI
177AsmCliHltLoop (
178 VOID
179 );
65e79f93 180
8f7b315b
JF
181/**
182 Get available system memory below 1MB by specified size.
183
184 @param PeiCpuMpData Pointer to PEI CPU MP Data
185**/
186VOID
187BackupAndPrepareWakeupBuffer(
188 IN PEI_CPU_MP_DATA *PeiCpuMpData
189 );
190
191/**
192 Restore wakeup buffer data.
193
194 @param PeiCpuMpData Pointer to PEI CPU MP Data
195**/
196VOID
197RestoreWakeupBuffer(
198 IN PEI_CPU_MP_DATA *PeiCpuMpData
199 );
200
201/**
202 Notify function on End Of Pei PPI.
203
204 On S3 boot, this function will restore wakeup buffer data.
205 On normal boot, this function will flag wakeup buffer to be un-used type.
206
207 @param PeiServices The pointer to the PEI Services Table.
208 @param NotifyDescriptor Address of the notification descriptor data structure.
209 @param Ppi Address of the PPI that was installed.
210
211 @retval EFI_SUCCESS When everything is OK.
212
213**/
214EFI_STATUS
215EFIAPI
216CpuMpEndOfPeiCallback (
217 IN EFI_PEI_SERVICES **PeiServices,
218 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,
219 IN VOID *Ppi
220 );
221
60ca9e8c
JF
222/**
223 This function will be called by BSP to wakeup AP.
224
225 @param PeiCpuMpData Pointer to PEI CPU MP Data
226 @param Broadcast TRUE: Send broadcast IPI to all APs
227 FALSE: Send IPI to AP by ApicId
228 @param ApicId Apic ID for the processor to be waked
229 @param Procedure The function to be invoked by AP
230 @param ProcedureArgument The argument to be passed into AP function
231**/
232VOID
233WakeUpAP (
234 IN PEI_CPU_MP_DATA *PeiCpuMpData,
235 IN BOOLEAN Broadcast,
236 IN UINT32 ApicId,
237 IN EFI_AP_PROCEDURE Procedure, OPTIONAL
238 IN VOID *ProcedureArgument OPTIONAL
239 );
240
a21fe428
JF
241/**
242 Get CPU MP Data pointer from the Guided HOB.
243
244 @return Pointer to Pointer to PEI CPU MP Data
245**/
246PEI_CPU_MP_DATA *
247GetMpHobData (
248 VOID
249 );
250
60ca9e8c
JF
251/**
252 Find the current Processor number by APIC ID.
253
254 @param PeiCpuMpData Pointer to PEI CPU MP Data
255 @param ProcessorNumber Return the pocessor number found
256
257 @retval EFI_SUCCESS ProcessorNumber is found and returned.
258 @retval EFI_NOT_FOUND ProcessorNumber is not found.
259**/
260EFI_STATUS
261GetProcessorNumber (
262 IN PEI_CPU_MP_DATA *PeiCpuMpData,
263 OUT UINTN *ProcessorNumber
264 );
265
a21fe428
JF
266/**
267 Collects BIST data from PPI.
268
269 This function collects BIST data from Sec Platform Information2 PPI
270 or SEC Platform Information PPI.
271
272 @param PeiServices Pointer to PEI Services Table
273 @param PeiCpuMpData Pointer to PEI CPU MP Data
274
275**/
276VOID
277CollectBistDataFromPpi (
278 IN CONST EFI_PEI_SERVICES **PeiServices,
279 IN PEI_CPU_MP_DATA *PeiCpuMpData
280 );
281
282/**
283 Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.
284
285 @param PeiServices The pointer to the PEI Services Table.
286 @param StructureSize The pointer to the variable describing size of the input buffer.
287 @param PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.
288
289 @retval EFI_SUCCESS The data was successfully returned.
290 @retval EFI_BUFFER_TOO_SMALL The buffer was too small. The current buffer size needed to
291 hold the record is returned in StructureSize.
292
293**/
294EFI_STATUS
295EFIAPI
296SecPlatformInformation2 (
297 IN CONST EFI_PEI_SERVICES **PeiServices,
298 IN OUT UINT64 *StructureSize,
299 OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2
300 );
301
65e79f93 302#endif