]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/Library/CpuCommonFeaturesLib/MonitorMwait.c
UefiCpuPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / Library / CpuCommonFeaturesLib / MonitorMwait.c
CommitLineData
80c4b236
JF
1/** @file\r
2 MonitorMwait feature.\r
3\r
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
0acd8697 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
80c4b236
JF
6\r
7**/\r
8\r
9#include "CpuCommonFeatures.h"\r
10\r
11/**\r
12 Detects if MONITOR/MWAIT feature supported on current processor.\r
13\r
14 @param[in] ProcessorNumber The index of the CPU executing this function.\r
15 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
16 structure for the CPU executing this function.\r
17 @param[in] ConfigData A pointer to the configuration buffer returned\r
18 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
19 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
20 RegisterCpuFeature().\r
21\r
22 @retval TRUE MONITOR/MWAIT feature is supported.\r
23 @retval FALSE MONITOR/MWAIT feature is not supported.\r
24\r
25 @note This service could be called by BSP/APs.\r
26**/\r
27BOOLEAN\r
28EFIAPI\r
29MonitorMwaitSupport (\r
30 IN UINTN ProcessorNumber,\r
31 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
32 IN VOID *ConfigData OPTIONAL\r
33 )\r
34{\r
35 return (CpuInfo->CpuIdVersionInfoEcx.Bits.MONITOR == 1);\r
36}\r
37\r
38/**\r
39 Initializes MONITOR/MWAIT feature to specific state.\r
40\r
41 @param[in] ProcessorNumber The index of the CPU executing this function.\r
42 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION\r
43 structure for the CPU executing this function.\r
44 @param[in] ConfigData A pointer to the configuration buffer returned\r
45 by CPU_FEATURE_GET_CONFIG_DATA. NULL if\r
46 CPU_FEATURE_GET_CONFIG_DATA was not provided in\r
47 RegisterCpuFeature().\r
48 @param[in] State If TRUE, then the MONITOR/MWAIT feature must be enabled.\r
49 If FALSE, then the MONITOR/MWAIT feature must be disabled.\r
50\r
51 @retval RETURN_SUCCESS MONITOR/MWAIT feature is initialized.\r
52\r
53 @note This service could be called by BSP only.\r
54**/\r
55RETURN_STATUS\r
56EFIAPI\r
57MonitorMwaitInitialize (\r
58 IN UINTN ProcessorNumber,\r
59 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,\r
60 IN VOID *ConfigData, OPTIONAL\r
61 IN BOOLEAN State\r
62 )\r
63{\r
d28daadd
ED
64 //\r
65 // The scope of the MSR_IA32_MISC_ENABLE is core for below processor type, only program\r
66 // MSR_IA32_MISC_ENABLE for thread 0 in each core.\r
67 //\r
68 if (IS_CORE2_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||\r
69 IS_ATOM_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||\r
70 IS_GOLDMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||\r
71 IS_SILVERMONT_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||\r
72 IS_PENTIUM_4_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel) ||\r
73 IS_CORE_PROCESSOR (CpuInfo->DisplayFamily, CpuInfo->DisplayModel)) {\r
74 if (CpuInfo->ProcessorInfo.Location.Thread != 0) {\r
75 return RETURN_SUCCESS;\r
76 }\r
77 }\r
78\r
80c4b236
JF
79 CPU_REGISTER_TABLE_WRITE_FIELD (\r
80 ProcessorNumber,\r
81 Msr,\r
82 MSR_IA32_MISC_ENABLE,\r
83 MSR_IA32_MISC_ENABLE_REGISTER,\r
84 Bits.MONITOR,\r
85 (State) ? 1 : 0\r
86 );\r
87 return RETURN_SUCCESS;\r
88}\r