1 /*
2 * Copyright 2016 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 */
23
24 #include <linux/delay.h>
25 #include <linux/module.h>
26 #include <linux/pci.h>
27 #include <linux/slab.h>
28
29 #include "hwmgr.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"
36 #include "smu9.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_smumgr.h"
43 #include "vega10_processpptables.h"
44 #include "vega10_pptable.h"
45 #include "vega10_thermal.h"
46 #include "pp_debug.h"
47 #include "amd_pcie_helpers.h"
48 #include "ppinterrupt.h"
49 #include "pp_overdriver.h"
50 #include "pp_thermal.h"
51 #include "vega10_baco.h"
52
53 #include "smuio/smuio_9_0_offset.h"
54 #include "smuio/smuio_9_0_sh_mask.h"
55
56 #define smnPCIE_LC_SPEED_CNTL 0x11140290
57 #define smnPCIE_LC_LINK_WIDTH_CNTL 0x11140288
58
59 #define HBM_MEMORY_CHANNEL_WIDTH 128
60
61 static const uint32_t channel_number[] = {1, 2, 0, 4, 0, 8, 0, 16, 2};
62
63 #define mmDF_CS_AON0_DramBaseAddress0 0x0044
64 #define mmDF_CS_AON0_DramBaseAddress0_BASE_IDX 0
65
66 //DF_CS_AON0_DramBaseAddress0
67 #define DF_CS_AON0_DramBaseAddress0__AddrRngVal__SHIFT 0x0
68 #define DF_CS_AON0_DramBaseAddress0__LgcyMmioHoleEn__SHIFT 0x1
69 #define DF_CS_AON0_DramBaseAddress0__IntLvNumChan__SHIFT 0x4
70 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel__SHIFT 0x8
71 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr__SHIFT 0xc
72 #define DF_CS_AON0_DramBaseAddress0__AddrRngVal_MASK 0x00000001L
73 #define DF_CS_AON0_DramBaseAddress0__LgcyMmioHoleEn_MASK 0x00000002L
74 #define DF_CS_AON0_DramBaseAddress0__IntLvNumChan_MASK 0x000000F0L
75 #define DF_CS_AON0_DramBaseAddress0__IntLvAddrSel_MASK 0x00000700L
76 #define DF_CS_AON0_DramBaseAddress0__DramBaseAddr_MASK 0xFFFFF000L
77
78 typedef enum {
79 CLK_SMNCLK = 0,
80 CLK_SOCCLK,
81 CLK_MP0CLK,
82 CLK_MP1CLK,
83 CLK_LCLK,
84 CLK_DCEFCLK,
85 CLK_VCLK,
86 CLK_DCLK,
87 CLK_ECLK,
88 CLK_UCLK,
89 CLK_GFXCLK,
90 CLK_COUNT,
91 } CLOCK_ID_e;
92
93 static const ULONG PhwVega10_Magic = (ULONG)(PHM_VIslands_Magic);
94
cast_phw_vega10_power_state(struct pp_hw_power_state * hw_ps)95 static struct vega10_power_state *cast_phw_vega10_power_state(
96 struct pp_hw_power_state *hw_ps)
97 {
98 PP_ASSERT_WITH_CODE((PhwVega10_Magic == hw_ps->magic),
99 "Invalid Powerstate Type!",
100 return NULL;);
101
102 return (struct vega10_power_state *)hw_ps;
103 }
104
cast_const_phw_vega10_power_state(const struct pp_hw_power_state * hw_ps)105 static const struct vega10_power_state *cast_const_phw_vega10_power_state(
106 const struct pp_hw_power_state *hw_ps)
107 {
108 PP_ASSERT_WITH_CODE((PhwVega10_Magic == hw_ps->magic),
109 "Invalid Powerstate Type!",
110 return NULL;);
111
112 return (const struct vega10_power_state *)hw_ps;
113 }
114
vega10_set_default_registry_data(struct pp_hwmgr * hwmgr)115 static void vega10_set_default_registry_data(struct pp_hwmgr *hwmgr)
116 {
117 struct vega10_hwmgr *data = hwmgr->backend;
118
119 data->registry_data.sclk_dpm_key_disabled =
120 hwmgr->feature_mask & PP_SCLK_DPM_MASK ? false : true;
121 data->registry_data.socclk_dpm_key_disabled =
122 hwmgr->feature_mask & PP_SOCCLK_DPM_MASK ? false : true;
123 data->registry_data.mclk_dpm_key_disabled =
124 hwmgr->feature_mask & PP_MCLK_DPM_MASK ? false : true;
125 data->registry_data.pcie_dpm_key_disabled =
126 hwmgr->feature_mask & PP_PCIE_DPM_MASK ? false : true;
127
128 data->registry_data.dcefclk_dpm_key_disabled =
129 hwmgr->feature_mask & PP_DCEFCLK_DPM_MASK ? false : true;
130
131 if (hwmgr->feature_mask & PP_POWER_CONTAINMENT_MASK) {
132 data->registry_data.power_containment_support = 1;
133 data->registry_data.enable_pkg_pwr_tracking_feature = 1;
134 data->registry_data.enable_tdc_limit_feature = 1;
135 }
136
137 data->registry_data.clock_stretcher_support =
138 hwmgr->feature_mask & PP_CLOCK_STRETCH_MASK ? true : false;
139
140 data->registry_data.ulv_support =
141 hwmgr->feature_mask & PP_ULV_MASK ? true : false;
142
143 data->registry_data.sclk_deep_sleep_support =
144 hwmgr->feature_mask & PP_SCLK_DEEP_SLEEP_MASK ? true : false;
145
146 data->registry_data.disable_water_mark = 0;
147
148 data->registry_data.fan_control_support = 1;
149 data->registry_data.thermal_support = 1;
150 data->registry_data.fw_ctf_enabled = 1;
151
152 data->registry_data.avfs_support =
153 hwmgr->feature_mask & PP_AVFS_MASK ? true : false;
154 data->registry_data.led_dpm_enabled = 1;
155
156 data->registry_data.vr0hot_enabled = 1;
157 data->registry_data.vr1hot_enabled = 1;
158 data->registry_data.regulator_hot_gpio_support = 1;
159
160 data->registry_data.didt_support = 1;
161 if (data->registry_data.didt_support) {
162 data->registry_data.didt_mode = 6;
163 data->registry_data.sq_ramping_support = 1;
164 data->registry_data.db_ramping_support = 0;
165 data->registry_data.td_ramping_support = 0;
166 data->registry_data.tcp_ramping_support = 0;
167 data->registry_data.dbr_ramping_support = 0;
168 data->registry_data.edc_didt_support = 1;
169 data->registry_data.gc_didt_support = 0;
170 data->registry_data.psm_didt_support = 0;
171 }
172
173 data->display_voltage_mode = PPVEGA10_VEGA10DISPLAYVOLTAGEMODE_DFLT;
174 data->dcef_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
175 data->dcef_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
176 data->dcef_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
177 data->disp_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
178 data->disp_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
179 data->disp_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
180 data->pixel_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
181 data->pixel_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
182 data->pixel_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
183 data->phy_clk_quad_eqn_a = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
184 data->phy_clk_quad_eqn_b = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
185 data->phy_clk_quad_eqn_c = PPREGKEY_VEGA10QUADRATICEQUATION_DFLT;
186
187 data->gfxclk_average_alpha = PPVEGA10_VEGA10GFXCLKAVERAGEALPHA_DFLT;
188 data->socclk_average_alpha = PPVEGA10_VEGA10SOCCLKAVERAGEALPHA_DFLT;
189 data->uclk_average_alpha = PPVEGA10_VEGA10UCLKCLKAVERAGEALPHA_DFLT;
190 data->gfx_activity_average_alpha = PPVEGA10_VEGA10GFXACTIVITYAVERAGEALPHA_DFLT;
191 }
192
vega10_set_features_platform_caps(struct pp_hwmgr * hwmgr)193 static int vega10_set_features_platform_caps(struct pp_hwmgr *hwmgr)
194 {
195 struct vega10_hwmgr *data = hwmgr->backend;
196 struct phm_ppt_v2_information *table_info =
197 (struct phm_ppt_v2_information *)hwmgr->pptable;
198 struct amdgpu_device *adev = hwmgr->adev;
199
200 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
201 PHM_PlatformCaps_SclkDeepSleep);
202
203 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
204 PHM_PlatformCaps_DynamicPatchPowerState);
205
206 if (data->vddci_control == VEGA10_VOLTAGE_CONTROL_NONE)
207 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
208 PHM_PlatformCaps_ControlVDDCI);
209
210 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
211 PHM_PlatformCaps_EnableSMU7ThermalManagement);
212
213 if (adev->pg_flags & AMD_PG_SUPPORT_UVD)
214 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
215 PHM_PlatformCaps_UVDPowerGating);
216
217 if (adev->pg_flags & AMD_PG_SUPPORT_VCE)
218 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
219 PHM_PlatformCaps_VCEPowerGating);
220
221 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
222 PHM_PlatformCaps_UnTabledHardwareInterface);
223
224 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
225 PHM_PlatformCaps_FanSpeedInTableIsRPM);
226
227 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
228 PHM_PlatformCaps_ODFuzzyFanControlSupport);
229
230 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
231 PHM_PlatformCaps_DynamicPowerManagement);
232
233 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
234 PHM_PlatformCaps_SMC);
235
236 /* power tune caps */
237 /* assume disabled */
238 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
239 PHM_PlatformCaps_PowerContainment);
240 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
241 PHM_PlatformCaps_DiDtSupport);
242 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
243 PHM_PlatformCaps_SQRamping);
244 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
245 PHM_PlatformCaps_DBRamping);
246 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
247 PHM_PlatformCaps_TDRamping);
248 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
249 PHM_PlatformCaps_TCPRamping);
250 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
251 PHM_PlatformCaps_DBRRamping);
252 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
253 PHM_PlatformCaps_DiDtEDCEnable);
254 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
255 PHM_PlatformCaps_GCEDC);
256 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
257 PHM_PlatformCaps_PSM);
258
259 if (data->registry_data.didt_support) {
260 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DiDtSupport);
261 if (data->registry_data.sq_ramping_support)
262 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SQRamping);
263 if (data->registry_data.db_ramping_support)
264 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DBRamping);
265 if (data->registry_data.td_ramping_support)
266 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_TDRamping);
267 if (data->registry_data.tcp_ramping_support)
268 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_TCPRamping);
269 if (data->registry_data.dbr_ramping_support)
270 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DBRRamping);
271 if (data->registry_data.edc_didt_support)
272 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DiDtEDCEnable);
273 if (data->registry_data.gc_didt_support)
274 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_GCEDC);
275 if (data->registry_data.psm_didt_support)
276 phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PSM);
277 }
278
279 if (data->registry_data.power_containment_support)
280 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
281 PHM_PlatformCaps_PowerContainment);
282 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
283 PHM_PlatformCaps_CAC);
284
285 if (table_info->tdp_table->usClockStretchAmount &&
286 data->registry_data.clock_stretcher_support)
287 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
288 PHM_PlatformCaps_ClockStretcher);
289
290 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
291 PHM_PlatformCaps_RegulatorHot);
292 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
293 PHM_PlatformCaps_AutomaticDCTransition);
294
295 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
296 PHM_PlatformCaps_UVDDPM);
297 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
298 PHM_PlatformCaps_VCEDPM);
299
300 return 0;
301 }
302
vega10_odn_initial_default_setting(struct pp_hwmgr * hwmgr)303 static int vega10_odn_initial_default_setting(struct pp_hwmgr *hwmgr)
304 {
305 struct vega10_hwmgr *data = hwmgr->backend;
306 struct phm_ppt_v2_information *table_info =
307 (struct phm_ppt_v2_information *)(hwmgr->pptable);
308 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
309 struct vega10_odn_vddc_lookup_table *od_lookup_table;
310 struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table;
311 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table[3];
312 struct phm_ppt_v1_clock_voltage_dependency_table *od_table[3];
313 struct pp_atomfwctrl_avfs_parameters avfs_params = {0};
314 uint32_t i;
315 int result;
316
317 result = pp_atomfwctrl_get_avfs_information(hwmgr, &avfs_params);
318 if (!result) {
319 data->odn_dpm_table.max_vddc = avfs_params.ulMaxVddc;
320 data->odn_dpm_table.min_vddc = avfs_params.ulMinVddc;
321 }
322
323 od_lookup_table = &odn_table->vddc_lookup_table;
324 vddc_lookup_table = table_info->vddc_lookup_table;
325
326 for (i = 0; i < vddc_lookup_table->count; i++)
327 od_lookup_table->entries[i].us_vdd = vddc_lookup_table->entries[i].us_vdd;
328
329 od_lookup_table->count = vddc_lookup_table->count;
330
331 dep_table[0] = table_info->vdd_dep_on_sclk;
332 dep_table[1] = table_info->vdd_dep_on_mclk;
333 dep_table[2] = table_info->vdd_dep_on_socclk;
334 od_table[0] = (struct phm_ppt_v1_clock_voltage_dependency_table *)&odn_table->vdd_dep_on_sclk;
335 od_table[1] = (struct phm_ppt_v1_clock_voltage_dependency_table *)&odn_table->vdd_dep_on_mclk;
336 od_table[2] = (struct phm_ppt_v1_clock_voltage_dependency_table *)&odn_table->vdd_dep_on_socclk;
337
338 for (i = 0; i < 3; i++)
339 smu_get_voltage_dependency_table_ppt_v1(dep_table[i], od_table[i]);
340
341 if (odn_table->max_vddc == 0 || odn_table->max_vddc > 2000)
342 odn_table->max_vddc = dep_table[0]->entries[dep_table[0]->count - 1].vddc;
343 if (odn_table->min_vddc == 0 || odn_table->min_vddc > 2000)
344 odn_table->min_vddc = dep_table[0]->entries[0].vddc;
345
346 i = od_table[2]->count - 1;
347 od_table[2]->entries[i].clk = hwmgr->platform_descriptor.overdriveLimit.memoryClock > od_table[2]->entries[i].clk ?
348 hwmgr->platform_descriptor.overdriveLimit.memoryClock :
349 od_table[2]->entries[i].clk;
350 od_table[2]->entries[i].vddc = odn_table->max_vddc > od_table[2]->entries[i].vddc ?
351 odn_table->max_vddc :
352 od_table[2]->entries[i].vddc;
353
354 return 0;
355 }
356
vega10_init_dpm_defaults(struct pp_hwmgr * hwmgr)357 static int vega10_init_dpm_defaults(struct pp_hwmgr *hwmgr)
358 {
359 struct vega10_hwmgr *data = hwmgr->backend;
360 uint32_t sub_vendor_id, hw_revision;
361 uint32_t top32, bottom32;
362 struct amdgpu_device *adev = hwmgr->adev;
363 int ret, i;
364
365 vega10_initialize_power_tune_defaults(hwmgr);
366
367 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
368 data->smu_features[i].smu_feature_id = 0xffff;
369 data->smu_features[i].smu_feature_bitmap = 1 << i;
370 data->smu_features[i].enabled = false;
371 data->smu_features[i].supported = false;
372 }
373
374 data->smu_features[GNLD_DPM_PREFETCHER].smu_feature_id =
375 FEATURE_DPM_PREFETCHER_BIT;
376 data->smu_features[GNLD_DPM_GFXCLK].smu_feature_id =
377 FEATURE_DPM_GFXCLK_BIT;
378 data->smu_features[GNLD_DPM_UCLK].smu_feature_id =
379 FEATURE_DPM_UCLK_BIT;
380 data->smu_features[GNLD_DPM_SOCCLK].smu_feature_id =
381 FEATURE_DPM_SOCCLK_BIT;
382 data->smu_features[GNLD_DPM_UVD].smu_feature_id =
383 FEATURE_DPM_UVD_BIT;
384 data->smu_features[GNLD_DPM_VCE].smu_feature_id =
385 FEATURE_DPM_VCE_BIT;
386 data->smu_features[GNLD_DPM_MP0CLK].smu_feature_id =
387 FEATURE_DPM_MP0CLK_BIT;
388 data->smu_features[GNLD_DPM_LINK].smu_feature_id =
389 FEATURE_DPM_LINK_BIT;
390 data->smu_features[GNLD_DPM_DCEFCLK].smu_feature_id =
391 FEATURE_DPM_DCEFCLK_BIT;
392 data->smu_features[GNLD_ULV].smu_feature_id =
393 FEATURE_ULV_BIT;
394 data->smu_features[GNLD_AVFS].smu_feature_id =
395 FEATURE_AVFS_BIT;
396 data->smu_features[GNLD_DS_GFXCLK].smu_feature_id =
397 FEATURE_DS_GFXCLK_BIT;
398 data->smu_features[GNLD_DS_SOCCLK].smu_feature_id =
399 FEATURE_DS_SOCCLK_BIT;
400 data->smu_features[GNLD_DS_LCLK].smu_feature_id =
401 FEATURE_DS_LCLK_BIT;
402 data->smu_features[GNLD_PPT].smu_feature_id =
403 FEATURE_PPT_BIT;
404 data->smu_features[GNLD_TDC].smu_feature_id =
405 FEATURE_TDC_BIT;
406 data->smu_features[GNLD_THERMAL].smu_feature_id =
407 FEATURE_THERMAL_BIT;
408 data->smu_features[GNLD_GFX_PER_CU_CG].smu_feature_id =
409 FEATURE_GFX_PER_CU_CG_BIT;
410 data->smu_features[GNLD_RM].smu_feature_id =
411 FEATURE_RM_BIT;
412 data->smu_features[GNLD_DS_DCEFCLK].smu_feature_id =
413 FEATURE_DS_DCEFCLK_BIT;
414 data->smu_features[GNLD_ACDC].smu_feature_id =
415 FEATURE_ACDC_BIT;
416 data->smu_features[GNLD_VR0HOT].smu_feature_id =
417 FEATURE_VR0HOT_BIT;
418 data->smu_features[GNLD_VR1HOT].smu_feature_id =
419 FEATURE_VR1HOT_BIT;
420 data->smu_features[GNLD_FW_CTF].smu_feature_id =
421 FEATURE_FW_CTF_BIT;
422 data->smu_features[GNLD_LED_DISPLAY].smu_feature_id =
423 FEATURE_LED_DISPLAY_BIT;
424 data->smu_features[GNLD_FAN_CONTROL].smu_feature_id =
425 FEATURE_FAN_CONTROL_BIT;
426 data->smu_features[GNLD_ACG].smu_feature_id = FEATURE_ACG_BIT;
427 data->smu_features[GNLD_DIDT].smu_feature_id = FEATURE_GFX_EDC_BIT;
428 data->smu_features[GNLD_PCC_LIMIT].smu_feature_id = FEATURE_PCC_LIMIT_CONTROL_BIT;
429
430 if (!data->registry_data.prefetcher_dpm_key_disabled)
431 data->smu_features[GNLD_DPM_PREFETCHER].supported = true;
432
433 if (!data->registry_data.sclk_dpm_key_disabled)
434 data->smu_features[GNLD_DPM_GFXCLK].supported = true;
435
436 if (!data->registry_data.mclk_dpm_key_disabled)
437 data->smu_features[GNLD_DPM_UCLK].supported = true;
438
439 if (!data->registry_data.socclk_dpm_key_disabled)
440 data->smu_features[GNLD_DPM_SOCCLK].supported = true;
441
442 if (PP_CAP(PHM_PlatformCaps_UVDDPM))
443 data->smu_features[GNLD_DPM_UVD].supported = true;
444
445 if (PP_CAP(PHM_PlatformCaps_VCEDPM))
446 data->smu_features[GNLD_DPM_VCE].supported = true;
447
448 data->smu_features[GNLD_DPM_LINK].supported = true;
449
450 if (!data->registry_data.dcefclk_dpm_key_disabled)
451 data->smu_features[GNLD_DPM_DCEFCLK].supported = true;
452
453 if (PP_CAP(PHM_PlatformCaps_SclkDeepSleep) &&
454 data->registry_data.sclk_deep_sleep_support) {
455 data->smu_features[GNLD_DS_GFXCLK].supported = true;
456 data->smu_features[GNLD_DS_SOCCLK].supported = true;
457 data->smu_features[GNLD_DS_LCLK].supported = true;
458 data->smu_features[GNLD_DS_DCEFCLK].supported = true;
459 }
460
461 if (data->registry_data.enable_pkg_pwr_tracking_feature)
462 data->smu_features[GNLD_PPT].supported = true;
463
464 if (data->registry_data.enable_tdc_limit_feature)
465 data->smu_features[GNLD_TDC].supported = true;
466
467 if (data->registry_data.thermal_support)
468 data->smu_features[GNLD_THERMAL].supported = true;
469
470 if (data->registry_data.fan_control_support)
471 data->smu_features[GNLD_FAN_CONTROL].supported = true;
472
473 if (data->registry_data.fw_ctf_enabled)
474 data->smu_features[GNLD_FW_CTF].supported = true;
475
476 if (data->registry_data.avfs_support)
477 data->smu_features[GNLD_AVFS].supported = true;
478
479 if (data->registry_data.led_dpm_enabled)
480 data->smu_features[GNLD_LED_DISPLAY].supported = true;
481
482 if (data->registry_data.vr1hot_enabled)
483 data->smu_features[GNLD_VR1HOT].supported = true;
484
485 if (data->registry_data.vr0hot_enabled)
486 data->smu_features[GNLD_VR0HOT].supported = true;
487
488 ret = smum_send_msg_to_smc(hwmgr,
489 PPSMC_MSG_GetSmuVersion,
490 &hwmgr->smu_version);
491 if (ret)
492 return ret;
493
494 /* ACG firmware has major version 5 */
495 if ((hwmgr->smu_version & 0xff000000) == 0x5000000)
496 data->smu_features[GNLD_ACG].supported = true;
497 if (data->registry_data.didt_support)
498 data->smu_features[GNLD_DIDT].supported = true;
499
500 hw_revision = adev->pdev->revision;
501 sub_vendor_id = adev->pdev->subsystem_vendor;
502
503 if ((hwmgr->chip_id == 0x6862 ||
504 hwmgr->chip_id == 0x6861 ||
505 hwmgr->chip_id == 0x6868) &&
506 (hw_revision == 0) &&
507 (sub_vendor_id != 0x1002))
508 data->smu_features[GNLD_PCC_LIMIT].supported = true;
509
510 /* Get the SN to turn into a Unique ID */
511 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumTop32, &top32);
512 if (ret)
513 return ret;
514
515 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumBottom32, &bottom32);
516 if (ret)
517 return ret;
518
519 adev->unique_id = ((uint64_t)bottom32 << 32) | top32;
520 return 0;
521 }
522
523 #ifdef PPLIB_VEGA10_EVV_SUPPORT
vega10_get_socclk_for_voltage_evv(struct pp_hwmgr * hwmgr,phm_ppt_v1_voltage_lookup_table * lookup_table,uint16_t virtual_voltage_id,int32_t * socclk)524 static int vega10_get_socclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
525 phm_ppt_v1_voltage_lookup_table *lookup_table,
526 uint16_t virtual_voltage_id, int32_t *socclk)
527 {
528 uint8_t entry_id;
529 uint8_t voltage_id;
530 struct phm_ppt_v2_information *table_info =
531 (struct phm_ppt_v2_information *)(hwmgr->pptable);
532
533 PP_ASSERT_WITH_CODE(lookup_table->count != 0,
534 "Lookup table is empty",
535 return -EINVAL);
536
537 /* search for leakage voltage ID 0xff01 ~ 0xff08 and sclk */
538 for (entry_id = 0; entry_id < table_info->vdd_dep_on_sclk->count; entry_id++) {
539 voltage_id = table_info->vdd_dep_on_socclk->entries[entry_id].vddInd;
540 if (lookup_table->entries[voltage_id].us_vdd == virtual_voltage_id)
541 break;
542 }
543
544 PP_ASSERT_WITH_CODE(entry_id < table_info->vdd_dep_on_socclk->count,
545 "Can't find requested voltage id in vdd_dep_on_socclk table!",
546 return -EINVAL);
547
548 *socclk = table_info->vdd_dep_on_socclk->entries[entry_id].clk;
549
550 return 0;
551 }
552
553 #define ATOM_VIRTUAL_VOLTAGE_ID0 0xff01
554 /**
555 * vega10_get_evv_voltages - Get Leakage VDDC based on leakage ID.
556 *
557 * @hwmgr: the address of the powerplay hardware manager.
558 * return: always 0.
559 */
vega10_get_evv_voltages(struct pp_hwmgr * hwmgr)560 static int vega10_get_evv_voltages(struct pp_hwmgr *hwmgr)
561 {
562 struct vega10_hwmgr *data = hwmgr->backend;
563 uint16_t vv_id;
564 uint32_t vddc = 0;
565 uint16_t i, j;
566 uint32_t sclk = 0;
567 struct phm_ppt_v2_information *table_info =
568 (struct phm_ppt_v2_information *)hwmgr->pptable;
569 struct phm_ppt_v1_clock_voltage_dependency_table *socclk_table =
570 table_info->vdd_dep_on_socclk;
571 int result;
572
573 for (i = 0; i < VEGA10_MAX_LEAKAGE_COUNT; i++) {
574 vv_id = ATOM_VIRTUAL_VOLTAGE_ID0 + i;
575
576 if (!vega10_get_socclk_for_voltage_evv(hwmgr,
577 table_info->vddc_lookup_table, vv_id, &sclk)) {
578 if (PP_CAP(PHM_PlatformCaps_ClockStretcher)) {
579 for (j = 1; j < socclk_table->count; j++) {
580 if (socclk_table->entries[j].clk == sclk &&
581 socclk_table->entries[j].cks_enable == 0) {
582 sclk += 5000;
583 break;
584 }
585 }
586 }
587
588 PP_ASSERT_WITH_CODE(!atomctrl_get_voltage_evv_on_sclk_ai(hwmgr,
589 VOLTAGE_TYPE_VDDC, sclk, vv_id, &vddc),
590 "Error retrieving EVV voltage value!",
591 continue);
592
593
594 /* need to make sure vddc is less than 2v or else, it could burn the ASIC. */
595 PP_ASSERT_WITH_CODE((vddc < 2000 && vddc != 0),
596 "Invalid VDDC value", result = -EINVAL;);
597
598 /* the voltage should not be zero nor equal to leakage ID */
599 if (vddc != 0 && vddc != vv_id) {
600 data->vddc_leakage.actual_voltage[data->vddc_leakage.count] = (uint16_t)(vddc/100);
601 data->vddc_leakage.leakage_id[data->vddc_leakage.count] = vv_id;
602 data->vddc_leakage.count++;
603 }
604 }
605 }
606
607 return 0;
608 }
609
610 /**
611 * vega10_patch_with_vdd_leakage - Change virtual leakage voltage to actual value.
612 *
613 * @hwmgr: the address of the powerplay hardware manager.
614 * @voltage: pointer to changing voltage
615 * @leakage_table: pointer to leakage table
616 */
vega10_patch_with_vdd_leakage(struct pp_hwmgr * hwmgr,uint16_t * voltage,struct vega10_leakage_voltage * leakage_table)617 static void vega10_patch_with_vdd_leakage(struct pp_hwmgr *hwmgr,
618 uint16_t *voltage, struct vega10_leakage_voltage *leakage_table)
619 {
620 uint32_t index;
621
622 /* search for leakage voltage ID 0xff01 ~ 0xff08 */
623 for (index = 0; index < leakage_table->count; index++) {
624 /* if this voltage matches a leakage voltage ID */
625 /* patch with actual leakage voltage */
626 if (leakage_table->leakage_id[index] == *voltage) {
627 *voltage = leakage_table->actual_voltage[index];
628 break;
629 }
630 }
631
632 if (*voltage > ATOM_VIRTUAL_VOLTAGE_ID0)
633 pr_info("Voltage value looks like a Leakage ID but it's not patched\n");
634 }
635
636 /**
637 * vega10_patch_lookup_table_with_leakage - Patch voltage lookup table by EVV leakages.
638 *
639 * @hwmgr: the address of the powerplay hardware manager.
640 * @lookup_table: pointer to voltage lookup table
641 * @leakage_table: pointer to leakage table
642 * return: always 0
643 */
vega10_patch_lookup_table_with_leakage(struct pp_hwmgr * hwmgr,phm_ppt_v1_voltage_lookup_table * lookup_table,struct vega10_leakage_voltage * leakage_table)644 static int vega10_patch_lookup_table_with_leakage(struct pp_hwmgr *hwmgr,
645 phm_ppt_v1_voltage_lookup_table *lookup_table,
646 struct vega10_leakage_voltage *leakage_table)
647 {
648 uint32_t i;
649
650 for (i = 0; i < lookup_table->count; i++)
651 vega10_patch_with_vdd_leakage(hwmgr,
652 &lookup_table->entries[i].us_vdd, leakage_table);
653
654 return 0;
655 }
656
vega10_patch_clock_voltage_limits_with_vddc_leakage(struct pp_hwmgr * hwmgr,struct vega10_leakage_voltage * leakage_table,uint16_t * vddc)657 static int vega10_patch_clock_voltage_limits_with_vddc_leakage(
658 struct pp_hwmgr *hwmgr, struct vega10_leakage_voltage *leakage_table,
659 uint16_t *vddc)
660 {
661 vega10_patch_with_vdd_leakage(hwmgr, (uint16_t *)vddc, leakage_table);
662
663 return 0;
664 }
665 #endif
666
vega10_patch_voltage_dependency_tables_with_lookup_table(struct pp_hwmgr * hwmgr)667 static int vega10_patch_voltage_dependency_tables_with_lookup_table(
668 struct pp_hwmgr *hwmgr)
669 {
670 uint8_t entry_id, voltage_id;
671 unsigned i;
672 struct phm_ppt_v2_information *table_info =
673 (struct phm_ppt_v2_information *)(hwmgr->pptable);
674 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
675 table_info->mm_dep_table;
676 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table =
677 table_info->vdd_dep_on_mclk;
678
679 for (i = 0; i < 6; i++) {
680 struct phm_ppt_v1_clock_voltage_dependency_table *vdt;
681 switch (i) {
682 case 0: vdt = table_info->vdd_dep_on_socclk; break;
683 case 1: vdt = table_info->vdd_dep_on_sclk; break;
684 case 2: vdt = table_info->vdd_dep_on_dcefclk; break;
685 case 3: vdt = table_info->vdd_dep_on_pixclk; break;
686 case 4: vdt = table_info->vdd_dep_on_dispclk; break;
687 case 5: vdt = table_info->vdd_dep_on_phyclk; break;
688 }
689
690 for (entry_id = 0; entry_id < vdt->count; entry_id++) {
691 voltage_id = vdt->entries[entry_id].vddInd;
692 vdt->entries[entry_id].vddc =
693 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
694 }
695 }
696
697 for (entry_id = 0; entry_id < mm_table->count; ++entry_id) {
698 voltage_id = mm_table->entries[entry_id].vddcInd;
699 mm_table->entries[entry_id].vddc =
700 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
701 }
702
703 for (entry_id = 0; entry_id < mclk_table->count; ++entry_id) {
704 voltage_id = mclk_table->entries[entry_id].vddInd;
705 mclk_table->entries[entry_id].vddc =
706 table_info->vddc_lookup_table->entries[voltage_id].us_vdd;
707 voltage_id = mclk_table->entries[entry_id].vddciInd;
708 mclk_table->entries[entry_id].vddci =
709 table_info->vddci_lookup_table->entries[voltage_id].us_vdd;
710 voltage_id = mclk_table->entries[entry_id].mvddInd;
711 mclk_table->entries[entry_id].mvdd =
712 table_info->vddmem_lookup_table->entries[voltage_id].us_vdd;
713 }
714
715
716 return 0;
717
718 }
719
vega10_sort_lookup_table(struct pp_hwmgr * hwmgr,struct phm_ppt_v1_voltage_lookup_table * lookup_table)720 static int vega10_sort_lookup_table(struct pp_hwmgr *hwmgr,
721 struct phm_ppt_v1_voltage_lookup_table *lookup_table)
722 {
723 uint32_t table_size, i, j;
724
725 PP_ASSERT_WITH_CODE(lookup_table && lookup_table->count,
726 "Lookup table is empty", return -EINVAL);
727
728 table_size = lookup_table->count;
729
730 /* Sorting voltages */
731 for (i = 0; i < table_size - 1; i++) {
732 for (j = i + 1; j > 0; j--) {
733 if (lookup_table->entries[j].us_vdd <
734 lookup_table->entries[j - 1].us_vdd) {
735 swap(lookup_table->entries[j - 1],
736 lookup_table->entries[j]);
737 }
738 }
739 }
740
741 return 0;
742 }
743
vega10_complete_dependency_tables(struct pp_hwmgr * hwmgr)744 static int vega10_complete_dependency_tables(struct pp_hwmgr *hwmgr)
745 {
746 int result = 0;
747 int tmp_result;
748 struct phm_ppt_v2_information *table_info =
749 (struct phm_ppt_v2_information *)(hwmgr->pptable);
750 #ifdef PPLIB_VEGA10_EVV_SUPPORT
751 struct vega10_hwmgr *data = hwmgr->backend;
752
753 tmp_result = vega10_patch_lookup_table_with_leakage(hwmgr,
754 table_info->vddc_lookup_table, &(data->vddc_leakage));
755 if (tmp_result)
756 result = tmp_result;
757
758 tmp_result = vega10_patch_clock_voltage_limits_with_vddc_leakage(hwmgr,
759 &(data->vddc_leakage), &table_info->max_clock_voltage_on_dc.vddc);
760 if (tmp_result)
761 result = tmp_result;
762 #endif
763
764 tmp_result = vega10_patch_voltage_dependency_tables_with_lookup_table(hwmgr);
765 if (tmp_result)
766 result = tmp_result;
767
768 tmp_result = vega10_sort_lookup_table(hwmgr, table_info->vddc_lookup_table);
769 if (tmp_result)
770 result = tmp_result;
771
772 return result;
773 }
774
vega10_set_private_data_based_on_pptable(struct pp_hwmgr * hwmgr)775 static int vega10_set_private_data_based_on_pptable(struct pp_hwmgr *hwmgr)
776 {
777 struct phm_ppt_v2_information *table_info =
778 (struct phm_ppt_v2_information *)(hwmgr->pptable);
779 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_sclk_vdd_table =
780 table_info->vdd_dep_on_socclk;
781 struct phm_ppt_v1_clock_voltage_dependency_table *allowed_mclk_vdd_table =
782 table_info->vdd_dep_on_mclk;
783
784 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table,
785 "VDD dependency on SCLK table is missing. This table is mandatory", return -EINVAL);
786 PP_ASSERT_WITH_CODE(allowed_sclk_vdd_table->count >= 1,
787 "VDD dependency on SCLK table is empty. This table is mandatory", return -EINVAL);
788
789 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table,
790 "VDD dependency on MCLK table is missing. This table is mandatory", return -EINVAL);
791 PP_ASSERT_WITH_CODE(allowed_mclk_vdd_table->count >= 1,
792 "VDD dependency on MCLK table is empty. This table is mandatory", return -EINVAL);
793
794 table_info->max_clock_voltage_on_ac.sclk =
795 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].clk;
796 table_info->max_clock_voltage_on_ac.mclk =
797 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].clk;
798 table_info->max_clock_voltage_on_ac.vddc =
799 allowed_sclk_vdd_table->entries[allowed_sclk_vdd_table->count - 1].vddc;
800 table_info->max_clock_voltage_on_ac.vddci =
801 allowed_mclk_vdd_table->entries[allowed_mclk_vdd_table->count - 1].vddci;
802
803 hwmgr->dyn_state.max_clock_voltage_on_ac.sclk =
804 table_info->max_clock_voltage_on_ac.sclk;
805 hwmgr->dyn_state.max_clock_voltage_on_ac.mclk =
806 table_info->max_clock_voltage_on_ac.mclk;
807 hwmgr->dyn_state.max_clock_voltage_on_ac.vddc =
808 table_info->max_clock_voltage_on_ac.vddc;
809 hwmgr->dyn_state.max_clock_voltage_on_ac.vddci =
810 table_info->max_clock_voltage_on_ac.vddci;
811
812 return 0;
813 }
814
vega10_hwmgr_backend_fini(struct pp_hwmgr * hwmgr)815 static int vega10_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
816 {
817 kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
818 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
819
820 kfree(hwmgr->backend);
821 hwmgr->backend = NULL;
822
823 return 0;
824 }
825
vega10_hwmgr_backend_init(struct pp_hwmgr * hwmgr)826 static int vega10_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
827 {
828 int result = 0;
829 struct vega10_hwmgr *data;
830 uint32_t config_telemetry = 0;
831 struct pp_atomfwctrl_voltage_table vol_table;
832 struct amdgpu_device *adev = hwmgr->adev;
833
834 data = kzalloc_obj(struct vega10_hwmgr);
835 if (data == NULL)
836 return -ENOMEM;
837
838 hwmgr->backend = data;
839
840 hwmgr->workload_mask = 1 << hwmgr->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT];
841 hwmgr->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
842 hwmgr->default_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
843
844 vega10_set_default_registry_data(hwmgr);
845 data->disable_dpm_mask = 0xff;
846
847 /* need to set voltage control types before EVV patching */
848 data->vddc_control = VEGA10_VOLTAGE_CONTROL_NONE;
849 data->mvdd_control = VEGA10_VOLTAGE_CONTROL_NONE;
850 data->vddci_control = VEGA10_VOLTAGE_CONTROL_NONE;
851
852 /* VDDCR_SOC */
853 if (pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(hwmgr,
854 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2)) {
855 if (!pp_atomfwctrl_get_voltage_table_v4(hwmgr,
856 VOLTAGE_TYPE_VDDC, VOLTAGE_OBJ_SVID2,
857 &vol_table)) {
858 config_telemetry = ((vol_table.telemetry_slope << 8) & 0xff00) |
859 (vol_table.telemetry_offset & 0xff);
860 data->vddc_control = VEGA10_VOLTAGE_CONTROL_BY_SVID2;
861 }
862 } else {
863 kfree(hwmgr->backend);
864 hwmgr->backend = NULL;
865 PP_ASSERT_WITH_CODE(false,
866 "VDDCR_SOC is not SVID2!",
867 return -1);
868 }
869
870 /* MVDDC */
871 if (pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(hwmgr,
872 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2)) {
873 if (!pp_atomfwctrl_get_voltage_table_v4(hwmgr,
874 VOLTAGE_TYPE_MVDDC, VOLTAGE_OBJ_SVID2,
875 &vol_table)) {
876 config_telemetry |=
877 ((vol_table.telemetry_slope << 24) & 0xff000000) |
878 ((vol_table.telemetry_offset << 16) & 0xff0000);
879 data->mvdd_control = VEGA10_VOLTAGE_CONTROL_BY_SVID2;
880 }
881 }
882
883 /* VDDCI_MEM */
884 if (PP_CAP(PHM_PlatformCaps_ControlVDDCI)) {
885 if (pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(hwmgr,
886 VOLTAGE_TYPE_VDDCI, VOLTAGE_OBJ_GPIO_LUT))
887 data->vddci_control = VEGA10_VOLTAGE_CONTROL_BY_GPIO;
888 }
889
890 data->config_telemetry = config_telemetry;
891
892 vega10_set_features_platform_caps(hwmgr);
893
894 result = vega10_init_dpm_defaults(hwmgr);
895 if (result)
896 return result;
897
898 #ifdef PPLIB_VEGA10_EVV_SUPPORT
899 /* Get leakage voltage based on leakage ID. */
900 PP_ASSERT_WITH_CODE(!vega10_get_evv_voltages(hwmgr),
901 "Get EVV Voltage Failed. Abort Driver loading!",
902 return -1);
903 #endif
904
905 /* Patch our voltage dependency table with actual leakage voltage
906 * We need to perform leakage translation before it's used by other functions
907 */
908 vega10_complete_dependency_tables(hwmgr);
909
910 /* Parse pptable data read from VBIOS */
911 vega10_set_private_data_based_on_pptable(hwmgr);
912
913 data->is_tlu_enabled = false;
914
915 hwmgr->platform_descriptor.hardwareActivityPerformanceLevels =
916 VEGA10_MAX_HARDWARE_POWERLEVELS;
917 hwmgr->platform_descriptor.hardwarePerformanceLevels = 2;
918 hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
919
920 hwmgr->platform_descriptor.vbiosInterruptId = 0x20000400; /* IRQ_SOURCE1_SW_INT */
921 /* The true clock step depends on the frequency, typically 4.5 or 9 MHz. Here we use 5. */
922 hwmgr->platform_descriptor.clockStep.engineClock = 500;
923 hwmgr->platform_descriptor.clockStep.memoryClock = 500;
924
925 data->total_active_cus = adev->gfx.cu_info.number;
926 if (!hwmgr->not_vf)
927 return result;
928
929 /* Setup default Overdrive Fan control settings */
930 data->odn_fan_table.target_fan_speed =
931 hwmgr->thermal_controller.advanceFanControlParameters.usMaxFanRPM;
932 data->odn_fan_table.target_temperature =
933 hwmgr->thermal_controller.
934 advanceFanControlParameters.ucTargetTemperature;
935 data->odn_fan_table.min_performance_clock =
936 hwmgr->thermal_controller.advanceFanControlParameters.
937 ulMinFanSCLKAcousticLimit;
938 data->odn_fan_table.min_fan_limit =
939 hwmgr->thermal_controller.
940 advanceFanControlParameters.usFanPWMMinLimit *
941 hwmgr->thermal_controller.fanInfo.ulMaxRPM / 100;
942
943 data->mem_channels = (RREG32_SOC15(DF, 0, mmDF_CS_AON0_DramBaseAddress0) &
944 DF_CS_AON0_DramBaseAddress0__IntLvNumChan_MASK) >>
945 DF_CS_AON0_DramBaseAddress0__IntLvNumChan__SHIFT;
946 PP_ASSERT_WITH_CODE(data->mem_channels < ARRAY_SIZE(channel_number),
947 "Mem Channel Index Exceeded maximum!",
948 return -EINVAL);
949
950 return result;
951 }
952
vega10_init_sclk_threshold(struct pp_hwmgr * hwmgr)953 static int vega10_init_sclk_threshold(struct pp_hwmgr *hwmgr)
954 {
955 struct vega10_hwmgr *data = hwmgr->backend;
956
957 data->low_sclk_interrupt_threshold = 0;
958
959 return 0;
960 }
961
vega10_setup_dpm_led_config(struct pp_hwmgr * hwmgr)962 static int vega10_setup_dpm_led_config(struct pp_hwmgr *hwmgr)
963 {
964 struct vega10_hwmgr *data = hwmgr->backend;
965 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
966
967 struct pp_atomfwctrl_voltage_table table;
968 uint8_t i, j;
969 uint32_t mask = 0;
970 uint32_t tmp;
971 int32_t ret = 0;
972
973 ret = pp_atomfwctrl_get_voltage_table_v4(hwmgr, VOLTAGE_TYPE_LEDDPM,
974 VOLTAGE_OBJ_GPIO_LUT, &table);
975
976 if (!ret) {
977 tmp = table.mask_low;
978 for (i = 0, j = 0; i < 32; i++) {
979 if (tmp & 1) {
980 mask |= (uint32_t)(i << (8 * j));
981 if (++j >= 3)
982 break;
983 }
984 tmp >>= 1;
985 }
986 }
987
988 pp_table->LedPin0 = (uint8_t)(mask & 0xff);
989 pp_table->LedPin1 = (uint8_t)((mask >> 8) & 0xff);
990 pp_table->LedPin2 = (uint8_t)((mask >> 16) & 0xff);
991 return 0;
992 }
993
vega10_setup_asic_task(struct pp_hwmgr * hwmgr)994 static int vega10_setup_asic_task(struct pp_hwmgr *hwmgr)
995 {
996 if (!hwmgr->not_vf)
997 return 0;
998
999 PP_ASSERT_WITH_CODE(!vega10_init_sclk_threshold(hwmgr),
1000 "Failed to init sclk threshold!",
1001 return -EINVAL);
1002
1003 PP_ASSERT_WITH_CODE(!vega10_setup_dpm_led_config(hwmgr),
1004 "Failed to set up led dpm config!",
1005 return -EINVAL);
1006
1007 smum_send_msg_to_smc_with_parameter(hwmgr,
1008 PPSMC_MSG_NumOfDisplays,
1009 0,
1010 NULL);
1011
1012 return 0;
1013 }
1014
1015 /**
1016 * vega10_trim_voltage_table - Remove repeated voltage values and create table with unique values.
1017 *
1018 * @hwmgr: the address of the powerplay hardware manager.
1019 * @vol_table: the pointer to changing voltage table
1020 * return: 0 in success
1021 */
vega10_trim_voltage_table(struct pp_hwmgr * hwmgr,struct pp_atomfwctrl_voltage_table * vol_table)1022 static int vega10_trim_voltage_table(struct pp_hwmgr *hwmgr,
1023 struct pp_atomfwctrl_voltage_table *vol_table)
1024 {
1025 uint32_t i, j;
1026 uint16_t vvalue;
1027 bool found = false;
1028 struct pp_atomfwctrl_voltage_table *table;
1029
1030 PP_ASSERT_WITH_CODE(vol_table,
1031 "Voltage Table empty.", return -EINVAL);
1032 table = kzalloc_obj(struct pp_atomfwctrl_voltage_table);
1033
1034 if (!table)
1035 return -ENOMEM;
1036
1037 table->mask_low = vol_table->mask_low;
1038 table->phase_delay = vol_table->phase_delay;
1039
1040 for (i = 0; i < vol_table->count; i++) {
1041 vvalue = vol_table->entries[i].value;
1042 found = false;
1043
1044 for (j = 0; j < table->count; j++) {
1045 if (vvalue == table->entries[j].value) {
1046 found = true;
1047 break;
1048 }
1049 }
1050
1051 if (!found) {
1052 table->entries[table->count].value = vvalue;
1053 table->entries[table->count].smio_low =
1054 vol_table->entries[i].smio_low;
1055 table->count++;
1056 }
1057 }
1058
1059 memcpy(vol_table, table, sizeof(struct pp_atomfwctrl_voltage_table));
1060 kfree(table);
1061
1062 return 0;
1063 }
1064
vega10_get_mvdd_voltage_table(struct pp_hwmgr * hwmgr,phm_ppt_v1_clock_voltage_dependency_table * dep_table,struct pp_atomfwctrl_voltage_table * vol_table)1065 static int vega10_get_mvdd_voltage_table(struct pp_hwmgr *hwmgr,
1066 phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1067 struct pp_atomfwctrl_voltage_table *vol_table)
1068 {
1069 int i;
1070
1071 PP_ASSERT_WITH_CODE(dep_table->count,
1072 "Voltage Dependency Table empty.",
1073 return -EINVAL);
1074
1075 vol_table->mask_low = 0;
1076 vol_table->phase_delay = 0;
1077 vol_table->count = dep_table->count;
1078
1079 for (i = 0; i < vol_table->count; i++) {
1080 vol_table->entries[i].value = dep_table->entries[i].mvdd;
1081 vol_table->entries[i].smio_low = 0;
1082 }
1083
1084 PP_ASSERT_WITH_CODE(!vega10_trim_voltage_table(hwmgr,
1085 vol_table),
1086 "Failed to trim MVDD Table!",
1087 return -1);
1088
1089 return 0;
1090 }
1091
vega10_get_vddci_voltage_table(struct pp_hwmgr * hwmgr,phm_ppt_v1_clock_voltage_dependency_table * dep_table,struct pp_atomfwctrl_voltage_table * vol_table)1092 static int vega10_get_vddci_voltage_table(struct pp_hwmgr *hwmgr,
1093 phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1094 struct pp_atomfwctrl_voltage_table *vol_table)
1095 {
1096 uint32_t i;
1097
1098 PP_ASSERT_WITH_CODE(dep_table->count,
1099 "Voltage Dependency Table empty.",
1100 return -EINVAL);
1101
1102 vol_table->mask_low = 0;
1103 vol_table->phase_delay = 0;
1104 vol_table->count = dep_table->count;
1105
1106 for (i = 0; i < dep_table->count; i++) {
1107 vol_table->entries[i].value = dep_table->entries[i].vddci;
1108 vol_table->entries[i].smio_low = 0;
1109 }
1110
1111 PP_ASSERT_WITH_CODE(!vega10_trim_voltage_table(hwmgr, vol_table),
1112 "Failed to trim VDDCI table.",
1113 return -1);
1114
1115 return 0;
1116 }
1117
vega10_get_vdd_voltage_table(struct pp_hwmgr * hwmgr,phm_ppt_v1_clock_voltage_dependency_table * dep_table,struct pp_atomfwctrl_voltage_table * vol_table)1118 static int vega10_get_vdd_voltage_table(struct pp_hwmgr *hwmgr,
1119 phm_ppt_v1_clock_voltage_dependency_table *dep_table,
1120 struct pp_atomfwctrl_voltage_table *vol_table)
1121 {
1122 int i;
1123
1124 PP_ASSERT_WITH_CODE(dep_table->count,
1125 "Voltage Dependency Table empty.",
1126 return -EINVAL);
1127
1128 vol_table->mask_low = 0;
1129 vol_table->phase_delay = 0;
1130 vol_table->count = dep_table->count;
1131
1132 for (i = 0; i < vol_table->count; i++) {
1133 vol_table->entries[i].value = dep_table->entries[i].vddc;
1134 vol_table->entries[i].smio_low = 0;
1135 }
1136
1137 return 0;
1138 }
1139
1140 /* ---- Voltage Tables ----
1141 * If the voltage table would be bigger than
1142 * what will fit into the state table on
1143 * the SMC keep only the higher entries.
1144 */
vega10_trim_voltage_table_to_fit_state_table(struct pp_hwmgr * hwmgr,uint32_t max_vol_steps,struct pp_atomfwctrl_voltage_table * vol_table)1145 static void vega10_trim_voltage_table_to_fit_state_table(
1146 struct pp_hwmgr *hwmgr,
1147 uint32_t max_vol_steps,
1148 struct pp_atomfwctrl_voltage_table *vol_table)
1149 {
1150 unsigned int i, diff;
1151
1152 if (vol_table->count <= max_vol_steps)
1153 return;
1154
1155 diff = vol_table->count - max_vol_steps;
1156
1157 for (i = 0; i < max_vol_steps; i++)
1158 vol_table->entries[i] = vol_table->entries[i + diff];
1159
1160 vol_table->count = max_vol_steps;
1161 }
1162
1163 /**
1164 * vega10_construct_voltage_tables - Create Voltage Tables.
1165 *
1166 * @hwmgr: the address of the powerplay hardware manager.
1167 * return: always 0
1168 */
vega10_construct_voltage_tables(struct pp_hwmgr * hwmgr)1169 static int vega10_construct_voltage_tables(struct pp_hwmgr *hwmgr)
1170 {
1171 struct vega10_hwmgr *data = hwmgr->backend;
1172 struct phm_ppt_v2_information *table_info =
1173 (struct phm_ppt_v2_information *)hwmgr->pptable;
1174 int result;
1175
1176 if (data->mvdd_control == VEGA10_VOLTAGE_CONTROL_BY_SVID2 ||
1177 data->mvdd_control == VEGA10_VOLTAGE_CONTROL_NONE) {
1178 result = vega10_get_mvdd_voltage_table(hwmgr,
1179 table_info->vdd_dep_on_mclk,
1180 &(data->mvdd_voltage_table));
1181 PP_ASSERT_WITH_CODE(!result,
1182 "Failed to retrieve MVDDC table!",
1183 return result);
1184 }
1185
1186 if (data->vddci_control == VEGA10_VOLTAGE_CONTROL_NONE) {
1187 result = vega10_get_vddci_voltage_table(hwmgr,
1188 table_info->vdd_dep_on_mclk,
1189 &(data->vddci_voltage_table));
1190 PP_ASSERT_WITH_CODE(!result,
1191 "Failed to retrieve VDDCI_MEM table!",
1192 return result);
1193 }
1194
1195 if (data->vddc_control == VEGA10_VOLTAGE_CONTROL_BY_SVID2 ||
1196 data->vddc_control == VEGA10_VOLTAGE_CONTROL_NONE) {
1197 result = vega10_get_vdd_voltage_table(hwmgr,
1198 table_info->vdd_dep_on_sclk,
1199 &(data->vddc_voltage_table));
1200 PP_ASSERT_WITH_CODE(!result,
1201 "Failed to retrieve VDDCR_SOC table!",
1202 return result);
1203 }
1204
1205 PP_ASSERT_WITH_CODE(data->vddc_voltage_table.count <= 16,
1206 "Too many voltage values for VDDC. Trimming to fit state table.",
1207 vega10_trim_voltage_table_to_fit_state_table(hwmgr,
1208 16, &(data->vddc_voltage_table)));
1209
1210 PP_ASSERT_WITH_CODE(data->vddci_voltage_table.count <= 16,
1211 "Too many voltage values for VDDCI. Trimming to fit state table.",
1212 vega10_trim_voltage_table_to_fit_state_table(hwmgr,
1213 16, &(data->vddci_voltage_table)));
1214
1215 PP_ASSERT_WITH_CODE(data->mvdd_voltage_table.count <= 16,
1216 "Too many voltage values for MVDD. Trimming to fit state table.",
1217 vega10_trim_voltage_table_to_fit_state_table(hwmgr,
1218 16, &(data->mvdd_voltage_table)));
1219
1220
1221 return 0;
1222 }
1223
1224 /*
1225 * vega10_init_dpm_state
1226 * Function to initialize all Soft Min/Max and Hard Min/Max to 0xff.
1227 *
1228 * @dpm_state: - the address of the DPM Table to initiailize.
1229 * return: None.
1230 */
vega10_init_dpm_state(struct vega10_dpm_state * dpm_state)1231 static void vega10_init_dpm_state(struct vega10_dpm_state *dpm_state)
1232 {
1233 dpm_state->soft_min_level = 0xff;
1234 dpm_state->soft_max_level = 0xff;
1235 dpm_state->hard_min_level = 0xff;
1236 dpm_state->hard_max_level = 0xff;
1237 }
1238
vega10_setup_default_single_dpm_table(struct pp_hwmgr * hwmgr,struct vega10_single_dpm_table * dpm_table,struct phm_ppt_v1_clock_voltage_dependency_table * dep_table)1239 static void vega10_setup_default_single_dpm_table(struct pp_hwmgr *hwmgr,
1240 struct vega10_single_dpm_table *dpm_table,
1241 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table)
1242 {
1243 int i;
1244
1245 dpm_table->count = 0;
1246
1247 for (i = 0; i < dep_table->count; i++) {
1248 if (i == 0 || dpm_table->dpm_levels[dpm_table->count - 1].value <=
1249 dep_table->entries[i].clk) {
1250 dpm_table->dpm_levels[dpm_table->count].value =
1251 dep_table->entries[i].clk;
1252 dpm_table->dpm_levels[dpm_table->count].enabled = true;
1253 dpm_table->count++;
1254 }
1255 }
1256 }
vega10_setup_default_pcie_table(struct pp_hwmgr * hwmgr)1257 static int vega10_setup_default_pcie_table(struct pp_hwmgr *hwmgr)
1258 {
1259 struct vega10_hwmgr *data = hwmgr->backend;
1260 struct vega10_pcie_table *pcie_table = &(data->dpm_table.pcie_table);
1261 struct phm_ppt_v2_information *table_info =
1262 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1263 struct phm_ppt_v1_pcie_table *bios_pcie_table =
1264 table_info->pcie_table;
1265 uint32_t i;
1266
1267 PP_ASSERT_WITH_CODE(bios_pcie_table->count,
1268 "Incorrect number of PCIE States from VBIOS!",
1269 return -1);
1270
1271 for (i = 0; i < NUM_LINK_LEVELS; i++) {
1272 if (data->registry_data.pcieSpeedOverride)
1273 pcie_table->pcie_gen[i] =
1274 data->registry_data.pcieSpeedOverride;
1275 else
1276 pcie_table->pcie_gen[i] =
1277 bios_pcie_table->entries[i].gen_speed;
1278
1279 if (data->registry_data.pcieLaneOverride)
1280 pcie_table->pcie_lane[i] = (uint8_t)encode_pcie_lane_width(
1281 data->registry_data.pcieLaneOverride);
1282 else
1283 pcie_table->pcie_lane[i] = (uint8_t)encode_pcie_lane_width(
1284 bios_pcie_table->entries[i].lane_width);
1285 if (data->registry_data.pcieClockOverride)
1286 pcie_table->lclk[i] =
1287 data->registry_data.pcieClockOverride;
1288 else
1289 pcie_table->lclk[i] =
1290 bios_pcie_table->entries[i].pcie_sclk;
1291 }
1292
1293 pcie_table->count = NUM_LINK_LEVELS;
1294
1295 return 0;
1296 }
1297
1298 /*
1299 * This function is to initialize all DPM state tables
1300 * for SMU based on the dependency table.
1301 * Dynamic state patching function will then trim these
1302 * state tables to the allowed range based
1303 * on the power policy or external client requests,
1304 * such as UVD request, etc.
1305 */
vega10_setup_default_dpm_tables(struct pp_hwmgr * hwmgr)1306 static int vega10_setup_default_dpm_tables(struct pp_hwmgr *hwmgr)
1307 {
1308 struct vega10_hwmgr *data = hwmgr->backend;
1309 struct phm_ppt_v2_information *table_info =
1310 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1311 struct vega10_single_dpm_table *dpm_table;
1312 uint32_t i;
1313
1314 struct phm_ppt_v1_clock_voltage_dependency_table *dep_soc_table =
1315 table_info->vdd_dep_on_socclk;
1316 struct phm_ppt_v1_clock_voltage_dependency_table *dep_gfx_table =
1317 table_info->vdd_dep_on_sclk;
1318 struct phm_ppt_v1_clock_voltage_dependency_table *dep_mclk_table =
1319 table_info->vdd_dep_on_mclk;
1320 struct phm_ppt_v1_mm_clock_voltage_dependency_table *dep_mm_table =
1321 table_info->mm_dep_table;
1322 struct phm_ppt_v1_clock_voltage_dependency_table *dep_dcef_table =
1323 table_info->vdd_dep_on_dcefclk;
1324 struct phm_ppt_v1_clock_voltage_dependency_table *dep_pix_table =
1325 table_info->vdd_dep_on_pixclk;
1326 struct phm_ppt_v1_clock_voltage_dependency_table *dep_disp_table =
1327 table_info->vdd_dep_on_dispclk;
1328 struct phm_ppt_v1_clock_voltage_dependency_table *dep_phy_table =
1329 table_info->vdd_dep_on_phyclk;
1330
1331 PP_ASSERT_WITH_CODE(dep_soc_table,
1332 "SOCCLK dependency table is missing. This table is mandatory",
1333 return -EINVAL);
1334 PP_ASSERT_WITH_CODE(dep_soc_table->count >= 1,
1335 "SOCCLK dependency table is empty. This table is mandatory",
1336 return -EINVAL);
1337
1338 PP_ASSERT_WITH_CODE(dep_gfx_table,
1339 "GFXCLK dependency table is missing. This table is mandatory",
1340 return -EINVAL);
1341 PP_ASSERT_WITH_CODE(dep_gfx_table->count >= 1,
1342 "GFXCLK dependency table is empty. This table is mandatory",
1343 return -EINVAL);
1344
1345 PP_ASSERT_WITH_CODE(dep_mclk_table,
1346 "MCLK dependency table is missing. This table is mandatory",
1347 return -EINVAL);
1348 PP_ASSERT_WITH_CODE(dep_mclk_table->count >= 1,
1349 "MCLK dependency table has to have is missing. This table is mandatory",
1350 return -EINVAL);
1351
1352 /* Initialize Sclk DPM table based on allow Sclk values */
1353 dpm_table = &(data->dpm_table.soc_table);
1354 vega10_setup_default_single_dpm_table(hwmgr,
1355 dpm_table,
1356 dep_soc_table);
1357
1358 vega10_init_dpm_state(&(dpm_table->dpm_state));
1359
1360 dpm_table = &(data->dpm_table.gfx_table);
1361 vega10_setup_default_single_dpm_table(hwmgr,
1362 dpm_table,
1363 dep_gfx_table);
1364 if (hwmgr->platform_descriptor.overdriveLimit.engineClock == 0)
1365 hwmgr->platform_descriptor.overdriveLimit.engineClock =
1366 dpm_table->dpm_levels[dpm_table->count-1].value;
1367 vega10_init_dpm_state(&(dpm_table->dpm_state));
1368
1369 /* Initialize Mclk DPM table based on allow Mclk values */
1370 data->dpm_table.mem_table.count = 0;
1371 dpm_table = &(data->dpm_table.mem_table);
1372 vega10_setup_default_single_dpm_table(hwmgr,
1373 dpm_table,
1374 dep_mclk_table);
1375 if (hwmgr->platform_descriptor.overdriveLimit.memoryClock == 0)
1376 hwmgr->platform_descriptor.overdriveLimit.memoryClock =
1377 dpm_table->dpm_levels[dpm_table->count-1].value;
1378 vega10_init_dpm_state(&(dpm_table->dpm_state));
1379
1380 data->dpm_table.eclk_table.count = 0;
1381 dpm_table = &(data->dpm_table.eclk_table);
1382 for (i = 0; i < dep_mm_table->count; i++) {
1383 if (i == 0 || dpm_table->dpm_levels
1384 [dpm_table->count - 1].value <=
1385 dep_mm_table->entries[i].eclk) {
1386 dpm_table->dpm_levels[dpm_table->count].value =
1387 dep_mm_table->entries[i].eclk;
1388 dpm_table->dpm_levels[dpm_table->count].enabled = i == 0;
1389 dpm_table->count++;
1390 }
1391 }
1392 vega10_init_dpm_state(&(dpm_table->dpm_state));
1393
1394 data->dpm_table.vclk_table.count = 0;
1395 data->dpm_table.dclk_table.count = 0;
1396 dpm_table = &(data->dpm_table.vclk_table);
1397 for (i = 0; i < dep_mm_table->count; i++) {
1398 if (i == 0 || dpm_table->dpm_levels
1399 [dpm_table->count - 1].value <=
1400 dep_mm_table->entries[i].vclk) {
1401 dpm_table->dpm_levels[dpm_table->count].value =
1402 dep_mm_table->entries[i].vclk;
1403 dpm_table->dpm_levels[dpm_table->count].enabled = i == 0;
1404 dpm_table->count++;
1405 }
1406 }
1407 vega10_init_dpm_state(&(dpm_table->dpm_state));
1408
1409 dpm_table = &(data->dpm_table.dclk_table);
1410 for (i = 0; i < dep_mm_table->count; i++) {
1411 if (i == 0 || dpm_table->dpm_levels
1412 [dpm_table->count - 1].value <=
1413 dep_mm_table->entries[i].dclk) {
1414 dpm_table->dpm_levels[dpm_table->count].value =
1415 dep_mm_table->entries[i].dclk;
1416 dpm_table->dpm_levels[dpm_table->count].enabled = i == 0;
1417 dpm_table->count++;
1418 }
1419 }
1420 vega10_init_dpm_state(&(dpm_table->dpm_state));
1421
1422 /* Assume there is no headless Vega10 for now */
1423 dpm_table = &(data->dpm_table.dcef_table);
1424 vega10_setup_default_single_dpm_table(hwmgr,
1425 dpm_table,
1426 dep_dcef_table);
1427
1428 vega10_init_dpm_state(&(dpm_table->dpm_state));
1429
1430 dpm_table = &(data->dpm_table.pixel_table);
1431 vega10_setup_default_single_dpm_table(hwmgr,
1432 dpm_table,
1433 dep_pix_table);
1434
1435 vega10_init_dpm_state(&(dpm_table->dpm_state));
1436
1437 dpm_table = &(data->dpm_table.display_table);
1438 vega10_setup_default_single_dpm_table(hwmgr,
1439 dpm_table,
1440 dep_disp_table);
1441
1442 vega10_init_dpm_state(&(dpm_table->dpm_state));
1443
1444 dpm_table = &(data->dpm_table.phy_table);
1445 vega10_setup_default_single_dpm_table(hwmgr,
1446 dpm_table,
1447 dep_phy_table);
1448
1449 vega10_init_dpm_state(&(dpm_table->dpm_state));
1450
1451 vega10_setup_default_pcie_table(hwmgr);
1452
1453 /* Zero out the saved copy of the CUSTOM profile
1454 * This will be checked when trying to set the profile
1455 * and will require that new values be passed in
1456 */
1457 data->custom_profile_mode[0] = 0;
1458 data->custom_profile_mode[1] = 0;
1459 data->custom_profile_mode[2] = 0;
1460 data->custom_profile_mode[3] = 0;
1461
1462 /* save a copy of the default DPM table */
1463 memcpy(&(data->golden_dpm_table), &(data->dpm_table),
1464 sizeof(struct vega10_dpm_table));
1465
1466 return 0;
1467 }
1468
1469 /*
1470 * vega10_populate_ulv_state
1471 * Function to provide parameters for Utral Low Voltage state to SMC.
1472 *
1473 * @hwmgr: - the address of the hardware manager.
1474 * return: Always 0.
1475 */
vega10_populate_ulv_state(struct pp_hwmgr * hwmgr)1476 static int vega10_populate_ulv_state(struct pp_hwmgr *hwmgr)
1477 {
1478 struct vega10_hwmgr *data = hwmgr->backend;
1479 struct phm_ppt_v2_information *table_info =
1480 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1481
1482 data->smc_state_table.pp_table.UlvOffsetVid =
1483 (uint8_t)table_info->us_ulv_voltage_offset;
1484
1485 data->smc_state_table.pp_table.UlvSmnclkDid =
1486 (uint8_t)(table_info->us_ulv_smnclk_did);
1487 data->smc_state_table.pp_table.UlvMp1clkDid =
1488 (uint8_t)(table_info->us_ulv_mp1clk_did);
1489 data->smc_state_table.pp_table.UlvGfxclkBypass =
1490 (uint8_t)(table_info->us_ulv_gfxclk_bypass);
1491 data->smc_state_table.pp_table.UlvPhaseSheddingPsi0 =
1492 (uint8_t)(data->vddc_voltage_table.psi0_enable);
1493 data->smc_state_table.pp_table.UlvPhaseSheddingPsi1 =
1494 (uint8_t)(data->vddc_voltage_table.psi1_enable);
1495
1496 return 0;
1497 }
1498
vega10_populate_single_lclk_level(struct pp_hwmgr * hwmgr,uint32_t lclock,uint8_t * curr_lclk_did)1499 static int vega10_populate_single_lclk_level(struct pp_hwmgr *hwmgr,
1500 uint32_t lclock, uint8_t *curr_lclk_did)
1501 {
1502 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1503
1504 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(
1505 hwmgr,
1506 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1507 lclock, ÷rs),
1508 "Failed to get LCLK clock settings from VBIOS!",
1509 return -1);
1510
1511 *curr_lclk_did = dividers.ulDid;
1512
1513 return 0;
1514 }
1515
vega10_override_pcie_parameters(struct pp_hwmgr * hwmgr)1516 static int vega10_override_pcie_parameters(struct pp_hwmgr *hwmgr)
1517 {
1518 struct amdgpu_device *adev = (struct amdgpu_device *)(hwmgr->adev);
1519 struct vega10_hwmgr *data =
1520 (struct vega10_hwmgr *)(hwmgr->backend);
1521 uint32_t pcie_gen = 0, pcie_width = 0;
1522 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1523 int i;
1524
1525 if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN4)
1526 pcie_gen = 3;
1527 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
1528 pcie_gen = 2;
1529 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
1530 pcie_gen = 1;
1531 else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1)
1532 pcie_gen = 0;
1533
1534 if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X16)
1535 pcie_width = 6;
1536 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X12)
1537 pcie_width = 5;
1538 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X8)
1539 pcie_width = 4;
1540 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X4)
1541 pcie_width = 3;
1542 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X2)
1543 pcie_width = 2;
1544 else if (adev->pm.pcie_mlw_mask & CAIL_PCIE_LINK_WIDTH_SUPPORT_X1)
1545 pcie_width = 1;
1546
1547 for (i = 0; i < NUM_LINK_LEVELS; i++) {
1548 if (pp_table->PcieGenSpeed[i] > pcie_gen)
1549 pp_table->PcieGenSpeed[i] = pcie_gen;
1550
1551 if (pp_table->PcieLaneCount[i] > pcie_width)
1552 pp_table->PcieLaneCount[i] = pcie_width;
1553 }
1554
1555 if (data->registry_data.pcie_dpm_key_disabled) {
1556 for (i = 0; i < NUM_LINK_LEVELS; i++) {
1557 pp_table->PcieGenSpeed[i] = pcie_gen;
1558 pp_table->PcieLaneCount[i] = pcie_width;
1559 }
1560 }
1561
1562 return 0;
1563 }
1564
vega10_populate_smc_link_levels(struct pp_hwmgr * hwmgr)1565 static int vega10_populate_smc_link_levels(struct pp_hwmgr *hwmgr)
1566 {
1567 int result = -1;
1568 struct vega10_hwmgr *data = hwmgr->backend;
1569 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1570 struct vega10_pcie_table *pcie_table =
1571 &(data->dpm_table.pcie_table);
1572 uint32_t i, j;
1573
1574 for (i = 0; i < pcie_table->count; i++) {
1575 pp_table->PcieGenSpeed[i] = pcie_table->pcie_gen[i];
1576 pp_table->PcieLaneCount[i] = pcie_table->pcie_lane[i];
1577
1578 result = vega10_populate_single_lclk_level(hwmgr,
1579 pcie_table->lclk[i], &(pp_table->LclkDid[i]));
1580 if (result) {
1581 pr_info("Populate LClock Level %d Failed!\n", i);
1582 return result;
1583 }
1584 }
1585
1586 j = i - 1;
1587 while (i < NUM_LINK_LEVELS) {
1588 pp_table->PcieGenSpeed[i] = pcie_table->pcie_gen[j];
1589 pp_table->PcieLaneCount[i] = pcie_table->pcie_lane[j];
1590
1591 result = vega10_populate_single_lclk_level(hwmgr,
1592 pcie_table->lclk[j], &(pp_table->LclkDid[i]));
1593 if (result) {
1594 pr_info("Populate LClock Level %d Failed!\n", i);
1595 return result;
1596 }
1597 i++;
1598 }
1599
1600 return result;
1601 }
1602
1603 /**
1604 * vega10_populate_single_gfx_level - Populates single SMC GFXSCLK structure
1605 * using the provided engine clock
1606 *
1607 * @hwmgr: the address of the hardware manager
1608 * @gfx_clock: the GFX clock to use to populate the structure.
1609 * @current_gfxclk_level: location in PPTable for the SMC GFXCLK structure.
1610 * @acg_freq: ACG frequenty to return (MHz)
1611 */
vega10_populate_single_gfx_level(struct pp_hwmgr * hwmgr,uint32_t gfx_clock,PllSetting_t * current_gfxclk_level,uint32_t * acg_freq)1612 static int vega10_populate_single_gfx_level(struct pp_hwmgr *hwmgr,
1613 uint32_t gfx_clock, PllSetting_t *current_gfxclk_level,
1614 uint32_t *acg_freq)
1615 {
1616 struct phm_ppt_v2_information *table_info =
1617 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1618 struct phm_ppt_v1_clock_voltage_dependency_table *dep_on_sclk;
1619 struct vega10_hwmgr *data = hwmgr->backend;
1620 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1621 uint32_t gfx_max_clock =
1622 hwmgr->platform_descriptor.overdriveLimit.engineClock;
1623 uint32_t i = 0;
1624
1625 if (hwmgr->od_enabled)
1626 dep_on_sclk = (struct phm_ppt_v1_clock_voltage_dependency_table *)
1627 &(data->odn_dpm_table.vdd_dep_on_sclk);
1628 else
1629 dep_on_sclk = table_info->vdd_dep_on_sclk;
1630
1631 PP_ASSERT_WITH_CODE(dep_on_sclk,
1632 "Invalid SOC_VDD-GFX_CLK Dependency Table!",
1633 return -EINVAL);
1634
1635 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_SCLK)
1636 gfx_clock = gfx_clock > gfx_max_clock ? gfx_max_clock : gfx_clock;
1637 else {
1638 for (i = 0; i < dep_on_sclk->count; i++) {
1639 if (dep_on_sclk->entries[i].clk == gfx_clock)
1640 break;
1641 }
1642 PP_ASSERT_WITH_CODE(dep_on_sclk->count > i,
1643 "Cannot find gfx_clk in SOC_VDD-GFX_CLK!",
1644 return -EINVAL);
1645 }
1646
1647 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1648 COMPUTE_GPUCLK_INPUT_FLAG_GFXCLK,
1649 gfx_clock, ÷rs),
1650 "Failed to get GFX Clock settings from VBIOS!",
1651 return -EINVAL);
1652
1653 /* Feedback Multiplier: bit 0:8 int, bit 15:12 post_div, bit 31:16 frac */
1654 current_gfxclk_level->FbMult =
1655 cpu_to_le32(dividers.ulPll_fb_mult);
1656 /* Spread FB Multiplier bit: bit 0:8 int, bit 31:16 frac */
1657 current_gfxclk_level->SsOn = dividers.ucPll_ss_enable;
1658 current_gfxclk_level->SsFbMult =
1659 cpu_to_le32(dividers.ulPll_ss_fbsmult);
1660 current_gfxclk_level->SsSlewFrac =
1661 cpu_to_le16(dividers.usPll_ss_slew_frac);
1662 current_gfxclk_level->Did = (uint8_t)(dividers.ulDid);
1663
1664 *acg_freq = gfx_clock / 100; /* 100 Khz to Mhz conversion */
1665
1666 return 0;
1667 }
1668
1669 /**
1670 * vega10_populate_single_soc_level - Populates single SMC SOCCLK structure
1671 * using the provided clock.
1672 *
1673 * @hwmgr: the address of the hardware manager.
1674 * @soc_clock: the SOC clock to use to populate the structure.
1675 * @current_soc_did: DFS divider to pass back to caller
1676 * @current_vol_index: index of current VDD to pass back to caller
1677 * return: 0 on success
1678 */
vega10_populate_single_soc_level(struct pp_hwmgr * hwmgr,uint32_t soc_clock,uint8_t * current_soc_did,uint8_t * current_vol_index)1679 static int vega10_populate_single_soc_level(struct pp_hwmgr *hwmgr,
1680 uint32_t soc_clock, uint8_t *current_soc_did,
1681 uint8_t *current_vol_index)
1682 {
1683 struct vega10_hwmgr *data = hwmgr->backend;
1684 struct phm_ppt_v2_information *table_info =
1685 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1686 struct phm_ppt_v1_clock_voltage_dependency_table *dep_on_soc;
1687 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1688 uint32_t i;
1689
1690 if (hwmgr->od_enabled) {
1691 dep_on_soc = (struct phm_ppt_v1_clock_voltage_dependency_table *)
1692 &data->odn_dpm_table.vdd_dep_on_socclk;
1693 for (i = 0; i < dep_on_soc->count; i++) {
1694 if (dep_on_soc->entries[i].clk >= soc_clock)
1695 break;
1696 }
1697 } else {
1698 dep_on_soc = table_info->vdd_dep_on_socclk;
1699 for (i = 0; i < dep_on_soc->count; i++) {
1700 if (dep_on_soc->entries[i].clk == soc_clock)
1701 break;
1702 }
1703 }
1704
1705 PP_ASSERT_WITH_CODE(dep_on_soc->count > i,
1706 "Cannot find SOC_CLK in SOC_VDD-SOC_CLK Dependency Table",
1707 return -EINVAL);
1708
1709 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
1710 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
1711 soc_clock, ÷rs),
1712 "Failed to get SOC Clock settings from VBIOS!",
1713 return -EINVAL);
1714
1715 *current_soc_did = (uint8_t)dividers.ulDid;
1716 *current_vol_index = (uint8_t)(dep_on_soc->entries[i].vddInd);
1717 return 0;
1718 }
1719
1720 /**
1721 * vega10_populate_all_graphic_levels - Populates all SMC SCLK levels' structure
1722 * based on the trimmed allowed dpm engine clock states
1723 *
1724 * @hwmgr: the address of the hardware manager
1725 */
vega10_populate_all_graphic_levels(struct pp_hwmgr * hwmgr)1726 static int vega10_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
1727 {
1728 struct vega10_hwmgr *data = hwmgr->backend;
1729 struct phm_ppt_v2_information *table_info =
1730 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1731 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1732 struct vega10_single_dpm_table *dpm_table = &(data->dpm_table.gfx_table);
1733 int result = 0;
1734 uint32_t i, j;
1735
1736 for (i = 0; i < dpm_table->count; i++) {
1737 result = vega10_populate_single_gfx_level(hwmgr,
1738 dpm_table->dpm_levels[i].value,
1739 &(pp_table->GfxclkLevel[i]),
1740 &(pp_table->AcgFreqTable[i]));
1741 if (result)
1742 return result;
1743 }
1744
1745 j = i - 1;
1746 while (i < NUM_GFXCLK_DPM_LEVELS) {
1747 result = vega10_populate_single_gfx_level(hwmgr,
1748 dpm_table->dpm_levels[j].value,
1749 &(pp_table->GfxclkLevel[i]),
1750 &(pp_table->AcgFreqTable[i]));
1751 if (result)
1752 return result;
1753 i++;
1754 }
1755
1756 pp_table->GfxclkSlewRate =
1757 cpu_to_le16(table_info->us_gfxclk_slew_rate);
1758
1759 dpm_table = &(data->dpm_table.soc_table);
1760 for (i = 0; i < dpm_table->count; i++) {
1761 result = vega10_populate_single_soc_level(hwmgr,
1762 dpm_table->dpm_levels[i].value,
1763 &(pp_table->SocclkDid[i]),
1764 &(pp_table->SocDpmVoltageIndex[i]));
1765 if (result)
1766 return result;
1767 }
1768
1769 j = i - 1;
1770 while (i < NUM_SOCCLK_DPM_LEVELS) {
1771 result = vega10_populate_single_soc_level(hwmgr,
1772 dpm_table->dpm_levels[j].value,
1773 &(pp_table->SocclkDid[i]),
1774 &(pp_table->SocDpmVoltageIndex[i]));
1775 if (result)
1776 return result;
1777 i++;
1778 }
1779
1780 return result;
1781 }
1782
vega10_populate_vddc_soc_levels(struct pp_hwmgr * hwmgr)1783 static void vega10_populate_vddc_soc_levels(struct pp_hwmgr *hwmgr)
1784 {
1785 struct vega10_hwmgr *data = hwmgr->backend;
1786 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1787 struct phm_ppt_v2_information *table_info = hwmgr->pptable;
1788 struct phm_ppt_v1_voltage_lookup_table *vddc_lookup_table;
1789
1790 uint8_t soc_vid = 0;
1791 uint32_t i, max_vddc_level;
1792
1793 if (hwmgr->od_enabled)
1794 vddc_lookup_table = (struct phm_ppt_v1_voltage_lookup_table *)&data->odn_dpm_table.vddc_lookup_table;
1795 else
1796 vddc_lookup_table = table_info->vddc_lookup_table;
1797
1798 max_vddc_level = vddc_lookup_table->count;
1799 for (i = 0; i < max_vddc_level; i++) {
1800 soc_vid = (uint8_t)convert_to_vid(vddc_lookup_table->entries[i].us_vdd);
1801 pp_table->SocVid[i] = soc_vid;
1802 }
1803 while (i < MAX_REGULAR_DPM_NUMBER) {
1804 pp_table->SocVid[i] = soc_vid;
1805 i++;
1806 }
1807 }
1808
1809 /*
1810 * Populates single SMC GFXCLK structure using the provided clock.
1811 *
1812 * @hwmgr: the address of the hardware manager.
1813 * @mem_clock: the memory clock to use to populate the structure.
1814 * return: 0 on success..
1815 */
vega10_populate_single_memory_level(struct pp_hwmgr * hwmgr,uint32_t mem_clock,uint8_t * current_mem_vid,PllSetting_t * current_memclk_level,uint8_t * current_mem_soc_vind)1816 static int vega10_populate_single_memory_level(struct pp_hwmgr *hwmgr,
1817 uint32_t mem_clock, uint8_t *current_mem_vid,
1818 PllSetting_t *current_memclk_level, uint8_t *current_mem_soc_vind)
1819 {
1820 struct vega10_hwmgr *data = hwmgr->backend;
1821 struct phm_ppt_v2_information *table_info =
1822 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1823 struct phm_ppt_v1_clock_voltage_dependency_table *dep_on_mclk;
1824 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1825 uint32_t mem_max_clock =
1826 hwmgr->platform_descriptor.overdriveLimit.memoryClock;
1827 uint32_t i = 0;
1828
1829 if (hwmgr->od_enabled)
1830 dep_on_mclk = (struct phm_ppt_v1_clock_voltage_dependency_table *)
1831 &data->odn_dpm_table.vdd_dep_on_mclk;
1832 else
1833 dep_on_mclk = table_info->vdd_dep_on_mclk;
1834
1835 PP_ASSERT_WITH_CODE(dep_on_mclk,
1836 "Invalid SOC_VDD-UCLK Dependency Table!",
1837 return -EINVAL);
1838
1839 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
1840 mem_clock = mem_clock > mem_max_clock ? mem_max_clock : mem_clock;
1841 } else {
1842 for (i = 0; i < dep_on_mclk->count; i++) {
1843 if (dep_on_mclk->entries[i].clk == mem_clock)
1844 break;
1845 }
1846 PP_ASSERT_WITH_CODE(dep_on_mclk->count > i,
1847 "Cannot find UCLK in SOC_VDD-UCLK Dependency Table!",
1848 return -EINVAL);
1849 }
1850
1851 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(
1852 hwmgr, COMPUTE_GPUCLK_INPUT_FLAG_UCLK, mem_clock, ÷rs),
1853 "Failed to get UCLK settings from VBIOS!",
1854 return -1);
1855
1856 *current_mem_vid =
1857 (uint8_t)(convert_to_vid(dep_on_mclk->entries[i].mvdd));
1858 *current_mem_soc_vind =
1859 (uint8_t)(dep_on_mclk->entries[i].vddInd);
1860 current_memclk_level->FbMult = cpu_to_le32(dividers.ulPll_fb_mult);
1861 current_memclk_level->Did = (uint8_t)(dividers.ulDid);
1862
1863 PP_ASSERT_WITH_CODE(current_memclk_level->Did >= 1,
1864 "Invalid Divider ID!",
1865 return -EINVAL);
1866
1867 return 0;
1868 }
1869
1870 /**
1871 * vega10_populate_all_memory_levels - Populates all SMC MCLK levels' structure
1872 * based on the trimmed allowed dpm memory clock states.
1873 *
1874 * @hwmgr: the address of the hardware manager.
1875 * return: PP_Result_OK on success.
1876 */
vega10_populate_all_memory_levels(struct pp_hwmgr * hwmgr)1877 static int vega10_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1878 {
1879 struct vega10_hwmgr *data = hwmgr->backend;
1880 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1881 struct vega10_single_dpm_table *dpm_table =
1882 &(data->dpm_table.mem_table);
1883 int result = 0;
1884 uint32_t i, j;
1885
1886 for (i = 0; i < dpm_table->count; i++) {
1887 result = vega10_populate_single_memory_level(hwmgr,
1888 dpm_table->dpm_levels[i].value,
1889 &(pp_table->MemVid[i]),
1890 &(pp_table->UclkLevel[i]),
1891 &(pp_table->MemSocVoltageIndex[i]));
1892 if (result)
1893 return result;
1894 }
1895
1896 j = i - 1;
1897 while (i < NUM_UCLK_DPM_LEVELS) {
1898 result = vega10_populate_single_memory_level(hwmgr,
1899 dpm_table->dpm_levels[j].value,
1900 &(pp_table->MemVid[i]),
1901 &(pp_table->UclkLevel[i]),
1902 &(pp_table->MemSocVoltageIndex[i]));
1903 if (result)
1904 return result;
1905 i++;
1906 }
1907
1908 pp_table->NumMemoryChannels = (uint16_t)(data->mem_channels);
1909 pp_table->MemoryChannelWidth =
1910 (uint16_t)(HBM_MEMORY_CHANNEL_WIDTH *
1911 channel_number[data->mem_channels]);
1912
1913 pp_table->LowestUclkReservedForUlv =
1914 (uint8_t)(data->lowest_uclk_reserved_for_ulv);
1915
1916 return result;
1917 }
1918
vega10_populate_single_display_type(struct pp_hwmgr * hwmgr,DSPCLK_e disp_clock)1919 static int vega10_populate_single_display_type(struct pp_hwmgr *hwmgr,
1920 DSPCLK_e disp_clock)
1921 {
1922 struct vega10_hwmgr *data = hwmgr->backend;
1923 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
1924 struct phm_ppt_v2_information *table_info =
1925 (struct phm_ppt_v2_information *)
1926 (hwmgr->pptable);
1927 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
1928 uint32_t i;
1929 uint16_t clk = 0, vddc = 0;
1930 uint8_t vid = 0;
1931
1932 switch (disp_clock) {
1933 case DSPCLK_DCEFCLK:
1934 dep_table = table_info->vdd_dep_on_dcefclk;
1935 break;
1936 case DSPCLK_DISPCLK:
1937 dep_table = table_info->vdd_dep_on_dispclk;
1938 break;
1939 case DSPCLK_PIXCLK:
1940 dep_table = table_info->vdd_dep_on_pixclk;
1941 break;
1942 case DSPCLK_PHYCLK:
1943 dep_table = table_info->vdd_dep_on_phyclk;
1944 break;
1945 default:
1946 return -1;
1947 }
1948
1949 PP_ASSERT_WITH_CODE(dep_table->count <= NUM_DSPCLK_LEVELS,
1950 "Number Of Entries Exceeded maximum!",
1951 return -1);
1952
1953 for (i = 0; i < dep_table->count; i++) {
1954 clk = (uint16_t)(dep_table->entries[i].clk / 100);
1955 vddc = table_info->vddc_lookup_table->
1956 entries[dep_table->entries[i].vddInd].us_vdd;
1957 vid = (uint8_t)convert_to_vid(vddc);
1958 pp_table->DisplayClockTable[disp_clock][i].Freq =
1959 cpu_to_le16(clk);
1960 pp_table->DisplayClockTable[disp_clock][i].Vid =
1961 cpu_to_le16(vid);
1962 }
1963
1964 while (i < NUM_DSPCLK_LEVELS) {
1965 pp_table->DisplayClockTable[disp_clock][i].Freq =
1966 cpu_to_le16(clk);
1967 pp_table->DisplayClockTable[disp_clock][i].Vid =
1968 cpu_to_le16(vid);
1969 i++;
1970 }
1971
1972 return 0;
1973 }
1974
vega10_populate_all_display_clock_levels(struct pp_hwmgr * hwmgr)1975 static int vega10_populate_all_display_clock_levels(struct pp_hwmgr *hwmgr)
1976 {
1977 uint32_t i;
1978
1979 for (i = 0; i < DSPCLK_COUNT; i++) {
1980 PP_ASSERT_WITH_CODE(!vega10_populate_single_display_type(hwmgr, i),
1981 "Failed to populate Clock in DisplayClockTable!",
1982 return -1);
1983 }
1984
1985 return 0;
1986 }
1987
vega10_populate_single_eclock_level(struct pp_hwmgr * hwmgr,uint32_t eclock,uint8_t * current_eclk_did,uint8_t * current_soc_vol)1988 static int vega10_populate_single_eclock_level(struct pp_hwmgr *hwmgr,
1989 uint32_t eclock, uint8_t *current_eclk_did,
1990 uint8_t *current_soc_vol)
1991 {
1992 struct phm_ppt_v2_information *table_info =
1993 (struct phm_ppt_v2_information *)(hwmgr->pptable);
1994 struct phm_ppt_v1_mm_clock_voltage_dependency_table *dep_table =
1995 table_info->mm_dep_table;
1996 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
1997 uint32_t i;
1998
1999 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
2000 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2001 eclock, ÷rs),
2002 "Failed to get ECLK clock settings from VBIOS!",
2003 return -1);
2004
2005 *current_eclk_did = (uint8_t)dividers.ulDid;
2006
2007 for (i = 0; i < dep_table->count; i++) {
2008 if (dep_table->entries[i].eclk == eclock)
2009 *current_soc_vol = dep_table->entries[i].vddcInd;
2010 }
2011
2012 return 0;
2013 }
2014
vega10_populate_smc_vce_levels(struct pp_hwmgr * hwmgr)2015 static int vega10_populate_smc_vce_levels(struct pp_hwmgr *hwmgr)
2016 {
2017 struct vega10_hwmgr *data = hwmgr->backend;
2018 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2019 struct vega10_single_dpm_table *dpm_table = &(data->dpm_table.eclk_table);
2020 int result = -EINVAL;
2021 uint32_t i, j;
2022
2023 for (i = 0; i < dpm_table->count; i++) {
2024 result = vega10_populate_single_eclock_level(hwmgr,
2025 dpm_table->dpm_levels[i].value,
2026 &(pp_table->EclkDid[i]),
2027 &(pp_table->VceDpmVoltageIndex[i]));
2028 if (result)
2029 return result;
2030 }
2031
2032 j = i - 1;
2033 while (i < NUM_VCE_DPM_LEVELS) {
2034 result = vega10_populate_single_eclock_level(hwmgr,
2035 dpm_table->dpm_levels[j].value,
2036 &(pp_table->EclkDid[i]),
2037 &(pp_table->VceDpmVoltageIndex[i]));
2038 if (result)
2039 return result;
2040 i++;
2041 }
2042
2043 return result;
2044 }
2045
vega10_populate_single_vclock_level(struct pp_hwmgr * hwmgr,uint32_t vclock,uint8_t * current_vclk_did)2046 static int vega10_populate_single_vclock_level(struct pp_hwmgr *hwmgr,
2047 uint32_t vclock, uint8_t *current_vclk_did)
2048 {
2049 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
2050
2051 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
2052 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2053 vclock, ÷rs),
2054 "Failed to get VCLK clock settings from VBIOS!",
2055 return -EINVAL);
2056
2057 *current_vclk_did = (uint8_t)dividers.ulDid;
2058
2059 return 0;
2060 }
2061
vega10_populate_single_dclock_level(struct pp_hwmgr * hwmgr,uint32_t dclock,uint8_t * current_dclk_did)2062 static int vega10_populate_single_dclock_level(struct pp_hwmgr *hwmgr,
2063 uint32_t dclock, uint8_t *current_dclk_did)
2064 {
2065 struct pp_atomfwctrl_clock_dividers_soc15 dividers;
2066
2067 PP_ASSERT_WITH_CODE(!pp_atomfwctrl_get_gpu_pll_dividers_vega10(hwmgr,
2068 COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
2069 dclock, ÷rs),
2070 "Failed to get DCLK clock settings from VBIOS!",
2071 return -EINVAL);
2072
2073 *current_dclk_did = (uint8_t)dividers.ulDid;
2074
2075 return 0;
2076 }
2077
vega10_populate_smc_uvd_levels(struct pp_hwmgr * hwmgr)2078 static int vega10_populate_smc_uvd_levels(struct pp_hwmgr *hwmgr)
2079 {
2080 struct vega10_hwmgr *data = hwmgr->backend;
2081 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2082 struct vega10_single_dpm_table *vclk_dpm_table =
2083 &(data->dpm_table.vclk_table);
2084 struct vega10_single_dpm_table *dclk_dpm_table =
2085 &(data->dpm_table.dclk_table);
2086 struct phm_ppt_v2_information *table_info =
2087 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2088 struct phm_ppt_v1_mm_clock_voltage_dependency_table *dep_table =
2089 table_info->mm_dep_table;
2090 int result = -EINVAL;
2091 uint32_t i, j;
2092
2093 for (i = 0; i < vclk_dpm_table->count; i++) {
2094 result = vega10_populate_single_vclock_level(hwmgr,
2095 vclk_dpm_table->dpm_levels[i].value,
2096 &(pp_table->VclkDid[i]));
2097 if (result)
2098 return result;
2099 }
2100
2101 j = i - 1;
2102 while (i < NUM_UVD_DPM_LEVELS) {
2103 result = vega10_populate_single_vclock_level(hwmgr,
2104 vclk_dpm_table->dpm_levels[j].value,
2105 &(pp_table->VclkDid[i]));
2106 if (result)
2107 return result;
2108 i++;
2109 }
2110
2111 for (i = 0; i < dclk_dpm_table->count; i++) {
2112 result = vega10_populate_single_dclock_level(hwmgr,
2113 dclk_dpm_table->dpm_levels[i].value,
2114 &(pp_table->DclkDid[i]));
2115 if (result)
2116 return result;
2117 }
2118
2119 j = i - 1;
2120 while (i < NUM_UVD_DPM_LEVELS) {
2121 result = vega10_populate_single_dclock_level(hwmgr,
2122 dclk_dpm_table->dpm_levels[j].value,
2123 &(pp_table->DclkDid[i]));
2124 if (result)
2125 return result;
2126 i++;
2127 }
2128
2129 for (i = 0; i < dep_table->count; i++) {
2130 if (dep_table->entries[i].vclk ==
2131 vclk_dpm_table->dpm_levels[i].value &&
2132 dep_table->entries[i].dclk ==
2133 dclk_dpm_table->dpm_levels[i].value)
2134 pp_table->UvdDpmVoltageIndex[i] =
2135 dep_table->entries[i].vddcInd;
2136 else
2137 return -1;
2138 }
2139
2140 j = i - 1;
2141 while (i < NUM_UVD_DPM_LEVELS) {
2142 pp_table->UvdDpmVoltageIndex[i] = dep_table->entries[j].vddcInd;
2143 i++;
2144 }
2145
2146 return 0;
2147 }
2148
vega10_populate_clock_stretcher_table(struct pp_hwmgr * hwmgr)2149 static int vega10_populate_clock_stretcher_table(struct pp_hwmgr *hwmgr)
2150 {
2151 struct vega10_hwmgr *data = hwmgr->backend;
2152 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2153 struct phm_ppt_v2_information *table_info =
2154 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2155 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
2156 table_info->vdd_dep_on_sclk;
2157 uint32_t i;
2158
2159 for (i = 0; i < dep_table->count; i++) {
2160 pp_table->CksEnable[i] = dep_table->entries[i].cks_enable;
2161 pp_table->CksVidOffset[i] = (uint8_t)(dep_table->entries[i].cks_voffset
2162 * VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
2163 }
2164
2165 return 0;
2166 }
2167
vega10_populate_avfs_parameters(struct pp_hwmgr * hwmgr)2168 static int vega10_populate_avfs_parameters(struct pp_hwmgr *hwmgr)
2169 {
2170 struct vega10_hwmgr *data = hwmgr->backend;
2171 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2172 struct phm_ppt_v2_information *table_info =
2173 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2174 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
2175 table_info->vdd_dep_on_sclk;
2176 struct pp_atomfwctrl_avfs_parameters avfs_params = {0};
2177 int result = 0;
2178 uint32_t i;
2179
2180 pp_table->MinVoltageVid = (uint8_t)0xff;
2181 pp_table->MaxVoltageVid = (uint8_t)0;
2182
2183 if (data->smu_features[GNLD_AVFS].supported) {
2184 result = pp_atomfwctrl_get_avfs_information(hwmgr, &avfs_params);
2185 if (!result) {
2186 pp_table->MinVoltageVid = (uint8_t)
2187 convert_to_vid((uint16_t)(avfs_params.ulMinVddc));
2188 pp_table->MaxVoltageVid = (uint8_t)
2189 convert_to_vid((uint16_t)(avfs_params.ulMaxVddc));
2190
2191 pp_table->AConstant[0] = cpu_to_le32(avfs_params.ulMeanNsigmaAcontant0);
2192 pp_table->AConstant[1] = cpu_to_le32(avfs_params.ulMeanNsigmaAcontant1);
2193 pp_table->AConstant[2] = cpu_to_le32(avfs_params.ulMeanNsigmaAcontant2);
2194 pp_table->DC_tol_sigma = cpu_to_le16(avfs_params.usMeanNsigmaDcTolSigma);
2195 pp_table->Platform_mean = cpu_to_le16(avfs_params.usMeanNsigmaPlatformMean);
2196 pp_table->Platform_sigma = cpu_to_le16(avfs_params.usMeanNsigmaDcTolSigma);
2197 pp_table->PSM_Age_CompFactor = cpu_to_le16(avfs_params.usPsmAgeComfactor);
2198
2199 pp_table->BtcGbVdroopTableCksOff.a0 =
2200 cpu_to_le32(avfs_params.ulGbVdroopTableCksoffA0);
2201 pp_table->BtcGbVdroopTableCksOff.a0_shift = 20;
2202 pp_table->BtcGbVdroopTableCksOff.a1 =
2203 cpu_to_le32(avfs_params.ulGbVdroopTableCksoffA1);
2204 pp_table->BtcGbVdroopTableCksOff.a1_shift = 20;
2205 pp_table->BtcGbVdroopTableCksOff.a2 =
2206 cpu_to_le32(avfs_params.ulGbVdroopTableCksoffA2);
2207 pp_table->BtcGbVdroopTableCksOff.a2_shift = 20;
2208
2209 pp_table->OverrideBtcGbCksOn = avfs_params.ucEnableGbVdroopTableCkson;
2210 pp_table->BtcGbVdroopTableCksOn.a0 =
2211 cpu_to_le32(avfs_params.ulGbVdroopTableCksonA0);
2212 pp_table->BtcGbVdroopTableCksOn.a0_shift = 20;
2213 pp_table->BtcGbVdroopTableCksOn.a1 =
2214 cpu_to_le32(avfs_params.ulGbVdroopTableCksonA1);
2215 pp_table->BtcGbVdroopTableCksOn.a1_shift = 20;
2216 pp_table->BtcGbVdroopTableCksOn.a2 =
2217 cpu_to_le32(avfs_params.ulGbVdroopTableCksonA2);
2218 pp_table->BtcGbVdroopTableCksOn.a2_shift = 20;
2219
2220 pp_table->AvfsGbCksOn.m1 =
2221 cpu_to_le32(avfs_params.ulGbFuseTableCksonM1);
2222 pp_table->AvfsGbCksOn.m2 =
2223 cpu_to_le32(avfs_params.ulGbFuseTableCksonM2);
2224 pp_table->AvfsGbCksOn.b =
2225 cpu_to_le32(avfs_params.ulGbFuseTableCksonB);
2226 pp_table->AvfsGbCksOn.m1_shift = 24;
2227 pp_table->AvfsGbCksOn.m2_shift = 12;
2228 pp_table->AvfsGbCksOn.b_shift = 0;
2229
2230 pp_table->OverrideAvfsGbCksOn =
2231 avfs_params.ucEnableGbFuseTableCkson;
2232 pp_table->AvfsGbCksOff.m1 =
2233 cpu_to_le32(avfs_params.ulGbFuseTableCksoffM1);
2234 pp_table->AvfsGbCksOff.m2 =
2235 cpu_to_le32(avfs_params.ulGbFuseTableCksoffM2);
2236 pp_table->AvfsGbCksOff.b =
2237 cpu_to_le32(avfs_params.ulGbFuseTableCksoffB);
2238 pp_table->AvfsGbCksOff.m1_shift = 24;
2239 pp_table->AvfsGbCksOff.m2_shift = 12;
2240 pp_table->AvfsGbCksOff.b_shift = 0;
2241
2242 for (i = 0; i < dep_table->count; i++)
2243 pp_table->StaticVoltageOffsetVid[i] =
2244 convert_to_vid((uint8_t)(dep_table->entries[i].sclk_offset));
2245
2246 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2247 data->disp_clk_quad_eqn_a) &&
2248 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2249 data->disp_clk_quad_eqn_b)) {
2250 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m1 =
2251 (int32_t)data->disp_clk_quad_eqn_a;
2252 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m2 =
2253 (int32_t)data->disp_clk_quad_eqn_b;
2254 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].b =
2255 (int32_t)data->disp_clk_quad_eqn_c;
2256 } else {
2257 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m1 =
2258 (int32_t)avfs_params.ulDispclk2GfxclkM1;
2259 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m2 =
2260 (int32_t)avfs_params.ulDispclk2GfxclkM2;
2261 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].b =
2262 (int32_t)avfs_params.ulDispclk2GfxclkB;
2263 }
2264
2265 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m1_shift = 24;
2266 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].m2_shift = 12;
2267 pp_table->DisplayClock2Gfxclk[DSPCLK_DISPCLK].b_shift = 12;
2268
2269 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2270 data->dcef_clk_quad_eqn_a) &&
2271 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2272 data->dcef_clk_quad_eqn_b)) {
2273 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m1 =
2274 (int32_t)data->dcef_clk_quad_eqn_a;
2275 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m2 =
2276 (int32_t)data->dcef_clk_quad_eqn_b;
2277 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].b =
2278 (int32_t)data->dcef_clk_quad_eqn_c;
2279 } else {
2280 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m1 =
2281 (int32_t)avfs_params.ulDcefclk2GfxclkM1;
2282 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m2 =
2283 (int32_t)avfs_params.ulDcefclk2GfxclkM2;
2284 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].b =
2285 (int32_t)avfs_params.ulDcefclk2GfxclkB;
2286 }
2287
2288 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m1_shift = 24;
2289 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].m2_shift = 12;
2290 pp_table->DisplayClock2Gfxclk[DSPCLK_DCEFCLK].b_shift = 12;
2291
2292 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2293 data->pixel_clk_quad_eqn_a) &&
2294 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2295 data->pixel_clk_quad_eqn_b)) {
2296 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m1 =
2297 (int32_t)data->pixel_clk_quad_eqn_a;
2298 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m2 =
2299 (int32_t)data->pixel_clk_quad_eqn_b;
2300 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].b =
2301 (int32_t)data->pixel_clk_quad_eqn_c;
2302 } else {
2303 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m1 =
2304 (int32_t)avfs_params.ulPixelclk2GfxclkM1;
2305 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m2 =
2306 (int32_t)avfs_params.ulPixelclk2GfxclkM2;
2307 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].b =
2308 (int32_t)avfs_params.ulPixelclk2GfxclkB;
2309 }
2310
2311 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m1_shift = 24;
2312 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].m2_shift = 12;
2313 pp_table->DisplayClock2Gfxclk[DSPCLK_PIXCLK].b_shift = 12;
2314 if ((PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2315 data->phy_clk_quad_eqn_a) &&
2316 (PPREGKEY_VEGA10QUADRATICEQUATION_DFLT !=
2317 data->phy_clk_quad_eqn_b)) {
2318 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m1 =
2319 (int32_t)data->phy_clk_quad_eqn_a;
2320 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m2 =
2321 (int32_t)data->phy_clk_quad_eqn_b;
2322 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].b =
2323 (int32_t)data->phy_clk_quad_eqn_c;
2324 } else {
2325 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m1 =
2326 (int32_t)avfs_params.ulPhyclk2GfxclkM1;
2327 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m2 =
2328 (int32_t)avfs_params.ulPhyclk2GfxclkM2;
2329 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].b =
2330 (int32_t)avfs_params.ulPhyclk2GfxclkB;
2331 }
2332
2333 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m1_shift = 24;
2334 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].m2_shift = 12;
2335 pp_table->DisplayClock2Gfxclk[DSPCLK_PHYCLK].b_shift = 12;
2336
2337 pp_table->AcgBtcGbVdroopTable.a0 = avfs_params.ulAcgGbVdroopTableA0;
2338 pp_table->AcgBtcGbVdroopTable.a0_shift = 20;
2339 pp_table->AcgBtcGbVdroopTable.a1 = avfs_params.ulAcgGbVdroopTableA1;
2340 pp_table->AcgBtcGbVdroopTable.a1_shift = 20;
2341 pp_table->AcgBtcGbVdroopTable.a2 = avfs_params.ulAcgGbVdroopTableA2;
2342 pp_table->AcgBtcGbVdroopTable.a2_shift = 20;
2343
2344 pp_table->AcgAvfsGb.m1 = avfs_params.ulAcgGbFuseTableM1;
2345 pp_table->AcgAvfsGb.m2 = avfs_params.ulAcgGbFuseTableM2;
2346 pp_table->AcgAvfsGb.b = avfs_params.ulAcgGbFuseTableB;
2347 pp_table->AcgAvfsGb.m1_shift = 24;
2348 pp_table->AcgAvfsGb.m2_shift = 12;
2349 pp_table->AcgAvfsGb.b_shift = 0;
2350
2351 } else {
2352 data->smu_features[GNLD_AVFS].supported = false;
2353 }
2354 }
2355
2356 return 0;
2357 }
2358
vega10_acg_enable(struct pp_hwmgr * hwmgr)2359 static int vega10_acg_enable(struct pp_hwmgr *hwmgr)
2360 {
2361 struct vega10_hwmgr *data = hwmgr->backend;
2362 uint32_t agc_btc_response;
2363 int ret;
2364
2365 if (data->smu_features[GNLD_ACG].supported) {
2366 if (0 == vega10_enable_smc_features(hwmgr, true,
2367 data->smu_features[GNLD_DPM_PREFETCHER].smu_feature_bitmap))
2368 data->smu_features[GNLD_DPM_PREFETCHER].enabled = true;
2369
2370 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_InitializeAcg, NULL);
2371 if (ret)
2372 return ret;
2373
2374 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgBtc, &agc_btc_response);
2375 if (ret)
2376 agc_btc_response = 0;
2377
2378 if (1 == agc_btc_response) {
2379 if (1 == data->acg_loop_state)
2380 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgInClosedLoop, NULL);
2381 else if (2 == data->acg_loop_state)
2382 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_RunAcgInOpenLoop, NULL);
2383 if (0 == vega10_enable_smc_features(hwmgr, true,
2384 data->smu_features[GNLD_ACG].smu_feature_bitmap))
2385 data->smu_features[GNLD_ACG].enabled = true;
2386 } else {
2387 pr_info("[ACG_Enable] ACG BTC Returned Failed Status!\n");
2388 data->smu_features[GNLD_ACG].enabled = false;
2389 }
2390 }
2391
2392 return 0;
2393 }
2394
vega10_acg_disable(struct pp_hwmgr * hwmgr)2395 static int vega10_acg_disable(struct pp_hwmgr *hwmgr)
2396 {
2397 struct vega10_hwmgr *data = hwmgr->backend;
2398
2399 if (data->smu_features[GNLD_ACG].supported &&
2400 data->smu_features[GNLD_ACG].enabled)
2401 if (!vega10_enable_smc_features(hwmgr, false,
2402 data->smu_features[GNLD_ACG].smu_feature_bitmap))
2403 data->smu_features[GNLD_ACG].enabled = false;
2404
2405 return 0;
2406 }
2407
vega10_populate_gpio_parameters(struct pp_hwmgr * hwmgr)2408 static int vega10_populate_gpio_parameters(struct pp_hwmgr *hwmgr)
2409 {
2410 struct vega10_hwmgr *data = hwmgr->backend;
2411 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2412 struct pp_atomfwctrl_gpio_parameters gpio_params = {0};
2413 int result;
2414
2415 result = pp_atomfwctrl_get_gpio_information(hwmgr, &gpio_params);
2416 if (!result) {
2417 if (PP_CAP(PHM_PlatformCaps_RegulatorHot) &&
2418 data->registry_data.regulator_hot_gpio_support) {
2419 pp_table->VR0HotGpio = gpio_params.ucVR0HotGpio;
2420 pp_table->VR0HotPolarity = gpio_params.ucVR0HotPolarity;
2421 pp_table->VR1HotGpio = gpio_params.ucVR1HotGpio;
2422 pp_table->VR1HotPolarity = gpio_params.ucVR1HotPolarity;
2423 } else {
2424 pp_table->VR0HotGpio = 0;
2425 pp_table->VR0HotPolarity = 0;
2426 pp_table->VR1HotGpio = 0;
2427 pp_table->VR1HotPolarity = 0;
2428 }
2429
2430 if (PP_CAP(PHM_PlatformCaps_AutomaticDCTransition) &&
2431 data->registry_data.ac_dc_switch_gpio_support) {
2432 pp_table->AcDcGpio = gpio_params.ucAcDcGpio;
2433 pp_table->AcDcPolarity = gpio_params.ucAcDcPolarity;
2434 } else {
2435 pp_table->AcDcGpio = 0;
2436 pp_table->AcDcPolarity = 0;
2437 }
2438 }
2439
2440 return result;
2441 }
2442
vega10_avfs_enable(struct pp_hwmgr * hwmgr,bool enable)2443 static int vega10_avfs_enable(struct pp_hwmgr *hwmgr, bool enable)
2444 {
2445 struct vega10_hwmgr *data = hwmgr->backend;
2446
2447 if (data->smu_features[GNLD_AVFS].supported) {
2448 /* Already enabled or disabled */
2449 if (!(enable ^ data->smu_features[GNLD_AVFS].enabled))
2450 return 0;
2451
2452 if (enable) {
2453 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2454 true,
2455 data->smu_features[GNLD_AVFS].smu_feature_bitmap),
2456 "[avfs_control] Attempt to Enable AVFS feature Failed!",
2457 return -1);
2458 data->smu_features[GNLD_AVFS].enabled = true;
2459 } else {
2460 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2461 false,
2462 data->smu_features[GNLD_AVFS].smu_feature_bitmap),
2463 "[avfs_control] Attempt to Disable AVFS feature Failed!",
2464 return -1);
2465 data->smu_features[GNLD_AVFS].enabled = false;
2466 }
2467 }
2468
2469 return 0;
2470 }
2471
vega10_update_avfs(struct pp_hwmgr * hwmgr)2472 static int vega10_update_avfs(struct pp_hwmgr *hwmgr)
2473 {
2474 struct vega10_hwmgr *data = hwmgr->backend;
2475
2476 if (data->need_update_dpm_table & DPMTABLE_OD_UPDATE_VDDC) {
2477 vega10_avfs_enable(hwmgr, false);
2478 } else if (data->need_update_dpm_table) {
2479 vega10_avfs_enable(hwmgr, false);
2480 vega10_avfs_enable(hwmgr, true);
2481 } else {
2482 vega10_avfs_enable(hwmgr, true);
2483 }
2484
2485 return 0;
2486 }
2487
vega10_populate_and_upload_avfs_fuse_override(struct pp_hwmgr * hwmgr)2488 static int vega10_populate_and_upload_avfs_fuse_override(struct pp_hwmgr *hwmgr)
2489 {
2490 int result = 0;
2491
2492 uint64_t serial_number = 0;
2493 uint32_t top32, bottom32;
2494 struct phm_fuses_default fuse;
2495
2496 struct vega10_hwmgr *data = hwmgr->backend;
2497 AvfsFuseOverride_t *avfs_fuse_table = &(data->smc_state_table.avfs_fuse_override_table);
2498
2499 result = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumTop32, &top32);
2500 if (result)
2501 return result;
2502 result = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ReadSerialNumBottom32, &bottom32);
2503 if (result)
2504 return result;
2505 serial_number = ((uint64_t)bottom32 << 32) | top32;
2506
2507 if (pp_override_get_default_fuse_value(serial_number, &fuse) == 0) {
2508 avfs_fuse_table->VFT0_b = fuse.VFT0_b;
2509 avfs_fuse_table->VFT0_m1 = fuse.VFT0_m1;
2510 avfs_fuse_table->VFT0_m2 = fuse.VFT0_m2;
2511 avfs_fuse_table->VFT1_b = fuse.VFT1_b;
2512 avfs_fuse_table->VFT1_m1 = fuse.VFT1_m1;
2513 avfs_fuse_table->VFT1_m2 = fuse.VFT1_m2;
2514 avfs_fuse_table->VFT2_b = fuse.VFT2_b;
2515 avfs_fuse_table->VFT2_m1 = fuse.VFT2_m1;
2516 avfs_fuse_table->VFT2_m2 = fuse.VFT2_m2;
2517 result = smum_smc_table_manager(hwmgr, (uint8_t *)avfs_fuse_table,
2518 AVFSFUSETABLE, false);
2519 PP_ASSERT_WITH_CODE(!result,
2520 "Failed to upload FuseOVerride!",
2521 );
2522 }
2523
2524 return result;
2525 }
2526
vega10_check_dpm_table_updated(struct pp_hwmgr * hwmgr)2527 static void vega10_check_dpm_table_updated(struct pp_hwmgr *hwmgr)
2528 {
2529 struct vega10_hwmgr *data = hwmgr->backend;
2530 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
2531 struct phm_ppt_v2_information *table_info = hwmgr->pptable;
2532 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
2533 struct phm_ppt_v1_clock_voltage_dependency_table *odn_dep_table;
2534 uint32_t i;
2535
2536 dep_table = table_info->vdd_dep_on_mclk;
2537 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dep_on_mclk);
2538
2539 for (i = 0; i < dep_table->count; i++) {
2540 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
2541 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_MCLK;
2542 return;
2543 }
2544 }
2545
2546 dep_table = table_info->vdd_dep_on_sclk;
2547 odn_dep_table = (struct phm_ppt_v1_clock_voltage_dependency_table *)&(odn_table->vdd_dep_on_sclk);
2548 for (i = 0; i < dep_table->count; i++) {
2549 if (dep_table->entries[i].vddc != odn_dep_table->entries[i].vddc) {
2550 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC | DPMTABLE_OD_UPDATE_SCLK;
2551 return;
2552 }
2553 }
2554 }
2555
2556 /**
2557 * vega10_init_smc_table - Initializes the SMC table and uploads it
2558 *
2559 * @hwmgr: the address of the powerplay hardware manager.
2560 * return: always 0
2561 */
vega10_init_smc_table(struct pp_hwmgr * hwmgr)2562 static int vega10_init_smc_table(struct pp_hwmgr *hwmgr)
2563 {
2564 int result;
2565 struct vega10_hwmgr *data = hwmgr->backend;
2566 struct phm_ppt_v2_information *table_info =
2567 (struct phm_ppt_v2_information *)(hwmgr->pptable);
2568 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
2569 struct pp_atomfwctrl_voltage_table voltage_table;
2570 struct pp_atomfwctrl_bios_boot_up_values boot_up_values;
2571 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
2572
2573 result = vega10_setup_default_dpm_tables(hwmgr);
2574 PP_ASSERT_WITH_CODE(!result,
2575 "Failed to setup default DPM tables!",
2576 return result);
2577
2578 if (!hwmgr->not_vf)
2579 return 0;
2580
2581 /* initialize ODN table */
2582 if (hwmgr->od_enabled) {
2583 if (odn_table->max_vddc) {
2584 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_OD_UPDATE_MCLK;
2585 vega10_check_dpm_table_updated(hwmgr);
2586 } else {
2587 vega10_odn_initial_default_setting(hwmgr);
2588 }
2589 }
2590
2591 result = pp_atomfwctrl_get_voltage_table_v4(hwmgr, VOLTAGE_TYPE_VDDC,
2592 VOLTAGE_OBJ_SVID2, &voltage_table);
2593 PP_ASSERT_WITH_CODE(!result,
2594 "Failed to get voltage table!",
2595 return result);
2596 pp_table->MaxVidStep = voltage_table.max_vid_step;
2597
2598 pp_table->GfxDpmVoltageMode =
2599 (uint8_t)(table_info->uc_gfx_dpm_voltage_mode);
2600 pp_table->SocDpmVoltageMode =
2601 (uint8_t)(table_info->uc_soc_dpm_voltage_mode);
2602 pp_table->UclkDpmVoltageMode =
2603 (uint8_t)(table_info->uc_uclk_dpm_voltage_mode);
2604 pp_table->UvdDpmVoltageMode =
2605 (uint8_t)(table_info->uc_uvd_dpm_voltage_mode);
2606 pp_table->VceDpmVoltageMode =
2607 (uint8_t)(table_info->uc_vce_dpm_voltage_mode);
2608 pp_table->Mp0DpmVoltageMode =
2609 (uint8_t)(table_info->uc_mp0_dpm_voltage_mode);
2610
2611 pp_table->DisplayDpmVoltageMode =
2612 (uint8_t)(table_info->uc_dcef_dpm_voltage_mode);
2613
2614 data->vddc_voltage_table.psi0_enable = voltage_table.psi0_enable;
2615 data->vddc_voltage_table.psi1_enable = voltage_table.psi1_enable;
2616
2617 if (data->registry_data.ulv_support &&
2618 table_info->us_ulv_voltage_offset) {
2619 result = vega10_populate_ulv_state(hwmgr);
2620 PP_ASSERT_WITH_CODE(!result,
2621 "Failed to initialize ULV state!",
2622 return result);
2623 }
2624
2625 result = vega10_populate_smc_link_levels(hwmgr);
2626 PP_ASSERT_WITH_CODE(!result,
2627 "Failed to initialize Link Level!",
2628 return result);
2629
2630 result = vega10_override_pcie_parameters(hwmgr);
2631 PP_ASSERT_WITH_CODE(!result,
2632 "Failed to override pcie parameters!",
2633 return result);
2634
2635 result = vega10_populate_all_graphic_levels(hwmgr);
2636 PP_ASSERT_WITH_CODE(!result,
2637 "Failed to initialize Graphics Level!",
2638 return result);
2639
2640 result = vega10_populate_all_memory_levels(hwmgr);
2641 PP_ASSERT_WITH_CODE(!result,
2642 "Failed to initialize Memory Level!",
2643 return result);
2644
2645 vega10_populate_vddc_soc_levels(hwmgr);
2646
2647 result = vega10_populate_all_display_clock_levels(hwmgr);
2648 PP_ASSERT_WITH_CODE(!result,
2649 "Failed to initialize Display Level!",
2650 return result);
2651
2652 result = vega10_populate_smc_vce_levels(hwmgr);
2653 PP_ASSERT_WITH_CODE(!result,
2654 "Failed to initialize VCE Level!",
2655 return result);
2656
2657 result = vega10_populate_smc_uvd_levels(hwmgr);
2658 PP_ASSERT_WITH_CODE(!result,
2659 "Failed to initialize UVD Level!",
2660 return result);
2661
2662 if (data->registry_data.clock_stretcher_support) {
2663 result = vega10_populate_clock_stretcher_table(hwmgr);
2664 PP_ASSERT_WITH_CODE(!result,
2665 "Failed to populate Clock Stretcher Table!",
2666 return result);
2667 }
2668
2669 result = pp_atomfwctrl_get_vbios_bootup_values(hwmgr, &boot_up_values);
2670 if (!result) {
2671 data->vbios_boot_state.vddc = boot_up_values.usVddc;
2672 data->vbios_boot_state.vddci = boot_up_values.usVddci;
2673 data->vbios_boot_state.mvddc = boot_up_values.usMvddc;
2674 data->vbios_boot_state.gfx_clock = boot_up_values.ulGfxClk;
2675 data->vbios_boot_state.mem_clock = boot_up_values.ulUClk;
2676 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr,
2677 SMU9_SYSPLL0_SOCCLK_ID, 0, &boot_up_values.ulSocClk);
2678
2679 pp_atomfwctrl_get_clk_information_by_clkid(hwmgr,
2680 SMU9_SYSPLL0_DCEFCLK_ID, 0, &boot_up_values.ulDCEFClk);
2681
2682 data->vbios_boot_state.soc_clock = boot_up_values.ulSocClk;
2683 data->vbios_boot_state.dcef_clock = boot_up_values.ulDCEFClk;
2684 if (0 != boot_up_values.usVddc) {
2685 smum_send_msg_to_smc_with_parameter(hwmgr,
2686 PPSMC_MSG_SetFloorSocVoltage,
2687 (boot_up_values.usVddc * 4),
2688 NULL);
2689 data->vbios_boot_state.bsoc_vddc_lock = true;
2690 } else {
2691 data->vbios_boot_state.bsoc_vddc_lock = false;
2692 }
2693 smum_send_msg_to_smc_with_parameter(hwmgr,
2694 PPSMC_MSG_SetMinDeepSleepDcefclk,
2695 (uint32_t)(data->vbios_boot_state.dcef_clock / 100),
2696 NULL);
2697 }
2698
2699 result = vega10_populate_avfs_parameters(hwmgr);
2700 PP_ASSERT_WITH_CODE(!result,
2701 "Failed to initialize AVFS Parameters!",
2702 return result);
2703
2704 result = vega10_populate_gpio_parameters(hwmgr);
2705 PP_ASSERT_WITH_CODE(!result,
2706 "Failed to initialize GPIO Parameters!",
2707 return result);
2708
2709 pp_table->GfxclkAverageAlpha = (uint8_t)
2710 (data->gfxclk_average_alpha);
2711 pp_table->SocclkAverageAlpha = (uint8_t)
2712 (data->socclk_average_alpha);
2713 pp_table->UclkAverageAlpha = (uint8_t)
2714 (data->uclk_average_alpha);
2715 pp_table->GfxActivityAverageAlpha = (uint8_t)
2716 (data->gfx_activity_average_alpha);
2717
2718 vega10_populate_and_upload_avfs_fuse_override(hwmgr);
2719
2720 result = smum_smc_table_manager(hwmgr, (uint8_t *)pp_table, PPTABLE, false);
2721
2722 PP_ASSERT_WITH_CODE(!result,
2723 "Failed to upload PPtable!", return result);
2724
2725 result = vega10_avfs_enable(hwmgr, true);
2726 PP_ASSERT_WITH_CODE(!result, "Attempt to enable AVFS feature Failed!",
2727 return result);
2728 vega10_acg_enable(hwmgr);
2729
2730 return 0;
2731 }
2732
vega10_enable_thermal_protection(struct pp_hwmgr * hwmgr)2733 static int vega10_enable_thermal_protection(struct pp_hwmgr *hwmgr)
2734 {
2735 struct vega10_hwmgr *data = hwmgr->backend;
2736
2737 if (data->smu_features[GNLD_THERMAL].supported) {
2738 if (data->smu_features[GNLD_THERMAL].enabled)
2739 pr_info("THERMAL Feature Already enabled!");
2740
2741 PP_ASSERT_WITH_CODE(
2742 !vega10_enable_smc_features(hwmgr,
2743 true,
2744 data->smu_features[GNLD_THERMAL].smu_feature_bitmap),
2745 "Enable THERMAL Feature Failed!",
2746 return -1);
2747 data->smu_features[GNLD_THERMAL].enabled = true;
2748 }
2749
2750 return 0;
2751 }
2752
vega10_disable_thermal_protection(struct pp_hwmgr * hwmgr)2753 static int vega10_disable_thermal_protection(struct pp_hwmgr *hwmgr)
2754 {
2755 struct vega10_hwmgr *data = hwmgr->backend;
2756
2757 if (data->smu_features[GNLD_THERMAL].supported) {
2758 if (!data->smu_features[GNLD_THERMAL].enabled)
2759 pr_info("THERMAL Feature Already disabled!");
2760
2761 PP_ASSERT_WITH_CODE(
2762 !vega10_enable_smc_features(hwmgr,
2763 false,
2764 data->smu_features[GNLD_THERMAL].smu_feature_bitmap),
2765 "disable THERMAL Feature Failed!",
2766 return -1);
2767 data->smu_features[GNLD_THERMAL].enabled = false;
2768 }
2769
2770 return 0;
2771 }
2772
vega10_enable_vrhot_feature(struct pp_hwmgr * hwmgr)2773 static int vega10_enable_vrhot_feature(struct pp_hwmgr *hwmgr)
2774 {
2775 struct vega10_hwmgr *data = hwmgr->backend;
2776
2777 if (PP_CAP(PHM_PlatformCaps_RegulatorHot)) {
2778 if (data->smu_features[GNLD_VR0HOT].supported) {
2779 PP_ASSERT_WITH_CODE(
2780 !vega10_enable_smc_features(hwmgr,
2781 true,
2782 data->smu_features[GNLD_VR0HOT].smu_feature_bitmap),
2783 "Attempt to Enable VR0 Hot feature Failed!",
2784 return -1);
2785 data->smu_features[GNLD_VR0HOT].enabled = true;
2786 } else {
2787 if (data->smu_features[GNLD_VR1HOT].supported) {
2788 PP_ASSERT_WITH_CODE(
2789 !vega10_enable_smc_features(hwmgr,
2790 true,
2791 data->smu_features[GNLD_VR1HOT].smu_feature_bitmap),
2792 "Attempt to Enable VR0 Hot feature Failed!",
2793 return -1);
2794 data->smu_features[GNLD_VR1HOT].enabled = true;
2795 }
2796 }
2797 }
2798 return 0;
2799 }
2800
vega10_enable_ulv(struct pp_hwmgr * hwmgr)2801 static int vega10_enable_ulv(struct pp_hwmgr *hwmgr)
2802 {
2803 struct vega10_hwmgr *data = hwmgr->backend;
2804
2805 if (data->registry_data.ulv_support) {
2806 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2807 true, data->smu_features[GNLD_ULV].smu_feature_bitmap),
2808 "Enable ULV Feature Failed!",
2809 return -1);
2810 data->smu_features[GNLD_ULV].enabled = true;
2811 }
2812
2813 return 0;
2814 }
2815
vega10_disable_ulv(struct pp_hwmgr * hwmgr)2816 static int vega10_disable_ulv(struct pp_hwmgr *hwmgr)
2817 {
2818 struct vega10_hwmgr *data = hwmgr->backend;
2819
2820 if (data->registry_data.ulv_support) {
2821 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2822 false, data->smu_features[GNLD_ULV].smu_feature_bitmap),
2823 "disable ULV Feature Failed!",
2824 return -EINVAL);
2825 data->smu_features[GNLD_ULV].enabled = false;
2826 }
2827
2828 return 0;
2829 }
2830
vega10_enable_deep_sleep_master_switch(struct pp_hwmgr * hwmgr)2831 static int vega10_enable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2832 {
2833 struct vega10_hwmgr *data = hwmgr->backend;
2834
2835 if (data->smu_features[GNLD_DS_GFXCLK].supported) {
2836 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2837 true, data->smu_features[GNLD_DS_GFXCLK].smu_feature_bitmap),
2838 "Attempt to Enable DS_GFXCLK Feature Failed!",
2839 return -EINVAL);
2840 data->smu_features[GNLD_DS_GFXCLK].enabled = true;
2841 }
2842
2843 if (data->smu_features[GNLD_DS_SOCCLK].supported) {
2844 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2845 true, data->smu_features[GNLD_DS_SOCCLK].smu_feature_bitmap),
2846 "Attempt to Enable DS_SOCCLK Feature Failed!",
2847 return -EINVAL);
2848 data->smu_features[GNLD_DS_SOCCLK].enabled = true;
2849 }
2850
2851 if (data->smu_features[GNLD_DS_LCLK].supported) {
2852 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2853 true, data->smu_features[GNLD_DS_LCLK].smu_feature_bitmap),
2854 "Attempt to Enable DS_LCLK Feature Failed!",
2855 return -EINVAL);
2856 data->smu_features[GNLD_DS_LCLK].enabled = true;
2857 }
2858
2859 if (data->smu_features[GNLD_DS_DCEFCLK].supported) {
2860 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2861 true, data->smu_features[GNLD_DS_DCEFCLK].smu_feature_bitmap),
2862 "Attempt to Enable DS_DCEFCLK Feature Failed!",
2863 return -EINVAL);
2864 data->smu_features[GNLD_DS_DCEFCLK].enabled = true;
2865 }
2866
2867 return 0;
2868 }
2869
vega10_disable_deep_sleep_master_switch(struct pp_hwmgr * hwmgr)2870 static int vega10_disable_deep_sleep_master_switch(struct pp_hwmgr *hwmgr)
2871 {
2872 struct vega10_hwmgr *data = hwmgr->backend;
2873
2874 if (data->smu_features[GNLD_DS_GFXCLK].supported) {
2875 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2876 false, data->smu_features[GNLD_DS_GFXCLK].smu_feature_bitmap),
2877 "Attempt to disable DS_GFXCLK Feature Failed!",
2878 return -EINVAL);
2879 data->smu_features[GNLD_DS_GFXCLK].enabled = false;
2880 }
2881
2882 if (data->smu_features[GNLD_DS_SOCCLK].supported) {
2883 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2884 false, data->smu_features[GNLD_DS_SOCCLK].smu_feature_bitmap),
2885 "Attempt to disable DS_ Feature Failed!",
2886 return -EINVAL);
2887 data->smu_features[GNLD_DS_SOCCLK].enabled = false;
2888 }
2889
2890 if (data->smu_features[GNLD_DS_LCLK].supported) {
2891 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2892 false, data->smu_features[GNLD_DS_LCLK].smu_feature_bitmap),
2893 "Attempt to disable DS_LCLK Feature Failed!",
2894 return -EINVAL);
2895 data->smu_features[GNLD_DS_LCLK].enabled = false;
2896 }
2897
2898 if (data->smu_features[GNLD_DS_DCEFCLK].supported) {
2899 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2900 false, data->smu_features[GNLD_DS_DCEFCLK].smu_feature_bitmap),
2901 "Attempt to disable DS_DCEFCLK Feature Failed!",
2902 return -EINVAL);
2903 data->smu_features[GNLD_DS_DCEFCLK].enabled = false;
2904 }
2905
2906 return 0;
2907 }
2908
vega10_stop_dpm(struct pp_hwmgr * hwmgr,uint32_t bitmap)2909 static int vega10_stop_dpm(struct pp_hwmgr *hwmgr, uint32_t bitmap)
2910 {
2911 struct vega10_hwmgr *data = hwmgr->backend;
2912 uint32_t i, feature_mask = 0;
2913
2914 if (!hwmgr->not_vf)
2915 return 0;
2916
2917 if(data->smu_features[GNLD_LED_DISPLAY].supported == true){
2918 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2919 false, data->smu_features[GNLD_LED_DISPLAY].smu_feature_bitmap),
2920 "Attempt to disable LED DPM feature failed!", return -EINVAL);
2921 data->smu_features[GNLD_LED_DISPLAY].enabled = false;
2922 }
2923
2924 for (i = 0; i < GNLD_DPM_MAX; i++) {
2925 if (data->smu_features[i].smu_feature_bitmap & bitmap) {
2926 if (data->smu_features[i].supported) {
2927 if (data->smu_features[i].enabled) {
2928 feature_mask |= data->smu_features[i].
2929 smu_feature_bitmap;
2930 data->smu_features[i].enabled = false;
2931 }
2932 }
2933 }
2934 }
2935
2936 return vega10_enable_smc_features(hwmgr, false, feature_mask);
2937 }
2938
2939 /**
2940 * vega10_start_dpm - Tell SMC to enabled the supported DPMs.
2941 *
2942 * @hwmgr: the address of the powerplay hardware manager.
2943 * @bitmap: bitmap for the features to enabled.
2944 * return: 0 on at least one DPM is successfully enabled.
2945 */
vega10_start_dpm(struct pp_hwmgr * hwmgr,uint32_t bitmap)2946 static int vega10_start_dpm(struct pp_hwmgr *hwmgr, uint32_t bitmap)
2947 {
2948 struct vega10_hwmgr *data = hwmgr->backend;
2949 uint32_t i, feature_mask = 0;
2950
2951 for (i = 0; i < GNLD_DPM_MAX; i++) {
2952 if (data->smu_features[i].smu_feature_bitmap & bitmap) {
2953 if (data->smu_features[i].supported) {
2954 if (!data->smu_features[i].enabled) {
2955 feature_mask |= data->smu_features[i].
2956 smu_feature_bitmap;
2957 data->smu_features[i].enabled = true;
2958 }
2959 }
2960 }
2961 }
2962
2963 if (vega10_enable_smc_features(hwmgr,
2964 true, feature_mask)) {
2965 for (i = 0; i < GNLD_DPM_MAX; i++) {
2966 if (data->smu_features[i].smu_feature_bitmap &
2967 feature_mask)
2968 data->smu_features[i].enabled = false;
2969 }
2970 }
2971
2972 if(data->smu_features[GNLD_LED_DISPLAY].supported == true){
2973 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2974 true, data->smu_features[GNLD_LED_DISPLAY].smu_feature_bitmap),
2975 "Attempt to Enable LED DPM feature Failed!", return -EINVAL);
2976 data->smu_features[GNLD_LED_DISPLAY].enabled = true;
2977 }
2978
2979 if (data->vbios_boot_state.bsoc_vddc_lock) {
2980 smum_send_msg_to_smc_with_parameter(hwmgr,
2981 PPSMC_MSG_SetFloorSocVoltage, 0,
2982 NULL);
2983 data->vbios_boot_state.bsoc_vddc_lock = false;
2984 }
2985
2986 if (PP_CAP(PHM_PlatformCaps_Falcon_QuickTransition)) {
2987 if (data->smu_features[GNLD_ACDC].supported) {
2988 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2989 true, data->smu_features[GNLD_ACDC].smu_feature_bitmap),
2990 "Attempt to Enable DS_GFXCLK Feature Failed!",
2991 return -1);
2992 data->smu_features[GNLD_ACDC].enabled = true;
2993 }
2994 }
2995
2996 if (data->registry_data.pcie_dpm_key_disabled) {
2997 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
2998 false, data->smu_features[GNLD_DPM_LINK].smu_feature_bitmap),
2999 "Attempt to Disable Link DPM feature Failed!", return -EINVAL);
3000 data->smu_features[GNLD_DPM_LINK].enabled = false;
3001 data->smu_features[GNLD_DPM_LINK].supported = false;
3002 }
3003
3004 return 0;
3005 }
3006
3007
vega10_enable_disable_PCC_limit_feature(struct pp_hwmgr * hwmgr,bool enable)3008 static int vega10_enable_disable_PCC_limit_feature(struct pp_hwmgr *hwmgr, bool enable)
3009 {
3010 struct vega10_hwmgr *data = hwmgr->backend;
3011
3012 if (data->smu_features[GNLD_PCC_LIMIT].supported) {
3013 if (enable == data->smu_features[GNLD_PCC_LIMIT].enabled)
3014 pr_info("GNLD_PCC_LIMIT has been %s \n", enable ? "enabled" : "disabled");
3015 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
3016 enable, data->smu_features[GNLD_PCC_LIMIT].smu_feature_bitmap),
3017 "Attempt to Enable PCC Limit feature Failed!",
3018 return -EINVAL);
3019 data->smu_features[GNLD_PCC_LIMIT].enabled = enable;
3020 }
3021
3022 return 0;
3023 }
3024
vega10_populate_umdpstate_clocks(struct pp_hwmgr * hwmgr)3025 static void vega10_populate_umdpstate_clocks(struct pp_hwmgr *hwmgr)
3026 {
3027 struct phm_ppt_v2_information *table_info =
3028 (struct phm_ppt_v2_information *)(hwmgr->pptable);
3029
3030 if (table_info->vdd_dep_on_sclk->count > VEGA10_UMD_PSTATE_GFXCLK_LEVEL &&
3031 table_info->vdd_dep_on_mclk->count > VEGA10_UMD_PSTATE_MCLK_LEVEL) {
3032 hwmgr->pstate_sclk = table_info->vdd_dep_on_sclk->entries[VEGA10_UMD_PSTATE_GFXCLK_LEVEL].clk;
3033 hwmgr->pstate_mclk = table_info->vdd_dep_on_mclk->entries[VEGA10_UMD_PSTATE_MCLK_LEVEL].clk;
3034 } else {
3035 hwmgr->pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3036 hwmgr->pstate_mclk = table_info->vdd_dep_on_mclk->entries[0].clk;
3037 }
3038
3039 hwmgr->pstate_sclk_peak = table_info->vdd_dep_on_sclk->entries[table_info->vdd_dep_on_sclk->count - 1].clk;
3040 hwmgr->pstate_mclk_peak = table_info->vdd_dep_on_mclk->entries[table_info->vdd_dep_on_mclk->count - 1].clk;
3041
3042 /* make sure the output is in Mhz */
3043 hwmgr->pstate_sclk /= 100;
3044 hwmgr->pstate_mclk /= 100;
3045 hwmgr->pstate_sclk_peak /= 100;
3046 hwmgr->pstate_mclk_peak /= 100;
3047 }
3048
vega10_enable_dpm_tasks(struct pp_hwmgr * hwmgr)3049 static int vega10_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
3050 {
3051 struct vega10_hwmgr *data = hwmgr->backend;
3052 int tmp_result, result = 0;
3053
3054 if (hwmgr->not_vf) {
3055 vega10_enable_disable_PCC_limit_feature(hwmgr, true);
3056
3057 smum_send_msg_to_smc_with_parameter(hwmgr,
3058 PPSMC_MSG_ConfigureTelemetry, data->config_telemetry,
3059 NULL);
3060
3061 tmp_result = vega10_construct_voltage_tables(hwmgr);
3062 PP_ASSERT_WITH_CODE(!tmp_result,
3063 "Failed to construct voltage tables!",
3064 result = tmp_result);
3065 }
3066
3067 if (hwmgr->not_vf || hwmgr->pp_one_vf) {
3068 tmp_result = vega10_init_smc_table(hwmgr);
3069 PP_ASSERT_WITH_CODE(!tmp_result,
3070 "Failed to initialize SMC table!",
3071 result = tmp_result);
3072 }
3073
3074 if (hwmgr->not_vf) {
3075 if (PP_CAP(PHM_PlatformCaps_ThermalController)) {
3076 tmp_result = vega10_enable_thermal_protection(hwmgr);
3077 PP_ASSERT_WITH_CODE(!tmp_result,
3078 "Failed to enable thermal protection!",
3079 result = tmp_result);
3080 }
3081
3082 tmp_result = vega10_enable_vrhot_feature(hwmgr);
3083 PP_ASSERT_WITH_CODE(!tmp_result,
3084 "Failed to enable VR hot feature!",
3085 result = tmp_result);
3086
3087 tmp_result = vega10_enable_deep_sleep_master_switch(hwmgr);
3088 PP_ASSERT_WITH_CODE(!tmp_result,
3089 "Failed to enable deep sleep master switch!",
3090 result = tmp_result);
3091 }
3092
3093 if (hwmgr->not_vf) {
3094 tmp_result = vega10_start_dpm(hwmgr, SMC_DPM_FEATURES);
3095 PP_ASSERT_WITH_CODE(!tmp_result,
3096 "Failed to start DPM!", result = tmp_result);
3097 }
3098
3099 if (hwmgr->not_vf) {
3100 /* enable didt, do not abort if failed didt */
3101 tmp_result = vega10_enable_didt_config(hwmgr);
3102 PP_ASSERT(!tmp_result,
3103 "Failed to enable didt config!");
3104 }
3105
3106 tmp_result = vega10_enable_power_containment(hwmgr);
3107 PP_ASSERT_WITH_CODE(!tmp_result,
3108 "Failed to enable power containment!",
3109 result = tmp_result);
3110
3111 if (hwmgr->not_vf) {
3112 tmp_result = vega10_power_control_set_level(hwmgr);
3113 PP_ASSERT_WITH_CODE(!tmp_result,
3114 "Failed to power control set level!",
3115 result = tmp_result);
3116
3117 tmp_result = vega10_enable_ulv(hwmgr);
3118 PP_ASSERT_WITH_CODE(!tmp_result,
3119 "Failed to enable ULV!",
3120 result = tmp_result);
3121 }
3122
3123 vega10_populate_umdpstate_clocks(hwmgr);
3124
3125 return result;
3126 }
3127
vega10_get_power_state_size(struct pp_hwmgr * hwmgr)3128 static int vega10_get_power_state_size(struct pp_hwmgr *hwmgr)
3129 {
3130 return sizeof(struct vega10_power_state);
3131 }
3132
vega10_get_pp_table_entry_callback_func(struct pp_hwmgr * hwmgr,void * state,struct pp_power_state * power_state,void * pp_table,uint32_t classification_flag)3133 static int vega10_get_pp_table_entry_callback_func(struct pp_hwmgr *hwmgr,
3134 void *state, struct pp_power_state *power_state,
3135 void *pp_table, uint32_t classification_flag)
3136 {
3137 ATOM_Vega10_GFXCLK_Dependency_Record_V2 *patom_record_V2;
3138 struct vega10_power_state *vega10_ps =
3139 cast_phw_vega10_power_state(&(power_state->hardware));
3140 struct vega10_performance_level *performance_level;
3141 ATOM_Vega10_State *state_entry = (ATOM_Vega10_State *)state;
3142 ATOM_Vega10_POWERPLAYTABLE *powerplay_table =
3143 (ATOM_Vega10_POWERPLAYTABLE *)pp_table;
3144 ATOM_Vega10_SOCCLK_Dependency_Table *socclk_dep_table =
3145 (ATOM_Vega10_SOCCLK_Dependency_Table *)
3146 (((unsigned long)powerplay_table) +
3147 le16_to_cpu(powerplay_table->usSocclkDependencyTableOffset));
3148 ATOM_Vega10_GFXCLK_Dependency_Table *gfxclk_dep_table =
3149 (ATOM_Vega10_GFXCLK_Dependency_Table *)
3150 (((unsigned long)powerplay_table) +
3151 le16_to_cpu(powerplay_table->usGfxclkDependencyTableOffset));
3152 ATOM_Vega10_MCLK_Dependency_Table *mclk_dep_table =
3153 (ATOM_Vega10_MCLK_Dependency_Table *)
3154 (((unsigned long)powerplay_table) +
3155 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
3156
3157
3158 /* The following fields are not initialized here:
3159 * id orderedList allStatesList
3160 */
3161 power_state->classification.ui_label =
3162 (le16_to_cpu(state_entry->usClassification) &
3163 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >>
3164 ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
3165 power_state->classification.flags = classification_flag;
3166 /* NOTE: There is a classification2 flag in BIOS
3167 * that is not being used right now
3168 */
3169 power_state->classification.temporary_state = false;
3170 power_state->classification.to_be_deleted = false;
3171
3172 power_state->validation.disallowOnDC =
3173 ((le32_to_cpu(state_entry->ulCapsAndSettings) &
3174 ATOM_Vega10_DISALLOW_ON_DC) != 0);
3175
3176 power_state->display.disableFrameModulation = false;
3177 power_state->display.limitRefreshrate = false;
3178 power_state->display.enableVariBright =
3179 ((le32_to_cpu(state_entry->ulCapsAndSettings) &
3180 ATOM_Vega10_ENABLE_VARIBRIGHT) != 0);
3181
3182 power_state->validation.supportedPowerLevels = 0;
3183 power_state->uvd_clocks.VCLK = 0;
3184 power_state->uvd_clocks.DCLK = 0;
3185 power_state->temperatures.min = 0;
3186 power_state->temperatures.max = 0;
3187
3188 performance_level = &(vega10_ps->performance_levels
3189 [vega10_ps->performance_level_count++]);
3190
3191 PP_ASSERT_WITH_CODE(
3192 (vega10_ps->performance_level_count <
3193 NUM_GFXCLK_DPM_LEVELS),
3194 "Performance levels exceeds SMC limit!",
3195 return -1);
3196
3197 PP_ASSERT_WITH_CODE(
3198 (vega10_ps->performance_level_count <
3199 hwmgr->platform_descriptor.
3200 hardwareActivityPerformanceLevels),
3201 "Performance levels exceeds Driver limit!",
3202 return -1);
3203
3204 /* Performance levels are arranged from low to high. */
3205 performance_level->soc_clock = socclk_dep_table->entries
3206 [state_entry->ucSocClockIndexLow].ulClk;
3207 performance_level->gfx_clock = gfxclk_dep_table->entries
3208 [state_entry->ucGfxClockIndexLow].ulClk;
3209 performance_level->mem_clock = mclk_dep_table->entries
3210 [state_entry->ucMemClockIndexLow].ulMemClk;
3211
3212 performance_level = &(vega10_ps->performance_levels
3213 [vega10_ps->performance_level_count++]);
3214 performance_level->soc_clock = socclk_dep_table->entries
3215 [state_entry->ucSocClockIndexHigh].ulClk;
3216 if (gfxclk_dep_table->ucRevId == 0) {
3217 /* under vega10 pp one vf mode, the gfx clk dpm need be lower
3218 * to level-4 due to the limited 110w-power
3219 */
3220 if (hwmgr->pp_one_vf && (state_entry->ucGfxClockIndexHigh > 0))
3221 performance_level->gfx_clock =
3222 gfxclk_dep_table->entries[4].ulClk;
3223 else
3224 performance_level->gfx_clock = gfxclk_dep_table->entries
3225 [state_entry->ucGfxClockIndexHigh].ulClk;
3226 } else if (gfxclk_dep_table->ucRevId == 1) {
3227 patom_record_V2 = (ATOM_Vega10_GFXCLK_Dependency_Record_V2 *)gfxclk_dep_table->entries;
3228 if (hwmgr->pp_one_vf && (state_entry->ucGfxClockIndexHigh > 0))
3229 performance_level->gfx_clock = patom_record_V2[4].ulClk;
3230 else
3231 performance_level->gfx_clock =
3232 patom_record_V2[state_entry->ucGfxClockIndexHigh].ulClk;
3233 }
3234
3235 performance_level->mem_clock = mclk_dep_table->entries
3236 [state_entry->ucMemClockIndexHigh].ulMemClk;
3237 return 0;
3238 }
3239
vega10_get_pp_table_entry(struct pp_hwmgr * hwmgr,unsigned long entry_index,struct pp_power_state * state)3240 static int vega10_get_pp_table_entry(struct pp_hwmgr *hwmgr,
3241 unsigned long entry_index, struct pp_power_state *state)
3242 {
3243 int result;
3244 struct vega10_power_state *vega10_ps;
3245
3246 state->hardware.magic = PhwVega10_Magic;
3247
3248 vega10_ps = cast_phw_vega10_power_state(&state->hardware);
3249
3250 result = vega10_get_powerplay_table_entry(hwmgr, entry_index, state,
3251 vega10_get_pp_table_entry_callback_func);
3252 if (result)
3253 return result;
3254
3255 /*
3256 * This is the earliest time we have all the dependency table
3257 * and the VBIOS boot state
3258 */
3259 /* set DC compatible flag if this state supports DC */
3260 if (!state->validation.disallowOnDC)
3261 vega10_ps->dc_compatible = true;
3262
3263 vega10_ps->uvd_clks.vclk = state->uvd_clocks.VCLK;
3264 vega10_ps->uvd_clks.dclk = state->uvd_clocks.DCLK;
3265
3266 return 0;
3267 }
3268
vega10_patch_boot_state(struct pp_hwmgr * hwmgr,struct pp_hw_power_state * hw_ps)3269 static int vega10_patch_boot_state(struct pp_hwmgr *hwmgr,
3270 struct pp_hw_power_state *hw_ps)
3271 {
3272 return 0;
3273 }
3274
vega10_apply_state_adjust_rules(struct pp_hwmgr * hwmgr,struct pp_power_state * request_ps,const struct pp_power_state * current_ps)3275 static int vega10_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
3276 struct pp_power_state *request_ps,
3277 const struct pp_power_state *current_ps)
3278 {
3279 struct amdgpu_device *adev = hwmgr->adev;
3280 struct vega10_power_state *vega10_ps;
3281 uint32_t sclk;
3282 uint32_t mclk;
3283 struct PP_Clocks minimum_clocks = {0};
3284 bool disable_mclk_switching;
3285 bool disable_mclk_switching_for_frame_lock;
3286 bool disable_mclk_switching_for_vr;
3287 bool force_mclk_high;
3288 const struct phm_clock_and_voltage_limits *max_limits;
3289 uint32_t i;
3290 struct vega10_hwmgr *data = hwmgr->backend;
3291 struct phm_ppt_v2_information *table_info =
3292 (struct phm_ppt_v2_information *)(hwmgr->pptable);
3293 int32_t count;
3294 uint32_t stable_pstate_sclk_dpm_percentage;
3295 uint32_t stable_pstate_sclk = 0, stable_pstate_mclk = 0;
3296 uint32_t latency;
3297
3298 vega10_ps = cast_phw_vega10_power_state(&request_ps->hardware);
3299 if (!vega10_ps)
3300 return -EINVAL;
3301
3302 data->battery_state = (PP_StateUILabel_Battery ==
3303 request_ps->classification.ui_label);
3304
3305 if (vega10_ps->performance_level_count != 2)
3306 pr_info("VI should always have 2 performance levels");
3307
3308 max_limits = adev->pm.ac_power ?
3309 &(hwmgr->dyn_state.max_clock_voltage_on_ac) :
3310 &(hwmgr->dyn_state.max_clock_voltage_on_dc);
3311
3312 /* Cap clock DPM tables at DC MAX if it is in DC. */
3313 if (!adev->pm.ac_power) {
3314 for (i = 0; i < vega10_ps->performance_level_count; i++) {
3315 if (vega10_ps->performance_levels[i].mem_clock >
3316 max_limits->mclk)
3317 vega10_ps->performance_levels[i].mem_clock =
3318 max_limits->mclk;
3319 if (vega10_ps->performance_levels[i].gfx_clock >
3320 max_limits->sclk)
3321 vega10_ps->performance_levels[i].gfx_clock =
3322 max_limits->sclk;
3323 }
3324 }
3325
3326 /* result = PHM_CheckVBlankTime(hwmgr, &vblankTooShort);*/
3327 minimum_clocks.engineClock = hwmgr->display_config->min_core_set_clock;
3328 minimum_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
3329
3330 if (PP_CAP(PHM_PlatformCaps_StablePState)) {
3331 stable_pstate_sclk_dpm_percentage =
3332 data->registry_data.stable_pstate_sclk_dpm_percentage;
3333 PP_ASSERT_WITH_CODE(
3334 data->registry_data.stable_pstate_sclk_dpm_percentage >= 1 &&
3335 data->registry_data.stable_pstate_sclk_dpm_percentage <= 100,
3336 "percent sclk value must range from 1% to 100%, setting default value",
3337 stable_pstate_sclk_dpm_percentage = 75);
3338
3339 max_limits = &(hwmgr->dyn_state.max_clock_voltage_on_ac);
3340 stable_pstate_sclk = (max_limits->sclk *
3341 stable_pstate_sclk_dpm_percentage) / 100;
3342
3343 for (count = table_info->vdd_dep_on_sclk->count - 1;
3344 count >= 0; count--) {
3345 if (stable_pstate_sclk >=
3346 table_info->vdd_dep_on_sclk->entries[count].clk) {
3347 stable_pstate_sclk =
3348 table_info->vdd_dep_on_sclk->entries[count].clk;
3349 break;
3350 }
3351 }
3352
3353 if (count < 0)
3354 stable_pstate_sclk = table_info->vdd_dep_on_sclk->entries[0].clk;
3355
3356 stable_pstate_mclk = max_limits->mclk;
3357
3358 minimum_clocks.engineClock = stable_pstate_sclk;
3359 minimum_clocks.memoryClock = stable_pstate_mclk;
3360 }
3361
3362 disable_mclk_switching_for_frame_lock =
3363 PP_CAP(PHM_PlatformCaps_DisableMclkSwitchingForFrameLock);
3364 disable_mclk_switching_for_vr =
3365 PP_CAP(PHM_PlatformCaps_DisableMclkSwitchForVR);
3366 force_mclk_high = PP_CAP(PHM_PlatformCaps_ForceMclkHigh);
3367
3368 if (hwmgr->display_config->num_display == 0)
3369 disable_mclk_switching = false;
3370 else
3371 disable_mclk_switching = ((1 < hwmgr->display_config->num_display) &&
3372 !hwmgr->display_config->multi_monitor_in_sync) ||
3373 disable_mclk_switching_for_frame_lock ||
3374 disable_mclk_switching_for_vr ||
3375 force_mclk_high;
3376
3377 sclk = vega10_ps->performance_levels[0].gfx_clock;
3378 mclk = vega10_ps->performance_levels[0].mem_clock;
3379
3380 if (sclk < minimum_clocks.engineClock)
3381 sclk = (minimum_clocks.engineClock > max_limits->sclk) ?
3382 max_limits->sclk : minimum_clocks.engineClock;
3383
3384 if (mclk < minimum_clocks.memoryClock)
3385 mclk = (minimum_clocks.memoryClock > max_limits->mclk) ?
3386 max_limits->mclk : minimum_clocks.memoryClock;
3387
3388 vega10_ps->performance_levels[0].gfx_clock = sclk;
3389 vega10_ps->performance_levels[0].mem_clock = mclk;
3390
3391 if (vega10_ps->performance_levels[1].gfx_clock <
3392 vega10_ps->performance_levels[0].gfx_clock)
3393 vega10_ps->performance_levels[0].gfx_clock =
3394 vega10_ps->performance_levels[1].gfx_clock;
3395
3396 if (disable_mclk_switching) {
3397 /* Set Mclk the max of level 0 and level 1 */
3398 if (mclk < vega10_ps->performance_levels[1].mem_clock)
3399 mclk = vega10_ps->performance_levels[1].mem_clock;
3400
3401 /* Find the lowest MCLK frequency that is within
3402 * the tolerable latency defined in DAL
3403 */
3404 latency = hwmgr->display_config->dce_tolerable_mclk_in_active_latency;
3405 for (i = 0; i < data->mclk_latency_table.count; i++) {
3406 if ((data->mclk_latency_table.entries[i].latency <= latency) &&
3407 (data->mclk_latency_table.entries[i].frequency >=
3408 vega10_ps->performance_levels[0].mem_clock) &&
3409 (data->mclk_latency_table.entries[i].frequency <=
3410 vega10_ps->performance_levels[1].mem_clock))
3411 mclk = data->mclk_latency_table.entries[i].frequency;
3412 }
3413 vega10_ps->performance_levels[0].mem_clock = mclk;
3414 } else {
3415 if (vega10_ps->performance_levels[1].mem_clock <
3416 vega10_ps->performance_levels[0].mem_clock)
3417 vega10_ps->performance_levels[0].mem_clock =
3418 vega10_ps->performance_levels[1].mem_clock;
3419 }
3420
3421 if (PP_CAP(PHM_PlatformCaps_StablePState)) {
3422 for (i = 0; i < vega10_ps->performance_level_count; i++) {
3423 vega10_ps->performance_levels[i].gfx_clock = stable_pstate_sclk;
3424 vega10_ps->performance_levels[i].mem_clock = stable_pstate_mclk;
3425 }
3426 }
3427
3428 return 0;
3429 }
3430
vega10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr * hwmgr,const void * input)3431 static int vega10_find_dpm_states_clocks_in_dpm_table(struct pp_hwmgr *hwmgr, const void *input)
3432 {
3433 struct vega10_hwmgr *data = hwmgr->backend;
3434 const struct phm_set_power_state_input *states =
3435 (const struct phm_set_power_state_input *)input;
3436 const struct vega10_power_state *vega10_ps =
3437 cast_const_phw_vega10_power_state(states->pnew_state);
3438 struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table);
3439 struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table);
3440 uint32_t sclk, mclk;
3441 uint32_t i;
3442
3443 if (vega10_ps == NULL)
3444 return -EINVAL;
3445 sclk = vega10_ps->performance_levels
3446 [vega10_ps->performance_level_count - 1].gfx_clock;
3447 mclk = vega10_ps->performance_levels
3448 [vega10_ps->performance_level_count - 1].mem_clock;
3449
3450 for (i = 0; i < sclk_table->count; i++) {
3451 if (sclk == sclk_table->dpm_levels[i].value)
3452 break;
3453 }
3454
3455 if (i >= sclk_table->count) {
3456 if (sclk > sclk_table->dpm_levels[i-1].value) {
3457 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
3458 sclk_table->dpm_levels[i-1].value = sclk;
3459 }
3460 }
3461
3462 for (i = 0; i < mclk_table->count; i++) {
3463 if (mclk == mclk_table->dpm_levels[i].value)
3464 break;
3465 }
3466
3467 if (i >= mclk_table->count) {
3468 if (mclk > mclk_table->dpm_levels[i-1].value) {
3469 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
3470 mclk_table->dpm_levels[i-1].value = mclk;
3471 }
3472 }
3473
3474 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
3475 data->need_update_dpm_table |= DPMTABLE_UPDATE_MCLK;
3476
3477 return 0;
3478 }
3479
vega10_populate_and_upload_sclk_mclk_dpm_levels(struct pp_hwmgr * hwmgr,const void * input)3480 static int vega10_populate_and_upload_sclk_mclk_dpm_levels(
3481 struct pp_hwmgr *hwmgr, const void *input)
3482 {
3483 int result = 0;
3484 struct vega10_hwmgr *data = hwmgr->backend;
3485 struct vega10_dpm_table *dpm_table = &data->dpm_table;
3486 struct vega10_odn_dpm_table *odn_table = &data->odn_dpm_table;
3487 struct vega10_odn_clock_voltage_dependency_table *odn_clk_table = &odn_table->vdd_dep_on_sclk;
3488 int count;
3489
3490 if (!data->need_update_dpm_table)
3491 return 0;
3492
3493 if (hwmgr->od_enabled && data->need_update_dpm_table & DPMTABLE_OD_UPDATE_SCLK) {
3494 for (count = 0; count < dpm_table->gfx_table.count; count++)
3495 dpm_table->gfx_table.dpm_levels[count].value = odn_clk_table->entries[count].clk;
3496 }
3497
3498 odn_clk_table = &odn_table->vdd_dep_on_mclk;
3499 if (hwmgr->od_enabled && data->need_update_dpm_table & DPMTABLE_OD_UPDATE_MCLK) {
3500 for (count = 0; count < dpm_table->mem_table.count; count++)
3501 dpm_table->mem_table.dpm_levels[count].value = odn_clk_table->entries[count].clk;
3502 }
3503
3504 if (data->need_update_dpm_table &
3505 (DPMTABLE_OD_UPDATE_SCLK | DPMTABLE_UPDATE_SCLK | DPMTABLE_UPDATE_SOCCLK)) {
3506 result = vega10_populate_all_graphic_levels(hwmgr);
3507 PP_ASSERT_WITH_CODE((0 == result),
3508 "Failed to populate SCLK during PopulateNewDPMClocksStates Function!",
3509 return result);
3510 }
3511
3512 if (data->need_update_dpm_table &
3513 (DPMTABLE_OD_UPDATE_MCLK | DPMTABLE_UPDATE_MCLK)) {
3514 result = vega10_populate_all_memory_levels(hwmgr);
3515 PP_ASSERT_WITH_CODE((0 == result),
3516 "Failed to populate MCLK during PopulateNewDPMClocksStates Function!",
3517 return result);
3518 }
3519
3520 vega10_populate_vddc_soc_levels(hwmgr);
3521
3522 return result;
3523 }
3524
vega10_trim_single_dpm_states(struct pp_hwmgr * hwmgr,struct vega10_single_dpm_table * dpm_table,uint32_t low_limit,uint32_t high_limit)3525 static int vega10_trim_single_dpm_states(struct pp_hwmgr *hwmgr,
3526 struct vega10_single_dpm_table *dpm_table,
3527 uint32_t low_limit, uint32_t high_limit)
3528 {
3529 uint32_t i;
3530
3531 for (i = 0; i < dpm_table->count; i++) {
3532 if ((dpm_table->dpm_levels[i].value < low_limit) ||
3533 (dpm_table->dpm_levels[i].value > high_limit))
3534 dpm_table->dpm_levels[i].enabled = false;
3535 else
3536 dpm_table->dpm_levels[i].enabled = true;
3537 }
3538 return 0;
3539 }
3540
vega10_trim_single_dpm_states_with_mask(struct pp_hwmgr * hwmgr,struct vega10_single_dpm_table * dpm_table,uint32_t low_limit,uint32_t high_limit,uint32_t disable_dpm_mask)3541 static int vega10_trim_single_dpm_states_with_mask(struct pp_hwmgr *hwmgr,
3542 struct vega10_single_dpm_table *dpm_table,
3543 uint32_t low_limit, uint32_t high_limit,
3544 uint32_t disable_dpm_mask)
3545 {
3546 uint32_t i;
3547
3548 for (i = 0; i < dpm_table->count; i++) {
3549 if ((dpm_table->dpm_levels[i].value < low_limit) ||
3550 (dpm_table->dpm_levels[i].value > high_limit))
3551 dpm_table->dpm_levels[i].enabled = false;
3552 else if (!((1 << i) & disable_dpm_mask))
3553 dpm_table->dpm_levels[i].enabled = false;
3554 else
3555 dpm_table->dpm_levels[i].enabled = true;
3556 }
3557 return 0;
3558 }
3559
vega10_trim_dpm_states(struct pp_hwmgr * hwmgr,const struct vega10_power_state * vega10_ps)3560 static int vega10_trim_dpm_states(struct pp_hwmgr *hwmgr,
3561 const struct vega10_power_state *vega10_ps)
3562 {
3563 struct vega10_hwmgr *data = hwmgr->backend;
3564 uint32_t high_limit_count;
3565
3566 PP_ASSERT_WITH_CODE((vega10_ps->performance_level_count >= 1),
3567 "power state did not have any performance level",
3568 return -1);
3569
3570 high_limit_count = (vega10_ps->performance_level_count == 1) ? 0 : 1;
3571
3572 vega10_trim_single_dpm_states(hwmgr,
3573 &(data->dpm_table.soc_table),
3574 vega10_ps->performance_levels[0].soc_clock,
3575 vega10_ps->performance_levels[high_limit_count].soc_clock);
3576
3577 vega10_trim_single_dpm_states_with_mask(hwmgr,
3578 &(data->dpm_table.gfx_table),
3579 vega10_ps->performance_levels[0].gfx_clock,
3580 vega10_ps->performance_levels[high_limit_count].gfx_clock,
3581 data->disable_dpm_mask);
3582
3583 vega10_trim_single_dpm_states(hwmgr,
3584 &(data->dpm_table.mem_table),
3585 vega10_ps->performance_levels[0].mem_clock,
3586 vega10_ps->performance_levels[high_limit_count].mem_clock);
3587
3588 return 0;
3589 }
3590
vega10_find_lowest_dpm_level(struct vega10_single_dpm_table * table)3591 static uint32_t vega10_find_lowest_dpm_level(
3592 struct vega10_single_dpm_table *table)
3593 {
3594 uint32_t i;
3595
3596 for (i = 0; i < table->count; i++) {
3597 if (table->dpm_levels[i].enabled)
3598 break;
3599 }
3600
3601 return i;
3602 }
3603
vega10_find_highest_dpm_level(struct vega10_single_dpm_table * table)3604 static uint32_t vega10_find_highest_dpm_level(
3605 struct vega10_single_dpm_table *table)
3606 {
3607 uint32_t i = 0;
3608
3609 if (table->count <= MAX_REGULAR_DPM_NUMBER) {
3610 for (i = table->count; i > 0; i--) {
3611 if (table->dpm_levels[i - 1].enabled)
3612 return i - 1;
3613 }
3614 } else {
3615 pr_info("DPM Table Has Too Many Entries!");
3616 return MAX_REGULAR_DPM_NUMBER - 1;
3617 }
3618
3619 return i;
3620 }
3621
vega10_apply_dal_minimum_voltage_request(struct pp_hwmgr * hwmgr)3622 static void vega10_apply_dal_minimum_voltage_request(
3623 struct pp_hwmgr *hwmgr)
3624 {
3625 return;
3626 }
3627
vega10_get_soc_index_for_max_uclk(struct pp_hwmgr * hwmgr)3628 static int vega10_get_soc_index_for_max_uclk(struct pp_hwmgr *hwmgr)
3629 {
3630 struct phm_ppt_v1_clock_voltage_dependency_table *vdd_dep_table_on_mclk;
3631 struct phm_ppt_v2_information *table_info =
3632 (struct phm_ppt_v2_information *)(hwmgr->pptable);
3633
3634 vdd_dep_table_on_mclk = table_info->vdd_dep_on_mclk;
3635
3636 return vdd_dep_table_on_mclk->entries[NUM_UCLK_DPM_LEVELS - 1].vddInd + 1;
3637 }
3638
vega10_upload_dpm_bootup_level(struct pp_hwmgr * hwmgr)3639 static int vega10_upload_dpm_bootup_level(struct pp_hwmgr *hwmgr)
3640 {
3641 struct vega10_hwmgr *data = hwmgr->backend;
3642 uint32_t socclk_idx;
3643
3644 vega10_apply_dal_minimum_voltage_request(hwmgr);
3645
3646 if (!data->registry_data.sclk_dpm_key_disabled) {
3647 if (data->smc_state_table.gfx_boot_level !=
3648 data->dpm_table.gfx_table.dpm_state.soft_min_level) {
3649 smum_send_msg_to_smc_with_parameter(hwmgr,
3650 PPSMC_MSG_SetSoftMinGfxclkByIndex,
3651 data->smc_state_table.gfx_boot_level,
3652 NULL);
3653
3654 data->dpm_table.gfx_table.dpm_state.soft_min_level =
3655 data->smc_state_table.gfx_boot_level;
3656 }
3657 }
3658
3659 if (!data->registry_data.mclk_dpm_key_disabled) {
3660 if (data->smc_state_table.mem_boot_level !=
3661 data->dpm_table.mem_table.dpm_state.soft_min_level) {
3662 if ((data->smc_state_table.mem_boot_level == NUM_UCLK_DPM_LEVELS - 1)
3663 && hwmgr->not_vf) {
3664 socclk_idx = vega10_get_soc_index_for_max_uclk(hwmgr);
3665 smum_send_msg_to_smc_with_parameter(hwmgr,
3666 PPSMC_MSG_SetSoftMinSocclkByIndex,
3667 socclk_idx,
3668 NULL);
3669 } else {
3670 smum_send_msg_to_smc_with_parameter(hwmgr,
3671 PPSMC_MSG_SetSoftMinUclkByIndex,
3672 data->smc_state_table.mem_boot_level,
3673 NULL);
3674 }
3675 data->dpm_table.mem_table.dpm_state.soft_min_level =
3676 data->smc_state_table.mem_boot_level;
3677 }
3678 }
3679
3680 if (!hwmgr->not_vf)
3681 return 0;
3682
3683 if (!data->registry_data.socclk_dpm_key_disabled) {
3684 if (data->smc_state_table.soc_boot_level !=
3685 data->dpm_table.soc_table.dpm_state.soft_min_level) {
3686 smum_send_msg_to_smc_with_parameter(hwmgr,
3687 PPSMC_MSG_SetSoftMinSocclkByIndex,
3688 data->smc_state_table.soc_boot_level,
3689 NULL);
3690 data->dpm_table.soc_table.dpm_state.soft_min_level =
3691 data->smc_state_table.soc_boot_level;
3692 }
3693 }
3694
3695 return 0;
3696 }
3697
vega10_upload_dpm_max_level(struct pp_hwmgr * hwmgr)3698 static int vega10_upload_dpm_max_level(struct pp_hwmgr *hwmgr)
3699 {
3700 struct vega10_hwmgr *data = hwmgr->backend;
3701
3702 vega10_apply_dal_minimum_voltage_request(hwmgr);
3703
3704 if (!data->registry_data.sclk_dpm_key_disabled) {
3705 if (data->smc_state_table.gfx_max_level !=
3706 data->dpm_table.gfx_table.dpm_state.soft_max_level) {
3707 smum_send_msg_to_smc_with_parameter(hwmgr,
3708 PPSMC_MSG_SetSoftMaxGfxclkByIndex,
3709 data->smc_state_table.gfx_max_level,
3710 NULL);
3711 data->dpm_table.gfx_table.dpm_state.soft_max_level =
3712 data->smc_state_table.gfx_max_level;
3713 }
3714 }
3715
3716 if (!data->registry_data.mclk_dpm_key_disabled) {
3717 if (data->smc_state_table.mem_max_level !=
3718 data->dpm_table.mem_table.dpm_state.soft_max_level) {
3719 smum_send_msg_to_smc_with_parameter(hwmgr,
3720 PPSMC_MSG_SetSoftMaxUclkByIndex,
3721 data->smc_state_table.mem_max_level,
3722 NULL);
3723 data->dpm_table.mem_table.dpm_state.soft_max_level =
3724 data->smc_state_table.mem_max_level;
3725 }
3726 }
3727
3728 if (!hwmgr->not_vf)
3729 return 0;
3730
3731 if (!data->registry_data.socclk_dpm_key_disabled) {
3732 if (data->smc_state_table.soc_max_level !=
3733 data->dpm_table.soc_table.dpm_state.soft_max_level) {
3734 smum_send_msg_to_smc_with_parameter(hwmgr,
3735 PPSMC_MSG_SetSoftMaxSocclkByIndex,
3736 data->smc_state_table.soc_max_level,
3737 NULL);
3738 data->dpm_table.soc_table.dpm_state.soft_max_level =
3739 data->smc_state_table.soc_max_level;
3740 }
3741 }
3742
3743 return 0;
3744 }
3745
vega10_generate_dpm_level_enable_mask(struct pp_hwmgr * hwmgr,const void * input)3746 static int vega10_generate_dpm_level_enable_mask(
3747 struct pp_hwmgr *hwmgr, const void *input)
3748 {
3749 struct vega10_hwmgr *data = hwmgr->backend;
3750 const struct phm_set_power_state_input *states =
3751 (const struct phm_set_power_state_input *)input;
3752 const struct vega10_power_state *vega10_ps =
3753 cast_const_phw_vega10_power_state(states->pnew_state);
3754 int i;
3755
3756 if (vega10_ps == NULL)
3757 return -EINVAL;
3758
3759 PP_ASSERT_WITH_CODE(!vega10_trim_dpm_states(hwmgr, vega10_ps),
3760 "Attempt to Trim DPM States Failed!",
3761 return -1);
3762
3763 data->smc_state_table.gfx_boot_level =
3764 vega10_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
3765 data->smc_state_table.gfx_max_level =
3766 vega10_find_highest_dpm_level(&(data->dpm_table.gfx_table));
3767 data->smc_state_table.mem_boot_level =
3768 vega10_find_lowest_dpm_level(&(data->dpm_table.mem_table));
3769 data->smc_state_table.mem_max_level =
3770 vega10_find_highest_dpm_level(&(data->dpm_table.mem_table));
3771 data->smc_state_table.soc_boot_level =
3772 vega10_find_lowest_dpm_level(&(data->dpm_table.soc_table));
3773 data->smc_state_table.soc_max_level =
3774 vega10_find_highest_dpm_level(&(data->dpm_table.soc_table));
3775
3776 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
3777 "Attempt to upload DPM Bootup Levels Failed!",
3778 return -1);
3779 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
3780 "Attempt to upload DPM Max Levels Failed!",
3781 return -1);
3782 for(i = data->smc_state_table.gfx_boot_level; i < data->smc_state_table.gfx_max_level; i++)
3783 data->dpm_table.gfx_table.dpm_levels[i].enabled = true;
3784
3785
3786 for(i = data->smc_state_table.mem_boot_level; i < data->smc_state_table.mem_max_level; i++)
3787 data->dpm_table.mem_table.dpm_levels[i].enabled = true;
3788
3789 for (i = data->smc_state_table.soc_boot_level; i < data->smc_state_table.soc_max_level; i++)
3790 data->dpm_table.soc_table.dpm_levels[i].enabled = true;
3791
3792 return 0;
3793 }
3794
vega10_enable_disable_vce_dpm(struct pp_hwmgr * hwmgr,bool enable)3795 int vega10_enable_disable_vce_dpm(struct pp_hwmgr *hwmgr, bool enable)
3796 {
3797 struct vega10_hwmgr *data = hwmgr->backend;
3798
3799 if (data->smu_features[GNLD_DPM_VCE].supported) {
3800 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
3801 enable,
3802 data->smu_features[GNLD_DPM_VCE].smu_feature_bitmap),
3803 "Attempt to Enable/Disable DPM VCE Failed!",
3804 return -1);
3805 data->smu_features[GNLD_DPM_VCE].enabled = enable;
3806 }
3807
3808 return 0;
3809 }
3810
vega10_update_sclk_threshold(struct pp_hwmgr * hwmgr)3811 static int vega10_update_sclk_threshold(struct pp_hwmgr *hwmgr)
3812 {
3813 struct vega10_hwmgr *data = hwmgr->backend;
3814 uint32_t low_sclk_interrupt_threshold = 0;
3815
3816 if (PP_CAP(PHM_PlatformCaps_SclkThrottleLowNotification) &&
3817 (data->low_sclk_interrupt_threshold != 0)) {
3818 low_sclk_interrupt_threshold =
3819 data->low_sclk_interrupt_threshold;
3820
3821 data->smc_state_table.pp_table.LowGfxclkInterruptThreshold =
3822 cpu_to_le32(low_sclk_interrupt_threshold);
3823
3824 /* This message will also enable SmcToHost Interrupt */
3825 smum_send_msg_to_smc_with_parameter(hwmgr,
3826 PPSMC_MSG_SetLowGfxclkInterruptThreshold,
3827 (uint32_t)low_sclk_interrupt_threshold,
3828 NULL);
3829 }
3830
3831 return 0;
3832 }
3833
vega10_set_power_state_tasks(struct pp_hwmgr * hwmgr,const void * input)3834 static int vega10_set_power_state_tasks(struct pp_hwmgr *hwmgr,
3835 const void *input)
3836 {
3837 int tmp_result, result = 0;
3838 struct vega10_hwmgr *data = hwmgr->backend;
3839 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
3840
3841 tmp_result = vega10_find_dpm_states_clocks_in_dpm_table(hwmgr, input);
3842 PP_ASSERT_WITH_CODE(!tmp_result,
3843 "Failed to find DPM states clocks in DPM table!",
3844 result = tmp_result);
3845
3846 tmp_result = vega10_populate_and_upload_sclk_mclk_dpm_levels(hwmgr, input);
3847 PP_ASSERT_WITH_CODE(!tmp_result,
3848 "Failed to populate and upload SCLK MCLK DPM levels!",
3849 result = tmp_result);
3850
3851 tmp_result = vega10_generate_dpm_level_enable_mask(hwmgr, input);
3852 PP_ASSERT_WITH_CODE(!tmp_result,
3853 "Failed to generate DPM level enabled mask!",
3854 result = tmp_result);
3855
3856 tmp_result = vega10_update_sclk_threshold(hwmgr);
3857 PP_ASSERT_WITH_CODE(!tmp_result,
3858 "Failed to update SCLK threshold!",
3859 result = tmp_result);
3860
3861 result = smum_smc_table_manager(hwmgr, (uint8_t *)pp_table, PPTABLE, false);
3862 PP_ASSERT_WITH_CODE(!result,
3863 "Failed to upload PPtable!", return result);
3864
3865 /*
3866 * If a custom pp table is loaded, set DPMTABLE_OD_UPDATE_VDDC flag.
3867 * That effectively disables AVFS feature.
3868 */
3869 if(hwmgr->hardcode_pp_table != NULL)
3870 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC;
3871
3872 vega10_update_avfs(hwmgr);
3873
3874 /*
3875 * Clear all OD flags except DPMTABLE_OD_UPDATE_VDDC.
3876 * That will help to keep AVFS disabled.
3877 */
3878 data->need_update_dpm_table &= DPMTABLE_OD_UPDATE_VDDC;
3879
3880 return 0;
3881 }
3882
vega10_dpm_get_sclk(struct pp_hwmgr * hwmgr,bool low)3883 static uint32_t vega10_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
3884 {
3885 struct pp_power_state *ps;
3886 struct vega10_power_state *vega10_ps;
3887
3888 if (hwmgr == NULL)
3889 return -EINVAL;
3890
3891 ps = hwmgr->request_ps;
3892
3893 if (ps == NULL)
3894 return -EINVAL;
3895
3896 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
3897
3898 if (low)
3899 return vega10_ps->performance_levels[0].gfx_clock;
3900 else
3901 return vega10_ps->performance_levels
3902 [vega10_ps->performance_level_count - 1].gfx_clock;
3903 }
3904
vega10_dpm_get_mclk(struct pp_hwmgr * hwmgr,bool low)3905 static uint32_t vega10_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
3906 {
3907 struct pp_power_state *ps;
3908 struct vega10_power_state *vega10_ps;
3909
3910 if (hwmgr == NULL)
3911 return -EINVAL;
3912
3913 ps = hwmgr->request_ps;
3914
3915 if (ps == NULL)
3916 return -EINVAL;
3917
3918 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
3919
3920 if (low)
3921 return vega10_ps->performance_levels[0].mem_clock;
3922 else
3923 return vega10_ps->performance_levels
3924 [vega10_ps->performance_level_count-1].mem_clock;
3925 }
3926
vega10_get_gpu_power(struct pp_hwmgr * hwmgr,uint32_t * query)3927 static int vega10_get_gpu_power(struct pp_hwmgr *hwmgr,
3928 uint32_t *query)
3929 {
3930 uint32_t value;
3931 int ret;
3932
3933 if (!query)
3934 return -EINVAL;
3935
3936 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrPkgPwr, &value);
3937 if (ret)
3938 return ret;
3939
3940 /* SMC returning actual watts, keep consistent with legacy asics, low 8 bit as 8 fractional bits */
3941 *query = value << 8;
3942
3943 return 0;
3944 }
3945
vega10_read_sensor(struct pp_hwmgr * hwmgr,int idx,void * value,int * size)3946 static int vega10_read_sensor(struct pp_hwmgr *hwmgr, int idx,
3947 void *value, int *size)
3948 {
3949 struct amdgpu_device *adev = hwmgr->adev;
3950 uint32_t sclk_mhz, mclk_idx, activity_percent = 0;
3951 struct vega10_hwmgr *data = hwmgr->backend;
3952 struct vega10_dpm_table *dpm_table = &data->dpm_table;
3953 int ret = 0;
3954 uint32_t val_vid;
3955
3956 switch (idx) {
3957 case AMDGPU_PP_SENSOR_GFX_SCLK:
3958 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetAverageGfxclkActualFrequency, &sclk_mhz);
3959 if (ret)
3960 break;
3961
3962 *((uint32_t *)value) = sclk_mhz * 100;
3963 break;
3964 case AMDGPU_PP_SENSOR_GFX_MCLK:
3965 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentUclkIndex, &mclk_idx);
3966 if (ret)
3967 break;
3968 if (mclk_idx < dpm_table->mem_table.count) {
3969 *((uint32_t *)value) = dpm_table->mem_table.dpm_levels[mclk_idx].value;
3970 *size = 4;
3971 } else {
3972 ret = -EINVAL;
3973 }
3974 break;
3975 case AMDGPU_PP_SENSOR_GPU_LOAD:
3976 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetAverageGfxActivity, 0,
3977 &activity_percent);
3978 *((uint32_t *)value) = activity_percent > 100 ? 100 : activity_percent;
3979 *size = 4;
3980 break;
3981 case AMDGPU_PP_SENSOR_GPU_TEMP:
3982 *((uint32_t *)value) = vega10_thermal_get_temperature(hwmgr);
3983 *size = 4;
3984 break;
3985 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
3986 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetTemperatureHotspot, (uint32_t *)value);
3987 *((uint32_t *)value) = *((uint32_t *)value) *
3988 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
3989 *size = 4;
3990 break;
3991 case AMDGPU_PP_SENSOR_MEM_TEMP:
3992 smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetTemperatureHBM, (uint32_t *)value);
3993 *((uint32_t *)value) = *((uint32_t *)value) *
3994 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
3995 *size = 4;
3996 break;
3997 case AMDGPU_PP_SENSOR_UVD_POWER:
3998 *((uint32_t *)value) = data->uvd_power_gated ? 0 : 1;
3999 *size = 4;
4000 break;
4001 case AMDGPU_PP_SENSOR_VCE_POWER:
4002 *((uint32_t *)value) = data->vce_power_gated ? 0 : 1;
4003 *size = 4;
4004 break;
4005 case AMDGPU_PP_SENSOR_GPU_INPUT_POWER:
4006 ret = vega10_get_gpu_power(hwmgr, (uint32_t *)value);
4007 break;
4008 case AMDGPU_PP_SENSOR_VDDGFX:
4009 val_vid = (RREG32_SOC15(SMUIO, 0, mmSMUSVI0_PLANE0_CURRENTVID) &
4010 SMUSVI0_PLANE0_CURRENTVID__CURRENT_SVI0_PLANE0_VID_MASK) >>
4011 SMUSVI0_PLANE0_CURRENTVID__CURRENT_SVI0_PLANE0_VID__SHIFT;
4012 *((uint32_t *)value) = (uint32_t)convert_to_vddc((uint8_t)val_vid);
4013 return 0;
4014 case AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK:
4015 ret = vega10_get_enabled_smc_features(hwmgr, (uint64_t *)value);
4016 if (!ret)
4017 *size = 8;
4018 break;
4019 default:
4020 ret = -EOPNOTSUPP;
4021 break;
4022 }
4023
4024 return ret;
4025 }
4026
vega10_notify_smc_display_change(struct pp_hwmgr * hwmgr,bool has_disp)4027 static void vega10_notify_smc_display_change(struct pp_hwmgr *hwmgr,
4028 bool has_disp)
4029 {
4030 smum_send_msg_to_smc_with_parameter(hwmgr,
4031 PPSMC_MSG_SetUclkFastSwitch,
4032 has_disp ? 1 : 0,
4033 NULL);
4034 }
4035
vega10_display_clock_voltage_request(struct pp_hwmgr * hwmgr,struct pp_display_clock_request * clock_req)4036 static int vega10_display_clock_voltage_request(struct pp_hwmgr *hwmgr,
4037 struct pp_display_clock_request *clock_req)
4038 {
4039 int result = 0;
4040 enum amd_pp_clock_type clk_type = clock_req->clock_type;
4041 uint32_t clk_freq = clock_req->clock_freq_in_khz / 1000;
4042 DSPCLK_e clk_select = 0;
4043 uint32_t clk_request = 0;
4044
4045 switch (clk_type) {
4046 case amd_pp_dcef_clock:
4047 clk_select = DSPCLK_DCEFCLK;
4048 break;
4049 case amd_pp_disp_clock:
4050 clk_select = DSPCLK_DISPCLK;
4051 break;
4052 case amd_pp_pixel_clock:
4053 clk_select = DSPCLK_PIXCLK;
4054 break;
4055 case amd_pp_phy_clock:
4056 clk_select = DSPCLK_PHYCLK;
4057 break;
4058 default:
4059 pr_info("[DisplayClockVoltageRequest]Invalid Clock Type!");
4060 result = -1;
4061 break;
4062 }
4063
4064 if (!result) {
4065 clk_request = (clk_freq << 16) | clk_select;
4066 smum_send_msg_to_smc_with_parameter(hwmgr,
4067 PPSMC_MSG_RequestDisplayClockByFreq,
4068 clk_request,
4069 NULL);
4070 }
4071
4072 return result;
4073 }
4074
vega10_get_uclk_index(struct pp_hwmgr * hwmgr,struct phm_ppt_v1_clock_voltage_dependency_table * mclk_table,uint32_t frequency)4075 static uint8_t vega10_get_uclk_index(struct pp_hwmgr *hwmgr,
4076 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table,
4077 uint32_t frequency)
4078 {
4079 uint8_t count;
4080 uint8_t i;
4081
4082 if (mclk_table == NULL || mclk_table->count == 0)
4083 return 0;
4084
4085 count = (uint8_t)(mclk_table->count);
4086
4087 for(i = 0; i < count; i++) {
4088 if(mclk_table->entries[i].clk >= frequency)
4089 return i;
4090 }
4091
4092 return i-1;
4093 }
4094
vega10_notify_smc_display_config_after_ps_adjustment(struct pp_hwmgr * hwmgr)4095 static int vega10_notify_smc_display_config_after_ps_adjustment(
4096 struct pp_hwmgr *hwmgr)
4097 {
4098 struct vega10_hwmgr *data = hwmgr->backend;
4099 struct vega10_single_dpm_table *dpm_table =
4100 &data->dpm_table.dcef_table;
4101 struct phm_ppt_v2_information *table_info =
4102 (struct phm_ppt_v2_information *)hwmgr->pptable;
4103 struct phm_ppt_v1_clock_voltage_dependency_table *mclk_table = table_info->vdd_dep_on_mclk;
4104 uint32_t idx;
4105 struct PP_Clocks min_clocks = {0};
4106 uint32_t i;
4107 struct pp_display_clock_request clock_req;
4108
4109 if ((hwmgr->display_config->num_display > 1) &&
4110 !hwmgr->display_config->multi_monitor_in_sync &&
4111 !hwmgr->display_config->nb_pstate_switch_disable)
4112 vega10_notify_smc_display_change(hwmgr, false);
4113 else
4114 vega10_notify_smc_display_change(hwmgr, true);
4115
4116 min_clocks.dcefClock = hwmgr->display_config->min_dcef_set_clk;
4117 min_clocks.dcefClockInSR = hwmgr->display_config->min_dcef_deep_sleep_set_clk;
4118 min_clocks.memoryClock = hwmgr->display_config->min_mem_set_clock;
4119
4120 for (i = 0; i < dpm_table->count; i++) {
4121 if (dpm_table->dpm_levels[i].value == min_clocks.dcefClock)
4122 break;
4123 }
4124
4125 if (i < dpm_table->count) {
4126 clock_req.clock_type = amd_pp_dcef_clock;
4127 clock_req.clock_freq_in_khz = dpm_table->dpm_levels[i].value * 10;
4128 if (!vega10_display_clock_voltage_request(hwmgr, &clock_req)) {
4129 smum_send_msg_to_smc_with_parameter(
4130 hwmgr, PPSMC_MSG_SetMinDeepSleepDcefclk,
4131 min_clocks.dcefClockInSR / 100,
4132 NULL);
4133 } else {
4134 pr_info("Attempt to set Hard Min for DCEFCLK Failed!");
4135 }
4136 } else {
4137 pr_debug("Cannot find requested DCEFCLK!");
4138 }
4139
4140 if (min_clocks.memoryClock != 0) {
4141 idx = vega10_get_uclk_index(hwmgr, mclk_table, min_clocks.memoryClock);
4142 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetSoftMinUclkByIndex, idx,
4143 NULL);
4144 data->dpm_table.mem_table.dpm_state.soft_min_level= idx;
4145 }
4146
4147 return 0;
4148 }
4149
vega10_force_dpm_highest(struct pp_hwmgr * hwmgr)4150 static int vega10_force_dpm_highest(struct pp_hwmgr *hwmgr)
4151 {
4152 struct vega10_hwmgr *data = hwmgr->backend;
4153
4154 data->smc_state_table.gfx_boot_level =
4155 data->smc_state_table.gfx_max_level =
4156 vega10_find_highest_dpm_level(&(data->dpm_table.gfx_table));
4157 data->smc_state_table.mem_boot_level =
4158 data->smc_state_table.mem_max_level =
4159 vega10_find_highest_dpm_level(&(data->dpm_table.mem_table));
4160
4161 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
4162 "Failed to upload boot level to highest!",
4163 return -1);
4164
4165 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
4166 "Failed to upload dpm max level to highest!",
4167 return -1);
4168
4169 return 0;
4170 }
4171
vega10_force_dpm_lowest(struct pp_hwmgr * hwmgr)4172 static int vega10_force_dpm_lowest(struct pp_hwmgr *hwmgr)
4173 {
4174 struct vega10_hwmgr *data = hwmgr->backend;
4175
4176 data->smc_state_table.gfx_boot_level =
4177 data->smc_state_table.gfx_max_level =
4178 vega10_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
4179 data->smc_state_table.mem_boot_level =
4180 data->smc_state_table.mem_max_level =
4181 vega10_find_lowest_dpm_level(&(data->dpm_table.mem_table));
4182
4183 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
4184 "Failed to upload boot level to highest!",
4185 return -1);
4186
4187 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
4188 "Failed to upload dpm max level to highest!",
4189 return -1);
4190
4191 return 0;
4192
4193 }
4194
vega10_unforce_dpm_levels(struct pp_hwmgr * hwmgr)4195 static int vega10_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
4196 {
4197 struct vega10_hwmgr *data = hwmgr->backend;
4198
4199 data->smc_state_table.gfx_boot_level =
4200 vega10_find_lowest_dpm_level(&(data->dpm_table.gfx_table));
4201 data->smc_state_table.gfx_max_level =
4202 vega10_find_highest_dpm_level(&(data->dpm_table.gfx_table));
4203 data->smc_state_table.mem_boot_level =
4204 vega10_find_lowest_dpm_level(&(data->dpm_table.mem_table));
4205 data->smc_state_table.mem_max_level =
4206 vega10_find_highest_dpm_level(&(data->dpm_table.mem_table));
4207
4208 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
4209 "Failed to upload DPM Bootup Levels!",
4210 return -1);
4211
4212 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
4213 "Failed to upload DPM Max Levels!",
4214 return -1);
4215 return 0;
4216 }
4217
vega10_get_profiling_clk_mask(struct pp_hwmgr * hwmgr,enum amd_dpm_forced_level level,uint32_t * sclk_mask,uint32_t * mclk_mask,uint32_t * soc_mask)4218 static int vega10_get_profiling_clk_mask(struct pp_hwmgr *hwmgr, enum amd_dpm_forced_level level,
4219 uint32_t *sclk_mask, uint32_t *mclk_mask, uint32_t *soc_mask)
4220 {
4221 struct phm_ppt_v2_information *table_info =
4222 (struct phm_ppt_v2_information *)(hwmgr->pptable);
4223
4224 if (table_info->vdd_dep_on_sclk->count > VEGA10_UMD_PSTATE_GFXCLK_LEVEL &&
4225 table_info->vdd_dep_on_socclk->count > VEGA10_UMD_PSTATE_SOCCLK_LEVEL &&
4226 table_info->vdd_dep_on_mclk->count > VEGA10_UMD_PSTATE_MCLK_LEVEL) {
4227 *sclk_mask = VEGA10_UMD_PSTATE_GFXCLK_LEVEL;
4228 *soc_mask = VEGA10_UMD_PSTATE_SOCCLK_LEVEL;
4229 *mclk_mask = VEGA10_UMD_PSTATE_MCLK_LEVEL;
4230 }
4231
4232 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
4233 *sclk_mask = 0;
4234 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
4235 *mclk_mask = 0;
4236 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
4237 /* under vega10 pp one vf mode, the gfx clk dpm need be lower
4238 * to level-4 due to the limited power
4239 */
4240 if (hwmgr->pp_one_vf)
4241 *sclk_mask = 4;
4242 else
4243 *sclk_mask = table_info->vdd_dep_on_sclk->count - 1;
4244 *soc_mask = table_info->vdd_dep_on_socclk->count - 1;
4245 *mclk_mask = table_info->vdd_dep_on_mclk->count - 1;
4246 }
4247
4248 return 0;
4249 }
4250
vega10_set_fan_control_mode(struct pp_hwmgr * hwmgr,uint32_t mode)4251 static void vega10_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
4252 {
4253 if (!hwmgr->not_vf)
4254 return;
4255
4256 switch (mode) {
4257 case AMD_FAN_CTRL_NONE:
4258 vega10_fan_ctrl_set_fan_speed_pwm(hwmgr, 255);
4259 break;
4260 case AMD_FAN_CTRL_MANUAL:
4261 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
4262 vega10_fan_ctrl_stop_smc_fan_control(hwmgr);
4263 break;
4264 case AMD_FAN_CTRL_AUTO:
4265 if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
4266 vega10_fan_ctrl_start_smc_fan_control(hwmgr);
4267 break;
4268 default:
4269 break;
4270 }
4271 }
4272
vega10_force_clock_level(struct pp_hwmgr * hwmgr,enum pp_clock_type type,uint32_t mask)4273 static int vega10_force_clock_level(struct pp_hwmgr *hwmgr,
4274 enum pp_clock_type type, uint32_t mask)
4275 {
4276 struct vega10_hwmgr *data = hwmgr->backend;
4277
4278 switch (type) {
4279 case PP_SCLK:
4280 data->smc_state_table.gfx_boot_level = mask ? (ffs(mask) - 1) : 0;
4281 data->smc_state_table.gfx_max_level = mask ? (fls(mask) - 1) : 0;
4282
4283 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
4284 "Failed to upload boot level to lowest!",
4285 return -EINVAL);
4286
4287 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
4288 "Failed to upload dpm max level to highest!",
4289 return -EINVAL);
4290 break;
4291
4292 case PP_MCLK:
4293 data->smc_state_table.mem_boot_level = mask ? (ffs(mask) - 1) : 0;
4294 data->smc_state_table.mem_max_level = mask ? (fls(mask) - 1) : 0;
4295
4296 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
4297 "Failed to upload boot level to lowest!",
4298 return -EINVAL);
4299
4300 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
4301 "Failed to upload dpm max level to highest!",
4302 return -EINVAL);
4303
4304 break;
4305
4306 case PP_SOCCLK:
4307 data->smc_state_table.soc_boot_level = mask ? (ffs(mask) - 1) : 0;
4308 data->smc_state_table.soc_max_level = mask ? (fls(mask) - 1) : 0;
4309
4310 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_bootup_level(hwmgr),
4311 "Failed to upload boot level to lowest!",
4312 return -EINVAL);
4313
4314 PP_ASSERT_WITH_CODE(!vega10_upload_dpm_max_level(hwmgr),
4315 "Failed to upload dpm max level to highest!",
4316 return -EINVAL);
4317
4318 break;
4319
4320 case PP_DCEFCLK:
4321 pr_info("Setting DCEFCLK min/max dpm level is not supported!\n");
4322 break;
4323
4324 case PP_PCIE:
4325 default:
4326 break;
4327 }
4328
4329 return 0;
4330 }
4331
vega10_dpm_force_dpm_level(struct pp_hwmgr * hwmgr,enum amd_dpm_forced_level level)4332 static int vega10_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
4333 enum amd_dpm_forced_level level)
4334 {
4335 int ret = 0;
4336 uint32_t sclk_mask = 0;
4337 uint32_t mclk_mask = 0;
4338 uint32_t soc_mask = 0;
4339
4340 switch (level) {
4341 case AMD_DPM_FORCED_LEVEL_HIGH:
4342 ret = vega10_force_dpm_highest(hwmgr);
4343 break;
4344 case AMD_DPM_FORCED_LEVEL_LOW:
4345 ret = vega10_force_dpm_lowest(hwmgr);
4346 break;
4347 case AMD_DPM_FORCED_LEVEL_AUTO:
4348 ret = vega10_unforce_dpm_levels(hwmgr);
4349 break;
4350 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
4351 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
4352 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
4353 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
4354 ret = vega10_get_profiling_clk_mask(hwmgr, level, &sclk_mask, &mclk_mask, &soc_mask);
4355 if (ret)
4356 return ret;
4357 vega10_force_clock_level(hwmgr, PP_SCLK, 1<<sclk_mask);
4358 vega10_force_clock_level(hwmgr, PP_MCLK, 1<<mclk_mask);
4359 break;
4360 case AMD_DPM_FORCED_LEVEL_MANUAL:
4361 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
4362 default:
4363 break;
4364 }
4365
4366 if (!hwmgr->not_vf)
4367 return ret;
4368
4369 if (!ret) {
4370 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
4371 vega10_set_fan_control_mode(hwmgr, AMD_FAN_CTRL_NONE);
4372 else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
4373 vega10_set_fan_control_mode(hwmgr, AMD_FAN_CTRL_AUTO);
4374 }
4375
4376 return ret;
4377 }
4378
vega10_get_fan_control_mode(struct pp_hwmgr * hwmgr)4379 static uint32_t vega10_get_fan_control_mode(struct pp_hwmgr *hwmgr)
4380 {
4381 struct vega10_hwmgr *data = hwmgr->backend;
4382
4383 if (data->smu_features[GNLD_FAN_CONTROL].enabled == false)
4384 return AMD_FAN_CTRL_MANUAL;
4385 else
4386 return AMD_FAN_CTRL_AUTO;
4387 }
4388
vega10_get_dal_power_level(struct pp_hwmgr * hwmgr,struct amd_pp_simple_clock_info * info)4389 static int vega10_get_dal_power_level(struct pp_hwmgr *hwmgr,
4390 struct amd_pp_simple_clock_info *info)
4391 {
4392 struct phm_ppt_v2_information *table_info =
4393 (struct phm_ppt_v2_information *)hwmgr->pptable;
4394 struct phm_clock_and_voltage_limits *max_limits =
4395 &table_info->max_clock_voltage_on_ac;
4396
4397 info->engine_max_clock = max_limits->sclk;
4398 info->memory_max_clock = max_limits->mclk;
4399
4400 return 0;
4401 }
4402
vega10_get_sclks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)4403 static void vega10_get_sclks(struct pp_hwmgr *hwmgr,
4404 struct pp_clock_levels_with_latency *clocks)
4405 {
4406 struct phm_ppt_v2_information *table_info =
4407 (struct phm_ppt_v2_information *)hwmgr->pptable;
4408 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4409 table_info->vdd_dep_on_sclk;
4410 uint32_t i;
4411
4412 clocks->num_levels = 0;
4413 for (i = 0; i < dep_table->count; i++) {
4414 if (dep_table->entries[i].clk) {
4415 clocks->data[clocks->num_levels].clocks_in_khz =
4416 dep_table->entries[i].clk * 10;
4417 clocks->num_levels++;
4418 }
4419 }
4420
4421 }
4422
vega10_get_memclocks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)4423 static void vega10_get_memclocks(struct pp_hwmgr *hwmgr,
4424 struct pp_clock_levels_with_latency *clocks)
4425 {
4426 struct phm_ppt_v2_information *table_info =
4427 (struct phm_ppt_v2_information *)hwmgr->pptable;
4428 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4429 table_info->vdd_dep_on_mclk;
4430 struct vega10_hwmgr *data = hwmgr->backend;
4431 uint32_t j = 0;
4432 uint32_t i;
4433
4434 for (i = 0; i < dep_table->count; i++) {
4435 if (dep_table->entries[i].clk) {
4436
4437 clocks->data[j].clocks_in_khz =
4438 dep_table->entries[i].clk * 10;
4439 data->mclk_latency_table.entries[j].frequency =
4440 dep_table->entries[i].clk;
4441 clocks->data[j].latency_in_us =
4442 data->mclk_latency_table.entries[j].latency = 25;
4443 j++;
4444 }
4445 }
4446 clocks->num_levels = data->mclk_latency_table.count = j;
4447 }
4448
vega10_get_dcefclocks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)4449 static void vega10_get_dcefclocks(struct pp_hwmgr *hwmgr,
4450 struct pp_clock_levels_with_latency *clocks)
4451 {
4452 struct phm_ppt_v2_information *table_info =
4453 (struct phm_ppt_v2_information *)hwmgr->pptable;
4454 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4455 table_info->vdd_dep_on_dcefclk;
4456 uint32_t i;
4457
4458 for (i = 0; i < dep_table->count; i++) {
4459 clocks->data[i].clocks_in_khz = dep_table->entries[i].clk * 10;
4460 clocks->data[i].latency_in_us = 0;
4461 clocks->num_levels++;
4462 }
4463 }
4464
vega10_get_socclocks(struct pp_hwmgr * hwmgr,struct pp_clock_levels_with_latency * clocks)4465 static void vega10_get_socclocks(struct pp_hwmgr *hwmgr,
4466 struct pp_clock_levels_with_latency *clocks)
4467 {
4468 struct phm_ppt_v2_information *table_info =
4469 (struct phm_ppt_v2_information *)hwmgr->pptable;
4470 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table =
4471 table_info->vdd_dep_on_socclk;
4472 uint32_t i;
4473
4474 for (i = 0; i < dep_table->count; i++) {
4475 clocks->data[i].clocks_in_khz = dep_table->entries[i].clk * 10;
4476 clocks->data[i].latency_in_us = 0;
4477 clocks->num_levels++;
4478 }
4479 }
4480
vega10_get_clock_by_type_with_latency(struct pp_hwmgr * hwmgr,enum amd_pp_clock_type type,struct pp_clock_levels_with_latency * clocks)4481 static int vega10_get_clock_by_type_with_latency(struct pp_hwmgr *hwmgr,
4482 enum amd_pp_clock_type type,
4483 struct pp_clock_levels_with_latency *clocks)
4484 {
4485 switch (type) {
4486 case amd_pp_sys_clock:
4487 vega10_get_sclks(hwmgr, clocks);
4488 break;
4489 case amd_pp_mem_clock:
4490 vega10_get_memclocks(hwmgr, clocks);
4491 break;
4492 case amd_pp_dcef_clock:
4493 vega10_get_dcefclocks(hwmgr, clocks);
4494 break;
4495 case amd_pp_soc_clock:
4496 vega10_get_socclocks(hwmgr, clocks);
4497 break;
4498 default:
4499 return -1;
4500 }
4501
4502 return 0;
4503 }
4504
vega10_get_clock_by_type_with_voltage(struct pp_hwmgr * hwmgr,enum amd_pp_clock_type type,struct pp_clock_levels_with_voltage * clocks)4505 static int vega10_get_clock_by_type_with_voltage(struct pp_hwmgr *hwmgr,
4506 enum amd_pp_clock_type type,
4507 struct pp_clock_levels_with_voltage *clocks)
4508 {
4509 struct phm_ppt_v2_information *table_info =
4510 (struct phm_ppt_v2_information *)hwmgr->pptable;
4511 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table;
4512 uint32_t i;
4513
4514 switch (type) {
4515 case amd_pp_mem_clock:
4516 dep_table = table_info->vdd_dep_on_mclk;
4517 break;
4518 case amd_pp_dcef_clock:
4519 dep_table = table_info->vdd_dep_on_dcefclk;
4520 break;
4521 case amd_pp_disp_clock:
4522 dep_table = table_info->vdd_dep_on_dispclk;
4523 break;
4524 case amd_pp_pixel_clock:
4525 dep_table = table_info->vdd_dep_on_pixclk;
4526 break;
4527 case amd_pp_phy_clock:
4528 dep_table = table_info->vdd_dep_on_phyclk;
4529 break;
4530 default:
4531 return -1;
4532 }
4533
4534 for (i = 0; i < dep_table->count; i++) {
4535 clocks->data[i].clocks_in_khz = dep_table->entries[i].clk * 10;
4536 clocks->data[i].voltage_in_mv = (uint32_t)(table_info->vddc_lookup_table->
4537 entries[dep_table->entries[i].vddInd].us_vdd);
4538 clocks->num_levels++;
4539 }
4540
4541 if (i < dep_table->count)
4542 return -1;
4543
4544 return 0;
4545 }
4546
vega10_set_watermarks_for_clocks_ranges(struct pp_hwmgr * hwmgr,void * clock_range)4547 static int vega10_set_watermarks_for_clocks_ranges(struct pp_hwmgr *hwmgr,
4548 void *clock_range)
4549 {
4550 struct vega10_hwmgr *data = hwmgr->backend;
4551 struct dm_pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges = clock_range;
4552 Watermarks_t *table = &(data->smc_state_table.water_marks_table);
4553
4554 if (!data->registry_data.disable_water_mark) {
4555 smu_set_watermarks_for_clocks_ranges(table, wm_with_clock_ranges);
4556 data->water_marks_bitmap = WaterMarksExist;
4557 }
4558
4559 return 0;
4560 }
4561
vega10_get_ppfeature_status(struct pp_hwmgr * hwmgr,char * buf)4562 static int vega10_get_ppfeature_status(struct pp_hwmgr *hwmgr, char *buf)
4563 {
4564 static const char *ppfeature_name[] = {
4565 "DPM_PREFETCHER",
4566 "GFXCLK_DPM",
4567 "UCLK_DPM",
4568 "SOCCLK_DPM",
4569 "UVD_DPM",
4570 "VCE_DPM",
4571 "ULV",
4572 "MP0CLK_DPM",
4573 "LINK_DPM",
4574 "DCEFCLK_DPM",
4575 "AVFS",
4576 "GFXCLK_DS",
4577 "SOCCLK_DS",
4578 "LCLK_DS",
4579 "PPT",
4580 "TDC",
4581 "THERMAL",
4582 "GFX_PER_CU_CG",
4583 "RM",
4584 "DCEFCLK_DS",
4585 "ACDC",
4586 "VR0HOT",
4587 "VR1HOT",
4588 "FW_CTF",
4589 "LED_DISPLAY",
4590 "FAN_CONTROL",
4591 "FAST_PPT",
4592 "DIDT",
4593 "ACG",
4594 "PCC_LIMIT"};
4595 static const char *output_title[] = {
4596 "FEATURES",
4597 "BITMASK",
4598 "ENABLEMENT"};
4599 uint64_t features_enabled;
4600 int i;
4601 int ret = 0;
4602 int size = 0;
4603
4604 phm_get_sysfs_buf(&buf, &size);
4605
4606 ret = vega10_get_enabled_smc_features(hwmgr, &features_enabled);
4607 PP_ASSERT_WITH_CODE(!ret,
4608 "[EnableAllSmuFeatures] Failed to get enabled smc features!",
4609 return ret);
4610
4611 size += sysfs_emit_at(buf, size, "Current ppfeatures: 0x%016llx\n", features_enabled);
4612 size += sysfs_emit_at(buf, size, "%-19s %-22s %s\n",
4613 output_title[0],
4614 output_title[1],
4615 output_title[2]);
4616 for (i = 0; i < GNLD_FEATURES_MAX; i++) {
4617 size += sysfs_emit_at(buf, size, "%-19s 0x%016llx %6s\n",
4618 ppfeature_name[i],
4619 1ULL << i,
4620 (features_enabled & (1ULL << i)) ? "Y" : "N");
4621 }
4622
4623 return size;
4624 }
4625
vega10_set_ppfeature_status(struct pp_hwmgr * hwmgr,uint64_t new_ppfeature_masks)4626 static int vega10_set_ppfeature_status(struct pp_hwmgr *hwmgr, uint64_t new_ppfeature_masks)
4627 {
4628 uint64_t features_enabled;
4629 uint64_t features_to_enable;
4630 uint64_t features_to_disable;
4631 int ret = 0;
4632
4633 if (new_ppfeature_masks >= (1ULL << GNLD_FEATURES_MAX))
4634 return -EINVAL;
4635
4636 ret = vega10_get_enabled_smc_features(hwmgr, &features_enabled);
4637 if (ret)
4638 return ret;
4639
4640 features_to_disable =
4641 features_enabled & ~new_ppfeature_masks;
4642 features_to_enable =
4643 ~features_enabled & new_ppfeature_masks;
4644
4645 pr_debug("features_to_disable 0x%llx\n", features_to_disable);
4646 pr_debug("features_to_enable 0x%llx\n", features_to_enable);
4647
4648 if (features_to_disable) {
4649 ret = vega10_enable_smc_features(hwmgr, false, features_to_disable);
4650 if (ret)
4651 return ret;
4652 }
4653
4654 if (features_to_enable) {
4655 ret = vega10_enable_smc_features(hwmgr, true, features_to_enable);
4656 if (ret)
4657 return ret;
4658 }
4659
4660 return 0;
4661 }
4662
vega10_get_current_pcie_link_width_level(struct pp_hwmgr * hwmgr)4663 static int vega10_get_current_pcie_link_width_level(struct pp_hwmgr *hwmgr)
4664 {
4665 struct amdgpu_device *adev = hwmgr->adev;
4666
4667 return (RREG32_PCIE(smnPCIE_LC_LINK_WIDTH_CNTL) &
4668 PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD_MASK)
4669 >> PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_RD__SHIFT;
4670 }
4671
vega10_get_current_pcie_link_speed_level(struct pp_hwmgr * hwmgr)4672 static int vega10_get_current_pcie_link_speed_level(struct pp_hwmgr *hwmgr)
4673 {
4674 struct amdgpu_device *adev = hwmgr->adev;
4675
4676 return (RREG32_PCIE(smnPCIE_LC_SPEED_CNTL) &
4677 PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK)
4678 >> PSWUSP0_PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
4679 }
4680
vega10_emit_clock_levels(struct pp_hwmgr * hwmgr,enum pp_clock_type type,char * buf,int * offset)4681 static int vega10_emit_clock_levels(struct pp_hwmgr *hwmgr,
4682 enum pp_clock_type type, char *buf, int *offset)
4683 {
4684 struct vega10_hwmgr *data = hwmgr->backend;
4685 struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table);
4686 struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table);
4687 struct vega10_single_dpm_table *soc_table = &(data->dpm_table.soc_table);
4688 struct vega10_single_dpm_table *dcef_table = &(data->dpm_table.dcef_table);
4689 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep = NULL;
4690 uint32_t gen_speed, lane_width, current_gen_speed, current_lane_width;
4691 PPTable_t *pptable = &(data->smc_state_table.pp_table);
4692
4693 uint32_t i, now, count = 0;
4694 int ret = 0;
4695
4696 switch (type) {
4697 case PP_SCLK:
4698 if (data->registry_data.sclk_dpm_key_disabled)
4699 return -EOPNOTSUPP;
4700
4701 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentGfxclkIndex, &now);
4702 if (unlikely(ret != 0))
4703 return ret;
4704
4705 if (hwmgr->pp_one_vf &&
4706 (hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK))
4707 count = 5;
4708 else
4709 count = sclk_table->count;
4710 for (i = 0; i < count; i++)
4711 *offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
4712 i, sclk_table->dpm_levels[i].value / 100,
4713 (i == now) ? "*" : "");
4714 break;
4715 case PP_MCLK:
4716 if (data->registry_data.mclk_dpm_key_disabled)
4717 return -EOPNOTSUPP;
4718
4719 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentUclkIndex, &now);
4720 if (unlikely(ret != 0))
4721 return ret;
4722
4723 for (i = 0; i < mclk_table->count; i++)
4724 *offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
4725 i, mclk_table->dpm_levels[i].value / 100,
4726 (i == now) ? "*" : "");
4727 break;
4728 case PP_SOCCLK:
4729 if (data->registry_data.socclk_dpm_key_disabled)
4730 return -EOPNOTSUPP;
4731
4732 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetCurrentSocclkIndex, &now);
4733 if (unlikely(ret != 0))
4734 return ret;
4735
4736 for (i = 0; i < soc_table->count; i++)
4737 *offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
4738 i, soc_table->dpm_levels[i].value / 100,
4739 (i == now) ? "*" : "");
4740 break;
4741 case PP_DCEFCLK:
4742 if (data->registry_data.dcefclk_dpm_key_disabled)
4743 return -EOPNOTSUPP;
4744
4745 ret = smum_send_msg_to_smc_with_parameter(hwmgr,
4746 PPSMC_MSG_GetClockFreqMHz,
4747 CLK_DCEFCLK, &now);
4748 if (unlikely(ret != 0))
4749 return ret;
4750
4751 for (i = 0; i < dcef_table->count; i++)
4752 *offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
4753 i, dcef_table->dpm_levels[i].value / 100,
4754 (dcef_table->dpm_levels[i].value / 100 == now) ?
4755 "*" : "");
4756 break;
4757 case PP_PCIE:
4758 current_gen_speed =
4759 vega10_get_current_pcie_link_speed_level(hwmgr);
4760 current_lane_width =
4761 vega10_get_current_pcie_link_width_level(hwmgr);
4762 for (i = 0; i < NUM_LINK_LEVELS; i++) {
4763 gen_speed = pptable->PcieGenSpeed[i];
4764 lane_width = pptable->PcieLaneCount[i];
4765
4766 *offset += sysfs_emit_at(buf, *offset, "%d: %s %s %s\n", i,
4767 (gen_speed == 0) ? "2.5GT/s," :
4768 (gen_speed == 1) ? "5.0GT/s," :
4769 (gen_speed == 2) ? "8.0GT/s," :
4770 (gen_speed == 3) ? "16.0GT/s," : "",
4771 (lane_width == 1) ? "x1" :
4772 (lane_width == 2) ? "x2" :
4773 (lane_width == 3) ? "x4" :
4774 (lane_width == 4) ? "x8" :
4775 (lane_width == 5) ? "x12" :
4776 (lane_width == 6) ? "x16" : "",
4777 (current_gen_speed == gen_speed) &&
4778 (current_lane_width == lane_width) ?
4779 "*" : "");
4780 }
4781 break;
4782
4783 case OD_SCLK:
4784 if (!hwmgr->od_enabled)
4785 return -EOPNOTSUPP;
4786
4787 *offset += sysfs_emit_at(buf, *offset, "%s:\n", "OD_SCLK");
4788 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_sclk;
4789 for (i = 0; i < podn_vdd_dep->count; i++)
4790 *offset += sysfs_emit_at(buf, *offset, "%d: %10uMhz %10umV\n",
4791 i, podn_vdd_dep->entries[i].clk / 100,
4792 podn_vdd_dep->entries[i].vddc);
4793 break;
4794 case OD_MCLK:
4795 if (!hwmgr->od_enabled)
4796 return -EOPNOTSUPP;
4797
4798 *offset += sysfs_emit_at(buf, *offset, "%s:\n", "OD_MCLK");
4799 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_mclk;
4800 for (i = 0; i < podn_vdd_dep->count; i++)
4801 *offset += sysfs_emit_at(buf, *offset, "%d: %10uMhz %10umV\n",
4802 i, podn_vdd_dep->entries[i].clk/100,
4803 podn_vdd_dep->entries[i].vddc);
4804 break;
4805 case OD_RANGE:
4806 if (!hwmgr->od_enabled)
4807 return -EOPNOTSUPP;
4808
4809 *offset += sysfs_emit_at(buf, *offset, "%s:\n", "OD_RANGE");
4810 *offset += sysfs_emit_at(buf, *offset, "SCLK: %7uMHz %10uMHz\n",
4811 data->golden_dpm_table.gfx_table.dpm_levels[0].value/100,
4812 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
4813 *offset += sysfs_emit_at(buf, *offset, "MCLK: %7uMHz %10uMHz\n",
4814 data->golden_dpm_table.mem_table.dpm_levels[0].value/100,
4815 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
4816 *offset += sysfs_emit_at(buf, *offset, "VDDC: %7umV %11umV\n",
4817 data->odn_dpm_table.min_vddc,
4818 data->odn_dpm_table.max_vddc);
4819 break;
4820 default:
4821 ret = -ENOENT;
4822 break;
4823 }
4824 return ret;
4825 }
4826
vega10_display_configuration_changed_task(struct pp_hwmgr * hwmgr)4827 static int vega10_display_configuration_changed_task(struct pp_hwmgr *hwmgr)
4828 {
4829 struct vega10_hwmgr *data = hwmgr->backend;
4830 Watermarks_t *wm_table = &(data->smc_state_table.water_marks_table);
4831 int result = 0;
4832
4833 if ((data->water_marks_bitmap & WaterMarksExist) &&
4834 !(data->water_marks_bitmap & WaterMarksLoaded)) {
4835 result = smum_smc_table_manager(hwmgr, (uint8_t *)wm_table, WMTABLE, false);
4836 PP_ASSERT_WITH_CODE(result, "Failed to update WMTABLE!", return -EINVAL);
4837 data->water_marks_bitmap |= WaterMarksLoaded;
4838 }
4839
4840 if (data->water_marks_bitmap & WaterMarksLoaded) {
4841 smum_send_msg_to_smc_with_parameter(hwmgr,
4842 PPSMC_MSG_NumOfDisplays, hwmgr->display_config->num_display,
4843 NULL);
4844 }
4845
4846 return result;
4847 }
4848
vega10_enable_disable_uvd_dpm(struct pp_hwmgr * hwmgr,bool enable)4849 static int vega10_enable_disable_uvd_dpm(struct pp_hwmgr *hwmgr, bool enable)
4850 {
4851 struct vega10_hwmgr *data = hwmgr->backend;
4852
4853 if (data->smu_features[GNLD_DPM_UVD].supported) {
4854 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
4855 enable,
4856 data->smu_features[GNLD_DPM_UVD].smu_feature_bitmap),
4857 "Attempt to Enable/Disable DPM UVD Failed!",
4858 return -1);
4859 data->smu_features[GNLD_DPM_UVD].enabled = enable;
4860 }
4861 return 0;
4862 }
4863
vega10_power_gate_vce(struct pp_hwmgr * hwmgr,bool bgate)4864 static void vega10_power_gate_vce(struct pp_hwmgr *hwmgr, bool bgate)
4865 {
4866 struct vega10_hwmgr *data = hwmgr->backend;
4867
4868 data->vce_power_gated = bgate;
4869 vega10_enable_disable_vce_dpm(hwmgr, !bgate);
4870 }
4871
vega10_power_gate_uvd(struct pp_hwmgr * hwmgr,bool bgate)4872 static void vega10_power_gate_uvd(struct pp_hwmgr *hwmgr, bool bgate)
4873 {
4874 struct vega10_hwmgr *data = hwmgr->backend;
4875
4876 data->uvd_power_gated = bgate;
4877 vega10_enable_disable_uvd_dpm(hwmgr, !bgate);
4878 }
4879
vega10_are_power_levels_equal(const struct vega10_performance_level * pl1,const struct vega10_performance_level * pl2)4880 static inline bool vega10_are_power_levels_equal(
4881 const struct vega10_performance_level *pl1,
4882 const struct vega10_performance_level *pl2)
4883 {
4884 return ((pl1->soc_clock == pl2->soc_clock) &&
4885 (pl1->gfx_clock == pl2->gfx_clock) &&
4886 (pl1->mem_clock == pl2->mem_clock));
4887 }
4888
vega10_check_states_equal(struct pp_hwmgr * hwmgr,const struct pp_hw_power_state * pstate1,const struct pp_hw_power_state * pstate2,bool * equal)4889 static int vega10_check_states_equal(struct pp_hwmgr *hwmgr,
4890 const struct pp_hw_power_state *pstate1,
4891 const struct pp_hw_power_state *pstate2, bool *equal)
4892 {
4893 const struct vega10_power_state *vega10_psa;
4894 const struct vega10_power_state *vega10_psb;
4895 int i;
4896
4897 if (pstate1 == NULL || pstate2 == NULL || equal == NULL)
4898 return -EINVAL;
4899
4900 vega10_psa = cast_const_phw_vega10_power_state(pstate1);
4901 vega10_psb = cast_const_phw_vega10_power_state(pstate2);
4902 if (vega10_psa == NULL || vega10_psb == NULL)
4903 return -EINVAL;
4904
4905 /* If the two states don't even have the same number of performance levels
4906 * they cannot be the same state.
4907 */
4908 if (vega10_psa->performance_level_count != vega10_psb->performance_level_count) {
4909 *equal = false;
4910 return 0;
4911 }
4912
4913 for (i = 0; i < vega10_psa->performance_level_count; i++) {
4914 if (!vega10_are_power_levels_equal(&(vega10_psa->performance_levels[i]),
4915 &(vega10_psb->performance_levels[i]))) {
4916 /* If we have found even one performance level pair
4917 * that is different the states are different.
4918 */
4919 *equal = false;
4920 return 0;
4921 }
4922 }
4923
4924 /* If all performance levels are the same try to use the UVD clocks to break the tie.*/
4925 *equal = ((vega10_psa->uvd_clks.vclk == vega10_psb->uvd_clks.vclk) &&
4926 (vega10_psa->uvd_clks.dclk == vega10_psb->uvd_clks.dclk));
4927 *equal &= ((vega10_psa->vce_clks.evclk == vega10_psb->vce_clks.evclk) &&
4928 (vega10_psa->vce_clks.ecclk == vega10_psb->vce_clks.ecclk));
4929 *equal &= (vega10_psa->sclk_threshold == vega10_psb->sclk_threshold);
4930
4931 return 0;
4932 }
4933
4934 static bool
vega10_check_smc_update_required_for_display_configuration(struct pp_hwmgr * hwmgr)4935 vega10_check_smc_update_required_for_display_configuration(struct pp_hwmgr *hwmgr)
4936 {
4937 struct vega10_hwmgr *data = hwmgr->backend;
4938 bool is_update_required = false;
4939
4940 if (data->display_timing.num_existing_displays != hwmgr->display_config->num_display)
4941 is_update_required = true;
4942
4943 if (PP_CAP(PHM_PlatformCaps_SclkDeepSleep)) {
4944 if (data->display_timing.min_clock_in_sr != hwmgr->display_config->min_core_set_clock_in_sr)
4945 is_update_required = true;
4946 }
4947
4948 return is_update_required;
4949 }
4950
vega10_disable_dpm_tasks(struct pp_hwmgr * hwmgr)4951 static int vega10_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
4952 {
4953 int tmp_result, result = 0;
4954
4955 if (!hwmgr->not_vf)
4956 return 0;
4957
4958 if (PP_CAP(PHM_PlatformCaps_ThermalController))
4959 vega10_disable_thermal_protection(hwmgr);
4960
4961 tmp_result = vega10_disable_power_containment(hwmgr);
4962 PP_ASSERT_WITH_CODE((tmp_result == 0),
4963 "Failed to disable power containment!", result = tmp_result);
4964
4965 tmp_result = vega10_disable_didt_config(hwmgr);
4966 PP_ASSERT_WITH_CODE((tmp_result == 0),
4967 "Failed to disable didt config!", result = tmp_result);
4968
4969 tmp_result = vega10_avfs_enable(hwmgr, false);
4970 PP_ASSERT_WITH_CODE((tmp_result == 0),
4971 "Failed to disable AVFS!", result = tmp_result);
4972
4973 tmp_result = vega10_stop_dpm(hwmgr, SMC_DPM_FEATURES);
4974 PP_ASSERT_WITH_CODE((tmp_result == 0),
4975 "Failed to stop DPM!", result = tmp_result);
4976
4977 tmp_result = vega10_disable_deep_sleep_master_switch(hwmgr);
4978 PP_ASSERT_WITH_CODE((tmp_result == 0),
4979 "Failed to disable deep sleep!", result = tmp_result);
4980
4981 tmp_result = vega10_disable_ulv(hwmgr);
4982 PP_ASSERT_WITH_CODE((tmp_result == 0),
4983 "Failed to disable ulv!", result = tmp_result);
4984
4985 tmp_result = vega10_acg_disable(hwmgr);
4986 PP_ASSERT_WITH_CODE((tmp_result == 0),
4987 "Failed to disable acg!", result = tmp_result);
4988
4989 vega10_enable_disable_PCC_limit_feature(hwmgr, false);
4990 return result;
4991 }
4992
vega10_power_off_asic(struct pp_hwmgr * hwmgr)4993 static int vega10_power_off_asic(struct pp_hwmgr *hwmgr)
4994 {
4995 struct vega10_hwmgr *data = hwmgr->backend;
4996 int result;
4997
4998 result = vega10_disable_dpm_tasks(hwmgr);
4999 PP_ASSERT_WITH_CODE((0 == result),
5000 "[disable_dpm_tasks] Failed to disable DPM!",
5001 );
5002 data->water_marks_bitmap &= ~(WaterMarksLoaded);
5003
5004 return result;
5005 }
5006
vega10_get_sclk_od(struct pp_hwmgr * hwmgr)5007 static int vega10_get_sclk_od(struct pp_hwmgr *hwmgr)
5008 {
5009 struct vega10_hwmgr *data = hwmgr->backend;
5010 struct vega10_single_dpm_table *sclk_table = &(data->dpm_table.gfx_table);
5011 struct vega10_single_dpm_table *golden_sclk_table =
5012 &(data->golden_dpm_table.gfx_table);
5013 int value = sclk_table->dpm_levels[sclk_table->count - 1].value;
5014 int golden_value = golden_sclk_table->dpm_levels
5015 [golden_sclk_table->count - 1].value;
5016
5017 value -= golden_value;
5018 value = DIV_ROUND_UP(value * 100, golden_value);
5019
5020 return value;
5021 }
5022
vega10_set_sclk_od(struct pp_hwmgr * hwmgr,uint32_t value)5023 static int vega10_set_sclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5024 {
5025 struct vega10_hwmgr *data = hwmgr->backend;
5026 struct vega10_single_dpm_table *golden_sclk_table =
5027 &(data->golden_dpm_table.gfx_table);
5028 struct pp_power_state *ps;
5029 struct vega10_power_state *vega10_ps;
5030
5031 ps = hwmgr->request_ps;
5032
5033 if (ps == NULL)
5034 return -EINVAL;
5035
5036 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
5037 if (vega10_ps == NULL)
5038 return -EINVAL;
5039
5040 vega10_ps->performance_levels
5041 [vega10_ps->performance_level_count - 1].gfx_clock =
5042 golden_sclk_table->dpm_levels
5043 [golden_sclk_table->count - 1].value *
5044 value / 100 +
5045 golden_sclk_table->dpm_levels
5046 [golden_sclk_table->count - 1].value;
5047
5048 if (vega10_ps->performance_levels
5049 [vega10_ps->performance_level_count - 1].gfx_clock >
5050 hwmgr->platform_descriptor.overdriveLimit.engineClock) {
5051 vega10_ps->performance_levels
5052 [vega10_ps->performance_level_count - 1].gfx_clock =
5053 hwmgr->platform_descriptor.overdriveLimit.engineClock;
5054 pr_warn("max sclk supported by vbios is %d\n",
5055 hwmgr->platform_descriptor.overdriveLimit.engineClock);
5056 }
5057 return 0;
5058 }
5059
vega10_get_mclk_od(struct pp_hwmgr * hwmgr)5060 static int vega10_get_mclk_od(struct pp_hwmgr *hwmgr)
5061 {
5062 struct vega10_hwmgr *data = hwmgr->backend;
5063 struct vega10_single_dpm_table *mclk_table = &(data->dpm_table.mem_table);
5064 struct vega10_single_dpm_table *golden_mclk_table =
5065 &(data->golden_dpm_table.mem_table);
5066 int value = mclk_table->dpm_levels[mclk_table->count - 1].value;
5067 int golden_value = golden_mclk_table->dpm_levels
5068 [golden_mclk_table->count - 1].value;
5069
5070 value -= golden_value;
5071 value = DIV_ROUND_UP(value * 100, golden_value);
5072
5073 return value;
5074 }
5075
vega10_set_mclk_od(struct pp_hwmgr * hwmgr,uint32_t value)5076 static int vega10_set_mclk_od(struct pp_hwmgr *hwmgr, uint32_t value)
5077 {
5078 struct vega10_hwmgr *data = hwmgr->backend;
5079 struct vega10_single_dpm_table *golden_mclk_table =
5080 &(data->golden_dpm_table.mem_table);
5081 struct pp_power_state *ps;
5082 struct vega10_power_state *vega10_ps;
5083
5084 ps = hwmgr->request_ps;
5085
5086 if (ps == NULL)
5087 return -EINVAL;
5088
5089 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
5090 if (vega10_ps == NULL)
5091 return -EINVAL;
5092
5093 vega10_ps->performance_levels
5094 [vega10_ps->performance_level_count - 1].mem_clock =
5095 golden_mclk_table->dpm_levels
5096 [golden_mclk_table->count - 1].value *
5097 value / 100 +
5098 golden_mclk_table->dpm_levels
5099 [golden_mclk_table->count - 1].value;
5100
5101 if (vega10_ps->performance_levels
5102 [vega10_ps->performance_level_count - 1].mem_clock >
5103 hwmgr->platform_descriptor.overdriveLimit.memoryClock) {
5104 vega10_ps->performance_levels
5105 [vega10_ps->performance_level_count - 1].mem_clock =
5106 hwmgr->platform_descriptor.overdriveLimit.memoryClock;
5107 pr_warn("max mclk supported by vbios is %d\n",
5108 hwmgr->platform_descriptor.overdriveLimit.memoryClock);
5109 }
5110
5111 return 0;
5112 }
5113
vega10_notify_cac_buffer_info(struct pp_hwmgr * hwmgr,uint32_t virtual_addr_low,uint32_t virtual_addr_hi,uint32_t mc_addr_low,uint32_t mc_addr_hi,uint32_t size)5114 static int vega10_notify_cac_buffer_info(struct pp_hwmgr *hwmgr,
5115 uint32_t virtual_addr_low,
5116 uint32_t virtual_addr_hi,
5117 uint32_t mc_addr_low,
5118 uint32_t mc_addr_hi,
5119 uint32_t size)
5120 {
5121 smum_send_msg_to_smc_with_parameter(hwmgr,
5122 PPSMC_MSG_SetSystemVirtualDramAddrHigh,
5123 virtual_addr_hi,
5124 NULL);
5125 smum_send_msg_to_smc_with_parameter(hwmgr,
5126 PPSMC_MSG_SetSystemVirtualDramAddrLow,
5127 virtual_addr_low,
5128 NULL);
5129 smum_send_msg_to_smc_with_parameter(hwmgr,
5130 PPSMC_MSG_DramLogSetDramAddrHigh,
5131 mc_addr_hi,
5132 NULL);
5133
5134 smum_send_msg_to_smc_with_parameter(hwmgr,
5135 PPSMC_MSG_DramLogSetDramAddrLow,
5136 mc_addr_low,
5137 NULL);
5138
5139 smum_send_msg_to_smc_with_parameter(hwmgr,
5140 PPSMC_MSG_DramLogSetDramSize,
5141 size,
5142 NULL);
5143 return 0;
5144 }
5145
vega10_get_thermal_temperature_range(struct pp_hwmgr * hwmgr,struct PP_TemperatureRange * thermal_data)5146 static int vega10_get_thermal_temperature_range(struct pp_hwmgr *hwmgr,
5147 struct PP_TemperatureRange *thermal_data)
5148 {
5149 struct vega10_hwmgr *data = hwmgr->backend;
5150 PPTable_t *pp_table = &(data->smc_state_table.pp_table);
5151 struct phm_ppt_v2_information *pp_table_info =
5152 (struct phm_ppt_v2_information *)(hwmgr->pptable);
5153 struct phm_tdp_table *tdp_table = pp_table_info->tdp_table;
5154
5155 memcpy(thermal_data, &SMU7ThermalWithDelayPolicy[0], sizeof(struct PP_TemperatureRange));
5156
5157 thermal_data->max = pp_table->TedgeLimit *
5158 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5159 thermal_data->edge_emergency_max = (pp_table->TedgeLimit + CTF_OFFSET_EDGE) *
5160 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5161 thermal_data->hotspot_crit_max = pp_table->ThotspotLimit *
5162 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5163 thermal_data->hotspot_emergency_max = (pp_table->ThotspotLimit + CTF_OFFSET_HOTSPOT) *
5164 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5165 thermal_data->mem_crit_max = pp_table->ThbmLimit *
5166 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5167 thermal_data->mem_emergency_max = (pp_table->ThbmLimit + CTF_OFFSET_HBM)*
5168 PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5169
5170 if (tdp_table->usSoftwareShutdownTemp > pp_table->ThotspotLimit &&
5171 tdp_table->usSoftwareShutdownTemp < VEGA10_THERMAL_MAXIMUM_ALERT_TEMP)
5172 thermal_data->sw_ctf_threshold = tdp_table->usSoftwareShutdownTemp;
5173 else
5174 thermal_data->sw_ctf_threshold = VEGA10_THERMAL_MAXIMUM_ALERT_TEMP;
5175 thermal_data->sw_ctf_threshold *= PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
5176
5177 return 0;
5178 }
5179
vega10_get_power_profile_mode(struct pp_hwmgr * hwmgr,char * buf)5180 static int vega10_get_power_profile_mode(struct pp_hwmgr *hwmgr, char *buf)
5181 {
5182 struct vega10_hwmgr *data = hwmgr->backend;
5183 uint32_t i, size = 0;
5184 static const uint8_t profile_mode_setting[6][4] = {{70, 60, 0, 0,},
5185 {70, 60, 1, 3,},
5186 {90, 60, 0, 0,},
5187 {70, 60, 0, 0,},
5188 {70, 90, 0, 0,},
5189 {30, 60, 0, 6,},
5190 };
5191 static const char *title[6] = {"NUM",
5192 "MODE_NAME",
5193 "BUSY_SET_POINT",
5194 "FPS",
5195 "USE_RLC_BUSY",
5196 "MIN_ACTIVE_LEVEL"};
5197
5198 if (!buf)
5199 return -EINVAL;
5200
5201 phm_get_sysfs_buf(&buf, &size);
5202
5203 size += sysfs_emit_at(buf, size, "%s %16s %s %s %s %s\n",title[0],
5204 title[1], title[2], title[3], title[4], title[5]);
5205
5206 for (i = 0; i < PP_SMC_POWER_PROFILE_CUSTOM; i++)
5207 size += sysfs_emit_at(buf, size, "%3d %14s%s: %14d %3d %10d %14d\n",
5208 i, amdgpu_pp_profile_name[i], (i == hwmgr->power_profile_mode) ? "*" : " ",
5209 profile_mode_setting[i][0], profile_mode_setting[i][1],
5210 profile_mode_setting[i][2], profile_mode_setting[i][3]);
5211
5212 size += sysfs_emit_at(buf, size, "%3d %14s%s: %14d %3d %10d %14d\n", i,
5213 amdgpu_pp_profile_name[i], (i == hwmgr->power_profile_mode) ? "*" : " ",
5214 data->custom_profile_mode[0], data->custom_profile_mode[1],
5215 data->custom_profile_mode[2], data->custom_profile_mode[3]);
5216 return size;
5217 }
5218
vega10_get_power_profile_mode_quirks(struct pp_hwmgr * hwmgr)5219 static bool vega10_get_power_profile_mode_quirks(struct pp_hwmgr *hwmgr)
5220 {
5221 struct amdgpu_device *adev = hwmgr->adev;
5222
5223 return (adev->pdev->device == 0x6860);
5224 }
5225
vega10_set_power_profile_mode(struct pp_hwmgr * hwmgr,long * input,uint32_t size)5226 static int vega10_set_power_profile_mode(struct pp_hwmgr *hwmgr, long *input, uint32_t size)
5227 {
5228 struct vega10_hwmgr *data = hwmgr->backend;
5229 uint8_t busy_set_point;
5230 uint8_t FPS;
5231 uint8_t use_rlc_busy;
5232 uint8_t min_active_level;
5233 uint32_t power_profile_mode = input[size];
5234
5235 if (power_profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
5236 if (size != 0 && size != 4)
5237 return -EINVAL;
5238
5239 /* If size = 0 and the CUSTOM profile has been set already
5240 * then just apply the profile. The copy stored in the hwmgr
5241 * is zeroed out on init
5242 */
5243 if (size == 0) {
5244 if (data->custom_profile_mode[0] != 0)
5245 goto out;
5246 else
5247 return -EINVAL;
5248 }
5249
5250 data->custom_profile_mode[0] = busy_set_point = input[0];
5251 data->custom_profile_mode[1] = FPS = input[1];
5252 data->custom_profile_mode[2] = use_rlc_busy = input[2];
5253 data->custom_profile_mode[3] = min_active_level = input[3];
5254 smum_send_msg_to_smc_with_parameter(hwmgr,
5255 PPSMC_MSG_SetCustomGfxDpmParameters,
5256 busy_set_point | FPS<<8 |
5257 use_rlc_busy << 16 | min_active_level<<24,
5258 NULL);
5259 }
5260
5261 out:
5262 if (vega10_get_power_profile_mode_quirks(hwmgr))
5263 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetWorkloadMask,
5264 1 << power_profile_mode,
5265 NULL);
5266 else
5267 smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_SetWorkloadMask,
5268 (!power_profile_mode) ? 0 : 1 << (power_profile_mode - 1),
5269 NULL);
5270
5271 hwmgr->power_profile_mode = power_profile_mode;
5272
5273 return 0;
5274 }
5275
5276
vega10_check_clk_voltage_valid(struct pp_hwmgr * hwmgr,enum PP_OD_DPM_TABLE_COMMAND type,uint32_t clk,uint32_t voltage)5277 static bool vega10_check_clk_voltage_valid(struct pp_hwmgr *hwmgr,
5278 enum PP_OD_DPM_TABLE_COMMAND type,
5279 uint32_t clk,
5280 uint32_t voltage)
5281 {
5282 struct vega10_hwmgr *data = hwmgr->backend;
5283 struct vega10_odn_dpm_table *odn_table = &(data->odn_dpm_table);
5284 struct vega10_single_dpm_table *golden_table;
5285
5286 if (voltage < odn_table->min_vddc || voltage > odn_table->max_vddc) {
5287 pr_info("OD voltage is out of range [%d - %d] mV\n", odn_table->min_vddc, odn_table->max_vddc);
5288 return false;
5289 }
5290
5291 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
5292 golden_table = &(data->golden_dpm_table.gfx_table);
5293 if (golden_table->dpm_levels[0].value > clk ||
5294 hwmgr->platform_descriptor.overdriveLimit.engineClock < clk) {
5295 pr_info("OD engine clock is out of range [%d - %d] MHz\n",
5296 golden_table->dpm_levels[0].value/100,
5297 hwmgr->platform_descriptor.overdriveLimit.engineClock/100);
5298 return false;
5299 }
5300 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
5301 golden_table = &(data->golden_dpm_table.mem_table);
5302 if (golden_table->dpm_levels[0].value > clk ||
5303 hwmgr->platform_descriptor.overdriveLimit.memoryClock < clk) {
5304 pr_info("OD memory clock is out of range [%d - %d] MHz\n",
5305 golden_table->dpm_levels[0].value/100,
5306 hwmgr->platform_descriptor.overdriveLimit.memoryClock/100);
5307 return false;
5308 }
5309 } else {
5310 return false;
5311 }
5312
5313 return true;
5314 }
5315
vega10_odn_update_power_state(struct pp_hwmgr * hwmgr)5316 static void vega10_odn_update_power_state(struct pp_hwmgr *hwmgr)
5317 {
5318 struct vega10_hwmgr *data = hwmgr->backend;
5319 struct pp_power_state *ps = hwmgr->request_ps;
5320 struct vega10_power_state *vega10_ps;
5321 struct vega10_single_dpm_table *gfx_dpm_table =
5322 &data->dpm_table.gfx_table;
5323 struct vega10_single_dpm_table *soc_dpm_table =
5324 &data->dpm_table.soc_table;
5325 struct vega10_single_dpm_table *mem_dpm_table =
5326 &data->dpm_table.mem_table;
5327 int max_level;
5328
5329 if (!ps)
5330 return;
5331
5332 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
5333 if (vega10_ps == NULL)
5334 return;
5335
5336 max_level = vega10_ps->performance_level_count - 1;
5337
5338 if (vega10_ps->performance_levels[max_level].gfx_clock !=
5339 gfx_dpm_table->dpm_levels[gfx_dpm_table->count - 1].value)
5340 vega10_ps->performance_levels[max_level].gfx_clock =
5341 gfx_dpm_table->dpm_levels[gfx_dpm_table->count - 1].value;
5342
5343 if (vega10_ps->performance_levels[max_level].soc_clock !=
5344 soc_dpm_table->dpm_levels[soc_dpm_table->count - 1].value)
5345 vega10_ps->performance_levels[max_level].soc_clock =
5346 soc_dpm_table->dpm_levels[soc_dpm_table->count - 1].value;
5347
5348 if (vega10_ps->performance_levels[max_level].mem_clock !=
5349 mem_dpm_table->dpm_levels[mem_dpm_table->count - 1].value)
5350 vega10_ps->performance_levels[max_level].mem_clock =
5351 mem_dpm_table->dpm_levels[mem_dpm_table->count - 1].value;
5352
5353 if (!hwmgr->ps)
5354 return;
5355
5356 ps = (struct pp_power_state *)((unsigned long)(hwmgr->ps) + hwmgr->ps_size * (hwmgr->num_ps - 1));
5357 vega10_ps = cast_phw_vega10_power_state(&ps->hardware);
5358 if (vega10_ps == NULL)
5359 return;
5360
5361 max_level = vega10_ps->performance_level_count - 1;
5362
5363 if (vega10_ps->performance_levels[max_level].gfx_clock !=
5364 gfx_dpm_table->dpm_levels[gfx_dpm_table->count - 1].value)
5365 vega10_ps->performance_levels[max_level].gfx_clock =
5366 gfx_dpm_table->dpm_levels[gfx_dpm_table->count - 1].value;
5367
5368 if (vega10_ps->performance_levels[max_level].soc_clock !=
5369 soc_dpm_table->dpm_levels[soc_dpm_table->count - 1].value)
5370 vega10_ps->performance_levels[max_level].soc_clock =
5371 soc_dpm_table->dpm_levels[soc_dpm_table->count - 1].value;
5372
5373 if (vega10_ps->performance_levels[max_level].mem_clock !=
5374 mem_dpm_table->dpm_levels[mem_dpm_table->count - 1].value)
5375 vega10_ps->performance_levels[max_level].mem_clock =
5376 mem_dpm_table->dpm_levels[mem_dpm_table->count - 1].value;
5377 }
5378
vega10_odn_update_soc_table(struct pp_hwmgr * hwmgr,enum PP_OD_DPM_TABLE_COMMAND type)5379 static void vega10_odn_update_soc_table(struct pp_hwmgr *hwmgr,
5380 enum PP_OD_DPM_TABLE_COMMAND type)
5381 {
5382 struct vega10_hwmgr *data = hwmgr->backend;
5383 struct phm_ppt_v2_information *table_info = hwmgr->pptable;
5384 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table = table_info->vdd_dep_on_socclk;
5385 struct vega10_single_dpm_table *dpm_table = &data->golden_dpm_table.mem_table;
5386
5387 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep_on_socclk =
5388 &data->odn_dpm_table.vdd_dep_on_socclk;
5389 struct vega10_odn_vddc_lookup_table *od_vddc_lookup_table = &data->odn_dpm_table.vddc_lookup_table;
5390
5391 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep;
5392 uint8_t i, j;
5393
5394 if (type == PP_OD_EDIT_SCLK_VDDC_TABLE) {
5395 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_sclk;
5396 for (i = 0; i < podn_vdd_dep->count; i++)
5397 od_vddc_lookup_table->entries[i].us_vdd = podn_vdd_dep->entries[i].vddc;
5398 } else if (type == PP_OD_EDIT_MCLK_VDDC_TABLE) {
5399 podn_vdd_dep = &data->odn_dpm_table.vdd_dep_on_mclk;
5400 for (i = 0; i < dpm_table->count; i++) {
5401 for (j = 0; j < od_vddc_lookup_table->count; j++) {
5402 if (od_vddc_lookup_table->entries[j].us_vdd >
5403 podn_vdd_dep->entries[i].vddc)
5404 break;
5405 }
5406 if (j == od_vddc_lookup_table->count) {
5407 j = od_vddc_lookup_table->count - 1;
5408 od_vddc_lookup_table->entries[j].us_vdd =
5409 podn_vdd_dep->entries[i].vddc;
5410 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_VDDC;
5411 }
5412 podn_vdd_dep->entries[i].vddInd = j;
5413 }
5414 dpm_table = &data->dpm_table.soc_table;
5415 for (i = 0; i < dep_table->count; i++) {
5416 if (dep_table->entries[i].vddInd == podn_vdd_dep->entries[podn_vdd_dep->count-1].vddInd &&
5417 dep_table->entries[i].clk < podn_vdd_dep->entries[podn_vdd_dep->count-1].clk) {
5418 data->need_update_dpm_table |= DPMTABLE_UPDATE_SOCCLK;
5419 for (; (i < dep_table->count) &&
5420 (dep_table->entries[i].clk < podn_vdd_dep->entries[podn_vdd_dep->count - 1].clk); i++) {
5421 podn_vdd_dep_on_socclk->entries[i].clk = podn_vdd_dep->entries[podn_vdd_dep->count-1].clk;
5422 dpm_table->dpm_levels[i].value = podn_vdd_dep_on_socclk->entries[i].clk;
5423 }
5424 break;
5425 } else {
5426 dpm_table->dpm_levels[i].value = dep_table->entries[i].clk;
5427 podn_vdd_dep_on_socclk->entries[i].vddc = dep_table->entries[i].vddc;
5428 podn_vdd_dep_on_socclk->entries[i].vddInd = dep_table->entries[i].vddInd;
5429 podn_vdd_dep_on_socclk->entries[i].clk = dep_table->entries[i].clk;
5430 }
5431 }
5432 if (podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].clk <
5433 podn_vdd_dep->entries[podn_vdd_dep->count - 1].clk) {
5434 data->need_update_dpm_table |= DPMTABLE_UPDATE_SOCCLK;
5435 podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].clk =
5436 podn_vdd_dep->entries[podn_vdd_dep->count - 1].clk;
5437 dpm_table->dpm_levels[podn_vdd_dep_on_socclk->count - 1].value =
5438 podn_vdd_dep->entries[podn_vdd_dep->count - 1].clk;
5439 }
5440 if (podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].vddInd <
5441 podn_vdd_dep->entries[podn_vdd_dep->count - 1].vddInd) {
5442 data->need_update_dpm_table |= DPMTABLE_UPDATE_SOCCLK;
5443 podn_vdd_dep_on_socclk->entries[podn_vdd_dep_on_socclk->count - 1].vddInd =
5444 podn_vdd_dep->entries[podn_vdd_dep->count - 1].vddInd;
5445 }
5446 }
5447 vega10_odn_update_power_state(hwmgr);
5448 }
5449
vega10_odn_edit_dpm_table(struct pp_hwmgr * hwmgr,enum PP_OD_DPM_TABLE_COMMAND type,long * input,uint32_t size)5450 static int vega10_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
5451 enum PP_OD_DPM_TABLE_COMMAND type,
5452 long *input, uint32_t size)
5453 {
5454 struct vega10_hwmgr *data = hwmgr->backend;
5455 struct vega10_odn_clock_voltage_dependency_table *podn_vdd_dep_table;
5456 struct vega10_single_dpm_table *dpm_table;
5457
5458 uint32_t input_clk;
5459 uint32_t input_vol;
5460 uint32_t input_level;
5461 uint32_t i;
5462
5463 PP_ASSERT_WITH_CODE(input, "NULL user input for clock and voltage",
5464 return -EINVAL);
5465
5466 if (!hwmgr->od_enabled) {
5467 pr_info("OverDrive feature not enabled\n");
5468 return -EINVAL;
5469 }
5470
5471 if (PP_OD_EDIT_SCLK_VDDC_TABLE == type) {
5472 dpm_table = &data->dpm_table.gfx_table;
5473 podn_vdd_dep_table = &data->odn_dpm_table.vdd_dep_on_sclk;
5474 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_SCLK;
5475 } else if (PP_OD_EDIT_MCLK_VDDC_TABLE == type) {
5476 dpm_table = &data->dpm_table.mem_table;
5477 podn_vdd_dep_table = &data->odn_dpm_table.vdd_dep_on_mclk;
5478 data->need_update_dpm_table |= DPMTABLE_OD_UPDATE_MCLK;
5479 } else if (PP_OD_RESTORE_DEFAULT_TABLE == type) {
5480 memcpy(&(data->dpm_table), &(data->golden_dpm_table), sizeof(struct vega10_dpm_table));
5481 vega10_odn_initial_default_setting(hwmgr);
5482 vega10_odn_update_power_state(hwmgr);
5483 /* force to update all clock tables */
5484 data->need_update_dpm_table = DPMTABLE_UPDATE_SCLK |
5485 DPMTABLE_UPDATE_MCLK |
5486 DPMTABLE_UPDATE_SOCCLK;
5487 return 0;
5488 } else if (PP_OD_COMMIT_DPM_TABLE == type) {
5489 vega10_check_dpm_table_updated(hwmgr);
5490 return 0;
5491 } else {
5492 return -EINVAL;
5493 }
5494
5495 for (i = 0; i < size; i += 3) {
5496 if (i + 3 > size || input[i] >= podn_vdd_dep_table->count) {
5497 pr_info("invalid clock voltage input\n");
5498 return 0;
5499 }
5500 input_level = input[i];
5501 input_clk = input[i+1] * 100;
5502 input_vol = input[i+2];
5503
5504 if (vega10_check_clk_voltage_valid(hwmgr, type, input_clk, input_vol)) {
5505 dpm_table->dpm_levels[input_level].value = input_clk;
5506 podn_vdd_dep_table->entries[input_level].clk = input_clk;
5507 podn_vdd_dep_table->entries[input_level].vddc = input_vol;
5508 } else {
5509 return -EINVAL;
5510 }
5511 }
5512 vega10_odn_update_soc_table(hwmgr, type);
5513 return 0;
5514 }
5515
vega10_set_mp1_state(struct pp_hwmgr * hwmgr,enum pp_mp1_state mp1_state)5516 static int vega10_set_mp1_state(struct pp_hwmgr *hwmgr,
5517 enum pp_mp1_state mp1_state)
5518 {
5519 uint16_t msg;
5520 int ret;
5521
5522 switch (mp1_state) {
5523 case PP_MP1_STATE_UNLOAD:
5524 msg = PPSMC_MSG_PrepareMp1ForUnload;
5525 break;
5526 case PP_MP1_STATE_SHUTDOWN:
5527 case PP_MP1_STATE_RESET:
5528 case PP_MP1_STATE_NONE:
5529 default:
5530 return 0;
5531 }
5532
5533 PP_ASSERT_WITH_CODE((ret = smum_send_msg_to_smc(hwmgr, msg, NULL)) == 0,
5534 "[PrepareMp1] Failed!",
5535 return ret);
5536
5537 return 0;
5538 }
5539
vega10_get_performance_level(struct pp_hwmgr * hwmgr,const struct pp_hw_power_state * state,PHM_PerformanceLevelDesignation designation,uint32_t index,PHM_PerformanceLevel * level)5540 static int vega10_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
5541 PHM_PerformanceLevelDesignation designation, uint32_t index,
5542 PHM_PerformanceLevel *level)
5543 {
5544 const struct vega10_power_state *vega10_ps;
5545 uint32_t i;
5546
5547 if (level == NULL || hwmgr == NULL || state == NULL)
5548 return -EINVAL;
5549
5550 vega10_ps = cast_const_phw_vega10_power_state(state);
5551 if (vega10_ps == NULL)
5552 return -EINVAL;
5553
5554 i = index > vega10_ps->performance_level_count - 1 ?
5555 vega10_ps->performance_level_count - 1 : index;
5556
5557 level->coreClock = vega10_ps->performance_levels[i].gfx_clock;
5558 level->memory_clock = vega10_ps->performance_levels[i].mem_clock;
5559
5560 return 0;
5561 }
5562
vega10_disable_power_features_for_compute_performance(struct pp_hwmgr * hwmgr,bool disable)5563 static int vega10_disable_power_features_for_compute_performance(struct pp_hwmgr *hwmgr, bool disable)
5564 {
5565 struct vega10_hwmgr *data = hwmgr->backend;
5566 uint32_t feature_mask = 0;
5567
5568 if (disable) {
5569 feature_mask |= data->smu_features[GNLD_ULV].enabled ?
5570 data->smu_features[GNLD_ULV].smu_feature_bitmap : 0;
5571 feature_mask |= data->smu_features[GNLD_DS_GFXCLK].enabled ?
5572 data->smu_features[GNLD_DS_GFXCLK].smu_feature_bitmap : 0;
5573 feature_mask |= data->smu_features[GNLD_DS_SOCCLK].enabled ?
5574 data->smu_features[GNLD_DS_SOCCLK].smu_feature_bitmap : 0;
5575 feature_mask |= data->smu_features[GNLD_DS_LCLK].enabled ?
5576 data->smu_features[GNLD_DS_LCLK].smu_feature_bitmap : 0;
5577 feature_mask |= data->smu_features[GNLD_DS_DCEFCLK].enabled ?
5578 data->smu_features[GNLD_DS_DCEFCLK].smu_feature_bitmap : 0;
5579 } else {
5580 feature_mask |= (!data->smu_features[GNLD_ULV].enabled) ?
5581 data->smu_features[GNLD_ULV].smu_feature_bitmap : 0;
5582 feature_mask |= (!data->smu_features[GNLD_DS_GFXCLK].enabled) ?
5583 data->smu_features[GNLD_DS_GFXCLK].smu_feature_bitmap : 0;
5584 feature_mask |= (!data->smu_features[GNLD_DS_SOCCLK].enabled) ?
5585 data->smu_features[GNLD_DS_SOCCLK].smu_feature_bitmap : 0;
5586 feature_mask |= (!data->smu_features[GNLD_DS_LCLK].enabled) ?
5587 data->smu_features[GNLD_DS_LCLK].smu_feature_bitmap : 0;
5588 feature_mask |= (!data->smu_features[GNLD_DS_DCEFCLK].enabled) ?
5589 data->smu_features[GNLD_DS_DCEFCLK].smu_feature_bitmap : 0;
5590 }
5591
5592 if (feature_mask)
5593 PP_ASSERT_WITH_CODE(!vega10_enable_smc_features(hwmgr,
5594 !disable, feature_mask),
5595 "enable/disable power features for compute performance Failed!",
5596 return -EINVAL);
5597
5598 if (disable) {
5599 data->smu_features[GNLD_ULV].enabled = false;
5600 data->smu_features[GNLD_DS_GFXCLK].enabled = false;
5601 data->smu_features[GNLD_DS_SOCCLK].enabled = false;
5602 data->smu_features[GNLD_DS_LCLK].enabled = false;
5603 data->smu_features[GNLD_DS_DCEFCLK].enabled = false;
5604 } else {
5605 data->smu_features[GNLD_ULV].enabled = true;
5606 data->smu_features[GNLD_DS_GFXCLK].enabled = true;
5607 data->smu_features[GNLD_DS_SOCCLK].enabled = true;
5608 data->smu_features[GNLD_DS_LCLK].enabled = true;
5609 data->smu_features[GNLD_DS_DCEFCLK].enabled = true;
5610 }
5611
5612 return 0;
5613
5614 }
5615
5616 static const struct pp_hwmgr_func vega10_hwmgr_funcs = {
5617 .backend_init = vega10_hwmgr_backend_init,
5618 .backend_fini = vega10_hwmgr_backend_fini,
5619 .asic_setup = vega10_setup_asic_task,
5620 .dynamic_state_management_enable = vega10_enable_dpm_tasks,
5621 .dynamic_state_management_disable = vega10_disable_dpm_tasks,
5622 .get_num_of_pp_table_entries =
5623 vega10_get_number_of_powerplay_table_entries,
5624 .get_power_state_size = vega10_get_power_state_size,
5625 .get_pp_table_entry = vega10_get_pp_table_entry,
5626 .patch_boot_state = vega10_patch_boot_state,
5627 .apply_state_adjust_rules = vega10_apply_state_adjust_rules,
5628 .power_state_set = vega10_set_power_state_tasks,
5629 .get_sclk = vega10_dpm_get_sclk,
5630 .get_mclk = vega10_dpm_get_mclk,
5631 .notify_smc_display_config_after_ps_adjustment =
5632 vega10_notify_smc_display_config_after_ps_adjustment,
5633 .force_dpm_level = vega10_dpm_force_dpm_level,
5634 .stop_thermal_controller = vega10_thermal_stop_thermal_controller,
5635 .get_fan_speed_info = vega10_fan_ctrl_get_fan_speed_info,
5636 .get_fan_speed_pwm = vega10_fan_ctrl_get_fan_speed_pwm,
5637 .set_fan_speed_pwm = vega10_fan_ctrl_set_fan_speed_pwm,
5638 .reset_fan_speed_to_default =
5639 vega10_fan_ctrl_reset_fan_speed_to_default,
5640 .get_fan_speed_rpm = vega10_fan_ctrl_get_fan_speed_rpm,
5641 .set_fan_speed_rpm = vega10_fan_ctrl_set_fan_speed_rpm,
5642 .uninitialize_thermal_controller =
5643 vega10_thermal_ctrl_uninitialize_thermal_controller,
5644 .set_fan_control_mode = vega10_set_fan_control_mode,
5645 .get_fan_control_mode = vega10_get_fan_control_mode,
5646 .read_sensor = vega10_read_sensor,
5647 .get_dal_power_level = vega10_get_dal_power_level,
5648 .get_clock_by_type_with_latency = vega10_get_clock_by_type_with_latency,
5649 .get_clock_by_type_with_voltage = vega10_get_clock_by_type_with_voltage,
5650 .set_watermarks_for_clocks_ranges = vega10_set_watermarks_for_clocks_ranges,
5651 .display_clock_voltage_request = vega10_display_clock_voltage_request,
5652 .force_clock_level = vega10_force_clock_level,
5653 .emit_clock_levels = vega10_emit_clock_levels,
5654 .display_config_changed = vega10_display_configuration_changed_task,
5655 .powergate_uvd = vega10_power_gate_uvd,
5656 .powergate_vce = vega10_power_gate_vce,
5657 .check_states_equal = vega10_check_states_equal,
5658 .check_smc_update_required_for_display_configuration =
5659 vega10_check_smc_update_required_for_display_configuration,
5660 .power_off_asic = vega10_power_off_asic,
5661 .disable_smc_firmware_ctf = vega10_thermal_disable_alert,
5662 .get_sclk_od = vega10_get_sclk_od,
5663 .set_sclk_od = vega10_set_sclk_od,
5664 .get_mclk_od = vega10_get_mclk_od,
5665 .set_mclk_od = vega10_set_mclk_od,
5666 .avfs_control = vega10_avfs_enable,
5667 .notify_cac_buffer_info = vega10_notify_cac_buffer_info,
5668 .get_thermal_temperature_range = vega10_get_thermal_temperature_range,
5669 .register_irq_handlers = smu9_register_irq_handlers,
5670 .start_thermal_controller = vega10_start_thermal_controller,
5671 .get_power_profile_mode = vega10_get_power_profile_mode,
5672 .set_power_profile_mode = vega10_set_power_profile_mode,
5673 .set_power_limit = vega10_set_power_limit,
5674 .odn_edit_dpm_table = vega10_odn_edit_dpm_table,
5675 .get_performance_level = vega10_get_performance_level,
5676 .get_bamaco_support = smu9_get_bamaco_support,
5677 .get_asic_baco_state = smu9_baco_get_state,
5678 .set_asic_baco_state = vega10_baco_set_state,
5679 .enable_mgpu_fan_boost = vega10_enable_mgpu_fan_boost,
5680 .get_ppfeature_status = vega10_get_ppfeature_status,
5681 .set_ppfeature_status = vega10_set_ppfeature_status,
5682 .set_mp1_state = vega10_set_mp1_state,
5683 .disable_power_features_for_compute_performance =
5684 vega10_disable_power_features_for_compute_performance,
5685 };
5686
vega10_hwmgr_init(struct pp_hwmgr * hwmgr)5687 int vega10_hwmgr_init(struct pp_hwmgr *hwmgr)
5688 {
5689 struct amdgpu_device *adev = hwmgr->adev;
5690
5691 hwmgr->hwmgr_func = &vega10_hwmgr_funcs;
5692 hwmgr->pptable_func = &vega10_pptable_funcs;
5693 if (amdgpu_passthrough(adev))
5694 return vega10_baco_set_cap(hwmgr);
5695
5696 return 0;
5697 }
5698