2 CPU MP Initialize Library common functions.
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.
19 Detect whether Mwait-monitor feature is supported.
21 @retval TRUE Mwait-monitor feature is supported.
22 @retval FALSE Mwait-monitor feature is not supported.
29 CPUID_VERSION_INFO_ECX VersionInfoEcx
;
31 AsmCpuid (CPUID_VERSION_INFO
, NULL
, NULL
, &VersionInfoEcx
.Uint32
, NULL
);
32 return (VersionInfoEcx
.Bits
.MONITOR
== 1) ? TRUE
: FALSE
;
38 @param[out] MonitorFilterSize Returns the largest monitor-line size in bytes.
40 @return The AP loop mode.
44 OUT UINT32
*MonitorFilterSize
48 CPUID_MONITOR_MWAIT_EBX MonitorMwaitEbx
;
50 ASSERT (MonitorFilterSize
!= NULL
);
52 ApLoopMode
= PcdGet8 (PcdCpuApLoopMode
);
53 ASSERT (ApLoopMode
>= ApInHltLoop
&& ApLoopMode
<= ApInRunLoop
);
54 if (ApLoopMode
== ApInMwaitLoop
) {
55 if (!IsMwaitSupport ()) {
57 // If processor does not support MONITOR/MWAIT feature,
58 // force AP in Hlt-loop mode
60 ApLoopMode
= ApInHltLoop
;
64 if (ApLoopMode
!= ApInMwaitLoop
) {
65 *MonitorFilterSize
= sizeof (UINT32
);
68 // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes
69 // CPUID.[EAX=05H].EDX: C-states supported using MWAIT
71 AsmCpuid (CPUID_MONITOR_MWAIT
, NULL
, &MonitorMwaitEbx
.Uint32
, NULL
, NULL
);
72 *MonitorFilterSize
= MonitorMwaitEbx
.Bits
.LargestMonitorLineSize
;
78 MP Initialize Library initialization.
80 This service will allocate AP reset vector and wakeup all APs to do APs
83 This service must be invoked before all other MP Initialize Library
86 @retval EFI_SUCCESS MP initialization succeeds.
87 @retval Others MP initialization fails.
96 UINT32 MaxLogicalProcessorNumber
;
98 MP_ASSEMBLY_ADDRESS_MAP AddressMap
;
100 UINT32 MonitorFilterSize
;
103 CPU_MP_DATA
*CpuMpData
;
105 UINT8
*MonitorBuffer
;
106 UINTN ApResetVectorSize
;
107 UINTN BackupBufferAddr
;
108 MaxLogicalProcessorNumber
= PcdGet32(PcdCpuMaxLogicalProcessorNumber
);
110 AsmGetAddressMap (&AddressMap
);
111 ApResetVectorSize
= AddressMap
.RendezvousFunnelSize
+ sizeof (MP_CPU_EXCHANGE_INFO
);
112 ApStackSize
= PcdGet32(PcdCpuApStackSize
);
113 ApLoopMode
= GetApLoopMode (&MonitorFilterSize
);
115 BufferSize
= ApStackSize
* MaxLogicalProcessorNumber
;
116 BufferSize
+= MonitorFilterSize
* MaxLogicalProcessorNumber
;
117 BufferSize
+= sizeof (CPU_MP_DATA
);
118 BufferSize
+= ApResetVectorSize
;
119 BufferSize
+= (sizeof (CPU_AP_DATA
) + sizeof (CPU_INFO_IN_HOB
))* MaxLogicalProcessorNumber
;
120 MpBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (BufferSize
));
121 ASSERT (MpBuffer
!= NULL
);
122 ZeroMem (MpBuffer
, BufferSize
);
123 Buffer
= (UINTN
) MpBuffer
;
125 MonitorBuffer
= (UINT8
*) (Buffer
+ ApStackSize
* MaxLogicalProcessorNumber
);
126 BackupBufferAddr
= (UINTN
) MonitorBuffer
+ MonitorFilterSize
* MaxLogicalProcessorNumber
;
127 CpuMpData
= (CPU_MP_DATA
*) (BackupBufferAddr
+ ApResetVectorSize
);
128 CpuMpData
->Buffer
= Buffer
;
129 CpuMpData
->CpuApStackSize
= ApStackSize
;
130 CpuMpData
->BackupBuffer
= BackupBufferAddr
;
131 CpuMpData
->BackupBufferSize
= ApResetVectorSize
;
132 CpuMpData
->EndOfPeiFlag
= FALSE
;
133 CpuMpData
->WakeupBuffer
= (UINTN
) -1;
134 CpuMpData
->CpuCount
= 1;
135 CpuMpData
->BspNumber
= 0;
136 CpuMpData
->WaitEvent
= NULL
;
137 CpuMpData
->CpuData
= (CPU_AP_DATA
*) (CpuMpData
+ 1);
138 CpuMpData
->CpuInfoInHob
= (UINT64
) (UINTN
) (CpuMpData
->CpuData
+ MaxLogicalProcessorNumber
);
139 InitializeSpinLock(&CpuMpData
->MpLock
);
141 // Save assembly code information
143 CopyMem (&CpuMpData
->AddressMap
, &AddressMap
, sizeof (MP_ASSEMBLY_ADDRESS_MAP
));
145 // Finally set AP loop mode
147 CpuMpData
->ApLoopMode
= ApLoopMode
;
148 DEBUG ((DEBUG_INFO
, "AP Loop Mode is %d\n", CpuMpData
->ApLoopMode
));
150 // Store BSP's MTRR setting
152 MtrrGetAllMtrrs (&CpuMpData
->MtrrTable
);
158 Gets detailed MP-related information on the requested processor at the
159 instant this call is made. This service may only be called from the BSP.
161 @param[in] ProcessorNumber The handle number of processor.
162 @param[out] ProcessorInfoBuffer A pointer to the buffer where information for
163 the requested processor is deposited.
164 @param[out] HealthData Return processor health data.
166 @retval EFI_SUCCESS Processor information was returned.
167 @retval EFI_DEVICE_ERROR The calling processor is an AP.
168 @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.
169 @retval EFI_NOT_FOUND The processor with the handle specified by
170 ProcessorNumber does not exist in the platform.
171 @retval EFI_NOT_READY MP Initialize Library is not initialized.
176 MpInitLibGetProcessorInfo (
177 IN UINTN ProcessorNumber
,
178 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
,
179 OUT EFI_HEALTH_FLAGS
*HealthData OPTIONAL
182 return EFI_UNSUPPORTED
;
185 This return the handle number for the calling processor. This service may be
186 called from the BSP and APs.
188 @param[out] ProcessorNumber Pointer to the handle number of AP.
189 The range is from 0 to the total number of
190 logical processors minus 1. The total number of
191 logical processors can be retrieved by
192 MpInitLibGetNumberOfProcessors().
194 @retval EFI_SUCCESS The current processor handle number was returned
196 @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.
197 @retval EFI_NOT_READY MP Initialize Library is not initialized.
203 OUT UINTN
*ProcessorNumber
206 return EFI_UNSUPPORTED
;
209 Retrieves the number of logical processor in the platform and the number of
210 those logical processors that are enabled on this boot. This service may only
211 be called from the BSP.
213 @param[out] NumberOfProcessors Pointer to the total number of logical
214 processors in the system, including the BSP
216 @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical
217 processors that exist in system, including
220 @retval EFI_SUCCESS The number of logical processors and enabled
221 logical processors was retrieved.
222 @retval EFI_DEVICE_ERROR The calling processor is an AP.
223 @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors
225 @retval EFI_NOT_READY MP Initialize Library is not initialized.
230 MpInitLibGetNumberOfProcessors (
231 OUT UINTN
*NumberOfProcessors
, OPTIONAL
232 OUT UINTN
*NumberOfEnabledProcessors OPTIONAL
235 return EFI_UNSUPPORTED
;