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.
24 #include <linux/firmware.h>
26 #include "amdgpu_smu.h"
27 #include "smu_internal.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_offset.h"
39 #include "nbio/nbio_7_4_sh_mask.h"
40 #include "amdgpu_xgmi.h"
41 #include <linux/i2c.h>
42 #include <linux/pci.h>
43 #include "amdgpu_ras.h"
45 #define to_amdgpu_device(x) (container_of(x, struct amdgpu_device, pm.smu_i2c))
47 #define CTF_OFFSET_EDGE 5
48 #define CTF_OFFSET_HOTSPOT 5
49 #define CTF_OFFSET_HBM 5
51 #define MSG_MAP(msg, index, valid_in_vf) \
52 [SMU_MSG_##msg] = {1, (index), (valid_in_vf)}
53 #define ARCTURUS_FEA_MAP(smu_feature, arcturus_feature) \
54 [smu_feature] = {1, (arcturus_feature)}
56 #define SMU_FEATURES_LOW_MASK 0x00000000FFFFFFFF
57 #define SMU_FEATURES_LOW_SHIFT 0
58 #define SMU_FEATURES_HIGH_MASK 0xFFFFFFFF00000000
59 #define SMU_FEATURES_HIGH_SHIFT 32
61 #define SMC_DPM_FEATURE ( \
62 FEATURE_DPM_PREFETCHER_MASK | \
63 FEATURE_DPM_GFXCLK_MASK | \
64 FEATURE_DPM_UCLK_MASK | \
65 FEATURE_DPM_SOCCLK_MASK | \
66 FEATURE_DPM_MP0CLK_MASK | \
67 FEATURE_DPM_FCLK_MASK | \
68 FEATURE_DPM_XGMI_MASK)
70 /* possible frequency drift (1Mhz) */
73 static struct smu_11_0_msg_mapping arcturus_message_map[SMU_MSG_MAX_COUNT] = {
74 MSG_MAP(TestMessage, PPSMC_MSG_TestMessage, 0),
75 MSG_MAP(GetSmuVersion, PPSMC_MSG_GetSmuVersion, 1),
76 MSG_MAP(GetDriverIfVersion, PPSMC_MSG_GetDriverIfVersion, 1),
77 MSG_MAP(SetAllowedFeaturesMaskLow, PPSMC_MSG_SetAllowedFeaturesMaskLow, 0),
78 MSG_MAP(SetAllowedFeaturesMaskHigh, PPSMC_MSG_SetAllowedFeaturesMaskHigh, 0),
79 MSG_MAP(EnableAllSmuFeatures, PPSMC_MSG_EnableAllSmuFeatures, 0),
80 MSG_MAP(DisableAllSmuFeatures, PPSMC_MSG_DisableAllSmuFeatures, 0),
81 MSG_MAP(EnableSmuFeaturesLow, PPSMC_MSG_EnableSmuFeaturesLow, 1),
82 MSG_MAP(EnableSmuFeaturesHigh, PPSMC_MSG_EnableSmuFeaturesHigh, 1),
83 MSG_MAP(DisableSmuFeaturesLow, PPSMC_MSG_DisableSmuFeaturesLow, 0),
84 MSG_MAP(DisableSmuFeaturesHigh, PPSMC_MSG_DisableSmuFeaturesHigh, 0),
85 MSG_MAP(GetEnabledSmuFeaturesLow, PPSMC_MSG_GetEnabledSmuFeaturesLow, 0),
86 MSG_MAP(GetEnabledSmuFeaturesHigh, PPSMC_MSG_GetEnabledSmuFeaturesHigh, 0),
87 MSG_MAP(SetDriverDramAddrHigh, PPSMC_MSG_SetDriverDramAddrHigh, 1),
88 MSG_MAP(SetDriverDramAddrLow, PPSMC_MSG_SetDriverDramAddrLow, 1),
89 MSG_MAP(SetToolsDramAddrHigh, PPSMC_MSG_SetToolsDramAddrHigh, 0),
90 MSG_MAP(SetToolsDramAddrLow, PPSMC_MSG_SetToolsDramAddrLow, 0),
91 MSG_MAP(TransferTableSmu2Dram, PPSMC_MSG_TransferTableSmu2Dram, 1),
92 MSG_MAP(TransferTableDram2Smu, PPSMC_MSG_TransferTableDram2Smu, 0),
93 MSG_MAP(UseDefaultPPTable, PPSMC_MSG_UseDefaultPPTable, 0),
94 MSG_MAP(UseBackupPPTable, PPSMC_MSG_UseBackupPPTable, 0),
95 MSG_MAP(SetSystemVirtualDramAddrHigh, PPSMC_MSG_SetSystemVirtualDramAddrHigh, 0),
96 MSG_MAP(SetSystemVirtualDramAddrLow, PPSMC_MSG_SetSystemVirtualDramAddrLow, 0),
97 MSG_MAP(EnterBaco, PPSMC_MSG_EnterBaco, 0),
98 MSG_MAP(ExitBaco, PPSMC_MSG_ExitBaco, 0),
99 MSG_MAP(ArmD3, PPSMC_MSG_ArmD3, 0),
100 MSG_MAP(SetSoftMinByFreq, PPSMC_MSG_SetSoftMinByFreq, 0),
101 MSG_MAP(SetSoftMaxByFreq, PPSMC_MSG_SetSoftMaxByFreq, 0),
102 MSG_MAP(SetHardMinByFreq, PPSMC_MSG_SetHardMinByFreq, 0),
103 MSG_MAP(SetHardMaxByFreq, PPSMC_MSG_SetHardMaxByFreq, 0),
104 MSG_MAP(GetMinDpmFreq, PPSMC_MSG_GetMinDpmFreq, 0),
105 MSG_MAP(GetMaxDpmFreq, PPSMC_MSG_GetMaxDpmFreq, 0),
106 MSG_MAP(GetDpmFreqByIndex, PPSMC_MSG_GetDpmFreqByIndex, 1),
107 MSG_MAP(SetWorkloadMask, PPSMC_MSG_SetWorkloadMask, 1),
108 MSG_MAP(SetDfSwitchType, PPSMC_MSG_SetDfSwitchType, 0),
109 MSG_MAP(GetVoltageByDpm, PPSMC_MSG_GetVoltageByDpm, 0),
110 MSG_MAP(GetVoltageByDpmOverdrive, PPSMC_MSG_GetVoltageByDpmOverdrive, 0),
111 MSG_MAP(SetPptLimit, PPSMC_MSG_SetPptLimit, 0),
112 MSG_MAP(GetPptLimit, PPSMC_MSG_GetPptLimit, 1),
113 MSG_MAP(PowerUpVcn0, PPSMC_MSG_PowerUpVcn0, 0),
114 MSG_MAP(PowerDownVcn0, PPSMC_MSG_PowerDownVcn0, 0),
115 MSG_MAP(PowerUpVcn1, PPSMC_MSG_PowerUpVcn1, 0),
116 MSG_MAP(PowerDownVcn1, PPSMC_MSG_PowerDownVcn1, 0),
117 MSG_MAP(PrepareMp1ForUnload, PPSMC_MSG_PrepareMp1ForUnload, 0),
118 MSG_MAP(PrepareMp1ForReset, PPSMC_MSG_PrepareMp1ForReset, 0),
119 MSG_MAP(PrepareMp1ForShutdown, PPSMC_MSG_PrepareMp1ForShutdown, 0),
120 MSG_MAP(SoftReset, PPSMC_MSG_SoftReset, 0),
121 MSG_MAP(RunAfllBtc, PPSMC_MSG_RunAfllBtc, 0),
122 MSG_MAP(RunDcBtc, PPSMC_MSG_RunDcBtc, 0),
123 MSG_MAP(DramLogSetDramAddrHigh, PPSMC_MSG_DramLogSetDramAddrHigh, 0),
124 MSG_MAP(DramLogSetDramAddrLow, PPSMC_MSG_DramLogSetDramAddrLow, 0),
125 MSG_MAP(DramLogSetDramSize, PPSMC_MSG_DramLogSetDramSize, 0),
126 MSG_MAP(GetDebugData, PPSMC_MSG_GetDebugData, 0),
127 MSG_MAP(WaflTest, PPSMC_MSG_WaflTest, 0),
128 MSG_MAP(SetXgmiMode, PPSMC_MSG_SetXgmiMode, 0),
129 MSG_MAP(SetMemoryChannelEnable, PPSMC_MSG_SetMemoryChannelEnable, 0),
130 MSG_MAP(DFCstateControl, PPSMC_MSG_DFCstateControl, 0),
131 MSG_MAP(GmiPwrDnControl, PPSMC_MSG_GmiPwrDnControl, 0),
132 MSG_MAP(ReadSerialNumTop32, PPSMC_MSG_ReadSerialNumTop32, 1),
133 MSG_MAP(ReadSerialNumBottom32, PPSMC_MSG_ReadSerialNumBottom32, 1),
136 static struct smu_11_0_cmn2aisc_mapping arcturus_clk_map[SMU_CLK_COUNT] = {
137 CLK_MAP(GFXCLK, PPCLK_GFXCLK),
138 CLK_MAP(SCLK, PPCLK_GFXCLK),
139 CLK_MAP(SOCCLK, PPCLK_SOCCLK),
140 CLK_MAP(FCLK, PPCLK_FCLK),
141 CLK_MAP(UCLK, PPCLK_UCLK),
142 CLK_MAP(MCLK, PPCLK_UCLK),
143 CLK_MAP(DCLK, PPCLK_DCLK),
144 CLK_MAP(VCLK, PPCLK_VCLK),
147 static struct smu_11_0_cmn2aisc_mapping arcturus_feature_mask_map[SMU_FEATURE_COUNT] = {
148 FEA_MAP(DPM_PREFETCHER),
154 ARCTURUS_FEA_MAP(SMU_FEATURE_XGMI_BIT, FEATURE_DPM_XGMI_BIT),
161 ARCTURUS_FEA_MAP(SMU_FEATURE_VCN_PG_BIT, FEATURE_DPM_VCN_BIT),
162 FEA_MAP(RSMU_SMN_CG),
170 FEA_MAP(FAN_CONTROL),
172 FEA_MAP(OUT_OF_BAND_MONITOR),
173 FEA_MAP(TEMP_DEPENDENT_VMIN),
176 static struct smu_11_0_cmn2aisc_mapping arcturus_table_map[SMU_TABLE_COUNT] = {
179 TAB_MAP(AVFS_PSM_DEBUG),
180 TAB_MAP(AVFS_FUSE_OVERRIDE),
181 TAB_MAP(PMSTATUSLOG),
182 TAB_MAP(SMU_METRICS),
183 TAB_MAP(DRIVER_SMU_CONFIG),
185 TAB_MAP(I2C_COMMANDS),
186 TAB_MAP(ACTIVITY_MONITOR_COEFF),
189 static struct smu_11_0_cmn2aisc_mapping arcturus_pwr_src_map[SMU_POWER_SOURCE_COUNT] = {
194 static struct smu_11_0_cmn2aisc_mapping arcturus_workload_map[PP_SMC_POWER_PROFILE_COUNT] = {
195 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT, WORKLOAD_PPLIB_DEFAULT_BIT),
196 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_POWERSAVING, WORKLOAD_PPLIB_POWER_SAVING_BIT),
197 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VIDEO, WORKLOAD_PPLIB_VIDEO_BIT),
198 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_COMPUTE, WORKLOAD_PPLIB_COMPUTE_BIT),
199 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM, WORKLOAD_PPLIB_CUSTOM_BIT),
202 static int arcturus_get_smu_msg_index(struct smu_context *smc, uint32_t index)
204 struct smu_11_0_msg_mapping mapping;
206 if (index >= SMU_MSG_MAX_COUNT)
209 mapping = arcturus_message_map[index];
210 if (!(mapping.valid_mapping))
213 if (amdgpu_sriov_vf(smc->adev) && !mapping.valid_in_vf)
216 return mapping.map_to;
219 static int arcturus_get_smu_clk_index(struct smu_context *smc, uint32_t index)
221 struct smu_11_0_cmn2aisc_mapping mapping;
223 if (index >= SMU_CLK_COUNT)
226 mapping = arcturus_clk_map[index];
227 if (!(mapping.valid_mapping)) {
228 pr_warn("Unsupported SMU clk: %d\n", index);
232 return mapping.map_to;
235 static int arcturus_get_smu_feature_index(struct smu_context *smc, uint32_t index)
237 struct smu_11_0_cmn2aisc_mapping mapping;
239 if (index >= SMU_FEATURE_COUNT)
242 mapping = arcturus_feature_mask_map[index];
243 if (!(mapping.valid_mapping)) {
247 return mapping.map_to;
250 static int arcturus_get_smu_table_index(struct smu_context *smc, uint32_t index)
252 struct smu_11_0_cmn2aisc_mapping mapping;
254 if (index >= SMU_TABLE_COUNT)
257 mapping = arcturus_table_map[index];
258 if (!(mapping.valid_mapping)) {
259 pr_warn("Unsupported SMU table: %d\n", index);
263 return mapping.map_to;
266 static int arcturus_get_pwr_src_index(struct smu_context *smc, uint32_t index)
268 struct smu_11_0_cmn2aisc_mapping mapping;
270 if (index >= SMU_POWER_SOURCE_COUNT)
273 mapping = arcturus_pwr_src_map[index];
274 if (!(mapping.valid_mapping)) {
275 pr_warn("Unsupported SMU power source: %d\n", index);
279 return mapping.map_to;
283 static int arcturus_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER_PROFILE profile)
285 struct smu_11_0_cmn2aisc_mapping mapping;
287 if (profile > PP_SMC_POWER_PROFILE_CUSTOM)
290 mapping = arcturus_workload_map[profile];
291 if (!(mapping.valid_mapping))
294 return mapping.map_to;
297 static int arcturus_tables_init(struct smu_context *smu, struct smu_table *tables)
299 struct smu_table_context *smu_table = &smu->smu_table;
301 SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t),
302 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
304 SMU_TABLE_INIT(tables, SMU_TABLE_PMSTATUSLOG, SMU11_TOOL_SIZE,
305 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
307 SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
308 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
310 SMU_TABLE_INIT(tables, SMU_TABLE_I2C_COMMANDS, sizeof(SwI2cRequest_t),
311 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
313 SMU_TABLE_INIT(tables, SMU_TABLE_ACTIVITY_MONITOR_COEFF,
314 sizeof(DpmActivityMonitorCoeffInt_t), PAGE_SIZE,
315 AMDGPU_GEM_DOMAIN_VRAM);
317 smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
318 if (!smu_table->metrics_table)
320 smu_table->metrics_time = 0;
325 static int arcturus_allocate_dpm_context(struct smu_context *smu)
327 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
329 if (smu_dpm->dpm_context)
332 smu_dpm->dpm_context = kzalloc(sizeof(struct arcturus_dpm_table),
334 if (!smu_dpm->dpm_context)
337 if (smu_dpm->golden_dpm_context)
340 smu_dpm->golden_dpm_context = kzalloc(sizeof(struct arcturus_dpm_table),
342 if (!smu_dpm->golden_dpm_context)
345 smu_dpm->dpm_context_size = sizeof(struct arcturus_dpm_table);
347 smu_dpm->dpm_current_power_state = kzalloc(sizeof(struct smu_power_state),
349 if (!smu_dpm->dpm_current_power_state)
352 smu_dpm->dpm_request_power_state = kzalloc(sizeof(struct smu_power_state),
354 if (!smu_dpm->dpm_request_power_state)
361 arcturus_get_allowed_feature_mask(struct smu_context *smu,
362 uint32_t *feature_mask, uint32_t num)
367 /* pptable will handle the features to enable */
368 memset(feature_mask, 0xFF, sizeof(uint32_t) * num);
374 arcturus_set_single_dpm_table(struct smu_context *smu,
375 struct arcturus_single_dpm_table *single_dpm_table,
379 uint32_t i, num_of_levels = 0, clk;
381 ret = smu_send_smc_msg_with_param(smu,
382 SMU_MSG_GetDpmFreqByIndex,
383 (clk_id << 16 | 0xFF),
386 pr_err("[%s] failed to get dpm levels!\n", __func__);
390 single_dpm_table->count = num_of_levels;
391 for (i = 0; i < num_of_levels; i++) {
392 ret = smu_send_smc_msg_with_param(smu,
393 SMU_MSG_GetDpmFreqByIndex,
397 pr_err("[%s] failed to get dpm freq by index!\n", __func__);
400 single_dpm_table->dpm_levels[i].value = clk;
401 single_dpm_table->dpm_levels[i].enabled = true;
406 static void arcturus_init_single_dpm_state(struct arcturus_dpm_state *dpm_state)
408 dpm_state->soft_min_level = 0x0;
409 dpm_state->soft_max_level = 0xffff;
410 dpm_state->hard_min_level = 0x0;
411 dpm_state->hard_max_level = 0xffff;
414 static int arcturus_set_default_dpm_table(struct smu_context *smu)
418 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
419 struct arcturus_dpm_table *dpm_table = NULL;
420 struct arcturus_single_dpm_table *single_dpm_table;
422 dpm_table = smu_dpm->dpm_context;
425 single_dpm_table = &(dpm_table->soc_table);
426 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
427 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
430 pr_err("[%s] failed to get socclk dpm levels!\n", __func__);
434 single_dpm_table->count = 1;
435 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.socclk / 100;
437 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
440 single_dpm_table = &(dpm_table->gfx_table);
441 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT)) {
442 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
445 pr_err("[SetupDefaultDpmTable] failed to get gfxclk dpm levels!");
449 single_dpm_table->count = 1;
450 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.gfxclk / 100;
452 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
455 single_dpm_table = &(dpm_table->mem_table);
456 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT)) {
457 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
460 pr_err("[SetupDefaultDpmTable] failed to get memclk dpm levels!");
464 single_dpm_table->count = 1;
465 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.uclk / 100;
467 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
470 single_dpm_table = &(dpm_table->fclk_table);
471 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_FCLK_BIT)) {
472 ret = arcturus_set_single_dpm_table(smu, single_dpm_table,
475 pr_err("[SetupDefaultDpmTable] failed to get fclk dpm levels!");
479 single_dpm_table->count = 1;
480 single_dpm_table->dpm_levels[0].value = smu->smu_table.boot_values.fclk / 100;
482 arcturus_init_single_dpm_state(&(single_dpm_table->dpm_state));
484 memcpy(smu_dpm->golden_dpm_context, dpm_table,
485 sizeof(struct arcturus_dpm_table));
490 static int arcturus_check_powerplay_table(struct smu_context *smu)
492 struct smu_table_context *table_context = &smu->smu_table;
493 struct smu_11_0_powerplay_table *powerplay_table =
494 table_context->power_play_table;
495 struct smu_baco_context *smu_baco = &smu->smu_baco;
497 mutex_lock(&smu_baco->mutex);
498 if (powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_BACO ||
499 powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_MACO)
500 smu_baco->platform_support = true;
501 mutex_unlock(&smu_baco->mutex);
503 table_context->thermal_controller_type =
504 powerplay_table->thermal_controller_type;
509 static int arcturus_store_powerplay_table(struct smu_context *smu)
511 struct smu_table_context *table_context = &smu->smu_table;
512 struct smu_11_0_powerplay_table *powerplay_table =
513 table_context->power_play_table;
515 memcpy(table_context->driver_pptable, &powerplay_table->smc_pptable,
521 static int arcturus_append_powerplay_table(struct smu_context *smu)
523 struct smu_table_context *table_context = &smu->smu_table;
524 PPTable_t *smc_pptable = table_context->driver_pptable;
525 struct atom_smc_dpm_info_v4_6 *smc_dpm_table;
528 index = get_index_into_master_table(atom_master_list_of_data_tables_v2_1,
531 ret = smu_get_atom_data_table(smu, index, NULL, NULL, NULL,
532 (uint8_t **)&smc_dpm_table);
536 pr_info("smc_dpm_info table revision(format.content): %d.%d\n",
537 smc_dpm_table->table_header.format_revision,
538 smc_dpm_table->table_header.content_revision);
540 if ((smc_dpm_table->table_header.format_revision == 4) &&
541 (smc_dpm_table->table_header.content_revision == 6))
542 memcpy(&smc_pptable->MaxVoltageStepGfx,
543 &smc_dpm_table->maxvoltagestepgfx,
544 sizeof(*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_6, maxvoltagestepgfx));
549 static int arcturus_setup_pptable(struct smu_context *smu)
553 ret = smu_v11_0_setup_pptable(smu);
557 ret = arcturus_store_powerplay_table(smu);
561 ret = arcturus_append_powerplay_table(smu);
565 ret = arcturus_check_powerplay_table(smu);
572 static int arcturus_run_btc(struct smu_context *smu)
576 ret = smu_send_smc_msg(smu, SMU_MSG_RunAfllBtc, NULL);
578 pr_err("RunAfllBtc failed!\n");
582 return smu_send_smc_msg(smu, SMU_MSG_RunDcBtc, NULL);
585 static int arcturus_populate_umd_state_clk(struct smu_context *smu)
587 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
588 struct arcturus_dpm_table *dpm_table = NULL;
589 struct arcturus_single_dpm_table *gfx_table = NULL;
590 struct arcturus_single_dpm_table *mem_table = NULL;
592 dpm_table = smu_dpm->dpm_context;
593 gfx_table = &(dpm_table->gfx_table);
594 mem_table = &(dpm_table->mem_table);
596 smu->pstate_sclk = gfx_table->dpm_levels[0].value;
597 smu->pstate_mclk = mem_table->dpm_levels[0].value;
599 if (gfx_table->count > ARCTURUS_UMD_PSTATE_GFXCLK_LEVEL &&
600 mem_table->count > ARCTURUS_UMD_PSTATE_MCLK_LEVEL) {
601 smu->pstate_sclk = gfx_table->dpm_levels[ARCTURUS_UMD_PSTATE_GFXCLK_LEVEL].value;
602 smu->pstate_mclk = mem_table->dpm_levels[ARCTURUS_UMD_PSTATE_MCLK_LEVEL].value;
605 smu->pstate_sclk = smu->pstate_sclk * 100;
606 smu->pstate_mclk = smu->pstate_mclk * 100;
611 static int arcturus_get_clk_table(struct smu_context *smu,
612 struct pp_clock_levels_with_latency *clocks,
613 struct arcturus_single_dpm_table *dpm_table)
617 count = (dpm_table->count > MAX_NUM_CLOCKS) ? MAX_NUM_CLOCKS : dpm_table->count;
618 clocks->num_levels = count;
620 for (i = 0; i < count; i++) {
621 clocks->data[i].clocks_in_khz =
622 dpm_table->dpm_levels[i].value * 1000;
623 clocks->data[i].latency_in_us = 0;
629 static int arcturus_freqs_in_same_level(int32_t frequency1,
632 return (abs(frequency1 - frequency2) <= EPSILON);
635 static int arcturus_print_clk_levels(struct smu_context *smu,
636 enum smu_clk_type type, char *buf)
638 int i, now, size = 0;
640 struct pp_clock_levels_with_latency clocks;
641 struct arcturus_single_dpm_table *single_dpm_table;
642 struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
643 struct arcturus_dpm_table *dpm_table = NULL;
645 if (amdgpu_ras_intr_triggered())
646 return snprintf(buf, PAGE_SIZE, "unavailable\n");
648 dpm_table = smu_dpm->dpm_context;
652 ret = smu_get_current_clk_freq(smu, SMU_GFXCLK, &now);
654 pr_err("Attempt to get current gfx clk Failed!");
658 single_dpm_table = &(dpm_table->gfx_table);
659 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
661 pr_err("Attempt to get gfx clk levels Failed!");
666 * For DPM disabled case, there will be only one clock level.
667 * And it's safe to assume that is always the current clock.
669 for (i = 0; i < clocks.num_levels; i++)
670 size += sprintf(buf + size, "%d: %uMhz %s\n", i,
671 clocks.data[i].clocks_in_khz / 1000,
672 (clocks.num_levels == 1) ? "*" :
673 (arcturus_freqs_in_same_level(
674 clocks.data[i].clocks_in_khz / 1000,
675 now / 100) ? "*" : ""));
679 ret = smu_get_current_clk_freq(smu, SMU_UCLK, &now);
681 pr_err("Attempt to get current mclk Failed!");
685 single_dpm_table = &(dpm_table->mem_table);
686 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
688 pr_err("Attempt to get memory clk levels Failed!");
692 for (i = 0; i < clocks.num_levels; i++)
693 size += sprintf(buf + size, "%d: %uMhz %s\n",
694 i, clocks.data[i].clocks_in_khz / 1000,
695 (clocks.num_levels == 1) ? "*" :
696 (arcturus_freqs_in_same_level(
697 clocks.data[i].clocks_in_khz / 1000,
698 now / 100) ? "*" : ""));
702 ret = smu_get_current_clk_freq(smu, SMU_SOCCLK, &now);
704 pr_err("Attempt to get current socclk Failed!");
708 single_dpm_table = &(dpm_table->soc_table);
709 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
711 pr_err("Attempt to get socclk levels Failed!");
715 for (i = 0; i < clocks.num_levels; i++)
716 size += sprintf(buf + size, "%d: %uMhz %s\n",
717 i, clocks.data[i].clocks_in_khz / 1000,
718 (clocks.num_levels == 1) ? "*" :
719 (arcturus_freqs_in_same_level(
720 clocks.data[i].clocks_in_khz / 1000,
721 now / 100) ? "*" : ""));
725 ret = smu_get_current_clk_freq(smu, SMU_FCLK, &now);
727 pr_err("Attempt to get current fclk Failed!");
731 single_dpm_table = &(dpm_table->fclk_table);
732 ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
734 pr_err("Attempt to get fclk levels Failed!");
738 for (i = 0; i < single_dpm_table->count; i++)
739 size += sprintf(buf + size, "%d: %uMhz %s\n",
740 i, single_dpm_table->dpm_levels[i].value,
741 (clocks.num_levels == 1) ? "*" :
742 (arcturus_freqs_in_same_level(
743 clocks.data[i].clocks_in_khz / 1000,
744 now / 100) ? "*" : ""));
754 static int arcturus_upload_dpm_level(struct smu_context *smu, bool max,
755 uint32_t feature_mask)
757 struct arcturus_single_dpm_table *single_dpm_table;
758 struct arcturus_dpm_table *dpm_table =
759 smu->smu_dpm.dpm_context;
763 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT) &&
764 (feature_mask & FEATURE_DPM_GFXCLK_MASK)) {
765 single_dpm_table = &(dpm_table->gfx_table);
766 freq = max ? single_dpm_table->dpm_state.soft_max_level :
767 single_dpm_table->dpm_state.soft_min_level;
768 ret = smu_send_smc_msg_with_param(smu,
769 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
770 (PPCLK_GFXCLK << 16) | (freq & 0xffff),
773 pr_err("Failed to set soft %s gfxclk !\n",
774 max ? "max" : "min");
779 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT) &&
780 (feature_mask & FEATURE_DPM_UCLK_MASK)) {
781 single_dpm_table = &(dpm_table->mem_table);
782 freq = max ? single_dpm_table->dpm_state.soft_max_level :
783 single_dpm_table->dpm_state.soft_min_level;
784 ret = smu_send_smc_msg_with_param(smu,
785 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
786 (PPCLK_UCLK << 16) | (freq & 0xffff),
789 pr_err("Failed to set soft %s memclk !\n",
790 max ? "max" : "min");
795 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT) &&
796 (feature_mask & FEATURE_DPM_SOCCLK_MASK)) {
797 single_dpm_table = &(dpm_table->soc_table);
798 freq = max ? single_dpm_table->dpm_state.soft_max_level :
799 single_dpm_table->dpm_state.soft_min_level;
800 ret = smu_send_smc_msg_with_param(smu,
801 (max ? SMU_MSG_SetSoftMaxByFreq : SMU_MSG_SetSoftMinByFreq),
802 (PPCLK_SOCCLK << 16) | (freq & 0xffff),
805 pr_err("Failed to set soft %s socclk !\n",
806 max ? "max" : "min");
814 static int arcturus_force_clk_levels(struct smu_context *smu,
815 enum smu_clk_type type, uint32_t mask)
817 struct arcturus_dpm_table *dpm_table;
818 struct arcturus_single_dpm_table *single_dpm_table;
819 uint32_t soft_min_level, soft_max_level;
820 uint32_t smu_version;
823 ret = smu_get_smc_version(smu, NULL, &smu_version);
825 pr_err("Failed to get smu version!\n");
829 if (smu_version >= 0x361200) {
830 pr_err("Forcing clock level is not supported with "
831 "54.18 and onwards SMU firmwares\n");
835 soft_min_level = mask ? (ffs(mask) - 1) : 0;
836 soft_max_level = mask ? (fls(mask) - 1) : 0;
838 dpm_table = smu->smu_dpm.dpm_context;
842 single_dpm_table = &(dpm_table->gfx_table);
844 if (soft_max_level >= single_dpm_table->count) {
845 pr_err("Clock level specified %d is over max allowed %d\n",
846 soft_max_level, single_dpm_table->count - 1);
851 single_dpm_table->dpm_state.soft_min_level =
852 single_dpm_table->dpm_levels[soft_min_level].value;
853 single_dpm_table->dpm_state.soft_max_level =
854 single_dpm_table->dpm_levels[soft_max_level].value;
856 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
858 pr_err("Failed to upload boot level to lowest!\n");
862 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
864 pr_err("Failed to upload dpm max level to highest!\n");
872 * Should not arrive here since Arcturus does not
873 * support mclk/socclk/fclk softmin/softmax settings
885 static int arcturus_get_thermal_temperature_range(struct smu_context *smu,
886 struct smu_temperature_range *range)
888 PPTable_t *pptable = smu->smu_table.driver_pptable;
893 range->max = pptable->TedgeLimit *
894 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
895 range->edge_emergency_max = (pptable->TedgeLimit + CTF_OFFSET_EDGE) *
896 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
897 range->hotspot_crit_max = pptable->ThotspotLimit *
898 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
899 range->hotspot_emergency_max = (pptable->ThotspotLimit + CTF_OFFSET_HOTSPOT) *
900 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
901 range->mem_crit_max = pptable->TmemLimit *
902 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
903 range->mem_emergency_max = (pptable->TmemLimit + CTF_OFFSET_HBM)*
904 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
909 static int arcturus_get_metrics_table(struct smu_context *smu,
910 SmuMetrics_t *metrics_table)
912 struct smu_table_context *smu_table= &smu->smu_table;
915 mutex_lock(&smu->metrics_lock);
916 if (!smu_table->metrics_time ||
917 time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
918 ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
919 (void *)smu_table->metrics_table, false);
921 pr_info("Failed to export SMU metrics table!\n");
922 mutex_unlock(&smu->metrics_lock);
925 smu_table->metrics_time = jiffies;
928 memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
929 mutex_unlock(&smu->metrics_lock);
934 static int arcturus_get_current_activity_percent(struct smu_context *smu,
935 enum amd_pp_sensors sensor,
938 SmuMetrics_t metrics;
944 ret = arcturus_get_metrics_table(smu, &metrics);
949 case AMDGPU_PP_SENSOR_GPU_LOAD:
950 *value = metrics.AverageGfxActivity;
952 case AMDGPU_PP_SENSOR_MEM_LOAD:
953 *value = metrics.AverageUclkActivity;
956 pr_err("Invalid sensor for retrieving clock activity\n");
963 static int arcturus_get_gpu_power(struct smu_context *smu, uint32_t *value)
965 SmuMetrics_t metrics;
971 ret = arcturus_get_metrics_table(smu, &metrics);
975 *value = metrics.AverageSocketPower << 8;
980 static int arcturus_thermal_get_temperature(struct smu_context *smu,
981 enum amd_pp_sensors sensor,
984 SmuMetrics_t metrics;
990 ret = arcturus_get_metrics_table(smu, &metrics);
995 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
996 *value = metrics.TemperatureHotspot *
997 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
999 case AMDGPU_PP_SENSOR_EDGE_TEMP:
1000 *value = metrics.TemperatureEdge *
1001 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1003 case AMDGPU_PP_SENSOR_MEM_TEMP:
1004 *value = metrics.TemperatureHBM *
1005 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1008 pr_err("Invalid sensor for retrieving temp\n");
1015 static int arcturus_read_sensor(struct smu_context *smu,
1016 enum amd_pp_sensors sensor,
1017 void *data, uint32_t *size)
1019 struct smu_table_context *table_context = &smu->smu_table;
1020 PPTable_t *pptable = table_context->driver_pptable;
1023 if (amdgpu_ras_intr_triggered())
1029 mutex_lock(&smu->sensor_lock);
1031 case AMDGPU_PP_SENSOR_MAX_FAN_RPM:
1032 *(uint32_t *)data = pptable->FanMaximumRpm;
1035 case AMDGPU_PP_SENSOR_MEM_LOAD:
1036 case AMDGPU_PP_SENSOR_GPU_LOAD:
1037 ret = arcturus_get_current_activity_percent(smu,
1042 case AMDGPU_PP_SENSOR_GPU_POWER:
1043 ret = arcturus_get_gpu_power(smu, (uint32_t *)data);
1046 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
1047 case AMDGPU_PP_SENSOR_EDGE_TEMP:
1048 case AMDGPU_PP_SENSOR_MEM_TEMP:
1049 ret = arcturus_thermal_get_temperature(smu, sensor,
1054 ret = smu_v11_0_read_sensor(smu, sensor, data, size);
1056 mutex_unlock(&smu->sensor_lock);
1061 static int arcturus_get_fan_speed_rpm(struct smu_context *smu,
1064 SmuMetrics_t metrics;
1070 ret = arcturus_get_metrics_table(smu, &metrics);
1074 *speed = metrics.CurrFanSpeed;
1079 static int arcturus_get_fan_speed_percent(struct smu_context *smu,
1082 PPTable_t *pptable = smu->smu_table.driver_pptable;
1083 uint32_t percent, current_rpm;
1089 ret = arcturus_get_fan_speed_rpm(smu, ¤t_rpm);
1093 percent = current_rpm * 100 / pptable->FanMaximumRpm;
1094 *speed = percent > 100 ? 100 : percent;
1099 static int arcturus_get_current_clk_freq_by_table(struct smu_context *smu,
1100 enum smu_clk_type clk_type,
1103 static SmuMetrics_t metrics;
1104 int ret = 0, clk_id = 0;
1109 clk_id = smu_clk_get_index(smu, clk_type);
1113 ret = arcturus_get_metrics_table(smu, &metrics);
1120 * CurrClock[clk_id] can provide accurate
1121 * output only when the dpm feature is enabled.
1122 * We can use Average_* for dpm disabled case.
1123 * But this is available for gfxclk/uclk/socclk.
1125 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_GFXCLK_BIT))
1126 *value = metrics.CurrClock[PPCLK_GFXCLK];
1128 *value = metrics.AverageGfxclkFrequency;
1131 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UCLK_BIT))
1132 *value = metrics.CurrClock[PPCLK_UCLK];
1134 *value = metrics.AverageUclkFrequency;
1137 if (smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT))
1138 *value = metrics.CurrClock[PPCLK_SOCCLK];
1140 *value = metrics.AverageSocclkFrequency;
1143 *value = metrics.CurrClock[clk_id];
1150 static uint32_t arcturus_find_lowest_dpm_level(struct arcturus_single_dpm_table *table)
1154 for (i = 0; i < table->count; i++) {
1155 if (table->dpm_levels[i].enabled)
1158 if (i >= table->count) {
1160 table->dpm_levels[i].enabled = true;
1166 static uint32_t arcturus_find_highest_dpm_level(struct arcturus_single_dpm_table *table)
1170 if (table->count <= 0) {
1171 pr_err("[%s] DPM Table has no entry!", __func__);
1174 if (table->count > MAX_DPM_NUMBER) {
1175 pr_err("[%s] DPM Table has too many entries!", __func__);
1176 return MAX_DPM_NUMBER - 1;
1179 for (i = table->count - 1; i >= 0; i--) {
1180 if (table->dpm_levels[i].enabled)
1185 table->dpm_levels[i].enabled = true;
1193 static int arcturus_force_dpm_limit_value(struct smu_context *smu, bool highest)
1195 struct arcturus_dpm_table *dpm_table =
1196 (struct arcturus_dpm_table *)smu->smu_dpm.dpm_context;
1197 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(smu->adev, 0);
1198 uint32_t soft_level;
1203 soft_level = arcturus_find_highest_dpm_level(&(dpm_table->gfx_table));
1205 soft_level = arcturus_find_lowest_dpm_level(&(dpm_table->gfx_table));
1207 dpm_table->gfx_table.dpm_state.soft_min_level =
1208 dpm_table->gfx_table.dpm_state.soft_max_level =
1209 dpm_table->gfx_table.dpm_levels[soft_level].value;
1211 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
1213 pr_err("Failed to upload boot level to %s!\n",
1214 highest ? "highest" : "lowest");
1218 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
1220 pr_err("Failed to upload dpm max level to %s!\n!",
1221 highest ? "highest" : "lowest");
1227 * Force XGMI Pstate to highest or lowest
1228 * TODO: revise this when xgmi dpm is functional
1230 ret = smu_v11_0_set_xgmi_pstate(smu, highest ? 1 : 0);
1235 static int arcturus_unforce_dpm_levels(struct smu_context *smu)
1237 struct arcturus_dpm_table *dpm_table =
1238 (struct arcturus_dpm_table *)smu->smu_dpm.dpm_context;
1239 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(smu->adev, 0);
1240 uint32_t soft_min_level, soft_max_level;
1244 soft_min_level = arcturus_find_lowest_dpm_level(&(dpm_table->gfx_table));
1245 soft_max_level = arcturus_find_highest_dpm_level(&(dpm_table->gfx_table));
1246 dpm_table->gfx_table.dpm_state.soft_min_level =
1247 dpm_table->gfx_table.dpm_levels[soft_min_level].value;
1248 dpm_table->gfx_table.dpm_state.soft_max_level =
1249 dpm_table->gfx_table.dpm_levels[soft_max_level].value;
1251 ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
1253 pr_err("Failed to upload DPM Bootup Levels!");
1257 ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
1259 pr_err("Failed to upload DPM Max Levels!");
1265 * Reset XGMI Pstate back to default
1266 * TODO: revise this when xgmi dpm is functional
1268 ret = smu_v11_0_set_xgmi_pstate(smu, 0);
1274 arcturus_get_profiling_clk_mask(struct smu_context *smu,
1275 enum amd_dpm_forced_level level,
1276 uint32_t *sclk_mask,
1277 uint32_t *mclk_mask,
1280 struct arcturus_dpm_table *dpm_table =
1281 (struct arcturus_dpm_table *)smu->smu_dpm.dpm_context;
1282 struct arcturus_single_dpm_table *gfx_dpm_table;
1283 struct arcturus_single_dpm_table *mem_dpm_table;
1284 struct arcturus_single_dpm_table *soc_dpm_table;
1286 if (!smu->smu_dpm.dpm_context)
1289 gfx_dpm_table = &dpm_table->gfx_table;
1290 mem_dpm_table = &dpm_table->mem_table;
1291 soc_dpm_table = &dpm_table->soc_table;
1297 if (gfx_dpm_table->count > ARCTURUS_UMD_PSTATE_GFXCLK_LEVEL &&
1298 mem_dpm_table->count > ARCTURUS_UMD_PSTATE_MCLK_LEVEL &&
1299 soc_dpm_table->count > ARCTURUS_UMD_PSTATE_SOCCLK_LEVEL) {
1300 *sclk_mask = ARCTURUS_UMD_PSTATE_GFXCLK_LEVEL;
1301 *mclk_mask = ARCTURUS_UMD_PSTATE_MCLK_LEVEL;
1302 *soc_mask = ARCTURUS_UMD_PSTATE_SOCCLK_LEVEL;
1305 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
1307 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
1309 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
1310 *sclk_mask = gfx_dpm_table->count - 1;
1311 *mclk_mask = mem_dpm_table->count - 1;
1312 *soc_mask = soc_dpm_table->count - 1;
1318 static int arcturus_get_power_limit(struct smu_context *smu,
1322 PPTable_t *pptable = smu->smu_table.driver_pptable;
1323 uint32_t asic_default_power_limit = 0;
1327 if (!smu->power_limit) {
1328 if (smu_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
1329 power_src = smu_power_get_index(smu, SMU_POWER_SOURCE_AC);
1333 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetPptLimit,
1334 power_src << 16, &asic_default_power_limit);
1336 pr_err("[%s] get PPT limit failed!", __func__);
1340 /* the last hope to figure out the ppt limit */
1342 pr_err("Cannot get PPT limit due to pptable missing!");
1345 asic_default_power_limit =
1346 pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
1349 smu->power_limit = asic_default_power_limit;
1353 *limit = smu_v11_0_get_max_power_limit(smu);
1355 *limit = smu->power_limit;
1360 static int arcturus_get_power_profile_mode(struct smu_context *smu,
1363 DpmActivityMonitorCoeffInt_t activity_monitor;
1364 static const char *profile_name[] = {
1372 static const char *title[] = {
1373 "PROFILE_INDEX(NAME)",
1377 "MinActiveFreqType",
1382 "PD_Data_error_coeff",
1383 "PD_Data_error_rate_coeff"};
1384 uint32_t i, size = 0;
1385 int16_t workload_type = 0;
1387 uint32_t smu_version;
1392 result = smu_get_smc_version(smu, NULL, &smu_version);
1396 if (smu_version >= 0x360d00)
1397 size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
1398 title[0], title[1], title[2], title[3], title[4], title[5],
1399 title[6], title[7], title[8], title[9], title[10]);
1401 size += sprintf(buf + size, "%16s\n",
1404 for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
1406 * Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT
1407 * Not all profile modes are supported on arcturus.
1409 workload_type = smu_workload_get_type(smu, i);
1410 if (workload_type < 0)
1413 if (smu_version >= 0x360d00) {
1414 result = smu_update_table(smu,
1415 SMU_TABLE_ACTIVITY_MONITOR_COEFF,
1417 (void *)(&activity_monitor),
1420 pr_err("[%s] Failed to get activity monitor!", __func__);
1425 size += sprintf(buf + size, "%2d %14s%s\n",
1426 i, profile_name[i], (i == smu->power_profile_mode) ? "*" : " ");
1428 if (smu_version >= 0x360d00) {
1429 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1433 activity_monitor.Gfx_FPS,
1434 activity_monitor.Gfx_UseRlcBusy,
1435 activity_monitor.Gfx_MinActiveFreqType,
1436 activity_monitor.Gfx_MinActiveFreq,
1437 activity_monitor.Gfx_BoosterFreqType,
1438 activity_monitor.Gfx_BoosterFreq,
1439 activity_monitor.Gfx_PD_Data_limit_c,
1440 activity_monitor.Gfx_PD_Data_error_coeff,
1441 activity_monitor.Gfx_PD_Data_error_rate_coeff);
1443 size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
1447 activity_monitor.Mem_FPS,
1448 activity_monitor.Mem_UseRlcBusy,
1449 activity_monitor.Mem_MinActiveFreqType,
1450 activity_monitor.Mem_MinActiveFreq,
1451 activity_monitor.Mem_BoosterFreqType,
1452 activity_monitor.Mem_BoosterFreq,
1453 activity_monitor.Mem_PD_Data_limit_c,
1454 activity_monitor.Mem_PD_Data_error_coeff,
1455 activity_monitor.Mem_PD_Data_error_rate_coeff);
1462 static int arcturus_set_power_profile_mode(struct smu_context *smu,
1466 DpmActivityMonitorCoeffInt_t activity_monitor;
1467 int workload_type = 0;
1468 uint32_t profile_mode = input[size];
1470 uint32_t smu_version;
1472 if (profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
1473 pr_err("Invalid power profile mode %d\n", profile_mode);
1477 ret = smu_get_smc_version(smu, NULL, &smu_version);
1481 if ((profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) &&
1482 (smu_version >=0x360d00)) {
1483 ret = smu_update_table(smu,
1484 SMU_TABLE_ACTIVITY_MONITOR_COEFF,
1485 WORKLOAD_PPLIB_CUSTOM_BIT,
1486 (void *)(&activity_monitor),
1489 pr_err("[%s] Failed to get activity monitor!", __func__);
1494 case 0: /* Gfxclk */
1495 activity_monitor.Gfx_FPS = input[1];
1496 activity_monitor.Gfx_UseRlcBusy = input[2];
1497 activity_monitor.Gfx_MinActiveFreqType = input[3];
1498 activity_monitor.Gfx_MinActiveFreq = input[4];
1499 activity_monitor.Gfx_BoosterFreqType = input[5];
1500 activity_monitor.Gfx_BoosterFreq = input[6];
1501 activity_monitor.Gfx_PD_Data_limit_c = input[7];
1502 activity_monitor.Gfx_PD_Data_error_coeff = input[8];
1503 activity_monitor.Gfx_PD_Data_error_rate_coeff = input[9];
1506 activity_monitor.Mem_FPS = input[1];
1507 activity_monitor.Mem_UseRlcBusy = input[2];
1508 activity_monitor.Mem_MinActiveFreqType = input[3];
1509 activity_monitor.Mem_MinActiveFreq = input[4];
1510 activity_monitor.Mem_BoosterFreqType = input[5];
1511 activity_monitor.Mem_BoosterFreq = input[6];
1512 activity_monitor.Mem_PD_Data_limit_c = input[7];
1513 activity_monitor.Mem_PD_Data_error_coeff = input[8];
1514 activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
1518 ret = smu_update_table(smu,
1519 SMU_TABLE_ACTIVITY_MONITOR_COEFF,
1520 WORKLOAD_PPLIB_CUSTOM_BIT,
1521 (void *)(&activity_monitor),
1524 pr_err("[%s] Failed to set activity monitor!", __func__);
1530 * Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT
1531 * Not all profile modes are supported on arcturus.
1533 workload_type = smu_workload_get_type(smu, profile_mode);
1534 if (workload_type < 0) {
1535 pr_err("Unsupported power profile mode %d on arcturus\n", profile_mode);
1539 ret = smu_send_smc_msg_with_param(smu,
1540 SMU_MSG_SetWorkloadMask,
1544 pr_err("Fail to set workload type %d\n", workload_type);
1548 smu->power_profile_mode = profile_mode;
1553 static int arcturus_set_performance_level(struct smu_context *smu,
1554 enum amd_dpm_forced_level level)
1556 uint32_t smu_version;
1559 ret = smu_get_smc_version(smu, NULL, &smu_version);
1561 pr_err("Failed to get smu version!\n");
1566 case AMD_DPM_FORCED_LEVEL_HIGH:
1567 case AMD_DPM_FORCED_LEVEL_LOW:
1568 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
1569 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
1570 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
1571 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
1572 if (smu_version >= 0x361200) {
1573 pr_err("Forcing clock level is not supported with "
1574 "54.18 and onwards SMU firmwares\n");
1582 return smu_v11_0_set_performance_level(smu, level);
1585 static void arcturus_dump_pptable(struct smu_context *smu)
1587 struct smu_table_context *table_context = &smu->smu_table;
1588 PPTable_t *pptable = table_context->driver_pptable;
1591 pr_info("Dumped PPTable:\n");
1593 pr_info("Version = 0x%08x\n", pptable->Version);
1595 pr_info("FeaturesToRun[0] = 0x%08x\n", pptable->FeaturesToRun[0]);
1596 pr_info("FeaturesToRun[1] = 0x%08x\n", pptable->FeaturesToRun[1]);
1598 for (i = 0; i < PPT_THROTTLER_COUNT; i++) {
1599 pr_info("SocketPowerLimitAc[%d] = %d\n", i, pptable->SocketPowerLimitAc[i]);
1600 pr_info("SocketPowerLimitAcTau[%d] = %d\n", i, pptable->SocketPowerLimitAcTau[i]);
1603 pr_info("TdcLimitSoc = %d\n", pptable->TdcLimitSoc);
1604 pr_info("TdcLimitSocTau = %d\n", pptable->TdcLimitSocTau);
1605 pr_info("TdcLimitGfx = %d\n", pptable->TdcLimitGfx);
1606 pr_info("TdcLimitGfxTau = %d\n", pptable->TdcLimitGfxTau);
1608 pr_info("TedgeLimit = %d\n", pptable->TedgeLimit);
1609 pr_info("ThotspotLimit = %d\n", pptable->ThotspotLimit);
1610 pr_info("TmemLimit = %d\n", pptable->TmemLimit);
1611 pr_info("Tvr_gfxLimit = %d\n", pptable->Tvr_gfxLimit);
1612 pr_info("Tvr_memLimit = %d\n", pptable->Tvr_memLimit);
1613 pr_info("Tvr_socLimit = %d\n", pptable->Tvr_socLimit);
1614 pr_info("FitLimit = %d\n", pptable->FitLimit);
1616 pr_info("PpmPowerLimit = %d\n", pptable->PpmPowerLimit);
1617 pr_info("PpmTemperatureThreshold = %d\n", pptable->PpmTemperatureThreshold);
1619 pr_info("ThrottlerControlMask = %d\n", pptable->ThrottlerControlMask);
1621 pr_info("UlvVoltageOffsetGfx = %d\n", pptable->UlvVoltageOffsetGfx);
1622 pr_info("UlvPadding = 0x%08x\n", pptable->UlvPadding);
1624 pr_info("UlvGfxclkBypass = %d\n", pptable->UlvGfxclkBypass);
1625 pr_info("Padding234[0] = 0x%02x\n", pptable->Padding234[0]);
1626 pr_info("Padding234[1] = 0x%02x\n", pptable->Padding234[1]);
1627 pr_info("Padding234[2] = 0x%02x\n", pptable->Padding234[2]);
1629 pr_info("MinVoltageGfx = %d\n", pptable->MinVoltageGfx);
1630 pr_info("MinVoltageSoc = %d\n", pptable->MinVoltageSoc);
1631 pr_info("MaxVoltageGfx = %d\n", pptable->MaxVoltageGfx);
1632 pr_info("MaxVoltageSoc = %d\n", pptable->MaxVoltageSoc);
1634 pr_info("LoadLineResistanceGfx = %d\n", pptable->LoadLineResistanceGfx);
1635 pr_info("LoadLineResistanceSoc = %d\n", pptable->LoadLineResistanceSoc);
1637 pr_info("[PPCLK_GFXCLK]\n"
1638 " .VoltageMode = 0x%02x\n"
1639 " .SnapToDiscrete = 0x%02x\n"
1640 " .NumDiscreteLevels = 0x%02x\n"
1641 " .padding = 0x%02x\n"
1642 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1643 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1644 " .SsFmin = 0x%04x\n"
1645 " .Padding_16 = 0x%04x\n",
1646 pptable->DpmDescriptor[PPCLK_GFXCLK].VoltageMode,
1647 pptable->DpmDescriptor[PPCLK_GFXCLK].SnapToDiscrete,
1648 pptable->DpmDescriptor[PPCLK_GFXCLK].NumDiscreteLevels,
1649 pptable->DpmDescriptor[PPCLK_GFXCLK].padding,
1650 pptable->DpmDescriptor[PPCLK_GFXCLK].ConversionToAvfsClk.m,
1651 pptable->DpmDescriptor[PPCLK_GFXCLK].ConversionToAvfsClk.b,
1652 pptable->DpmDescriptor[PPCLK_GFXCLK].SsCurve.a,
1653 pptable->DpmDescriptor[PPCLK_GFXCLK].SsCurve.b,
1654 pptable->DpmDescriptor[PPCLK_GFXCLK].SsCurve.c,
1655 pptable->DpmDescriptor[PPCLK_GFXCLK].SsFmin,
1656 pptable->DpmDescriptor[PPCLK_GFXCLK].Padding16);
1658 pr_info("[PPCLK_VCLK]\n"
1659 " .VoltageMode = 0x%02x\n"
1660 " .SnapToDiscrete = 0x%02x\n"
1661 " .NumDiscreteLevels = 0x%02x\n"
1662 " .padding = 0x%02x\n"
1663 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1664 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1665 " .SsFmin = 0x%04x\n"
1666 " .Padding_16 = 0x%04x\n",
1667 pptable->DpmDescriptor[PPCLK_VCLK].VoltageMode,
1668 pptable->DpmDescriptor[PPCLK_VCLK].SnapToDiscrete,
1669 pptable->DpmDescriptor[PPCLK_VCLK].NumDiscreteLevels,
1670 pptable->DpmDescriptor[PPCLK_VCLK].padding,
1671 pptable->DpmDescriptor[PPCLK_VCLK].ConversionToAvfsClk.m,
1672 pptable->DpmDescriptor[PPCLK_VCLK].ConversionToAvfsClk.b,
1673 pptable->DpmDescriptor[PPCLK_VCLK].SsCurve.a,
1674 pptable->DpmDescriptor[PPCLK_VCLK].SsCurve.b,
1675 pptable->DpmDescriptor[PPCLK_VCLK].SsCurve.c,
1676 pptable->DpmDescriptor[PPCLK_VCLK].SsFmin,
1677 pptable->DpmDescriptor[PPCLK_VCLK].Padding16);
1679 pr_info("[PPCLK_DCLK]\n"
1680 " .VoltageMode = 0x%02x\n"
1681 " .SnapToDiscrete = 0x%02x\n"
1682 " .NumDiscreteLevels = 0x%02x\n"
1683 " .padding = 0x%02x\n"
1684 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1685 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1686 " .SsFmin = 0x%04x\n"
1687 " .Padding_16 = 0x%04x\n",
1688 pptable->DpmDescriptor[PPCLK_DCLK].VoltageMode,
1689 pptable->DpmDescriptor[PPCLK_DCLK].SnapToDiscrete,
1690 pptable->DpmDescriptor[PPCLK_DCLK].NumDiscreteLevels,
1691 pptable->DpmDescriptor[PPCLK_DCLK].padding,
1692 pptable->DpmDescriptor[PPCLK_DCLK].ConversionToAvfsClk.m,
1693 pptable->DpmDescriptor[PPCLK_DCLK].ConversionToAvfsClk.b,
1694 pptable->DpmDescriptor[PPCLK_DCLK].SsCurve.a,
1695 pptable->DpmDescriptor[PPCLK_DCLK].SsCurve.b,
1696 pptable->DpmDescriptor[PPCLK_DCLK].SsCurve.c,
1697 pptable->DpmDescriptor[PPCLK_DCLK].SsFmin,
1698 pptable->DpmDescriptor[PPCLK_DCLK].Padding16);
1700 pr_info("[PPCLK_SOCCLK]\n"
1701 " .VoltageMode = 0x%02x\n"
1702 " .SnapToDiscrete = 0x%02x\n"
1703 " .NumDiscreteLevels = 0x%02x\n"
1704 " .padding = 0x%02x\n"
1705 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1706 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1707 " .SsFmin = 0x%04x\n"
1708 " .Padding_16 = 0x%04x\n",
1709 pptable->DpmDescriptor[PPCLK_SOCCLK].VoltageMode,
1710 pptable->DpmDescriptor[PPCLK_SOCCLK].SnapToDiscrete,
1711 pptable->DpmDescriptor[PPCLK_SOCCLK].NumDiscreteLevels,
1712 pptable->DpmDescriptor[PPCLK_SOCCLK].padding,
1713 pptable->DpmDescriptor[PPCLK_SOCCLK].ConversionToAvfsClk.m,
1714 pptable->DpmDescriptor[PPCLK_SOCCLK].ConversionToAvfsClk.b,
1715 pptable->DpmDescriptor[PPCLK_SOCCLK].SsCurve.a,
1716 pptable->DpmDescriptor[PPCLK_SOCCLK].SsCurve.b,
1717 pptable->DpmDescriptor[PPCLK_SOCCLK].SsCurve.c,
1718 pptable->DpmDescriptor[PPCLK_SOCCLK].SsFmin,
1719 pptable->DpmDescriptor[PPCLK_SOCCLK].Padding16);
1721 pr_info("[PPCLK_UCLK]\n"
1722 " .VoltageMode = 0x%02x\n"
1723 " .SnapToDiscrete = 0x%02x\n"
1724 " .NumDiscreteLevels = 0x%02x\n"
1725 " .padding = 0x%02x\n"
1726 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1727 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1728 " .SsFmin = 0x%04x\n"
1729 " .Padding_16 = 0x%04x\n",
1730 pptable->DpmDescriptor[PPCLK_UCLK].VoltageMode,
1731 pptable->DpmDescriptor[PPCLK_UCLK].SnapToDiscrete,
1732 pptable->DpmDescriptor[PPCLK_UCLK].NumDiscreteLevels,
1733 pptable->DpmDescriptor[PPCLK_UCLK].padding,
1734 pptable->DpmDescriptor[PPCLK_UCLK].ConversionToAvfsClk.m,
1735 pptable->DpmDescriptor[PPCLK_UCLK].ConversionToAvfsClk.b,
1736 pptable->DpmDescriptor[PPCLK_UCLK].SsCurve.a,
1737 pptable->DpmDescriptor[PPCLK_UCLK].SsCurve.b,
1738 pptable->DpmDescriptor[PPCLK_UCLK].SsCurve.c,
1739 pptable->DpmDescriptor[PPCLK_UCLK].SsFmin,
1740 pptable->DpmDescriptor[PPCLK_UCLK].Padding16);
1742 pr_info("[PPCLK_FCLK]\n"
1743 " .VoltageMode = 0x%02x\n"
1744 " .SnapToDiscrete = 0x%02x\n"
1745 " .NumDiscreteLevels = 0x%02x\n"
1746 " .padding = 0x%02x\n"
1747 " .ConversionToAvfsClk{m = 0x%08x b = 0x%08x}\n"
1748 " .SsCurve {a = 0x%08x b = 0x%08x c = 0x%08x}\n"
1749 " .SsFmin = 0x%04x\n"
1750 " .Padding_16 = 0x%04x\n",
1751 pptable->DpmDescriptor[PPCLK_FCLK].VoltageMode,
1752 pptable->DpmDescriptor[PPCLK_FCLK].SnapToDiscrete,
1753 pptable->DpmDescriptor[PPCLK_FCLK].NumDiscreteLevels,
1754 pptable->DpmDescriptor[PPCLK_FCLK].padding,
1755 pptable->DpmDescriptor[PPCLK_FCLK].ConversionToAvfsClk.m,
1756 pptable->DpmDescriptor[PPCLK_FCLK].ConversionToAvfsClk.b,
1757 pptable->DpmDescriptor[PPCLK_FCLK].SsCurve.a,
1758 pptable->DpmDescriptor[PPCLK_FCLK].SsCurve.b,
1759 pptable->DpmDescriptor[PPCLK_FCLK].SsCurve.c,
1760 pptable->DpmDescriptor[PPCLK_FCLK].SsFmin,
1761 pptable->DpmDescriptor[PPCLK_FCLK].Padding16);
1764 pr_info("FreqTableGfx\n");
1765 for (i = 0; i < NUM_GFXCLK_DPM_LEVELS; i++)
1766 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableGfx[i]);
1768 pr_info("FreqTableVclk\n");
1769 for (i = 0; i < NUM_VCLK_DPM_LEVELS; i++)
1770 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableVclk[i]);
1772 pr_info("FreqTableDclk\n");
1773 for (i = 0; i < NUM_DCLK_DPM_LEVELS; i++)
1774 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableDclk[i]);
1776 pr_info("FreqTableSocclk\n");
1777 for (i = 0; i < NUM_SOCCLK_DPM_LEVELS; i++)
1778 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableSocclk[i]);
1780 pr_info("FreqTableUclk\n");
1781 for (i = 0; i < NUM_UCLK_DPM_LEVELS; i++)
1782 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableUclk[i]);
1784 pr_info("FreqTableFclk\n");
1785 for (i = 0; i < NUM_FCLK_DPM_LEVELS; i++)
1786 pr_info(" .[%02d] = %d\n", i, pptable->FreqTableFclk[i]);
1788 pr_info("Mp0clkFreq\n");
1789 for (i = 0; i < NUM_MP0CLK_DPM_LEVELS; i++)
1790 pr_info(" .[%d] = %d\n", i, pptable->Mp0clkFreq[i]);
1792 pr_info("Mp0DpmVoltage\n");
1793 for (i = 0; i < NUM_MP0CLK_DPM_LEVELS; i++)
1794 pr_info(" .[%d] = %d\n", i, pptable->Mp0DpmVoltage[i]);
1796 pr_info("GfxclkFidle = 0x%x\n", pptable->GfxclkFidle);
1797 pr_info("GfxclkSlewRate = 0x%x\n", pptable->GfxclkSlewRate);
1798 pr_info("Padding567[0] = 0x%x\n", pptable->Padding567[0]);
1799 pr_info("Padding567[1] = 0x%x\n", pptable->Padding567[1]);
1800 pr_info("Padding567[2] = 0x%x\n", pptable->Padding567[2]);
1801 pr_info("Padding567[3] = 0x%x\n", pptable->Padding567[3]);
1802 pr_info("GfxclkDsMaxFreq = %d\n", pptable->GfxclkDsMaxFreq);
1803 pr_info("GfxclkSource = 0x%x\n", pptable->GfxclkSource);
1804 pr_info("Padding456 = 0x%x\n", pptable->Padding456);
1806 pr_info("EnableTdpm = %d\n", pptable->EnableTdpm);
1807 pr_info("TdpmHighHystTemperature = %d\n", pptable->TdpmHighHystTemperature);
1808 pr_info("TdpmLowHystTemperature = %d\n", pptable->TdpmLowHystTemperature);
1809 pr_info("GfxclkFreqHighTempLimit = %d\n", pptable->GfxclkFreqHighTempLimit);
1811 pr_info("FanStopTemp = %d\n", pptable->FanStopTemp);
1812 pr_info("FanStartTemp = %d\n", pptable->FanStartTemp);
1814 pr_info("FanGainEdge = %d\n", pptable->FanGainEdge);
1815 pr_info("FanGainHotspot = %d\n", pptable->FanGainHotspot);
1816 pr_info("FanGainVrGfx = %d\n", pptable->FanGainVrGfx);
1817 pr_info("FanGainVrSoc = %d\n", pptable->FanGainVrSoc);
1818 pr_info("FanGainVrMem = %d\n", pptable->FanGainVrMem);
1819 pr_info("FanGainHbm = %d\n", pptable->FanGainHbm);
1821 pr_info("FanPwmMin = %d\n", pptable->FanPwmMin);
1822 pr_info("FanAcousticLimitRpm = %d\n", pptable->FanAcousticLimitRpm);
1823 pr_info("FanThrottlingRpm = %d\n", pptable->FanThrottlingRpm);
1824 pr_info("FanMaximumRpm = %d\n", pptable->FanMaximumRpm);
1825 pr_info("FanTargetTemperature = %d\n", pptable->FanTargetTemperature);
1826 pr_info("FanTargetGfxclk = %d\n", pptable->FanTargetGfxclk);
1827 pr_info("FanZeroRpmEnable = %d\n", pptable->FanZeroRpmEnable);
1828 pr_info("FanTachEdgePerRev = %d\n", pptable->FanTachEdgePerRev);
1829 pr_info("FanTempInputSelect = %d\n", pptable->FanTempInputSelect);
1831 pr_info("FuzzyFan_ErrorSetDelta = %d\n", pptable->FuzzyFan_ErrorSetDelta);
1832 pr_info("FuzzyFan_ErrorRateSetDelta = %d\n", pptable->FuzzyFan_ErrorRateSetDelta);
1833 pr_info("FuzzyFan_PwmSetDelta = %d\n", pptable->FuzzyFan_PwmSetDelta);
1834 pr_info("FuzzyFan_Reserved = %d\n", pptable->FuzzyFan_Reserved);
1836 pr_info("OverrideAvfsGb[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->OverrideAvfsGb[AVFS_VOLTAGE_GFX]);
1837 pr_info("OverrideAvfsGb[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->OverrideAvfsGb[AVFS_VOLTAGE_SOC]);
1838 pr_info("Padding8_Avfs[0] = %d\n", pptable->Padding8_Avfs[0]);
1839 pr_info("Padding8_Avfs[1] = %d\n", pptable->Padding8_Avfs[1]);
1841 pr_info("dBtcGbGfxPll{a = 0x%x b = 0x%x c = 0x%x}\n",
1842 pptable->dBtcGbGfxPll.a,
1843 pptable->dBtcGbGfxPll.b,
1844 pptable->dBtcGbGfxPll.c);
1845 pr_info("dBtcGbGfxAfll{a = 0x%x b = 0x%x c = 0x%x}\n",
1846 pptable->dBtcGbGfxAfll.a,
1847 pptable->dBtcGbGfxAfll.b,
1848 pptable->dBtcGbGfxAfll.c);
1849 pr_info("dBtcGbSoc{a = 0x%x b = 0x%x c = 0x%x}\n",
1850 pptable->dBtcGbSoc.a,
1851 pptable->dBtcGbSoc.b,
1852 pptable->dBtcGbSoc.c);
1854 pr_info("qAgingGb[AVFS_VOLTAGE_GFX]{m = 0x%x b = 0x%x}\n",
1855 pptable->qAgingGb[AVFS_VOLTAGE_GFX].m,
1856 pptable->qAgingGb[AVFS_VOLTAGE_GFX].b);
1857 pr_info("qAgingGb[AVFS_VOLTAGE_SOC]{m = 0x%x b = 0x%x}\n",
1858 pptable->qAgingGb[AVFS_VOLTAGE_SOC].m,
1859 pptable->qAgingGb[AVFS_VOLTAGE_SOC].b);
1861 pr_info("qStaticVoltageOffset[AVFS_VOLTAGE_GFX]{a = 0x%x b = 0x%x c = 0x%x}\n",
1862 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_GFX].a,
1863 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_GFX].b,
1864 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_GFX].c);
1865 pr_info("qStaticVoltageOffset[AVFS_VOLTAGE_SOC]{a = 0x%x b = 0x%x c = 0x%x}\n",
1866 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_SOC].a,
1867 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_SOC].b,
1868 pptable->qStaticVoltageOffset[AVFS_VOLTAGE_SOC].c);
1870 pr_info("DcTol[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcTol[AVFS_VOLTAGE_GFX]);
1871 pr_info("DcTol[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcTol[AVFS_VOLTAGE_SOC]);
1873 pr_info("DcBtcEnabled[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcEnabled[AVFS_VOLTAGE_GFX]);
1874 pr_info("DcBtcEnabled[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcEnabled[AVFS_VOLTAGE_SOC]);
1875 pr_info("Padding8_GfxBtc[0] = 0x%x\n", pptable->Padding8_GfxBtc[0]);
1876 pr_info("Padding8_GfxBtc[1] = 0x%x\n", pptable->Padding8_GfxBtc[1]);
1878 pr_info("DcBtcMin[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcMin[AVFS_VOLTAGE_GFX]);
1879 pr_info("DcBtcMin[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcMin[AVFS_VOLTAGE_SOC]);
1880 pr_info("DcBtcMax[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcMax[AVFS_VOLTAGE_GFX]);
1881 pr_info("DcBtcMax[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcMax[AVFS_VOLTAGE_SOC]);
1883 pr_info("DcBtcGb[AVFS_VOLTAGE_GFX] = 0x%x\n", pptable->DcBtcGb[AVFS_VOLTAGE_GFX]);
1884 pr_info("DcBtcGb[AVFS_VOLTAGE_SOC] = 0x%x\n", pptable->DcBtcGb[AVFS_VOLTAGE_SOC]);
1886 pr_info("XgmiDpmPstates\n");
1887 for (i = 0; i < NUM_XGMI_LEVELS; i++)
1888 pr_info(" .[%d] = %d\n", i, pptable->XgmiDpmPstates[i]);
1889 pr_info("XgmiDpmSpare[0] = 0x%02x\n", pptable->XgmiDpmSpare[0]);
1890 pr_info("XgmiDpmSpare[1] = 0x%02x\n", pptable->XgmiDpmSpare[1]);
1892 pr_info("VDDGFX_TVmin = %d\n", pptable->VDDGFX_TVmin);
1893 pr_info("VDDSOC_TVmin = %d\n", pptable->VDDSOC_TVmin);
1894 pr_info("VDDGFX_Vmin_HiTemp = %d\n", pptable->VDDGFX_Vmin_HiTemp);
1895 pr_info("VDDGFX_Vmin_LoTemp = %d\n", pptable->VDDGFX_Vmin_LoTemp);
1896 pr_info("VDDSOC_Vmin_HiTemp = %d\n", pptable->VDDSOC_Vmin_HiTemp);
1897 pr_info("VDDSOC_Vmin_LoTemp = %d\n", pptable->VDDSOC_Vmin_LoTemp);
1898 pr_info("VDDGFX_TVminHystersis = %d\n", pptable->VDDGFX_TVminHystersis);
1899 pr_info("VDDSOC_TVminHystersis = %d\n", pptable->VDDSOC_TVminHystersis);
1901 pr_info("DebugOverrides = 0x%x\n", pptable->DebugOverrides);
1902 pr_info("ReservedEquation0{a = 0x%x b = 0x%x c = 0x%x}\n",
1903 pptable->ReservedEquation0.a,
1904 pptable->ReservedEquation0.b,
1905 pptable->ReservedEquation0.c);
1906 pr_info("ReservedEquation1{a = 0x%x b = 0x%x c = 0x%x}\n",
1907 pptable->ReservedEquation1.a,
1908 pptable->ReservedEquation1.b,
1909 pptable->ReservedEquation1.c);
1910 pr_info("ReservedEquation2{a = 0x%x b = 0x%x c = 0x%x}\n",
1911 pptable->ReservedEquation2.a,
1912 pptable->ReservedEquation2.b,
1913 pptable->ReservedEquation2.c);
1914 pr_info("ReservedEquation3{a = 0x%x b = 0x%x c = 0x%x}\n",
1915 pptable->ReservedEquation3.a,
1916 pptable->ReservedEquation3.b,
1917 pptable->ReservedEquation3.c);
1919 pr_info("MinVoltageUlvGfx = %d\n", pptable->MinVoltageUlvGfx);
1920 pr_info("PaddingUlv = %d\n", pptable->PaddingUlv);
1922 pr_info("TotalPowerConfig = %d\n", pptable->TotalPowerConfig);
1923 pr_info("TotalPowerSpare1 = %d\n", pptable->TotalPowerSpare1);
1924 pr_info("TotalPowerSpare2 = %d\n", pptable->TotalPowerSpare2);
1926 pr_info("PccThresholdLow = %d\n", pptable->PccThresholdLow);
1927 pr_info("PccThresholdHigh = %d\n", pptable->PccThresholdHigh);
1929 pr_info("Board Parameters:\n");
1930 pr_info("MaxVoltageStepGfx = 0x%x\n", pptable->MaxVoltageStepGfx);
1931 pr_info("MaxVoltageStepSoc = 0x%x\n", pptable->MaxVoltageStepSoc);
1933 pr_info("VddGfxVrMapping = 0x%x\n", pptable->VddGfxVrMapping);
1934 pr_info("VddSocVrMapping = 0x%x\n", pptable->VddSocVrMapping);
1935 pr_info("VddMemVrMapping = 0x%x\n", pptable->VddMemVrMapping);
1936 pr_info("BoardVrMapping = 0x%x\n", pptable->BoardVrMapping);
1938 pr_info("GfxUlvPhaseSheddingMask = 0x%x\n", pptable->GfxUlvPhaseSheddingMask);
1939 pr_info("ExternalSensorPresent = 0x%x\n", pptable->ExternalSensorPresent);
1941 pr_info("GfxMaxCurrent = 0x%x\n", pptable->GfxMaxCurrent);
1942 pr_info("GfxOffset = 0x%x\n", pptable->GfxOffset);
1943 pr_info("Padding_TelemetryGfx = 0x%x\n", pptable->Padding_TelemetryGfx);
1945 pr_info("SocMaxCurrent = 0x%x\n", pptable->SocMaxCurrent);
1946 pr_info("SocOffset = 0x%x\n", pptable->SocOffset);
1947 pr_info("Padding_TelemetrySoc = 0x%x\n", pptable->Padding_TelemetrySoc);
1949 pr_info("MemMaxCurrent = 0x%x\n", pptable->MemMaxCurrent);
1950 pr_info("MemOffset = 0x%x\n", pptable->MemOffset);
1951 pr_info("Padding_TelemetryMem = 0x%x\n", pptable->Padding_TelemetryMem);
1953 pr_info("BoardMaxCurrent = 0x%x\n", pptable->BoardMaxCurrent);
1954 pr_info("BoardOffset = 0x%x\n", pptable->BoardOffset);
1955 pr_info("Padding_TelemetryBoardInput = 0x%x\n", pptable->Padding_TelemetryBoardInput);
1957 pr_info("VR0HotGpio = %d\n", pptable->VR0HotGpio);
1958 pr_info("VR0HotPolarity = %d\n", pptable->VR0HotPolarity);
1959 pr_info("VR1HotGpio = %d\n", pptable->VR1HotGpio);
1960 pr_info("VR1HotPolarity = %d\n", pptable->VR1HotPolarity);
1962 pr_info("PllGfxclkSpreadEnabled = %d\n", pptable->PllGfxclkSpreadEnabled);
1963 pr_info("PllGfxclkSpreadPercent = %d\n", pptable->PllGfxclkSpreadPercent);
1964 pr_info("PllGfxclkSpreadFreq = %d\n", pptable->PllGfxclkSpreadFreq);
1966 pr_info("UclkSpreadEnabled = %d\n", pptable->UclkSpreadEnabled);
1967 pr_info("UclkSpreadPercent = %d\n", pptable->UclkSpreadPercent);
1968 pr_info("UclkSpreadFreq = %d\n", pptable->UclkSpreadFreq);
1970 pr_info("FclkSpreadEnabled = %d\n", pptable->FclkSpreadEnabled);
1971 pr_info("FclkSpreadPercent = %d\n", pptable->FclkSpreadPercent);
1972 pr_info("FclkSpreadFreq = %d\n", pptable->FclkSpreadFreq);
1974 pr_info("FllGfxclkSpreadEnabled = %d\n", pptable->FllGfxclkSpreadEnabled);
1975 pr_info("FllGfxclkSpreadPercent = %d\n", pptable->FllGfxclkSpreadPercent);
1976 pr_info("FllGfxclkSpreadFreq = %d\n", pptable->FllGfxclkSpreadFreq);
1978 for (i = 0; i < NUM_I2C_CONTROLLERS; i++) {
1979 pr_info("I2cControllers[%d]:\n", i);
1980 pr_info(" .Enabled = %d\n",
1981 pptable->I2cControllers[i].Enabled);
1982 pr_info(" .SlaveAddress = 0x%x\n",
1983 pptable->I2cControllers[i].SlaveAddress);
1984 pr_info(" .ControllerPort = %d\n",
1985 pptable->I2cControllers[i].ControllerPort);
1986 pr_info(" .ControllerName = %d\n",
1987 pptable->I2cControllers[i].ControllerName);
1988 pr_info(" .ThermalThrottler = %d\n",
1989 pptable->I2cControllers[i].ThermalThrotter);
1990 pr_info(" .I2cProtocol = %d\n",
1991 pptable->I2cControllers[i].I2cProtocol);
1992 pr_info(" .Speed = %d\n",
1993 pptable->I2cControllers[i].Speed);
1996 pr_info("MemoryChannelEnabled = %d\n", pptable->MemoryChannelEnabled);
1997 pr_info("DramBitWidth = %d\n", pptable->DramBitWidth);
1999 pr_info("TotalBoardPower = %d\n", pptable->TotalBoardPower);
2001 pr_info("XgmiLinkSpeed\n");
2002 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
2003 pr_info(" .[%d] = %d\n", i, pptable->XgmiLinkSpeed[i]);
2004 pr_info("XgmiLinkWidth\n");
2005 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
2006 pr_info(" .[%d] = %d\n", i, pptable->XgmiLinkWidth[i]);
2007 pr_info("XgmiFclkFreq\n");
2008 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
2009 pr_info(" .[%d] = %d\n", i, pptable->XgmiFclkFreq[i]);
2010 pr_info("XgmiSocVoltage\n");
2011 for (i = 0; i < NUM_XGMI_PSTATE_LEVELS; i++)
2012 pr_info(" .[%d] = %d\n", i, pptable->XgmiSocVoltage[i]);
2016 static bool arcturus_is_dpm_running(struct smu_context *smu)
2019 uint32_t feature_mask[2];
2020 unsigned long feature_enabled;
2021 ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
2022 feature_enabled = (unsigned long)((uint64_t)feature_mask[0] |
2023 ((uint64_t)feature_mask[1] << 32));
2024 return !!(feature_enabled & SMC_DPM_FEATURE);
2027 static int arcturus_dpm_set_uvd_enable(struct smu_context *smu, bool enable)
2029 struct smu_power_context *smu_power = &smu->smu_power;
2030 struct smu_power_gate *power_gate = &smu_power->power_gate;
2034 if (!smu_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
2035 ret = smu_feature_set_enabled(smu, SMU_FEATURE_VCN_PG_BIT, 1);
2037 pr_err("[EnableVCNDPM] failed!\n");
2041 power_gate->vcn_gated = false;
2043 if (smu_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
2044 ret = smu_feature_set_enabled(smu, SMU_FEATURE_VCN_PG_BIT, 0);
2046 pr_err("[DisableVCNDPM] failed!\n");
2050 power_gate->vcn_gated = true;
2057 static void arcturus_fill_eeprom_i2c_req(SwI2cRequest_t *req, bool write,
2058 uint8_t address, uint32_t numbytes,
2063 BUG_ON(numbytes > MAX_SW_I2C_COMMANDS);
2065 req->I2CcontrollerPort = 0;
2067 req->SlaveAddress = address;
2068 req->NumCmds = numbytes;
2070 for (i = 0; i < numbytes; i++) {
2071 SwI2cCmd_t *cmd = &req->SwI2cCmds[i];
2073 /* First 2 bytes are always write for lower 2b EEPROM address */
2080 /* Add RESTART for read after address filled */
2081 cmd->CmdConfig |= (i == 2 && !write) ? CMDCONFIG_RESTART_MASK : 0;
2083 /* Add STOP in the end */
2084 cmd->CmdConfig |= (i == (numbytes - 1)) ? CMDCONFIG_STOP_MASK : 0;
2086 /* Fill with data regardless if read or write to simplify code */
2087 cmd->RegisterAddr = data[i];
2091 static int arcturus_i2c_eeprom_read_data(struct i2c_adapter *control,
2096 uint32_t i, ret = 0;
2098 struct amdgpu_device *adev = to_amdgpu_device(control);
2099 struct smu_table_context *smu_table = &adev->smu.smu_table;
2100 struct smu_table *table = &smu_table->driver_table;
2102 memset(&req, 0, sizeof(req));
2103 arcturus_fill_eeprom_i2c_req(&req, false, address, numbytes, data);
2105 mutex_lock(&adev->smu.mutex);
2106 /* Now read data starting with that address */
2107 ret = smu_update_table(&adev->smu, SMU_TABLE_I2C_COMMANDS, 0, &req,
2109 mutex_unlock(&adev->smu.mutex);
2112 SwI2cRequest_t *res = (SwI2cRequest_t *)table->cpu_addr;
2114 /* Assume SMU fills res.SwI2cCmds[i].Data with read bytes */
2115 for (i = 0; i < numbytes; i++)
2116 data[i] = res->SwI2cCmds[i].Data;
2118 pr_debug("arcturus_i2c_eeprom_read_data, address = %x, bytes = %d, data :",
2119 (uint16_t)address, numbytes);
2121 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE,
2122 8, 1, data, numbytes, false);
2124 pr_err("arcturus_i2c_eeprom_read_data - error occurred :%x", ret);
2129 static int arcturus_i2c_eeprom_write_data(struct i2c_adapter *control,
2136 struct amdgpu_device *adev = to_amdgpu_device(control);
2138 memset(&req, 0, sizeof(req));
2139 arcturus_fill_eeprom_i2c_req(&req, true, address, numbytes, data);
2141 mutex_lock(&adev->smu.mutex);
2142 ret = smu_update_table(&adev->smu, SMU_TABLE_I2C_COMMANDS, 0, &req, true);
2143 mutex_unlock(&adev->smu.mutex);
2146 pr_debug("arcturus_i2c_write(), address = %x, bytes = %d , data: ",
2147 (uint16_t)address, numbytes);
2149 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE,
2150 8, 1, data, numbytes, false);
2152 * According to EEPROM spec there is a MAX of 10 ms required for
2153 * EEPROM to flush internal RX buffer after STOP was issued at the
2154 * end of write transaction. During this time the EEPROM will not be
2155 * responsive to any more commands - so wait a bit more.
2160 pr_err("arcturus_i2c_write- error occurred :%x", ret);
2165 static int arcturus_i2c_eeprom_i2c_xfer(struct i2c_adapter *i2c_adap,
2166 struct i2c_msg *msgs, int num)
2168 uint32_t i, j, ret, data_size, data_chunk_size, next_eeprom_addr = 0;
2169 uint8_t *data_ptr, data_chunk[MAX_SW_I2C_COMMANDS] = { 0 };
2171 for (i = 0; i < num; i++) {
2173 * SMU interface allows at most MAX_SW_I2C_COMMANDS bytes of data at
2174 * once and hence the data needs to be spliced into chunks and sent each
2177 data_size = msgs[i].len - 2;
2178 data_chunk_size = MAX_SW_I2C_COMMANDS - 2;
2179 next_eeprom_addr = (msgs[i].buf[0] << 8 & 0xff00) | (msgs[i].buf[1] & 0xff);
2180 data_ptr = msgs[i].buf + 2;
2182 for (j = 0; j < data_size / data_chunk_size; j++) {
2183 /* Insert the EEPROM dest addess, bits 0-15 */
2184 data_chunk[0] = ((next_eeprom_addr >> 8) & 0xff);
2185 data_chunk[1] = (next_eeprom_addr & 0xff);
2187 if (msgs[i].flags & I2C_M_RD) {
2188 ret = arcturus_i2c_eeprom_read_data(i2c_adap,
2189 (uint8_t)msgs[i].addr,
2190 data_chunk, MAX_SW_I2C_COMMANDS);
2192 memcpy(data_ptr, data_chunk + 2, data_chunk_size);
2195 memcpy(data_chunk + 2, data_ptr, data_chunk_size);
2197 ret = arcturus_i2c_eeprom_write_data(i2c_adap,
2198 (uint8_t)msgs[i].addr,
2199 data_chunk, MAX_SW_I2C_COMMANDS);
2207 next_eeprom_addr += data_chunk_size;
2208 data_ptr += data_chunk_size;
2211 if (data_size % data_chunk_size) {
2212 data_chunk[0] = ((next_eeprom_addr >> 8) & 0xff);
2213 data_chunk[1] = (next_eeprom_addr & 0xff);
2215 if (msgs[i].flags & I2C_M_RD) {
2216 ret = arcturus_i2c_eeprom_read_data(i2c_adap,
2217 (uint8_t)msgs[i].addr,
2218 data_chunk, (data_size % data_chunk_size) + 2);
2220 memcpy(data_ptr, data_chunk + 2, data_size % data_chunk_size);
2222 memcpy(data_chunk + 2, data_ptr, data_size % data_chunk_size);
2224 ret = arcturus_i2c_eeprom_write_data(i2c_adap,
2225 (uint8_t)msgs[i].addr,
2226 data_chunk, (data_size % data_chunk_size) + 2);
2240 static u32 arcturus_i2c_eeprom_i2c_func(struct i2c_adapter *adap)
2242 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
2246 static const struct i2c_algorithm arcturus_i2c_eeprom_i2c_algo = {
2247 .master_xfer = arcturus_i2c_eeprom_i2c_xfer,
2248 .functionality = arcturus_i2c_eeprom_i2c_func,
2251 static bool arcturus_i2c_adapter_is_added(struct i2c_adapter *control)
2253 struct amdgpu_device *adev = to_amdgpu_device(control);
2255 return control->dev.parent == &adev->pdev->dev;
2258 static int arcturus_i2c_eeprom_control_init(struct i2c_adapter *control)
2260 struct amdgpu_device *adev = to_amdgpu_device(control);
2263 /* smu_i2c_eeprom_init may be called twice in sriov */
2264 if (arcturus_i2c_adapter_is_added(control))
2267 control->owner = THIS_MODULE;
2268 control->class = I2C_CLASS_SPD;
2269 control->dev.parent = &adev->pdev->dev;
2270 control->algo = &arcturus_i2c_eeprom_i2c_algo;
2271 snprintf(control->name, sizeof(control->name), "AMDGPU EEPROM");
2273 res = i2c_add_adapter(control);
2275 DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
2280 static void arcturus_i2c_eeprom_control_fini(struct i2c_adapter *control)
2282 if (!arcturus_i2c_adapter_is_added(control))
2285 i2c_del_adapter(control);
2288 static void arcturus_get_unique_id(struct smu_context *smu)
2290 struct amdgpu_device *adev = smu->adev;
2291 uint32_t top32, bottom32, smu_version, size;
2295 if (smu_get_smc_version(smu, NULL, &smu_version)) {
2296 pr_warn("Failed to get smu version, cannot get unique_id or serial_number\n");
2300 /* PPSMC_MSG_ReadSerial* is supported by 54.23.0 and onwards */
2301 if (smu_version < 0x361700) {
2302 pr_warn("ReadSerial is only supported by PMFW 54.23.0 and onwards\n");
2306 /* Get the SN to turn into a Unique ID */
2307 smu_send_smc_msg(smu, SMU_MSG_ReadSerialNumTop32, &top32);
2308 smu_send_smc_msg(smu, SMU_MSG_ReadSerialNumBottom32, &bottom32);
2310 id = ((uint64_t)bottom32 << 32) | top32;
2311 adev->unique_id = id;
2312 /* For Arcturus-and-later, unique_id == serial_number, so convert it to a
2313 * 16-digit HEX string for convenience and backwards-compatibility
2315 size = sprintf(sn, "%llx", id);
2316 memcpy(adev->serial, &sn, size);
2319 static bool arcturus_is_baco_supported(struct smu_context *smu)
2321 struct amdgpu_device *adev = smu->adev;
2324 if (!smu_v11_0_baco_is_support(smu) || amdgpu_sriov_vf(adev))
2327 val = RREG32_SOC15(NBIO, 0, mmRCC_BIF_STRAP0);
2328 return (val & RCC_BIF_STRAP0__STRAP_PX_CAPABLE_MASK) ? true : false;
2331 static uint32_t arcturus_get_pptable_power_limit(struct smu_context *smu)
2333 PPTable_t *pptable = smu->smu_table.driver_pptable;
2335 return pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
2338 static int arcturus_set_df_cstate(struct smu_context *smu,
2339 enum pp_df_cstate state)
2341 uint32_t smu_version;
2344 ret = smu_get_smc_version(smu, NULL, &smu_version);
2346 pr_err("Failed to get smu version!\n");
2350 /* PPSMC_MSG_DFCstateControl is supported by 54.15.0 and onwards */
2351 if (smu_version < 0x360F00) {
2352 pr_err("DFCstateControl is only supported by PMFW 54.15.0 and onwards\n");
2356 return smu_send_smc_msg_with_param(smu, SMU_MSG_DFCstateControl, state, NULL);
2359 static int arcturus_allow_xgmi_power_down(struct smu_context *smu, bool en)
2361 uint32_t smu_version;
2364 ret = smu_get_smc_version(smu, NULL, &smu_version);
2366 pr_err("Failed to get smu version!\n");
2370 /* PPSMC_MSG_GmiPwrDnControl is supported by 54.23.0 and onwards */
2371 if (smu_version < 0x00361700) {
2372 pr_err("XGMI power down control is only supported by PMFW 54.23.0 and onwards\n");
2377 return smu_send_smc_msg_with_param(smu,
2378 SMU_MSG_GmiPwrDnControl,
2382 return smu_send_smc_msg_with_param(smu,
2383 SMU_MSG_GmiPwrDnControl,
2388 static const struct throttling_logging_label {
2389 uint32_t feature_mask;
2391 } logging_label[] = {
2392 {(1U << THROTTLER_TEMP_HOTSPOT_BIT), "GPU"},
2393 {(1U << THROTTLER_TEMP_MEM_BIT), "HBM"},
2394 {(1U << THROTTLER_TEMP_VR_GFX_BIT), "VR of GFX rail"},
2395 {(1U << THROTTLER_TEMP_VR_MEM_BIT), "VR of HBM rail"},
2396 {(1U << THROTTLER_TEMP_VR_SOC_BIT), "VR of SOC rail"},
2397 {(1U << THROTTLER_VRHOT0_BIT), "VR0 HOT"},
2398 {(1U << THROTTLER_VRHOT1_BIT), "VR1 HOT"},
2400 static void arcturus_log_thermal_throttling_event(struct smu_context *smu)
2402 int throttler_idx, throtting_events = 0, buf_idx = 0;
2403 struct amdgpu_device *adev = smu->adev;
2404 SmuMetrics_t metrics;
2407 arcturus_get_metrics_table(smu, &metrics);
2409 memset(log_buf, 0, sizeof(log_buf));
2410 for (throttler_idx = 0; throttler_idx < ARRAY_SIZE(logging_label);
2412 if (metrics.ThrottlerStatus & logging_label[throttler_idx].feature_mask) {
2414 buf_idx += snprintf(log_buf + buf_idx,
2415 sizeof(log_buf) - buf_idx,
2417 throtting_events > 1 ? " and " : "",
2418 logging_label[throttler_idx].label);
2419 if (buf_idx >= sizeof(log_buf)) {
2420 pr_err("buffer overflow!\n");
2421 log_buf[sizeof(log_buf) - 1] = '\0';
2427 dev_warn(adev->dev, "WARN: GPU thermal throttling temperature reached, expect performance decrease. %s.\n",
2431 static const struct pptable_funcs arcturus_ppt_funcs = {
2432 /* translate smu index into arcturus specific index */
2433 .get_smu_msg_index = arcturus_get_smu_msg_index,
2434 .get_smu_clk_index = arcturus_get_smu_clk_index,
2435 .get_smu_feature_index = arcturus_get_smu_feature_index,
2436 .get_smu_table_index = arcturus_get_smu_table_index,
2437 .get_smu_power_index= arcturus_get_pwr_src_index,
2438 .get_workload_type = arcturus_get_workload_type,
2439 /* internal structurs allocations */
2440 .tables_init = arcturus_tables_init,
2441 .alloc_dpm_context = arcturus_allocate_dpm_context,
2443 .get_allowed_feature_mask = arcturus_get_allowed_feature_mask,
2445 .run_btc = arcturus_run_btc,
2446 /* dpm/clk tables */
2447 .set_default_dpm_table = arcturus_set_default_dpm_table,
2448 .populate_umd_state_clk = arcturus_populate_umd_state_clk,
2449 .get_thermal_temperature_range = arcturus_get_thermal_temperature_range,
2450 .get_current_clk_freq_by_table = arcturus_get_current_clk_freq_by_table,
2451 .print_clk_levels = arcturus_print_clk_levels,
2452 .force_clk_levels = arcturus_force_clk_levels,
2453 .read_sensor = arcturus_read_sensor,
2454 .get_fan_speed_percent = arcturus_get_fan_speed_percent,
2455 .get_fan_speed_rpm = arcturus_get_fan_speed_rpm,
2456 .force_dpm_limit_value = arcturus_force_dpm_limit_value,
2457 .unforce_dpm_levels = arcturus_unforce_dpm_levels,
2458 .get_profiling_clk_mask = arcturus_get_profiling_clk_mask,
2459 .get_power_profile_mode = arcturus_get_power_profile_mode,
2460 .set_power_profile_mode = arcturus_set_power_profile_mode,
2461 .set_performance_level = arcturus_set_performance_level,
2462 /* debug (internal used) */
2463 .dump_pptable = arcturus_dump_pptable,
2464 .get_power_limit = arcturus_get_power_limit,
2465 .is_dpm_running = arcturus_is_dpm_running,
2466 .dpm_set_uvd_enable = arcturus_dpm_set_uvd_enable,
2467 .i2c_eeprom_init = arcturus_i2c_eeprom_control_init,
2468 .i2c_eeprom_fini = arcturus_i2c_eeprom_control_fini,
2469 .get_unique_id = arcturus_get_unique_id,
2470 .init_microcode = smu_v11_0_init_microcode,
2471 .load_microcode = smu_v11_0_load_microcode,
2472 .init_smc_tables = smu_v11_0_init_smc_tables,
2473 .fini_smc_tables = smu_v11_0_fini_smc_tables,
2474 .init_power = smu_v11_0_init_power,
2475 .fini_power = smu_v11_0_fini_power,
2476 .check_fw_status = smu_v11_0_check_fw_status,
2477 /* pptable related */
2478 .setup_pptable = arcturus_setup_pptable,
2479 .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
2480 .populate_smc_tables = smu_v11_0_populate_smc_pptable,
2481 .check_fw_version = smu_v11_0_check_fw_version,
2482 .write_pptable = smu_v11_0_write_pptable,
2483 .set_min_dcef_deep_sleep = NULL,
2484 .set_driver_table_location = smu_v11_0_set_driver_table_location,
2485 .set_tool_table_location = smu_v11_0_set_tool_table_location,
2486 .notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
2487 .system_features_control = smu_v11_0_system_features_control,
2488 .send_smc_msg_with_param = smu_v11_0_send_msg_with_param,
2489 .init_display_count = NULL,
2490 .set_allowed_mask = smu_v11_0_set_allowed_mask,
2491 .get_enabled_mask = smu_v11_0_get_enabled_mask,
2492 .notify_display_change = NULL,
2493 .set_power_limit = smu_v11_0_set_power_limit,
2494 .get_current_clk_freq = smu_v11_0_get_current_clk_freq,
2495 .init_max_sustainable_clocks = smu_v11_0_init_max_sustainable_clocks,
2496 .enable_thermal_alert = smu_v11_0_enable_thermal_alert,
2497 .disable_thermal_alert = smu_v11_0_disable_thermal_alert,
2498 .set_deep_sleep_dcefclk = smu_v11_0_set_deep_sleep_dcefclk,
2499 .display_clock_voltage_request = smu_v11_0_display_clock_voltage_request,
2500 .get_fan_control_mode = smu_v11_0_get_fan_control_mode,
2501 .set_fan_control_mode = smu_v11_0_set_fan_control_mode,
2502 .set_fan_speed_percent = smu_v11_0_set_fan_speed_percent,
2503 .set_fan_speed_rpm = smu_v11_0_set_fan_speed_rpm,
2504 .set_xgmi_pstate = smu_v11_0_set_xgmi_pstate,
2505 .gfx_off_control = smu_v11_0_gfx_off_control,
2506 .register_irq_handler = smu_v11_0_register_irq_handler,
2507 .set_azalia_d3_pme = smu_v11_0_set_azalia_d3_pme,
2508 .get_max_sustainable_clocks_by_dc = smu_v11_0_get_max_sustainable_clocks_by_dc,
2509 .baco_is_support= arcturus_is_baco_supported,
2510 .baco_get_state = smu_v11_0_baco_get_state,
2511 .baco_set_state = smu_v11_0_baco_set_state,
2512 .baco_enter = smu_v11_0_baco_enter,
2513 .baco_exit = smu_v11_0_baco_exit,
2514 .get_dpm_ultimate_freq = smu_v11_0_get_dpm_ultimate_freq,
2515 .set_soft_freq_limited_range = smu_v11_0_set_soft_freq_limited_range,
2516 .override_pcie_parameters = NULL,
2517 .get_pptable_power_limit = arcturus_get_pptable_power_limit,
2518 .set_df_cstate = arcturus_set_df_cstate,
2519 .allow_xgmi_power_down = arcturus_allow_xgmi_power_down,
2520 .log_thermal_throttling_event = arcturus_log_thermal_throttling_event,
2523 void arcturus_set_ppt_funcs(struct smu_context *smu)
2525 smu->ppt_funcs = &arcturus_ppt_funcs;