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