2 Common header file for MP Initialize Library.
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
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.
20 #include <Register/Cpuid.h>
21 #include <Register/Msr.h>
22 #include <Register/LocalApic.h>
23 #include <Register/Microcode.h>
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>
38 #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P')
40 #define CPU_INIT_MP_LIB_HOB_GUID \
42 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \
46 // AP loop state when APs are in idle state
47 // It's value is the same with PcdCpuApLoopMode
56 // AP initialization state during APs wakeup
76 // CPU volatile registers around INIT-SIPI-SIPI
88 } CPU_VOLATILE_REGISTERS
;
95 volatile UINT32
*StartupApSignal
;
96 volatile UINTN ApFunction
;
97 volatile UINTN ApFunctionArgument
;
102 volatile CPU_STATE State
;
103 CPU_VOLATILE_REGISTERS VolatileRegisters
;
113 // Basic CPU information saved in Guided HOB.
114 // Because the contents will be shard between PEI and DXE,
115 // we need to make sure the each fields offset same in different
119 UINT32 InitialApicId
;
125 // AP reset code information including code address and size,
126 // this structure will be shared be C code and assembly code.
127 // It is natural aligned by design.
130 UINT8
*RendezvousFunnelAddress
;
131 UINTN ModeEntryOffset
;
132 UINTN RendezvousFunnelSize
;
133 UINT8
*RelocateApLoopFuncAddress
;
134 UINTN RelocateApLoopFuncSize
;
135 } MP_ASSEMBLY_ADDRESS_MAP
;
137 typedef struct _CPU_MP_DATA CPU_MP_DATA
;
142 // MP CPU exchange information for AP reset code
143 // This structure is required to be packed because fixed field offsets
144 // into this structure are used in assembly code in this module
151 IA32_DESCRIPTOR GdtrProfile
;
152 IA32_DESCRIPTOR IdtrProfile
;
155 UINTN NumApsExecuting
;
158 UINTN EnableExecuteDisable
;
160 CPU_MP_DATA
*CpuMpData
;
161 } MP_CPU_EXCHANGE_INFO
;
166 // CPU MP Data save in memory
168 struct _CPU_MP_DATA
{
173 // The above fields data will be passed from PEI to DXE
174 // Please make sure the fields offset same in the different
179 UINTN CpuApStackSize
;
180 MP_ASSEMBLY_ADDRESS_MAP AddressMap
;
183 UINTN BackupBufferSize
;
184 BOOLEAN EndOfPeiFlag
;
186 volatile UINT32 StartCount
;
187 volatile UINT32 FinishedCount
;
188 volatile UINT32 RunningCount
;
189 BOOLEAN SingleThread
;
190 EFI_AP_PROCEDURE Procedure
;
197 UINTN
**FailedCpuList
;
199 AP_INIT_STATE InitFlag
;
200 BOOLEAN X2ApicEnable
;
201 MTRR_SETTINGS MtrrTable
;
203 UINT8 ApTargetCState
;
204 UINT16 PmCodeSegment
;
205 CPU_AP_DATA
*CpuData
;
206 volatile MP_CPU_EXCHANGE_INFO
*MpCpuExchangeInfo
;
209 extern EFI_GUID mCpuInitMpLibHobGuid
;
212 Assembly code to place AP into safe loop mode.
214 Place AP into targeted C-State if MONITOR is supported, otherwise
215 place AP into hlt state.
216 Place AP in protected mode if the current is long mode. Due to AP maybe
217 wakeup by some hardware event. It could avoid accessing page table that
218 may not available during booting to OS.
220 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
221 FALSE indicates MONITOR is not supported.
222 @param[in] ApTargetCState Target C-State value.
223 @param[in] PmCodeSegment Protected mode code segment value.
227 (EFIAPI
* ASM_RELOCATE_AP_LOOP
) (
228 IN BOOLEAN MwaitSupport
,
229 IN UINTN ApTargetCState
,
230 IN UINTN PmCodeSegment
234 Assembly code to get starting address and size of the rendezvous entry for APs.
235 Information for fixing a jump instruction in the code is also returned.
237 @param[out] AddressMap Output buffer for address map information.
242 OUT MP_ASSEMBLY_ADDRESS_MAP
*AddressMap
246 Get the pointer to CPU MP Data structure.
248 @return The pointer to CPU MP Data structure.
256 Save the pointer to CPU MP Data structure.
258 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
262 IN CPU_MP_DATA
*CpuMpData
266 Allocate reset vector buffer.
268 @param[in, out] CpuMpData The pointer to CPU MP Data structure.
271 AllocateResetVector (
272 IN OUT CPU_MP_DATA
*CpuMpData
276 Free AP reset vector buffer.
278 @param[in] CpuMpData The pointer to CPU MP Data structure.
282 IN CPU_MP_DATA
*CpuMpData
286 This function will be called by BSP to wakeup AP.
288 @param[in] CpuMpData Pointer to CPU MP Data
289 @param[in] Broadcast TRUE: Send broadcast IPI to all APs
290 FALSE: Send IPI to AP by ApicId
291 @param[in] ProcessorNumber The handle number of specified processor
292 @param[in] Procedure The function to be invoked by AP
293 @param[in] ProcedureArgument The argument to be passed into AP function
297 IN CPU_MP_DATA
*CpuMpData
,
298 IN BOOLEAN Broadcast
,
299 IN UINTN ProcessorNumber
,
300 IN EFI_AP_PROCEDURE Procedure
, OPTIONAL
301 IN VOID
*ProcedureArgument OPTIONAL
305 Initialize global data for MP support.
307 @param[in] CpuMpData The pointer to CPU MP Data structure.
311 IN CPU_MP_DATA
*CpuMpData
315 Get pointer to CPU MP Data structure from GUIDed HOB.
317 @return The pointer to CPU MP Data structure.
320 GetCpuMpDataFromGuidedHob (
325 Detect whether specified processor can find matching microcode patch and load it.
327 @param[in] PeiCpuMpData Pointer to PEI CPU MP Data
331 IN CPU_MP_DATA
*CpuMpData
335 Notify function on End Of PEI PPI.
337 On S3 boot, this function will restore wakeup buffer data.
338 On normal boot, this function will flag wakeup buffer to be un-used type.
340 @param[in] PeiServices The pointer to the PEI Services Table.
341 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
342 @param[in] Ppi Address of the PPI that was installed.
344 @retval EFI_SUCCESS When everything is OK.
348 CpuMpEndOfPeiCallback (
349 IN EFI_PEI_SERVICES
**PeiServices
,
350 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,