2 * Copyright 2016 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 "hardwaremanager.h"
32 #include "ppatomfwctrl.h"
33 #include "atomfirmware.h"
34 #include "cgs_common.h"
35 #include "vega10_powertune.h"
37 #include "smu9_driver_if.h"
38 #include "vega10_inc.h"
39 #include "soc15_common.h"
40 #include "pppcielanes.h"
41 #include "vega10_hwmgr.h"
42 #include "vega10_processpptables.h"
43 #include "vega10_pptable.h"
44 #include "vega10_thermal.h"
46 #include "amd_pcie_helpers.h"
47 #include "ppinterrupt.h"
48 #include "pp_overdriver.h"
49 #include "pp_thermal.h"
51 #include "smuio/smuio_9_0_offset.h"
52 #include "smuio/smuio_9_0_sh_mask.h"
54 #define HBM_MEMORY_CHANNEL_WIDTH 128
56 static const uint32_t channel_number[] = {1, 2, 0, 4, 0, 8, 0, 16, 2};
58 #define MEM_FREQ_LOW_LATENCY 25000
59 #define MEM_FREQ_HIGH_LATENCY 80000
60 #define MEM_LATENCY_HIGH 245
61 #define MEM_LATENCY_LOW 35
62 #define MEM_LATENCY_ERR 0xFFFF
64 #define mmDF_CS_AON0_DramBaseAddress0 0x0044
65 #define mmDF_CS_AON0_DramBaseAddress0_BASE_IDX 0
67 //DF_CS_AON0_DramBaseAddress0
68 #define DF_CS_AON0_DramBaseAddress0__AddrRngVal__SHIFT 0x0
69 #define DF_CS_AON0_DramBaseAddress0__LgcyMmioHoleEn__SHIFT 0x1
70 #define DF_CS_AON0_DramBaseAddress0__IntLvNumChan__SHIFT 0x4
71 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel__SHIFT 0x8
72 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr__SHIFT 0xc
73 #define DF_CS_AON0_DramBaseAddress0__AddrRngVal_MASK 0x00000001L
74 #define DF_CS_AON0_DramBaseAddress0__LgcyMmioHoleEn_MASK 0x00000002L
75 #define DF_CS_AON0_DramBaseAddress0__IntLvNumChan_MASK 0x000000F0L
76 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel_MASK 0x00000700L
77 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr_MASK 0xFFFFF000L
79 static const ULONG PhwVega10_Magic = (ULONG)(PHM_VIslands_Magic);
81 struct vega10_power_state *cast_phw_vega10_power_state(
82 struct pp_hw_power_state *hw_ps)
84 PP_ASSERT_WITH_CODE((PhwVega10_Magic == hw_ps->magic),
85 "Invalid Powerstate Type!",
88 return (struct vega10_power_state *)hw_ps;
91 const struct vega10_power_state *cast_const_phw_vega10_power_state(
92 const struct pp_hw_power_state *hw_ps)
94 PP_ASSERT_WITH_CODE((PhwVega10_Magic == hw_ps->magic),
95 "Invalid Powerstate Type!",
98 return (const struct vega10_power_state *)hw_ps;
101 static void vega10_set_default_registry_data(struct pp_hwmgr *hwmgr)
103 struct vega10_hwmgr *data = hwmgr->backend;
105 data->registry_data.sclk_dpm_key_disabled =
106 hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
107 data->registry_data.socclk_dpm_key_disabled =
108 hwmgr->feature_mask & PP_SOCCLK_DPM_MASK ? false : true;
109 data->registry_data.mclk_dpm_key_disabled =
110 hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
111 data->registry_data.pcie_dpm_key_disabled =
112 hwmgr->feature_mask & PP_PCIE_DPM_MASK ? false : true;
114 data->registry_data.dcefclk_dpm_key_disabled =
115 hwmgr->feature_mask & PP_DCEFCLK_DPM_MASK ? false : true;
117 if (hwmgr->feature_mask & PP_POWER_CONTAINMENT_MASK) {
118 data->registry_data.power_containment_support = 1;
119 data->registry_data.enable_pkg_pwr_tracking_feature = 1;
120 data->registry_data.enable_tdc_limit_feature = 1;
123 data->registry_data.clock_stretcher_support =
124 hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK ? true : false;
126 data->registry_data.ulv_support =
127 hwmgr->feature_mask & PP_ULV_MASK ? true : false;
129 data->registry_data.sclk_deep_sleep_support =
130 hwmgr->feature_mask & PP_SCLK_DEEP_SLEEP_MASK ? true : false;
132 data->registry_data.disable_water_mark = 0;
134 data->registry_data.fan_control_support = 1;
135 data->registry_data.thermal_support = 1;
136 data->registry_data.fw_ctf_enabled = 1;
138 data->registry_data.avfs_support = 1;
139 data->registry_data.led_dpm_enabled = 1;
141 data->registry_data.vr0hot_enabled = 1;
142 data->registry_data.vr1hot_enabled = 1;
143 data->registry_data.regulator_hot_gpio_support = 1;
145 data->registry_data.didt_support = 1;
146 if (data->registry_data.didt_support) {
147 data->registry_data.didt_mode = 6;
148 data->registry_data.sq_ramping_support = 1;
149 data->registry_data.db_ramping_support = 0;
150 data->registry_data.td_ramping_support = 0;
151 data->registry_data.tcp_ramping_support = 0;
152 data->registry_data.dbr_ramping_support = 0;
153 data->registry_data.edc_didt_support = 1;
154 data->registry_data.gc_didt_support = 0;
155 data->registry_data.psm_didt_support = 0;
158 data->display_voltage_mode = PPVEGA10_VEGA10DISPLAYVOLTAGEMODE_DFLT;
159 data->dcef_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
160 data->dcef_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
161 data->dcef_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
162 data->disp_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
163 data->disp_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
164 data->disp_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
165 data->pixel_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
166 data->pixel_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
167 data->pixel_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
168 data->phy_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
169 data->phy_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
170 data->phy_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
172 data->gfxclk_average_alpha = PPVEGA10_VEGA10GFXCLKAVERAGEALPHA_DFLT;
173 data->socclk_average_alpha = PPVEGA10_VEGA10SOCCLKAVERAGEALPHA_DFLT;
174 data->uclk_average_alpha = PPVEGA10_VEGA10UCLKCLKAVERAGEALPHA_DFLT;
175 data->gfx_activity_average_alpha = PPVEGA10_VEGA10GFXACTIVITYAVERAGEALPHA_DFLT;
178 static int vega10_set_features_platform_caps(struct pp_hwmgr *hwmgr)
180 struct vega10_hwmgr *data = hwmgr->backend;
181 struct phm_ppt_v2_information *table_info =
182 (struct phm_ppt_v2_information *)hwmgr->pptable;
183 struct amdgpu_device *adev = hwmgr->adev;
185 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
186 PHM_PlatformCaps_SclkDeepSleep);
188 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
189 PHM_PlatformCaps_DynamicPatchPowerState);
191 if (data->vddci_control == VEGA10_VOLTAGE_CONTROL_NONE)
192 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
193 PHM_PlatformCaps_ControlVDDCI);
195 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
196 PHM_PlatformCaps_EnableSMU7ThermalManagement);
198 if (adev->pg_flags & AMD_PG_SUPPORT_UVD)
199 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
200 PHM_PlatformCaps_UVDPowerGating);
202 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
203 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
204 PHM_PlatformCaps_VCEPowerGating);
206 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
207 PHM_PlatformCaps_UnTabledHardwareInterface);
209 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
210 PHM_PlatformCaps_FanSpeedInTableIsRPM);
212 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
213 PHM_PlatformCaps_ODFuzzyFanControlSupport);
215 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
216 PHM_PlatformCaps_DynamicPowerManagement);
218 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
219 PHM_PlatformCaps_SMC);
221 /* power tune caps */
222 /* assume disabled */
223 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
224 PHM_PlatformCaps_PowerContainment);
225 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
226 PHM_PlatformCaps_DiDtSupport);
227 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
228 PHM_PlatformCaps_SQRamping);
229 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
230 PHM_PlatformCaps_DBRamping);
231 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
232 PHM_PlatformCaps_TDRamping);
233 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
234 PHM_PlatformCaps_TCPRamping);
235 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
236 PHM_PlatformCaps_DBRRamping);
237 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
238 PHM_PlatformCaps_DiDtEDCEnable);
239 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
240 PHM_PlatformCaps_GCEDC);
241 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
242 PHM_PlatformCaps_PSM);
244 if (data->registry_data.didt_support) {
245 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DiDtSupport);
246 if (data->registry_data.sq_ramping_support)
247 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SQRamping);
248 if (data->registry_data.db_ramping_support)
249 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DBRamping);
250 if (data->registry_data.td_ramping_support)
251 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_TDRamping);
252 if (data->registry_data.tcp_ramping_support)
253 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_TCPRamping);
254 if (data->registry_data.dbr_ramping_support)
255 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DBRRamping);
256 if (data->registry_data.edc_didt_support)
257 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DiDtEDCEnable);
258 if (data->registry_data.gc_didt_support)
259 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_GCEDC);
260 if (data->registry_data.psm_didt_support)
261 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PSM);
264 if (data->registry_data.power_containment_support)
265 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
266 PHM_PlatformCaps_PowerContainment);
267 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
268 PHM_PlatformCaps_CAC);
270 if (table_info->tdp_table->usClockStretchAmount &&
271 data->registry_data.clock_stretcher_support)
272 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
273 PHM_PlatformCaps_ClockStretcher);
275 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
276 PHM_PlatformCaps_RegulatorHot);
277 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
278 PHM_PlatformCaps_AutomaticDCTransition);
280 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
281 PHM_PlatformCaps_UVDDPM);
282 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
283 PHM_PlatformCaps_VCEDPM);
288 static int vega10_odn_initial_default_setting(struct pp_hwmgr *hwmgr)
290 struct vega10_hwmgr *data = hwmgr->backend;
291 struct phm_ppt_v2_information *table_info =
292 (struct phm_ppt_v2_information *)(hwmgr->pptable);
293 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
294 struct vega10_odn_vddc_lookup_table *od_lookup_table;
295 struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table;
296 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table[3];
297 struct phm_ppt_v1_clock_voltage_dependency_table *od_table[3];
300 od_lookup_table = &odn_table->vddc_lookup_table;
301 vddc_lookup_table = table_info->vddc_lookup_table;
303 for (i = 0; i < vddc_lookup_table->count; i++)
304 od_lookup_table->entries[i].us_vdd = vddc_lookup_table->entries[i].us_vdd;
306 od_lookup_table->count = vddc_lookup_table->count;
308 dep_table[0] = table_info->vdd_dep_on_sclk;
309 dep_table[1] = table_info->vdd_dep_on_mclk;
310 dep_table[2] = table_info->vdd_dep_on_socclk;
311 od_table[0] = (struct phm_ppt_v1_clock_voltage_dependency_table *)&odn_table->vdd_dep_on_sclk;
312 od_table[1] = (struct phm_ppt_v1_clock_voltage_dependency_table *)&odn_table->vdd_dep_on_mclk;
313 od_table[2] = (struct phm_ppt_v1_clock_voltage_dependency_table *)&odn_table->vdd_dep_on_socclk;
315 for (i = 0; i < 3; i++)
316 smu_get_voltage_dependency_table_ppt_v1(dep_table[i], od_table[i]);
318 if (odn_table->max_vddc == 0 || odn_table->max_vddc > 2000)
319 odn_table->max_vddc = dep_table[0]->entries[dep_table[0]->count - 1].vddc;
320 if (odn_table->min_vddc == 0 || odn_table->min_vddc > 2000)
321 odn_table->min_vddc = dep_table[0]->entries[0].vddc;
323 i = od_table[2]->count - 1;
324 od_table[2]->entries[i].clk = hwmgr->platform_descriptor.overdriveLimit.memoryClock;
325 od_table[2]->entries[i].vddc = odn_table->max_vddc;
330 static void vega10_init_dpm_defaults(struct pp_hwmgr *hwmgr)
332 struct vega10_hwmgr *data = hwmgr->backend;
334 uint32_t sub_vendor_id, hw_revision;
335 struct amdgpu_device *adev = hwmgr->adev;
337 vega10_initialize_power_tune_defaults(hwmgr);
339 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
340 data->smu_features[i].smu_feature_id = 0xffff;
341 data->smu_features[i].smu_feature_bitmap = 1 << i;
342 data->smu_features[i].enabled = false;
343 data->smu_features[i].supported = false;
346 data->smu_features[GNLD_DPM_PREFETCHER].smu_feature_id =
347 FEATURE_DPM_PREFETCHER_BIT;
348 data->smu_features[GNLD_DPM_GFXCLK].smu_feature_id =
349 FEATURE_DPM_GFXCLK_BIT;
350 data->smu_features[GNLD_DPM_UCLK].smu_feature_id =
351 FEATURE_DPM_UCLK_BIT;
352 data->smu_features[GNLD_DPM_SOCCLK].smu_feature_id =
353 FEATURE_DPM_SOCCLK_BIT;
354 data->smu_features[GNLD_DPM_UVD].smu_feature_id =
356 data->smu_features[GNLD_DPM_VCE].smu_feature_id =
358 data->smu_features[GNLD_DPM_MP0CLK].smu_feature_id =
359 FEATURE_DPM_MP0CLK_BIT;
360 data->smu_features[GNLD_DPM_LINK].smu_feature_id =
361 FEATURE_DPM_LINK_BIT;
362 data->smu_features[GNLD_DPM_DCEFCLK].smu_feature_id =
363 FEATURE_DPM_DCEFCLK_BIT;
364 data->smu_features[GNLD_ULV].smu_feature_id =
366 data->smu_features[GNLD_AVFS].smu_feature_id =
368 data->smu_features[GNLD_DS_GFXCLK].smu_feature_id =
369 FEATURE_DS_GFXCLK_BIT;
370 data->smu_features[GNLD_DS_SOCCLK].smu_feature_id =
371 FEATURE_DS_SOCCLK_BIT;
372 data->smu_features[GNLD_DS_LCLK].smu_feature_id =
374 data->smu_features[GNLD_PPT].smu_feature_id =
376 data->smu_features[GNLD_TDC].smu_feature_id =
378 data->smu_features[GNLD_THERMAL].smu_feature_id =
380 data->smu_features[GNLD_GFX_PER_CU_CG].smu_feature_id =
381 FEATURE_GFX_PER_CU_CG_BIT;
382 data->smu_features[GNLD_RM].smu_feature_id =
384 data->smu_features[GNLD_DS_DCEFCLK].smu_feature_id =
385 FEATURE_DS_DCEFCLK_BIT;
386 data->smu_features[GNLD_ACDC].smu_feature_id =
388 data->smu_features[GNLD_VR0HOT].smu_feature_id =
390 data->smu_features[GNLD_VR1HOT].smu_feature_id =
392 data->smu_features[GNLD_FW_CTF].smu_feature_id =
394 data->smu_features[GNLD_LED_DISPLAY].smu_feature_id =
395 FEATURE_LED_DISPLAY_BIT;
396 data->smu_features[GNLD_FAN_CONTROL].smu_feature_id =
397 FEATURE_FAN_CONTROL_BIT;
398 data->smu_features[GNLD_ACG].smu_feature_id = FEATURE_ACG_BIT;
399 data->smu_features[GNLD_DIDT].smu_feature_id = FEATURE_GFX_EDC_BIT;
400 data->smu_features[GNLD_PCC_LIMIT].smu_feature_id = FEATURE_PCC_LIMIT_CONTROL_BIT;
402 if (!data->registry_data.prefetcher_dpm_key_disabled)
403 data->smu_features[GNLD_DPM_PREFETCHER].supported = true;
405 if (!data->registry_data.sclk_dpm_key_disabled)
406 data->smu_features[GNLD_DPM_GFXCLK].supported = true;
408 if (!data->registry_data.mclk_dpm_key_disabled)
409 data->smu_features[GNLD_DPM_UCLK].supported = true;
411 if (!data->registry_data.socclk_dpm_key_disabled)
412 data->smu_features[GNLD_DPM_SOCCLK].supported = true;
414 if (PP_CAP(PHM_PlatformCaps_UVDDPM))
415 data->smu_features[GNLD_DPM_UVD].supported = true;
417 if (PP_CAP(PHM_PlatformCaps_VCEDPM))
418 data->smu_features[GNLD_DPM_VCE].supported = true;
420 if (!data->registry_data.pcie_dpm_key_disabled)
421 data->smu_features[GNLD_DPM_LINK].supported = true;
423 if (!data->registry_data.dcefclk_dpm_key_disabled)
424 data->smu_features[GNLD_DPM_DCEFCLK].supported = true;
426 if (PP_CAP(PHM_PlatformCaps_SclkDeepSleep) &&
427 data->registry_data.sclk_deep_sleep_support) {
428 data->smu_features[GNLD_DS_GFXCLK].supported = true;
429 data->smu_features[GNLD_DS_SOCCLK].supported = true;
430 data->smu_features[GNLD_DS_LCLK].supported = true;
431 data->smu_features[GNLD_DS_DCEFCLK].supported = true;
434 if (data->registry_data.enable_pkg_pwr_tracking_feature)
435 data->smu_features[GNLD_PPT].supported = true;
437 if (data->registry_data.enable_tdc_limit_feature)
438 data->smu_features[GNLD_TDC].supported = true;
440 if (data->registry_data.thermal_support)
441 data->smu_features[GNLD_THERMAL].supported = true;
443 if (data->registry_data.fan_control_support)
444 data->smu_features[GNLD_FAN_CONTROL].supported = true;
446 if (data->registry_data.fw_ctf_enabled)
447 data->smu_features[GNLD_FW_CTF].supported = true;
449 if (data->registry_data.avfs_support)
450 data->smu_features[GNLD_AVFS].supported = true;
452 if (data->registry_data.led_dpm_enabled)
453 data->smu_features[GNLD_LED_DISPLAY].supported = true;
455 if (data->registry_data.vr1hot_enabled)
456 data->smu_features[GNLD_VR1HOT].supported = true;
458 if (data->registry_data.vr0hot_enabled)
459 data->smu_features[GNLD_VR0HOT].supported = true;
461 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetSmuVersion);
462 hwmgr->smu_version = smum_get_argument(hwmgr);
463 /* ACG firmware has major version 5 */
464 if ((hwmgr->smu_version & 0xff000000) == 0x5000000)
465 data->smu_features[GNLD_ACG].supported = true;
466 if (data->registry_data.didt_support)
467 data->smu_features[GNLD_DIDT].supported = true;
469 hw_revision = adev->pdev->revision;
470 sub_vendor_id = adev->pdev->subsystem_vendor;
472 if ((hwmgr->chip_id == 0x6862 ||
473 hwmgr->chip_id == 0x6861 ||
474 hwmgr->chip_id == 0x6868) &&
475 (hw_revision == 0) &&
476 (sub_vendor_id != 0x1002))
477 data->smu_features[GNLD_PCC_LIMIT].supported = true;
480 #ifdef PPLIB_VEGA10_EVV_SUPPORT
481 static int vega10_get_socclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
482 phm_ppt_v1_voltage_lookup_table *lookup_table,
483 uint16_t virtual_voltage_id, int32_t *socclk)
487 struct phm_ppt_v2_information *table_info =
488 (struct phm_ppt_v2_information *)(hwmgr->pptable);
490 PP_ASSERT_WITH_CODE(lookup_table->count != 0,
491 "Lookup table is empty",
494 /* search for leakage voltage ID 0xff01 ~ 0xff08 and sclk */
495 for (entry_id = 0; entry_id < table_info->vdd_dep_on_sclk->count; entry_id++) {
496 voltage_id = table_info->vdd_dep_on_socclk->entries[entry_id].vddInd;
497 if (lookup_table->entries[voltage_id].us_vdd == virtual_voltage_id)
501 PP_ASSERT_WITH_CODE(entry_id < table_info->vdd_dep_on_socclk->count,
502 "Can't find requested voltage id in vdd_dep_on_socclk table!",
505 *socclk = table_info->vdd_dep_on_socclk->entries[entry_id].clk;
510 #define ATOM_VIRTUAL_VOLTAGE_ID0 0xff01
512 * Get Leakage VDDC based on leakage ID.
514 * @param hwmgr the address of the powerplay hardware manager.
517 static int vega10_get_evv_voltages(struct pp_hwmgr *hwmgr)
519 struct vega10_hwmgr *data = hwmgr->backend;
524 struct phm_ppt_v2_information *table_info =
525 (struct phm_ppt_v2_information *)hwmgr->pptable;
526 struct phm_ppt_v1_clock_voltage_dependency_table *socclk_table =
527 table_info->vdd_dep_on_socclk;
530 for (i = 0; i < VEGA10_MAX_LEAKAGE_COUNT; i++) {
531 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
533 if (!vega10_get_socclk_for_voltage_evv(hwmgr,
534 table_info->vddc_lookup_table, vv_id, &sclk)) {
535 if (PP_CAP(PHM_PlatformCaps_ClockStretcher)) {
536 for (j = 1; j < socclk_table->count; j++) {
537 if (socclk_table->entries[j].clk == sclk &&
538 socclk_table->entries[j].cks_enable == 0) {
545 PP_ASSERT_WITH_CODE(!atomctrl_get_voltage_evv_on_sclk_ai(hwmgr,
546 VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc),
547 "Error retrieving EVV voltage value!",
551 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
552 PP_ASSERT_WITH_CODE((vddc < 2000 && vddc != 0),
553 "Invalid VDDC value", result = -EINVAL;);
555 /* the voltage should not be zero nor equal to leakage ID */
556 if (vddc != 0 && vddc != vv_id) {
557 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc/100);
558 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
559 data->vddc_leakage.count++;
568 * Change virtual leakage voltage to actual value.
570 * @param hwmgr the address of the powerplay hardware manager.
571 * @param pointer to changing voltage
572 * @param pointer to leakage table
574 static void vega10_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
575 uint16_t *voltage, struct vega10_leakage_voltage *leakage_table)
579 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
580 for (index = 0; index < leakage_table->count; index++) {
581 /* if this voltage matches a leakage voltage ID */
582 /* patch with actual leakage voltage */
583 if (leakage_table->leakage_id[index] == *voltage) {
584 *voltage = leakage_table->actual_voltage[index];
589 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
590 pr_info("Voltage value looks like a Leakage ID but it's not patched\n");
594 * Patch voltage lookup table by EVV leakages.
596 * @param hwmgr the address of the powerplay hardware manager.
597 * @param pointer to voltage lookup table
598 * @param pointer to leakage table
601 static int vega10_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
602 phm_ppt_v1_voltage_lookup_table *lookup_table,
603 struct vega10_leakage_voltage *leakage_table)
607 for (i = 0; i < lookup_table->count; i++)
608 vega10_patch_with_vdd_leakage(hwmgr,
609 &lookup_table->entries[i].us_vdd, leakage_table);
614 static int vega10_patch_clock_voltage_limits_with_vddc_leakage(
615 struct pp_hwmgr *hwmgr, struct vega10_leakage_voltage *leakage_table,
618 vega10_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
624 static int vega10_patch_voltage_dependency_tables_with_lookup_table(
625 struct pp_hwmgr *hwmgr)
627 uint8_t entry_id, voltage_id;
629 struct phm_ppt_v2_information *table_info =
630 (struct phm_ppt_v2_information *)(hwmgr->pptable);
631 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
632 table_info->mm_dep_table;
633 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
634 table_info->vdd_dep_on_mclk;
636 for (i = 0; i < 6; i++) {
637 struct phm_ppt_v1_clock_voltage_dependency_table *vdt;
639 case 0: vdt = table_info->vdd_dep_on_socclk; break;
640 case 1: vdt = table_info->vdd_dep_on_sclk; break;
641 case 2: vdt = table_info->vdd_dep_on_dcefclk; break;
642 case 3: vdt = table_info->vdd_dep_on_pixclk; break;
643 case 4: vdt = table_info->vdd_dep_on_dispclk; break;
644 case 5: vdt = table_info->vdd_dep_on_phyclk; break;
647 for (entry_id = 0; entry_id < vdt->count; entry_id++) {
648 voltage_id = vdt->entries[entry_id].vddInd;
649 vdt->entries[entry_id].vddc =
650 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
654 for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
655 voltage_id = mm_table->entries[entry_id].vddcInd;
656 mm_table->entries[entry_id].vddc =
657 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
660 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
661 voltage_id = mclk_table->entries[entry_id].vddInd;
662 mclk_table->entries[entry_id].vddc =
663 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
664 voltage_id = mclk_table->entries[entry_id].vddciInd;
665 mclk_table->entries[entry_id].vddci =
666 table_info->vddci_lookup_table->entries[voltage_id].us_vdd;
667 voltage_id = mclk_table->entries[entry_id].mvddInd;
668 mclk_table->entries[entry_id].mvdd =
669 table_info->vddmem_lookup_table->entries[voltage_id].us_vdd;
677 static int vega10_sort_lookup_table(struct pp_hwmgr *hwmgr,
678 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
680 uint32_t table_size, i, j;
681 struct phm_ppt_v1_voltage_lookup_record tmp_voltage_lookup_record;
683 PP_ASSERT_WITH_CODE(lookup_table && lookup_table->count,
684 "Lookup table is empty", return -EINVAL);
686 table_size = lookup_table->count;
688 /* Sorting voltages */
689 for (i = 0; i < table_size - 1; i++) {
690 for (j = i + 1; j > 0; j--) {
691 if (lookup_table->entries[j].us_vdd <
692 lookup_table->entries[j - 1].us_vdd) {
693 tmp_voltage_lookup_record = lookup_table->entries[j - 1];
694 lookup_table->entries[j - 1] = lookup_table->entries[j];
695 lookup_table->entries[j] = tmp_voltage_lookup_record;
703 static int vega10_complete_dependency_tables(struct pp_hwmgr *hwmgr)
707 struct phm_ppt_v2_information *table_info =
708 (struct phm_ppt_v2_information *)(hwmgr->pptable);
709 #ifdef PPLIB_VEGA10_EVV_SUPPORT
710 struct vega10_hwmgr *data = hwmgr->backend;
712 tmp_result = vega10_patch_lookup_table_with_leakage(hwmgr,
713 table_info->vddc_lookup_table, &(data->vddc_leakage));
717 tmp_result = vega10_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
718 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
723 tmp_result = vega10_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
727 tmp_result = vega10_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
734 static int vega10_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
736 struct phm_ppt_v2_information *table_info =
737 (struct phm_ppt_v2_information *)(hwmgr->pptable);
738 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
739 table_info->vdd_dep_on_socclk;
740 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
741 table_info->vdd_dep_on_mclk;
743 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table,
744 "VDD dependency on SCLK table is missing. This table is mandatory", return -EINVAL);
745 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
746 "VDD dependency on SCLK table is empty. This table is mandatory", return -EINVAL);
748 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table,
749 "VDD dependency on MCLK table is missing. This table is mandatory", return -EINVAL);
750 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
751 "VDD dependency on MCLK table is empty. This table is mandatory", return -EINVAL);
753 table_info->max_clock_voltage_on_ac.sclk =
754 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
755 table_info->max_clock_voltage_on_ac.mclk =
756 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
757 table_info->max_clock_voltage_on_ac.vddc =
758 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
759 table_info->max_clock_voltage_on_ac.vddci =
760 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
762 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
763 table_info->max_clock_voltage_on_ac.sclk;
764 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
765 table_info->max_clock_voltage_on_ac.mclk;
766 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
767 table_info->max_clock_voltage_on_ac.vddc;
768 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =
769 table_info->max_clock_voltage_on_ac.vddci;
774 static int vega10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
776 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
777 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
779 kfree(hwmgr->backend);
780 hwmgr->backend = NULL;
785 static int vega10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
788 struct vega10_hwmgr *data;
789 uint32_t config_telemetry = 0;
790 struct pp_atomfwctrl_voltage_table vol_table;
791 struct amdgpu_device *adev = hwmgr->adev;
793 data = kzalloc(sizeof(struct vega10_hwmgr), GFP_KERNEL);
797 hwmgr->backend = data;
799 hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_VIDEO];
800 hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_VIDEO;
801 hwmgr->default_power_profile_mode = PP_SMC_POWER_PROFILE_VIDEO;
803 vega10_set_default_registry_data(hwmgr);
804 data->disable_dpm_mask = 0xff;
806 /* need to set voltage control types before EVV patching */
807 data->vddc_control = VEGA10_VOLTAGE_CONTROL_NONE;
808 data->mvdd_control = VEGA10_VOLTAGE_CONTROL_NONE;
809 data->vddci_control = VEGA10_VOLTAGE_CONTROL_NONE;
812 if (pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(hwmgr,
813 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) {
814 if (!pp_atomfwctrl_get_voltage_table_v4(hwmgr,
815 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2,
817 config_telemetry = ((vol_table.telemetry_slope << 8) & 0xff00) |
818 (vol_table.telemetry_offset & 0xff);
819 data->vddc_control = VEGA10_VOLTAGE_CONTROL_BY_SVID2;
822 kfree(hwmgr->backend);
823 hwmgr->backend = NULL;
824 PP_ASSERT_WITH_CODE(false,
825 "VDDCR_SOC is not SVID2!",
830 if (pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(hwmgr,
831 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2)) {
832 if (!pp_atomfwctrl_get_voltage_table_v4(hwmgr,
833 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2,
836 ((vol_table.telemetry_slope << 24) & 0xff000000) |
837 ((vol_table.telemetry_offset << 16) & 0xff0000);
838 data->mvdd_control = VEGA10_VOLTAGE_CONTROL_BY_SVID2;
843 if (PP_CAP(PHM_PlatformCaps_ControlVDDCI)) {
844 if (pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(hwmgr,
845 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
846 data->vddci_control = VEGA10_VOLTAGE_CONTROL_BY_GPIO;
849 data->config_telemetry = config_telemetry;
851 vega10_set_features_platform_caps(hwmgr);
853 vega10_init_dpm_defaults(hwmgr);
855 #ifdef PPLIB_VEGA10_EVV_SUPPORT
856 /* Get leakage voltage based on leakage ID. */
857 PP_ASSERT_WITH_CODE(!vega10_get_evv_voltages(hwmgr),
858 "Get EVV Voltage Failed. Abort Driver loading!",
862 /* Patch our voltage dependency table with actual leakage voltage
863 * We need to perform leakage translation before it's used by other functions
865 vega10_complete_dependency_tables(hwmgr);
867 /* Parse pptable data read from VBIOS */
868 vega10_set_private_data_based_on_pptable(hwmgr);
870 data->is_tlu_enabled = false;
872 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
873 VEGA10_MAX_HARDWARE_POWERLEVELS;
874 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
875 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
877 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
878 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
879 hwmgr->platform_descriptor.clockStep.engineClock = 500;
880 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
882 data->total_active_cus = adev->gfx.cu_info.number;
883 /* Setup default Overdrive Fan control settings */
884 data->odn_fan_table.target_fan_speed =
885 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM;
886 data->odn_fan_table.target_temperature =
887 hwmgr->thermal_controller.
888 advanceFanControlParameters.ucTargetTemperature;
889 data->odn_fan_table.min_performance_clock =
890 hwmgr->thermal_controller.advanceFanControlParameters.
891 ulMinFanSCLKAcousticLimit;
892 data->odn_fan_table.min_fan_limit =
893 hwmgr->thermal_controller.
894 advanceFanControlParameters.usFanPWMMinLimit *
895 hwmgr->thermal_controller.fanInfo.ulMaxRPM / 100;
897 data->mem_channels = (RREG32_SOC15(DF, 0, mmDF_CS_AON0_DramBaseAddress0) &
898 DF_CS_AON0_DramBaseAddress0__IntLvNumChan_MASK) >>
899 DF_CS_AON0_DramBaseAddress0__IntLvNumChan__SHIFT;
900 PP_ASSERT_WITH_CODE(data->mem_channels < ARRAY_SIZE(channel_number),
901 "Mem Channel Index Exceeded maximum!",
907 static int vega10_init_sclk_threshold(struct pp_hwmgr *hwmgr)
909 struct vega10_hwmgr *data = hwmgr->backend;
911 data->low_sclk_interrupt_threshold = 0;
916 static int vega10_setup_dpm_led_config(struct pp_hwmgr *hwmgr)
918 struct vega10_hwmgr *data = hwmgr->backend;
919 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
921 struct pp_atomfwctrl_voltage_table table;
927 ret = pp_atomfwctrl_get_voltage_table_v4(hwmgr, VOLTAGE_TYPE_LEDDPM,
928 VOLTAGE_OBJ_GPIO_LUT, &table);
931 tmp = table.mask_low;
932 for (i = 0, j = 0; i < 32; i++) {
934 mask |= (uint32_t)(i << (8 * j));
942 pp_table->LedPin0 = (uint8_t)(mask & 0xff);
943 pp_table->LedPin1 = (uint8_t)((mask >> 8) & 0xff);
944 pp_table->LedPin2 = (uint8_t)((mask >> 16) & 0xff);
948 static int vega10_setup_asic_task(struct pp_hwmgr *hwmgr)
950 PP_ASSERT_WITH_CODE(!vega10_init_sclk_threshold(hwmgr),
951 "Failed to init sclk threshold!",
954 PP_ASSERT_WITH_CODE(!vega10_setup_dpm_led_config(hwmgr),
955 "Failed to set up led dpm config!",
958 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_NumOfDisplays, 0);
964 * Remove repeated voltage values and create table with unique values.
966 * @param hwmgr the address of the powerplay hardware manager.
967 * @param vol_table the pointer to changing voltage table
968 * @return 0 in success
971 static int vega10_trim_voltage_table(struct pp_hwmgr *hwmgr,
972 struct pp_atomfwctrl_voltage_table *vol_table)
977 struct pp_atomfwctrl_voltage_table *table;
979 PP_ASSERT_WITH_CODE(vol_table,
980 "Voltage Table empty.", return -EINVAL);
981 table = kzalloc(sizeof(struct pp_atomfwctrl_voltage_table),
987 table->mask_low = vol_table->mask_low;
988 table->phase_delay = vol_table->phase_delay;
990 for (i = 0; i < vol_table->count; i++) {
991 vvalue = vol_table->entries[i].value;
994 for (j = 0; j < table->count; j++) {
995 if (vvalue == table->entries[j].value) {
1002 table->entries[table->count].value = vvalue;
1003 table->entries[table->count].smio_low =
1004 vol_table->entries[i].smio_low;
1009 memcpy(vol_table, table, sizeof(struct pp_atomfwctrl_voltage_table));
1015 static int vega10_get_mvdd_voltage_table(struct pp_hwmgr *hwmgr,
1016 phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1017 struct pp_atomfwctrl_voltage_table *vol_table)
1021 PP_ASSERT_WITH_CODE(dep_table->count,
1022 "Voltage Dependency Table empty.",
1025 vol_table->mask_low = 0;
1026 vol_table->phase_delay = 0;
1027 vol_table->count = dep_table->count;
1029 for (i = 0; i < vol_table->count; i++) {
1030 vol_table->entries[i].value = dep_table->entries[i].mvdd;
1031 vol_table->entries[i].smio_low = 0;
1034 PP_ASSERT_WITH_CODE(!vega10_trim_voltage_table(hwmgr,
1036 "Failed to trim MVDD Table!",
1042 static int vega10_get_vddci_voltage_table(struct pp_hwmgr *hwmgr,
1043 phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1044 struct pp_atomfwctrl_voltage_table *vol_table)
1048 PP_ASSERT_WITH_CODE(dep_table->count,
1049 "Voltage Dependency Table empty.",
1052 vol_table->mask_low = 0;
1053 vol_table->phase_delay = 0;
1054 vol_table->count = dep_table->count;
1056 for (i = 0; i < dep_table->count; i++) {
1057 vol_table->entries[i].value = dep_table->entries[i].vddci;
1058 vol_table->entries[i].smio_low = 0;
1061 PP_ASSERT_WITH_CODE(!vega10_trim_voltage_table(hwmgr, vol_table),
1062 "Failed to trim VDDCI table.",
1068 static int vega10_get_vdd_voltage_table(struct pp_hwmgr *hwmgr,
1069 phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1070 struct pp_atomfwctrl_voltage_table *vol_table)
1074 PP_ASSERT_WITH_CODE(dep_table->count,
1075 "Voltage Dependency Table empty.",
1078 vol_table->mask_low = 0;
1079 vol_table->phase_delay = 0;
1080 vol_table->count = dep_table->count;
1082 for (i = 0; i < vol_table->count; i++) {
1083 vol_table->entries[i].value = dep_table->entries[i].vddc;
1084 vol_table->entries[i].smio_low = 0;
1090 /* ---- Voltage Tables ----
1091 * If the voltage table would be bigger than
1092 * what will fit into the state table on
1093 * the SMC keep only the higher entries.
1095 static void vega10_trim_voltage_table_to_fit_state_table(
1096 struct pp_hwmgr *hwmgr,
1097 uint32_t max_vol_steps,
1098 struct pp_atomfwctrl_voltage_table *vol_table)
1100 unsigned int i, diff;
1102 if (vol_table->count <= max_vol_steps)
1105 diff = vol_table->count - max_vol_steps;
1107 for (i = 0; i < max_vol_steps; i++)
1108 vol_table->entries[i] = vol_table->entries[i + diff];
1110 vol_table->count = max_vol_steps;
1114 * Create Voltage Tables.
1116 * @param hwmgr the address of the powerplay hardware manager.
1119 static int vega10_construct_voltage_tables(struct pp_hwmgr *hwmgr)
1121 struct vega10_hwmgr *data = hwmgr->backend;
1122 struct phm_ppt_v2_information *table_info =
1123 (struct phm_ppt_v2_information *)hwmgr->pptable;
1126 if (data->mvdd_control == VEGA10_VOLTAGE_CONTROL_BY_SVID2 ||
1127 data->mvdd_control == VEGA10_VOLTAGE_CONTROL_NONE) {
1128 result = vega10_get_mvdd_voltage_table(hwmgr,
1129 table_info->vdd_dep_on_mclk,
1130 &(data->mvdd_voltage_table));
1131 PP_ASSERT_WITH_CODE(!result,
1132 "Failed to retrieve MVDDC table!",
1136 if (data->vddci_control == VEGA10_VOLTAGE_CONTROL_NONE) {
1137 result = vega10_get_vddci_voltage_table(hwmgr,
1138 table_info->vdd_dep_on_mclk,
1139 &(data->vddci_voltage_table));
1140 PP_ASSERT_WITH_CODE(!result,
1141 "Failed to retrieve VDDCI_MEM table!",
1145 if (data->vddc_control == VEGA10_VOLTAGE_CONTROL_BY_SVID2 ||
1146 data->vddc_control == VEGA10_VOLTAGE_CONTROL_NONE) {
1147 result = vega10_get_vdd_voltage_table(hwmgr,
1148 table_info->vdd_dep_on_sclk,
1149 &(data->vddc_voltage_table));
1150 PP_ASSERT_WITH_CODE(!result,
1151 "Failed to retrieve VDDCR_SOC table!",
1155 PP_ASSERT_WITH_CODE(data->vddc_voltage_table.count <= 16,
1156 "Too many voltage values for VDDC. Trimming to fit state table.",
1157 vega10_trim_voltage_table_to_fit_state_table(hwmgr,
1158 16, &(data->vddc_voltage_table)));
1160 PP_ASSERT_WITH_CODE(data->vddci_voltage_table.count <= 16,
1161 "Too many voltage values for VDDCI. Trimming to fit state table.",
1162 vega10_trim_voltage_table_to_fit_state_table(hwmgr,
1163 16, &(data->vddci_voltage_table)));
1165 PP_ASSERT_WITH_CODE(data->mvdd_voltage_table.count <= 16,
1166 "Too many voltage values for MVDD. Trimming to fit state table.",
1167 vega10_trim_voltage_table_to_fit_state_table(hwmgr,
1168 16, &(data->mvdd_voltage_table)));
1175 * @fn vega10_init_dpm_state
1176 * @brief Function to initialize all Soft Min/Max and Hard Min/Max to 0xff.
1178 * @param dpm_state - the address of the DPM Table to initiailize.
1181 static void vega10_init_dpm_state(struct vega10_dpm_state *dpm_state)
1183 dpm_state->soft_min_level = 0xff;
1184 dpm_state->soft_max_level = 0xff;
1185 dpm_state->hard_min_level = 0xff;
1186 dpm_state->hard_max_level = 0xff;
1189 static void vega10_setup_default_single_dpm_table(struct pp_hwmgr *hwmgr,
1190 struct vega10_single_dpm_table *dpm_table,
1191 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table)
1195 dpm_table->count = 0;
1197 for (i = 0; i < dep_table->count; i++) {
1198 if (i == 0 || dpm_table->dpm_levels[dpm_table->count - 1].value <=
1199 dep_table->entries[i].clk) {
1200 dpm_table->dpm_levels[dpm_table->count].value =
1201 dep_table->entries[i].clk;
1202 dpm_table->dpm_levels[dpm_table->count].enabled = true;
1207 static int vega10_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
1209 struct vega10_hwmgr *data = hwmgr->backend;
1210 struct vega10_pcie_table *pcie_table = &(data->dpm_table.pcie_table);
1211 struct phm_ppt_v2_information *table_info =
1212 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1213 struct phm_ppt_v1_pcie_table *bios_pcie_table =
1214 table_info->pcie_table;
1217 PP_ASSERT_WITH_CODE(bios_pcie_table->count,
1218 "Incorrect number of PCIE States from VBIOS!",
1221 for (i = 0; i < NUM_LINK_LEVELS; i++) {
1222 if (data->registry_data.pcieSpeedOverride)
1223 pcie_table->pcie_gen[i] =
1224 data->registry_data.pcieSpeedOverride;
1226 pcie_table->pcie_gen[i] =
1227 bios_pcie_table->entries[i].gen_speed;
1229 if (data->registry_data.pcieLaneOverride)
1230 pcie_table->pcie_lane[i] = (uint8_t)encode_pcie_lane_width(
1231 data->registry_data.pcieLaneOverride);
1233 pcie_table->pcie_lane[i] = (uint8_t)encode_pcie_lane_width(
1234 bios_pcie_table->entries[i].lane_width);
1235 if (data->registry_data.pcieClockOverride)
1236 pcie_table->lclk[i] =
1237 data->registry_data.pcieClockOverride;
1239 pcie_table->lclk[i] =
1240 bios_pcie_table->entries[i].pcie_sclk;
1243 pcie_table->count = NUM_LINK_LEVELS;
1249 * This function is to initialize all DPM state tables
1250 * for SMU based on the dependency table.
1251 * Dynamic state patching function will then trim these
1252 * state tables to the allowed range based
1253 * on the power policy or external client requests,
1254 * such as UVD request, etc.
1256 static int vega10_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1258 struct vega10_hwmgr *data = hwmgr->backend;
1259 struct phm_ppt_v2_information *table_info =
1260 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1261 struct vega10_single_dpm_table *dpm_table;
1264 struct phm_ppt_v1_clock_voltage_dependency_table *dep_soc_table =
1265 table_info->vdd_dep_on_socclk;
1266 struct phm_ppt_v1_clock_voltage_dependency_table *dep_gfx_table =
1267 table_info->vdd_dep_on_sclk;
1268 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
1269 table_info->vdd_dep_on_mclk;
1270 struct phm_ppt_v1_mm_clock_voltage_dependency_table *dep_mm_table =
1271 table_info->mm_dep_table;
1272 struct phm_ppt_v1_clock_voltage_dependency_table *dep_dcef_table =
1273 table_info->vdd_dep_on_dcefclk;
1274 struct phm_ppt_v1_clock_voltage_dependency_table *dep_pix_table =
1275 table_info->vdd_dep_on_pixclk;
1276 struct phm_ppt_v1_clock_voltage_dependency_table *dep_disp_table =
1277 table_info->vdd_dep_on_dispclk;
1278 struct phm_ppt_v1_clock_voltage_dependency_table *dep_phy_table =
1279 table_info->vdd_dep_on_phyclk;
1281 PP_ASSERT_WITH_CODE(dep_soc_table,
1282 "SOCCLK dependency table is missing. This table is mandatory",
1284 PP_ASSERT_WITH_CODE(dep_soc_table->count >= 1,
1285 "SOCCLK dependency table is empty. This table is mandatory",
1288 PP_ASSERT_WITH_CODE(dep_gfx_table,
1289 "GFXCLK dependency table is missing. This table is mandatory",
1291 PP_ASSERT_WITH_CODE(dep_gfx_table->count >= 1,
1292 "GFXCLK dependency table is empty. This table is mandatory",
1295 PP_ASSERT_WITH_CODE(dep_mclk_table,
1296 "MCLK dependency table is missing. This table is mandatory",
1298 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
1299 "MCLK dependency table has to have is missing. This table is mandatory",
1302 /* Initialize Sclk DPM table based on allow Sclk values */
1303 dpm_table = &(data->dpm_table.soc_table);
1304 vega10_setup_default_single_dpm_table(hwmgr,
1308 vega10_init_dpm_state(&(dpm_table->dpm_state));
1310 dpm_table = &(data->dpm_table.gfx_table);
1311 vega10_setup_default_single_dpm_table(hwmgr,
1314 vega10_init_dpm_state(&(dpm_table->dpm_state));
1316 /* Initialize Mclk DPM table based on allow Mclk values */
1317 data->dpm_table.mem_table.count = 0;
1318 dpm_table = &(data->dpm_table.mem_table);
1319 vega10_setup_default_single_dpm_table(hwmgr,
1322 vega10_init_dpm_state(&(dpm_table->dpm_state));
1324 data->dpm_table.eclk_table.count = 0;
1325 dpm_table = &(data->dpm_table.eclk_table);
1326 for (i = 0; i < dep_mm_table->count; i++) {
1327 if (i == 0 || dpm_table->dpm_levels
1328 [dpm_table->count - 1].value <=
1329 dep_mm_table->entries[i].eclk) {
1330 dpm_table->dpm_levels[dpm_table->count].value =
1331 dep_mm_table->entries[i].eclk;
1332 dpm_table->dpm_levels[dpm_table->count].enabled =
1333 (i == 0) ? true : false;
1337 vega10_init_dpm_state(&(dpm_table->dpm_state));
1339 data->dpm_table.vclk_table.count = 0;
1340 data->dpm_table.dclk_table.count = 0;
1341 dpm_table = &(data->dpm_table.vclk_table);
1342 for (i = 0; i < dep_mm_table->count; i++) {
1343 if (i == 0 || dpm_table->dpm_levels
1344 [dpm_table->count - 1].value <=
1345 dep_mm_table->entries[i].vclk) {
1346 dpm_table->dpm_levels[dpm_table->count].value =
1347 dep_mm_table->entries[i].vclk;
1348 dpm_table->dpm_levels[dpm_table->count].enabled =
1349 (i == 0) ? true : false;
1353 vega10_init_dpm_state(&(dpm_table->dpm_state));
1355 dpm_table = &(data->dpm_table.dclk_table);
1356 for (i = 0; i < dep_mm_table->count; i++) {
1357 if (i == 0 || dpm_table->dpm_levels
1358 [dpm_table->count - 1].value <=
1359 dep_mm_table->entries[i].dclk) {
1360 dpm_table->dpm_levels[dpm_table->count].value =
1361 dep_mm_table->entries[i].dclk;
1362 dpm_table->dpm_levels[dpm_table->count].enabled =
1363 (i == 0) ? true : false;
1367 vega10_init_dpm_state(&(dpm_table->dpm_state));
1369 /* Assume there is no headless Vega10 for now */
1370 dpm_table = &(data->dpm_table.dcef_table);
1371 vega10_setup_default_single_dpm_table(hwmgr,
1375 vega10_init_dpm_state(&(dpm_table->dpm_state));
1377 dpm_table = &(data->dpm_table.pixel_table);
1378 vega10_setup_default_single_dpm_table(hwmgr,
1382 vega10_init_dpm_state(&(dpm_table->dpm_state));
1384 dpm_table = &(data->dpm_table.display_table);
1385 vega10_setup_default_single_dpm_table(hwmgr,
1389 vega10_init_dpm_state(&(dpm_table->dpm_state));
1391 dpm_table = &(data->dpm_table.phy_table);
1392 vega10_setup_default_single_dpm_table(hwmgr,
1396 vega10_init_dpm_state(&(dpm_table->dpm_state));
1398 vega10_setup_default_pcie_table(hwmgr);
1400 /* save a copy of the default DPM table */
1401 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1402 sizeof(struct vega10_dpm_table));
1408 * @fn vega10_populate_ulv_state
1409 * @brief Function to provide parameters for Utral Low Voltage state to SMC.
1411 * @param hwmgr - the address of the hardware manager.
1414 static int vega10_populate_ulv_state(struct pp_hwmgr *hwmgr)
1416 struct vega10_hwmgr *data = hwmgr->backend;
1417 struct phm_ppt_v2_information *table_info =
1418 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1420 data->smc_state_table.pp_table.UlvOffsetVid =
1421 (uint8_t)table_info->us_ulv_voltage_offset;
1423 data->smc_state_table.pp_table.UlvSmnclkDid =
1424 (uint8_t)(table_info->us_ulv_smnclk_did);
1425 data->smc_state_table.pp_table.UlvMp1clkDid =
1426 (uint8_t)(table_info->us_ulv_mp1clk_did);
1427 data->smc_state_table.pp_table.UlvGfxclkBypass =
1428 (uint8_t)(table_info->us_ulv_gfxclk_bypass);
1429 data->smc_state_table.pp_table.UlvPhaseSheddingPsi0 =
1430 (uint8_t)(data->vddc_voltage_table.psi0_enable);
1431 data->smc_state_table.pp_table.UlvPhaseSheddingPsi1 =
1432 (uint8_t)(data->vddc_voltage_table.psi1_enable);
1437 static int vega10_populate_single_lclk_level(struct pp_hwmgr *hwmgr,
1438 uint32_t lclock, uint8_t *curr_lclk_did)
1440 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1442 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(
1444 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1446 "Failed to get LCLK clock settings from VBIOS!",
1449 *curr_lclk_did = dividers.ulDid;
1454 static int vega10_populate_smc_link_levels(struct pp_hwmgr *hwmgr)
1457 struct vega10_hwmgr *data = hwmgr->backend;
1458 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1459 struct vega10_pcie_table *pcie_table =
1460 &(data->dpm_table.pcie_table);
1463 for (i = 0; i < pcie_table->count; i++) {
1464 pp_table->PcieGenSpeed[i] = pcie_table->pcie_gen[i];
1465 pp_table->PcieLaneCount[i] = pcie_table->pcie_lane[i];
1467 result = vega10_populate_single_lclk_level(hwmgr,
1468 pcie_table->lclk[i], &(pp_table->LclkDid[i]));
1470 pr_info("Populate LClock Level %d Failed!\n", i);
1476 while (i < NUM_LINK_LEVELS) {
1477 pp_table->PcieGenSpeed[i] = pcie_table->pcie_gen[j];
1478 pp_table->PcieLaneCount[i] = pcie_table->pcie_lane[j];
1480 result = vega10_populate_single_lclk_level(hwmgr,
1481 pcie_table->lclk[j], &(pp_table->LclkDid[i]));
1483 pr_info("Populate LClock Level %d Failed!\n", i);
1493 * Populates single SMC GFXSCLK structure using the provided engine clock
1495 * @param hwmgr the address of the hardware manager
1496 * @param gfx_clock the GFX clock to use to populate the structure.
1497 * @param current_gfxclk_level location in PPTable for the SMC GFXCLK structure.
1500 static int vega10_populate_single_gfx_level(struct pp_hwmgr *hwmgr,
1501 uint32_t gfx_clock, PllSetting_t *current_gfxclk_level,
1504 struct phm_ppt_v2_information *table_info =
1505 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1506 struct phm_ppt_v1_clock_voltage_dependency_table *dep_on_sclk;
1507 struct vega10_hwmgr *data = hwmgr->backend;
1508 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1509 uint32_t gfx_max_clock =
1510 hwmgr->platform_descriptor.overdriveLimit.engineClock;
1513 if (hwmgr->od_enabled)
1514 dep_on_sclk = (struct phm_ppt_v1_clock_voltage_dependency_table *)
1515 &(data->odn_dpm_table.vdd_dep_on_sclk);
1517 dep_on_sclk = table_info->vdd_dep_on_sclk;
1519 PP_ASSERT_WITH_CODE(dep_on_sclk,
1520 "Invalid SOC_VDD-GFX_CLK Dependency Table!",
1523 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_SCLK)
1524 gfx_clock = gfx_clock > gfx_max_clock ? gfx_max_clock : gfx_clock;
1526 for (i = 0; i < dep_on_sclk->count; i++) {
1527 if (dep_on_sclk->entries[i].clk == gfx_clock)
1530 PP_ASSERT_WITH_CODE(dep_on_sclk->count > i,
1531 "Cannot find gfx_clk in SOC_VDD-GFX_CLK!",
1535 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1536 COMPUTE_GPUCLK_INPUT_FLAG_GFXCLK,
1537 gfx_clock, ÷rs),
1538 "Failed to get GFX Clock settings from VBIOS!",
1541 /* Feedback Multiplier: bit 0:8 int, bit 15:12 post_div, bit 31:16 frac */
1542 current_gfxclk_level->FbMult =
1543 cpu_to_le32(dividers.ulPll_fb_mult);
1544 /* Spread FB Multiplier bit: bit 0:8 int, bit 31:16 frac */
1545 current_gfxclk_level->SsOn = dividers.ucPll_ss_enable;
1546 current_gfxclk_level->SsFbMult =
1547 cpu_to_le32(dividers.ulPll_ss_fbsmult);
1548 current_gfxclk_level->SsSlewFrac =
1549 cpu_to_le16(dividers.usPll_ss_slew_frac);
1550 current_gfxclk_level->Did = (uint8_t)(dividers.ulDid);
1552 *acg_freq = gfx_clock / 100; /* 100 Khz to Mhz conversion */
1558 * @brief Populates single SMC SOCCLK structure using the provided clock.
1560 * @param hwmgr - the address of the hardware manager.
1561 * @param soc_clock - the SOC clock to use to populate the structure.
1562 * @param current_socclk_level - location in PPTable for the SMC SOCCLK structure.
1563 * @return 0 on success..
1565 static int vega10_populate_single_soc_level(struct pp_hwmgr *hwmgr,
1566 uint32_t soc_clock, uint8_t *current_soc_did,
1567 uint8_t *current_vol_index)
1569 struct vega10_hwmgr *data = hwmgr->backend;
1570 struct phm_ppt_v2_information *table_info =
1571 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1572 struct phm_ppt_v1_clock_voltage_dependency_table *dep_on_soc;
1573 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1576 if (hwmgr->od_enabled) {
1577 dep_on_soc = (struct phm_ppt_v1_clock_voltage_dependency_table *)
1578 &data->odn_dpm_table.vdd_dep_on_socclk;
1579 for (i = 0; i < dep_on_soc->count; i++) {
1580 if (dep_on_soc->entries[i].clk >= soc_clock)
1584 dep_on_soc = table_info->vdd_dep_on_socclk;
1585 for (i = 0; i < dep_on_soc->count; i++) {
1586 if (dep_on_soc->entries[i].clk == soc_clock)
1591 PP_ASSERT_WITH_CODE(dep_on_soc->count > i,
1592 "Cannot find SOC_CLK in SOC_VDD-SOC_CLK Dependency Table",
1595 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1596 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1597 soc_clock, ÷rs),
1598 "Failed to get SOC Clock settings from VBIOS!",
1601 *current_soc_did = (uint8_t)dividers.ulDid;
1602 *current_vol_index = (uint8_t)(dep_on_soc->entries[i].vddInd);
1607 * Populates all SMC SCLK levels' structure based on the trimmed allowed dpm engine clock states
1609 * @param hwmgr the address of the hardware manager
1611 static int vega10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1613 struct vega10_hwmgr *data = hwmgr->backend;
1614 struct phm_ppt_v2_information *table_info =
1615 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1616 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1617 struct vega10_single_dpm_table *dpm_table = &(data->dpm_table.gfx_table);
1621 for (i = 0; i < dpm_table->count; i++) {
1622 result = vega10_populate_single_gfx_level(hwmgr,
1623 dpm_table->dpm_levels[i].value,
1624 &(pp_table->GfxclkLevel[i]),
1625 &(pp_table->AcgFreqTable[i]));
1631 while (i < NUM_GFXCLK_DPM_LEVELS) {
1632 result = vega10_populate_single_gfx_level(hwmgr,
1633 dpm_table->dpm_levels[j].value,
1634 &(pp_table->GfxclkLevel[i]),
1635 &(pp_table->AcgFreqTable[i]));
1641 pp_table->GfxclkSlewRate =
1642 cpu_to_le16(table_info->us_gfxclk_slew_rate);
1644 dpm_table = &(data->dpm_table.soc_table);
1645 for (i = 0; i < dpm_table->count; i++) {
1646 result = vega10_populate_single_soc_level(hwmgr,
1647 dpm_table->dpm_levels[i].value,
1648 &(pp_table->SocclkDid[i]),
1649 &(pp_table->SocDpmVoltageIndex[i]));
1655 while (i < NUM_SOCCLK_DPM_LEVELS) {
1656 result = vega10_populate_single_soc_level(hwmgr,
1657 dpm_table->dpm_levels[j].value,
1658 &(pp_table->SocclkDid[i]),
1659 &(pp_table->SocDpmVoltageIndex[i]));
1668 static void vega10_populate_vddc_soc_levels(struct pp_hwmgr *hwmgr)
1670 struct vega10_hwmgr *data = hwmgr->backend;
1671 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1672 struct phm_ppt_v2_information *table_info = hwmgr->pptable;
1673 struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table;
1675 uint8_t soc_vid = 0;
1676 uint32_t i, max_vddc_level;
1678 if (hwmgr->od_enabled)
1679 vddc_lookup_table = (struct phm_ppt_v1_voltage_lookup_table *)&data->odn_dpm_table.vddc_lookup_table;
1681 vddc_lookup_table = table_info->vddc_lookup_table;
1683 max_vddc_level = vddc_lookup_table->count;
1684 for (i = 0; i < max_vddc_level; i++) {
1685 soc_vid = (uint8_t)convert_to_vid(vddc_lookup_table->entries[i].us_vdd);
1686 pp_table->SocVid[i] = soc_vid;
1688 while (i < MAX_REGULAR_DPM_NUMBER) {
1689 pp_table->SocVid[i] = soc_vid;
1695 * @brief Populates single SMC GFXCLK structure using the provided clock.
1697 * @param hwmgr - the address of the hardware manager.
1698 * @param mem_clock - the memory clock to use to populate the structure.
1699 * @return 0 on success..
1701 static int vega10_populate_single_memory_level(struct pp_hwmgr *hwmgr,
1702 uint32_t mem_clock, uint8_t *current_mem_vid,
1703 PllSetting_t *current_memclk_level, uint8_t *current_mem_soc_vind)
1705 struct vega10_hwmgr *data = hwmgr->backend;
1706 struct phm_ppt_v2_information *table_info =
1707 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1708 struct phm_ppt_v1_clock_voltage_dependency_table *dep_on_mclk;
1709 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1710 uint32_t mem_max_clock =
1711 hwmgr->platform_descriptor.overdriveLimit.memoryClock;
1714 if (hwmgr->od_enabled)
1715 dep_on_mclk = (struct phm_ppt_v1_clock_voltage_dependency_table *)
1716 &data->odn_dpm_table.vdd_dep_on_mclk;
1718 dep_on_mclk = table_info->vdd_dep_on_mclk;
1720 PP_ASSERT_WITH_CODE(dep_on_mclk,
1721 "Invalid SOC_VDD-UCLK Dependency Table!",
1724 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
1725 mem_clock = mem_clock > mem_max_clock ? mem_max_clock : mem_clock;
1727 for (i = 0; i < dep_on_mclk->count; i++) {
1728 if (dep_on_mclk->entries[i].clk == mem_clock)
1731 PP_ASSERT_WITH_CODE(dep_on_mclk->count > i,
1732 "Cannot find UCLK in SOC_VDD-UCLK Dependency Table!",
1736 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(
1737 hwmgr, COMPUTE_GPUCLK_INPUT_FLAG_UCLK, mem_clock, ÷rs),
1738 "Failed to get UCLK settings from VBIOS!",
1742 (uint8_t)(convert_to_vid(dep_on_mclk->entries[i].mvdd));
1743 *current_mem_soc_vind =
1744 (uint8_t)(dep_on_mclk->entries[i].vddInd);
1745 current_memclk_level->FbMult = cpu_to_le32(dividers.ulPll_fb_mult);
1746 current_memclk_level->Did = (uint8_t)(dividers.ulDid);
1748 PP_ASSERT_WITH_CODE(current_memclk_level->Did >= 1,
1749 "Invalid Divider ID!",
1756 * @brief Populates all SMC MCLK levels' structure based on the trimmed allowed dpm memory clock states.
1758 * @param pHwMgr - the address of the hardware manager.
1759 * @return PP_Result_OK on success.
1761 static int vega10_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1763 struct vega10_hwmgr *data = hwmgr->backend;
1764 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1765 struct vega10_single_dpm_table *dpm_table =
1766 &(data->dpm_table.mem_table);
1770 for (i = 0; i < dpm_table->count; i++) {
1771 result = vega10_populate_single_memory_level(hwmgr,
1772 dpm_table->dpm_levels[i].value,
1773 &(pp_table->MemVid[i]),
1774 &(pp_table->UclkLevel[i]),
1775 &(pp_table->MemSocVoltageIndex[i]));
1781 while (i < NUM_UCLK_DPM_LEVELS) {
1782 result = vega10_populate_single_memory_level(hwmgr,
1783 dpm_table->dpm_levels[j].value,
1784 &(pp_table->MemVid[i]),
1785 &(pp_table->UclkLevel[i]),
1786 &(pp_table->MemSocVoltageIndex[i]));
1792 pp_table->NumMemoryChannels = (uint16_t)(data->mem_channels);
1793 pp_table->MemoryChannelWidth =
1794 (uint16_t)(HBM_MEMORY_CHANNEL_WIDTH *
1795 channel_number[data->mem_channels]);
1797 pp_table->LowestUclkReservedForUlv =
1798 (uint8_t)(data->lowest_uclk_reserved_for_ulv);
1803 static int vega10_populate_single_display_type(struct pp_hwmgr *hwmgr,
1804 DSPCLK_e disp_clock)
1806 struct vega10_hwmgr *data = hwmgr->backend;
1807 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1808 struct phm_ppt_v2_information *table_info =
1809 (struct phm_ppt_v2_information *)
1811 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
1813 uint16_t clk = 0, vddc = 0;
1816 switch (disp_clock) {
1817 case DSPCLK_DCEFCLK:
1818 dep_table = table_info->vdd_dep_on_dcefclk;
1820 case DSPCLK_DISPCLK:
1821 dep_table = table_info->vdd_dep_on_dispclk;
1824 dep_table = table_info->vdd_dep_on_pixclk;
1827 dep_table = table_info->vdd_dep_on_phyclk;
1833 PP_ASSERT_WITH_CODE(dep_table->count <= NUM_DSPCLK_LEVELS,
1834 "Number Of Entries Exceeded maximum!",
1837 for (i = 0; i < dep_table->count; i++) {
1838 clk = (uint16_t)(dep_table->entries[i].clk / 100);
1839 vddc = table_info->vddc_lookup_table->
1840 entries[dep_table->entries[i].vddInd].us_vdd;
1841 vid = (uint8_t)convert_to_vid(vddc);
1842 pp_table->DisplayClockTable[disp_clock][i].Freq =
1844 pp_table->DisplayClockTable[disp_clock][i].Vid =
1848 while (i < NUM_DSPCLK_LEVELS) {
1849 pp_table->DisplayClockTable[disp_clock][i].Freq =
1851 pp_table->DisplayClockTable[disp_clock][i].Vid =
1859 static int vega10_populate_all_display_clock_levels(struct pp_hwmgr *hwmgr)
1863 for (i = 0; i < DSPCLK_COUNT; i++) {
1864 PP_ASSERT_WITH_CODE(!vega10_populate_single_display_type(hwmgr, i),
1865 "Failed to populate Clock in DisplayClockTable!",
1872 static int vega10_populate_single_eclock_level(struct pp_hwmgr *hwmgr,
1873 uint32_t eclock, uint8_t *current_eclk_did,
1874 uint8_t *current_soc_vol)
1876 struct phm_ppt_v2_information *table_info =
1877 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1878 struct phm_ppt_v1_mm_clock_voltage_dependency_table *dep_table =
1879 table_info->mm_dep_table;
1880 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1883 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1884 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1886 "Failed to get ECLK clock settings from VBIOS!",
1889 *current_eclk_did = (uint8_t)dividers.ulDid;
1891 for (i = 0; i < dep_table->count; i++) {
1892 if (dep_table->entries[i].eclk == eclock)
1893 *current_soc_vol = dep_table->entries[i].vddcInd;
1899 static int vega10_populate_smc_vce_levels(struct pp_hwmgr *hwmgr)
1901 struct vega10_hwmgr *data = hwmgr->backend;
1902 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1903 struct vega10_single_dpm_table *dpm_table = &(data->dpm_table.eclk_table);
1904 int result = -EINVAL;
1907 for (i = 0; i < dpm_table->count; i++) {
1908 result = vega10_populate_single_eclock_level(hwmgr,
1909 dpm_table->dpm_levels[i].value,
1910 &(pp_table->EclkDid[i]),
1911 &(pp_table->VceDpmVoltageIndex[i]));
1917 while (i < NUM_VCE_DPM_LEVELS) {
1918 result = vega10_populate_single_eclock_level(hwmgr,
1919 dpm_table->dpm_levels[j].value,
1920 &(pp_table->EclkDid[i]),
1921 &(pp_table->VceDpmVoltageIndex[i]));
1930 static int vega10_populate_single_vclock_level(struct pp_hwmgr *hwmgr,
1931 uint32_t vclock, uint8_t *current_vclk_did)
1933 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1935 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1936 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1938 "Failed to get VCLK clock settings from VBIOS!",
1941 *current_vclk_did = (uint8_t)dividers.ulDid;
1946 static int vega10_populate_single_dclock_level(struct pp_hwmgr *hwmgr,
1947 uint32_t dclock, uint8_t *current_dclk_did)
1949 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1951 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1952 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1954 "Failed to get DCLK clock settings from VBIOS!",
1957 *current_dclk_did = (uint8_t)dividers.ulDid;
1962 static int vega10_populate_smc_uvd_levels(struct pp_hwmgr *hwmgr)
1964 struct vega10_hwmgr *data = hwmgr->backend;
1965 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1966 struct vega10_single_dpm_table *vclk_dpm_table =
1967 &(data->dpm_table.vclk_table);
1968 struct vega10_single_dpm_table *dclk_dpm_table =
1969 &(data->dpm_table.dclk_table);
1970 struct phm_ppt_v2_information *table_info =
1971 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1972 struct phm_ppt_v1_mm_clock_voltage_dependency_table *dep_table =
1973 table_info->mm_dep_table;
1974 int result = -EINVAL;
1977 for (i = 0; i < vclk_dpm_table->count; i++) {
1978 result = vega10_populate_single_vclock_level(hwmgr,
1979 vclk_dpm_table->dpm_levels[i].value,
1980 &(pp_table->VclkDid[i]));
1986 while (i < NUM_UVD_DPM_LEVELS) {
1987 result = vega10_populate_single_vclock_level(hwmgr,
1988 vclk_dpm_table->dpm_levels[j].value,
1989 &(pp_table->VclkDid[i]));
1995 for (i = 0; i < dclk_dpm_table->count; i++) {
1996 result = vega10_populate_single_dclock_level(hwmgr,
1997 dclk_dpm_table->dpm_levels[i].value,
1998 &(pp_table->DclkDid[i]));
2004 while (i < NUM_UVD_DPM_LEVELS) {
2005 result = vega10_populate_single_dclock_level(hwmgr,
2006 dclk_dpm_table->dpm_levels[j].value,
2007 &(pp_table->DclkDid[i]));
2013 for (i = 0; i < dep_table->count; i++) {
2014 if (dep_table->entries[i].vclk ==
2015 vclk_dpm_table->dpm_levels[i].value &&
2016 dep_table->entries[i].dclk ==
2017 dclk_dpm_table->dpm_levels[i].value)
2018 pp_table->UvdDpmVoltageIndex[i] =
2019 dep_table->entries[i].vddcInd;
2025 while (i < NUM_UVD_DPM_LEVELS) {
2026 pp_table->UvdDpmVoltageIndex[i] = dep_table->entries[j].vddcInd;
2033 static int vega10_populate_clock_stretcher_table(struct pp_hwmgr *hwmgr)
2035 struct vega10_hwmgr *data = hwmgr->backend;
2036 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2037 struct phm_ppt_v2_information *table_info =
2038 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2039 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
2040 table_info->vdd_dep_on_sclk;
2043 for (i = 0; i < dep_table->count; i++) {
2044 pp_table->CksEnable[i] = dep_table->entries[i].cks_enable;
2045 pp_table->CksVidOffset[i] = (uint8_t)(dep_table->entries[i].cks_voffset
2046 * VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
2052 static int vega10_populate_avfs_parameters(struct pp_hwmgr *hwmgr)
2054 struct vega10_hwmgr *data = hwmgr->backend;
2055 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2056 struct phm_ppt_v2_information *table_info =
2057 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2058 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
2059 table_info->vdd_dep_on_sclk;
2060 struct pp_atomfwctrl_avfs_parameters avfs_params = {0};
2064 pp_table->MinVoltageVid = (uint8_t)0xff;
2065 pp_table->MaxVoltageVid = (uint8_t)0;
2067 if (data->smu_features[GNLD_AVFS].supported) {
2068 result = pp_atomfwctrl_get_avfs_information(hwmgr, &avfs_params);
2070 data->odn_dpm_table.max_vddc = avfs_params.ulMaxVddc;
2071 data->odn_dpm_table.min_vddc = avfs_params.ulMinVddc;
2073 pp_table->MinVoltageVid = (uint8_t)
2074 convert_to_vid((uint16_t)(avfs_params.ulMinVddc));
2075 pp_table->MaxVoltageVid = (uint8_t)
2076 convert_to_vid((uint16_t)(avfs_params.ulMaxVddc));
2078 pp_table->AConstant[0] = cpu_to_le32(avfs_params.ulMeanNsigmaAcontant0);
2079 pp_table->AConstant[1] = cpu_to_le32(avfs_params.ulMeanNsigmaAcontant1);
2080 pp_table->AConstant[2] = cpu_to_le32(avfs_params.ulMeanNsigmaAcontant2);
2081 pp_table->DC_tol_sigma = cpu_to_le16(avfs_params.usMeanNsigmaDcTolSigma);
2082 pp_table->Platform_mean = cpu_to_le16(avfs_params.usMeanNsigmaPlatformMean);
2083 pp_table->Platform_sigma = cpu_to_le16(avfs_params.usMeanNsigmaDcTolSigma);
2084 pp_table->PSM_Age_CompFactor = cpu_to_le16(avfs_params.usPsmAgeComfactor);
2086 pp_table->BtcGbVdroopTableCksOff.a0 =
2087 cpu_to_le32(avfs_params.ulGbVdroopTableCksoffA0);
2088 pp_table->BtcGbVdroopTableCksOff.a0_shift = 20;
2089 pp_table->BtcGbVdroopTableCksOff.a1 =
2090 cpu_to_le32(avfs_params.ulGbVdroopTableCksoffA1);
2091 pp_table->BtcGbVdroopTableCksOff.a1_shift = 20;
2092 pp_table->BtcGbVdroopTableCksOff.a2 =
2093 cpu_to_le32(avfs_params.ulGbVdroopTableCksoffA2);
2094 pp_table->BtcGbVdroopTableCksOff.a2_shift = 20;
2096 pp_table->OverrideBtcGbCksOn = avfs_params.ucEnableGbVdroopTableCkson;
2097 pp_table->BtcGbVdroopTableCksOn.a0 =
2098 cpu_to_le32(avfs_params.ulGbVdroopTableCksonA0);
2099 pp_table->BtcGbVdroopTableCksOn.a0_shift = 20;
2100 pp_table->BtcGbVdroopTableCksOn.a1 =
2101 cpu_to_le32(avfs_params.ulGbVdroopTableCksonA1);
2102 pp_table->BtcGbVdroopTableCksOn.a1_shift = 20;
2103 pp_table->BtcGbVdroopTableCksOn.a2 =
2104 cpu_to_le32(avfs_params.ulGbVdroopTableCksonA2);
2105 pp_table->BtcGbVdroopTableCksOn.a2_shift = 20;
2107 pp_table->AvfsGbCksOn.m1 =
2108 cpu_to_le32(avfs_params.ulGbFuseTableCksonM1);
2109 pp_table->AvfsGbCksOn.m2 =
2110 cpu_to_le32(avfs_params.ulGbFuseTableCksonM2);
2111 pp_table->AvfsGbCksOn.b =
2112 cpu_to_le32(avfs_params.ulGbFuseTableCksonB);
2113 pp_table->AvfsGbCksOn.m1_shift = 24;
2114 pp_table->AvfsGbCksOn.m2_shift = 12;
2115 pp_table->AvfsGbCksOn.b_shift = 0;
2117 pp_table->OverrideAvfsGbCksOn =
2118 avfs_params.ucEnableGbFuseTableCkson;
2119 pp_table->AvfsGbCksOff.m1 =
2120 cpu_to_le32(avfs_params.ulGbFuseTableCksoffM1);
2121 pp_table->AvfsGbCksOff.m2 =
2122 cpu_to_le32(avfs_params.ulGbFuseTableCksoffM2);
2123 pp_table->AvfsGbCksOff.b =
2124 cpu_to_le32(avfs_params.ulGbFuseTableCksoffB);
2125 pp_table->AvfsGbCksOff.m1_shift = 24;
2126 pp_table->AvfsGbCksOff.m2_shift = 12;
2127 pp_table->AvfsGbCksOff.b_shift = 0;
2129 for (i = 0; i < dep_table->count; i++)
2130 pp_table->StaticVoltageOffsetVid[i] =
2131 convert_to_vid((uint8_t)(dep_table->entries[i].sclk_offset));
2133 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2134 data->disp_clk_quad_eqn_a) &&
2135 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2136 data->disp_clk_quad_eqn_b)) {
2137 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m1 =
2138 (int32_t)data->disp_clk_quad_eqn_a;
2139 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m2 =
2140 (int32_t)data->disp_clk_quad_eqn_b;
2141 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].b =
2142 (int32_t)data->disp_clk_quad_eqn_c;
2144 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m1 =
2145 (int32_t)avfs_params.ulDispclk2GfxclkM1;
2146 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m2 =
2147 (int32_t)avfs_params.ulDispclk2GfxclkM2;
2148 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].b =
2149 (int32_t)avfs_params.ulDispclk2GfxclkB;
2152 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m1_shift = 24;
2153 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m2_shift = 12;
2154 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].b_shift = 12;
2156 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2157 data->dcef_clk_quad_eqn_a) &&
2158 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2159 data->dcef_clk_quad_eqn_b)) {
2160 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m1 =
2161 (int32_t)data->dcef_clk_quad_eqn_a;
2162 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m2 =
2163 (int32_t)data->dcef_clk_quad_eqn_b;
2164 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].b =
2165 (int32_t)data->dcef_clk_quad_eqn_c;
2167 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m1 =
2168 (int32_t)avfs_params.ulDcefclk2GfxclkM1;
2169 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m2 =
2170 (int32_t)avfs_params.ulDcefclk2GfxclkM2;
2171 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].b =
2172 (int32_t)avfs_params.ulDcefclk2GfxclkB;
2175 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m1_shift = 24;
2176 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m2_shift = 12;
2177 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].b_shift = 12;
2179 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2180 data->pixel_clk_quad_eqn_a) &&
2181 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2182 data->pixel_clk_quad_eqn_b)) {
2183 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m1 =
2184 (int32_t)data->pixel_clk_quad_eqn_a;
2185 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m2 =
2186 (int32_t)data->pixel_clk_quad_eqn_b;
2187 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].b =
2188 (int32_t)data->pixel_clk_quad_eqn_c;
2190 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m1 =
2191 (int32_t)avfs_params.ulPixelclk2GfxclkM1;
2192 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m2 =
2193 (int32_t)avfs_params.ulPixelclk2GfxclkM2;
2194 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].b =
2195 (int32_t)avfs_params.ulPixelclk2GfxclkB;
2198 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m1_shift = 24;
2199 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m2_shift = 12;
2200 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].b_shift = 12;
2201 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2202 data->phy_clk_quad_eqn_a) &&
2203 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2204 data->phy_clk_quad_eqn_b)) {
2205 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m1 =
2206 (int32_t)data->phy_clk_quad_eqn_a;
2207 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m2 =
2208 (int32_t)data->phy_clk_quad_eqn_b;
2209 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].b =
2210 (int32_t)data->phy_clk_quad_eqn_c;
2212 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m1 =
2213 (int32_t)avfs_params.ulPhyclk2GfxclkM1;
2214 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m2 =
2215 (int32_t)avfs_params.ulPhyclk2GfxclkM2;
2216 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].b =
2217 (int32_t)avfs_params.ulPhyclk2GfxclkB;
2220 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m1_shift = 24;
2221 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m2_shift = 12;
2222 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].b_shift = 12;
2224 pp_table->AcgBtcGbVdroopTable.a0 = avfs_params.ulAcgGbVdroopTableA0;
2225 pp_table->AcgBtcGbVdroopTable.a0_shift = 20;
2226 pp_table->AcgBtcGbVdroopTable.a1 = avfs_params.ulAcgGbVdroopTableA1;
2227 pp_table->AcgBtcGbVdroopTable.a1_shift = 20;
2228 pp_table->AcgBtcGbVdroopTable.a2 = avfs_params.ulAcgGbVdroopTableA2;
2229 pp_table->AcgBtcGbVdroopTable.a2_shift = 20;
2231 pp_table->AcgAvfsGb.m1 = avfs_params.ulAcgGbFuseTableM1;
2232 pp_table->AcgAvfsGb.m2 = avfs_params.ulAcgGbFuseTableM2;
2233 pp_table->AcgAvfsGb.b = avfs_params.ulAcgGbFuseTableB;
2234 pp_table->AcgAvfsGb.m1_shift = 0;
2235 pp_table->AcgAvfsGb.m2_shift = 0;
2236 pp_table->AcgAvfsGb.b_shift = 0;
2239 data->smu_features[GNLD_AVFS].supported = false;
2246 static int vega10_acg_enable(struct pp_hwmgr *hwmgr)
2248 struct vega10_hwmgr *data = hwmgr->backend;
2249 uint32_t agc_btc_response;
2251 if (data->smu_features[GNLD_ACG].supported) {
2252 if (0 == vega10_enable_smc_features(hwmgr, true,
2253 data->smu_features[GNLD_DPM_PREFETCHER].smu_feature_bitmap))
2254 data->smu_features[GNLD_DPM_PREFETCHER].enabled = true;
2256 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_InitializeAcg);
2258 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgBtc);
2259 agc_btc_response = smum_get_argument(hwmgr);
2261 if (1 == agc_btc_response) {
2262 if (1 == data->acg_loop_state)
2263 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgInClosedLoop);
2264 else if (2 == data->acg_loop_state)
2265 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgInOpenLoop);
2266 if (0 == vega10_enable_smc_features(hwmgr, true,
2267 data->smu_features[GNLD_ACG].smu_feature_bitmap))
2268 data->smu_features[GNLD_ACG].enabled = true;
2270 pr_info("[ACG_Enable] ACG BTC Returned Failed Status!\n");
2271 data->smu_features[GNLD_ACG].enabled = false;
2278 static int vega10_acg_disable(struct pp_hwmgr *hwmgr)
2280 struct vega10_hwmgr *data = hwmgr->backend;
2282 if (data->smu_features[GNLD_ACG].supported &&
2283 data->smu_features[GNLD_ACG].enabled)
2284 if (!vega10_enable_smc_features(hwmgr, false,
2285 data->smu_features[GNLD_ACG].smu_feature_bitmap))
2286 data->smu_features[GNLD_ACG].enabled = false;
2291 static int vega10_populate_gpio_parameters(struct pp_hwmgr *hwmgr)
2293 struct vega10_hwmgr *data = hwmgr->backend;
2294 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2295 struct pp_atomfwctrl_gpio_parameters gpio_params = {0};
2298 result = pp_atomfwctrl_get_gpio_information(hwmgr, &gpio_params);
2300 if (PP_CAP(PHM_PlatformCaps_RegulatorHot) &&
2301 data->registry_data.regulator_hot_gpio_support) {
2302 pp_table->VR0HotGpio = gpio_params.ucVR0HotGpio;
2303 pp_table->VR0HotPolarity = gpio_params.ucVR0HotPolarity;
2304 pp_table->VR1HotGpio = gpio_params.ucVR1HotGpio;
2305 pp_table->VR1HotPolarity = gpio_params.ucVR1HotPolarity;
2307 pp_table->VR0HotGpio = 0;
2308 pp_table->VR0HotPolarity = 0;
2309 pp_table->VR1HotGpio = 0;
2310 pp_table->VR1HotPolarity = 0;
2313 if (PP_CAP(PHM_PlatformCaps_AutomaticDCTransition) &&
2314 data->registry_data.ac_dc_switch_gpio_support) {
2315 pp_table->AcDcGpio = gpio_params.ucAcDcGpio;
2316 pp_table->AcDcPolarity = gpio_params.ucAcDcPolarity;
2318 pp_table->AcDcGpio = 0;
2319 pp_table->AcDcPolarity = 0;
2326 static int vega10_avfs_enable(struct pp_hwmgr *hwmgr, bool enable)
2328 struct vega10_hwmgr *data = hwmgr->backend;
2330 if (data->smu_features[GNLD_AVFS].supported) {
2332 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2334 data->smu_features[GNLD_AVFS].smu_feature_bitmap),
2335 "[avfs_control] Attempt to Enable AVFS feature Failed!",
2337 data->smu_features[GNLD_AVFS].enabled = true;
2339 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2341 data->smu_features[GNLD_AVFS].smu_feature_bitmap),
2342 "[avfs_control] Attempt to Disable AVFS feature Failed!",
2344 data->smu_features[GNLD_AVFS].enabled = false;
2351 static int vega10_update_avfs(struct pp_hwmgr *hwmgr)
2353 struct vega10_hwmgr *data = hwmgr->backend;
2355 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
2356 vega10_avfs_enable(hwmgr, false);
2357 } else if (data->need_update_dpm_table) {
2358 vega10_avfs_enable(hwmgr, false);
2359 vega10_avfs_enable(hwmgr, true);
2361 vega10_avfs_enable(hwmgr, true);
2367 static int vega10_populate_and_upload_avfs_fuse_override(struct pp_hwmgr *hwmgr)
2371 uint64_t serial_number = 0;
2372 uint32_t top32, bottom32;
2373 struct phm_fuses_default fuse;
2375 struct vega10_hwmgr *data = hwmgr->backend;
2376 AvfsFuseOverride_t *avfs_fuse_table = &(data->smc_state_table.avfs_fuse_override_table);
2378 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumTop32);
2379 top32 = smum_get_argument(hwmgr);
2381 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumBottom32);
2382 bottom32 = smum_get_argument(hwmgr);
2384 serial_number = ((uint64_t)bottom32 << 32) | top32;
2386 if (pp_override_get_default_fuse_value(serial_number, &fuse) == 0) {
2387 avfs_fuse_table->VFT0_b = fuse.VFT0_b;
2388 avfs_fuse_table->VFT0_m1 = fuse.VFT0_m1;
2389 avfs_fuse_table->VFT0_m2 = fuse.VFT0_m2;
2390 avfs_fuse_table->VFT1_b = fuse.VFT1_b;
2391 avfs_fuse_table->VFT1_m1 = fuse.VFT1_m1;
2392 avfs_fuse_table->VFT1_m2 = fuse.VFT1_m2;
2393 avfs_fuse_table->VFT2_b = fuse.VFT2_b;
2394 avfs_fuse_table->VFT2_m1 = fuse.VFT2_m1;
2395 avfs_fuse_table->VFT2_m2 = fuse.VFT2_m2;
2396 result = smum_smc_table_manager(hwmgr, (uint8_t *)avfs_fuse_table,
2397 AVFSFUSETABLE, false);
2398 PP_ASSERT_WITH_CODE(!result,
2399 "Failed to upload FuseOVerride!",
2407 * Initializes the SMC table and uploads it
2409 * @param hwmgr the address of the powerplay hardware manager.
2410 * @param pInput the pointer to input data (PowerState)
2413 static int vega10_init_smc_table(struct pp_hwmgr *hwmgr)
2416 struct vega10_hwmgr *data = hwmgr->backend;
2417 struct phm_ppt_v2_information *table_info =
2418 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2419 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2420 struct pp_atomfwctrl_voltage_table voltage_table;
2421 struct pp_atomfwctrl_bios_boot_up_values boot_up_values;
2423 result = vega10_setup_default_dpm_tables(hwmgr);
2424 PP_ASSERT_WITH_CODE(!result,
2425 "Failed to setup default DPM tables!",
2428 /* initialize ODN table */
2429 if (hwmgr->od_enabled)
2430 vega10_odn_initial_default_setting(hwmgr);
2432 pp_atomfwctrl_get_voltage_table_v4(hwmgr, VOLTAGE_TYPE_VDDC,
2433 VOLTAGE_OBJ_SVID2, &voltage_table);
2434 pp_table->MaxVidStep = voltage_table.max_vid_step;
2436 pp_table->GfxDpmVoltageMode =
2437 (uint8_t)(table_info->uc_gfx_dpm_voltage_mode);
2438 pp_table->SocDpmVoltageMode =
2439 (uint8_t)(table_info->uc_soc_dpm_voltage_mode);
2440 pp_table->UclkDpmVoltageMode =
2441 (uint8_t)(table_info->uc_uclk_dpm_voltage_mode);
2442 pp_table->UvdDpmVoltageMode =
2443 (uint8_t)(table_info->uc_uvd_dpm_voltage_mode);
2444 pp_table->VceDpmVoltageMode =
2445 (uint8_t)(table_info->uc_vce_dpm_voltage_mode);
2446 pp_table->Mp0DpmVoltageMode =
2447 (uint8_t)(table_info->uc_mp0_dpm_voltage_mode);
2449 pp_table->DisplayDpmVoltageMode =
2450 (uint8_t)(table_info->uc_dcef_dpm_voltage_mode);
2452 data->vddc_voltage_table.psi0_enable = voltage_table.psi0_enable;
2453 data->vddc_voltage_table.psi1_enable = voltage_table.psi1_enable;
2455 if (data->registry_data.ulv_support &&
2456 table_info->us_ulv_voltage_offset) {
2457 result = vega10_populate_ulv_state(hwmgr);
2458 PP_ASSERT_WITH_CODE(!result,
2459 "Failed to initialize ULV state!",
2463 result = vega10_populate_smc_link_levels(hwmgr);
2464 PP_ASSERT_WITH_CODE(!result,
2465 "Failed to initialize Link Level!",
2468 result = vega10_populate_all_graphic_levels(hwmgr);
2469 PP_ASSERT_WITH_CODE(!result,
2470 "Failed to initialize Graphics Level!",
2473 result = vega10_populate_all_memory_levels(hwmgr);
2474 PP_ASSERT_WITH_CODE(!result,
2475 "Failed to initialize Memory Level!",
2478 vega10_populate_vddc_soc_levels(hwmgr);
2480 result = vega10_populate_all_display_clock_levels(hwmgr);
2481 PP_ASSERT_WITH_CODE(!result,
2482 "Failed to initialize Display Level!",
2485 result = vega10_populate_smc_vce_levels(hwmgr);
2486 PP_ASSERT_WITH_CODE(!result,
2487 "Failed to initialize VCE Level!",
2490 result = vega10_populate_smc_uvd_levels(hwmgr);
2491 PP_ASSERT_WITH_CODE(!result,
2492 "Failed to initialize UVD Level!",
2495 if (data->registry_data.clock_stretcher_support) {
2496 result = vega10_populate_clock_stretcher_table(hwmgr);
2497 PP_ASSERT_WITH_CODE(!result,
2498 "Failed to populate Clock Stretcher Table!",
2502 result = pp_atomfwctrl_get_vbios_bootup_values(hwmgr, &boot_up_values);
2504 data->vbios_boot_state.vddc = boot_up_values.usVddc;
2505 data->vbios_boot_state.vddci = boot_up_values.usVddci;
2506 data->vbios_boot_state.mvddc = boot_up_values.usMvddc;
2507 data->vbios_boot_state.gfx_clock = boot_up_values.ulGfxClk;
2508 data->vbios_boot_state.mem_clock = boot_up_values.ulUClk;
2509 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr,
2510 SMU9_SYSPLL0_SOCCLK_ID, &boot_up_values.ulSocClk);
2512 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr,
2513 SMU9_SYSPLL0_DCEFCLK_ID, &boot_up_values.ulDCEFClk);
2515 data->vbios_boot_state.soc_clock = boot_up_values.ulSocClk;
2516 data->vbios_boot_state.dcef_clock = boot_up_values.ulDCEFClk;
2517 if (0 != boot_up_values.usVddc) {
2518 smum_send_msg_to_smc_with_parameter(hwmgr,
2519 PPSMC_MSG_SetFloorSocVoltage,
2520 (boot_up_values.usVddc * 4));
2521 data->vbios_boot_state.bsoc_vddc_lock = true;
2523 data->vbios_boot_state.bsoc_vddc_lock = false;
2525 smum_send_msg_to_smc_with_parameter(hwmgr,
2526 PPSMC_MSG_SetMinDeepSleepDcefclk,
2527 (uint32_t)(data->vbios_boot_state.dcef_clock / 100));
2530 result = vega10_populate_avfs_parameters(hwmgr);
2531 PP_ASSERT_WITH_CODE(!result,
2532 "Failed to initialize AVFS Parameters!",
2535 result = vega10_populate_gpio_parameters(hwmgr);
2536 PP_ASSERT_WITH_CODE(!result,
2537 "Failed to initialize GPIO Parameters!",
2540 pp_table->GfxclkAverageAlpha = (uint8_t)
2541 (data->gfxclk_average_alpha);
2542 pp_table->SocclkAverageAlpha = (uint8_t)
2543 (data->socclk_average_alpha);
2544 pp_table->UclkAverageAlpha = (uint8_t)
2545 (data->uclk_average_alpha);
2546 pp_table->GfxActivityAverageAlpha = (uint8_t)
2547 (data->gfx_activity_average_alpha);
2549 vega10_populate_and_upload_avfs_fuse_override(hwmgr);
2551 result = smum_smc_table_manager(hwmgr, (uint8_t *)pp_table, PPTABLE, false);
2553 PP_ASSERT_WITH_CODE(!result,
2554 "Failed to upload PPtable!", return result);
2556 result = vega10_avfs_enable(hwmgr, true);
2557 PP_ASSERT_WITH_CODE(!result, "Attempt to enable AVFS feature Failed!",
2559 vega10_acg_enable(hwmgr);
2564 static int vega10_enable_thermal_protection(struct pp_hwmgr *hwmgr)
2566 struct vega10_hwmgr *data = hwmgr->backend;
2568 if (data->smu_features[GNLD_THERMAL].supported) {
2569 if (data->smu_features[GNLD_THERMAL].enabled)
2570 pr_info("THERMAL Feature Already enabled!");
2572 PP_ASSERT_WITH_CODE(
2573 !vega10_enable_smc_features(hwmgr,
2575 data->smu_features[GNLD_THERMAL].smu_feature_bitmap),
2576 "Enable THERMAL Feature Failed!",
2578 data->smu_features[GNLD_THERMAL].enabled = true;
2584 static int vega10_disable_thermal_protection(struct pp_hwmgr *hwmgr)
2586 struct vega10_hwmgr *data = hwmgr->backend;
2588 if (data->smu_features[GNLD_THERMAL].supported) {
2589 if (!data->smu_features[GNLD_THERMAL].enabled)
2590 pr_info("THERMAL Feature Already disabled!");
2592 PP_ASSERT_WITH_CODE(
2593 !vega10_enable_smc_features(hwmgr,
2595 data->smu_features[GNLD_THERMAL].smu_feature_bitmap),
2596 "disable THERMAL Feature Failed!",
2598 data->smu_features[GNLD_THERMAL].enabled = false;
2604 static int vega10_enable_vrhot_feature(struct pp_hwmgr *hwmgr)
2606 struct vega10_hwmgr *data = hwmgr->backend;
2608 if (PP_CAP(PHM_PlatformCaps_RegulatorHot)) {
2609 if (data->smu_features[GNLD_VR0HOT].supported) {
2610 PP_ASSERT_WITH_CODE(
2611 !vega10_enable_smc_features(hwmgr,
2613 data->smu_features[GNLD_VR0HOT].smu_feature_bitmap),
2614 "Attempt to Enable VR0 Hot feature Failed!",
2616 data->smu_features[GNLD_VR0HOT].enabled = true;
2618 if (data->smu_features[GNLD_VR1HOT].supported) {
2619 PP_ASSERT_WITH_CODE(
2620 !vega10_enable_smc_features(hwmgr,
2622 data->smu_features[GNLD_VR1HOT].smu_feature_bitmap),
2623 "Attempt to Enable VR0 Hot feature Failed!",
2625 data->smu_features[GNLD_VR1HOT].enabled = true;
2632 static int vega10_enable_ulv(struct pp_hwmgr *hwmgr)
2634 struct vega10_hwmgr *data = hwmgr->backend;
2636 if (data->registry_data.ulv_support) {
2637 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2638 true, data->smu_features[GNLD_ULV].smu_feature_bitmap),
2639 "Enable ULV Feature Failed!",
2641 data->smu_features[GNLD_ULV].enabled = true;
2647 static int vega10_disable_ulv(struct pp_hwmgr *hwmgr)
2649 struct vega10_hwmgr *data = hwmgr->backend;
2651 if (data->registry_data.ulv_support) {
2652 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2653 false, data->smu_features[GNLD_ULV].smu_feature_bitmap),
2654 "disable ULV Feature Failed!",
2656 data->smu_features[GNLD_ULV].enabled = false;
2662 static int vega10_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2664 struct vega10_hwmgr *data = hwmgr->backend;
2666 if (data->smu_features[GNLD_DS_GFXCLK].supported) {
2667 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2668 true, data->smu_features[GNLD_DS_GFXCLK].smu_feature_bitmap),
2669 "Attempt to Enable DS_GFXCLK Feature Failed!",
2671 data->smu_features[GNLD_DS_GFXCLK].enabled = true;
2674 if (data->smu_features[GNLD_DS_SOCCLK].supported) {
2675 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2676 true, data->smu_features[GNLD_DS_SOCCLK].smu_feature_bitmap),
2677 "Attempt to Enable DS_SOCCLK Feature Failed!",
2679 data->smu_features[GNLD_DS_SOCCLK].enabled = true;
2682 if (data->smu_features[GNLD_DS_LCLK].supported) {
2683 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2684 true, data->smu_features[GNLD_DS_LCLK].smu_feature_bitmap),
2685 "Attempt to Enable DS_LCLK Feature Failed!",
2687 data->smu_features[GNLD_DS_LCLK].enabled = true;
2690 if (data->smu_features[GNLD_DS_DCEFCLK].supported) {
2691 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2692 true, data->smu_features[GNLD_DS_DCEFCLK].smu_feature_bitmap),
2693 "Attempt to Enable DS_DCEFCLK Feature Failed!",
2695 data->smu_features[GNLD_DS_DCEFCLK].enabled = true;
2701 static int vega10_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2703 struct vega10_hwmgr *data = hwmgr->backend;
2705 if (data->smu_features[GNLD_DS_GFXCLK].supported) {
2706 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2707 false, data->smu_features[GNLD_DS_GFXCLK].smu_feature_bitmap),
2708 "Attempt to disable DS_GFXCLK Feature Failed!",
2710 data->smu_features[GNLD_DS_GFXCLK].enabled = false;
2713 if (data->smu_features[GNLD_DS_SOCCLK].supported) {
2714 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2715 false, data->smu_features[GNLD_DS_SOCCLK].smu_feature_bitmap),
2716 "Attempt to disable DS_ Feature Failed!",
2718 data->smu_features[GNLD_DS_SOCCLK].enabled = false;
2721 if (data->smu_features[GNLD_DS_LCLK].supported) {
2722 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2723 false, data->smu_features[GNLD_DS_LCLK].smu_feature_bitmap),
2724 "Attempt to disable DS_LCLK Feature Failed!",
2726 data->smu_features[GNLD_DS_LCLK].enabled = false;
2729 if (data->smu_features[GNLD_DS_DCEFCLK].supported) {
2730 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2731 false, data->smu_features[GNLD_DS_DCEFCLK].smu_feature_bitmap),
2732 "Attempt to disable DS_DCEFCLK Feature Failed!",
2734 data->smu_features[GNLD_DS_DCEFCLK].enabled = false;
2740 static int vega10_stop_dpm(struct pp_hwmgr *hwmgr, uint32_t bitmap)
2742 struct vega10_hwmgr *data = hwmgr->backend;
2743 uint32_t i, feature_mask = 0;
2746 if(data->smu_features[GNLD_LED_DISPLAY].supported == true){
2747 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2748 false, data->smu_features[GNLD_LED_DISPLAY].smu_feature_bitmap),
2749 "Attempt to disable LED DPM feature failed!", return -EINVAL);
2750 data->smu_features[GNLD_LED_DISPLAY].enabled = false;
2753 for (i = 0; i < GNLD_DPM_MAX; i++) {
2754 if (data->smu_features[i].smu_feature_bitmap & bitmap) {
2755 if (data->smu_features[i].supported) {
2756 if (data->smu_features[i].enabled) {
2757 feature_mask |= data->smu_features[i].
2759 data->smu_features[i].enabled = false;
2765 vega10_enable_smc_features(hwmgr, false, feature_mask);
2771 * @brief Tell SMC to enabled the supported DPMs.
2773 * @param hwmgr - the address of the powerplay hardware manager.
2774 * @Param bitmap - bitmap for the features to enabled.
2775 * @return 0 on at least one DPM is successfully enabled.
2777 static int vega10_start_dpm(struct pp_hwmgr *hwmgr, uint32_t bitmap)
2779 struct vega10_hwmgr *data = hwmgr->backend;
2780 uint32_t i, feature_mask = 0;
2782 for (i = 0; i < GNLD_DPM_MAX; i++) {
2783 if (data->smu_features[i].smu_feature_bitmap & bitmap) {
2784 if (data->smu_features[i].supported) {
2785 if (!data->smu_features[i].enabled) {
2786 feature_mask |= data->smu_features[i].
2788 data->smu_features[i].enabled = true;
2794 if (vega10_enable_smc_features(hwmgr,
2795 true, feature_mask)) {
2796 for (i = 0; i < GNLD_DPM_MAX; i++) {
2797 if (data->smu_features[i].smu_feature_bitmap &
2799 data->smu_features[i].enabled = false;
2803 if(data->smu_features[GNLD_LED_DISPLAY].supported == true){
2804 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2805 true, data->smu_features[GNLD_LED_DISPLAY].smu_feature_bitmap),
2806 "Attempt to Enable LED DPM feature Failed!", return -EINVAL);
2807 data->smu_features[GNLD_LED_DISPLAY].enabled = true;
2810 if (data->vbios_boot_state.bsoc_vddc_lock) {
2811 smum_send_msg_to_smc_with_parameter(hwmgr,
2812 PPSMC_MSG_SetFloorSocVoltage, 0);
2813 data->vbios_boot_state.bsoc_vddc_lock = false;
2816 if (PP_CAP(PHM_PlatformCaps_Falcon_QuickTransition)) {
2817 if (data->smu_features[GNLD_ACDC].supported) {
2818 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2819 true, data->smu_features[GNLD_ACDC].smu_feature_bitmap),
2820 "Attempt to Enable DS_GFXCLK Feature Failed!",
2822 data->smu_features[GNLD_ACDC].enabled = true;
2829 static int vega10_enable_disable_PCC_limit_feature(struct pp_hwmgr *hwmgr, bool enable)
2831 struct vega10_hwmgr *data = hwmgr->backend;
2833 if (data->smu_features[GNLD_PCC_LIMIT].supported) {
2834 if (enable == data->smu_features[GNLD_PCC_LIMIT].enabled)
2835 pr_info("GNLD_PCC_LIMIT has been %s \n", enable ? "enabled" : "disabled");
2836 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2837 enable, data->smu_features[GNLD_PCC_LIMIT].smu_feature_bitmap),
2838 "Attempt to Enable PCC Limit feature Failed!",
2840 data->smu_features[GNLD_PCC_LIMIT].enabled = enable;
2846 static int vega10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
2848 struct vega10_hwmgr *data = hwmgr->backend;
2849 int tmp_result, result = 0;
2851 vega10_enable_disable_PCC_limit_feature(hwmgr, true);
2853 if ((hwmgr->smu_version == 0x001c2c00) ||
2854 (hwmgr->smu_version == 0x001c2d00))
2855 smum_send_msg_to_smc_with_parameter(hwmgr,
2856 PPSMC_MSG_UpdatePkgPwrPidAlpha, 1);
2858 smum_send_msg_to_smc_with_parameter(hwmgr,
2859 PPSMC_MSG_ConfigureTelemetry, data->config_telemetry);
2861 tmp_result = vega10_construct_voltage_tables(hwmgr);
2862 PP_ASSERT_WITH_CODE(!tmp_result,
2863 "Failed to contruct voltage tables!",
2864 result = tmp_result);
2866 tmp_result = vega10_init_smc_table(hwmgr);
2867 PP_ASSERT_WITH_CODE(!tmp_result,
2868 "Failed to initialize SMC table!",
2869 result = tmp_result);
2871 if (PP_CAP(PHM_PlatformCaps_ThermalController)) {
2872 tmp_result = vega10_enable_thermal_protection(hwmgr);
2873 PP_ASSERT_WITH_CODE(!tmp_result,
2874 "Failed to enable thermal protection!",
2875 result = tmp_result);
2878 tmp_result = vega10_enable_vrhot_feature(hwmgr);
2879 PP_ASSERT_WITH_CODE(!tmp_result,
2880 "Failed to enable VR hot feature!",
2881 result = tmp_result);
2883 tmp_result = vega10_enable_deep_sleep_master_switch(hwmgr);
2884 PP_ASSERT_WITH_CODE(!tmp_result,
2885 "Failed to enable deep sleep master switch!",
2886 result = tmp_result);
2888 tmp_result = vega10_start_dpm(hwmgr, SMC_DPM_FEATURES);
2889 PP_ASSERT_WITH_CODE(!tmp_result,
2890 "Failed to start DPM!", result = tmp_result);
2892 /* enable didt, do not abort if failed didt */
2893 tmp_result = vega10_enable_didt_config(hwmgr);
2894 PP_ASSERT(!tmp_result,
2895 "Failed to enable didt config!");
2897 tmp_result = vega10_enable_power_containment(hwmgr);
2898 PP_ASSERT_WITH_CODE(!tmp_result,
2899 "Failed to enable power containment!",
2900 result = tmp_result);
2902 tmp_result = vega10_power_control_set_level(hwmgr);
2903 PP_ASSERT_WITH_CODE(!tmp_result,
2904 "Failed to power control set level!",
2905 result = tmp_result);
2907 tmp_result = vega10_enable_ulv(hwmgr);
2908 PP_ASSERT_WITH_CODE(!tmp_result,
2909 "Failed to enable ULV!",
2910 result = tmp_result);
2915 static int vega10_get_power_state_size(struct pp_hwmgr *hwmgr)
2917 return sizeof(struct vega10_power_state);
2920 static int vega10_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
2921 void *state, struct pp_power_state *power_state,
2922 void *pp_table, uint32_t classification_flag)
2924 ATOM_Vega10_GFXCLK_Dependency_Record_V2 *patom_record_V2;
2925 struct vega10_power_state *vega10_power_state =
2926 cast_phw_vega10_power_state(&(power_state->hardware));
2927 struct vega10_performance_level *performance_level;
2928 ATOM_Vega10_State *state_entry = (ATOM_Vega10_State *)state;
2929 ATOM_Vega10_POWERPLAYTABLE *powerplay_table =
2930 (ATOM_Vega10_POWERPLAYTABLE *)pp_table;
2931 ATOM_Vega10_SOCCLK_Dependency_Table *socclk_dep_table =
2932 (ATOM_Vega10_SOCCLK_Dependency_Table *)
2933 (((unsigned long)powerplay_table) +
2934 le16_to_cpu(powerplay_table->usSocclkDependencyTableOffset));
2935 ATOM_Vega10_GFXCLK_Dependency_Table *gfxclk_dep_table =
2936 (ATOM_Vega10_GFXCLK_Dependency_Table *)
2937 (((unsigned long)powerplay_table) +
2938 le16_to_cpu(powerplay_table->usGfxclkDependencyTableOffset));
2939 ATOM_Vega10_MCLK_Dependency_Table *mclk_dep_table =
2940 (ATOM_Vega10_MCLK_Dependency_Table *)
2941 (((unsigned long)powerplay_table) +
2942 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
2945 /* The following fields are not initialized here:
2946 * id orderedList allStatesList
2948 power_state->classification.ui_label =
2949 (le16_to_cpu(state_entry->usClassification) &
2950 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
2951 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
2952 power_state->classification.flags = classification_flag;
2953 /* NOTE: There is a classification2 flag in BIOS
2954 * that is not being used right now
2956 power_state->classification.temporary_state = false;
2957 power_state->classification.to_be_deleted = false;
2959 power_state->validation.disallowOnDC =
2960 ((le32_to_cpu(state_entry->ulCapsAndSettings) &
2961 ATOM_Vega10_DISALLOW_ON_DC) != 0);
2963 power_state->display.disableFrameModulation = false;
2964 power_state->display.limitRefreshrate = false;
2965 power_state->display.enableVariBright =
2966 ((le32_to_cpu(state_entry->ulCapsAndSettings) &
2967 ATOM_Vega10_ENABLE_VARIBRIGHT) != 0);
2969 power_state->validation.supportedPowerLevels = 0;
2970 power_state->uvd_clocks.VCLK = 0;
2971 power_state->uvd_clocks.DCLK = 0;
2972 power_state->temperatures.min = 0;
2973 power_state->temperatures.max = 0;
2975 performance_level = &(vega10_power_state->performance_levels
2976 [vega10_power_state->performance_level_count++]);
2978 PP_ASSERT_WITH_CODE(
2979 (vega10_power_state->performance_level_count <
2980 NUM_GFXCLK_DPM_LEVELS),
2981 "Performance levels exceeds SMC limit!",
2984 PP_ASSERT_WITH_CODE(
2985 (vega10_power_state->performance_level_count <=
2986 hwmgr->platform_descriptor.
2987 hardwareActivityPerformanceLevels),
2988 "Performance levels exceeds Driver limit!",
2991 /* Performance levels are arranged from low to high. */
2992 performance_level->soc_clock = socclk_dep_table->entries
2993 [state_entry->ucSocClockIndexLow].ulClk;
2994 performance_level->gfx_clock = gfxclk_dep_table->entries
2995 [state_entry->ucGfxClockIndexLow].ulClk;
2996 performance_level->mem_clock = mclk_dep_table->entries
2997 [state_entry->ucMemClockIndexLow].ulMemClk;
2999 performance_level = &(vega10_power_state->performance_levels
3000 [vega10_power_state->performance_level_count++]);
3001 performance_level->soc_clock = socclk_dep_table->entries
3002 [state_entry->ucSocClockIndexHigh].ulClk;
3003 if (gfxclk_dep_table->ucRevId == 0) {
3004 performance_level->gfx_clock = gfxclk_dep_table->entries
3005 [state_entry->ucGfxClockIndexHigh].ulClk;
3006 } else if (gfxclk_dep_table->ucRevId == 1) {
3007 patom_record_V2 = (ATOM_Vega10_GFXCLK_Dependency_Record_V2 *)gfxclk_dep_table->entries;
3008 performance_level->gfx_clock = patom_record_V2[state_entry->ucGfxClockIndexHigh].ulClk;
3011 performance_level->mem_clock = mclk_dep_table->entries
3012 [state_entry->ucMemClockIndexHigh].ulMemClk;
3016 static int vega10_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3017 unsigned long entry_index, struct pp_power_state *state)
3020 struct vega10_power_state *ps;
3022 state->hardware.magic = PhwVega10_Magic;
3024 ps = cast_phw_vega10_power_state(&state->hardware);
3026 result = vega10_get_powerplay_table_entry(hwmgr, entry_index, state,
3027 vega10_get_pp_table_entry_callback_func);
3030 * This is the earliest time we have all the dependency table
3031 * and the VBIOS boot state
3033 /* set DC compatible flag if this state supports DC */
3034 if (!state->validation.disallowOnDC)
3035 ps->dc_compatible = true;
3037 ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3038 ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3043 static int vega10_patch_boot_state(struct pp_hwmgr *hwmgr,
3044 struct pp_hw_power_state *hw_ps)
3049 static int vega10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3050 struct pp_power_state *request_ps,
3051 const struct pp_power_state *current_ps)
3053 struct vega10_power_state *vega10_ps =
3054 cast_phw_vega10_power_state(&request_ps->hardware);
3057 struct PP_Clocks minimum_clocks = {0};
3058 bool disable_mclk_switching;
3059 bool disable_mclk_switching_for_frame_lock;
3060 bool disable_mclk_switching_for_vr;
3061 bool force_mclk_high;
3062 const struct phm_clock_and_voltage_limits *max_limits;
3064 struct vega10_hwmgr *data = hwmgr->backend;
3065 struct phm_ppt_v2_information *table_info =
3066 (struct phm_ppt_v2_information *)(hwmgr->pptable);
3068 uint32_t stable_pstate_sclk_dpm_percentage;
3069 uint32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3072 data->battery_state = (PP_StateUILabel_Battery ==
3073 request_ps->classification.ui_label);
3075 if (vega10_ps->performance_level_count != 2)
3076 pr_info("VI should always have 2 performance levels");
3078 max_limits = (PP_PowerSource_AC == hwmgr->power_source) ?
3079 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3080 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3082 /* Cap clock DPM tables at DC MAX if it is in DC. */
3083 if (PP_PowerSource_DC == hwmgr->power_source) {
3084 for (i = 0; i < vega10_ps->performance_level_count; i++) {
3085 if (vega10_ps->performance_levels[i].mem_clock >
3087 vega10_ps->performance_levels[i].mem_clock =
3089 if (vega10_ps->performance_levels[i].gfx_clock >
3091 vega10_ps->performance_levels[i].gfx_clock =
3096 /* result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3097 minimum_clocks.engineClock = hwmgr->display_config->min_core_set_clock;
3098 minimum_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
3100 if (PP_CAP(PHM_PlatformCaps_StablePState)) {
3101 stable_pstate_sclk_dpm_percentage =
3102 data->registry_data.stable_pstate_sclk_dpm_percentage;
3103 PP_ASSERT_WITH_CODE(
3104 data->registry_data.stable_pstate_sclk_dpm_percentage >= 1 &&
3105 data->registry_data.stable_pstate_sclk_dpm_percentage <= 100,
3106 "percent sclk value must range from 1% to 100%, setting default value",
3107 stable_pstate_sclk_dpm_percentage = 75);
3109 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3110 stable_pstate_sclk = (max_limits->sclk *
3111 stable_pstate_sclk_dpm_percentage) / 100;
3113 for (count = table_info->vdd_dep_on_sclk->count - 1;
3114 count >= 0; count--) {
3115 if (stable_pstate_sclk >=
3116 table_info->vdd_dep_on_sclk->entries[count].clk) {
3117 stable_pstate_sclk =
3118 table_info->vdd_dep_on_sclk->entries[count].clk;
3124 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3126 stable_pstate_mclk = max_limits->mclk;
3128 minimum_clocks.engineClock = stable_pstate_sclk;
3129 minimum_clocks.memoryClock = stable_pstate_mclk;
3132 disable_mclk_switching_for_frame_lock =
3133 PP_CAP(PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3134 disable_mclk_switching_for_vr =
3135 PP_CAP(PHM_PlatformCaps_DisableMclkSwitchForVR);
3136 force_mclk_high = PP_CAP(PHM_PlatformCaps_ForceMclkHigh);
3138 if (hwmgr->display_config->num_display == 0)
3139 disable_mclk_switching = false;
3141 disable_mclk_switching = (hwmgr->display_config->num_display > 1) ||
3142 disable_mclk_switching_for_frame_lock ||
3143 disable_mclk_switching_for_vr ||
3146 sclk = vega10_ps->performance_levels[0].gfx_clock;
3147 mclk = vega10_ps->performance_levels[0].mem_clock;
3149 if (sclk < minimum_clocks.engineClock)
3150 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3151 max_limits->sclk : minimum_clocks.engineClock;
3153 if (mclk < minimum_clocks.memoryClock)
3154 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3155 max_limits->mclk : minimum_clocks.memoryClock;
3157 vega10_ps->performance_levels[0].gfx_clock = sclk;
3158 vega10_ps->performance_levels[0].mem_clock = mclk;
3160 if (vega10_ps->performance_levels[1].gfx_clock <
3161 vega10_ps->performance_levels[0].gfx_clock)
3162 vega10_ps->performance_levels[0].gfx_clock =
3163 vega10_ps->performance_levels[1].gfx_clock;
3165 if (disable_mclk_switching) {
3166 /* Set Mclk the max of level 0 and level 1 */
3167 if (mclk < vega10_ps->performance_levels[1].mem_clock)
3168 mclk = vega10_ps->performance_levels[1].mem_clock;
3170 /* Find the lowest MCLK frequency that is within
3171 * the tolerable latency defined in DAL
3174 for (i = 0; i < data->mclk_latency_table.count; i++) {
3175 if ((data->mclk_latency_table.entries[i].latency <= latency) &&
3176 (data->mclk_latency_table.entries[i].frequency >=
3177 vega10_ps->performance_levels[0].mem_clock) &&
3178 (data->mclk_latency_table.entries[i].frequency <=
3179 vega10_ps->performance_levels[1].mem_clock))
3180 mclk = data->mclk_latency_table.entries[i].frequency;
3182 vega10_ps->performance_levels[0].mem_clock = mclk;
3184 if (vega10_ps->performance_levels[1].mem_clock <
3185 vega10_ps->performance_levels[0].mem_clock)
3186 vega10_ps->performance_levels[0].mem_clock =
3187 vega10_ps->performance_levels[1].mem_clock;
3190 if (PP_CAP(PHM_PlatformCaps_StablePState)) {
3191 for (i = 0; i < vega10_ps->performance_level_count; i++) {
3192 vega10_ps->performance_levels[i].gfx_clock = stable_pstate_sclk;
3193 vega10_ps->performance_levels[i].mem_clock = stable_pstate_mclk;
3200 static int vega10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
3202 struct vega10_hwmgr *data = hwmgr->backend;
3204 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
3205 data->need_update_dpm_table |= DPMTABLE_UPDATE_MCLK;
3210 static int vega10_populate_and_upload_sclk_mclk_dpm_levels(
3211 struct pp_hwmgr *hwmgr, const void *input)
3214 struct vega10_hwmgr *data = hwmgr->backend;
3216 if (!data->need_update_dpm_table)
3219 if (data->need_update_dpm_table &
3220 (DPMTABLE_OD_UPDATE_SCLK + DPMTABLE_UPDATE_SCLK + DPMTABLE_UPDATE_SOCCLK)) {
3221 result = vega10_populate_all_graphic_levels(hwmgr);
3222 PP_ASSERT_WITH_CODE((0 == result),
3223 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
3227 if (data->need_update_dpm_table &
3228 (DPMTABLE_OD_UPDATE_MCLK + DPMTABLE_UPDATE_MCLK)) {
3229 result = vega10_populate_all_memory_levels(hwmgr);
3230 PP_ASSERT_WITH_CODE((0 == result),
3231 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
3235 vega10_populate_vddc_soc_levels(hwmgr);
3240 static int vega10_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
3241 struct vega10_single_dpm_table *dpm_table,
3242 uint32_t low_limit, uint32_t high_limit)
3246 for (i = 0; i < dpm_table->count; i++) {
3247 if ((dpm_table->dpm_levels[i].value < low_limit) ||
3248 (dpm_table->dpm_levels[i].value > high_limit))
3249 dpm_table->dpm_levels[i].enabled = false;
3251 dpm_table->dpm_levels[i].enabled = true;
3256 static int vega10_trim_single_dpm_states_with_mask(struct pp_hwmgr *hwmgr,
3257 struct vega10_single_dpm_table *dpm_table,
3258 uint32_t low_limit, uint32_t high_limit,
3259 uint32_t disable_dpm_mask)
3263 for (i = 0; i < dpm_table->count; i++) {
3264 if ((dpm_table->dpm_levels[i].value < low_limit) ||
3265 (dpm_table->dpm_levels[i].value > high_limit))
3266 dpm_table->dpm_levels[i].enabled = false;
3267 else if (!((1 << i) & disable_dpm_mask))
3268 dpm_table->dpm_levels[i].enabled = false;
3270 dpm_table->dpm_levels[i].enabled = true;
3275 static int vega10_trim_dpm_states(struct pp_hwmgr *hwmgr,
3276 const struct vega10_power_state *vega10_ps)
3278 struct vega10_hwmgr *data = hwmgr->backend;
3279 uint32_t high_limit_count;
3281 PP_ASSERT_WITH_CODE((vega10_ps->performance_level_count >= 1),
3282 "power state did not have any performance level",
3285 high_limit_count = (vega10_ps->performance_level_count == 1) ? 0 : 1;
3287 vega10_trim_single_dpm_states(hwmgr,
3288 &(data->dpm_table.soc_table),
3289 vega10_ps->performance_levels[0].soc_clock,
3290 vega10_ps->performance_levels[high_limit_count].soc_clock);
3292 vega10_trim_single_dpm_states_with_mask(hwmgr,
3293 &(data->dpm_table.gfx_table),
3294 vega10_ps->performance_levels[0].gfx_clock,
3295 vega10_ps->performance_levels[high_limit_count].gfx_clock,
3296 data->disable_dpm_mask);
3298 vega10_trim_single_dpm_states(hwmgr,
3299 &(data->dpm_table.mem_table),
3300 vega10_ps->performance_levels[0].mem_clock,
3301 vega10_ps->performance_levels[high_limit_count].mem_clock);
3306 static uint32_t vega10_find_lowest_dpm_level(
3307 struct vega10_single_dpm_table *table)
3311 for (i = 0; i < table->count; i++) {
3312 if (table->dpm_levels[i].enabled)
3319 static uint32_t vega10_find_highest_dpm_level(
3320 struct vega10_single_dpm_table *table)
3324 if (table->count <= MAX_REGULAR_DPM_NUMBER) {
3325 for (i = table->count; i > 0; i--) {
3326 if (table->dpm_levels[i - 1].enabled)
3330 pr_info("DPM Table Has Too Many Entries!");
3331 return MAX_REGULAR_DPM_NUMBER - 1;
3337 static void vega10_apply_dal_minimum_voltage_request(
3338 struct pp_hwmgr *hwmgr)
3343 static int vega10_get_soc_index_for_max_uclk(struct pp_hwmgr *hwmgr)
3345 struct phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_table_on_mclk;
3346 struct phm_ppt_v2_information *table_info =
3347 (struct phm_ppt_v2_information *)(hwmgr->pptable);
3349 vdd_dep_table_on_mclk = table_info->vdd_dep_on_mclk;
3351 return vdd_dep_table_on_mclk->entries[NUM_UCLK_DPM_LEVELS - 1].vddInd + 1;
3354 static int vega10_upload_dpm_bootup_level(struct pp_hwmgr *hwmgr)
3356 struct vega10_hwmgr *data = hwmgr->backend;
3357 uint32_t socclk_idx;
3359 vega10_apply_dal_minimum_voltage_request(hwmgr);
3361 if (!data->registry_data.sclk_dpm_key_disabled) {
3362 if (data->smc_state_table.gfx_boot_level !=
3363 data->dpm_table.gfx_table.dpm_state.soft_min_level) {
3364 smum_send_msg_to_smc_with_parameter(hwmgr,
3365 PPSMC_MSG_SetSoftMinGfxclkByIndex,
3366 data->smc_state_table.gfx_boot_level);
3367 data->dpm_table.gfx_table.dpm_state.soft_min_level =
3368 data->smc_state_table.gfx_boot_level;
3372 if (!data->registry_data.mclk_dpm_key_disabled) {
3373 if (data->smc_state_table.mem_boot_level !=
3374 data->dpm_table.mem_table.dpm_state.soft_min_level) {
3375 if (data->smc_state_table.mem_boot_level == NUM_UCLK_DPM_LEVELS - 1) {
3376 socclk_idx = vega10_get_soc_index_for_max_uclk(hwmgr);
3377 smum_send_msg_to_smc_with_parameter(hwmgr,
3378 PPSMC_MSG_SetSoftMinSocclkByIndex,
3381 smum_send_msg_to_smc_with_parameter(hwmgr,
3382 PPSMC_MSG_SetSoftMinUclkByIndex,
3383 data->smc_state_table.mem_boot_level);
3385 data->dpm_table.mem_table.dpm_state.soft_min_level =
3386 data->smc_state_table.mem_boot_level;
3393 static int vega10_upload_dpm_max_level(struct pp_hwmgr *hwmgr)
3395 struct vega10_hwmgr *data = hwmgr->backend;
3397 vega10_apply_dal_minimum_voltage_request(hwmgr);
3399 if (!data->registry_data.sclk_dpm_key_disabled) {
3400 if (data->smc_state_table.gfx_max_level !=
3401 data->dpm_table.gfx_table.dpm_state.soft_max_level) {
3402 smum_send_msg_to_smc_with_parameter(hwmgr,
3403 PPSMC_MSG_SetSoftMaxGfxclkByIndex,
3404 data->smc_state_table.gfx_max_level);
3405 data->dpm_table.gfx_table.dpm_state.soft_max_level =
3406 data->smc_state_table.gfx_max_level;
3410 if (!data->registry_data.mclk_dpm_key_disabled) {
3411 if (data->smc_state_table.mem_max_level !=
3412 data->dpm_table.mem_table.dpm_state.soft_max_level) {
3413 smum_send_msg_to_smc_with_parameter(hwmgr,
3414 PPSMC_MSG_SetSoftMaxUclkByIndex,
3415 data->smc_state_table.mem_max_level);
3416 data->dpm_table.mem_table.dpm_state.soft_max_level =
3417 data->smc_state_table.mem_max_level;
3424 static int vega10_generate_dpm_level_enable_mask(
3425 struct pp_hwmgr *hwmgr, const void *input)
3427 struct vega10_hwmgr *data = hwmgr->backend;
3428 const struct phm_set_power_state_input *states =
3429 (const struct phm_set_power_state_input *)input;
3430 const struct vega10_power_state *vega10_ps =
3431 cast_const_phw_vega10_power_state(states->pnew_state);
3434 PP_ASSERT_WITH_CODE(!vega10_trim_dpm_states(hwmgr, vega10_ps),
3435 "Attempt to Trim DPM States Failed!",
3438 data->smc_state_table.gfx_boot_level =
3439 vega10_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
3440 data->smc_state_table.gfx_max_level =
3441 vega10_find_highest_dpm_level(&(data->dpm_table.gfx_table));
3442 data->smc_state_table.mem_boot_level =
3443 vega10_find_lowest_dpm_level(&(data->dpm_table.mem_table));
3444 data->smc_state_table.mem_max_level =
3445 vega10_find_highest_dpm_level(&(data->dpm_table.mem_table));
3447 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3448 "Attempt to upload DPM Bootup Levels Failed!",
3450 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3451 "Attempt to upload DPM Max Levels Failed!",
3453 for(i = data->smc_state_table.gfx_boot_level; i < data->smc_state_table.gfx_max_level; i++)
3454 data->dpm_table.gfx_table.dpm_levels[i].enabled = true;
3457 for(i = data->smc_state_table.mem_boot_level; i < data->smc_state_table.mem_max_level; i++)
3458 data->dpm_table.mem_table.dpm_levels[i].enabled = true;
3463 int vega10_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
3465 struct vega10_hwmgr *data = hwmgr->backend;
3467 if (data->smu_features[GNLD_DPM_VCE].supported) {
3468 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
3470 data->smu_features[GNLD_DPM_VCE].smu_feature_bitmap),
3471 "Attempt to Enable/Disable DPM VCE Failed!",
3473 data->smu_features[GNLD_DPM_VCE].enabled = enable;
3479 static int vega10_update_sclk_threshold(struct pp_hwmgr *hwmgr)
3481 struct vega10_hwmgr *data = hwmgr->backend;
3482 uint32_t low_sclk_interrupt_threshold = 0;
3484 if (PP_CAP(PHM_PlatformCaps_SclkThrottleLowNotification) &&
3485 (data->low_sclk_interrupt_threshold != 0)) {
3486 low_sclk_interrupt_threshold =
3487 data->low_sclk_interrupt_threshold;
3489 data->smc_state_table.pp_table.LowGfxclkInterruptThreshold =
3490 cpu_to_le32(low_sclk_interrupt_threshold);
3492 /* This message will also enable SmcToHost Interrupt */
3493 smum_send_msg_to_smc_with_parameter(hwmgr,
3494 PPSMC_MSG_SetLowGfxclkInterruptThreshold,
3495 (uint32_t)low_sclk_interrupt_threshold);
3501 static int vega10_set_power_state_tasks(struct pp_hwmgr *hwmgr,
3504 int tmp_result, result = 0;
3505 struct vega10_hwmgr *data = hwmgr->backend;
3506 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
3508 tmp_result = vega10_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
3509 PP_ASSERT_WITH_CODE(!tmp_result,
3510 "Failed to find DPM states clocks in DPM table!",
3511 result = tmp_result);
3513 tmp_result = vega10_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
3514 PP_ASSERT_WITH_CODE(!tmp_result,
3515 "Failed to populate and upload SCLK MCLK DPM levels!",
3516 result = tmp_result);
3518 tmp_result = vega10_generate_dpm_level_enable_mask(hwmgr, input);
3519 PP_ASSERT_WITH_CODE(!tmp_result,
3520 "Failed to generate DPM level enabled mask!",
3521 result = tmp_result);
3523 tmp_result = vega10_update_sclk_threshold(hwmgr);
3524 PP_ASSERT_WITH_CODE(!tmp_result,
3525 "Failed to update SCLK threshold!",
3526 result = tmp_result);
3528 result = smum_smc_table_manager(hwmgr, (uint8_t *)pp_table, PPTABLE, false);
3529 PP_ASSERT_WITH_CODE(!result,
3530 "Failed to upload PPtable!", return result);
3532 vega10_update_avfs(hwmgr);
3534 data->need_update_dpm_table &= DPMTABLE_OD_UPDATE_VDDC;
3539 static uint32_t vega10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3541 struct pp_power_state *ps;
3542 struct vega10_power_state *vega10_ps;
3547 ps = hwmgr->request_ps;
3552 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
3555 return vega10_ps->performance_levels[0].gfx_clock;
3557 return vega10_ps->performance_levels
3558 [vega10_ps->performance_level_count - 1].gfx_clock;
3561 static uint32_t vega10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3563 struct pp_power_state *ps;
3564 struct vega10_power_state *vega10_ps;
3569 ps = hwmgr->request_ps;
3574 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
3577 return vega10_ps->performance_levels[0].mem_clock;
3579 return vega10_ps->performance_levels
3580 [vega10_ps->performance_level_count-1].mem_clock;
3583 static int vega10_get_gpu_power(struct pp_hwmgr *hwmgr,
3591 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrPkgPwr);
3592 value = smum_get_argument(hwmgr);
3594 /* SMC returning actual watts, keep consistent with legacy asics, low 8 bit as 8 fractional bits */
3595 *query = value << 8;
3600 static int vega10_read_sensor(struct pp_hwmgr *hwmgr, int idx,
3601 void *value, int *size)
3603 struct amdgpu_device *adev = hwmgr->adev;
3604 uint32_t sclk_mhz, mclk_idx, activity_percent = 0;
3605 struct vega10_hwmgr *data = hwmgr->backend;
3606 struct vega10_dpm_table *dpm_table = &data->dpm_table;
3611 case AMDGPU_PP_SENSOR_GFX_SCLK:
3612 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetAverageGfxclkActualFrequency);
3613 sclk_mhz = smum_get_argument(hwmgr);
3614 *((uint32_t *)value) = sclk_mhz * 100;
3616 case AMDGPU_PP_SENSOR_GFX_MCLK:
3617 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentUclkIndex);
3618 mclk_idx = smum_get_argument(hwmgr);
3619 if (mclk_idx < dpm_table->mem_table.count) {
3620 *((uint32_t *)value) = dpm_table->mem_table.dpm_levels[mclk_idx].value;
3626 case AMDGPU_PP_SENSOR_GPU_LOAD:
3627 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetAverageGfxActivity, 0);
3628 activity_percent = smum_get_argument(hwmgr);
3629 *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
3632 case AMDGPU_PP_SENSOR_GPU_TEMP:
3633 *((uint32_t *)value) = vega10_thermal_get_temperature(hwmgr);
3636 case AMDGPU_PP_SENSOR_UVD_POWER:
3637 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
3640 case AMDGPU_PP_SENSOR_VCE_POWER:
3641 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
3644 case AMDGPU_PP_SENSOR_GPU_POWER:
3645 ret = vega10_get_gpu_power(hwmgr, (uint32_t *)value);
3647 case AMDGPU_PP_SENSOR_VDDGFX:
3648 val_vid = (RREG32_SOC15(SMUIO, 0, mmSMUSVI0_PLANE0_CURRENTVID) &
3649 SMUSVI0_PLANE0_CURRENTVID__CURRENT_SVI0_PLANE0_VID_MASK) >>
3650 SMUSVI0_PLANE0_CURRENTVID__CURRENT_SVI0_PLANE0_VID__SHIFT;
3651 *((uint32_t *)value) = (uint32_t)convert_to_vddc((uint8_t)val_vid);
3661 static void vega10_notify_smc_display_change(struct pp_hwmgr *hwmgr,
3664 smum_send_msg_to_smc_with_parameter(hwmgr,
3665 PPSMC_MSG_SetUclkFastSwitch,
3669 int vega10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
3670 struct pp_display_clock_request *clock_req)
3673 enum amd_pp_clock_type clk_type = clock_req->clock_type;
3674 uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
3675 DSPCLK_e clk_select = 0;
3676 uint32_t clk_request = 0;
3679 case amd_pp_dcef_clock:
3680 clk_select = DSPCLK_DCEFCLK;
3682 case amd_pp_disp_clock:
3683 clk_select = DSPCLK_DISPCLK;
3685 case amd_pp_pixel_clock:
3686 clk_select = DSPCLK_PIXCLK;
3688 case amd_pp_phy_clock:
3689 clk_select = DSPCLK_PHYCLK;
3692 pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
3698 clk_request = (clk_freq << 16) | clk_select;
3699 smum_send_msg_to_smc_with_parameter(hwmgr,
3700 PPSMC_MSG_RequestDisplayClockByFreq,
3707 static uint8_t vega10_get_uclk_index(struct pp_hwmgr *hwmgr,
3708 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table,
3714 if (mclk_table == NULL || mclk_table->count == 0)
3717 count = (uint8_t)(mclk_table->count);
3719 for(i = 0; i < count; i++) {
3720 if(mclk_table->entries[i].clk >= frequency)
3727 static int vega10_notify_smc_display_config_after_ps_adjustment(
3728 struct pp_hwmgr *hwmgr)
3730 struct vega10_hwmgr *data = hwmgr->backend;
3731 struct vega10_single_dpm_table *dpm_table =
3732 &data->dpm_table.dcef_table;
3733 struct phm_ppt_v2_information *table_info =
3734 (struct phm_ppt_v2_information *)hwmgr->pptable;
3735 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table = table_info->vdd_dep_on_mclk;
3737 struct PP_Clocks min_clocks = {0};
3739 struct pp_display_clock_request clock_req;
3741 if (hwmgr->display_config->num_display > 1)
3742 vega10_notify_smc_display_change(hwmgr, false);
3744 vega10_notify_smc_display_change(hwmgr, true);
3746 min_clocks.dcefClock = hwmgr->display_config->min_dcef_set_clk;
3747 min_clocks.dcefClockInSR = hwmgr->display_config->min_dcef_deep_sleep_set_clk;
3748 min_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
3750 for (i = 0; i < dpm_table->count; i++) {
3751 if (dpm_table->dpm_levels[i].value == min_clocks.dcefClock)
3755 if (i < dpm_table->count) {
3756 clock_req.clock_type = amd_pp_dcef_clock;
3757 clock_req.clock_freq_in_khz = dpm_table->dpm_levels[i].value;
3758 if (!vega10_display_clock_voltage_request(hwmgr, &clock_req)) {
3759 smum_send_msg_to_smc_with_parameter(
3760 hwmgr, PPSMC_MSG_SetMinDeepSleepDcefclk,
3761 min_clocks.dcefClockInSR / 100);
3763 pr_info("Attempt to set Hard Min for DCEFCLK Failed!");
3766 pr_debug("Cannot find requested DCEFCLK!");
3769 if (min_clocks.memoryClock != 0) {
3770 idx = vega10_get_uclk_index(hwmgr, mclk_table, min_clocks.memoryClock);
3771 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetSoftMinUclkByIndex, idx);
3772 data->dpm_table.mem_table.dpm_state.soft_min_level= idx;
3778 static int vega10_force_dpm_highest(struct pp_hwmgr *hwmgr)
3780 struct vega10_hwmgr *data = hwmgr->backend;
3782 data->smc_state_table.gfx_boot_level =
3783 data->smc_state_table.gfx_max_level =
3784 vega10_find_highest_dpm_level(&(data->dpm_table.gfx_table));
3785 data->smc_state_table.mem_boot_level =
3786 data->smc_state_table.mem_max_level =
3787 vega10_find_highest_dpm_level(&(data->dpm_table.mem_table));
3789 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3790 "Failed to upload boot level to highest!",
3793 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3794 "Failed to upload dpm max level to highest!",
3800 static int vega10_force_dpm_lowest(struct pp_hwmgr *hwmgr)
3802 struct vega10_hwmgr *data = hwmgr->backend;
3804 data->smc_state_table.gfx_boot_level =
3805 data->smc_state_table.gfx_max_level =
3806 vega10_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
3807 data->smc_state_table.mem_boot_level =
3808 data->smc_state_table.mem_max_level =
3809 vega10_find_lowest_dpm_level(&(data->dpm_table.mem_table));
3811 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3812 "Failed to upload boot level to highest!",
3815 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3816 "Failed to upload dpm max level to highest!",
3823 static int vega10_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
3825 struct vega10_hwmgr *data = hwmgr->backend;
3827 data->smc_state_table.gfx_boot_level =
3828 vega10_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
3829 data->smc_state_table.gfx_max_level =
3830 vega10_find_highest_dpm_level(&(data->dpm_table.gfx_table));
3831 data->smc_state_table.mem_boot_level =
3832 vega10_find_lowest_dpm_level(&(data->dpm_table.mem_table));
3833 data->smc_state_table.mem_max_level =
3834 vega10_find_highest_dpm_level(&(data->dpm_table.mem_table));
3836 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3837 "Failed to upload DPM Bootup Levels!",
3840 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3841 "Failed to upload DPM Max Levels!",
3846 static int vega10_get_profiling_clk_mask(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
3847 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *soc_mask)
3849 struct phm_ppt_v2_information *table_info =
3850 (struct phm_ppt_v2_information *)(hwmgr->pptable);
3852 if (table_info->vdd_dep_on_sclk->count > VEGA10_UMD_PSTATE_GFXCLK_LEVEL &&
3853 table_info->vdd_dep_on_socclk->count > VEGA10_UMD_PSTATE_SOCCLK_LEVEL &&
3854 table_info->vdd_dep_on_mclk->count > VEGA10_UMD_PSTATE_MCLK_LEVEL) {
3855 *sclk_mask = VEGA10_UMD_PSTATE_GFXCLK_LEVEL;
3856 *soc_mask = VEGA10_UMD_PSTATE_SOCCLK_LEVEL;
3857 *mclk_mask = VEGA10_UMD_PSTATE_MCLK_LEVEL;
3858 hwmgr->pstate_sclk = table_info->vdd_dep_on_sclk->entries[VEGA10_UMD_PSTATE_GFXCLK_LEVEL].clk;
3859 hwmgr->pstate_mclk = table_info->vdd_dep_on_mclk->entries[VEGA10_UMD_PSTATE_MCLK_LEVEL].clk;
3862 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
3864 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
3866 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
3867 *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
3868 *soc_mask = table_info->vdd_dep_on_socclk->count - 1;
3869 *mclk_mask = table_info->vdd_dep_on_mclk->count - 1;
3874 static void vega10_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
3877 case AMD_FAN_CTRL_NONE:
3878 vega10_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
3880 case AMD_FAN_CTRL_MANUAL:
3881 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
3882 vega10_fan_ctrl_stop_smc_fan_control(hwmgr);
3884 case AMD_FAN_CTRL_AUTO:
3885 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
3886 vega10_fan_ctrl_start_smc_fan_control(hwmgr);
3893 static int vega10_force_clock_level(struct pp_hwmgr *hwmgr,
3894 enum pp_clock_type type, uint32_t mask)
3896 struct vega10_hwmgr *data = hwmgr->backend;
3900 data->smc_state_table.gfx_boot_level = mask ? (ffs(mask) - 1) : 0;
3901 data->smc_state_table.gfx_max_level = mask ? (fls(mask) - 1) : 0;
3903 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3904 "Failed to upload boot level to lowest!",
3907 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3908 "Failed to upload dpm max level to highest!",
3913 data->smc_state_table.mem_boot_level = mask ? (ffs(mask) - 1) : 0;
3914 data->smc_state_table.mem_max_level = mask ? (fls(mask) - 1) : 0;
3916 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3917 "Failed to upload boot level to lowest!",
3920 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3921 "Failed to upload dpm max level to highest!",
3934 static int vega10_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
3935 enum amd_dpm_forced_level level)
3938 uint32_t sclk_mask = 0;
3939 uint32_t mclk_mask = 0;
3940 uint32_t soc_mask = 0;
3942 if (hwmgr->pstate_sclk == 0)
3943 vega10_get_profiling_clk_mask(hwmgr, level, &sclk_mask, &mclk_mask, &soc_mask);
3946 case AMD_DPM_FORCED_LEVEL_HIGH:
3947 ret = vega10_force_dpm_highest(hwmgr);
3949 case AMD_DPM_FORCED_LEVEL_LOW:
3950 ret = vega10_force_dpm_lowest(hwmgr);
3952 case AMD_DPM_FORCED_LEVEL_AUTO:
3953 ret = vega10_unforce_dpm_levels(hwmgr);
3955 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
3956 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
3957 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
3958 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
3959 ret = vega10_get_profiling_clk_mask(hwmgr, level, &sclk_mask, &mclk_mask, &soc_mask);
3962 vega10_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
3963 vega10_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
3965 case AMD_DPM_FORCED_LEVEL_MANUAL:
3966 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
3972 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3973 vega10_set_fan_control_mode(hwmgr, AMD_FAN_CTRL_NONE);
3974 else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
3975 vega10_set_fan_control_mode(hwmgr, AMD_FAN_CTRL_AUTO);
3981 static uint32_t vega10_get_fan_control_mode(struct pp_hwmgr *hwmgr)
3983 struct vega10_hwmgr *data = hwmgr->backend;
3985 if (data->smu_features[GNLD_FAN_CONTROL].enabled == false)
3986 return AMD_FAN_CTRL_MANUAL;
3988 return AMD_FAN_CTRL_AUTO;
3991 static int vega10_get_dal_power_level(struct pp_hwmgr *hwmgr,
3992 struct amd_pp_simple_clock_info *info)
3994 struct phm_ppt_v2_information *table_info =
3995 (struct phm_ppt_v2_information *)hwmgr->pptable;
3996 struct phm_clock_and_voltage_limits *max_limits =
3997 &table_info->max_clock_voltage_on_ac;
3999 info->engine_max_clock = max_limits->sclk;
4000 info->memory_max_clock = max_limits->mclk;
4005 static void vega10_get_sclks(struct pp_hwmgr *hwmgr,
4006 struct pp_clock_levels_with_latency *clocks)
4008 struct phm_ppt_v2_information *table_info =
4009 (struct phm_ppt_v2_information *)hwmgr->pptable;
4010 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4011 table_info->vdd_dep_on_sclk;
4014 for (i = 0; i < dep_table->count; i++) {
4015 if (dep_table->entries[i].clk) {
4016 clocks->data[clocks->num_levels].clocks_in_khz =
4017 dep_table->entries[i].clk;
4018 clocks->num_levels++;
4024 static uint32_t vega10_get_mem_latency(struct pp_hwmgr *hwmgr,
4027 if (clock >= MEM_FREQ_LOW_LATENCY &&
4028 clock < MEM_FREQ_HIGH_LATENCY)
4029 return MEM_LATENCY_HIGH;
4030 else if (clock >= MEM_FREQ_HIGH_LATENCY)
4031 return MEM_LATENCY_LOW;
4033 return MEM_LATENCY_ERR;
4036 static void vega10_get_memclocks(struct pp_hwmgr *hwmgr,
4037 struct pp_clock_levels_with_latency *clocks)
4039 struct phm_ppt_v2_information *table_info =
4040 (struct phm_ppt_v2_information *)hwmgr->pptable;
4041 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4042 table_info->vdd_dep_on_mclk;
4043 struct vega10_hwmgr *data = hwmgr->backend;
4046 clocks->num_levels = 0;
4047 data->mclk_latency_table.count = 0;
4049 for (i = 0; i < dep_table->count; i++) {
4050 if (dep_table->entries[i].clk) {
4051 clocks->data[clocks->num_levels].clocks_in_khz =
4052 data->mclk_latency_table.entries
4053 [data->mclk_latency_table.count].frequency =
4054 dep_table->entries[i].clk;
4055 clocks->data[clocks->num_levels].latency_in_us =
4056 data->mclk_latency_table.entries
4057 [data->mclk_latency_table.count].latency =
4058 vega10_get_mem_latency(hwmgr,
4059 dep_table->entries[i].clk);
4060 clocks->num_levels++;
4061 data->mclk_latency_table.count++;
4066 static void vega10_get_dcefclocks(struct pp_hwmgr *hwmgr,
4067 struct pp_clock_levels_with_latency *clocks)
4069 struct phm_ppt_v2_information *table_info =
4070 (struct phm_ppt_v2_information *)hwmgr->pptable;
4071 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4072 table_info->vdd_dep_on_dcefclk;
4075 for (i = 0; i < dep_table->count; i++) {
4076 clocks->data[i].clocks_in_khz = dep_table->entries[i].clk;
4077 clocks->data[i].latency_in_us = 0;
4078 clocks->num_levels++;
4082 static void vega10_get_socclocks(struct pp_hwmgr *hwmgr,
4083 struct pp_clock_levels_with_latency *clocks)
4085 struct phm_ppt_v2_information *table_info =
4086 (struct phm_ppt_v2_information *)hwmgr->pptable;
4087 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4088 table_info->vdd_dep_on_socclk;
4091 for (i = 0; i < dep_table->count; i++) {
4092 clocks->data[i].clocks_in_khz = dep_table->entries[i].clk;
4093 clocks->data[i].latency_in_us = 0;
4094 clocks->num_levels++;
4098 static int vega10_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
4099 enum amd_pp_clock_type type,
4100 struct pp_clock_levels_with_latency *clocks)
4103 case amd_pp_sys_clock:
4104 vega10_get_sclks(hwmgr, clocks);
4106 case amd_pp_mem_clock:
4107 vega10_get_memclocks(hwmgr, clocks);
4109 case amd_pp_dcef_clock:
4110 vega10_get_dcefclocks(hwmgr, clocks);
4112 case amd_pp_soc_clock:
4113 vega10_get_socclocks(hwmgr, clocks);
4122 static int vega10_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
4123 enum amd_pp_clock_type type,
4124 struct pp_clock_levels_with_voltage *clocks)
4126 struct phm_ppt_v2_information *table_info =
4127 (struct phm_ppt_v2_information *)hwmgr->pptable;
4128 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
4132 case amd_pp_mem_clock:
4133 dep_table = table_info->vdd_dep_on_mclk;
4135 case amd_pp_dcef_clock:
4136 dep_table = table_info->vdd_dep_on_dcefclk;
4138 case amd_pp_disp_clock:
4139 dep_table = table_info->vdd_dep_on_dispclk;
4141 case amd_pp_pixel_clock:
4142 dep_table = table_info->vdd_dep_on_pixclk;
4144 case amd_pp_phy_clock:
4145 dep_table = table_info->vdd_dep_on_phyclk;
4151 for (i = 0; i < dep_table->count; i++) {
4152 clocks->data[i].clocks_in_khz = dep_table->entries[i].clk;
4153 clocks->data[i].voltage_in_mv = (uint32_t)(table_info->vddc_lookup_table->
4154 entries[dep_table->entries[i].vddInd].us_vdd);
4155 clocks->num_levels++;
4158 if (i < dep_table->count)
4164 static int vega10_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
4165 struct pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges)
4167 struct vega10_hwmgr *data = hwmgr->backend;
4168 Watermarks_t *table = &(data->smc_state_table.water_marks_table);
4171 if (!data->registry_data.disable_water_mark) {
4172 smu_set_watermarks_for_clocks_ranges(table, wm_with_clock_ranges);
4173 data->water_marks_bitmap = WaterMarksExist;
4179 static int vega10_print_clock_levels(struct pp_hwmgr *hwmgr,
4180 enum pp_clock_type type, char *buf)
4182 struct vega10_hwmgr *data = hwmgr->backend;
4183 struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table);
4184 struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table);
4185 struct vega10_pcie_table *pcie_table = &(data->dpm_table.pcie_table);
4186 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep = NULL;
4188 int i, now, size = 0;
4192 if (data->registry_data.sclk_dpm_key_disabled)
4195 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentGfxclkIndex);
4196 now = smum_get_argument(hwmgr);
4198 for (i = 0; i < sclk_table->count; i++)
4199 size += sprintf(buf + size, "%d: %uMhz %s\n",
4200 i, sclk_table->dpm_levels[i].value / 100,
4201 (i == now) ? "*" : "");
4204 if (data->registry_data.mclk_dpm_key_disabled)
4207 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentUclkIndex);
4208 now = smum_get_argument(hwmgr);
4210 for (i = 0; i < mclk_table->count; i++)
4211 size += sprintf(buf + size, "%d: %uMhz %s\n",
4212 i, mclk_table->dpm_levels[i].value / 100,
4213 (i == now) ? "*" : "");
4216 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentLinkIndex);
4217 now = smum_get_argument(hwmgr);
4219 for (i = 0; i < pcie_table->count; i++)
4220 size += sprintf(buf + size, "%d: %s %s\n", i,
4221 (pcie_table->pcie_gen[i] == 0) ? "2.5GT/s, x1" :
4222 (pcie_table->pcie_gen[i] == 1) ? "5.0GT/s, x16" :
4223 (pcie_table->pcie_gen[i] == 2) ? "8.0GT/s, x16" : "",
4224 (i == now) ? "*" : "");
4227 if (hwmgr->od_enabled) {
4228 size = sprintf(buf, "%s:\n", "OD_SCLK");
4229 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_sclk;
4230 for (i = 0; i < podn_vdd_dep->count; i++)
4231 size += sprintf(buf + size, "%d: %10uMhz %10umV\n",
4232 i, podn_vdd_dep->entries[i].clk / 100,
4233 podn_vdd_dep->entries[i].vddc);
4237 if (hwmgr->od_enabled) {
4238 size = sprintf(buf, "%s:\n", "OD_MCLK");
4239 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_mclk;
4240 for (i = 0; i < podn_vdd_dep->count; i++)
4241 size += sprintf(buf + size, "%d: %10uMhz %10umV\n",
4242 i, podn_vdd_dep->entries[i].clk/100,
4243 podn_vdd_dep->entries[i].vddc);
4247 if (hwmgr->od_enabled) {
4248 size = sprintf(buf, "%s:\n", "OD_RANGE");
4249 size += sprintf(buf + size, "SCLK: %7uMHz %10uMHz\n",
4250 data->golden_dpm_table.gfx_table.dpm_levels[0].value/100,
4251 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
4252 size += sprintf(buf + size, "MCLK: %7uMHz %10uMHz\n",
4253 data->golden_dpm_table.mem_table.dpm_levels[0].value/100,
4254 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
4255 size += sprintf(buf + size, "VDDC: %7umV %11umV\n",
4256 data->odn_dpm_table.min_vddc,
4257 data->odn_dpm_table.max_vddc);
4266 static int vega10_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4268 struct vega10_hwmgr *data = hwmgr->backend;
4269 Watermarks_t *wm_table = &(data->smc_state_table.water_marks_table);
4272 if ((data->water_marks_bitmap & WaterMarksExist) &&
4273 !(data->water_marks_bitmap & WaterMarksLoaded)) {
4274 result = smum_smc_table_manager(hwmgr, (uint8_t *)wm_table, WMTABLE, false);
4275 PP_ASSERT_WITH_CODE(result, "Failed to update WMTABLE!", return EINVAL);
4276 data->water_marks_bitmap |= WaterMarksLoaded;
4279 if (data->water_marks_bitmap & WaterMarksLoaded) {
4280 smum_send_msg_to_smc_with_parameter(hwmgr,
4281 PPSMC_MSG_NumOfDisplays, hwmgr->display_config->num_display);
4287 int vega10_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
4289 struct vega10_hwmgr *data = hwmgr->backend;
4291 if (data->smu_features[GNLD_DPM_UVD].supported) {
4292 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
4294 data->smu_features[GNLD_DPM_UVD].smu_feature_bitmap),
4295 "Attempt to Enable/Disable DPM UVD Failed!",
4297 data->smu_features[GNLD_DPM_UVD].enabled = enable;
4302 static void vega10_power_gate_vce(struct pp_hwmgr *hwmgr, bool bgate)
4304 struct vega10_hwmgr *data = hwmgr->backend;
4306 data->vce_power_gated = bgate;
4307 vega10_enable_disable_vce_dpm(hwmgr, !bgate);
4310 static void vega10_power_gate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
4312 struct vega10_hwmgr *data = hwmgr->backend;
4314 data->uvd_power_gated = bgate;
4315 vega10_enable_disable_uvd_dpm(hwmgr, !bgate);
4318 static inline bool vega10_are_power_levels_equal(
4319 const struct vega10_performance_level *pl1,
4320 const struct vega10_performance_level *pl2)
4322 return ((pl1->soc_clock == pl2->soc_clock) &&
4323 (pl1->gfx_clock == pl2->gfx_clock) &&
4324 (pl1->mem_clock == pl2->mem_clock));
4327 static int vega10_check_states_equal(struct pp_hwmgr *hwmgr,
4328 const struct pp_hw_power_state *pstate1,
4329 const struct pp_hw_power_state *pstate2, bool *equal)
4331 const struct vega10_power_state *psa;
4332 const struct vega10_power_state *psb;
4335 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4338 psa = cast_const_phw_vega10_power_state(pstate1);
4339 psb = cast_const_phw_vega10_power_state(pstate2);
4340 /* If the two states don't even have the same number of performance levels they cannot be the same state. */
4341 if (psa->performance_level_count != psb->performance_level_count) {
4346 for (i = 0; i < psa->performance_level_count; i++) {
4347 if (!vega10_are_power_levels_equal(&(psa->performance_levels[i]), &(psb->performance_levels[i]))) {
4348 /* If we have found even one performance level pair that is different the states are different. */
4354 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4355 *equal = ((psa->uvd_clks.vclk == psb->uvd_clks.vclk) && (psa->uvd_clks.dclk == psb->uvd_clks.dclk));
4356 *equal &= ((psa->vce_clks.evclk == psb->vce_clks.evclk) && (psa->vce_clks.ecclk == psb->vce_clks.ecclk));
4357 *equal &= (psa->sclk_threshold == psb->sclk_threshold);
4363 vega10_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4365 struct vega10_hwmgr *data = hwmgr->backend;
4366 bool is_update_required = false;
4368 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4369 is_update_required = true;
4371 if (PP_CAP(PHM_PlatformCaps_SclkDeepSleep)) {
4372 if (data->display_timing.min_clock_in_sr != hwmgr->display_config->min_core_set_clock_in_sr)
4373 is_update_required = true;
4376 return is_update_required;
4379 static int vega10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
4381 int tmp_result, result = 0;
4383 if (PP_CAP(PHM_PlatformCaps_ThermalController))
4384 vega10_disable_thermal_protection(hwmgr);
4386 tmp_result = vega10_disable_power_containment(hwmgr);
4387 PP_ASSERT_WITH_CODE((tmp_result == 0),
4388 "Failed to disable power containment!", result = tmp_result);
4390 tmp_result = vega10_disable_didt_config(hwmgr);
4391 PP_ASSERT_WITH_CODE((tmp_result == 0),
4392 "Failed to disable didt config!", result = tmp_result);
4394 tmp_result = vega10_avfs_enable(hwmgr, false);
4395 PP_ASSERT_WITH_CODE((tmp_result == 0),
4396 "Failed to disable AVFS!", result = tmp_result);
4398 tmp_result = vega10_stop_dpm(hwmgr, SMC_DPM_FEATURES);
4399 PP_ASSERT_WITH_CODE((tmp_result == 0),
4400 "Failed to stop DPM!", result = tmp_result);
4402 tmp_result = vega10_disable_deep_sleep_master_switch(hwmgr);
4403 PP_ASSERT_WITH_CODE((tmp_result == 0),
4404 "Failed to disable deep sleep!", result = tmp_result);
4406 tmp_result = vega10_disable_ulv(hwmgr);
4407 PP_ASSERT_WITH_CODE((tmp_result == 0),
4408 "Failed to disable ulv!", result = tmp_result);
4410 tmp_result = vega10_acg_disable(hwmgr);
4411 PP_ASSERT_WITH_CODE((tmp_result == 0),
4412 "Failed to disable acg!", result = tmp_result);
4414 vega10_enable_disable_PCC_limit_feature(hwmgr, false);
4418 static int vega10_power_off_asic(struct pp_hwmgr *hwmgr)
4420 struct vega10_hwmgr *data = hwmgr->backend;
4423 result = vega10_disable_dpm_tasks(hwmgr);
4424 PP_ASSERT_WITH_CODE((0 == result),
4425 "[disable_dpm_tasks] Failed to disable DPM!",
4427 data->water_marks_bitmap &= ~(WaterMarksLoaded);
4432 static int vega10_get_sclk_od(struct pp_hwmgr *hwmgr)
4434 struct vega10_hwmgr *data = hwmgr->backend;
4435 struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table);
4436 struct vega10_single_dpm_table *golden_sclk_table =
4437 &(data->golden_dpm_table.gfx_table);
4440 value = (sclk_table->dpm_levels[sclk_table->count - 1].value -
4441 golden_sclk_table->dpm_levels
4442 [golden_sclk_table->count - 1].value) *
4444 golden_sclk_table->dpm_levels
4445 [golden_sclk_table->count - 1].value;
4450 static int vega10_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
4452 struct vega10_hwmgr *data = hwmgr->backend;
4453 struct vega10_single_dpm_table *golden_sclk_table =
4454 &(data->golden_dpm_table.gfx_table);
4455 struct pp_power_state *ps;
4456 struct vega10_power_state *vega10_ps;
4458 ps = hwmgr->request_ps;
4463 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
4465 vega10_ps->performance_levels
4466 [vega10_ps->performance_level_count - 1].gfx_clock =
4467 golden_sclk_table->dpm_levels
4468 [golden_sclk_table->count - 1].value *
4470 golden_sclk_table->dpm_levels
4471 [golden_sclk_table->count - 1].value;
4473 if (vega10_ps->performance_levels
4474 [vega10_ps->performance_level_count - 1].gfx_clock >
4475 hwmgr->platform_descriptor.overdriveLimit.engineClock)
4476 vega10_ps->performance_levels
4477 [vega10_ps->performance_level_count - 1].gfx_clock =
4478 hwmgr->platform_descriptor.overdriveLimit.engineClock;
4483 static int vega10_get_mclk_od(struct pp_hwmgr *hwmgr)
4485 struct vega10_hwmgr *data = hwmgr->backend;
4486 struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table);
4487 struct vega10_single_dpm_table *golden_mclk_table =
4488 &(data->golden_dpm_table.mem_table);
4491 value = (mclk_table->dpm_levels
4492 [mclk_table->count - 1].value -
4493 golden_mclk_table->dpm_levels
4494 [golden_mclk_table->count - 1].value) *
4496 golden_mclk_table->dpm_levels
4497 [golden_mclk_table->count - 1].value;
4502 static int vega10_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
4504 struct vega10_hwmgr *data = hwmgr->backend;
4505 struct vega10_single_dpm_table *golden_mclk_table =
4506 &(data->golden_dpm_table.mem_table);
4507 struct pp_power_state *ps;
4508 struct vega10_power_state *vega10_ps;
4510 ps = hwmgr->request_ps;
4515 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
4517 vega10_ps->performance_levels
4518 [vega10_ps->performance_level_count - 1].mem_clock =
4519 golden_mclk_table->dpm_levels
4520 [golden_mclk_table->count - 1].value *
4522 golden_mclk_table->dpm_levels
4523 [golden_mclk_table->count - 1].value;
4525 if (vega10_ps->performance_levels
4526 [vega10_ps->performance_level_count - 1].mem_clock >
4527 hwmgr->platform_descriptor.overdriveLimit.memoryClock)
4528 vega10_ps->performance_levels
4529 [vega10_ps->performance_level_count - 1].mem_clock =
4530 hwmgr->platform_descriptor.overdriveLimit.memoryClock;
4535 static int vega10_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
4536 uint32_t virtual_addr_low,
4537 uint32_t virtual_addr_hi,
4538 uint32_t mc_addr_low,
4539 uint32_t mc_addr_hi,
4542 smum_send_msg_to_smc_with_parameter(hwmgr,
4543 PPSMC_MSG_SetSystemVirtualDramAddrHigh,
4545 smum_send_msg_to_smc_with_parameter(hwmgr,
4546 PPSMC_MSG_SetSystemVirtualDramAddrLow,
4548 smum_send_msg_to_smc_with_parameter(hwmgr,
4549 PPSMC_MSG_DramLogSetDramAddrHigh,
4552 smum_send_msg_to_smc_with_parameter(hwmgr,
4553 PPSMC_MSG_DramLogSetDramAddrLow,
4556 smum_send_msg_to_smc_with_parameter(hwmgr,
4557 PPSMC_MSG_DramLogSetDramSize,
4562 static int vega10_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
4563 struct PP_TemperatureRange *thermal_data)
4565 struct phm_ppt_v2_information *table_info =
4566 (struct phm_ppt_v2_information *)hwmgr->pptable;
4568 memcpy(thermal_data, &SMU7ThermalWithDelayPolicy[0], sizeof(struct PP_TemperatureRange));
4570 thermal_data->max = table_info->tdp_table->usSoftwareShutdownTemp *
4571 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
4576 static int vega10_get_power_profile_mode(struct pp_hwmgr *hwmgr, char *buf)
4578 struct vega10_hwmgr *data = hwmgr->backend;
4579 uint32_t i, size = 0;
4580 static const uint8_t profile_mode_setting[5][4] = {{70, 60, 1, 3,},
4586 static const char *profile_name[6] = {"3D_FULL_SCREEN",
4592 static const char *title[6] = {"NUM",
4597 "MIN_ACTIVE_LEVEL"};
4602 size += sprintf(buf + size, "%s %16s %s %s %s %s\n",title[0],
4603 title[1], title[2], title[3], title[4], title[5]);
4605 for (i = 0; i < PP_SMC_POWER_PROFILE_CUSTOM; i++)
4606 size += sprintf(buf + size, "%3d %14s%s: %14d %3d %10d %14d\n",
4607 i, profile_name[i], (i == hwmgr->power_profile_mode) ? "*" : " ",
4608 profile_mode_setting[i][0], profile_mode_setting[i][1],
4609 profile_mode_setting[i][2], profile_mode_setting[i][3]);
4610 size += sprintf(buf + size, "%3d %14s%s: %14d %3d %10d %14d\n", i,
4611 profile_name[i], (i == hwmgr->power_profile_mode) ? "*" : " ",
4612 data->custom_profile_mode[0], data->custom_profile_mode[1],
4613 data->custom_profile_mode[2], data->custom_profile_mode[3]);
4617 static int vega10_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint32_t size)
4619 struct vega10_hwmgr *data = hwmgr->backend;
4620 uint8_t busy_set_point;
4622 uint8_t use_rlc_busy;
4623 uint8_t min_active_level;
4625 hwmgr->power_profile_mode = input[size];
4627 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetWorkloadMask,
4628 1<<hwmgr->power_profile_mode);
4630 if (hwmgr->power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
4631 if (size == 0 || size > 4)
4634 data->custom_profile_mode[0] = busy_set_point = input[0];
4635 data->custom_profile_mode[1] = FPS = input[1];
4636 data->custom_profile_mode[2] = use_rlc_busy = input[2];
4637 data->custom_profile_mode[3] = min_active_level = input[3];
4638 smum_send_msg_to_smc_with_parameter(hwmgr,
4639 PPSMC_MSG_SetCustomGfxDpmParameters,
4640 busy_set_point | FPS<<8 |
4641 use_rlc_busy << 16 | min_active_level<<24);
4648 static bool vega10_check_clk_voltage_valid(struct pp_hwmgr *hwmgr,
4649 enum PP_OD_DPM_TABLE_COMMAND type,
4653 struct vega10_hwmgr *data = hwmgr->backend;
4654 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4655 struct vega10_single_dpm_table *golden_table;
4657 if (voltage < odn_table->min_vddc || voltage > odn_table->max_vddc) {
4658 pr_info("OD voltage is out of range [%d - %d] mV\n", odn_table->min_vddc, odn_table->max_vddc);
4662 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
4663 golden_table = &(data->golden_dpm_table.gfx_table);
4664 if (golden_table->dpm_levels[0].value > clk ||
4665 hwmgr->platform_descriptor.overdriveLimit.engineClock < clk) {
4666 pr_info("OD engine clock is out of range [%d - %d] MHz\n",
4667 golden_table->dpm_levels[0].value/100,
4668 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
4671 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
4672 golden_table = &(data->golden_dpm_table.mem_table);
4673 if (golden_table->dpm_levels[0].value > clk ||
4674 hwmgr->platform_descriptor.overdriveLimit.memoryClock < clk) {
4675 pr_info("OD memory clock is out of range [%d - %d] MHz\n",
4676 golden_table->dpm_levels[0].value/100,
4677 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
4687 static void vega10_check_dpm_table_updated(struct pp_hwmgr *hwmgr)
4689 struct vega10_hwmgr *data = hwmgr->backend;
4690 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
4691 struct phm_ppt_v2_information *table_info = hwmgr->pptable;
4692 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
4693 struct phm_ppt_v1_clock_voltage_dependency_table *odn_dep_table;
4696 dep_table = table_info->vdd_dep_on_mclk;
4697 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dep_on_mclk);
4699 for (i = 0; i < dep_table->count; i++) {
4700 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
4701 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_MCLK;
4706 dep_table = table_info->vdd_dep_on_sclk;
4707 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dep_on_sclk);
4708 for (i = 0; i < dep_table->count; i++) {
4709 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
4710 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_SCLK;
4715 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
4716 data->need_update_dpm_table &= ~DPMTABLE_OD_UPDATE_VDDC;
4717 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_OD_UPDATE_MCLK;
4721 static void vega10_odn_update_soc_table(struct pp_hwmgr *hwmgr,
4722 enum PP_OD_DPM_TABLE_COMMAND type)
4724 struct vega10_hwmgr *data = hwmgr->backend;
4725 struct phm_ppt_v2_information *table_info = hwmgr->pptable;
4726 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table = table_info->vdd_dep_on_socclk;
4727 struct vega10_single_dpm_table *dpm_table = &data->golden_dpm_table.soc_table;
4729 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep_on_socclk =
4730 &data->odn_dpm_table.vdd_dep_on_socclk;
4731 struct vega10_odn_vddc_lookup_table *od_vddc_lookup_table = &data->odn_dpm_table.vddc_lookup_table;
4733 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep;
4736 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
4737 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_sclk;
4738 for (i = 0; i < podn_vdd_dep->count - 1; i++)
4739 od_vddc_lookup_table->entries[i].us_vdd = podn_vdd_dep->entries[i].vddc;
4740 if (od_vddc_lookup_table->entries[i].us_vdd < podn_vdd_dep->entries[i].vddc)
4741 od_vddc_lookup_table->entries[i].us_vdd = podn_vdd_dep->entries[i].vddc;
4742 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
4743 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_mclk;
4744 for (i = 0; i < dpm_table->count; i++) {
4745 for (j = 0; j < od_vddc_lookup_table->count; j++) {
4746 if (od_vddc_lookup_table->entries[j].us_vdd >
4747 podn_vdd_dep->entries[i].vddc)
4750 if (j == od_vddc_lookup_table->count) {
4751 od_vddc_lookup_table->entries[j-1].us_vdd =
4752 podn_vdd_dep->entries[i].vddc;
4753 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC;
4755 podn_vdd_dep->entries[i].vddInd = j;
4757 dpm_table = &data->dpm_table.soc_table;
4758 for (i = 0; i < dep_table->count; i++) {
4759 if (dep_table->entries[i].vddInd == podn_vdd_dep->entries[dep_table->count-1].vddInd &&
4760 dep_table->entries[i].clk < podn_vdd_dep->entries[dep_table->count-1].clk) {
4761 data->need_update_dpm_table |= DPMTABLE_UPDATE_SOCCLK;
4762 podn_vdd_dep_on_socclk->entries[i].clk = podn_vdd_dep->entries[dep_table->count-1].clk;
4763 dpm_table->dpm_levels[i].value = podn_vdd_dep_on_socclk->entries[i].clk;
4766 if (podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].clk <
4767 podn_vdd_dep->entries[dep_table->count-1].clk) {
4768 data->need_update_dpm_table |= DPMTABLE_UPDATE_SOCCLK;
4769 podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].clk = podn_vdd_dep->entries[dep_table->count-1].clk;
4770 dpm_table->dpm_levels[podn_vdd_dep_on_socclk->count - 1].value = podn_vdd_dep->entries[dep_table->count-1].clk;
4772 if (podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].vddInd <
4773 podn_vdd_dep->entries[dep_table->count-1].vddInd) {
4774 data->need_update_dpm_table |= DPMTABLE_UPDATE_SOCCLK;
4775 podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].vddInd = podn_vdd_dep->entries[dep_table->count-1].vddInd;
4780 static int vega10_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
4781 enum PP_OD_DPM_TABLE_COMMAND type,
4782 long *input, uint32_t size)
4784 struct vega10_hwmgr *data = hwmgr->backend;
4785 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep_table;
4786 struct vega10_single_dpm_table *dpm_table;
4790 uint32_t input_level;
4793 PP_ASSERT_WITH_CODE(input, "NULL user input for clock and voltage",
4796 if (!hwmgr->od_enabled) {
4797 pr_info("OverDrive feature not enabled\n");
4801 if (PP_OD_EDIT_SCLK_VDDC_TABLE == type) {
4802 dpm_table = &data->dpm_table.gfx_table;
4803 podn_vdd_dep_table = &data->odn_dpm_table.vdd_dep_on_sclk;
4804 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
4805 } else if (PP_OD_EDIT_MCLK_VDDC_TABLE == type) {
4806 dpm_table = &data->dpm_table.mem_table;
4807 podn_vdd_dep_table = &data->odn_dpm_table.vdd_dep_on_mclk;
4808 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
4809 } else if (PP_OD_RESTORE_DEFAULT_TABLE == type) {
4810 memcpy(&(data->dpm_table), &(data->golden_dpm_table), sizeof(struct vega10_dpm_table));
4811 vega10_odn_initial_default_setting(hwmgr);
4813 } else if (PP_OD_COMMIT_DPM_TABLE == type) {
4814 vega10_check_dpm_table_updated(hwmgr);
4820 for (i = 0; i < size; i += 3) {
4821 if (i + 3 > size || input[i] >= podn_vdd_dep_table->count) {
4822 pr_info("invalid clock voltage input\n");
4825 input_level = input[i];
4826 input_clk = input[i+1] * 100;
4827 input_vol = input[i+2];
4829 if (vega10_check_clk_voltage_valid(hwmgr, type, input_clk, input_vol)) {
4830 dpm_table->dpm_levels[input_level].value = input_clk;
4831 podn_vdd_dep_table->entries[input_level].clk = input_clk;
4832 podn_vdd_dep_table->entries[input_level].vddc = input_vol;
4837 vega10_odn_update_soc_table(hwmgr, type);
4841 static const struct pp_hwmgr_func vega10_hwmgr_funcs = {
4842 .backend_init = vega10_hwmgr_backend_init,
4843 .backend_fini = vega10_hwmgr_backend_fini,
4844 .asic_setup = vega10_setup_asic_task,
4845 .dynamic_state_management_enable = vega10_enable_dpm_tasks,
4846 .dynamic_state_management_disable = vega10_disable_dpm_tasks,
4847 .get_num_of_pp_table_entries =
4848 vega10_get_number_of_powerplay_table_entries,
4849 .get_power_state_size = vega10_get_power_state_size,
4850 .get_pp_table_entry = vega10_get_pp_table_entry,
4851 .patch_boot_state = vega10_patch_boot_state,
4852 .apply_state_adjust_rules = vega10_apply_state_adjust_rules,
4853 .power_state_set = vega10_set_power_state_tasks,
4854 .get_sclk = vega10_dpm_get_sclk,
4855 .get_mclk = vega10_dpm_get_mclk,
4856 .notify_smc_display_config_after_ps_adjustment =
4857 vega10_notify_smc_display_config_after_ps_adjustment,
4858 .force_dpm_level = vega10_dpm_force_dpm_level,
4859 .stop_thermal_controller = vega10_thermal_stop_thermal_controller,
4860 .get_fan_speed_info = vega10_fan_ctrl_get_fan_speed_info,
4861 .get_fan_speed_percent = vega10_fan_ctrl_get_fan_speed_percent,
4862 .set_fan_speed_percent = vega10_fan_ctrl_set_fan_speed_percent,
4863 .reset_fan_speed_to_default =
4864 vega10_fan_ctrl_reset_fan_speed_to_default,
4865 .get_fan_speed_rpm = vega10_fan_ctrl_get_fan_speed_rpm,
4866 .set_fan_speed_rpm = vega10_fan_ctrl_set_fan_speed_rpm,
4867 .uninitialize_thermal_controller =
4868 vega10_thermal_ctrl_uninitialize_thermal_controller,
4869 .set_fan_control_mode = vega10_set_fan_control_mode,
4870 .get_fan_control_mode = vega10_get_fan_control_mode,
4871 .read_sensor = vega10_read_sensor,
4872 .get_dal_power_level = vega10_get_dal_power_level,
4873 .get_clock_by_type_with_latency = vega10_get_clock_by_type_with_latency,
4874 .get_clock_by_type_with_voltage = vega10_get_clock_by_type_with_voltage,
4875 .set_watermarks_for_clocks_ranges = vega10_set_watermarks_for_clocks_ranges,
4876 .display_clock_voltage_request = vega10_display_clock_voltage_request,
4877 .force_clock_level = vega10_force_clock_level,
4878 .print_clock_levels = vega10_print_clock_levels,
4879 .display_config_changed = vega10_display_configuration_changed_task,
4880 .powergate_uvd = vega10_power_gate_uvd,
4881 .powergate_vce = vega10_power_gate_vce,
4882 .check_states_equal = vega10_check_states_equal,
4883 .check_smc_update_required_for_display_configuration =
4884 vega10_check_smc_update_required_for_display_configuration,
4885 .power_off_asic = vega10_power_off_asic,
4886 .disable_smc_firmware_ctf = vega10_thermal_disable_alert,
4887 .get_sclk_od = vega10_get_sclk_od,
4888 .set_sclk_od = vega10_set_sclk_od,
4889 .get_mclk_od = vega10_get_mclk_od,
4890 .set_mclk_od = vega10_set_mclk_od,
4891 .avfs_control = vega10_avfs_enable,
4892 .notify_cac_buffer_info = vega10_notify_cac_buffer_info,
4893 .get_thermal_temperature_range = vega10_get_thermal_temperature_range,
4894 .register_irq_handlers = smu9_register_irq_handlers,
4895 .start_thermal_controller = vega10_start_thermal_controller,
4896 .get_power_profile_mode = vega10_get_power_profile_mode,
4897 .set_power_profile_mode = vega10_set_power_profile_mode,
4898 .set_power_limit = vega10_set_power_limit,
4899 .odn_edit_dpm_table = vega10_odn_edit_dpm_table,
4902 int vega10_enable_smc_features(struct pp_hwmgr *hwmgr,
4903 bool enable, uint32_t feature_mask)
4905 int msg = enable ? PPSMC_MSG_EnableSmuFeatures :
4906 PPSMC_MSG_DisableSmuFeatures;
4908 return smum_send_msg_to_smc_with_parameter(hwmgr,
4912 int vega10_hwmgr_init(struct pp_hwmgr *hwmgr)
4914 hwmgr->hwmgr_func = &vega10_hwmgr_funcs;
4915 hwmgr->pptable_func = &vega10_pptable_funcs;