VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/Library/CpuCommonFeaturesLib/ClockModulation.c@ 85718

Last change on this file since 85718 was 80721, checked in by vboxsync, 5 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/** @file
2 Clock Modulation feature.
3
4 Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include "CpuCommonFeatures.h"
10
11typedef struct {
12 CPUID_THERMAL_POWER_MANAGEMENT_EAX ThermalPowerManagementEax;
13 MSR_IA32_CLOCK_MODULATION_REGISTER ClockModulation;
14} CLOCK_MODULATION_CONFIG_DATA;
15
16/**
17 Prepares for the data used by CPU feature detection and initialization.
18
19 @param[in] NumberOfProcessors The number of CPUs in the platform.
20
21 @return Pointer to a buffer of CPU related configuration data.
22
23 @note This service could be called by BSP only.
24**/
25VOID *
26EFIAPI
27ClockModulationGetConfigData (
28 IN UINTN NumberOfProcessors
29 )
30{
31 UINT32 *ConfigData;
32
33 ConfigData = AllocateZeroPool (sizeof (CLOCK_MODULATION_CONFIG_DATA) * NumberOfProcessors);
34 ASSERT (ConfigData != NULL);
35 return ConfigData;
36}
37
38/**
39 Detects if Clock Modulation feature supported on current processor.
40
41 @param[in] ProcessorNumber The index of the CPU executing this function.
42 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
43 structure for the CPU executing this function.
44 @param[in] ConfigData A pointer to the configuration buffer returned
45 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
46 CPU_FEATURE_GET_CONFIG_DATA was not provided in
47 RegisterCpuFeature().
48
49 @retval TRUE Clock Modulation feature is supported.
50 @retval FALSE Clock Modulation feature is not supported.
51
52 @note This service could be called by BSP/APs.
53**/
54BOOLEAN
55EFIAPI
56ClockModulationSupport (
57 IN UINTN ProcessorNumber,
58 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
59 IN VOID *ConfigData OPTIONAL
60 )
61{
62 CLOCK_MODULATION_CONFIG_DATA *CmConfigData;
63
64 if (CpuInfo->CpuIdVersionInfoEdx.Bits.ACPI == 1) {
65 CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *) ConfigData;
66 ASSERT (CmConfigData != NULL);
67 AsmCpuid (
68 CPUID_THERMAL_POWER_MANAGEMENT,
69 &CmConfigData[ProcessorNumber].ThermalPowerManagementEax.Uint32,
70 NULL,
71 NULL,
72 NULL
73 );
74 CmConfigData[ProcessorNumber].ClockModulation.Uint64 = AsmReadMsr64 (MSR_IA32_CLOCK_MODULATION);
75 return TRUE;
76 }
77 return FALSE;
78}
79
80/**
81 Initializes Clock Modulation feature to specific state.
82
83 @param[in] ProcessorNumber The index of the CPU executing this function.
84 @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION
85 structure for the CPU executing this function.
86 @param[in] ConfigData A pointer to the configuration buffer returned
87 by CPU_FEATURE_GET_CONFIG_DATA. NULL if
88 CPU_FEATURE_GET_CONFIG_DATA was not provided in
89 RegisterCpuFeature().
90 @param[in] State If TRUE, then the Clock Modulation feature must be enabled.
91 If FALSE, then the Clock Modulation feature must be disabled.
92
93 @retval RETURN_SUCCESS Clock Modulation feature is initialized.
94
95 @note This service could be called by BSP only.
96**/
97RETURN_STATUS
98EFIAPI
99ClockModulationInitialize (
100 IN UINTN ProcessorNumber,
101 IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo,
102 IN VOID *ConfigData, OPTIONAL
103 IN BOOLEAN State
104 )
105{
106 CLOCK_MODULATION_CONFIG_DATA *CmConfigData;
107 MSR_IA32_CLOCK_MODULATION_REGISTER *ClockModulation;
108
109 CmConfigData = (CLOCK_MODULATION_CONFIG_DATA *) ConfigData;
110 ASSERT (CmConfigData != NULL);
111 ClockModulation = &CmConfigData[ProcessorNumber].ClockModulation;
112
113 if (State) {
114 ClockModulation->Bits.OnDemandClockModulationEnable = 1;
115 ClockModulation->Bits.OnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) >> 1;
116 if (CmConfigData[ProcessorNumber].ThermalPowerManagementEax.Bits.ECMD == 1) {
117 ClockModulation->Bits.ExtendedOnDemandClockModulationDutyCycle = PcdGet8 (PcdCpuClockModulationDutyCycle) & BIT0;
118 }
119 } else {
120 ClockModulation->Bits.OnDemandClockModulationEnable = 0;
121 }
122
123 CPU_REGISTER_TABLE_WRITE64 (
124 ProcessorNumber,
125 Msr,
126 MSR_IA32_CLOCK_MODULATION,
127 ClockModulation->Uint64
128 );
129
130 return RETURN_SUCCESS;
131}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette