]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Library/MpInitLib/MpLib.h
UefiCpuPkg/MpInitLib: Add MicrocodeDetect() and load microcode on BSP
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.h
1 /** @file
2 Common header file for MP Initialize Library.
3
4 Copyright (c) 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 _MP_LIB_H_
16 #define _MP_LIB_H_
17
18 #include <PiPei.h>
19
20 #include <Register/Cpuid.h>
21 #include <Register/Msr.h>
22 #include <Register/LocalApic.h>
23 #include <Register/Microcode.h>
24
25 #include <Library/MpInitLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/LocalApicLib.h>
31 #include <Library/CpuLib.h>
32 #include <Library/UefiCpuLib.h>
33 #include <Library/TimerLib.h>
34 #include <Library/SynchronizationLib.h>
35 #include <Library/MtrrLib.h>
36 #include <Library/HobLib.h>
37
38 //
39 // AP loop state when APs are in idle state
40 // It's value is the same with PcdCpuApLoopMode
41 //
42 typedef enum {
43 ApInHltLoop = 1,
44 ApInMwaitLoop = 2,
45 ApInRunLoop = 3
46 } AP_LOOP_MODE;
47
48 //
49 // AP initialization state during APs wakeup
50 //
51 typedef enum {
52 ApInitConfig = 1,
53 ApInitReconfig = 2,
54 ApInitDone = 3
55 } AP_INIT_STATE;
56
57 //
58 // AP state
59 //
60 typedef enum {
61 CpuStateIdle,
62 CpuStateReady,
63 CpuStateBusy,
64 CpuStateFinished,
65 CpuStateDisabled
66 } CPU_STATE;
67
68 //
69 // CPU volatile registers around INIT-SIPI-SIPI
70 //
71 typedef struct {
72 UINTN Cr0;
73 UINTN Cr3;
74 UINTN Cr4;
75 UINTN Dr0;
76 UINTN Dr1;
77 UINTN Dr2;
78 UINTN Dr3;
79 UINTN Dr6;
80 UINTN Dr7;
81 } CPU_VOLATILE_REGISTERS;
82
83 //
84 // AP related data
85 //
86 typedef struct {
87 SPIN_LOCK ApLock;
88 volatile UINT32 *StartupApSignal;
89 volatile UINTN ApFunction;
90 volatile UINTN ApFunctionArgument;
91 UINT32 InitialApicId;
92 UINT32 ApicId;
93 UINT32 Health;
94 BOOLEAN CpuHealthy;
95 volatile CPU_STATE State;
96 CPU_VOLATILE_REGISTERS VolatileRegisters;
97 BOOLEAN Waiting;
98 BOOLEAN *Finished;
99 UINT64 ExpectedTime;
100 UINT64 CurrentTime;
101 UINT64 TotalTime;
102 EFI_EVENT WaitEvent;
103 } CPU_AP_DATA;
104
105 //
106 // Basic CPU information saved in Guided HOB.
107 // Because the contents will be shard between PEI and DXE,
108 // we need to make sure the each fields offset same in different
109 // architecture.
110 //
111 typedef struct {
112 UINT32 InitialApicId;
113 UINT32 ApicId;
114 UINT32 Health;
115 } CPU_INFO_IN_HOB;
116
117 //
118 // AP reset code information including code address and size,
119 // this structure will be shared be C code and assembly code.
120 // It is natural aligned by design.
121 //
122 typedef struct {
123 UINT8 *RendezvousFunnelAddress;
124 UINTN ModeEntryOffset;
125 UINTN RendezvousFunnelSize;
126 UINT8 *RelocateApLoopFuncAddress;
127 UINTN RelocateApLoopFuncSize;
128 } MP_ASSEMBLY_ADDRESS_MAP;
129
130 typedef struct _CPU_MP_DATA CPU_MP_DATA;
131
132 #pragma pack(1)
133
134 //
135 // MP CPU exchange information for AP reset code
136 // This structure is required to be packed because fixed field offsets
137 // into this structure are used in assembly code in this module
138 //
139 typedef struct {
140 UINTN Lock;
141 UINTN StackStart;
142 UINTN StackSize;
143 UINTN CFunction;
144 IA32_DESCRIPTOR GdtrProfile;
145 IA32_DESCRIPTOR IdtrProfile;
146 UINTN BufferStart;
147 UINTN ModeOffset;
148 UINTN NumApsExecuting;
149 UINTN CodeSegment;
150 UINTN DataSegment;
151 UINTN EnableExecuteDisable;
152 UINTN Cr3;
153 CPU_MP_DATA *CpuMpData;
154 } MP_CPU_EXCHANGE_INFO;
155
156 #pragma pack()
157
158 //
159 // CPU MP Data save in memory
160 //
161 struct _CPU_MP_DATA {
162 UINT64 CpuInfoInHob;
163 UINT32 CpuCount;
164 UINT32 BspNumber;
165 //
166 // The above fields data will be passed from PEI to DXE
167 // Please make sure the fields offset same in the different
168 // architecture.
169 //
170 SPIN_LOCK MpLock;
171 UINTN Buffer;
172 UINTN CpuApStackSize;
173 MP_ASSEMBLY_ADDRESS_MAP AddressMap;
174 UINTN WakeupBuffer;
175 UINTN BackupBuffer;
176 UINTN BackupBufferSize;
177 BOOLEAN EndOfPeiFlag;
178
179 volatile UINT32 StartCount;
180 volatile UINT32 FinishedCount;
181 volatile UINT32 RunningCount;
182 BOOLEAN SingleThread;
183 EFI_AP_PROCEDURE Procedure;
184 VOID *ProcArguments;
185 BOOLEAN *Finished;
186 UINT64 ExpectedTime;
187 UINT64 CurrentTime;
188 UINT64 TotalTime;
189 EFI_EVENT WaitEvent;
190 UINTN **FailedCpuList;
191
192 AP_INIT_STATE InitFlag;
193 BOOLEAN X2ApicEnable;
194 MTRR_SETTINGS MtrrTable;
195 UINT8 ApLoopMode;
196 UINT8 ApTargetCState;
197 UINT16 PmCodeSegment;
198 CPU_AP_DATA *CpuData;
199 volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo;
200 };
201 /**
202 Assembly code to place AP into safe loop mode.
203
204 Place AP into targeted C-State if MONITOR is supported, otherwise
205 place AP into hlt state.
206 Place AP in protected mode if the current is long mode. Due to AP maybe
207 wakeup by some hardware event. It could avoid accessing page table that
208 may not available during booting to OS.
209
210 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
211 FALSE indicates MONITOR is not supported.
212 @param[in] ApTargetCState Target C-State value.
213 @param[in] PmCodeSegment Protected mode code segment value.
214 **/
215 typedef
216 VOID
217 (EFIAPI * ASM_RELOCATE_AP_LOOP) (
218 IN BOOLEAN MwaitSupport,
219 IN UINTN ApTargetCState,
220 IN UINTN PmCodeSegment
221 );
222
223 /**
224 Assembly code to get starting address and size of the rendezvous entry for APs.
225 Information for fixing a jump instruction in the code is also returned.
226
227 @param[out] AddressMap Output buffer for address map information.
228 **/
229 VOID
230 EFIAPI
231 AsmGetAddressMap (
232 OUT MP_ASSEMBLY_ADDRESS_MAP *AddressMap
233 );
234
235 /**
236 Detect whether specified processor can find matching microcode patch and load it.
237
238 @param[in] PeiCpuMpData Pointer to PEI CPU MP Data
239 **/
240 VOID
241 MicrocodeDetect (
242 IN CPU_MP_DATA *CpuMpData
243 );
244
245 #endif
246