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