2 * Copyright 2019 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <linux/firmware.h>
27 #include "amdgpu_smu.h"
28 #include "atomfirmware.h"
29 #include "amdgpu_atomfirmware.h"
30 #include "smu_v11_0.h"
31 #include "smu11_driver_if_arcturus.h"
32 #include "soc15_common.h"
34 #include "power_state.h"
35 #include "arcturus_ppt.h"
36 #include "smu_v11_0_pptable.h"
37 #include "arcturus_ppsmc.h"
38 #include "nbio/nbio_7_4_sh_mask.h"
40 #define CTF_OFFSET_EDGE 5
41 #define CTF_OFFSET_HOTSPOT 5
42 #define CTF_OFFSET_HBM 5
44 #define MSG_MAP(msg, index) \
45 [SMU_MSG_##msg] = {1, (index)}
46 #define ARCTURUS_FEA_MAP(smu_feature, arcturus_feature) \
47 [smu_feature] = {1, (arcturus_feature)}
49 #define SMU_FEATURES_LOW_MASK 0x00000000FFFFFFFF
50 #define SMU_FEATURES_LOW_SHIFT 0
51 #define SMU_FEATURES_HIGH_MASK 0xFFFFFFFF00000000
52 #define SMU_FEATURES_HIGH_SHIFT 32
54 static struct smu_11_0_cmn2aisc_mapping arcturus_message_map[SMU_MSG_MAX_COUNT] = {
55 MSG_MAP(TestMessage, PPSMC_MSG_TestMessage),
56 MSG_MAP(GetSmuVersion, PPSMC_MSG_GetSmuVersion),
57 MSG_MAP(GetDriverIfVersion, PPSMC_MSG_GetDriverIfVersion),
58 MSG_MAP(SetAllowedFeaturesMaskLow, PPSMC_MSG_SetAllowedFeaturesMaskLow),
59 MSG_MAP(SetAllowedFeaturesMaskHigh, PPSMC_MSG_SetAllowedFeaturesMaskHigh),
60 MSG_MAP(EnableAllSmuFeatures, PPSMC_MSG_EnableAllSmuFeatures),
61 MSG_MAP(DisableAllSmuFeatures, PPSMC_MSG_DisableAllSmuFeatures),
62 MSG_MAP(EnableSmuFeaturesLow, PPSMC_MSG_EnableSmuFeaturesLow),
63 MSG_MAP(EnableSmuFeaturesHigh, PPSMC_MSG_EnableSmuFeaturesHigh),
64 MSG_MAP(DisableSmuFeaturesLow, PPSMC_MSG_DisableSmuFeaturesLow),
65 MSG_MAP(DisableSmuFeaturesHigh, PPSMC_MSG_DisableSmuFeaturesHigh),
66 MSG_MAP(GetEnabledSmuFeaturesLow, PPSMC_MSG_GetEnabledSmuFeaturesLow),
67 MSG_MAP(GetEnabledSmuFeaturesHigh, PPSMC_MSG_GetEnabledSmuFeaturesHigh),
68 MSG_MAP(SetDriverDramAddrHigh, PPSMC_MSG_SetDriverDramAddrHigh),
69 MSG_MAP(SetDriverDramAddrLow, PPSMC_MSG_SetDriverDramAddrLow),
70 MSG_MAP(SetToolsDramAddrHigh, PPSMC_MSG_SetToolsDramAddrHigh),
71 MSG_MAP(SetToolsDramAddrLow, PPSMC_MSG_SetToolsDramAddrLow),
72 MSG_MAP(TransferTableSmu2Dram, PPSMC_MSG_TransferTableSmu2Dram),
73 MSG_MAP(TransferTableDram2Smu, PPSMC_MSG_TransferTableDram2Smu),
74 MSG_MAP(UseDefaultPPTable, PPSMC_MSG_UseDefaultPPTable),
75 MSG_MAP(UseBackupPPTable, PPSMC_MSG_UseBackupPPTable),
76 MSG_MAP(SetSystemVirtualDramAddrHigh, PPSMC_MSG_SetSystemVirtualDramAddrHigh),
77 MSG_MAP(SetSystemVirtualDramAddrLow, PPSMC_MSG_SetSystemVirtualDramAddrLow),
78 MSG_MAP(EnterBaco, PPSMC_MSG_EnterBaco),
79 MSG_MAP(ExitBaco, PPSMC_MSG_ExitBaco),
80 MSG_MAP(ArmD3, PPSMC_MSG_ArmD3),
81 MSG_MAP(SetSoftMinByFreq, PPSMC_MSG_SetSoftMinByFreq),
82 MSG_MAP(SetSoftMaxByFreq, PPSMC_MSG_SetSoftMaxByFreq),
83 MSG_MAP(SetHardMinByFreq, PPSMC_MSG_SetHardMinByFreq),
84 MSG_MAP(SetHardMaxByFreq, PPSMC_MSG_SetHardMaxByFreq),
85 MSG_MAP(GetMinDpmFreq, PPSMC_MSG_GetMinDpmFreq),
86 MSG_MAP(GetMaxDpmFreq, PPSMC_MSG_GetMaxDpmFreq),
87 MSG_MAP(GetDpmFreqByIndex, PPSMC_MSG_GetDpmFreqByIndex),
88 MSG_MAP(SetWorkloadMask, PPSMC_MSG_SetWorkloadMask),
89 MSG_MAP(SetDfSwitchType, PPSMC_MSG_SetDfSwitchType),
90 MSG_MAP(GetVoltageByDpm, PPSMC_MSG_GetVoltageByDpm),
91 MSG_MAP(GetVoltageByDpmOverdrive, PPSMC_MSG_GetVoltageByDpmOverdrive),
92 MSG_MAP(SetPptLimit, PPSMC_MSG_SetPptLimit),
93 MSG_MAP(GetPptLimit, PPSMC_MSG_GetPptLimit),
94 MSG_MAP(PowerUpVcn0, PPSMC_MSG_PowerUpVcn0),
95 MSG_MAP(PowerDownVcn0, PPSMC_MSG_PowerDownVcn0),
96 MSG_MAP(PowerUpVcn1, PPSMC_MSG_PowerUpVcn1),
97 MSG_MAP(PowerDownVcn1, PPSMC_MSG_PowerDownVcn1),
98 MSG_MAP(PrepareMp1ForUnload, PPSMC_MSG_PrepareMp1ForUnload),
99 MSG_MAP(PrepareMp1ForReset, PPSMC_MSG_PrepareMp1ForReset),
100 MSG_MAP(PrepareMp1ForShutdown, PPSMC_MSG_PrepareMp1ForShutdown),
101 MSG_MAP(SoftReset, PPSMC_MSG_SoftReset),
102 MSG_MAP(RunAfllBtc, PPSMC_MSG_RunAfllBtc),
103 MSG_MAP(RunGfxDcBtc, PPSMC_MSG_RunGfxDcBtc),
104 MSG_MAP(RunSocDcBtc, PPSMC_MSG_RunSocDcBtc),
105 MSG_MAP(DramLogSetDramAddrHigh, PPSMC_MSG_DramLogSetDramAddrHigh),
106 MSG_MAP(DramLogSetDramAddrLow, PPSMC_MSG_DramLogSetDramAddrLow),
107 MSG_MAP(DramLogSetDramSize, PPSMC_MSG_DramLogSetDramSize),
108 MSG_MAP(GetDebugData, PPSMC_MSG_GetDebugData),
109 MSG_MAP(WaflTest, PPSMC_MSG_WaflTest),
110 MSG_MAP(SetXgmiMode, PPSMC_MSG_SetXgmiMode),
111 MSG_MAP(SetMemoryChannelEnable, PPSMC_MSG_SetMemoryChannelEnable),
114 static struct smu_11_0_cmn2aisc_mapping arcturus_clk_map[SMU_CLK_COUNT] = {
115 CLK_MAP(GFXCLK, PPCLK_GFXCLK),
116 CLK_MAP(SCLK, PPCLK_GFXCLK),
117 CLK_MAP(SOCCLK, PPCLK_SOCCLK),
118 CLK_MAP(FCLK, PPCLK_FCLK),
119 CLK_MAP(UCLK, PPCLK_UCLK),
120 CLK_MAP(MCLK, PPCLK_UCLK),
121 CLK_MAP(DCLK, PPCLK_DCLK),
122 CLK_MAP(VCLK, PPCLK_VCLK),
125 static struct smu_11_0_cmn2aisc_mapping arcturus_feature_mask_map[SMU_FEATURE_COUNT] = {
126 FEA_MAP(DPM_PREFETCHER),
138 ARCTURUS_FEA_MAP(SMU_FEATURE_VCN_PG_BIT, FEATURE_DPM_VCN_BIT),
139 FEA_MAP(RSMU_SMN_CG),
146 FEA_MAP(FAN_CONTROL),
148 FEA_MAP(OUT_OF_BAND_MONITOR),
149 FEA_MAP(TEMP_DEPENDENT_VMIN),
152 static struct smu_11_0_cmn2aisc_mapping arcturus_table_map[SMU_TABLE_COUNT] = {
155 TAB_MAP(AVFS_PSM_DEBUG),
156 TAB_MAP(AVFS_FUSE_OVERRIDE),
157 TAB_MAP(PMSTATUSLOG),
158 TAB_MAP(SMU_METRICS),
159 TAB_MAP(DRIVER_SMU_CONFIG),
163 static struct smu_11_0_cmn2aisc_mapping arcturus_pwr_src_map[SMU_POWER_SOURCE_COUNT] = {
168 static struct smu_11_0_cmn2aisc_mapping arcturus_workload_map[PP_SMC_POWER_PROFILE_COUNT] = {
169 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT, WORKLOAD_PPLIB_DEFAULT_BIT),
170 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_POWERSAVING, WORKLOAD_PPLIB_POWER_SAVING_BIT),
171 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VIDEO, WORKLOAD_PPLIB_VIDEO_BIT),
172 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_COMPUTE, WORKLOAD_PPLIB_CUSTOM_BIT),
173 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM, WORKLOAD_PPLIB_CUSTOM_BIT),
176 static int arcturus_get_smu_msg_index(struct smu_context *smc, uint32_t index)
178 struct smu_11_0_cmn2aisc_mapping mapping;
180 if (index >= SMU_MSG_MAX_COUNT)
183 mapping = arcturus_message_map[index];
184 if (!(mapping.valid_mapping))
187 return mapping.map_to;
190 static int arcturus_get_smu_clk_index(struct smu_context *smc, uint32_t index)
192 struct smu_11_0_cmn2aisc_mapping mapping;
194 if (index >= SMU_CLK_COUNT)
197 mapping = arcturus_clk_map[index];
198 if (!(mapping.valid_mapping)) {
199 pr_warn("Unsupported SMU clk: %d\n", index);
203 return mapping.map_to;
206 static int arcturus_get_smu_feature_index(struct smu_context *smc, uint32_t index)
208 struct smu_11_0_cmn2aisc_mapping mapping;
210 if (index >= SMU_FEATURE_COUNT)
213 mapping = arcturus_feature_mask_map[index];
214 if (!(mapping.valid_mapping)) {
215 pr_warn("Unsupported SMU feature: %d\n", index);
219 return mapping.map_to;
222 static int arcturus_get_smu_table_index(struct smu_context *smc, uint32_t index)
224 struct smu_11_0_cmn2aisc_mapping mapping;
226 if (index >= SMU_TABLE_COUNT)
229 mapping = arcturus_table_map[index];
230 if (!(mapping.valid_mapping)) {
231 pr_warn("Unsupported SMU table: %d\n", index);
235 return mapping.map_to;
238 static int arcturus_get_pwr_src_index(struct smu_context *smc, uint32_t index)
240 struct smu_11_0_cmn2aisc_mapping mapping;
242 if (index >= SMU_POWER_SOURCE_COUNT)
245 mapping = arcturus_pwr_src_map[index];
246 if (!(mapping.valid_mapping)) {
247 pr_warn("Unsupported SMU power source: %d\n", index);
251 return mapping.map_to;
255 static int arcturus_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER_PROFILE profile)
257 struct smu_11_0_cmn2aisc_mapping mapping;
259 if (profile > PP_SMC_POWER_PROFILE_CUSTOM)
262 mapping = arcturus_workload_map[profile];
263 if (!(mapping.valid_mapping)) {
264 pr_warn("Unsupported SMU power source: %d\n", profile);
268 return mapping.map_to;
271 static int arcturus_tables_init(struct smu_context *smu, struct smu_table *tables)
273 struct smu_table_context *smu_table = &smu->smu_table;
275 SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t),
276 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
278 SMU_TABLE_INIT(tables, SMU_TABLE_PMSTATUSLOG, SMU11_TOOL_SIZE,
279 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
281 SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
282 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
284 smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
285 if (!smu_table->metrics_table)
287 smu_table->metrics_time = 0;
292 static int arcturus_allocate_dpm_context(struct smu_context *smu)
294 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
296 if (smu_dpm->dpm_context)
299 smu_dpm->dpm_context = kzalloc(sizeof(struct arcturus_dpm_table),
301 if (!smu_dpm->dpm_context)
304 if (smu_dpm->golden_dpm_context)
307 smu_dpm->golden_dpm_context = kzalloc(sizeof(struct arcturus_dpm_table),
309 if (!smu_dpm->golden_dpm_context)
312 smu_dpm->dpm_context_size = sizeof(struct arcturus_dpm_table);
314 smu_dpm->dpm_current_power_state = kzalloc(sizeof(struct smu_power_state),
316 if (!smu_dpm->dpm_current_power_state)
319 smu_dpm->dpm_request_power_state = kzalloc(sizeof(struct smu_power_state),
321 if (!smu_dpm->dpm_request_power_state)
327 #define FEATURE_MASK(feature) (1ULL << feature)
329 arcturus_get_allowed_feature_mask(struct smu_context *smu,
330 uint32_t *feature_mask, uint32_t num)
335 memset(feature_mask, 0, sizeof(uint32_t) * num);
337 *(uint64_t *)feature_mask |= FEATURE_MASK(FEATURE_DPM_PREFETCHER_BIT);
343 arcturus_set_single_dpm_table(struct smu_context *smu,
344 struct arcturus_single_dpm_table *single_dpm_table,
348 uint32_t i, num_of_levels = 0, clk;
350 ret = smu_send_smc_msg_with_param(smu,
351 SMU_MSG_GetDpmFreqByIndex,
352 (clk_id << 16 | 0xFF));
354 pr_err("[%s] failed to get dpm levels!\n", __func__);
358 smu_read_smc_arg(smu, &num_of_levels);
359 if (!num_of_levels) {
360 pr_err("[%s] number of clk levels is invalid!\n", __func__);
364 single_dpm_table->count = num_of_levels;
365 for (i = 0; i < num_of_levels; i++) {
366 ret = smu_send_smc_msg_with_param(smu,
367 SMU_MSG_GetDpmFreqByIndex,
370 pr_err("[%s] failed to get dpm freq by index!\n", __func__);
373 smu_read_smc_arg(smu, &clk);
375 pr_err("[%s] clk value is invalid!\n", __func__);
378 single_dpm_table->dpm_levels[i].value = clk;
379 single_dpm_table->dpm_levels[i].enabled = true;
384 static void arcturus_init_single_dpm_state(struct arcturus_dpm_state *dpm_state)
386 dpm_state->soft_min_level = 0x0;
387 dpm_state->soft_max_level = 0xffff;
388 dpm_state->hard_min_level = 0x0;
389 dpm_state->hard_max_level = 0xffff;
392 static int arcturus_set_default_dpm_table(struct smu_context *smu)
396 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
397 struct arcturus_dpm_table *dpm_table = NULL;
398 struct arcturus_single_dpm_table *single_dpm_table;
400 dpm_table = smu_dpm->dpm_context;
403 single_dpm_table = &(dpm_table->soc_table);
404 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
405 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
408 pr_err("[%s] failed to get socclk dpm levels!\n", __func__);
412 single_dpm_table->count = 1;
413 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.socclk / 100;
415 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
418 single_dpm_table = &(dpm_table->gfx_table);
419 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT)) {
420 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
423 pr_err("[SetupDefaultDpmTable] failed to get gfxclk dpm levels!");
427 single_dpm_table->count = 1;
428 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.gfxclk / 100;
430 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
433 single_dpm_table = &(dpm_table->mem_table);
434 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
435 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
438 pr_err("[SetupDefaultDpmTable] failed to get memclk dpm levels!");
442 single_dpm_table->count = 1;
443 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.uclk / 100;
445 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
448 single_dpm_table = &(dpm_table->fclk_table);
449 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_FCLK_BIT)) {
450 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
453 pr_err("[SetupDefaultDpmTable] failed to get fclk dpm levels!");
457 single_dpm_table->count = 0;
459 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
461 memcpy(smu_dpm->golden_dpm_context, dpm_table,
462 sizeof(struct arcturus_dpm_table));
467 static int arcturus_check_powerplay_table(struct smu_context *smu)
472 static int arcturus_store_powerplay_table(struct smu_context *smu)
474 struct smu_11_0_powerplay_table *powerplay_table = NULL;
475 struct smu_table_context *table_context = &smu->smu_table;
478 if (!table_context->power_play_table)
481 powerplay_table = table_context->power_play_table;
483 memcpy(table_context->driver_pptable, &powerplay_table->smc_pptable,
486 table_context->thermal_controller_type = powerplay_table->thermal_controller_type;
491 static int arcturus_append_powerplay_table(struct smu_context *smu)
493 struct smu_table_context *table_context = &smu->smu_table;
494 PPTable_t *smc_pptable = table_context->driver_pptable;
495 struct atom_smc_dpm_info_v4_6 *smc_dpm_table;
498 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
501 ret = smu_get_atom_data_table(smu, index, NULL, NULL, NULL,
502 (uint8_t **)&smc_dpm_table);
506 pr_info("smc_dpm_info table revision(format.content): %d.%d\n",
507 smc_dpm_table->table_header.format_revision,
508 smc_dpm_table->table_header.content_revision);
510 if ((smc_dpm_table->table_header.format_revision == 4) &&
511 (smc_dpm_table->table_header.content_revision == 6))
512 memcpy(&smc_pptable->MaxVoltageStepGfx,
513 &smc_dpm_table->maxvoltagestepgfx,
514 sizeof(*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_6, maxvoltagestepgfx));
519 static int arcturus_run_btc_afll(struct smu_context *smu)
521 return smu_send_smc_msg(smu, SMU_MSG_RunAfllBtc);
524 static int arcturus_populate_umd_state_clk(struct smu_context *smu)
526 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
527 struct arcturus_dpm_table *dpm_table = NULL;
528 struct arcturus_single_dpm_table *gfx_table = NULL;
529 struct arcturus_single_dpm_table *mem_table = NULL;
531 dpm_table = smu_dpm->dpm_context;
532 gfx_table = &(dpm_table->gfx_table);
533 mem_table = &(dpm_table->mem_table);
535 smu->pstate_sclk = gfx_table->dpm_levels[0].value;
536 smu->pstate_mclk = mem_table->dpm_levels[0].value;
538 if (gfx_table->count > ARCTURUS_UMD_PSTATE_GFXCLK_LEVEL &&
539 mem_table->count > ARCTURUS_UMD_PSTATE_MCLK_LEVEL) {
540 smu->pstate_sclk = gfx_table->dpm_levels[ARCTURUS_UMD_PSTATE_GFXCLK_LEVEL].value;
541 smu->pstate_mclk = mem_table->dpm_levels[ARCTURUS_UMD_PSTATE_MCLK_LEVEL].value;
544 smu->pstate_sclk = smu->pstate_sclk * 100;
545 smu->pstate_mclk = smu->pstate_mclk * 100;
550 static int arcturus_get_clk_table(struct smu_context *smu,
551 struct pp_clock_levels_with_latency *clocks,
552 struct arcturus_single_dpm_table *dpm_table)
556 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
557 clocks->num_levels = count;
559 for (i = 0; i < count; i++) {
560 clocks->data[i].clocks_in_khz =
561 dpm_table->dpm_levels[i].value * 1000;
562 clocks->data[i].latency_in_us = 0;
568 static int arcturus_print_clk_levels(struct smu_context *smu,
569 enum smu_clk_type type, char *buf)
571 int i, now, size = 0;
573 struct pp_clock_levels_with_latency clocks;
574 struct arcturus_single_dpm_table *single_dpm_table;
575 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
576 struct arcturus_dpm_table *dpm_table = NULL;
578 dpm_table = smu_dpm->dpm_context;
582 ret = smu_get_current_clk_freq(smu, SMU_GFXCLK, &now);
584 pr_err("Attempt to get current gfx clk Failed!");
588 single_dpm_table = &(dpm_table->gfx_table);
589 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
591 pr_err("Attempt to get gfx clk levels Failed!");
595 for (i = 0; i < clocks.num_levels; i++)
596 size += sprintf(buf + size, "%d: %uMhz %s\n", i,
597 clocks.data[i].clocks_in_khz / 1000,
598 (clocks.data[i].clocks_in_khz == now * 10)
603 ret = smu_get_current_clk_freq(smu, SMU_UCLK, &now);
605 pr_err("Attempt to get current mclk Failed!");
609 single_dpm_table = &(dpm_table->mem_table);
610 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
612 pr_err("Attempt to get memory clk levels Failed!");
616 for (i = 0; i < clocks.num_levels; i++)
617 size += sprintf(buf + size, "%d: %uMhz %s\n",
618 i, clocks.data[i].clocks_in_khz / 1000,
619 (clocks.data[i].clocks_in_khz == now * 10)
624 ret = smu_get_current_clk_freq(smu, SMU_SOCCLK, &now);
626 pr_err("Attempt to get current socclk Failed!");
630 single_dpm_table = &(dpm_table->soc_table);
631 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
633 pr_err("Attempt to get socclk levels Failed!");
637 for (i = 0; i < clocks.num_levels; i++)
638 size += sprintf(buf + size, "%d: %uMhz %s\n",
639 i, clocks.data[i].clocks_in_khz / 1000,
640 (clocks.data[i].clocks_in_khz == now * 10)
645 ret = smu_get_current_clk_freq(smu, SMU_FCLK, &now);
647 pr_err("Attempt to get current fclk Failed!");
651 single_dpm_table = &(dpm_table->fclk_table);
652 for (i = 0; i < single_dpm_table->count; i++)
653 size += sprintf(buf + size, "%d: %uMhz %s\n",
654 i, single_dpm_table->dpm_levels[i].value,
655 (single_dpm_table->dpm_levels[i].value == now / 100)
666 static int arcturus_upload_dpm_level(struct smu_context *smu, bool max,
667 uint32_t feature_mask)
669 struct arcturus_dpm_table *dpm_table;
670 struct arcturus_single_dpm_table *single_dpm_table;
674 dpm_table = smu->smu_dpm.dpm_context;
675 if (smu_feature_is_enabled(smu, FEATURE_DPM_GFXCLK_BIT) &&
676 (feature_mask & FEATURE_DPM_GFXCLK_MASK)) {
677 single_dpm_table = &(dpm_table->gfx_table);
678 freq = max ? single_dpm_table->dpm_state.soft_max_level :
679 single_dpm_table->dpm_state.soft_min_level;
680 ret = smu_send_smc_msg_with_param(smu,
681 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
682 (PPCLK_GFXCLK << 16) | (freq & 0xffff));
684 pr_err("Failed to set soft %s gfxclk !\n",
685 max ? "max" : "min");
693 static int arcturus_force_clk_levels(struct smu_context *smu,
694 enum smu_clk_type type, uint32_t mask)
696 struct arcturus_dpm_table *dpm_table;
697 struct arcturus_single_dpm_table *single_dpm_table;
698 uint32_t soft_min_level, soft_max_level;
701 mutex_lock(&(smu->mutex));
703 soft_min_level = mask ? (ffs(mask) - 1) : 0;
704 soft_max_level = mask ? (fls(mask) - 1) : 0;
706 dpm_table = smu->smu_dpm.dpm_context;
710 single_dpm_table = &(dpm_table->gfx_table);
712 if (soft_max_level >= single_dpm_table->count) {
713 pr_err("Clock level specified %d is over max allowed %d\n",
714 soft_max_level, single_dpm_table->count - 1);
719 single_dpm_table->dpm_state.soft_min_level =
720 single_dpm_table->dpm_levels[soft_min_level].value;
721 single_dpm_table->dpm_state.soft_max_level =
722 single_dpm_table->dpm_levels[soft_max_level].value;
724 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
726 pr_err("Failed to upload boot level to lowest!\n");
730 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
732 pr_err("Failed to upload dpm max level to highest!\n");
737 single_dpm_table = &(dpm_table->mem_table);
739 if (soft_max_level >= single_dpm_table->count) {
740 pr_err("Clock level specified %d is over max allowed %d\n",
741 soft_max_level, single_dpm_table->count - 1);
746 single_dpm_table->dpm_state.soft_min_level =
747 single_dpm_table->dpm_levels[soft_min_level].value;
748 single_dpm_table->dpm_state.soft_max_level =
749 single_dpm_table->dpm_levels[soft_max_level].value;
751 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_UCLK_MASK);
753 pr_err("Failed to upload boot level to lowest!\n");
757 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_UCLK_MASK);
759 pr_err("Failed to upload dpm max level to highest!\n");
764 single_dpm_table = &(dpm_table->soc_table);
766 if (soft_max_level >= single_dpm_table->count) {
767 pr_err("Clock level specified %d is over max allowed %d\n",
768 soft_max_level, single_dpm_table->count - 1);
773 single_dpm_table->dpm_state.soft_min_level =
774 single_dpm_table->dpm_levels[soft_min_level].value;
775 single_dpm_table->dpm_state.soft_max_level =
776 single_dpm_table->dpm_levels[soft_max_level].value;
778 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_SOCCLK_MASK);
780 pr_err("Failed to upload boot level to lowest!\n");
784 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_SOCCLK_MASK);
786 pr_err("Failed to upload dpm max level to highest!\n");
791 single_dpm_table = &(dpm_table->fclk_table);
793 if (soft_max_level >= single_dpm_table->count) {
794 pr_err("Clock level specified %d is over max allowed %d\n",
795 soft_max_level, single_dpm_table->count - 1);
800 single_dpm_table->dpm_state.soft_min_level =
801 single_dpm_table->dpm_levels[soft_min_level].value;
802 single_dpm_table->dpm_state.soft_max_level =
803 single_dpm_table->dpm_levels[soft_max_level].value;
805 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_FCLK_MASK);
807 pr_err("Failed to upload boot level to lowest!\n");
811 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_FCLK_MASK);
813 pr_err("Failed to upload dpm max level to highest!\n");
821 mutex_unlock(&(smu->mutex));
825 static const struct smu_temperature_range arcturus_thermal_policy[] =
827 {-273150, 99000, 99000, -273150, 99000, 99000, -273150, 99000, 99000},
828 { 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000},
831 static int arcturus_get_thermal_temperature_range(struct smu_context *smu,
832 struct smu_temperature_range *range)
835 PPTable_t *pptable = smu->smu_table.driver_pptable;
840 memcpy(range, &arcturus_thermal_policy[0], sizeof(struct smu_temperature_range));
842 range->max = pptable->TedgeLimit *
843 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
844 range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE) *
845 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
846 range->hotspot_crit_max = pptable->ThotspotLimit *
847 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
848 range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT) *
849 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
850 range->mem_crit_max = pptable->TmemLimit *
851 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
852 range->mem_emergency_max = (pptable->TmemLimit + CTF_OFFSET_HBM)*
853 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
859 static int arcturus_get_metrics_table(struct smu_context *smu,
860 SmuMetrics_t *metrics_table)
862 struct smu_table_context *smu_table= &smu->smu_table;
865 if (!smu_table->metrics_time ||
866 time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
867 ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
868 (void *)smu_table->metrics_table, false);
870 pr_info("Failed to export SMU metrics table!\n");
873 smu_table->metrics_time = jiffies;
876 memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
881 static int arcturus_get_current_activity_percent(struct smu_context *smu,
882 enum amd_pp_sensors sensor,
885 SmuMetrics_t metrics;
891 ret = arcturus_get_metrics_table(smu, &metrics);
896 case AMDGPU_PP_SENSOR_GPU_LOAD:
897 *value = metrics.AverageGfxActivity;
899 case AMDGPU_PP_SENSOR_MEM_LOAD:
900 *value = metrics.AverageUclkActivity;
903 pr_err("Invalid sensor for retrieving clock activity\n");
910 static int arcturus_get_gpu_power(struct smu_context *smu, uint32_t *value)
912 SmuMetrics_t metrics;
918 ret = arcturus_get_metrics_table(smu, &metrics);
922 *value = metrics.AverageSocketPower << 8;
927 static int arcturus_thermal_get_temperature(struct smu_context *smu,
928 enum amd_pp_sensors sensor,
931 SmuMetrics_t metrics;
937 ret = arcturus_get_metrics_table(smu, &metrics);
942 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
943 *value = metrics.TemperatureHotspot *
944 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
946 case AMDGPU_PP_SENSOR_EDGE_TEMP:
947 *value = metrics.TemperatureEdge *
948 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
950 case AMDGPU_PP_SENSOR_MEM_TEMP:
951 *value = metrics.TemperatureHBM *
952 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
955 pr_err("Invalid sensor for retrieving temp\n");
962 static int arcturus_read_sensor(struct smu_context *smu,
963 enum amd_pp_sensors sensor,
964 void *data, uint32_t *size)
966 struct smu_table_context *table_context = &smu->smu_table;
967 PPTable_t *pptable = table_context->driver_pptable;
971 case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
972 *(uint32_t *)data = pptable->FanMaximumRpm;
975 case AMDGPU_PP_SENSOR_MEM_LOAD:
976 case AMDGPU_PP_SENSOR_GPU_LOAD:
977 ret = arcturus_get_current_activity_percent(smu,
982 case AMDGPU_PP_SENSOR_GPU_POWER:
983 ret = arcturus_get_gpu_power(smu, (uint32_t *)data);
986 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
987 case AMDGPU_PP_SENSOR_EDGE_TEMP:
988 case AMDGPU_PP_SENSOR_MEM_TEMP:
989 ret = arcturus_thermal_get_temperature(smu, sensor,
1000 static int arcturus_get_fan_speed_rpm(struct smu_context *smu,
1003 SmuMetrics_t metrics;
1009 ret = arcturus_get_metrics_table(smu, &metrics);
1013 *speed = metrics.CurrFanSpeed;
1018 static int arcturus_get_fan_speed_percent(struct smu_context *smu,
1021 PPTable_t *pptable = smu->smu_table.driver_pptable;
1022 uint32_t percent, current_rpm;
1028 ret = arcturus_get_fan_speed_rpm(smu, ¤t_rpm);
1032 percent = current_rpm * 100 / pptable->FanMaximumRpm;
1033 *speed = percent > 100 ? 100 : percent;
1038 static int arcturus_get_current_clk_freq_by_table(struct smu_context *smu,
1039 enum smu_clk_type clk_type,
1042 static SmuMetrics_t metrics;
1043 int ret = 0, clk_id = 0;
1048 clk_id = smu_clk_get_index(smu, clk_type);
1052 ret = arcturus_get_metrics_table(smu, &metrics);
1056 *value = metrics.CurrClock[clk_id];
1061 static void arcturus_dump_pptable(struct smu_context *smu)
1063 struct smu_table_context *table_context = &smu->smu_table;
1064 PPTable_t *pptable = table_context->driver_pptable;
1067 pr_info("Dumped PPTable:\n");
1069 pr_info("Version = 0x%08x\n", pptable->Version);
1071 pr_info("FeaturesToRun[0] = 0x%08x\n", pptable->FeaturesToRun[0]);
1072 pr_info("FeaturesToRun[1] = 0x%08x\n", pptable->FeaturesToRun[1]);
1074 for (i = 0; i < PPT_THROTTLER_COUNT; i++) {
1075 pr_info("SocketPowerLimitAc[%d] = %d\n", i, pptable->SocketPowerLimitAc[i]);
1076 pr_info("SocketPowerLimitAcTau[%d] = %d\n", i, pptable->SocketPowerLimitAcTau[i]);
1079 pr_info("TdcLimitSoc = %d\n", pptable->TdcLimitSoc);
1080 pr_info("TdcLimitSocTau = %d\n", pptable->TdcLimitSocTau);
1081 pr_info("TdcLimitGfx = %d\n", pptable->TdcLimitGfx);
1082 pr_info("TdcLimitGfxTau = %d\n", pptable->TdcLimitGfxTau);
1084 pr_info("TedgeLimit = %d\n", pptable->TedgeLimit);
1085 pr_info("ThotspotLimit = %d\n", pptable->ThotspotLimit);
1086 pr_info("TmemLimit = %d\n", pptable->TmemLimit);
1087 pr_info("Tvr_gfxLimit = %d\n", pptable->Tvr_gfxLimit);
1088 pr_info("Tvr_memLimit = %d\n", pptable->Tvr_memLimit);
1089 pr_info("Tvr_socLimit = %d\n", pptable->Tvr_socLimit);
1090 pr_info("FitLimit = %d\n", pptable->FitLimit);
1092 pr_info("PpmPowerLimit = %d\n", pptable->PpmPowerLimit);
1093 pr_info("PpmTemperatureThreshold = %d\n", pptable->PpmTemperatureThreshold);
1095 pr_info("ThrottlerControlMask = %d\n", pptable->ThrottlerControlMask);
1097 pr_info("UlvVoltageOffsetGfx = %d\n", pptable->UlvVoltageOffsetGfx);
1098 pr_info("UlvPadding = 0x%08x\n", pptable->UlvPadding);
1100 pr_info("UlvGfxclkBypass = %d\n", pptable->UlvGfxclkBypass);
1101 pr_info("Padding234[0] = 0x%02x\n", pptable->Padding234[0]);
1102 pr_info("Padding234[1] = 0x%02x\n", pptable->Padding234[1]);
1103 pr_info("Padding234[2] = 0x%02x\n", pptable->Padding234[2]);
1105 pr_info("MinVoltageGfx = %d\n", pptable->MinVoltageGfx);
1106 pr_info("MinVoltageSoc = %d\n", pptable->MinVoltageSoc);
1107 pr_info("MaxVoltageGfx = %d\n", pptable->MaxVoltageGfx);
1108 pr_info("MaxVoltageSoc = %d\n", pptable->MaxVoltageSoc);
1110 pr_info("LoadLineResistanceGfx = %d\n", pptable->LoadLineResistanceGfx);
1111 pr_info("LoadLineResistanceSoc = %d\n", pptable->LoadLineResistanceSoc);
1113 pr_info("[PPCLK_GFXCLK]\n"
1114 " .VoltageMode = 0x%02x\n"
1115 " .SnapToDiscrete = 0x%02x\n"
1116 " .NumDiscreteLevels = 0x%02x\n"
1117 " .padding = 0x%02x\n"
1118 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1119 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1120 " .SsFmin = 0x%04x\n"
1121 " .Padding_16 = 0x%04x\n",
1122 pptable->DpmDescriptor[PPCLK_GFXCLK].VoltageMode,
1123 pptable->DpmDescriptor[PPCLK_GFXCLK].SnapToDiscrete,
1124 pptable->DpmDescriptor[PPCLK_GFXCLK].NumDiscreteLevels,
1125 pptable->DpmDescriptor[PPCLK_GFXCLK].padding,
1126 pptable->DpmDescriptor[PPCLK_GFXCLK].ConversionToAvfsClk.m,
1127 pptable->DpmDescriptor[PPCLK_GFXCLK].ConversionToAvfsClk.b,
1128 pptable->DpmDescriptor[PPCLK_GFXCLK].SsCurve.a,
1129 pptable->DpmDescriptor[PPCLK_GFXCLK].SsCurve.b,
1130 pptable->DpmDescriptor[PPCLK_GFXCLK].SsCurve.c,
1131 pptable->DpmDescriptor[PPCLK_GFXCLK].SsFmin,
1132 pptable->DpmDescriptor[PPCLK_GFXCLK].Padding16);
1134 pr_info("[PPCLK_VCLK]\n"
1135 " .VoltageMode = 0x%02x\n"
1136 " .SnapToDiscrete = 0x%02x\n"
1137 " .NumDiscreteLevels = 0x%02x\n"
1138 " .padding = 0x%02x\n"
1139 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1140 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1141 " .SsFmin = 0x%04x\n"
1142 " .Padding_16 = 0x%04x\n",
1143 pptable->DpmDescriptor[PPCLK_VCLK].VoltageMode,
1144 pptable->DpmDescriptor[PPCLK_VCLK].SnapToDiscrete,
1145 pptable->DpmDescriptor[PPCLK_VCLK].NumDiscreteLevels,
1146 pptable->DpmDescriptor[PPCLK_VCLK].padding,
1147 pptable->DpmDescriptor[PPCLK_VCLK].ConversionToAvfsClk.m,
1148 pptable->DpmDescriptor[PPCLK_VCLK].ConversionToAvfsClk.b,
1149 pptable->DpmDescriptor[PPCLK_VCLK].SsCurve.a,
1150 pptable->DpmDescriptor[PPCLK_VCLK].SsCurve.b,
1151 pptable->DpmDescriptor[PPCLK_VCLK].SsCurve.c,
1152 pptable->DpmDescriptor[PPCLK_VCLK].SsFmin,
1153 pptable->DpmDescriptor[PPCLK_VCLK].Padding16);
1155 pr_info("[PPCLK_DCLK]\n"
1156 " .VoltageMode = 0x%02x\n"
1157 " .SnapToDiscrete = 0x%02x\n"
1158 " .NumDiscreteLevels = 0x%02x\n"
1159 " .padding = 0x%02x\n"
1160 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1161 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1162 " .SsFmin = 0x%04x\n"
1163 " .Padding_16 = 0x%04x\n",
1164 pptable->DpmDescriptor[PPCLK_DCLK].VoltageMode,
1165 pptable->DpmDescriptor[PPCLK_DCLK].SnapToDiscrete,
1166 pptable->DpmDescriptor[PPCLK_DCLK].NumDiscreteLevels,
1167 pptable->DpmDescriptor[PPCLK_DCLK].padding,
1168 pptable->DpmDescriptor[PPCLK_DCLK].ConversionToAvfsClk.m,
1169 pptable->DpmDescriptor[PPCLK_DCLK].ConversionToAvfsClk.b,
1170 pptable->DpmDescriptor[PPCLK_DCLK].SsCurve.a,
1171 pptable->DpmDescriptor[PPCLK_DCLK].SsCurve.b,
1172 pptable->DpmDescriptor[PPCLK_DCLK].SsCurve.c,
1173 pptable->DpmDescriptor[PPCLK_DCLK].SsFmin,
1174 pptable->DpmDescriptor[PPCLK_DCLK].Padding16);
1176 pr_info("[PPCLK_SOCCLK]\n"
1177 " .VoltageMode = 0x%02x\n"
1178 " .SnapToDiscrete = 0x%02x\n"
1179 " .NumDiscreteLevels = 0x%02x\n"
1180 " .padding = 0x%02x\n"
1181 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1182 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1183 " .SsFmin = 0x%04x\n"
1184 " .Padding_16 = 0x%04x\n",
1185 pptable->DpmDescriptor[PPCLK_SOCCLK].VoltageMode,
1186 pptable->DpmDescriptor[PPCLK_SOCCLK].SnapToDiscrete,
1187 pptable->DpmDescriptor[PPCLK_SOCCLK].NumDiscreteLevels,
1188 pptable->DpmDescriptor[PPCLK_SOCCLK].padding,
1189 pptable->DpmDescriptor[PPCLK_SOCCLK].ConversionToAvfsClk.m,
1190 pptable->DpmDescriptor[PPCLK_SOCCLK].ConversionToAvfsClk.b,
1191 pptable->DpmDescriptor[PPCLK_SOCCLK].SsCurve.a,
1192 pptable->DpmDescriptor[PPCLK_SOCCLK].SsCurve.b,
1193 pptable->DpmDescriptor[PPCLK_SOCCLK].SsCurve.c,
1194 pptable->DpmDescriptor[PPCLK_SOCCLK].SsFmin,
1195 pptable->DpmDescriptor[PPCLK_SOCCLK].Padding16);
1197 pr_info("[PPCLK_UCLK]\n"
1198 " .VoltageMode = 0x%02x\n"
1199 " .SnapToDiscrete = 0x%02x\n"
1200 " .NumDiscreteLevels = 0x%02x\n"
1201 " .padding = 0x%02x\n"
1202 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1203 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1204 " .SsFmin = 0x%04x\n"
1205 " .Padding_16 = 0x%04x\n",
1206 pptable->DpmDescriptor[PPCLK_UCLK].VoltageMode,
1207 pptable->DpmDescriptor[PPCLK_UCLK].SnapToDiscrete,
1208 pptable->DpmDescriptor[PPCLK_UCLK].NumDiscreteLevels,
1209 pptable->DpmDescriptor[PPCLK_UCLK].padding,
1210 pptable->DpmDescriptor[PPCLK_UCLK].ConversionToAvfsClk.m,
1211 pptable->DpmDescriptor[PPCLK_UCLK].ConversionToAvfsClk.b,
1212 pptable->DpmDescriptor[PPCLK_UCLK].SsCurve.a,
1213 pptable->DpmDescriptor[PPCLK_UCLK].SsCurve.b,
1214 pptable->DpmDescriptor[PPCLK_UCLK].SsCurve.c,
1215 pptable->DpmDescriptor[PPCLK_UCLK].SsFmin,
1216 pptable->DpmDescriptor[PPCLK_UCLK].Padding16);
1218 pr_info("[PPCLK_FCLK]\n"
1219 " .VoltageMode = 0x%02x\n"
1220 " .SnapToDiscrete = 0x%02x\n"
1221 " .NumDiscreteLevels = 0x%02x\n"
1222 " .padding = 0x%02x\n"
1223 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1224 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1225 " .SsFmin = 0x%04x\n"
1226 " .Padding_16 = 0x%04x\n",
1227 pptable->DpmDescriptor[PPCLK_FCLK].VoltageMode,
1228 pptable->DpmDescriptor[PPCLK_FCLK].SnapToDiscrete,
1229 pptable->DpmDescriptor[PPCLK_FCLK].NumDiscreteLevels,
1230 pptable->DpmDescriptor[PPCLK_FCLK].padding,
1231 pptable->DpmDescriptor[PPCLK_FCLK].ConversionToAvfsClk.m,
1232 pptable->DpmDescriptor[PPCLK_FCLK].ConversionToAvfsClk.b,
1233 pptable->DpmDescriptor[PPCLK_FCLK].SsCurve.a,
1234 pptable->DpmDescriptor[PPCLK_FCLK].SsCurve.b,
1235 pptable->DpmDescriptor[PPCLK_FCLK].SsCurve.c,
1236 pptable->DpmDescriptor[PPCLK_FCLK].SsFmin,
1237 pptable->DpmDescriptor[PPCLK_FCLK].Padding16);
1240 pr_info("FreqTableGfx\n");
1241 for (i = 0; i < NUM_GFXCLK_DPM_LEVELS; i++)
1242 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableGfx[i]);
1244 pr_info("FreqTableVclk\n");
1245 for (i = 0; i < NUM_VCLK_DPM_LEVELS; i++)
1246 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableVclk[i]);
1248 pr_info("FreqTableDclk\n");
1249 for (i = 0; i < NUM_DCLK_DPM_LEVELS; i++)
1250 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableDclk[i]);
1252 pr_info("FreqTableSocclk\n");
1253 for (i = 0; i < NUM_SOCCLK_DPM_LEVELS; i++)
1254 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableSocclk[i]);
1256 pr_info("FreqTableUclk\n");
1257 for (i = 0; i < NUM_UCLK_DPM_LEVELS; i++)
1258 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableUclk[i]);
1260 pr_info("FreqTableFclk\n");
1261 for (i = 0; i < NUM_FCLK_DPM_LEVELS; i++)
1262 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableFclk[i]);
1264 pr_info("Mp0clkFreq\n");
1265 for (i = 0; i < NUM_MP0CLK_DPM_LEVELS; i++)
1266 pr_info(" .[%d] = %d\n", i, pptable->Mp0clkFreq[i]);
1268 pr_info("Mp0DpmVoltage\n");
1269 for (i = 0; i < NUM_MP0CLK_DPM_LEVELS; i++)
1270 pr_info(" .[%d] = %d\n", i, pptable->Mp0DpmVoltage[i]);
1272 pr_info("GfxclkFidle = 0x%x\n", pptable->GfxclkFidle);
1273 pr_info("GfxclkSlewRate = 0x%x\n", pptable->GfxclkSlewRate);
1274 pr_info("Padding567[0] = 0x%x\n", pptable->Padding567[0]);
1275 pr_info("Padding567[1] = 0x%x\n", pptable->Padding567[1]);
1276 pr_info("Padding567[2] = 0x%x\n", pptable->Padding567[2]);
1277 pr_info("Padding567[3] = 0x%x\n", pptable->Padding567[3]);
1278 pr_info("GfxclkDsMaxFreq = %d\n", pptable->GfxclkDsMaxFreq);
1279 pr_info("GfxclkSource = 0x%x\n", pptable->GfxclkSource);
1280 pr_info("Padding456 = 0x%x\n", pptable->Padding456);
1282 pr_info("EnableTdpm = %d\n", pptable->EnableTdpm);
1283 pr_info("TdpmHighHystTemperature = %d\n", pptable->TdpmHighHystTemperature);
1284 pr_info("TdpmLowHystTemperature = %d\n", pptable->TdpmLowHystTemperature);
1285 pr_info("GfxclkFreqHighTempLimit = %d\n", pptable->GfxclkFreqHighTempLimit);
1287 pr_info("FanStopTemp = %d\n", pptable->FanStopTemp);
1288 pr_info("FanStartTemp = %d\n", pptable->FanStartTemp);
1290 pr_info("FanGainEdge = %d\n", pptable->FanGainEdge);
1291 pr_info("FanGainHotspot = %d\n", pptable->FanGainHotspot);
1292 pr_info("FanGainVrGfx = %d\n", pptable->FanGainVrGfx);
1293 pr_info("FanGainVrSoc = %d\n", pptable->FanGainVrSoc);
1294 pr_info("FanGainVrMem = %d\n", pptable->FanGainVrMem);
1295 pr_info("FanGainHbm = %d\n", pptable->FanGainHbm);
1297 pr_info("FanPwmMin = %d\n", pptable->FanPwmMin);
1298 pr_info("FanAcousticLimitRpm = %d\n", pptable->FanAcousticLimitRpm);
1299 pr_info("FanThrottlingRpm = %d\n", pptable->FanThrottlingRpm);
1300 pr_info("FanMaximumRpm = %d\n", pptable->FanMaximumRpm);
1301 pr_info("FanTargetTemperature = %d\n", pptable->FanTargetTemperature);
1302 pr_info("FanTargetGfxclk = %d\n", pptable->FanTargetGfxclk);
1303 pr_info("FanZeroRpmEnable = %d\n", pptable->FanZeroRpmEnable);
1304 pr_info("FanTachEdgePerRev = %d\n", pptable->FanTachEdgePerRev);
1305 pr_info("FanTempInputSelect = %d\n", pptable->FanTempInputSelect);
1307 pr_info("FuzzyFan_ErrorSetDelta = %d\n", pptable->FuzzyFan_ErrorSetDelta);
1308 pr_info("FuzzyFan_ErrorRateSetDelta = %d\n", pptable->FuzzyFan_ErrorRateSetDelta);
1309 pr_info("FuzzyFan_PwmSetDelta = %d\n", pptable->FuzzyFan_PwmSetDelta);
1310 pr_info("FuzzyFan_Reserved = %d\n", pptable->FuzzyFan_Reserved);
1312 pr_info("OverrideAvfsGb[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->OverrideAvfsGb[AVFS_VOLTAGE_GFX]);
1313 pr_info("OverrideAvfsGb[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->OverrideAvfsGb[AVFS_VOLTAGE_SOC]);
1314 pr_info("Padding8_Avfs[0] = %d\n", pptable->Padding8_Avfs[0]);
1315 pr_info("Padding8_Avfs[1] = %d\n", pptable->Padding8_Avfs[1]);
1317 pr_info("dBtcGbGfxPll{a = 0x%x b = 0x%x c = 0x%x}\n",
1318 pptable->dBtcGbGfxPll.a,
1319 pptable->dBtcGbGfxPll.b,
1320 pptable->dBtcGbGfxPll.c);
1321 pr_info("dBtcGbGfxAfll{a = 0x%x b = 0x%x c = 0x%x}\n",
1322 pptable->dBtcGbGfxAfll.a,
1323 pptable->dBtcGbGfxAfll.b,
1324 pptable->dBtcGbGfxAfll.c);
1325 pr_info("dBtcGbSoc{a = 0x%x b = 0x%x c = 0x%x}\n",
1326 pptable->dBtcGbSoc.a,
1327 pptable->dBtcGbSoc.b,
1328 pptable->dBtcGbSoc.c);
1330 pr_info("qAgingGb[AVFS_VOLTAGE_GFX]{m = 0x%x b = 0x%x}\n",
1331 pptable->qAgingGb[AVFS_VOLTAGE_GFX].m,
1332 pptable->qAgingGb[AVFS_VOLTAGE_GFX].b);
1333 pr_info("qAgingGb[AVFS_VOLTAGE_SOC]{m = 0x%x b = 0x%x}\n",
1334 pptable->qAgingGb[AVFS_VOLTAGE_SOC].m,
1335 pptable->qAgingGb[AVFS_VOLTAGE_SOC].b);
1337 pr_info("qStaticVoltageOffset[AVFS_VOLTAGE_GFX]{a = 0x%x b = 0x%x c = 0x%x}\n",
1338 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_GFX].a,
1339 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_GFX].b,
1340 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_GFX].c);
1341 pr_info("qStaticVoltageOffset[AVFS_VOLTAGE_SOC]{a = 0x%x b = 0x%x c = 0x%x}\n",
1342 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_SOC].a,
1343 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_SOC].b,
1344 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_SOC].c);
1346 pr_info("DcTol[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcTol[AVFS_VOLTAGE_GFX]);
1347 pr_info("DcTol[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcTol[AVFS_VOLTAGE_SOC]);
1349 pr_info("DcBtcEnabled[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcEnabled[AVFS_VOLTAGE_GFX]);
1350 pr_info("DcBtcEnabled[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcEnabled[AVFS_VOLTAGE_SOC]);
1351 pr_info("Padding8_GfxBtc[0] = 0x%x\n", pptable->Padding8_GfxBtc[0]);
1352 pr_info("Padding8_GfxBtc[1] = 0x%x\n", pptable->Padding8_GfxBtc[1]);
1354 pr_info("DcBtcMin[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcMin[AVFS_VOLTAGE_GFX]);
1355 pr_info("DcBtcMin[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcMin[AVFS_VOLTAGE_SOC]);
1356 pr_info("DcBtcMax[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcMax[AVFS_VOLTAGE_GFX]);
1357 pr_info("DcBtcMax[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcMax[AVFS_VOLTAGE_SOC]);
1359 pr_info("DcBtcGb[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcGb[AVFS_VOLTAGE_GFX]);
1360 pr_info("DcBtcGb[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcGb[AVFS_VOLTAGE_SOC]);
1362 pr_info("XgmiDpmPstates\n");
1363 for (i = 0; i < NUM_XGMI_LEVELS; i++)
1364 pr_info(" .[%d] = %d\n", i, pptable->XgmiDpmPstates[i]);
1365 pr_info("XgmiDpmSpare[0] = 0x%02x\n", pptable->XgmiDpmSpare[0]);
1366 pr_info("XgmiDpmSpare[1] = 0x%02x\n", pptable->XgmiDpmSpare[1]);
1368 pr_info("VDDGFX_TVmin = %d\n", pptable->VDDGFX_TVmin);
1369 pr_info("VDDSOC_TVmin = %d\n", pptable->VDDSOC_TVmin);
1370 pr_info("VDDGFX_Vmin_HiTemp = %d\n", pptable->VDDGFX_Vmin_HiTemp);
1371 pr_info("VDDGFX_Vmin_LoTemp = %d\n", pptable->VDDGFX_Vmin_LoTemp);
1372 pr_info("VDDSOC_Vmin_HiTemp = %d\n", pptable->VDDSOC_Vmin_HiTemp);
1373 pr_info("VDDSOC_Vmin_LoTemp = %d\n", pptable->VDDSOC_Vmin_LoTemp);
1374 pr_info("VDDGFX_TVminHystersis = %d\n", pptable->VDDGFX_TVminHystersis);
1375 pr_info("VDDSOC_TVminHystersis = %d\n", pptable->VDDSOC_TVminHystersis);
1377 pr_info("DebugOverrides = 0x%x\n", pptable->DebugOverrides);
1378 pr_info("ReservedEquation0{a = 0x%x b = 0x%x c = 0x%x}\n",
1379 pptable->ReservedEquation0.a,
1380 pptable->ReservedEquation0.b,
1381 pptable->ReservedEquation0.c);
1382 pr_info("ReservedEquation1{a = 0x%x b = 0x%x c = 0x%x}\n",
1383 pptable->ReservedEquation1.a,
1384 pptable->ReservedEquation1.b,
1385 pptable->ReservedEquation1.c);
1386 pr_info("ReservedEquation2{a = 0x%x b = 0x%x c = 0x%x}\n",
1387 pptable->ReservedEquation2.a,
1388 pptable->ReservedEquation2.b,
1389 pptable->ReservedEquation2.c);
1390 pr_info("ReservedEquation3{a = 0x%x b = 0x%x c = 0x%x}\n",
1391 pptable->ReservedEquation3.a,
1392 pptable->ReservedEquation3.b,
1393 pptable->ReservedEquation3.c);
1395 pr_info("MinVoltageUlvGfx = %d\n", pptable->MinVoltageUlvGfx);
1396 pr_info("PaddingUlv = %d\n", pptable->PaddingUlv);
1398 pr_info("TotalPowerConfig = %d\n", pptable->TotalPowerConfig);
1399 pr_info("TotalPowerSpare1 = %d\n", pptable->TotalPowerSpare1);
1400 pr_info("TotalPowerSpare2 = %d\n", pptable->TotalPowerSpare2);
1402 pr_info("PccThresholdLow = %d\n", pptable->PccThresholdLow);
1403 pr_info("PccThresholdHigh = %d\n", pptable->PccThresholdHigh);
1405 pr_info("Board Parameters:\n");
1406 pr_info("MaxVoltageStepGfx = 0x%x\n", pptable->MaxVoltageStepGfx);
1407 pr_info("MaxVoltageStepSoc = 0x%x\n", pptable->MaxVoltageStepSoc);
1409 pr_info("VddGfxVrMapping = 0x%x\n", pptable->VddGfxVrMapping);
1410 pr_info("VddSocVrMapping = 0x%x\n", pptable->VddSocVrMapping);
1411 pr_info("VddMemVrMapping = 0x%x\n", pptable->VddMemVrMapping);
1412 pr_info("BoardVrMapping = 0x%x\n", pptable->BoardVrMapping);
1414 pr_info("GfxUlvPhaseSheddingMask = 0x%x\n", pptable->GfxUlvPhaseSheddingMask);
1415 pr_info("ExternalSensorPresent = 0x%x\n", pptable->ExternalSensorPresent);
1417 pr_info("GfxMaxCurrent = 0x%x\n", pptable->GfxMaxCurrent);
1418 pr_info("GfxOffset = 0x%x\n", pptable->GfxOffset);
1419 pr_info("Padding_TelemetryGfx = 0x%x\n", pptable->Padding_TelemetryGfx);
1421 pr_info("SocMaxCurrent = 0x%x\n", pptable->SocMaxCurrent);
1422 pr_info("SocOffset = 0x%x\n", pptable->SocOffset);
1423 pr_info("Padding_TelemetrySoc = 0x%x\n", pptable->Padding_TelemetrySoc);
1425 pr_info("MemMaxCurrent = 0x%x\n", pptable->MemMaxCurrent);
1426 pr_info("MemOffset = 0x%x\n", pptable->MemOffset);
1427 pr_info("Padding_TelemetryMem = 0x%x\n", pptable->Padding_TelemetryMem);
1429 pr_info("BoardMaxCurrent = 0x%x\n", pptable->BoardMaxCurrent);
1430 pr_info("BoardOffset = 0x%x\n", pptable->BoardOffset);
1431 pr_info("Padding_TelemetryBoardInput = 0x%x\n", pptable->Padding_TelemetryBoardInput);
1433 pr_info("VR0HotGpio = %d\n", pptable->VR0HotGpio);
1434 pr_info("VR0HotPolarity = %d\n", pptable->VR0HotPolarity);
1435 pr_info("VR1HotGpio = %d\n", pptable->VR1HotGpio);
1436 pr_info("VR1HotPolarity = %d\n", pptable->VR1HotPolarity);
1438 pr_info("PllGfxclkSpreadEnabled = %d\n", pptable->PllGfxclkSpreadEnabled);
1439 pr_info("PllGfxclkSpreadPercent = %d\n", pptable->PllGfxclkSpreadPercent);
1440 pr_info("PllGfxclkSpreadFreq = %d\n", pptable->PllGfxclkSpreadFreq);
1442 pr_info("UclkSpreadEnabled = %d\n", pptable->UclkSpreadEnabled);
1443 pr_info("UclkSpreadPercent = %d\n", pptable->UclkSpreadPercent);
1444 pr_info("UclkSpreadFreq = %d\n", pptable->UclkSpreadFreq);
1446 pr_info("FclkSpreadEnabled = %d\n", pptable->FclkSpreadEnabled);
1447 pr_info("FclkSpreadPercent = %d\n", pptable->FclkSpreadPercent);
1448 pr_info("FclkSpreadFreq = %d\n", pptable->FclkSpreadFreq);
1450 pr_info("FllGfxclkSpreadEnabled = %d\n", pptable->FllGfxclkSpreadEnabled);
1451 pr_info("FllGfxclkSpreadPercent = %d\n", pptable->FllGfxclkSpreadPercent);
1452 pr_info("FllGfxclkSpreadFreq = %d\n", pptable->FllGfxclkSpreadFreq);
1454 for (i = 0; i < NUM_I2C_CONTROLLERS; i++) {
1455 pr_info("I2cControllers[%d]:\n", i);
1456 pr_info(" .Enabled = %d\n",
1457 pptable->I2cControllers[i].Enabled);
1458 pr_info(" .SlaveAddress = 0x%x\n",
1459 pptable->I2cControllers[i].SlaveAddress);
1460 pr_info(" .ControllerPort = %d\n",
1461 pptable->I2cControllers[i].ControllerPort);
1462 pr_info(" .ControllerName = %d\n",
1463 pptable->I2cControllers[i].ControllerName);
1464 pr_info(" .ThermalThrottler = %d\n",
1465 pptable->I2cControllers[i].ThermalThrotter);
1466 pr_info(" .I2cProtocol = %d\n",
1467 pptable->I2cControllers[i].I2cProtocol);
1468 pr_info(" .Speed = %d\n",
1469 pptable->I2cControllers[i].Speed);
1472 pr_info("MemoryChannelEnabled = %d\n", pptable->MemoryChannelEnabled);
1473 pr_info("DramBitWidth = %d\n", pptable->DramBitWidth);
1475 pr_info("TotalBoardPower = %d\n", pptable->TotalBoardPower);
1477 pr_info("XgmiLinkSpeed\n");
1478 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
1479 pr_info(" .[%d] = %d\n", i, pptable->XgmiLinkSpeed[i]);
1480 pr_info("XgmiLinkWidth\n");
1481 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
1482 pr_info(" .[%d] = %d\n", i, pptable->XgmiLinkWidth[i]);
1483 pr_info("XgmiFclkFreq\n");
1484 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
1485 pr_info(" .[%d] = %d\n", i, pptable->XgmiFclkFreq[i]);
1486 pr_info("XgmiSocVoltage\n");
1487 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
1488 pr_info(" .[%d] = %d\n", i, pptable->XgmiSocVoltage[i]);
1492 static const struct pptable_funcs arcturus_ppt_funcs = {
1493 /* translate smu index into arcturus specific index */
1494 .get_smu_msg_index = arcturus_get_smu_msg_index,
1495 .get_smu_clk_index = arcturus_get_smu_clk_index,
1496 .get_smu_feature_index = arcturus_get_smu_feature_index,
1497 .get_smu_table_index = arcturus_get_smu_table_index,
1498 .get_smu_power_index= arcturus_get_pwr_src_index,
1499 .get_workload_type = arcturus_get_workload_type,
1500 /* internal structurs allocations */
1501 .tables_init = arcturus_tables_init,
1502 .alloc_dpm_context = arcturus_allocate_dpm_context,
1503 /* pptable related */
1504 .check_powerplay_table = arcturus_check_powerplay_table,
1505 .store_powerplay_table = arcturus_store_powerplay_table,
1506 .append_powerplay_table = arcturus_append_powerplay_table,
1508 .get_allowed_feature_mask = arcturus_get_allowed_feature_mask,
1510 .run_afll_btc = arcturus_run_btc_afll,
1511 /* dpm/clk tables */
1512 .set_default_dpm_table = arcturus_set_default_dpm_table,
1513 .populate_umd_state_clk = arcturus_populate_umd_state_clk,
1514 .get_thermal_temperature_range = arcturus_get_thermal_temperature_range,
1515 .get_current_clk_freq_by_table = arcturus_get_current_clk_freq_by_table,
1516 .print_clk_levels = arcturus_print_clk_levels,
1517 .force_clk_levels = arcturus_force_clk_levels,
1518 .read_sensor = arcturus_read_sensor,
1519 .get_fan_speed_percent = arcturus_get_fan_speed_percent,
1520 .get_fan_speed_rpm = arcturus_get_fan_speed_rpm,
1521 /* debug (internal used) */
1522 .dump_pptable = arcturus_dump_pptable,
1525 void arcturus_set_ppt_funcs(struct smu_context *smu)
1527 struct smu_table_context *smu_table = &smu->smu_table;
1529 smu->ppt_funcs = &arcturus_ppt_funcs;
1530 smu->smc_if_version = SMU11_DRIVER_IF_VERSION;
1531 smu_table->table_count = TABLE_COUNT;