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 CPU_INIT_MP_LIB_HOB_GUID \
40 0x58eb6a19, 0x3699, 0x4c68, { 0xa8, 0x36, 0xda, 0xcd, 0x8e, 0xdc, 0xad, 0x4a } \
44 // AP loop state when APs are in idle state
45 // It's value is the same with PcdCpuApLoopMode
54 // AP initialization state during APs wakeup
74 // CPU volatile registers around INIT-SIPI-SIPI
86 } CPU_VOLATILE_REGISTERS
;
93 volatile UINT32
*StartupApSignal
;
94 volatile UINTN ApFunction
;
95 volatile UINTN ApFunctionArgument
;
100 volatile CPU_STATE State
;
101 CPU_VOLATILE_REGISTERS VolatileRegisters
;
111 // Basic CPU information saved in Guided HOB.
112 // Because the contents will be shard between PEI and DXE,
113 // we need to make sure the each fields offset same in different
117 UINT32 InitialApicId
;
123 // AP reset code information including code address and size,
124 // this structure will be shared be C code and assembly code.
125 // It is natural aligned by design.
128 UINT8
*RendezvousFunnelAddress
;
129 UINTN ModeEntryOffset
;
130 UINTN RendezvousFunnelSize
;
131 UINT8
*RelocateApLoopFuncAddress
;
132 UINTN RelocateApLoopFuncSize
;
133 } MP_ASSEMBLY_ADDRESS_MAP
;
135 typedef struct _CPU_MP_DATA CPU_MP_DATA
;
140 // MP CPU exchange information for AP reset code
141 // This structure is required to be packed because fixed field offsets
142 // into this structure are used in assembly code in this module
149 IA32_DESCRIPTOR GdtrProfile
;
150 IA32_DESCRIPTOR IdtrProfile
;
153 UINTN NumApsExecuting
;
156 UINTN EnableExecuteDisable
;
158 CPU_MP_DATA
*CpuMpData
;
159 } MP_CPU_EXCHANGE_INFO
;
164 // CPU MP Data save in memory
166 struct _CPU_MP_DATA
{
171 // The above fields data will be passed from PEI to DXE
172 // Please make sure the fields offset same in the different
177 UINTN CpuApStackSize
;
178 MP_ASSEMBLY_ADDRESS_MAP AddressMap
;
181 UINTN BackupBufferSize
;
182 BOOLEAN EndOfPeiFlag
;
184 volatile UINT32 StartCount
;
185 volatile UINT32 FinishedCount
;
186 volatile UINT32 RunningCount
;
187 BOOLEAN SingleThread
;
188 EFI_AP_PROCEDURE Procedure
;
195 UINTN
**FailedCpuList
;
197 AP_INIT_STATE InitFlag
;
198 BOOLEAN X2ApicEnable
;
199 MTRR_SETTINGS MtrrTable
;
201 UINT8 ApTargetCState
;
202 UINT16 PmCodeSegment
;
203 CPU_AP_DATA
*CpuData
;
204 volatile MP_CPU_EXCHANGE_INFO
*MpCpuExchangeInfo
;
207 extern EFI_GUID mCpuInitMpLibHobGuid
;
210 Assembly code to place AP into safe loop mode.
212 Place AP into targeted C-State if MONITOR is supported, otherwise
213 place AP into hlt state.
214 Place AP in protected mode if the current is long mode. Due to AP maybe
215 wakeup by some hardware event. It could avoid accessing page table that
216 may not available during booting to OS.
218 @param[in] MwaitSupport TRUE indicates MONITOR is supported.
219 FALSE indicates MONITOR is not supported.
220 @param[in] ApTargetCState Target C-State value.
221 @param[in] PmCodeSegment Protected mode code segment value.
225 (EFIAPI
* ASM_RELOCATE_AP_LOOP
) (
226 IN BOOLEAN MwaitSupport
,
227 IN UINTN ApTargetCState
,
228 IN UINTN PmCodeSegment
232 Assembly code to get starting address and size of the rendezvous entry for APs.
233 Information for fixing a jump instruction in the code is also returned.
235 @param[out] AddressMap Output buffer for address map information.
240 OUT MP_ASSEMBLY_ADDRESS_MAP
*AddressMap
244 Get the pointer to CPU MP Data structure.
246 @return The pointer to CPU MP Data structure.
254 Save the pointer to CPU MP Data structure.
256 @param[in] CpuMpData The pointer to CPU MP Data structure will be saved.
260 IN CPU_MP_DATA
*CpuMpData
264 Initialize global data for MP support.
266 @param[in] CpuMpData The pointer to CPU MP Data structure.
270 IN CPU_MP_DATA
*CpuMpData
274 Get pointer to CPU MP Data structure from GUIDed HOB.
276 @return The pointer to CPU MP Data structure.
279 GetCpuMpDataFromGuidedHob (
284 Detect whether specified processor can find matching microcode patch and load it.
286 @param[in] PeiCpuMpData Pointer to PEI CPU MP Data
290 IN CPU_MP_DATA
*CpuMpData
294 Notify function on End Of PEI PPI.
296 On S3 boot, this function will restore wakeup buffer data.
297 On normal boot, this function will flag wakeup buffer to be un-used type.
299 @param[in] PeiServices The pointer to the PEI Services Table.
300 @param[in] NotifyDescriptor Address of the notification descriptor data structure.
301 @param[in] Ppi Address of the PPI that was installed.
303 @retval EFI_SUCCESS When everything is OK.
307 CpuMpEndOfPeiCallback (
308 IN EFI_PEI_SERVICES
**PeiServices
,
309 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,