]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
OvmfPkg: SmmCpuFeaturesLib: remove unnecessary bits
[mirror_edk2.git] / OvmfPkg / Library / SmmCpuFeaturesLib / SmmCpuFeaturesLib.c
CommitLineData
86d71589
PB
1/** @file\r
2The CPU specific programming for PiSmmCpuDxeSmm module.\r
3\r
4Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <PiSmm.h>\r
16#include <Library/SmmCpuFeaturesLib.h>\r
17#include <Library/BaseLib.h>\r
86d71589
PB
18#include <Library/PcdLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20#include <Library/DebugLib.h>\r
86d71589
PB
21#include <Register/SmramSaveStateMap.h>\r
22\r
86d71589
PB
23/**\r
24 The constructor function\r
25\r
26 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
27 @param[in] SystemTable A pointer to the EFI System Table.\r
28\r
29 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
30\r
31**/\r
32EFI_STATUS\r
33EFIAPI\r
34SmmCpuFeaturesLibConstructor (\r
35 IN EFI_HANDLE ImageHandle,\r
36 IN EFI_SYSTEM_TABLE *SystemTable\r
37 )\r
38{\r
86d71589 39 //\r
d7e71b29 40 // No need to program SMRRs on our virtual platform.\r
86d71589 41 //\r
86d71589
PB
42 return EFI_SUCCESS;\r
43}\r
44\r
45/**\r
46 Called during the very first SMI into System Management Mode to initialize\r
47 CPU features, including SMBASE, for the currently executing CPU. Since this\r
48 is the first SMI, the SMRAM Save State Map is at the default address of\r
49 SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET. The currently executing\r
50 CPU is specified by CpuIndex and CpuIndex can be used to access information\r
51 about the currently executing CPU in the ProcessorInfo array and the\r
52 HotPlugCpuData data structure.\r
53\r
54 @param[in] CpuIndex The index of the CPU to initialize. The value\r
55 must be between 0 and the NumberOfCpus field in\r
56 the System Management System Table (SMST).\r
57 @param[in] IsMonarch TRUE if the CpuIndex is the index of the CPU that\r
58 was elected as monarch during System Management\r
59 Mode initialization.\r
60 FALSE if the CpuIndex is not the index of the CPU\r
61 that was elected as monarch during System\r
62 Management Mode initialization.\r
63 @param[in] ProcessorInfo Pointer to an array of EFI_PROCESSOR_INFORMATION\r
64 structures. ProcessorInfo[CpuIndex] contains the\r
65 information for the currently executing CPU.\r
66 @param[in] CpuHotPlugData Pointer to the CPU_HOT_PLUG_DATA structure that\r
67 contains the ApidId and SmBase arrays.\r
68**/\r
69VOID\r
70EFIAPI\r
71SmmCpuFeaturesInitializeProcessor (\r
72 IN UINTN CpuIndex,\r
73 IN BOOLEAN IsMonarch,\r
74 IN EFI_PROCESSOR_INFORMATION *ProcessorInfo,\r
75 IN CPU_HOT_PLUG_DATA *CpuHotPlugData\r
76 )\r
77{\r
78 SMRAM_SAVE_STATE_MAP *CpuState;\r
86d71589
PB
79\r
80 //\r
81 // Configure SMBASE.\r
82 //\r
83 CpuState = (SMRAM_SAVE_STATE_MAP *)(UINTN)(SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET);\r
84 CpuState->x86.SMBASE = (UINT32)CpuHotPlugData->SmBase[CpuIndex];\r
85\r
86 //\r
d7e71b29 87 // No need to program SMRRs on our virtual platform.\r
86d71589 88 //\r
86d71589
PB
89}\r
90\r
91/**\r
92 This function updates the SMRAM save state on the currently executing CPU\r
93 to resume execution at a specific address after an RSM instruction. This\r
94 function must evaluate the SMRAM save state to determine the execution mode\r
95 the RSM instruction resumes and update the resume execution address with\r
96 either NewInstructionPointer32 or NewInstructionPoint. The auto HALT restart\r
97 flag in the SMRAM save state must always be cleared. This function returns\r
98 the value of the instruction pointer from the SMRAM save state that was\r
99 replaced. If this function returns 0, then the SMRAM save state was not\r
100 modified.\r
101\r
102 This function is called during the very first SMI on each CPU after\r
103 SmmCpuFeaturesInitializeProcessor() to set a flag in normal execution mode\r
104 to signal that the SMBASE of each CPU has been updated before the default\r
105 SMBASE address is used for the first SMI to the next CPU.\r
106\r
107 @param[in] CpuIndex The index of the CPU to hook. The value\r
108 must be between 0 and the NumberOfCpus\r
109 field in the System Management System Table\r
110 (SMST).\r
111 @param[in] CpuState Pointer to SMRAM Save State Map for the\r
112 currently executing CPU.\r
113 @param[in] NewInstructionPointer32 Instruction pointer to use if resuming to\r
114 32-bit execution mode from 64-bit SMM.\r
115 @param[in] NewInstructionPointer Instruction pointer to use if resuming to\r
116 same execution mode as SMM.\r
117\r
118 @retval 0 This function did modify the SMRAM save state.\r
119 @retval > 0 The original instruction pointer value from the SMRAM save state\r
120 before it was replaced.\r
121**/\r
122UINT64\r
123EFIAPI\r
124SmmCpuFeaturesHookReturnFromSmm (\r
125 IN UINTN CpuIndex,\r
126 IN SMRAM_SAVE_STATE_MAP *CpuState,\r
127 IN UINT64 NewInstructionPointer32,\r
128 IN UINT64 NewInstructionPointer\r
129 )\r
130{\r
131 return 0;\r
132}\r
133\r
134/**\r
135 Hook point in normal execution mode that allows the one CPU that was elected\r
136 as monarch during System Management Mode initialization to perform additional\r
137 initialization actions immediately after all of the CPUs have processed their\r
138 first SMI and called SmmCpuFeaturesInitializeProcessor() relocating SMBASE\r
139 into a buffer in SMRAM and called SmmCpuFeaturesHookReturnFromSmm().\r
140**/\r
141VOID\r
142EFIAPI\r
143SmmCpuFeaturesSmmRelocationComplete (\r
144 VOID\r
145 )\r
146{\r
147}\r
148\r
149/**\r
150 Return the size, in bytes, of a custom SMI Handler in bytes. If 0 is\r
151 returned, then a custom SMI handler is not provided by this library,\r
152 and the default SMI handler must be used.\r
153\r
154 @retval 0 Use the default SMI handler.\r
155 @retval > 0 Use the SMI handler installed by SmmCpuFeaturesInstallSmiHandler()\r
156 The caller is required to allocate enough SMRAM for each CPU to\r
157 support the size of the custom SMI handler.\r
158**/\r
159UINTN\r
160EFIAPI\r
161SmmCpuFeaturesGetSmiHandlerSize (\r
162 VOID\r
163 )\r
164{\r
165 return 0;\r
166}\r
167\r
168/**\r
169 Install a custom SMI handler for the CPU specified by CpuIndex. This function\r
170 is only called if SmmCpuFeaturesGetSmiHandlerSize() returns a size is greater\r
171 than zero and is called by the CPU that was elected as monarch during System\r
172 Management Mode initialization.\r
173\r
174 @param[in] CpuIndex The index of the CPU to install the custom SMI handler.\r
175 The value must be between 0 and the NumberOfCpus field\r
176 in the System Management System Table (SMST).\r
177 @param[in] SmBase The SMBASE address for the CPU specified by CpuIndex.\r
178 @param[in] SmiStack The stack to use when an SMI is processed by the\r
179 the CPU specified by CpuIndex.\r
180 @param[in] StackSize The size, in bytes, if the stack used when an SMI is\r
181 processed by the CPU specified by CpuIndex.\r
182 @param[in] GdtBase The base address of the GDT to use when an SMI is\r
183 processed by the CPU specified by CpuIndex.\r
184 @param[in] GdtSize The size, in bytes, of the GDT used when an SMI is\r
185 processed by the CPU specified by CpuIndex.\r
186 @param[in] IdtBase The base address of the IDT to use when an SMI is\r
187 processed by the CPU specified by CpuIndex.\r
188 @param[in] IdtSize The size, in bytes, of the IDT used when an SMI is\r
189 processed by the CPU specified by CpuIndex.\r
190 @param[in] Cr3 The base address of the page tables to use when an SMI\r
191 is processed by the CPU specified by CpuIndex.\r
192**/\r
193VOID\r
194EFIAPI\r
195SmmCpuFeaturesInstallSmiHandler (\r
196 IN UINTN CpuIndex,\r
197 IN UINT32 SmBase,\r
198 IN VOID *SmiStack,\r
199 IN UINTN StackSize,\r
200 IN UINTN GdtBase,\r
201 IN UINTN GdtSize,\r
202 IN UINTN IdtBase,\r
203 IN UINTN IdtSize,\r
204 IN UINT32 Cr3\r
205 )\r
206{\r
207}\r
208\r
209/**\r
210 Determines if MTRR registers must be configured to set SMRAM cache-ability\r
211 when executing in System Management Mode.\r
212\r
213 @retval TRUE MTRR registers must be configured to set SMRAM cache-ability.\r
214 @retval FALSE MTRR registers do not need to be configured to set SMRAM\r
215 cache-ability.\r
216**/\r
217BOOLEAN\r
218EFIAPI\r
219SmmCpuFeaturesNeedConfigureMtrrs (\r
220 VOID\r
221 )\r
222{\r
d7e71b29 223 return FALSE;\r
86d71589
PB
224}\r
225\r
226/**\r
227 Disable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigureMtrrs()\r
228 returns TRUE.\r
229**/\r
230VOID\r
231EFIAPI\r
232SmmCpuFeaturesDisableSmrr (\r
233 VOID\r
234 )\r
235{\r
d7e71b29
PB
236 //\r
237 // No SMRR support, nothing to do\r
238 //\r
86d71589
PB
239}\r
240\r
241/**\r
242 Enable SMRR register if SMRR is supported and SmmCpuFeaturesNeedConfigureMtrrs()\r
243 returns TRUE.\r
244**/\r
245VOID\r
246EFIAPI\r
247SmmCpuFeaturesReenableSmrr (\r
248 VOID\r
249 )\r
250{\r
d7e71b29
PB
251 //\r
252 // No SMRR support, nothing to do\r
253 //\r
86d71589
PB
254}\r
255\r
256/**\r
257 Processor specific hook point each time a CPU enters System Management Mode.\r
258\r
259 @param[in] CpuIndex The index of the CPU that has entered SMM. The value\r
260 must be between 0 and the NumberOfCpus field in the\r
261 System Management System Table (SMST).\r
262**/\r
263VOID\r
264EFIAPI\r
265SmmCpuFeaturesRendezvousEntry (\r
266 IN UINTN CpuIndex\r
267 )\r
268{\r
269 //\r
d7e71b29 270 // No SMRR support, nothing to do\r
86d71589 271 //\r
86d71589
PB
272}\r
273\r
274/**\r
275 Processor specific hook point each time a CPU exits System Management Mode.\r
276\r
277 @param[in] CpuIndex The index of the CPU that is exiting SMM. The value must\r
278 be between 0 and the NumberOfCpus field in the System\r
279 Management System Table (SMST).\r
280**/\r
281VOID\r
282EFIAPI\r
283SmmCpuFeaturesRendezvousExit (\r
284 IN UINTN CpuIndex\r
285 )\r
286{\r
287}\r
288\r
289/**\r
290 Check to see if an SMM register is supported by a specified CPU.\r
291\r
292 @param[in] CpuIndex The index of the CPU to check for SMM register support.\r
293 The value must be between 0 and the NumberOfCpus field\r
294 in the System Management System Table (SMST).\r
295 @param[in] RegName Identifies the SMM register to check for support.\r
296\r
297 @retval TRUE The SMM register specified by RegName is supported by the CPU\r
298 specified by CpuIndex.\r
299 @retval FALSE The SMM register specified by RegName is not supported by the\r
300 CPU specified by CpuIndex.\r
301**/\r
302BOOLEAN\r
303EFIAPI\r
304SmmCpuFeaturesIsSmmRegisterSupported (\r
305 IN UINTN CpuIndex,\r
306 IN SMM_REG_NAME RegName\r
307 )\r
308{\r
d7e71b29 309 ASSERT (RegName == SmmRegFeatureControl);\r
86d71589
PB
310 return FALSE;\r
311}\r
312\r
313/**\r
314 Returns the current value of the SMM register for the specified CPU.\r
315 If the SMM register is not supported, then 0 is returned.\r
316\r
317 @param[in] CpuIndex The index of the CPU to read the SMM register. The\r
318 value must be between 0 and the NumberOfCpus field in\r
319 the System Management System Table (SMST).\r
320 @param[in] RegName Identifies the SMM register to read.\r
321\r
322 @return The value of the SMM register specified by RegName from the CPU\r
323 specified by CpuIndex.\r
324**/\r
325UINT64\r
326EFIAPI\r
327SmmCpuFeaturesGetSmmRegister (\r
328 IN UINTN CpuIndex,\r
329 IN SMM_REG_NAME RegName\r
330 )\r
331{\r
d7e71b29
PB
332 //\r
333 // This is called for SmmRegSmmDelayed, SmmRegSmmBlocked, SmmRegSmmEnable.\r
334 // The last of these should actually be SmmRegSmmDisable, so we can just\r
335 // return FALSE.\r
336 //\r
86d71589
PB
337 return 0;\r
338}\r
339\r
340/**\r
341 Sets the value of an SMM register on a specified CPU.\r
342 If the SMM register is not supported, then no action is performed.\r
343\r
344 @param[in] CpuIndex The index of the CPU to write the SMM register. The\r
345 value must be between 0 and the NumberOfCpus field in\r
346 the System Management System Table (SMST).\r
347 @param[in] RegName Identifies the SMM register to write.\r
348 registers are read-only.\r
349 @param[in] Value The value to write to the SMM register.\r
350**/\r
351VOID\r
352EFIAPI\r
353SmmCpuFeaturesSetSmmRegister (\r
354 IN UINTN CpuIndex,\r
355 IN SMM_REG_NAME RegName,\r
356 IN UINT64 Value\r
357 )\r
358{\r
d7e71b29 359 ASSERT (FALSE);\r
86d71589
PB
360}\r
361\r
362/**\r
363 Read an SMM Save State register on the target processor. If this function\r
364 returns EFI_UNSUPPORTED, then the caller is responsible for reading the\r
365 SMM Save Sate register.\r
366\r
367 @param[in] CpuIndex The index of the CPU to read the SMM Save State. The\r
368 value must be between 0 and the NumberOfCpus field in\r
369 the System Management System Table (SMST).\r
370 @param[in] Register The SMM Save State register to read.\r
371 @param[in] Width The number of bytes to read from the CPU save state.\r
372 @param[out] Buffer Upon return, this holds the CPU register value read\r
373 from the save state.\r
374\r
375 @retval EFI_SUCCESS The register was read from Save State.\r
376 @retval EFI_INVALID_PARAMTER Buffer is NULL.\r
377 @retval EFI_UNSUPPORTED This function does not support reading Register.\r
378\r
379**/\r
380EFI_STATUS\r
381EFIAPI\r
382SmmCpuFeaturesReadSaveStateRegister (\r
383 IN UINTN CpuIndex,\r
384 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
385 IN UINTN Width,\r
386 OUT VOID *Buffer\r
387 )\r
388{\r
389 return EFI_UNSUPPORTED;\r
390}\r
391\r
392/**\r
393 Writes an SMM Save State register on the target processor. If this function\r
394 returns EFI_UNSUPPORTED, then the caller is responsible for writing the\r
395 SMM Save Sate register.\r
396\r
397 @param[in] CpuIndex The index of the CPU to write the SMM Save State. The\r
398 value must be between 0 and the NumberOfCpus field in\r
399 the System Management System Table (SMST).\r
400 @param[in] Register The SMM Save State register to write.\r
401 @param[in] Width The number of bytes to write to the CPU save state.\r
402 @param[in] Buffer Upon entry, this holds the new CPU register value.\r
403\r
404 @retval EFI_SUCCESS The register was written to Save State.\r
405 @retval EFI_INVALID_PARAMTER Buffer is NULL.\r
406 @retval EFI_UNSUPPORTED This function does not support writing Register.\r
407**/\r
408EFI_STATUS\r
409EFIAPI\r
410SmmCpuFeaturesWriteSaveStateRegister (\r
411 IN UINTN CpuIndex,\r
412 IN EFI_SMM_SAVE_STATE_REGISTER Register,\r
413 IN UINTN Width,\r
414 IN CONST VOID *Buffer\r
415 )\r
416{\r
417 return EFI_UNSUPPORTED;\r
418}\r
419\r
420/**\r
421 This function is hook point called after the gEfiSmmReadyToLockProtocolGuid\r
422 notification is completely processed.\r
423**/\r
424VOID\r
425EFIAPI\r
426SmmCpuFeaturesCompleteSmmReadyToLock (\r
427 VOID\r
428 )\r
429{\r
430}\r
431\r
432/**\r
433 This API provides a method for a CPU to allocate a specific region for storing page tables.\r
434\r
435 This API can be called more once to allocate memory for page tables.\r
436\r
437 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
438 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
439 is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
440 returned.\r
441\r
442 This function can also return NULL if there is no preference on where the page tables are allocated in SMRAM.\r
443\r
444 @param Pages The number of 4 KB pages to allocate.\r
445\r
446 @return A pointer to the allocated buffer for page tables.\r
447 @retval NULL Fail to allocate a specific region for storing page tables,\r
448 Or there is no preference on where the page tables are allocated in SMRAM.\r
449\r
450**/\r
451VOID *\r
452EFIAPI\r
453SmmCpuFeaturesAllocatePageTableMemory (\r
454 IN UINTN Pages\r
455 )\r
456{\r
457 return NULL;\r
458}\r
459\r