Commit | Line | Data |
---|---|---|
3e8ad6bd JF |
1 | /** @file\r |
2 | CPU MP Initialize Library common functions.\r | |
3 | \r | |
4 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "MpLib.h"\r | |
16 | \r | |
17 | \r | |
9ebcf0f4 JF |
18 | /**\r |
19 | Detect whether Mwait-monitor feature is supported.\r | |
20 | \r | |
21 | @retval TRUE Mwait-monitor feature is supported.\r | |
22 | @retval FALSE Mwait-monitor feature is not supported.\r | |
23 | **/\r | |
24 | BOOLEAN\r | |
25 | IsMwaitSupport (\r | |
26 | VOID\r | |
27 | )\r | |
28 | {\r | |
29 | CPUID_VERSION_INFO_ECX VersionInfoEcx;\r | |
30 | \r | |
31 | AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, &VersionInfoEcx.Uint32, NULL);\r | |
32 | return (VersionInfoEcx.Bits.MONITOR == 1) ? TRUE : FALSE;\r | |
33 | }\r | |
34 | \r | |
35 | /**\r | |
36 | Get AP loop mode.\r | |
37 | \r | |
38 | @param[out] MonitorFilterSize Returns the largest monitor-line size in bytes.\r | |
39 | \r | |
40 | @return The AP loop mode.\r | |
41 | **/\r | |
42 | UINT8\r | |
43 | GetApLoopMode (\r | |
44 | OUT UINT32 *MonitorFilterSize\r | |
45 | )\r | |
46 | {\r | |
47 | UINT8 ApLoopMode;\r | |
48 | CPUID_MONITOR_MWAIT_EBX MonitorMwaitEbx;\r | |
49 | \r | |
50 | ASSERT (MonitorFilterSize != NULL);\r | |
51 | \r | |
52 | ApLoopMode = PcdGet8 (PcdCpuApLoopMode);\r | |
53 | ASSERT (ApLoopMode >= ApInHltLoop && ApLoopMode <= ApInRunLoop);\r | |
54 | if (ApLoopMode == ApInMwaitLoop) {\r | |
55 | if (!IsMwaitSupport ()) {\r | |
56 | //\r | |
57 | // If processor does not support MONITOR/MWAIT feature,\r | |
58 | // force AP in Hlt-loop mode\r | |
59 | //\r | |
60 | ApLoopMode = ApInHltLoop;\r | |
61 | }\r | |
62 | }\r | |
63 | \r | |
64 | if (ApLoopMode != ApInMwaitLoop) {\r | |
65 | *MonitorFilterSize = sizeof (UINT32);\r | |
66 | } else {\r | |
67 | //\r | |
68 | // CPUID.[EAX=05H]:EBX.BIT0-15: Largest monitor-line size in bytes\r | |
69 | // CPUID.[EAX=05H].EDX: C-states supported using MWAIT\r | |
70 | //\r | |
71 | AsmCpuid (CPUID_MONITOR_MWAIT, NULL, &MonitorMwaitEbx.Uint32, NULL, NULL);\r | |
72 | *MonitorFilterSize = MonitorMwaitEbx.Bits.LargestMonitorLineSize;\r | |
73 | }\r | |
74 | \r | |
75 | return ApLoopMode;\r | |
76 | }\r | |
3e8ad6bd JF |
77 | /**\r |
78 | MP Initialize Library initialization.\r | |
79 | \r | |
80 | This service will allocate AP reset vector and wakeup all APs to do APs\r | |
81 | initialization.\r | |
82 | \r | |
83 | This service must be invoked before all other MP Initialize Library\r | |
84 | service are invoked.\r | |
85 | \r | |
86 | @retval EFI_SUCCESS MP initialization succeeds.\r | |
87 | @retval Others MP initialization fails.\r | |
88 | \r | |
89 | **/\r | |
90 | EFI_STATUS\r | |
91 | EFIAPI\r | |
92 | MpInitLibInitialize (\r | |
93 | VOID\r | |
94 | )\r | |
95 | {\r | |
e59f8f6b JF |
96 | UINT32 MaxLogicalProcessorNumber;\r |
97 | UINT32 ApStackSize;\r | |
f7f85d83 | 98 | MP_ASSEMBLY_ADDRESS_MAP AddressMap;\r |
e59f8f6b | 99 | UINTN BufferSize;\r |
9ebcf0f4 | 100 | UINT32 MonitorFilterSize;\r |
e59f8f6b JF |
101 | VOID *MpBuffer;\r |
102 | UINTN Buffer;\r | |
103 | CPU_MP_DATA *CpuMpData;\r | |
9ebcf0f4 | 104 | UINT8 ApLoopMode;\r |
e59f8f6b | 105 | UINT8 *MonitorBuffer;\r |
f7f85d83 | 106 | UINTN ApResetVectorSize;\r |
e59f8f6b JF |
107 | UINTN BackupBufferAddr;\r |
108 | MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber);\r | |
f7f85d83 JF |
109 | \r |
110 | AsmGetAddressMap (&AddressMap);\r | |
111 | ApResetVectorSize = AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_EXCHANGE_INFO);\r | |
e59f8f6b | 112 | ApStackSize = PcdGet32(PcdCpuApStackSize);\r |
9ebcf0f4 JF |
113 | ApLoopMode = GetApLoopMode (&MonitorFilterSize);\r |
114 | \r | |
e59f8f6b JF |
115 | BufferSize = ApStackSize * MaxLogicalProcessorNumber;\r |
116 | BufferSize += MonitorFilterSize * MaxLogicalProcessorNumber;\r | |
117 | BufferSize += sizeof (CPU_MP_DATA);\r | |
118 | BufferSize += ApResetVectorSize;\r | |
119 | BufferSize += (sizeof (CPU_AP_DATA) + sizeof (CPU_INFO_IN_HOB))* MaxLogicalProcessorNumber;\r | |
120 | MpBuffer = AllocatePages (EFI_SIZE_TO_PAGES (BufferSize));\r | |
121 | ASSERT (MpBuffer != NULL);\r | |
122 | ZeroMem (MpBuffer, BufferSize);\r | |
123 | Buffer = (UINTN) MpBuffer;\r | |
124 | \r | |
125 | MonitorBuffer = (UINT8 *) (Buffer + ApStackSize * MaxLogicalProcessorNumber);\r | |
126 | BackupBufferAddr = (UINTN) MonitorBuffer + MonitorFilterSize * MaxLogicalProcessorNumber;\r | |
127 | CpuMpData = (CPU_MP_DATA *) (BackupBufferAddr + ApResetVectorSize);\r | |
128 | CpuMpData->Buffer = Buffer;\r | |
129 | CpuMpData->CpuApStackSize = ApStackSize;\r | |
130 | CpuMpData->BackupBuffer = BackupBufferAddr;\r | |
131 | CpuMpData->BackupBufferSize = ApResetVectorSize;\r | |
132 | CpuMpData->EndOfPeiFlag = FALSE;\r | |
133 | CpuMpData->WakeupBuffer = (UINTN) -1;\r | |
134 | CpuMpData->CpuCount = 1;\r | |
135 | CpuMpData->BspNumber = 0;\r | |
136 | CpuMpData->WaitEvent = NULL;\r | |
137 | CpuMpData->CpuData = (CPU_AP_DATA *) (CpuMpData + 1);\r | |
138 | CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + MaxLogicalProcessorNumber);\r | |
139 | InitializeSpinLock(&CpuMpData->MpLock);\r | |
140 | //\r | |
141 | // Save assembly code information\r | |
142 | //\r | |
143 | CopyMem (&CpuMpData->AddressMap, &AddressMap, sizeof (MP_ASSEMBLY_ADDRESS_MAP));\r | |
144 | //\r | |
145 | // Finally set AP loop mode\r | |
146 | //\r | |
147 | CpuMpData->ApLoopMode = ApLoopMode;\r | |
148 | DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode));\r | |
149 | //\r | |
150 | // Store BSP's MTRR setting\r | |
151 | //\r | |
152 | MtrrGetAllMtrrs (&CpuMpData->MtrrTable);\r | |
153 | \r | |
f7f85d83 | 154 | return EFI_SUCCESS;\r |
3e8ad6bd JF |
155 | }\r |
156 | \r | |
157 | /**\r | |
158 | Gets detailed MP-related information on the requested processor at the\r | |
159 | instant this call is made. This service may only be called from the BSP.\r | |
160 | \r | |
161 | @param[in] ProcessorNumber The handle number of processor.\r | |
162 | @param[out] ProcessorInfoBuffer A pointer to the buffer where information for\r | |
163 | the requested processor is deposited.\r | |
164 | @param[out] HealthData Return processor health data.\r | |
165 | \r | |
166 | @retval EFI_SUCCESS Processor information was returned.\r | |
167 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
168 | @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL.\r | |
169 | @retval EFI_NOT_FOUND The processor with the handle specified by\r | |
170 | ProcessorNumber does not exist in the platform.\r | |
171 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
172 | \r | |
173 | **/\r | |
174 | EFI_STATUS\r | |
175 | EFIAPI\r | |
176 | MpInitLibGetProcessorInfo (\r | |
177 | IN UINTN ProcessorNumber,\r | |
178 | OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer,\r | |
179 | OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL\r | |
180 | )\r | |
181 | {\r | |
182 | return EFI_UNSUPPORTED;\r | |
183 | }\r | |
184 | /**\r | |
185 | This return the handle number for the calling processor. This service may be\r | |
186 | called from the BSP and APs.\r | |
187 | \r | |
188 | @param[out] ProcessorNumber Pointer to the handle number of AP.\r | |
189 | The range is from 0 to the total number of\r | |
190 | logical processors minus 1. The total number of\r | |
191 | logical processors can be retrieved by\r | |
192 | MpInitLibGetNumberOfProcessors().\r | |
193 | \r | |
194 | @retval EFI_SUCCESS The current processor handle number was returned\r | |
195 | in ProcessorNumber.\r | |
196 | @retval EFI_INVALID_PARAMETER ProcessorNumber is NULL.\r | |
197 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
198 | \r | |
199 | **/\r | |
200 | EFI_STATUS\r | |
201 | EFIAPI\r | |
202 | MpInitLibWhoAmI (\r | |
203 | OUT UINTN *ProcessorNumber\r | |
204 | )\r | |
205 | {\r | |
206 | return EFI_UNSUPPORTED;\r | |
207 | }\r | |
208 | /**\r | |
209 | Retrieves the number of logical processor in the platform and the number of\r | |
210 | those logical processors that are enabled on this boot. This service may only\r | |
211 | be called from the BSP.\r | |
212 | \r | |
213 | @param[out] NumberOfProcessors Pointer to the total number of logical\r | |
214 | processors in the system, including the BSP\r | |
215 | and disabled APs.\r | |
216 | @param[out] NumberOfEnabledProcessors Pointer to the number of enabled logical\r | |
217 | processors that exist in system, including\r | |
218 | the BSP.\r | |
219 | \r | |
220 | @retval EFI_SUCCESS The number of logical processors and enabled\r | |
221 | logical processors was retrieved.\r | |
222 | @retval EFI_DEVICE_ERROR The calling processor is an AP.\r | |
223 | @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfEnabledProcessors\r | |
224 | is NULL.\r | |
225 | @retval EFI_NOT_READY MP Initialize Library is not initialized.\r | |
226 | \r | |
227 | **/\r | |
228 | EFI_STATUS\r | |
229 | EFIAPI\r | |
230 | MpInitLibGetNumberOfProcessors (\r | |
231 | OUT UINTN *NumberOfProcessors, OPTIONAL\r | |
232 | OUT UINTN *NumberOfEnabledProcessors OPTIONAL\r | |
233 | )\r | |
234 | {\r | |
235 | return EFI_UNSUPPORTED;\r | |
236 | }\r |