2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <linux/delay.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
30 #include "amd_powerplay.h"
31 #include "vega20_smumgr.h"
32 #include "hardwaremanager.h"
33 #include "ppatomfwctrl.h"
34 #include "atomfirmware.h"
35 #include "cgs_common.h"
36 #include "vega20_powertune.h"
37 #include "vega20_inc.h"
38 #include "pppcielanes.h"
39 #include "vega20_hwmgr.h"
40 #include "vega20_processpptables.h"
41 #include "vega20_pptable.h"
42 #include "vega20_thermal.h"
43 #include "vega20_ppsmc.h"
45 #include "amd_pcie_helpers.h"
46 #include "ppinterrupt.h"
47 #include "pp_overdriver.h"
48 #include "pp_thermal.h"
49 #include "soc15_common.h"
50 #include "vega20_baco.h"
51 #include "smuio/smuio_9_0_offset.h"
52 #include "smuio/smuio_9_0_sh_mask.h"
53 #include "nbio/nbio_7_4_sh_mask.h"
55 #define smnPCIE_LC_SPEED_CNTL 0x11140290
56 #define smnPCIE_LC_LINK_WIDTH_CNTL 0x11140288
58 static void vega20_set_default_registry_data(struct pp_hwmgr *hwmgr)
60 struct vega20_hwmgr *data =
61 (struct vega20_hwmgr *)(hwmgr->backend);
63 data->gfxclk_average_alpha = PPVEGA20_VEGA20GFXCLKAVERAGEALPHA_DFLT;
64 data->socclk_average_alpha = PPVEGA20_VEGA20SOCCLKAVERAGEALPHA_DFLT;
65 data->uclk_average_alpha = PPVEGA20_VEGA20UCLKCLKAVERAGEALPHA_DFLT;
66 data->gfx_activity_average_alpha = PPVEGA20_VEGA20GFXACTIVITYAVERAGEALPHA_DFLT;
67 data->lowest_uclk_reserved_for_ulv = PPVEGA20_VEGA20LOWESTUCLKRESERVEDFORULV_DFLT;
69 data->display_voltage_mode = PPVEGA20_VEGA20DISPLAYVOLTAGEMODE_DFLT;
70 data->dcef_clk_quad_eqn_a = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
71 data->dcef_clk_quad_eqn_b = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
72 data->dcef_clk_quad_eqn_c = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
73 data->disp_clk_quad_eqn_a = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
74 data->disp_clk_quad_eqn_b = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
75 data->disp_clk_quad_eqn_c = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
76 data->pixel_clk_quad_eqn_a = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
77 data->pixel_clk_quad_eqn_b = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
78 data->pixel_clk_quad_eqn_c = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
79 data->phy_clk_quad_eqn_a = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
80 data->phy_clk_quad_eqn_b = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
81 data->phy_clk_quad_eqn_c = PPREGKEY_VEGA20QUADRATICEQUATION_DFLT;
84 * Disable the following features for now:
93 data->registry_data.disallowed_features = 0xE0041C00;
94 data->registry_data.od_state_in_dc_support = 0;
95 data->registry_data.thermal_support = 1;
96 data->registry_data.skip_baco_hardware = 0;
98 data->registry_data.log_avfs_param = 0;
99 data->registry_data.sclk_throttle_low_notification = 1;
100 data->registry_data.force_dpm_high = 0;
101 data->registry_data.stable_pstate_sclk_dpm_percentage = 75;
103 data->registry_data.didt_support = 0;
104 if (data->registry_data.didt_support) {
105 data->registry_data.didt_mode = 6;
106 data->registry_data.sq_ramping_support = 1;
107 data->registry_data.db_ramping_support = 0;
108 data->registry_data.td_ramping_support = 0;
109 data->registry_data.tcp_ramping_support = 0;
110 data->registry_data.dbr_ramping_support = 0;
111 data->registry_data.edc_didt_support = 1;
112 data->registry_data.gc_didt_support = 0;
113 data->registry_data.psm_didt_support = 0;
116 data->registry_data.pcie_lane_override = 0xff;
117 data->registry_data.pcie_speed_override = 0xff;
118 data->registry_data.pcie_clock_override = 0xffffffff;
119 data->registry_data.regulator_hot_gpio_support = 1;
120 data->registry_data.ac_dc_switch_gpio_support = 0;
121 data->registry_data.quick_transition_support = 0;
122 data->registry_data.zrpm_start_temp = 0xffff;
123 data->registry_data.zrpm_stop_temp = 0xffff;
124 data->registry_data.od8_feature_enable = 1;
125 data->registry_data.disable_water_mark = 0;
126 data->registry_data.disable_pp_tuning = 0;
127 data->registry_data.disable_xlpp_tuning = 0;
128 data->registry_data.disable_workload_policy = 0;
129 data->registry_data.perf_ui_tuning_profile_turbo = 0x19190F0F;
130 data->registry_data.perf_ui_tuning_profile_powerSave = 0x19191919;
131 data->registry_data.perf_ui_tuning_profile_xl = 0x00000F0A;
132 data->registry_data.force_workload_policy_mask = 0;
133 data->registry_data.disable_3d_fs_detection = 0;
134 data->registry_data.fps_support = 1;
135 data->registry_data.disable_auto_wattman = 1;
136 data->registry_data.auto_wattman_debug = 0;
137 data->registry_data.auto_wattman_sample_period = 100;
138 data->registry_data.fclk_gfxclk_ratio = 0;
139 data->registry_data.auto_wattman_threshold = 50;
140 data->registry_data.gfxoff_controlled_by_driver = 1;
141 data->gfxoff_allowed = false;
142 data->counter_gfxoff = 0;
145 static int vega20_set_features_platform_caps(struct pp_hwmgr *hwmgr)
147 struct vega20_hwmgr *data =
148 (struct vega20_hwmgr *)(hwmgr->backend);
149 struct amdgpu_device *adev = hwmgr->adev;
151 if (data->vddci_control == VEGA20_VOLTAGE_CONTROL_NONE)
152 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
153 PHM_PlatformCaps_ControlVDDCI);
155 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
156 PHM_PlatformCaps_TablelessHardwareInterface);
158 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
159 PHM_PlatformCaps_EnableSMU7ThermalManagement);
161 if (adev->pg_flags & AMD_PG_SUPPORT_UVD)
162 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
163 PHM_PlatformCaps_UVDPowerGating);
165 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
166 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
167 PHM_PlatformCaps_VCEPowerGating);
169 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
170 PHM_PlatformCaps_UnTabledHardwareInterface);
172 if (data->registry_data.od8_feature_enable)
173 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
174 PHM_PlatformCaps_OD8inACSupport);
176 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
177 PHM_PlatformCaps_ActivityReporting);
178 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
179 PHM_PlatformCaps_FanSpeedInTableIsRPM);
181 if (data->registry_data.od_state_in_dc_support) {
182 if (data->registry_data.od8_feature_enable)
183 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
184 PHM_PlatformCaps_OD8inDCSupport);
187 if (data->registry_data.thermal_support &&
188 data->registry_data.fuzzy_fan_control_support &&
189 hwmgr->thermal_controller.advanceFanControlParameters.usTMax)
190 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
191 PHM_PlatformCaps_ODFuzzyFanControlSupport);
193 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
194 PHM_PlatformCaps_DynamicPowerManagement);
195 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
196 PHM_PlatformCaps_SMC);
197 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
198 PHM_PlatformCaps_ThermalPolicyDelay);
200 if (data->registry_data.force_dpm_high)
201 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
202 PHM_PlatformCaps_ExclusiveModeAlwaysHigh);
204 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
205 PHM_PlatformCaps_DynamicUVDState);
207 if (data->registry_data.sclk_throttle_low_notification)
208 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
209 PHM_PlatformCaps_SclkThrottleLowNotification);
211 /* power tune caps */
212 /* assume disabled */
213 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
214 PHM_PlatformCaps_PowerContainment);
215 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
216 PHM_PlatformCaps_DiDtSupport);
217 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
218 PHM_PlatformCaps_SQRamping);
219 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
220 PHM_PlatformCaps_DBRamping);
221 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
222 PHM_PlatformCaps_TDRamping);
223 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
224 PHM_PlatformCaps_TCPRamping);
225 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
226 PHM_PlatformCaps_DBRRamping);
227 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
228 PHM_PlatformCaps_DiDtEDCEnable);
229 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
230 PHM_PlatformCaps_GCEDC);
231 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
232 PHM_PlatformCaps_PSM);
234 if (data->registry_data.didt_support) {
235 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
236 PHM_PlatformCaps_DiDtSupport);
237 if (data->registry_data.sq_ramping_support)
238 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
239 PHM_PlatformCaps_SQRamping);
240 if (data->registry_data.db_ramping_support)
241 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
242 PHM_PlatformCaps_DBRamping);
243 if (data->registry_data.td_ramping_support)
244 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
245 PHM_PlatformCaps_TDRamping);
246 if (data->registry_data.tcp_ramping_support)
247 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
248 PHM_PlatformCaps_TCPRamping);
249 if (data->registry_data.dbr_ramping_support)
250 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
251 PHM_PlatformCaps_DBRRamping);
252 if (data->registry_data.edc_didt_support)
253 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
254 PHM_PlatformCaps_DiDtEDCEnable);
255 if (data->registry_data.gc_didt_support)
256 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
257 PHM_PlatformCaps_GCEDC);
258 if (data->registry_data.psm_didt_support)
259 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
260 PHM_PlatformCaps_PSM);
263 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
264 PHM_PlatformCaps_RegulatorHot);
266 if (data->registry_data.ac_dc_switch_gpio_support) {
267 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
268 PHM_PlatformCaps_AutomaticDCTransition);
269 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
270 PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
273 if (data->registry_data.quick_transition_support) {
274 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
275 PHM_PlatformCaps_AutomaticDCTransition);
276 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
277 PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
278 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
279 PHM_PlatformCaps_Falcon_QuickTransition);
282 if (data->lowest_uclk_reserved_for_ulv != PPVEGA20_VEGA20LOWESTUCLKRESERVEDFORULV_DFLT) {
283 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
284 PHM_PlatformCaps_LowestUclkReservedForUlv);
285 if (data->lowest_uclk_reserved_for_ulv == 1)
286 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
287 PHM_PlatformCaps_LowestUclkReservedForUlv);
290 if (data->registry_data.custom_fan_support)
291 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
292 PHM_PlatformCaps_CustomFanControlSupport);
297 static void vega20_init_dpm_defaults(struct pp_hwmgr *hwmgr)
299 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
302 data->smu_features[GNLD_DPM_PREFETCHER].smu_feature_id =
303 FEATURE_DPM_PREFETCHER_BIT;
304 data->smu_features[GNLD_DPM_GFXCLK].smu_feature_id =
305 FEATURE_DPM_GFXCLK_BIT;
306 data->smu_features[GNLD_DPM_UCLK].smu_feature_id =
307 FEATURE_DPM_UCLK_BIT;
308 data->smu_features[GNLD_DPM_SOCCLK].smu_feature_id =
309 FEATURE_DPM_SOCCLK_BIT;
310 data->smu_features[GNLD_DPM_UVD].smu_feature_id =
312 data->smu_features[GNLD_DPM_VCE].smu_feature_id =
314 data->smu_features[GNLD_ULV].smu_feature_id =
316 data->smu_features[GNLD_DPM_MP0CLK].smu_feature_id =
317 FEATURE_DPM_MP0CLK_BIT;
318 data->smu_features[GNLD_DPM_LINK].smu_feature_id =
319 FEATURE_DPM_LINK_BIT;
320 data->smu_features[GNLD_DPM_DCEFCLK].smu_feature_id =
321 FEATURE_DPM_DCEFCLK_BIT;
322 data->smu_features[GNLD_DS_GFXCLK].smu_feature_id =
323 FEATURE_DS_GFXCLK_BIT;
324 data->smu_features[GNLD_DS_SOCCLK].smu_feature_id =
325 FEATURE_DS_SOCCLK_BIT;
326 data->smu_features[GNLD_DS_LCLK].smu_feature_id =
328 data->smu_features[GNLD_PPT].smu_feature_id =
330 data->smu_features[GNLD_TDC].smu_feature_id =
332 data->smu_features[GNLD_THERMAL].smu_feature_id =
334 data->smu_features[GNLD_GFX_PER_CU_CG].smu_feature_id =
335 FEATURE_GFX_PER_CU_CG_BIT;
336 data->smu_features[GNLD_RM].smu_feature_id =
338 data->smu_features[GNLD_DS_DCEFCLK].smu_feature_id =
339 FEATURE_DS_DCEFCLK_BIT;
340 data->smu_features[GNLD_ACDC].smu_feature_id =
342 data->smu_features[GNLD_VR0HOT].smu_feature_id =
344 data->smu_features[GNLD_VR1HOT].smu_feature_id =
346 data->smu_features[GNLD_FW_CTF].smu_feature_id =
348 data->smu_features[GNLD_LED_DISPLAY].smu_feature_id =
349 FEATURE_LED_DISPLAY_BIT;
350 data->smu_features[GNLD_FAN_CONTROL].smu_feature_id =
351 FEATURE_FAN_CONTROL_BIT;
352 data->smu_features[GNLD_DIDT].smu_feature_id = FEATURE_GFX_EDC_BIT;
353 data->smu_features[GNLD_GFXOFF].smu_feature_id = FEATURE_GFXOFF_BIT;
354 data->smu_features[GNLD_CG].smu_feature_id = FEATURE_CG_BIT;
355 data->smu_features[GNLD_DPM_FCLK].smu_feature_id = FEATURE_DPM_FCLK_BIT;
356 data->smu_features[GNLD_DS_FCLK].smu_feature_id = FEATURE_DS_FCLK_BIT;
357 data->smu_features[GNLD_DS_MP1CLK].smu_feature_id = FEATURE_DS_MP1CLK_BIT;
358 data->smu_features[GNLD_DS_MP0CLK].smu_feature_id = FEATURE_DS_MP0CLK_BIT;
359 data->smu_features[GNLD_XGMI].smu_feature_id = FEATURE_XGMI_BIT;
361 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
362 data->smu_features[i].smu_feature_bitmap =
363 (uint64_t)(1ULL << data->smu_features[i].smu_feature_id);
364 data->smu_features[i].allowed =
365 ((data->registry_data.disallowed_features >> i) & 1) ?
370 static int vega20_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
375 static int vega20_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
377 kfree(hwmgr->backend);
378 hwmgr->backend = NULL;
383 static int vega20_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
385 struct vega20_hwmgr *data;
386 struct amdgpu_device *adev = hwmgr->adev;
388 data = kzalloc(sizeof(struct vega20_hwmgr), GFP_KERNEL);
392 hwmgr->backend = data;
394 hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT];
395 hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
396 hwmgr->default_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
398 vega20_set_default_registry_data(hwmgr);
400 data->disable_dpm_mask = 0xff;
402 /* need to set voltage control types before EVV patching */
403 data->vddc_control = VEGA20_VOLTAGE_CONTROL_NONE;
404 data->mvdd_control = VEGA20_VOLTAGE_CONTROL_NONE;
405 data->vddci_control = VEGA20_VOLTAGE_CONTROL_NONE;
407 data->water_marks_bitmap = 0;
408 data->avfs_exist = false;
410 vega20_set_features_platform_caps(hwmgr);
412 vega20_init_dpm_defaults(hwmgr);
414 /* Parse pptable data read from VBIOS */
415 vega20_set_private_data_based_on_pptable(hwmgr);
417 data->is_tlu_enabled = false;
419 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
420 VEGA20_MAX_HARDWARE_POWERLEVELS;
421 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
422 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
424 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
425 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
426 hwmgr->platform_descriptor.clockStep.engineClock = 500;
427 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
429 data->total_active_cus = adev->gfx.cu_info.number;
434 static int vega20_init_sclk_threshold(struct pp_hwmgr *hwmgr)
436 struct vega20_hwmgr *data =
437 (struct vega20_hwmgr *)(hwmgr->backend);
439 data->low_sclk_interrupt_threshold = 0;
444 static int vega20_setup_asic_task(struct pp_hwmgr *hwmgr)
448 ret = vega20_init_sclk_threshold(hwmgr);
449 PP_ASSERT_WITH_CODE(!ret,
450 "Failed to init sclk threshold!",
457 * @fn vega20_init_dpm_state
458 * @brief Function to initialize all Soft Min/Max and Hard Min/Max to 0xff.
460 * @param dpm_state - the address of the DPM Table to initiailize.
463 static void vega20_init_dpm_state(struct vega20_dpm_state *dpm_state)
465 dpm_state->soft_min_level = 0x0;
466 dpm_state->soft_max_level = 0xffff;
467 dpm_state->hard_min_level = 0x0;
468 dpm_state->hard_max_level = 0xffff;
471 static int vega20_get_number_of_dpm_level(struct pp_hwmgr *hwmgr,
472 PPCLK_e clk_id, uint32_t *num_of_levels)
476 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
477 PPSMC_MSG_GetDpmFreqByIndex,
478 (clk_id << 16 | 0xFF));
479 PP_ASSERT_WITH_CODE(!ret,
480 "[GetNumOfDpmLevel] failed to get dpm levels!",
483 *num_of_levels = smum_get_argument(hwmgr);
484 PP_ASSERT_WITH_CODE(*num_of_levels > 0,
485 "[GetNumOfDpmLevel] number of clk levels is invalid!",
491 static int vega20_get_dpm_frequency_by_index(struct pp_hwmgr *hwmgr,
492 PPCLK_e clk_id, uint32_t index, uint32_t *clk)
496 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
497 PPSMC_MSG_GetDpmFreqByIndex,
498 (clk_id << 16 | index));
499 PP_ASSERT_WITH_CODE(!ret,
500 "[GetDpmFreqByIndex] failed to get dpm freq by index!",
503 *clk = smum_get_argument(hwmgr);
504 PP_ASSERT_WITH_CODE(*clk,
505 "[GetDpmFreqByIndex] clk value is invalid!",
511 static int vega20_setup_single_dpm_table(struct pp_hwmgr *hwmgr,
512 struct vega20_single_dpm_table *dpm_table, PPCLK_e clk_id)
515 uint32_t i, num_of_levels, clk;
517 ret = vega20_get_number_of_dpm_level(hwmgr, clk_id, &num_of_levels);
518 PP_ASSERT_WITH_CODE(!ret,
519 "[SetupSingleDpmTable] failed to get clk levels!",
522 dpm_table->count = num_of_levels;
524 for (i = 0; i < num_of_levels; i++) {
525 ret = vega20_get_dpm_frequency_by_index(hwmgr, clk_id, i, &clk);
526 PP_ASSERT_WITH_CODE(!ret,
527 "[SetupSingleDpmTable] failed to get clk of specific level!",
529 dpm_table->dpm_levels[i].value = clk;
530 dpm_table->dpm_levels[i].enabled = true;
536 static int vega20_setup_gfxclk_dpm_table(struct pp_hwmgr *hwmgr)
538 struct vega20_hwmgr *data =
539 (struct vega20_hwmgr *)(hwmgr->backend);
540 struct vega20_single_dpm_table *dpm_table;
543 dpm_table = &(data->dpm_table.gfx_table);
544 if (data->smu_features[GNLD_DPM_GFXCLK].enabled) {
545 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_GFXCLK);
546 PP_ASSERT_WITH_CODE(!ret,
547 "[SetupDefaultDpmTable] failed to get gfxclk dpm levels!",
550 dpm_table->count = 1;
551 dpm_table->dpm_levels[0].value = data->vbios_boot_state.gfx_clock / 100;
557 static int vega20_setup_memclk_dpm_table(struct pp_hwmgr *hwmgr)
559 struct vega20_hwmgr *data =
560 (struct vega20_hwmgr *)(hwmgr->backend);
561 struct vega20_single_dpm_table *dpm_table;
564 dpm_table = &(data->dpm_table.mem_table);
565 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
566 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_UCLK);
567 PP_ASSERT_WITH_CODE(!ret,
568 "[SetupDefaultDpmTable] failed to get memclk dpm levels!",
571 dpm_table->count = 1;
572 dpm_table->dpm_levels[0].value = data->vbios_boot_state.mem_clock / 100;
579 * This function is to initialize all DPM state tables
580 * for SMU based on the dependency table.
581 * Dynamic state patching function will then trim these
582 * state tables to the allowed range based
583 * on the power policy or external client requests,
584 * such as UVD request, etc.
586 static int vega20_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
588 struct vega20_hwmgr *data =
589 (struct vega20_hwmgr *)(hwmgr->backend);
590 struct vega20_single_dpm_table *dpm_table;
593 memset(&data->dpm_table, 0, sizeof(data->dpm_table));
596 dpm_table = &(data->dpm_table.soc_table);
597 if (data->smu_features[GNLD_DPM_SOCCLK].enabled) {
598 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_SOCCLK);
599 PP_ASSERT_WITH_CODE(!ret,
600 "[SetupDefaultDpmTable] failed to get socclk dpm levels!",
603 dpm_table->count = 1;
604 dpm_table->dpm_levels[0].value = data->vbios_boot_state.soc_clock / 100;
606 vega20_init_dpm_state(&(dpm_table->dpm_state));
609 dpm_table = &(data->dpm_table.gfx_table);
610 ret = vega20_setup_gfxclk_dpm_table(hwmgr);
613 vega20_init_dpm_state(&(dpm_table->dpm_state));
616 dpm_table = &(data->dpm_table.mem_table);
617 ret = vega20_setup_memclk_dpm_table(hwmgr);
620 vega20_init_dpm_state(&(dpm_table->dpm_state));
623 dpm_table = &(data->dpm_table.eclk_table);
624 if (data->smu_features[GNLD_DPM_VCE].enabled) {
625 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_ECLK);
626 PP_ASSERT_WITH_CODE(!ret,
627 "[SetupDefaultDpmTable] failed to get eclk dpm levels!",
630 dpm_table->count = 1;
631 dpm_table->dpm_levels[0].value = data->vbios_boot_state.eclock / 100;
633 vega20_init_dpm_state(&(dpm_table->dpm_state));
636 dpm_table = &(data->dpm_table.vclk_table);
637 if (data->smu_features[GNLD_DPM_UVD].enabled) {
638 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_VCLK);
639 PP_ASSERT_WITH_CODE(!ret,
640 "[SetupDefaultDpmTable] failed to get vclk dpm levels!",
643 dpm_table->count = 1;
644 dpm_table->dpm_levels[0].value = data->vbios_boot_state.vclock / 100;
646 vega20_init_dpm_state(&(dpm_table->dpm_state));
649 dpm_table = &(data->dpm_table.dclk_table);
650 if (data->smu_features[GNLD_DPM_UVD].enabled) {
651 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_DCLK);
652 PP_ASSERT_WITH_CODE(!ret,
653 "[SetupDefaultDpmTable] failed to get dclk dpm levels!",
656 dpm_table->count = 1;
657 dpm_table->dpm_levels[0].value = data->vbios_boot_state.dclock / 100;
659 vega20_init_dpm_state(&(dpm_table->dpm_state));
662 dpm_table = &(data->dpm_table.dcef_table);
663 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
664 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_DCEFCLK);
665 PP_ASSERT_WITH_CODE(!ret,
666 "[SetupDefaultDpmTable] failed to get dcefclk dpm levels!",
669 dpm_table->count = 1;
670 dpm_table->dpm_levels[0].value = data->vbios_boot_state.dcef_clock / 100;
672 vega20_init_dpm_state(&(dpm_table->dpm_state));
675 dpm_table = &(data->dpm_table.pixel_table);
676 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
677 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_PIXCLK);
678 PP_ASSERT_WITH_CODE(!ret,
679 "[SetupDefaultDpmTable] failed to get pixclk dpm levels!",
682 dpm_table->count = 0;
683 vega20_init_dpm_state(&(dpm_table->dpm_state));
686 dpm_table = &(data->dpm_table.display_table);
687 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
688 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_DISPCLK);
689 PP_ASSERT_WITH_CODE(!ret,
690 "[SetupDefaultDpmTable] failed to get dispclk dpm levels!",
693 dpm_table->count = 0;
694 vega20_init_dpm_state(&(dpm_table->dpm_state));
697 dpm_table = &(data->dpm_table.phy_table);
698 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
699 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_PHYCLK);
700 PP_ASSERT_WITH_CODE(!ret,
701 "[SetupDefaultDpmTable] failed to get phyclk dpm levels!",
704 dpm_table->count = 0;
705 vega20_init_dpm_state(&(dpm_table->dpm_state));
708 dpm_table = &(data->dpm_table.fclk_table);
709 if (data->smu_features[GNLD_DPM_FCLK].enabled) {
710 ret = vega20_setup_single_dpm_table(hwmgr, dpm_table, PPCLK_FCLK);
711 PP_ASSERT_WITH_CODE(!ret,
712 "[SetupDefaultDpmTable] failed to get fclk dpm levels!",
715 dpm_table->count = 0;
716 vega20_init_dpm_state(&(dpm_table->dpm_state));
718 /* save a copy of the default DPM table */
719 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
720 sizeof(struct vega20_dpm_table));
726 * Initializes the SMC table and uploads it
728 * @param hwmgr the address of the powerplay hardware manager.
729 * @param pInput the pointer to input data (PowerState)
732 static int vega20_init_smc_table(struct pp_hwmgr *hwmgr)
735 struct vega20_hwmgr *data =
736 (struct vega20_hwmgr *)(hwmgr->backend);
737 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
738 struct pp_atomfwctrl_bios_boot_up_values boot_up_values;
739 struct phm_ppt_v3_information *pptable_information =
740 (struct phm_ppt_v3_information *)hwmgr->pptable;
742 result = pp_atomfwctrl_get_vbios_bootup_values(hwmgr, &boot_up_values);
743 PP_ASSERT_WITH_CODE(!result,
744 "[InitSMCTable] Failed to get vbios bootup values!",
747 data->vbios_boot_state.vddc = boot_up_values.usVddc;
748 data->vbios_boot_state.vddci = boot_up_values.usVddci;
749 data->vbios_boot_state.mvddc = boot_up_values.usMvddc;
750 data->vbios_boot_state.gfx_clock = boot_up_values.ulGfxClk;
751 data->vbios_boot_state.mem_clock = boot_up_values.ulUClk;
752 data->vbios_boot_state.soc_clock = boot_up_values.ulSocClk;
753 data->vbios_boot_state.dcef_clock = boot_up_values.ulDCEFClk;
754 data->vbios_boot_state.eclock = boot_up_values.ulEClk;
755 data->vbios_boot_state.vclock = boot_up_values.ulVClk;
756 data->vbios_boot_state.dclock = boot_up_values.ulDClk;
757 data->vbios_boot_state.uc_cooling_id = boot_up_values.ucCoolingID;
759 smum_send_msg_to_smc_with_parameter(hwmgr,
760 PPSMC_MSG_SetMinDeepSleepDcefclk,
761 (uint32_t)(data->vbios_boot_state.dcef_clock / 100));
763 memcpy(pp_table, pptable_information->smc_pptable, sizeof(PPTable_t));
765 result = smum_smc_table_manager(hwmgr,
766 (uint8_t *)pp_table, TABLE_PPTABLE, false);
767 PP_ASSERT_WITH_CODE(!result,
768 "[InitSMCTable] Failed to upload PPtable!",
775 * Override PCIe link speed and link width for DPM Level 1. PPTable entries
776 * reflect the ASIC capabilities and not the system capabilities. For e.g.
777 * Vega20 board in a PCI Gen3 system. In this case, when SMU's tries to switch
778 * to DPM1, it fails as system doesn't support Gen4.
780 static int vega20_override_pcie_parameters(struct pp_hwmgr *hwmgr)
782 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
783 uint32_t pcie_gen = 0, pcie_width = 0, smu_pcie_arg;
786 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4)
788 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
790 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
792 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1)
795 if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16)
797 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12)
799 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8)
801 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4)
803 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2)
805 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X1)
808 /* Bit 31:16: LCLK DPM level. 0 is DPM0, and 1 is DPM1
809 * Bit 15:8: PCIE GEN, 0 to 3 corresponds to GEN1 to GEN4
810 * Bit 7:0: PCIE lane width, 1 to 7 corresponds is x1 to x32
812 smu_pcie_arg = (1 << 16) | (pcie_gen << 8) | pcie_width;
813 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
814 PPSMC_MSG_OverridePcieParameters, smu_pcie_arg);
815 PP_ASSERT_WITH_CODE(!ret,
816 "[OverridePcieParameters] Attempt to override pcie params failed!",
822 static int vega20_set_allowed_featuresmask(struct pp_hwmgr *hwmgr)
824 struct vega20_hwmgr *data =
825 (struct vega20_hwmgr *)(hwmgr->backend);
826 uint32_t allowed_features_low = 0, allowed_features_high = 0;
830 for (i = 0; i < GNLD_FEATURES_MAX; i++)
831 if (data->smu_features[i].allowed)
832 data->smu_features[i].smu_feature_id > 31 ?
833 (allowed_features_high |=
834 ((data->smu_features[i].smu_feature_bitmap >> SMU_FEATURES_HIGH_SHIFT)
836 (allowed_features_low |=
837 ((data->smu_features[i].smu_feature_bitmap >> SMU_FEATURES_LOW_SHIFT)
840 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
841 PPSMC_MSG_SetAllowedFeaturesMaskHigh, allowed_features_high);
842 PP_ASSERT_WITH_CODE(!ret,
843 "[SetAllowedFeaturesMask] Attempt to set allowed features mask(high) failed!",
846 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
847 PPSMC_MSG_SetAllowedFeaturesMaskLow, allowed_features_low);
848 PP_ASSERT_WITH_CODE(!ret,
849 "[SetAllowedFeaturesMask] Attempt to set allowed features mask (low) failed!",
855 static int vega20_run_btc(struct pp_hwmgr *hwmgr)
857 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunBtc);
860 static int vega20_run_btc_afll(struct pp_hwmgr *hwmgr)
862 return smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAfllBtc);
865 static int vega20_enable_all_smu_features(struct pp_hwmgr *hwmgr)
867 struct vega20_hwmgr *data =
868 (struct vega20_hwmgr *)(hwmgr->backend);
869 uint64_t features_enabled;
874 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc(hwmgr,
875 PPSMC_MSG_EnableAllSmuFeatures)) == 0,
876 "[EnableAllSMUFeatures] Failed to enable all smu features!",
879 ret = vega20_get_enabled_smc_features(hwmgr, &features_enabled);
880 PP_ASSERT_WITH_CODE(!ret,
881 "[EnableAllSmuFeatures] Failed to get enabled smc features!",
884 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
885 enabled = (features_enabled & data->smu_features[i].smu_feature_bitmap) ?
887 data->smu_features[i].enabled = enabled;
888 data->smu_features[i].supported = enabled;
891 if (data->smu_features[i].allowed && !enabled)
892 pr_info("[EnableAllSMUFeatures] feature %d is expected enabled!", i);
893 else if (!data->smu_features[i].allowed && enabled)
894 pr_info("[EnableAllSMUFeatures] feature %d is expected disabled!", i);
901 static int vega20_notify_smc_display_change(struct pp_hwmgr *hwmgr)
903 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
905 if (data->smu_features[GNLD_DPM_UCLK].enabled)
906 return smum_send_msg_to_smc_with_parameter(hwmgr,
907 PPSMC_MSG_SetUclkFastSwitch,
913 static int vega20_send_clock_ratio(struct pp_hwmgr *hwmgr)
915 struct vega20_hwmgr *data =
916 (struct vega20_hwmgr *)(hwmgr->backend);
918 return smum_send_msg_to_smc_with_parameter(hwmgr,
919 PPSMC_MSG_SetFclkGfxClkRatio,
920 data->registry_data.fclk_gfxclk_ratio);
923 static int vega20_disable_all_smu_features(struct pp_hwmgr *hwmgr)
925 struct vega20_hwmgr *data =
926 (struct vega20_hwmgr *)(hwmgr->backend);
927 uint64_t features_enabled;
932 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc(hwmgr,
933 PPSMC_MSG_DisableAllSmuFeatures)) == 0,
934 "[DisableAllSMUFeatures] Failed to disable all smu features!",
937 ret = vega20_get_enabled_smc_features(hwmgr, &features_enabled);
938 PP_ASSERT_WITH_CODE(!ret,
939 "[DisableAllSMUFeatures] Failed to get enabled smc features!",
942 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
943 enabled = (features_enabled & data->smu_features[i].smu_feature_bitmap) ?
945 data->smu_features[i].enabled = enabled;
946 data->smu_features[i].supported = enabled;
952 static int vega20_od8_set_feature_capabilities(
953 struct pp_hwmgr *hwmgr)
955 struct phm_ppt_v3_information *pptable_information =
956 (struct phm_ppt_v3_information *)hwmgr->pptable;
957 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
958 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
959 struct vega20_od8_settings *od_settings = &(data->od8_settings);
961 od_settings->overdrive8_capabilities = 0;
963 if (data->smu_features[GNLD_DPM_GFXCLK].enabled) {
964 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_GFXCLK_LIMITS] &&
965 pptable_information->od_settings_max[OD8_SETTING_GFXCLK_FMAX] > 0 &&
966 pptable_information->od_settings_min[OD8_SETTING_GFXCLK_FMIN] > 0 &&
967 (pptable_information->od_settings_max[OD8_SETTING_GFXCLK_FMAX] >=
968 pptable_information->od_settings_min[OD8_SETTING_GFXCLK_FMIN]))
969 od_settings->overdrive8_capabilities |= OD8_GFXCLK_LIMITS;
971 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_GFXCLK_CURVE] &&
972 (pptable_information->od_settings_min[OD8_SETTING_GFXCLK_VOLTAGE1] >=
973 pp_table->MinVoltageGfx / VOLTAGE_SCALE) &&
974 (pptable_information->od_settings_max[OD8_SETTING_GFXCLK_VOLTAGE3] <=
975 pp_table->MaxVoltageGfx / VOLTAGE_SCALE) &&
976 (pptable_information->od_settings_max[OD8_SETTING_GFXCLK_VOLTAGE3] >=
977 pptable_information->od_settings_min[OD8_SETTING_GFXCLK_VOLTAGE1]))
978 od_settings->overdrive8_capabilities |= OD8_GFXCLK_CURVE;
981 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
982 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_UCLK_MAX] &&
983 pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX] > 0 &&
984 pptable_information->od_settings_max[OD8_SETTING_UCLK_FMAX] > 0 &&
985 (pptable_information->od_settings_max[OD8_SETTING_UCLK_FMAX] >=
986 pptable_information->od_settings_min[OD8_SETTING_UCLK_FMAX]))
987 od_settings->overdrive8_capabilities |= OD8_UCLK_MAX;
990 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_POWER_LIMIT] &&
991 pptable_information->od_settings_max[OD8_SETTING_POWER_PERCENTAGE] > 0 &&
992 pptable_information->od_settings_max[OD8_SETTING_POWER_PERCENTAGE] <= 100 &&
993 pptable_information->od_settings_min[OD8_SETTING_POWER_PERCENTAGE] > 0 &&
994 pptable_information->od_settings_min[OD8_SETTING_POWER_PERCENTAGE] <= 100)
995 od_settings->overdrive8_capabilities |= OD8_POWER_LIMIT;
997 if (data->smu_features[GNLD_FAN_CONTROL].enabled) {
998 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_FAN_ACOUSTIC_LIMIT] &&
999 pptable_information->od_settings_min[OD8_SETTING_FAN_ACOUSTIC_LIMIT] > 0 &&
1000 pptable_information->od_settings_max[OD8_SETTING_FAN_ACOUSTIC_LIMIT] > 0 &&
1001 (pptable_information->od_settings_max[OD8_SETTING_FAN_ACOUSTIC_LIMIT] >=
1002 pptable_information->od_settings_min[OD8_SETTING_FAN_ACOUSTIC_LIMIT]))
1003 od_settings->overdrive8_capabilities |= OD8_ACOUSTIC_LIMIT_SCLK;
1005 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_FAN_SPEED_MIN] &&
1006 (pptable_information->od_settings_min[OD8_SETTING_FAN_MIN_SPEED] >=
1007 (pp_table->FanPwmMin * pp_table->FanMaximumRpm / 100)) &&
1008 pptable_information->od_settings_max[OD8_SETTING_FAN_MIN_SPEED] > 0 &&
1009 (pptable_information->od_settings_max[OD8_SETTING_FAN_MIN_SPEED] >=
1010 pptable_information->od_settings_min[OD8_SETTING_FAN_MIN_SPEED]))
1011 od_settings->overdrive8_capabilities |= OD8_FAN_SPEED_MIN;
1014 if (data->smu_features[GNLD_THERMAL].enabled) {
1015 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_TEMPERATURE_FAN] &&
1016 pptable_information->od_settings_max[OD8_SETTING_FAN_TARGET_TEMP] > 0 &&
1017 pptable_information->od_settings_min[OD8_SETTING_FAN_TARGET_TEMP] > 0 &&
1018 (pptable_information->od_settings_max[OD8_SETTING_FAN_TARGET_TEMP] >=
1019 pptable_information->od_settings_min[OD8_SETTING_FAN_TARGET_TEMP]))
1020 od_settings->overdrive8_capabilities |= OD8_TEMPERATURE_FAN;
1022 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_TEMPERATURE_SYSTEM] &&
1023 pptable_information->od_settings_max[OD8_SETTING_OPERATING_TEMP_MAX] > 0 &&
1024 pptable_information->od_settings_min[OD8_SETTING_OPERATING_TEMP_MAX] > 0 &&
1025 (pptable_information->od_settings_max[OD8_SETTING_OPERATING_TEMP_MAX] >=
1026 pptable_information->od_settings_min[OD8_SETTING_OPERATING_TEMP_MAX]))
1027 od_settings->overdrive8_capabilities |= OD8_TEMPERATURE_SYSTEM;
1030 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_MEMORY_TIMING_TUNE])
1031 od_settings->overdrive8_capabilities |= OD8_MEMORY_TIMING_TUNE;
1033 if (pptable_information->od_feature_capabilities[ATOM_VEGA20_ODFEATURE_FAN_ZERO_RPM_CONTROL] &&
1034 pp_table->FanZeroRpmEnable)
1035 od_settings->overdrive8_capabilities |= OD8_FAN_ZERO_RPM_CONTROL;
1037 if (!od_settings->overdrive8_capabilities)
1038 hwmgr->od_enabled = false;
1043 static int vega20_od8_set_feature_id(
1044 struct pp_hwmgr *hwmgr)
1046 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
1047 struct vega20_od8_settings *od_settings = &(data->od8_settings);
1049 if (od_settings->overdrive8_capabilities & OD8_GFXCLK_LIMITS) {
1050 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].feature_id =
1052 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].feature_id =
1055 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].feature_id =
1057 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].feature_id =
1061 if (od_settings->overdrive8_capabilities & OD8_GFXCLK_CURVE) {
1062 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].feature_id =
1064 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id =
1066 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].feature_id =
1068 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id =
1070 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].feature_id =
1072 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id =
1075 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].feature_id =
1077 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id =
1079 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].feature_id =
1081 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id =
1083 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].feature_id =
1085 od_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id =
1089 if (od_settings->overdrive8_capabilities & OD8_UCLK_MAX)
1090 od_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].feature_id = OD8_UCLK_MAX;
1092 od_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].feature_id = 0;
1094 if (od_settings->overdrive8_capabilities & OD8_POWER_LIMIT)
1095 od_settings->od8_settings_array[OD8_SETTING_POWER_PERCENTAGE].feature_id = OD8_POWER_LIMIT;
1097 od_settings->od8_settings_array[OD8_SETTING_POWER_PERCENTAGE].feature_id = 0;
1099 if (od_settings->overdrive8_capabilities & OD8_ACOUSTIC_LIMIT_SCLK)
1100 od_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].feature_id =
1101 OD8_ACOUSTIC_LIMIT_SCLK;
1103 od_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].feature_id =
1106 if (od_settings->overdrive8_capabilities & OD8_FAN_SPEED_MIN)
1107 od_settings->od8_settings_array[OD8_SETTING_FAN_MIN_SPEED].feature_id =
1110 od_settings->od8_settings_array[OD8_SETTING_FAN_MIN_SPEED].feature_id =
1113 if (od_settings->overdrive8_capabilities & OD8_TEMPERATURE_FAN)
1114 od_settings->od8_settings_array[OD8_SETTING_FAN_TARGET_TEMP].feature_id =
1115 OD8_TEMPERATURE_FAN;
1117 od_settings->od8_settings_array[OD8_SETTING_FAN_TARGET_TEMP].feature_id =
1120 if (od_settings->overdrive8_capabilities & OD8_TEMPERATURE_SYSTEM)
1121 od_settings->od8_settings_array[OD8_SETTING_OPERATING_TEMP_MAX].feature_id =
1122 OD8_TEMPERATURE_SYSTEM;
1124 od_settings->od8_settings_array[OD8_SETTING_OPERATING_TEMP_MAX].feature_id =
1130 static int vega20_od8_get_gfx_clock_base_voltage(
1131 struct pp_hwmgr *hwmgr,
1137 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
1138 PPSMC_MSG_GetAVFSVoltageByDpm,
1139 ((AVFS_CURVE << 24) | (OD8_HOTCURVE_TEMPERATURE << 16) | freq));
1140 PP_ASSERT_WITH_CODE(!ret,
1141 "[GetBaseVoltage] failed to get GFXCLK AVFS voltage from SMU!",
1144 *voltage = smum_get_argument(hwmgr);
1145 *voltage = *voltage / VOLTAGE_SCALE;
1150 static int vega20_od8_initialize_default_settings(
1151 struct pp_hwmgr *hwmgr)
1153 struct phm_ppt_v3_information *pptable_information =
1154 (struct phm_ppt_v3_information *)hwmgr->pptable;
1155 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
1156 struct vega20_od8_settings *od8_settings = &(data->od8_settings);
1157 OverDriveTable_t *od_table = &(data->smc_state_table.overdrive_table);
1160 /* Set Feature Capabilities */
1161 vega20_od8_set_feature_capabilities(hwmgr);
1163 /* Map FeatureID to individual settings */
1164 vega20_od8_set_feature_id(hwmgr);
1166 /* Set default values */
1167 ret = smum_smc_table_manager(hwmgr, (uint8_t *)od_table, TABLE_OVERDRIVE, true);
1168 PP_ASSERT_WITH_CODE(!ret,
1169 "Failed to export over drive table!",
1172 if (od8_settings->overdrive8_capabilities & OD8_GFXCLK_LIMITS) {
1173 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].default_value =
1174 od_table->GfxclkFmin;
1175 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].default_value =
1176 od_table->GfxclkFmax;
1178 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMIN].default_value =
1180 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FMAX].default_value =
1184 if (od8_settings->overdrive8_capabilities & OD8_GFXCLK_CURVE) {
1185 od_table->GfxclkFreq1 = od_table->GfxclkFmin;
1186 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].default_value =
1187 od_table->GfxclkFreq1;
1189 od_table->GfxclkFreq3 = od_table->GfxclkFmax;
1190 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].default_value =
1191 od_table->GfxclkFreq3;
1193 od_table->GfxclkFreq2 = (od_table->GfxclkFreq1 + od_table->GfxclkFreq3) / 2;
1194 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].default_value =
1195 od_table->GfxclkFreq2;
1197 PP_ASSERT_WITH_CODE(!vega20_od8_get_gfx_clock_base_voltage(hwmgr,
1198 &(od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value),
1199 od_table->GfxclkFreq1),
1200 "[PhwVega20_OD8_InitializeDefaultSettings] Failed to get Base clock voltage from SMU!",
1201 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value = 0);
1202 od_table->GfxclkVolt1 = od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value
1205 PP_ASSERT_WITH_CODE(!vega20_od8_get_gfx_clock_base_voltage(hwmgr,
1206 &(od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value),
1207 od_table->GfxclkFreq2),
1208 "[PhwVega20_OD8_InitializeDefaultSettings] Failed to get Base clock voltage from SMU!",
1209 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value = 0);
1210 od_table->GfxclkVolt2 = od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value
1213 PP_ASSERT_WITH_CODE(!vega20_od8_get_gfx_clock_base_voltage(hwmgr,
1214 &(od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value),
1215 od_table->GfxclkFreq3),
1216 "[PhwVega20_OD8_InitializeDefaultSettings] Failed to get Base clock voltage from SMU!",
1217 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value = 0);
1218 od_table->GfxclkVolt3 = od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value
1221 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ1].default_value =
1223 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE1].default_value =
1225 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ2].default_value =
1227 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE2].default_value =
1229 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_FREQ3].default_value =
1231 od8_settings->od8_settings_array[OD8_SETTING_GFXCLK_VOLTAGE3].default_value =
1235 if (od8_settings->overdrive8_capabilities & OD8_UCLK_MAX)
1236 od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].default_value =
1239 od8_settings->od8_settings_array[OD8_SETTING_UCLK_FMAX].default_value =
1242 if (od8_settings->overdrive8_capabilities & OD8_POWER_LIMIT)
1243 od8_settings->od8_settings_array[OD8_SETTING_POWER_PERCENTAGE].default_value =
1244 od_table->OverDrivePct;
1246 od8_settings->od8_settings_array[OD8_SETTING_POWER_PERCENTAGE].default_value =
1249 if (od8_settings->overdrive8_capabilities & OD8_ACOUSTIC_LIMIT_SCLK)
1250 od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].default_value =
1251 od_table->FanMaximumRpm;
1253 od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].default_value =
1256 if (od8_settings->overdrive8_capabilities & OD8_FAN_SPEED_MIN)
1257 od8_settings->od8_settings_array[OD8_SETTING_FAN_MIN_SPEED].default_value =
1258 od_table->FanMinimumPwm * data->smc_state_table.pp_table.FanMaximumRpm / 100;
1260 od8_settings->od8_settings_array[OD8_SETTING_FAN_MIN_SPEED].default_value =
1263 if (od8_settings->overdrive8_capabilities & OD8_TEMPERATURE_FAN)
1264 od8_settings->od8_settings_array[OD8_SETTING_FAN_TARGET_TEMP].default_value =
1265 od_table->FanTargetTemperature;
1267 od8_settings->od8_settings_array[OD8_SETTING_FAN_TARGET_TEMP].default_value =
1270 if (od8_settings->overdrive8_capabilities & OD8_TEMPERATURE_SYSTEM)
1271 od8_settings->od8_settings_array[OD8_SETTING_OPERATING_TEMP_MAX].default_value =
1272 od_table->MaxOpTemp;
1274 od8_settings->od8_settings_array[OD8_SETTING_OPERATING_TEMP_MAX].default_value =
1277 for (i = 0; i < OD8_SETTING_COUNT; i++) {
1278 if (od8_settings->od8_settings_array[i].feature_id) {
1279 od8_settings->od8_settings_array[i].min_value =
1280 pptable_information->od_settings_min[i];
1281 od8_settings->od8_settings_array[i].max_value =
1282 pptable_information->od_settings_max[i];
1283 od8_settings->od8_settings_array[i].current_value =
1284 od8_settings->od8_settings_array[i].default_value;
1286 od8_settings->od8_settings_array[i].min_value =
1288 od8_settings->od8_settings_array[i].max_value =
1290 od8_settings->od8_settings_array[i].current_value =
1295 ret = smum_smc_table_manager(hwmgr, (uint8_t *)od_table, TABLE_OVERDRIVE, false);
1296 PP_ASSERT_WITH_CODE(!ret,
1297 "Failed to import over drive table!",
1303 static int vega20_od8_set_settings(
1304 struct pp_hwmgr *hwmgr,
1308 OverDriveTable_t od_table;
1310 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
1311 struct vega20_od8_single_setting *od8_settings =
1312 data->od8_settings.od8_settings_array;
1314 ret = smum_smc_table_manager(hwmgr, (uint8_t *)(&od_table), TABLE_OVERDRIVE, true);
1315 PP_ASSERT_WITH_CODE(!ret,
1316 "Failed to export over drive table!",
1320 case OD8_SETTING_GFXCLK_FMIN:
1321 od_table.GfxclkFmin = (uint16_t)value;
1323 case OD8_SETTING_GFXCLK_FMAX:
1324 if (value < od8_settings[OD8_SETTING_GFXCLK_FMAX].min_value ||
1325 value > od8_settings[OD8_SETTING_GFXCLK_FMAX].max_value)
1328 od_table.GfxclkFmax = (uint16_t)value;
1330 case OD8_SETTING_GFXCLK_FREQ1:
1331 od_table.GfxclkFreq1 = (uint16_t)value;
1333 case OD8_SETTING_GFXCLK_VOLTAGE1:
1334 od_table.GfxclkVolt1 = (uint16_t)value;
1336 case OD8_SETTING_GFXCLK_FREQ2:
1337 od_table.GfxclkFreq2 = (uint16_t)value;
1339 case OD8_SETTING_GFXCLK_VOLTAGE2:
1340 od_table.GfxclkVolt2 = (uint16_t)value;
1342 case OD8_SETTING_GFXCLK_FREQ3:
1343 od_table.GfxclkFreq3 = (uint16_t)value;
1345 case OD8_SETTING_GFXCLK_VOLTAGE3:
1346 od_table.GfxclkVolt3 = (uint16_t)value;
1348 case OD8_SETTING_UCLK_FMAX:
1349 if (value < od8_settings[OD8_SETTING_UCLK_FMAX].min_value ||
1350 value > od8_settings[OD8_SETTING_UCLK_FMAX].max_value)
1352 od_table.UclkFmax = (uint16_t)value;
1354 case OD8_SETTING_POWER_PERCENTAGE:
1355 od_table.OverDrivePct = (int16_t)value;
1357 case OD8_SETTING_FAN_ACOUSTIC_LIMIT:
1358 od_table.FanMaximumRpm = (uint16_t)value;
1360 case OD8_SETTING_FAN_MIN_SPEED:
1361 od_table.FanMinimumPwm = (uint16_t)value;
1363 case OD8_SETTING_FAN_TARGET_TEMP:
1364 od_table.FanTargetTemperature = (uint16_t)value;
1366 case OD8_SETTING_OPERATING_TEMP_MAX:
1367 od_table.MaxOpTemp = (uint16_t)value;
1371 ret = smum_smc_table_manager(hwmgr, (uint8_t *)(&od_table), TABLE_OVERDRIVE, false);
1372 PP_ASSERT_WITH_CODE(!ret,
1373 "Failed to import over drive table!",
1379 static int vega20_get_sclk_od(
1380 struct pp_hwmgr *hwmgr)
1382 struct vega20_hwmgr *data = hwmgr->backend;
1383 struct vega20_single_dpm_table *sclk_table =
1384 &(data->dpm_table.gfx_table);
1385 struct vega20_single_dpm_table *golden_sclk_table =
1386 &(data->golden_dpm_table.gfx_table);
1387 int value = sclk_table->dpm_levels[sclk_table->count - 1].value;
1388 int golden_value = golden_sclk_table->dpm_levels
1389 [golden_sclk_table->count - 1].value;
1392 value -= golden_value;
1393 value = DIV_ROUND_UP(value * 100, golden_value);
1398 static int vega20_set_sclk_od(
1399 struct pp_hwmgr *hwmgr, uint32_t value)
1401 struct vega20_hwmgr *data = hwmgr->backend;
1402 struct vega20_single_dpm_table *golden_sclk_table =
1403 &(data->golden_dpm_table.gfx_table);
1407 od_sclk = golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value * value;
1409 od_sclk += golden_sclk_table->dpm_levels[golden_sclk_table->count - 1].value;
1411 ret = vega20_od8_set_settings(hwmgr, OD8_SETTING_GFXCLK_FMAX, od_sclk);
1412 PP_ASSERT_WITH_CODE(!ret,
1413 "[SetSclkOD] failed to set od gfxclk!",
1416 /* retrieve updated gfxclk table */
1417 ret = vega20_setup_gfxclk_dpm_table(hwmgr);
1418 PP_ASSERT_WITH_CODE(!ret,
1419 "[SetSclkOD] failed to refresh gfxclk table!",
1425 static int vega20_get_mclk_od(
1426 struct pp_hwmgr *hwmgr)
1428 struct vega20_hwmgr *data = hwmgr->backend;
1429 struct vega20_single_dpm_table *mclk_table =
1430 &(data->dpm_table.mem_table);
1431 struct vega20_single_dpm_table *golden_mclk_table =
1432 &(data->golden_dpm_table.mem_table);
1433 int value = mclk_table->dpm_levels[mclk_table->count - 1].value;
1434 int golden_value = golden_mclk_table->dpm_levels
1435 [golden_mclk_table->count - 1].value;
1438 value -= golden_value;
1439 value = DIV_ROUND_UP(value * 100, golden_value);
1444 static int vega20_set_mclk_od(
1445 struct pp_hwmgr *hwmgr, uint32_t value)
1447 struct vega20_hwmgr *data = hwmgr->backend;
1448 struct vega20_single_dpm_table *golden_mclk_table =
1449 &(data->golden_dpm_table.mem_table);
1453 od_mclk = golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value * value;
1455 od_mclk += golden_mclk_table->dpm_levels[golden_mclk_table->count - 1].value;
1457 ret = vega20_od8_set_settings(hwmgr, OD8_SETTING_UCLK_FMAX, od_mclk);
1458 PP_ASSERT_WITH_CODE(!ret,
1459 "[SetMclkOD] failed to set od memclk!",
1462 /* retrieve updated memclk table */
1463 ret = vega20_setup_memclk_dpm_table(hwmgr);
1464 PP_ASSERT_WITH_CODE(!ret,
1465 "[SetMclkOD] failed to refresh memclk table!",
1471 static int vega20_populate_umdpstate_clocks(
1472 struct pp_hwmgr *hwmgr)
1474 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
1475 struct vega20_single_dpm_table *gfx_table = &(data->dpm_table.gfx_table);
1476 struct vega20_single_dpm_table *mem_table = &(data->dpm_table.mem_table);
1478 hwmgr->pstate_sclk = gfx_table->dpm_levels[0].value;
1479 hwmgr->pstate_mclk = mem_table->dpm_levels[0].value;
1481 if (gfx_table->count > VEGA20_UMD_PSTATE_GFXCLK_LEVEL &&
1482 mem_table->count > VEGA20_UMD_PSTATE_MCLK_LEVEL) {
1483 hwmgr->pstate_sclk = gfx_table->dpm_levels[VEGA20_UMD_PSTATE_GFXCLK_LEVEL].value;
1484 hwmgr->pstate_mclk = mem_table->dpm_levels[VEGA20_UMD_PSTATE_MCLK_LEVEL].value;
1487 hwmgr->pstate_sclk = hwmgr->pstate_sclk * 100;
1488 hwmgr->pstate_mclk = hwmgr->pstate_mclk * 100;
1493 static int vega20_get_max_sustainable_clock(struct pp_hwmgr *hwmgr,
1494 PP_Clock *clock, PPCLK_e clock_select)
1498 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
1499 PPSMC_MSG_GetDcModeMaxDpmFreq,
1500 (clock_select << 16))) == 0,
1501 "[GetMaxSustainableClock] Failed to get max DC clock from SMC!",
1503 *clock = smum_get_argument(hwmgr);
1505 /* if DC limit is zero, return AC limit */
1507 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
1508 PPSMC_MSG_GetMaxDpmFreq,
1509 (clock_select << 16))) == 0,
1510 "[GetMaxSustainableClock] failed to get max AC clock from SMC!",
1512 *clock = smum_get_argument(hwmgr);
1518 static int vega20_init_max_sustainable_clocks(struct pp_hwmgr *hwmgr)
1520 struct vega20_hwmgr *data =
1521 (struct vega20_hwmgr *)(hwmgr->backend);
1522 struct vega20_max_sustainable_clocks *max_sustainable_clocks =
1523 &(data->max_sustainable_clocks);
1526 max_sustainable_clocks->uclock = data->vbios_boot_state.mem_clock / 100;
1527 max_sustainable_clocks->soc_clock = data->vbios_boot_state.soc_clock / 100;
1528 max_sustainable_clocks->dcef_clock = data->vbios_boot_state.dcef_clock / 100;
1529 max_sustainable_clocks->display_clock = 0xFFFFFFFF;
1530 max_sustainable_clocks->phy_clock = 0xFFFFFFFF;
1531 max_sustainable_clocks->pixel_clock = 0xFFFFFFFF;
1533 if (data->smu_features[GNLD_DPM_UCLK].enabled)
1534 PP_ASSERT_WITH_CODE((ret = vega20_get_max_sustainable_clock(hwmgr,
1535 &(max_sustainable_clocks->uclock),
1537 "[InitMaxSustainableClocks] failed to get max UCLK from SMC!",
1540 if (data->smu_features[GNLD_DPM_SOCCLK].enabled)
1541 PP_ASSERT_WITH_CODE((ret = vega20_get_max_sustainable_clock(hwmgr,
1542 &(max_sustainable_clocks->soc_clock),
1543 PPCLK_SOCCLK)) == 0,
1544 "[InitMaxSustainableClocks] failed to get max SOCCLK from SMC!",
1547 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
1548 PP_ASSERT_WITH_CODE((ret = vega20_get_max_sustainable_clock(hwmgr,
1549 &(max_sustainable_clocks->dcef_clock),
1550 PPCLK_DCEFCLK)) == 0,
1551 "[InitMaxSustainableClocks] failed to get max DCEFCLK from SMC!",
1553 PP_ASSERT_WITH_CODE((ret = vega20_get_max_sustainable_clock(hwmgr,
1554 &(max_sustainable_clocks->display_clock),
1555 PPCLK_DISPCLK)) == 0,
1556 "[InitMaxSustainableClocks] failed to get max DISPCLK from SMC!",
1558 PP_ASSERT_WITH_CODE((ret = vega20_get_max_sustainable_clock(hwmgr,
1559 &(max_sustainable_clocks->phy_clock),
1560 PPCLK_PHYCLK)) == 0,
1561 "[InitMaxSustainableClocks] failed to get max PHYCLK from SMC!",
1563 PP_ASSERT_WITH_CODE((ret = vega20_get_max_sustainable_clock(hwmgr,
1564 &(max_sustainable_clocks->pixel_clock),
1565 PPCLK_PIXCLK)) == 0,
1566 "[InitMaxSustainableClocks] failed to get max PIXCLK from SMC!",
1570 if (max_sustainable_clocks->soc_clock < max_sustainable_clocks->uclock)
1571 max_sustainable_clocks->uclock = max_sustainable_clocks->soc_clock;
1576 static int vega20_enable_mgpu_fan_boost(struct pp_hwmgr *hwmgr)
1580 result = smum_send_msg_to_smc(hwmgr,
1581 PPSMC_MSG_SetMGpuFanBoostLimitRpm);
1582 PP_ASSERT_WITH_CODE(!result,
1583 "[EnableMgpuFan] Failed to enable mgpu fan boost!",
1589 static void vega20_init_powergate_state(struct pp_hwmgr *hwmgr)
1591 struct vega20_hwmgr *data =
1592 (struct vega20_hwmgr *)(hwmgr->backend);
1594 data->uvd_power_gated = true;
1595 data->vce_power_gated = true;
1597 if (data->smu_features[GNLD_DPM_UVD].enabled)
1598 data->uvd_power_gated = false;
1600 if (data->smu_features[GNLD_DPM_VCE].enabled)
1601 data->vce_power_gated = false;
1604 static int vega20_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
1608 smum_send_msg_to_smc_with_parameter(hwmgr,
1609 PPSMC_MSG_NumOfDisplays, 0);
1611 result = vega20_set_allowed_featuresmask(hwmgr);
1612 PP_ASSERT_WITH_CODE(!result,
1613 "[EnableDPMTasks] Failed to set allowed featuresmask!\n",
1616 result = vega20_init_smc_table(hwmgr);
1617 PP_ASSERT_WITH_CODE(!result,
1618 "[EnableDPMTasks] Failed to initialize SMC table!",
1621 result = vega20_run_btc(hwmgr);
1622 PP_ASSERT_WITH_CODE(!result,
1623 "[EnableDPMTasks] Failed to run btc!",
1626 result = vega20_run_btc_afll(hwmgr);
1627 PP_ASSERT_WITH_CODE(!result,
1628 "[EnableDPMTasks] Failed to run btc afll!",
1631 result = vega20_enable_all_smu_features(hwmgr);
1632 PP_ASSERT_WITH_CODE(!result,
1633 "[EnableDPMTasks] Failed to enable all smu features!",
1636 result = vega20_override_pcie_parameters(hwmgr);
1637 PP_ASSERT_WITH_CODE(!result,
1638 "[EnableDPMTasks] Failed to override pcie parameters!",
1641 result = vega20_notify_smc_display_change(hwmgr);
1642 PP_ASSERT_WITH_CODE(!result,
1643 "[EnableDPMTasks] Failed to notify smc display change!",
1646 result = vega20_send_clock_ratio(hwmgr);
1647 PP_ASSERT_WITH_CODE(!result,
1648 "[EnableDPMTasks] Failed to send clock ratio!",
1651 /* Initialize UVD/VCE powergating state */
1652 vega20_init_powergate_state(hwmgr);
1654 result = vega20_setup_default_dpm_tables(hwmgr);
1655 PP_ASSERT_WITH_CODE(!result,
1656 "[EnableDPMTasks] Failed to setup default DPM tables!",
1659 result = vega20_init_max_sustainable_clocks(hwmgr);
1660 PP_ASSERT_WITH_CODE(!result,
1661 "[EnableDPMTasks] Failed to get maximum sustainable clocks!",
1664 result = vega20_power_control_set_level(hwmgr);
1665 PP_ASSERT_WITH_CODE(!result,
1666 "[EnableDPMTasks] Failed to power control set level!",
1669 result = vega20_od8_initialize_default_settings(hwmgr);
1670 PP_ASSERT_WITH_CODE(!result,
1671 "[EnableDPMTasks] Failed to initialize odn settings!",
1674 result = vega20_populate_umdpstate_clocks(hwmgr);
1675 PP_ASSERT_WITH_CODE(!result,
1676 "[EnableDPMTasks] Failed to populate umdpstate clocks!",
1679 result = smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetPptLimit,
1680 POWER_SOURCE_AC << 16);
1681 PP_ASSERT_WITH_CODE(!result,
1682 "[GetPptLimit] get default PPT limit failed!",
1684 hwmgr->power_limit =
1685 hwmgr->default_power_limit = smum_get_argument(hwmgr);
1690 static uint32_t vega20_find_lowest_dpm_level(
1691 struct vega20_single_dpm_table *table)
1695 for (i = 0; i < table->count; i++) {
1696 if (table->dpm_levels[i].enabled)
1699 if (i >= table->count) {
1701 table->dpm_levels[i].enabled = true;
1707 static uint32_t vega20_find_highest_dpm_level(
1708 struct vega20_single_dpm_table *table)
1712 PP_ASSERT_WITH_CODE(table != NULL,
1713 "[FindHighestDPMLevel] DPM Table does not exist!",
1715 PP_ASSERT_WITH_CODE(table->count > 0,
1716 "[FindHighestDPMLevel] DPM Table has no entry!",
1718 PP_ASSERT_WITH_CODE(table->count <= MAX_REGULAR_DPM_NUMBER,
1719 "[FindHighestDPMLevel] DPM Table has too many entries!",
1720 return MAX_REGULAR_DPM_NUMBER - 1);
1722 for (i = table->count - 1; i >= 0; i--) {
1723 if (table->dpm_levels[i].enabled)
1728 table->dpm_levels[i].enabled = true;
1734 static int vega20_upload_dpm_min_level(struct pp_hwmgr *hwmgr, uint32_t feature_mask)
1736 struct vega20_hwmgr *data =
1737 (struct vega20_hwmgr *)(hwmgr->backend);
1741 if (data->smu_features[GNLD_DPM_GFXCLK].enabled &&
1742 (feature_mask & FEATURE_DPM_GFXCLK_MASK)) {
1743 min_freq = data->dpm_table.gfx_table.dpm_state.soft_min_level;
1744 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1745 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1746 (PPCLK_GFXCLK << 16) | (min_freq & 0xffff))),
1747 "Failed to set soft min gfxclk !",
1751 if (data->smu_features[GNLD_DPM_UCLK].enabled &&
1752 (feature_mask & FEATURE_DPM_UCLK_MASK)) {
1753 min_freq = data->dpm_table.mem_table.dpm_state.soft_min_level;
1754 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1755 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1756 (PPCLK_UCLK << 16) | (min_freq & 0xffff))),
1757 "Failed to set soft min memclk !",
1761 if (data->smu_features[GNLD_DPM_UVD].enabled &&
1762 (feature_mask & FEATURE_DPM_UVD_MASK)) {
1763 min_freq = data->dpm_table.vclk_table.dpm_state.soft_min_level;
1765 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1766 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1767 (PPCLK_VCLK << 16) | (min_freq & 0xffff))),
1768 "Failed to set soft min vclk!",
1771 min_freq = data->dpm_table.dclk_table.dpm_state.soft_min_level;
1773 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1774 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1775 (PPCLK_DCLK << 16) | (min_freq & 0xffff))),
1776 "Failed to set soft min dclk!",
1780 if (data->smu_features[GNLD_DPM_VCE].enabled &&
1781 (feature_mask & FEATURE_DPM_VCE_MASK)) {
1782 min_freq = data->dpm_table.eclk_table.dpm_state.soft_min_level;
1784 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1785 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1786 (PPCLK_ECLK << 16) | (min_freq & 0xffff))),
1787 "Failed to set soft min eclk!",
1791 if (data->smu_features[GNLD_DPM_SOCCLK].enabled &&
1792 (feature_mask & FEATURE_DPM_SOCCLK_MASK)) {
1793 min_freq = data->dpm_table.soc_table.dpm_state.soft_min_level;
1795 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1796 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1797 (PPCLK_SOCCLK << 16) | (min_freq & 0xffff))),
1798 "Failed to set soft min socclk!",
1802 if (data->smu_features[GNLD_DPM_FCLK].enabled &&
1803 (feature_mask & FEATURE_DPM_FCLK_MASK)) {
1804 min_freq = data->dpm_table.fclk_table.dpm_state.soft_min_level;
1806 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1807 hwmgr, PPSMC_MSG_SetSoftMinByFreq,
1808 (PPCLK_FCLK << 16) | (min_freq & 0xffff))),
1809 "Failed to set soft min fclk!",
1813 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled &&
1814 (feature_mask & FEATURE_DPM_DCEFCLK_MASK)) {
1815 min_freq = data->dpm_table.dcef_table.dpm_state.hard_min_level;
1817 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1818 hwmgr, PPSMC_MSG_SetHardMinByFreq,
1819 (PPCLK_DCEFCLK << 16) | (min_freq & 0xffff))),
1820 "Failed to set hard min dcefclk!",
1827 static int vega20_upload_dpm_max_level(struct pp_hwmgr *hwmgr, uint32_t feature_mask)
1829 struct vega20_hwmgr *data =
1830 (struct vega20_hwmgr *)(hwmgr->backend);
1834 if (data->smu_features[GNLD_DPM_GFXCLK].enabled &&
1835 (feature_mask & FEATURE_DPM_GFXCLK_MASK)) {
1836 max_freq = data->dpm_table.gfx_table.dpm_state.soft_max_level;
1838 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1839 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1840 (PPCLK_GFXCLK << 16) | (max_freq & 0xffff))),
1841 "Failed to set soft max gfxclk!",
1845 if (data->smu_features[GNLD_DPM_UCLK].enabled &&
1846 (feature_mask & FEATURE_DPM_UCLK_MASK)) {
1847 max_freq = data->dpm_table.mem_table.dpm_state.soft_max_level;
1849 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1850 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1851 (PPCLK_UCLK << 16) | (max_freq & 0xffff))),
1852 "Failed to set soft max memclk!",
1856 if (data->smu_features[GNLD_DPM_UVD].enabled &&
1857 (feature_mask & FEATURE_DPM_UVD_MASK)) {
1858 max_freq = data->dpm_table.vclk_table.dpm_state.soft_max_level;
1860 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1861 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1862 (PPCLK_VCLK << 16) | (max_freq & 0xffff))),
1863 "Failed to set soft max vclk!",
1866 max_freq = data->dpm_table.dclk_table.dpm_state.soft_max_level;
1867 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1868 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1869 (PPCLK_DCLK << 16) | (max_freq & 0xffff))),
1870 "Failed to set soft max dclk!",
1874 if (data->smu_features[GNLD_DPM_VCE].enabled &&
1875 (feature_mask & FEATURE_DPM_VCE_MASK)) {
1876 max_freq = data->dpm_table.eclk_table.dpm_state.soft_max_level;
1878 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1879 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1880 (PPCLK_ECLK << 16) | (max_freq & 0xffff))),
1881 "Failed to set soft max eclk!",
1885 if (data->smu_features[GNLD_DPM_SOCCLK].enabled &&
1886 (feature_mask & FEATURE_DPM_SOCCLK_MASK)) {
1887 max_freq = data->dpm_table.soc_table.dpm_state.soft_max_level;
1889 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1890 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1891 (PPCLK_SOCCLK << 16) | (max_freq & 0xffff))),
1892 "Failed to set soft max socclk!",
1896 if (data->smu_features[GNLD_DPM_FCLK].enabled &&
1897 (feature_mask & FEATURE_DPM_FCLK_MASK)) {
1898 max_freq = data->dpm_table.fclk_table.dpm_state.soft_max_level;
1900 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(
1901 hwmgr, PPSMC_MSG_SetSoftMaxByFreq,
1902 (PPCLK_FCLK << 16) | (max_freq & 0xffff))),
1903 "Failed to set soft max fclk!",
1910 int vega20_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
1912 struct vega20_hwmgr *data =
1913 (struct vega20_hwmgr *)(hwmgr->backend);
1916 if (data->smu_features[GNLD_DPM_VCE].supported) {
1917 if (data->smu_features[GNLD_DPM_VCE].enabled == enable) {
1919 PP_DBG_LOG("[EnableDisableVCEDPM] feature VCE DPM already enabled!\n");
1921 PP_DBG_LOG("[EnableDisableVCEDPM] feature VCE DPM already disabled!\n");
1924 ret = vega20_enable_smc_features(hwmgr,
1926 data->smu_features[GNLD_DPM_VCE].smu_feature_bitmap);
1927 PP_ASSERT_WITH_CODE(!ret,
1928 "Attempt to Enable/Disable DPM VCE Failed!",
1930 data->smu_features[GNLD_DPM_VCE].enabled = enable;
1936 static int vega20_get_clock_ranges(struct pp_hwmgr *hwmgr,
1938 PPCLK_e clock_select,
1945 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
1946 PPSMC_MSG_GetMaxDpmFreq, (clock_select << 16))) == 0,
1947 "[GetClockRanges] Failed to get max clock from SMC!",
1949 *clock = smum_get_argument(hwmgr);
1951 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
1952 PPSMC_MSG_GetMinDpmFreq,
1953 (clock_select << 16))) == 0,
1954 "[GetClockRanges] Failed to get min clock from SMC!",
1956 *clock = smum_get_argument(hwmgr);
1962 static uint32_t vega20_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
1964 struct vega20_hwmgr *data =
1965 (struct vega20_hwmgr *)(hwmgr->backend);
1969 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_GFXCLK].enabled,
1970 "[GetSclks]: gfxclk dpm not enabled!\n",
1974 ret = vega20_get_clock_ranges(hwmgr, &gfx_clk, PPCLK_GFXCLK, false);
1975 PP_ASSERT_WITH_CODE(!ret,
1976 "[GetSclks]: fail to get min PPCLK_GFXCLK\n",
1979 ret = vega20_get_clock_ranges(hwmgr, &gfx_clk, PPCLK_GFXCLK, true);
1980 PP_ASSERT_WITH_CODE(!ret,
1981 "[GetSclks]: fail to get max PPCLK_GFXCLK\n",
1985 return (gfx_clk * 100);
1988 static uint32_t vega20_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
1990 struct vega20_hwmgr *data =
1991 (struct vega20_hwmgr *)(hwmgr->backend);
1995 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_UCLK].enabled,
1996 "[MemMclks]: memclk dpm not enabled!\n",
2000 ret = vega20_get_clock_ranges(hwmgr, &mem_clk, PPCLK_UCLK, false);
2001 PP_ASSERT_WITH_CODE(!ret,
2002 "[GetMclks]: fail to get min PPCLK_UCLK\n",
2005 ret = vega20_get_clock_ranges(hwmgr, &mem_clk, PPCLK_UCLK, true);
2006 PP_ASSERT_WITH_CODE(!ret,
2007 "[GetMclks]: fail to get max PPCLK_UCLK\n",
2011 return (mem_clk * 100);
2014 static int vega20_get_metrics_table(struct pp_hwmgr *hwmgr, SmuMetrics_t *metrics_table)
2016 struct vega20_hwmgr *data =
2017 (struct vega20_hwmgr *)(hwmgr->backend);
2020 if (!data->metrics_time || time_after(jiffies, data->metrics_time + HZ / 2)) {
2021 ret = smum_smc_table_manager(hwmgr, (uint8_t *)metrics_table,
2022 TABLE_SMU_METRICS, true);
2024 pr_info("Failed to export SMU metrics table!\n");
2027 memcpy(&data->metrics_table, metrics_table, sizeof(SmuMetrics_t));
2028 data->metrics_time = jiffies;
2030 memcpy(metrics_table, &data->metrics_table, sizeof(SmuMetrics_t));
2035 static int vega20_get_gpu_power(struct pp_hwmgr *hwmgr,
2039 SmuMetrics_t metrics_table;
2041 ret = vega20_get_metrics_table(hwmgr, &metrics_table);
2045 *query = metrics_table.CurrSocketPower << 8;
2050 static int vega20_get_current_clk_freq(struct pp_hwmgr *hwmgr,
2051 PPCLK_e clk_id, uint32_t *clk_freq)
2057 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(hwmgr,
2058 PPSMC_MSG_GetDpmClockFreq, (clk_id << 16))) == 0,
2059 "[GetCurrentClkFreq] Attempt to get Current Frequency Failed!",
2061 *clk_freq = smum_get_argument(hwmgr);
2063 *clk_freq = *clk_freq * 100;
2068 static int vega20_get_current_activity_percent(struct pp_hwmgr *hwmgr,
2069 uint32_t *activity_percent)
2072 SmuMetrics_t metrics_table;
2074 ret = vega20_get_metrics_table(hwmgr, &metrics_table);
2078 *activity_percent = metrics_table.AverageGfxActivity;
2083 static int vega20_read_sensor(struct pp_hwmgr *hwmgr, int idx,
2084 void *value, int *size)
2086 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2087 struct amdgpu_device *adev = hwmgr->adev;
2088 SmuMetrics_t metrics_table;
2093 case AMDGPU_PP_SENSOR_GFX_SCLK:
2094 ret = vega20_get_metrics_table(hwmgr, &metrics_table);
2098 *((uint32_t *)value) = metrics_table.AverageGfxclkFrequency * 100;
2101 case AMDGPU_PP_SENSOR_GFX_MCLK:
2102 ret = vega20_get_current_clk_freq(hwmgr,
2108 case AMDGPU_PP_SENSOR_GPU_LOAD:
2109 ret = vega20_get_current_activity_percent(hwmgr, (uint32_t *)value);
2113 case AMDGPU_PP_SENSOR_GPU_TEMP:
2114 *((uint32_t *)value) = vega20_thermal_get_temperature(hwmgr);
2117 case AMDGPU_PP_SENSOR_UVD_POWER:
2118 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
2121 case AMDGPU_PP_SENSOR_VCE_POWER:
2122 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
2125 case AMDGPU_PP_SENSOR_GPU_POWER:
2127 ret = vega20_get_gpu_power(hwmgr, (uint32_t *)value);
2129 case AMDGPU_PP_SENSOR_VDDGFX:
2130 val_vid = (RREG32_SOC15(SMUIO, 0, mmSMUSVI0_TEL_PLANE0) &
2131 SMUSVI0_TEL_PLANE0__SVI0_PLANE0_VDDCOR_MASK) >>
2132 SMUSVI0_TEL_PLANE0__SVI0_PLANE0_VDDCOR__SHIFT;
2133 *((uint32_t *)value) =
2134 (uint32_t)convert_to_vddc((uint8_t)val_vid);
2136 case AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK:
2137 ret = vega20_get_enabled_smc_features(hwmgr, (uint64_t *)value);
2148 int vega20_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
2149 struct pp_display_clock_request *clock_req)
2152 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2153 enum amd_pp_clock_type clk_type = clock_req->clock_type;
2154 uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
2155 PPCLK_e clk_select = 0;
2156 uint32_t clk_request = 0;
2158 if (data->smu_features[GNLD_DPM_DCEFCLK].enabled) {
2160 case amd_pp_dcef_clock:
2161 clk_select = PPCLK_DCEFCLK;
2163 case amd_pp_disp_clock:
2164 clk_select = PPCLK_DISPCLK;
2166 case amd_pp_pixel_clock:
2167 clk_select = PPCLK_PIXCLK;
2169 case amd_pp_phy_clock:
2170 clk_select = PPCLK_PHYCLK;
2173 pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
2179 clk_request = (clk_select << 16) | clk_freq;
2180 result = smum_send_msg_to_smc_with_parameter(hwmgr,
2181 PPSMC_MSG_SetHardMinByFreq,
2189 static int vega20_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
2190 PHM_PerformanceLevelDesignation designation, uint32_t index,
2191 PHM_PerformanceLevel *level)
2196 static int vega20_notify_smc_display_config_after_ps_adjustment(
2197 struct pp_hwmgr *hwmgr)
2199 struct vega20_hwmgr *data =
2200 (struct vega20_hwmgr *)(hwmgr->backend);
2201 struct vega20_single_dpm_table *dpm_table =
2202 &data->dpm_table.mem_table;
2203 struct PP_Clocks min_clocks = {0};
2204 struct pp_display_clock_request clock_req;
2207 min_clocks.dcefClock = hwmgr->display_config->min_dcef_set_clk;
2208 min_clocks.dcefClockInSR = hwmgr->display_config->min_dcef_deep_sleep_set_clk;
2209 min_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
2211 if (data->smu_features[GNLD_DPM_DCEFCLK].supported) {
2212 clock_req.clock_type = amd_pp_dcef_clock;
2213 clock_req.clock_freq_in_khz = min_clocks.dcefClock * 10;
2214 if (!vega20_display_clock_voltage_request(hwmgr, &clock_req)) {
2215 if (data->smu_features[GNLD_DS_DCEFCLK].supported)
2216 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc_with_parameter(
2217 hwmgr, PPSMC_MSG_SetMinDeepSleepDcefclk,
2218 min_clocks.dcefClockInSR / 100)) == 0,
2219 "Attempt to set divider for DCEFCLK Failed!",
2222 pr_info("Attempt to set Hard Min for DCEFCLK Failed!");
2226 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
2227 dpm_table->dpm_state.hard_min_level = min_clocks.memoryClock / 100;
2228 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(hwmgr,
2229 PPSMC_MSG_SetHardMinByFreq,
2230 (PPCLK_UCLK << 16 ) | dpm_table->dpm_state.hard_min_level)),
2231 "[SetHardMinFreq] Set hard min uclk failed!",
2238 static int vega20_force_dpm_highest(struct pp_hwmgr *hwmgr)
2240 struct vega20_hwmgr *data =
2241 (struct vega20_hwmgr *)(hwmgr->backend);
2242 uint32_t soft_level;
2245 soft_level = vega20_find_highest_dpm_level(&(data->dpm_table.gfx_table));
2247 data->dpm_table.gfx_table.dpm_state.soft_min_level =
2248 data->dpm_table.gfx_table.dpm_state.soft_max_level =
2249 data->dpm_table.gfx_table.dpm_levels[soft_level].value;
2251 soft_level = vega20_find_highest_dpm_level(&(data->dpm_table.mem_table));
2253 data->dpm_table.mem_table.dpm_state.soft_min_level =
2254 data->dpm_table.mem_table.dpm_state.soft_max_level =
2255 data->dpm_table.mem_table.dpm_levels[soft_level].value;
2257 soft_level = vega20_find_highest_dpm_level(&(data->dpm_table.soc_table));
2259 data->dpm_table.soc_table.dpm_state.soft_min_level =
2260 data->dpm_table.soc_table.dpm_state.soft_max_level =
2261 data->dpm_table.soc_table.dpm_levels[soft_level].value;
2263 ret = vega20_upload_dpm_min_level(hwmgr, 0xFFFFFFFF);
2264 PP_ASSERT_WITH_CODE(!ret,
2265 "Failed to upload boot level to highest!",
2268 ret = vega20_upload_dpm_max_level(hwmgr, 0xFFFFFFFF);
2269 PP_ASSERT_WITH_CODE(!ret,
2270 "Failed to upload dpm max level to highest!",
2276 static int vega20_force_dpm_lowest(struct pp_hwmgr *hwmgr)
2278 struct vega20_hwmgr *data =
2279 (struct vega20_hwmgr *)(hwmgr->backend);
2280 uint32_t soft_level;
2283 soft_level = vega20_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
2285 data->dpm_table.gfx_table.dpm_state.soft_min_level =
2286 data->dpm_table.gfx_table.dpm_state.soft_max_level =
2287 data->dpm_table.gfx_table.dpm_levels[soft_level].value;
2289 soft_level = vega20_find_lowest_dpm_level(&(data->dpm_table.mem_table));
2291 data->dpm_table.mem_table.dpm_state.soft_min_level =
2292 data->dpm_table.mem_table.dpm_state.soft_max_level =
2293 data->dpm_table.mem_table.dpm_levels[soft_level].value;
2295 soft_level = vega20_find_lowest_dpm_level(&(data->dpm_table.soc_table));
2297 data->dpm_table.soc_table.dpm_state.soft_min_level =
2298 data->dpm_table.soc_table.dpm_state.soft_max_level =
2299 data->dpm_table.soc_table.dpm_levels[soft_level].value;
2301 ret = vega20_upload_dpm_min_level(hwmgr, 0xFFFFFFFF);
2302 PP_ASSERT_WITH_CODE(!ret,
2303 "Failed to upload boot level to highest!",
2306 ret = vega20_upload_dpm_max_level(hwmgr, 0xFFFFFFFF);
2307 PP_ASSERT_WITH_CODE(!ret,
2308 "Failed to upload dpm max level to highest!",
2315 static int vega20_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
2317 struct vega20_hwmgr *data =
2318 (struct vega20_hwmgr *)(hwmgr->backend);
2319 uint32_t soft_min_level, soft_max_level;
2322 soft_min_level = vega20_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
2323 soft_max_level = vega20_find_highest_dpm_level(&(data->dpm_table.gfx_table));
2324 data->dpm_table.gfx_table.dpm_state.soft_min_level =
2325 data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
2326 data->dpm_table.gfx_table.dpm_state.soft_max_level =
2327 data->dpm_table.gfx_table.dpm_levels[soft_max_level].value;
2329 soft_min_level = vega20_find_lowest_dpm_level(&(data->dpm_table.mem_table));
2330 soft_max_level = vega20_find_highest_dpm_level(&(data->dpm_table.mem_table));
2331 data->dpm_table.mem_table.dpm_state.soft_min_level =
2332 data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
2333 data->dpm_table.mem_table.dpm_state.soft_max_level =
2334 data->dpm_table.mem_table.dpm_levels[soft_max_level].value;
2336 soft_min_level = vega20_find_lowest_dpm_level(&(data->dpm_table.soc_table));
2337 soft_max_level = vega20_find_highest_dpm_level(&(data->dpm_table.soc_table));
2338 data->dpm_table.soc_table.dpm_state.soft_min_level =
2339 data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
2340 data->dpm_table.soc_table.dpm_state.soft_max_level =
2341 data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
2343 ret = vega20_upload_dpm_min_level(hwmgr, 0xFFFFFFFF);
2344 PP_ASSERT_WITH_CODE(!ret,
2345 "Failed to upload DPM Bootup Levels!",
2348 ret = vega20_upload_dpm_max_level(hwmgr, 0xFFFFFFFF);
2349 PP_ASSERT_WITH_CODE(!ret,
2350 "Failed to upload DPM Max Levels!",
2356 static int vega20_get_profiling_clk_mask(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
2357 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *soc_mask)
2359 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2360 struct vega20_single_dpm_table *gfx_dpm_table = &(data->dpm_table.gfx_table);
2361 struct vega20_single_dpm_table *mem_dpm_table = &(data->dpm_table.mem_table);
2362 struct vega20_single_dpm_table *soc_dpm_table = &(data->dpm_table.soc_table);
2368 if (gfx_dpm_table->count > VEGA20_UMD_PSTATE_GFXCLK_LEVEL &&
2369 mem_dpm_table->count > VEGA20_UMD_PSTATE_MCLK_LEVEL &&
2370 soc_dpm_table->count > VEGA20_UMD_PSTATE_SOCCLK_LEVEL) {
2371 *sclk_mask = VEGA20_UMD_PSTATE_GFXCLK_LEVEL;
2372 *mclk_mask = VEGA20_UMD_PSTATE_MCLK_LEVEL;
2373 *soc_mask = VEGA20_UMD_PSTATE_SOCCLK_LEVEL;
2376 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
2378 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
2380 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
2381 *sclk_mask = gfx_dpm_table->count - 1;
2382 *mclk_mask = mem_dpm_table->count - 1;
2383 *soc_mask = soc_dpm_table->count - 1;
2389 static int vega20_force_clock_level(struct pp_hwmgr *hwmgr,
2390 enum pp_clock_type type, uint32_t mask)
2392 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2393 uint32_t soft_min_level, soft_max_level, hard_min_level;
2398 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2399 soft_max_level = mask ? (fls(mask) - 1) : 0;
2401 if (soft_max_level >= data->dpm_table.gfx_table.count) {
2402 pr_err("Clock level specified %d is over max allowed %d\n",
2404 data->dpm_table.gfx_table.count - 1);
2408 data->dpm_table.gfx_table.dpm_state.soft_min_level =
2409 data->dpm_table.gfx_table.dpm_levels[soft_min_level].value;
2410 data->dpm_table.gfx_table.dpm_state.soft_max_level =
2411 data->dpm_table.gfx_table.dpm_levels[soft_max_level].value;
2413 ret = vega20_upload_dpm_min_level(hwmgr, FEATURE_DPM_GFXCLK_MASK);
2414 PP_ASSERT_WITH_CODE(!ret,
2415 "Failed to upload boot level to lowest!",
2418 ret = vega20_upload_dpm_max_level(hwmgr, FEATURE_DPM_GFXCLK_MASK);
2419 PP_ASSERT_WITH_CODE(!ret,
2420 "Failed to upload dpm max level to highest!",
2425 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2426 soft_max_level = mask ? (fls(mask) - 1) : 0;
2428 if (soft_max_level >= data->dpm_table.mem_table.count) {
2429 pr_err("Clock level specified %d is over max allowed %d\n",
2431 data->dpm_table.mem_table.count - 1);
2435 data->dpm_table.mem_table.dpm_state.soft_min_level =
2436 data->dpm_table.mem_table.dpm_levels[soft_min_level].value;
2437 data->dpm_table.mem_table.dpm_state.soft_max_level =
2438 data->dpm_table.mem_table.dpm_levels[soft_max_level].value;
2440 ret = vega20_upload_dpm_min_level(hwmgr, FEATURE_DPM_UCLK_MASK);
2441 PP_ASSERT_WITH_CODE(!ret,
2442 "Failed to upload boot level to lowest!",
2445 ret = vega20_upload_dpm_max_level(hwmgr, FEATURE_DPM_UCLK_MASK);
2446 PP_ASSERT_WITH_CODE(!ret,
2447 "Failed to upload dpm max level to highest!",
2453 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2454 soft_max_level = mask ? (fls(mask) - 1) : 0;
2456 if (soft_max_level >= data->dpm_table.soc_table.count) {
2457 pr_err("Clock level specified %d is over max allowed %d\n",
2459 data->dpm_table.soc_table.count - 1);
2463 data->dpm_table.soc_table.dpm_state.soft_min_level =
2464 data->dpm_table.soc_table.dpm_levels[soft_min_level].value;
2465 data->dpm_table.soc_table.dpm_state.soft_max_level =
2466 data->dpm_table.soc_table.dpm_levels[soft_max_level].value;
2468 ret = vega20_upload_dpm_min_level(hwmgr, FEATURE_DPM_SOCCLK_MASK);
2469 PP_ASSERT_WITH_CODE(!ret,
2470 "Failed to upload boot level to lowest!",
2473 ret = vega20_upload_dpm_max_level(hwmgr, FEATURE_DPM_SOCCLK_MASK);
2474 PP_ASSERT_WITH_CODE(!ret,
2475 "Failed to upload dpm max level to highest!",
2481 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2482 soft_max_level = mask ? (fls(mask) - 1) : 0;
2484 if (soft_max_level >= data->dpm_table.fclk_table.count) {
2485 pr_err("Clock level specified %d is over max allowed %d\n",
2487 data->dpm_table.fclk_table.count - 1);
2491 data->dpm_table.fclk_table.dpm_state.soft_min_level =
2492 data->dpm_table.fclk_table.dpm_levels[soft_min_level].value;
2493 data->dpm_table.fclk_table.dpm_state.soft_max_level =
2494 data->dpm_table.fclk_table.dpm_levels[soft_max_level].value;
2496 ret = vega20_upload_dpm_min_level(hwmgr, FEATURE_DPM_FCLK_MASK);
2497 PP_ASSERT_WITH_CODE(!ret,
2498 "Failed to upload boot level to lowest!",
2501 ret = vega20_upload_dpm_max_level(hwmgr, FEATURE_DPM_FCLK_MASK);
2502 PP_ASSERT_WITH_CODE(!ret,
2503 "Failed to upload dpm max level to highest!",
2509 hard_min_level = mask ? (ffs(mask) - 1) : 0;
2511 if (hard_min_level >= data->dpm_table.dcef_table.count) {
2512 pr_err("Clock level specified %d is over max allowed %d\n",
2514 data->dpm_table.dcef_table.count - 1);
2518 data->dpm_table.dcef_table.dpm_state.hard_min_level =
2519 data->dpm_table.dcef_table.dpm_levels[hard_min_level].value;
2521 ret = vega20_upload_dpm_min_level(hwmgr, FEATURE_DPM_DCEFCLK_MASK);
2522 PP_ASSERT_WITH_CODE(!ret,
2523 "Failed to upload boot level to lowest!",
2526 //TODO: Setting DCEFCLK max dpm level is not supported
2531 soft_min_level = mask ? (ffs(mask) - 1) : 0;
2532 soft_max_level = mask ? (fls(mask) - 1) : 0;
2533 if (soft_min_level >= NUM_LINK_LEVELS ||
2534 soft_max_level >= NUM_LINK_LEVELS)
2537 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
2538 PPSMC_MSG_SetMinLinkDpmByIndex, soft_min_level);
2539 PP_ASSERT_WITH_CODE(!ret,
2540 "Failed to set min link dpm level!",
2552 static int vega20_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
2553 enum amd_dpm_forced_level level)
2556 uint32_t sclk_mask, mclk_mask, soc_mask;
2559 case AMD_DPM_FORCED_LEVEL_HIGH:
2560 ret = vega20_force_dpm_highest(hwmgr);
2563 case AMD_DPM_FORCED_LEVEL_LOW:
2564 ret = vega20_force_dpm_lowest(hwmgr);
2567 case AMD_DPM_FORCED_LEVEL_AUTO:
2568 ret = vega20_unforce_dpm_levels(hwmgr);
2571 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
2572 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
2573 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
2574 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
2575 ret = vega20_get_profiling_clk_mask(hwmgr, level, &sclk_mask, &mclk_mask, &soc_mask);
2578 vega20_force_clock_level(hwmgr, PP_SCLK, 1 << sclk_mask);
2579 vega20_force_clock_level(hwmgr, PP_MCLK, 1 << mclk_mask);
2580 vega20_force_clock_level(hwmgr, PP_SOCCLK, 1 << soc_mask);
2583 case AMD_DPM_FORCED_LEVEL_MANUAL:
2584 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
2592 static uint32_t vega20_get_fan_control_mode(struct pp_hwmgr *hwmgr)
2594 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2596 if (data->smu_features[GNLD_FAN_CONTROL].enabled == false)
2597 return AMD_FAN_CTRL_MANUAL;
2599 return AMD_FAN_CTRL_AUTO;
2602 static void vega20_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
2605 case AMD_FAN_CTRL_NONE:
2606 vega20_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
2608 case AMD_FAN_CTRL_MANUAL:
2609 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
2610 vega20_fan_ctrl_stop_smc_fan_control(hwmgr);
2612 case AMD_FAN_CTRL_AUTO:
2613 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
2614 vega20_fan_ctrl_start_smc_fan_control(hwmgr);
2621 static int vega20_get_dal_power_level(struct pp_hwmgr *hwmgr,
2622 struct amd_pp_simple_clock_info *info)
2625 struct phm_ppt_v2_information *table_info =
2626 (struct phm_ppt_v2_information *)hwmgr->pptable;
2627 struct phm_clock_and_voltage_limits *max_limits =
2628 &table_info->max_clock_voltage_on_ac;
2630 info->engine_max_clock = max_limits->sclk;
2631 info->memory_max_clock = max_limits->mclk;
2637 static int vega20_get_sclks(struct pp_hwmgr *hwmgr,
2638 struct pp_clock_levels_with_latency *clocks)
2640 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2641 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.gfx_table);
2644 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_GFXCLK].enabled,
2645 "[GetSclks]: gfxclk dpm not enabled!\n",
2648 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2649 clocks->num_levels = count;
2651 for (i = 0; i < count; i++) {
2652 clocks->data[i].clocks_in_khz =
2653 dpm_table->dpm_levels[i].value * 1000;
2654 clocks->data[i].latency_in_us = 0;
2660 static uint32_t vega20_get_mem_latency(struct pp_hwmgr *hwmgr,
2666 static int vega20_get_memclocks(struct pp_hwmgr *hwmgr,
2667 struct pp_clock_levels_with_latency *clocks)
2669 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2670 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.mem_table);
2673 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_UCLK].enabled,
2674 "[GetMclks]: uclk dpm not enabled!\n",
2677 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2678 clocks->num_levels = data->mclk_latency_table.count = count;
2680 for (i = 0; i < count; i++) {
2681 clocks->data[i].clocks_in_khz =
2682 data->mclk_latency_table.entries[i].frequency =
2683 dpm_table->dpm_levels[i].value * 1000;
2684 clocks->data[i].latency_in_us =
2685 data->mclk_latency_table.entries[i].latency =
2686 vega20_get_mem_latency(hwmgr, dpm_table->dpm_levels[i].value);
2692 static int vega20_get_dcefclocks(struct pp_hwmgr *hwmgr,
2693 struct pp_clock_levels_with_latency *clocks)
2695 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2696 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.dcef_table);
2699 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_DCEFCLK].enabled,
2700 "[GetDcfclocks]: dcefclk dpm not enabled!\n",
2703 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2704 clocks->num_levels = count;
2706 for (i = 0; i < count; i++) {
2707 clocks->data[i].clocks_in_khz =
2708 dpm_table->dpm_levels[i].value * 1000;
2709 clocks->data[i].latency_in_us = 0;
2715 static int vega20_get_socclocks(struct pp_hwmgr *hwmgr,
2716 struct pp_clock_levels_with_latency *clocks)
2718 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2719 struct vega20_single_dpm_table *dpm_table = &(data->dpm_table.soc_table);
2722 PP_ASSERT_WITH_CODE(data->smu_features[GNLD_DPM_SOCCLK].enabled,
2723 "[GetSocclks]: socclk dpm not enabled!\n",
2726 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
2727 clocks->num_levels = count;
2729 for (i = 0; i < count; i++) {
2730 clocks->data[i].clocks_in_khz =
2731 dpm_table->dpm_levels[i].value * 1000;
2732 clocks->data[i].latency_in_us = 0;
2739 static int vega20_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
2740 enum amd_pp_clock_type type,
2741 struct pp_clock_levels_with_latency *clocks)
2746 case amd_pp_sys_clock:
2747 ret = vega20_get_sclks(hwmgr, clocks);
2749 case amd_pp_mem_clock:
2750 ret = vega20_get_memclocks(hwmgr, clocks);
2752 case amd_pp_dcef_clock:
2753 ret = vega20_get_dcefclocks(hwmgr, clocks);
2755 case amd_pp_soc_clock:
2756 ret = vega20_get_socclocks(hwmgr, clocks);
2765 static int vega20_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
2766 enum amd_pp_clock_type type,
2767 struct pp_clock_levels_with_voltage *clocks)
2769 clocks->num_levels = 0;
2774 static int vega20_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
2777 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
2778 Watermarks_t *table = &(data->smc_state_table.water_marks_table);
2779 struct dm_pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges = clock_ranges;
2781 if (!data->registry_data.disable_water_mark &&
2782 data->smu_features[GNLD_DPM_DCEFCLK].supported &&
2783 data->smu_features[GNLD_DPM_SOCCLK].supported) {
2784 smu_set_watermarks_for_clocks_ranges(table, wm_with_clock_ranges);
2785 data->water_marks_bitmap |= WaterMarksExist;
2786 data->water_marks_bitmap &= ~WaterMarksLoaded;
2792 static int vega20_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
2793 enum PP_OD_DPM_TABLE_COMMAND type,
2794 long *input, uint32_t size)
2796 struct vega20_hwmgr *data =
2797 (struct vega20_hwmgr *)(hwmgr->backend);
2798 struct vega20_od8_single_setting *od8_settings =
2799 data->od8_settings.od8_settings_array;
2800 OverDriveTable_t *od_table =
2801 &(data->smc_state_table.overdrive_table);
2802 struct pp_clock_levels_with_latency clocks;
2803 int32_t input_index, input_clk, input_vol, i;
2807 PP_ASSERT_WITH_CODE(input, "NULL user input for clock and voltage",
2811 case PP_OD_EDIT_SCLK_VDDC_TABLE:
2812 if (!(od8_settings[OD8_SETTING_GFXCLK_FMIN].feature_id &&
2813 od8_settings[OD8_SETTING_GFXCLK_FMAX].feature_id)) {
2814 pr_info("Sclk min/max frequency overdrive not supported\n");
2818 for (i = 0; i < size; i += 2) {
2820 pr_info("invalid number of input parameters %d\n",
2825 input_index = input[i];
2826 input_clk = input[i + 1];
2828 if (input_index != 0 && input_index != 1) {
2829 pr_info("Invalid index %d\n", input_index);
2830 pr_info("Support min/max sclk frequency setting only which index by 0/1\n");
2834 if (input_clk < od8_settings[OD8_SETTING_GFXCLK_FMIN].min_value ||
2835 input_clk > od8_settings[OD8_SETTING_GFXCLK_FMAX].max_value) {
2836 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2838 od8_settings[OD8_SETTING_GFXCLK_FMIN].min_value,
2839 od8_settings[OD8_SETTING_GFXCLK_FMAX].max_value);
2843 if ((input_index == 0 && od_table->GfxclkFmin != input_clk) ||
2844 (input_index == 1 && od_table->GfxclkFmax != input_clk))
2845 data->gfxclk_overdrive = true;
2847 if (input_index == 0)
2848 od_table->GfxclkFmin = input_clk;
2850 od_table->GfxclkFmax = input_clk;
2855 case PP_OD_EDIT_MCLK_VDDC_TABLE:
2856 if (!od8_settings[OD8_SETTING_UCLK_FMAX].feature_id) {
2857 pr_info("Mclk max frequency overdrive not supported\n");
2861 ret = vega20_get_memclocks(hwmgr, &clocks);
2862 PP_ASSERT_WITH_CODE(!ret,
2863 "Attempt to get memory clk levels failed!",
2866 for (i = 0; i < size; i += 2) {
2868 pr_info("invalid number of input parameters %d\n",
2873 input_index = input[i];
2874 input_clk = input[i + 1];
2876 if (input_index != 1) {
2877 pr_info("Invalid index %d\n", input_index);
2878 pr_info("Support max Mclk frequency setting only which index by 1\n");
2882 if (input_clk < clocks.data[0].clocks_in_khz / 1000 ||
2883 input_clk > od8_settings[OD8_SETTING_UCLK_FMAX].max_value) {
2884 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2886 clocks.data[0].clocks_in_khz / 1000,
2887 od8_settings[OD8_SETTING_UCLK_FMAX].max_value);
2891 if (input_index == 1 && od_table->UclkFmax != input_clk)
2892 data->memclk_overdrive = true;
2894 od_table->UclkFmax = input_clk;
2899 case PP_OD_EDIT_VDDC_CURVE:
2900 if (!(od8_settings[OD8_SETTING_GFXCLK_FREQ1].feature_id &&
2901 od8_settings[OD8_SETTING_GFXCLK_FREQ2].feature_id &&
2902 od8_settings[OD8_SETTING_GFXCLK_FREQ3].feature_id &&
2903 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id &&
2904 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id &&
2905 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id)) {
2906 pr_info("Voltage curve calibrate not supported\n");
2910 for (i = 0; i < size; i += 3) {
2912 pr_info("invalid number of input parameters %d\n",
2917 input_index = input[i];
2918 input_clk = input[i + 1];
2919 input_vol = input[i + 2];
2921 if (input_index > 2) {
2922 pr_info("Setting for point %d is not supported\n",
2924 pr_info("Three supported points index by 0, 1, 2\n");
2928 od8_id = OD8_SETTING_GFXCLK_FREQ1 + 2 * input_index;
2929 if (input_clk < od8_settings[od8_id].min_value ||
2930 input_clk > od8_settings[od8_id].max_value) {
2931 pr_info("clock freq %d is not within allowed range [%d - %d]\n",
2933 od8_settings[od8_id].min_value,
2934 od8_settings[od8_id].max_value);
2938 od8_id = OD8_SETTING_GFXCLK_VOLTAGE1 + 2 * input_index;
2939 if (input_vol < od8_settings[od8_id].min_value ||
2940 input_vol > od8_settings[od8_id].max_value) {
2941 pr_info("clock voltage %d is not within allowed range [%d - %d]\n",
2943 od8_settings[od8_id].min_value,
2944 od8_settings[od8_id].max_value);
2948 switch (input_index) {
2950 od_table->GfxclkFreq1 = input_clk;
2951 od_table->GfxclkVolt1 = input_vol * VOLTAGE_SCALE;
2954 od_table->GfxclkFreq2 = input_clk;
2955 od_table->GfxclkVolt2 = input_vol * VOLTAGE_SCALE;
2958 od_table->GfxclkFreq3 = input_clk;
2959 od_table->GfxclkVolt3 = input_vol * VOLTAGE_SCALE;
2965 case PP_OD_RESTORE_DEFAULT_TABLE:
2966 data->gfxclk_overdrive = false;
2967 data->memclk_overdrive = false;
2969 ret = smum_smc_table_manager(hwmgr,
2970 (uint8_t *)od_table,
2971 TABLE_OVERDRIVE, true);
2972 PP_ASSERT_WITH_CODE(!ret,
2973 "Failed to export overdrive table!",
2977 case PP_OD_COMMIT_DPM_TABLE:
2978 ret = smum_smc_table_manager(hwmgr,
2979 (uint8_t *)od_table,
2980 TABLE_OVERDRIVE, false);
2981 PP_ASSERT_WITH_CODE(!ret,
2982 "Failed to import overdrive table!",
2985 /* retrieve updated gfxclk table */
2986 if (data->gfxclk_overdrive) {
2987 data->gfxclk_overdrive = false;
2989 ret = vega20_setup_gfxclk_dpm_table(hwmgr);
2994 /* retrieve updated memclk table */
2995 if (data->memclk_overdrive) {
2996 data->memclk_overdrive = false;
2998 ret = vega20_setup_memclk_dpm_table(hwmgr);
3011 static int vega20_get_ppfeature_status(struct pp_hwmgr *hwmgr, char *buf)
3013 static const char *ppfeature_name[] = {
3047 static const char *output_title[] = {
3051 uint64_t features_enabled;
3056 ret = vega20_get_enabled_smc_features(hwmgr, &features_enabled);
3057 PP_ASSERT_WITH_CODE(!ret,
3058 "[EnableAllSmuFeatures] Failed to get enabled smc features!",
3061 size += sprintf(buf + size, "Current ppfeatures: 0x%016llx\n", features_enabled);
3062 size += sprintf(buf + size, "%-19s %-22s %s\n",
3066 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
3067 size += sprintf(buf + size, "%-19s 0x%016llx %6s\n",
3070 (features_enabled & (1ULL << i)) ? "Y" : "N");
3076 static int vega20_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t new_ppfeature_masks)
3078 uint64_t features_enabled;
3079 uint64_t features_to_enable;
3080 uint64_t features_to_disable;
3083 if (new_ppfeature_masks >= (1ULL << GNLD_FEATURES_MAX))
3086 ret = vega20_get_enabled_smc_features(hwmgr, &features_enabled);
3090 features_to_disable =
3091 (features_enabled ^ new_ppfeature_masks) & features_enabled;
3092 features_to_enable =
3093 (features_enabled ^ new_ppfeature_masks) ^ features_to_disable;
3095 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
3096 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
3098 if (features_to_disable) {
3099 ret = vega20_enable_smc_features(hwmgr, false, features_to_disable);
3104 if (features_to_enable) {
3105 ret = vega20_enable_smc_features(hwmgr, true, features_to_enable);
3113 static int vega20_print_clock_levels(struct pp_hwmgr *hwmgr,
3114 enum pp_clock_type type, char *buf)
3116 struct vega20_hwmgr *data =
3117 (struct vega20_hwmgr *)(hwmgr->backend);
3118 struct vega20_od8_single_setting *od8_settings =
3119 data->od8_settings.od8_settings_array;
3120 OverDriveTable_t *od_table =
3121 &(data->smc_state_table.overdrive_table);
3122 struct phm_ppt_v3_information *pptable_information =
3123 (struct phm_ppt_v3_information *)hwmgr->pptable;
3124 PPTable_t *pptable = (PPTable_t *)pptable_information->smc_pptable;
3125 struct amdgpu_device *adev = hwmgr->adev;
3126 struct pp_clock_levels_with_latency clocks;
3127 struct vega20_single_dpm_table *fclk_dpm_table =
3128 &(data->dpm_table.fclk_table);
3129 int i, now, size = 0;
3131 uint32_t gen_speed, lane_width;
3135 ret = vega20_get_current_clk_freq(hwmgr, PPCLK_GFXCLK, &now);
3136 PP_ASSERT_WITH_CODE(!ret,
3137 "Attempt to get current gfx clk Failed!",
3140 ret = vega20_get_sclks(hwmgr, &clocks);
3141 PP_ASSERT_WITH_CODE(!ret,
3142 "Attempt to get gfx clk levels Failed!",
3145 for (i = 0; i < clocks.num_levels; i++)
3146 size += sprintf(buf + size, "%d: %uMhz %s\n",
3147 i, clocks.data[i].clocks_in_khz / 1000,
3148 (clocks.data[i].clocks_in_khz == now * 10) ? "*" : "");
3152 ret = vega20_get_current_clk_freq(hwmgr, PPCLK_UCLK, &now);
3153 PP_ASSERT_WITH_CODE(!ret,
3154 "Attempt to get current mclk freq Failed!",
3157 ret = vega20_get_memclocks(hwmgr, &clocks);
3158 PP_ASSERT_WITH_CODE(!ret,
3159 "Attempt to get memory clk levels Failed!",
3162 for (i = 0; i < clocks.num_levels; i++)
3163 size += sprintf(buf + size, "%d: %uMhz %s\n",
3164 i, clocks.data[i].clocks_in_khz / 1000,
3165 (clocks.data[i].clocks_in_khz == now * 10) ? "*" : "");
3169 ret = vega20_get_current_clk_freq(hwmgr, PPCLK_SOCCLK, &now);
3170 PP_ASSERT_WITH_CODE(!ret,
3171 "Attempt to get current socclk freq Failed!",
3174 ret = vega20_get_socclocks(hwmgr, &clocks);
3175 PP_ASSERT_WITH_CODE(!ret,
3176 "Attempt to get soc clk levels Failed!",
3179 for (i = 0; i < clocks.num_levels; i++)
3180 size += sprintf(buf + size, "%d: %uMhz %s\n",
3181 i, clocks.data[i].clocks_in_khz / 1000,
3182 (clocks.data[i].clocks_in_khz == now * 10) ? "*" : "");
3186 ret = vega20_get_current_clk_freq(hwmgr, PPCLK_FCLK, &now);
3187 PP_ASSERT_WITH_CODE(!ret,
3188 "Attempt to get current fclk freq Failed!",
3191 for (i = 0; i < fclk_dpm_table->count; i++)
3192 size += sprintf(buf + size, "%d: %uMhz %s\n",
3193 i, fclk_dpm_table->dpm_levels[i].value,
3194 fclk_dpm_table->dpm_levels[i].value == (now / 100) ? "*" : "");
3198 ret = vega20_get_current_clk_freq(hwmgr, PPCLK_DCEFCLK, &now);
3199 PP_ASSERT_WITH_CODE(!ret,
3200 "Attempt to get current dcefclk freq Failed!",
3203 ret = vega20_get_dcefclocks(hwmgr, &clocks);
3204 PP_ASSERT_WITH_CODE(!ret,
3205 "Attempt to get dcefclk levels Failed!",
3208 for (i = 0; i < clocks.num_levels; i++)
3209 size += sprintf(buf + size, "%d: %uMhz %s\n",
3210 i, clocks.data[i].clocks_in_khz / 1000,
3211 (clocks.data[i].clocks_in_khz == now * 10) ? "*" : "");
3215 gen_speed = (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
3216 PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
3217 >> PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
3218 lane_width = (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
3219 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
3220 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
3221 for (i = 0; i < NUM_LINK_LEVELS; i++)
3222 size += sprintf(buf + size, "%d: %s %s %dMhz %s\n", i,
3223 (pptable->PcieGenSpeed[i] == 0) ? "2.5GT/s," :
3224 (pptable->PcieGenSpeed[i] == 1) ? "5.0GT/s," :
3225 (pptable->PcieGenSpeed[i] == 2) ? "8.0GT/s," :
3226 (pptable->PcieGenSpeed[i] == 3) ? "16.0GT/s," : "",
3227 (pptable->PcieLaneCount[i] == 1) ? "x1" :
3228 (pptable->PcieLaneCount[i] == 2) ? "x2" :
3229 (pptable->PcieLaneCount[i] == 3) ? "x4" :
3230 (pptable->PcieLaneCount[i] == 4) ? "x8" :
3231 (pptable->PcieLaneCount[i] == 5) ? "x12" :
3232 (pptable->PcieLaneCount[i] == 6) ? "x16" : "",
3233 pptable->LclkFreq[i],
3234 (gen_speed == pptable->PcieGenSpeed[i]) &&
3235 (lane_width == pptable->PcieLaneCount[i]) ?
3240 if (od8_settings[OD8_SETTING_GFXCLK_FMIN].feature_id &&
3241 od8_settings[OD8_SETTING_GFXCLK_FMAX].feature_id) {
3242 size = sprintf(buf, "%s:\n", "OD_SCLK");
3243 size += sprintf(buf + size, "0: %10uMhz\n",
3244 od_table->GfxclkFmin);
3245 size += sprintf(buf + size, "1: %10uMhz\n",
3246 od_table->GfxclkFmax);
3251 if (od8_settings[OD8_SETTING_UCLK_FMAX].feature_id) {
3252 size = sprintf(buf, "%s:\n", "OD_MCLK");
3253 size += sprintf(buf + size, "1: %10uMhz\n",
3254 od_table->UclkFmax);
3260 if (od8_settings[OD8_SETTING_GFXCLK_FREQ1].feature_id &&
3261 od8_settings[OD8_SETTING_GFXCLK_FREQ2].feature_id &&
3262 od8_settings[OD8_SETTING_GFXCLK_FREQ3].feature_id &&
3263 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id &&
3264 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id &&
3265 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id) {
3266 size = sprintf(buf, "%s:\n", "OD_VDDC_CURVE");
3267 size += sprintf(buf + size, "0: %10uMhz %10dmV\n",
3268 od_table->GfxclkFreq1,
3269 od_table->GfxclkVolt1 / VOLTAGE_SCALE);
3270 size += sprintf(buf + size, "1: %10uMhz %10dmV\n",
3271 od_table->GfxclkFreq2,
3272 od_table->GfxclkVolt2 / VOLTAGE_SCALE);
3273 size += sprintf(buf + size, "2: %10uMhz %10dmV\n",
3274 od_table->GfxclkFreq3,
3275 od_table->GfxclkVolt3 / VOLTAGE_SCALE);
3281 size = sprintf(buf, "%s:\n", "OD_RANGE");
3283 if (od8_settings[OD8_SETTING_GFXCLK_FMIN].feature_id &&
3284 od8_settings[OD8_SETTING_GFXCLK_FMAX].feature_id) {
3285 size += sprintf(buf + size, "SCLK: %7uMhz %10uMhz\n",
3286 od8_settings[OD8_SETTING_GFXCLK_FMIN].min_value,
3287 od8_settings[OD8_SETTING_GFXCLK_FMAX].max_value);
3290 if (od8_settings[OD8_SETTING_UCLK_FMAX].feature_id) {
3291 ret = vega20_get_memclocks(hwmgr, &clocks);
3292 PP_ASSERT_WITH_CODE(!ret,
3293 "Fail to get memory clk levels!",
3296 size += sprintf(buf + size, "MCLK: %7uMhz %10uMhz\n",
3297 clocks.data[0].clocks_in_khz / 1000,
3298 od8_settings[OD8_SETTING_UCLK_FMAX].max_value);
3301 if (od8_settings[OD8_SETTING_GFXCLK_FREQ1].feature_id &&
3302 od8_settings[OD8_SETTING_GFXCLK_FREQ2].feature_id &&
3303 od8_settings[OD8_SETTING_GFXCLK_FREQ3].feature_id &&
3304 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE1].feature_id &&
3305 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE2].feature_id &&
3306 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE3].feature_id) {
3307 size += sprintf(buf + size, "VDDC_CURVE_SCLK[0]: %7uMhz %10uMhz\n",
3308 od8_settings[OD8_SETTING_GFXCLK_FREQ1].min_value,
3309 od8_settings[OD8_SETTING_GFXCLK_FREQ1].max_value);
3310 size += sprintf(buf + size, "VDDC_CURVE_VOLT[0]: %7dmV %11dmV\n",
3311 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE1].min_value,
3312 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE1].max_value);
3313 size += sprintf(buf + size, "VDDC_CURVE_SCLK[1]: %7uMhz %10uMhz\n",
3314 od8_settings[OD8_SETTING_GFXCLK_FREQ2].min_value,
3315 od8_settings[OD8_SETTING_GFXCLK_FREQ2].max_value);
3316 size += sprintf(buf + size, "VDDC_CURVE_VOLT[1]: %7dmV %11dmV\n",
3317 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE2].min_value,
3318 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE2].max_value);
3319 size += sprintf(buf + size, "VDDC_CURVE_SCLK[2]: %7uMhz %10uMhz\n",
3320 od8_settings[OD8_SETTING_GFXCLK_FREQ3].min_value,
3321 od8_settings[OD8_SETTING_GFXCLK_FREQ3].max_value);
3322 size += sprintf(buf + size, "VDDC_CURVE_VOLT[2]: %7dmV %11dmV\n",
3323 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE3].min_value,
3324 od8_settings[OD8_SETTING_GFXCLK_VOLTAGE3].max_value);
3334 static int vega20_set_uclk_to_highest_dpm_level(struct pp_hwmgr *hwmgr,
3335 struct vega20_single_dpm_table *dpm_table)
3337 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3340 if (data->smu_features[GNLD_DPM_UCLK].enabled) {
3341 PP_ASSERT_WITH_CODE(dpm_table->count > 0,
3342 "[SetUclkToHightestDpmLevel] Dpm table has no entry!",
3344 PP_ASSERT_WITH_CODE(dpm_table->count <= NUM_UCLK_DPM_LEVELS,
3345 "[SetUclkToHightestDpmLevel] Dpm table has too many entries!",
3348 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3349 PP_ASSERT_WITH_CODE(!(ret = smum_send_msg_to_smc_with_parameter(hwmgr,
3350 PPSMC_MSG_SetHardMinByFreq,
3351 (PPCLK_UCLK << 16 ) | dpm_table->dpm_state.hard_min_level)),
3352 "[SetUclkToHightestDpmLevel] Set hard min uclk failed!",
3359 static int vega20_pre_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
3361 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3364 smum_send_msg_to_smc_with_parameter(hwmgr,
3365 PPSMC_MSG_NumOfDisplays, 0);
3367 ret = vega20_set_uclk_to_highest_dpm_level(hwmgr,
3368 &data->dpm_table.mem_table);
3373 static int vega20_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
3375 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3377 Watermarks_t *wm_table = &(data->smc_state_table.water_marks_table);
3379 if ((data->water_marks_bitmap & WaterMarksExist) &&
3380 !(data->water_marks_bitmap & WaterMarksLoaded)) {
3381 result = smum_smc_table_manager(hwmgr,
3382 (uint8_t *)wm_table, TABLE_WATERMARKS, false);
3383 PP_ASSERT_WITH_CODE(!result,
3384 "Failed to update WMTABLE!",
3386 data->water_marks_bitmap |= WaterMarksLoaded;
3389 if ((data->water_marks_bitmap & WaterMarksExist) &&
3390 data->smu_features[GNLD_DPM_DCEFCLK].supported &&
3391 data->smu_features[GNLD_DPM_SOCCLK].supported) {
3392 result = smum_send_msg_to_smc_with_parameter(hwmgr,
3393 PPSMC_MSG_NumOfDisplays,
3394 hwmgr->display_config->num_display);
3400 int vega20_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
3402 struct vega20_hwmgr *data =
3403 (struct vega20_hwmgr *)(hwmgr->backend);
3406 if (data->smu_features[GNLD_DPM_UVD].supported) {
3407 if (data->smu_features[GNLD_DPM_UVD].enabled == enable) {
3409 PP_DBG_LOG("[EnableDisableUVDDPM] feature DPM UVD already enabled!\n");
3411 PP_DBG_LOG("[EnableDisableUVDDPM] feature DPM UVD already disabled!\n");
3414 ret = vega20_enable_smc_features(hwmgr,
3416 data->smu_features[GNLD_DPM_UVD].smu_feature_bitmap);
3417 PP_ASSERT_WITH_CODE(!ret,
3418 "[EnableDisableUVDDPM] Attempt to Enable/Disable DPM UVD Failed!",
3420 data->smu_features[GNLD_DPM_UVD].enabled = enable;
3426 static void vega20_power_gate_vce(struct pp_hwmgr *hwmgr, bool bgate)
3428 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3430 if (data->vce_power_gated == bgate)
3433 data->vce_power_gated = bgate;
3434 vega20_enable_disable_vce_dpm(hwmgr, !bgate);
3437 static void vega20_power_gate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
3439 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3441 if (data->uvd_power_gated == bgate)
3444 data->uvd_power_gated = bgate;
3445 vega20_enable_disable_uvd_dpm(hwmgr, !bgate);
3448 static int vega20_apply_clocks_adjust_rules(struct pp_hwmgr *hwmgr)
3450 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3451 struct vega20_single_dpm_table *dpm_table;
3452 bool vblank_too_short = false;
3453 bool disable_mclk_switching;
3454 uint32_t i, latency;
3456 disable_mclk_switching = ((1 < hwmgr->display_config->num_display) &&
3457 !hwmgr->display_config->multi_monitor_in_sync) ||
3459 latency = hwmgr->display_config->dce_tolerable_mclk_in_active_latency;
3462 dpm_table = &(data->dpm_table.gfx_table);
3463 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3464 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3465 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3466 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3468 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3469 if (VEGA20_UMD_PSTATE_GFXCLK_LEVEL < dpm_table->count) {
3470 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_GFXCLK_LEVEL].value;
3471 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_GFXCLK_LEVEL].value;
3474 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3475 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3476 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[0].value;
3479 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3480 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3481 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3486 dpm_table = &(data->dpm_table.mem_table);
3487 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3488 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3489 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3490 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3492 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3493 if (VEGA20_UMD_PSTATE_MCLK_LEVEL < dpm_table->count) {
3494 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_MCLK_LEVEL].value;
3495 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_MCLK_LEVEL].value;
3498 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
3499 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3500 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[0].value;
3503 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3504 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3505 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3509 /* honour DAL's UCLK Hardmin */
3510 if (dpm_table->dpm_state.hard_min_level < (hwmgr->display_config->min_mem_set_clock / 100))
3511 dpm_table->dpm_state.hard_min_level = hwmgr->display_config->min_mem_set_clock / 100;
3513 /* Hardmin is dependent on displayconfig */
3514 if (disable_mclk_switching) {
3515 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3516 for (i = 0; i < data->mclk_latency_table.count - 1; i++) {
3517 if (data->mclk_latency_table.entries[i].latency <= latency) {
3518 if (dpm_table->dpm_levels[i].value >= (hwmgr->display_config->min_mem_set_clock / 100)) {
3519 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[i].value;
3526 if (hwmgr->display_config->nb_pstate_switch_disable)
3527 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3530 dpm_table = &(data->dpm_table.vclk_table);
3531 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3532 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3533 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3534 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3536 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3537 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
3538 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
3539 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
3542 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3543 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3544 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3549 dpm_table = &(data->dpm_table.dclk_table);
3550 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3551 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3552 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3553 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3555 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3556 if (VEGA20_UMD_PSTATE_UVDCLK_LEVEL < dpm_table->count) {
3557 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
3558 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_UVDCLK_LEVEL].value;
3561 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3562 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3563 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3568 dpm_table = &(data->dpm_table.soc_table);
3569 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3570 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3571 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3572 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3574 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3575 if (VEGA20_UMD_PSTATE_SOCCLK_LEVEL < dpm_table->count) {
3576 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_SOCCLK_LEVEL].value;
3577 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_SOCCLK_LEVEL].value;
3580 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3581 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3582 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3587 dpm_table = &(data->dpm_table.eclk_table);
3588 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[0].value;
3589 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3590 dpm_table->dpm_state.hard_min_level = dpm_table->dpm_levels[0].value;
3591 dpm_table->dpm_state.hard_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3593 if (PP_CAP(PHM_PlatformCaps_UMDPState)) {
3594 if (VEGA20_UMD_PSTATE_VCEMCLK_LEVEL < dpm_table->count) {
3595 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_VCEMCLK_LEVEL].value;
3596 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[VEGA20_UMD_PSTATE_VCEMCLK_LEVEL].value;
3599 if (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3600 dpm_table->dpm_state.soft_min_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3601 dpm_table->dpm_state.soft_max_level = dpm_table->dpm_levels[dpm_table->count - 1].value;
3609 vega20_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
3611 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3612 bool is_update_required = false;
3614 if (data->display_timing.num_existing_displays !=
3615 hwmgr->display_config->num_display)
3616 is_update_required = true;
3618 if (data->registry_data.gfx_clk_deep_sleep_support &&
3619 (data->display_timing.min_clock_in_sr !=
3620 hwmgr->display_config->min_core_set_clock_in_sr))
3621 is_update_required = true;
3623 return is_update_required;
3626 static int vega20_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
3630 ret = vega20_disable_all_smu_features(hwmgr);
3631 PP_ASSERT_WITH_CODE(!ret,
3632 "[DisableDpmTasks] Failed to disable all smu features!",
3638 static int vega20_power_off_asic(struct pp_hwmgr *hwmgr)
3640 struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
3643 result = vega20_disable_dpm_tasks(hwmgr);
3644 PP_ASSERT_WITH_CODE((0 == result),
3645 "[PowerOffAsic] Failed to disable DPM!",
3647 data->water_marks_bitmap &= ~(WaterMarksLoaded);
3652 static int conv_power_profile_to_pplib_workload(int power_profile)
3654 int pplib_workload = 0;
3656 switch (power_profile) {
3657 case PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT:
3658 pplib_workload = WORKLOAD_DEFAULT_BIT;
3660 case PP_SMC_POWER_PROFILE_FULLSCREEN3D:
3661 pplib_workload = WORKLOAD_PPLIB_FULL_SCREEN_3D_BIT;
3663 case PP_SMC_POWER_PROFILE_POWERSAVING:
3664 pplib_workload = WORKLOAD_PPLIB_POWER_SAVING_BIT;
3666 case PP_SMC_POWER_PROFILE_VIDEO:
3667 pplib_workload = WORKLOAD_PPLIB_VIDEO_BIT;
3669 case PP_SMC_POWER_PROFILE_VR:
3670 pplib_workload = WORKLOAD_PPLIB_VR_BIT;
3672 case PP_SMC_POWER_PROFILE_COMPUTE:
3673 pplib_workload = WORKLOAD_PPLIB_COMPUTE_BIT;
3675 case PP_SMC_POWER_PROFILE_CUSTOM:
3676 pplib_workload = WORKLOAD_PPLIB_CUSTOM_BIT;
3680 return pplib_workload;
3683 static int vega20_get_power_profile_mode(struct pp_hwmgr *hwmgr, char *buf)
3685 DpmActivityMonitorCoeffInt_t activity_monitor;
3686 uint32_t i, size = 0;
3687 uint16_t workload_type = 0;
3688 static const char *profile_name[] = {
3696 static const char *title[] = {
3697 "PROFILE_INDEX(NAME)",
3701 "MinActiveFreqType",
3706 "PD_Data_error_coeff",
3707 "PD_Data_error_rate_coeff"};
3713 size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
3714 title[0], title[1], title[2], title[3], title[4], title[5],
3715 title[6], title[7], title[8], title[9], title[10]);
3717 for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
3718 /* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
3719 workload_type = conv_power_profile_to_pplib_workload(i);
3720 result = vega20_get_activity_monitor_coeff(hwmgr,
3721 (uint8_t *)(&activity_monitor), workload_type);
3722 PP_ASSERT_WITH_CODE(!result,
3723 "[GetPowerProfile] Failed to get activity monitor!",
3726 size += sprintf(buf + size, "%2d %14s%s:\n",
3727 i, profile_name[i], (i == hwmgr->power_profile_mode) ? "*" : " ");
3729 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
3733 activity_monitor.Gfx_FPS,
3734 activity_monitor.Gfx_UseRlcBusy,
3735 activity_monitor.Gfx_MinActiveFreqType,
3736 activity_monitor.Gfx_MinActiveFreq,
3737 activity_monitor.Gfx_BoosterFreqType,
3738 activity_monitor.Gfx_BoosterFreq,
3739 activity_monitor.Gfx_PD_Data_limit_c,
3740 activity_monitor.Gfx_PD_Data_error_coeff,
3741 activity_monitor.Gfx_PD_Data_error_rate_coeff);
3743 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
3747 activity_monitor.Soc_FPS,
3748 activity_monitor.Soc_UseRlcBusy,
3749 activity_monitor.Soc_MinActiveFreqType,
3750 activity_monitor.Soc_MinActiveFreq,
3751 activity_monitor.Soc_BoosterFreqType,
3752 activity_monitor.Soc_BoosterFreq,
3753 activity_monitor.Soc_PD_Data_limit_c,
3754 activity_monitor.Soc_PD_Data_error_coeff,
3755 activity_monitor.Soc_PD_Data_error_rate_coeff);
3757 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
3761 activity_monitor.Mem_FPS,
3762 activity_monitor.Mem_UseRlcBusy,
3763 activity_monitor.Mem_MinActiveFreqType,
3764 activity_monitor.Mem_MinActiveFreq,
3765 activity_monitor.Mem_BoosterFreqType,
3766 activity_monitor.Mem_BoosterFreq,
3767 activity_monitor.Mem_PD_Data_limit_c,
3768 activity_monitor.Mem_PD_Data_error_coeff,
3769 activity_monitor.Mem_PD_Data_error_rate_coeff);
3771 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
3775 activity_monitor.Fclk_FPS,
3776 activity_monitor.Fclk_UseRlcBusy,
3777 activity_monitor.Fclk_MinActiveFreqType,
3778 activity_monitor.Fclk_MinActiveFreq,
3779 activity_monitor.Fclk_BoosterFreqType,
3780 activity_monitor.Fclk_BoosterFreq,
3781 activity_monitor.Fclk_PD_Data_limit_c,
3782 activity_monitor.Fclk_PD_Data_error_coeff,
3783 activity_monitor.Fclk_PD_Data_error_rate_coeff);
3789 static int vega20_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint32_t size)
3791 DpmActivityMonitorCoeffInt_t activity_monitor;
3792 int workload_type, result = 0;
3794 hwmgr->power_profile_mode = input[size];
3796 if (hwmgr->power_profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
3797 pr_err("Invalid power profile mode %d\n", hwmgr->power_profile_mode);
3801 if (hwmgr->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
3805 result = vega20_get_activity_monitor_coeff(hwmgr,
3806 (uint8_t *)(&activity_monitor),
3807 WORKLOAD_PPLIB_CUSTOM_BIT);
3808 PP_ASSERT_WITH_CODE(!result,
3809 "[SetPowerProfile] Failed to get activity monitor!",
3813 case 0: /* Gfxclk */
3814 activity_monitor.Gfx_FPS = input[1];
3815 activity_monitor.Gfx_UseRlcBusy = input[2];
3816 activity_monitor.Gfx_MinActiveFreqType = input[3];
3817 activity_monitor.Gfx_MinActiveFreq = input[4];
3818 activity_monitor.Gfx_BoosterFreqType = input[5];
3819 activity_monitor.Gfx_BoosterFreq = input[6];
3820 activity_monitor.Gfx_PD_Data_limit_c = input[7];
3821 activity_monitor.Gfx_PD_Data_error_coeff = input[8];
3822 activity_monitor.Gfx_PD_Data_error_rate_coeff = input[9];
3824 case 1: /* Socclk */
3825 activity_monitor.Soc_FPS = input[1];
3826 activity_monitor.Soc_UseRlcBusy = input[2];
3827 activity_monitor.Soc_MinActiveFreqType = input[3];
3828 activity_monitor.Soc_MinActiveFreq = input[4];
3829 activity_monitor.Soc_BoosterFreqType = input[5];
3830 activity_monitor.Soc_BoosterFreq = input[6];
3831 activity_monitor.Soc_PD_Data_limit_c = input[7];
3832 activity_monitor.Soc_PD_Data_error_coeff = input[8];
3833 activity_monitor.Soc_PD_Data_error_rate_coeff = input[9];
3836 activity_monitor.Mem_FPS = input[1];
3837 activity_monitor.Mem_UseRlcBusy = input[2];
3838 activity_monitor.Mem_MinActiveFreqType = input[3];
3839 activity_monitor.Mem_MinActiveFreq = input[4];
3840 activity_monitor.Mem_BoosterFreqType = input[5];
3841 activity_monitor.Mem_BoosterFreq = input[6];
3842 activity_monitor.Mem_PD_Data_limit_c = input[7];
3843 activity_monitor.Mem_PD_Data_error_coeff = input[8];
3844 activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
3847 activity_monitor.Fclk_FPS = input[1];
3848 activity_monitor.Fclk_UseRlcBusy = input[2];
3849 activity_monitor.Fclk_MinActiveFreqType = input[3];
3850 activity_monitor.Fclk_MinActiveFreq = input[4];
3851 activity_monitor.Fclk_BoosterFreqType = input[5];
3852 activity_monitor.Fclk_BoosterFreq = input[6];
3853 activity_monitor.Fclk_PD_Data_limit_c = input[7];
3854 activity_monitor.Fclk_PD_Data_error_coeff = input[8];
3855 activity_monitor.Fclk_PD_Data_error_rate_coeff = input[9];
3859 result = vega20_set_activity_monitor_coeff(hwmgr,
3860 (uint8_t *)(&activity_monitor),
3861 WORKLOAD_PPLIB_CUSTOM_BIT);
3862 PP_ASSERT_WITH_CODE(!result,
3863 "[SetPowerProfile] Failed to set activity monitor!",
3867 /* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
3869 conv_power_profile_to_pplib_workload(hwmgr->power_profile_mode);
3870 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetWorkloadMask,
3871 1 << workload_type);
3876 static int vega20_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
3877 uint32_t virtual_addr_low,
3878 uint32_t virtual_addr_hi,
3879 uint32_t mc_addr_low,
3880 uint32_t mc_addr_hi,
3883 smum_send_msg_to_smc_with_parameter(hwmgr,
3884 PPSMC_MSG_SetSystemVirtualDramAddrHigh,
3886 smum_send_msg_to_smc_with_parameter(hwmgr,
3887 PPSMC_MSG_SetSystemVirtualDramAddrLow,
3889 smum_send_msg_to_smc_with_parameter(hwmgr,
3890 PPSMC_MSG_DramLogSetDramAddrHigh,
3893 smum_send_msg_to_smc_with_parameter(hwmgr,
3894 PPSMC_MSG_DramLogSetDramAddrLow,
3897 smum_send_msg_to_smc_with_parameter(hwmgr,
3898 PPSMC_MSG_DramLogSetDramSize,
3903 static int vega20_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
3904 struct PP_TemperatureRange *thermal_data)
3906 struct phm_ppt_v3_information *pptable_information =
3907 (struct phm_ppt_v3_information *)hwmgr->pptable;
3909 memcpy(thermal_data, &SMU7ThermalWithDelayPolicy[0], sizeof(struct PP_TemperatureRange));
3911 thermal_data->max = pptable_information->us_software_shutdown_temp *
3912 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
3917 static const struct pp_hwmgr_func vega20_hwmgr_funcs = {
3918 /* init/fini related */
3919 .backend_init = vega20_hwmgr_backend_init,
3920 .backend_fini = vega20_hwmgr_backend_fini,
3921 .asic_setup = vega20_setup_asic_task,
3922 .power_off_asic = vega20_power_off_asic,
3923 .dynamic_state_management_enable = vega20_enable_dpm_tasks,
3924 .dynamic_state_management_disable = vega20_disable_dpm_tasks,
3925 /* power state related */
3926 .apply_clocks_adjust_rules = vega20_apply_clocks_adjust_rules,
3927 .pre_display_config_changed = vega20_pre_display_configuration_changed_task,
3928 .display_config_changed = vega20_display_configuration_changed_task,
3929 .check_smc_update_required_for_display_configuration =
3930 vega20_check_smc_update_required_for_display_configuration,
3931 .notify_smc_display_config_after_ps_adjustment =
3932 vega20_notify_smc_display_config_after_ps_adjustment,
3934 .get_sclk = vega20_dpm_get_sclk,
3935 .get_mclk = vega20_dpm_get_mclk,
3936 .get_dal_power_level = vega20_get_dal_power_level,
3937 .get_clock_by_type_with_latency = vega20_get_clock_by_type_with_latency,
3938 .get_clock_by_type_with_voltage = vega20_get_clock_by_type_with_voltage,
3939 .set_watermarks_for_clocks_ranges = vega20_set_watermarks_for_clocks_ranges,
3940 .display_clock_voltage_request = vega20_display_clock_voltage_request,
3941 .get_performance_level = vega20_get_performance_level,
3942 /* UMD pstate, profile related */
3943 .force_dpm_level = vega20_dpm_force_dpm_level,
3944 .get_power_profile_mode = vega20_get_power_profile_mode,
3945 .set_power_profile_mode = vega20_set_power_profile_mode,
3947 .set_power_limit = vega20_set_power_limit,
3948 .get_sclk_od = vega20_get_sclk_od,
3949 .set_sclk_od = vega20_set_sclk_od,
3950 .get_mclk_od = vega20_get_mclk_od,
3951 .set_mclk_od = vega20_set_mclk_od,
3952 .odn_edit_dpm_table = vega20_odn_edit_dpm_table,
3953 /* for sysfs to retrive/set gfxclk/memclk */
3954 .force_clock_level = vega20_force_clock_level,
3955 .print_clock_levels = vega20_print_clock_levels,
3956 .read_sensor = vega20_read_sensor,
3957 .get_ppfeature_status = vega20_get_ppfeature_status,
3958 .set_ppfeature_status = vega20_set_ppfeature_status,
3959 /* powergate related */
3960 .powergate_uvd = vega20_power_gate_uvd,
3961 .powergate_vce = vega20_power_gate_vce,
3962 /* thermal related */
3963 .start_thermal_controller = vega20_start_thermal_controller,
3964 .stop_thermal_controller = vega20_thermal_stop_thermal_controller,
3965 .get_thermal_temperature_range = vega20_get_thermal_temperature_range,
3966 .register_irq_handlers = smu9_register_irq_handlers,
3967 .disable_smc_firmware_ctf = vega20_thermal_disable_alert,
3968 /* fan control related */
3969 .get_fan_speed_percent = vega20_fan_ctrl_get_fan_speed_percent,
3970 .set_fan_speed_percent = vega20_fan_ctrl_set_fan_speed_percent,
3971 .get_fan_speed_info = vega20_fan_ctrl_get_fan_speed_info,
3972 .get_fan_speed_rpm = vega20_fan_ctrl_get_fan_speed_rpm,
3973 .set_fan_speed_rpm = vega20_fan_ctrl_set_fan_speed_rpm,
3974 .get_fan_control_mode = vega20_get_fan_control_mode,
3975 .set_fan_control_mode = vega20_set_fan_control_mode,
3976 /* smu memory related */
3977 .notify_cac_buffer_info = vega20_notify_cac_buffer_info,
3978 .enable_mgpu_fan_boost = vega20_enable_mgpu_fan_boost,
3980 .get_asic_baco_capability = vega20_baco_get_capability,
3981 .get_asic_baco_state = vega20_baco_get_state,
3982 .set_asic_baco_state = vega20_baco_set_state,
3985 int vega20_hwmgr_init(struct pp_hwmgr *hwmgr)
3987 hwmgr->hwmgr_func = &vega20_hwmgr_funcs;
3988 hwmgr->pptable_func = &vega20_pptable_funcs;