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 #define SWSMU_CODE_LAYER_L2
27 #include "amdgpu_smu.h"
28 #include "smu_v12_0_ppsmc.h"
29 #include "smu12_driver_if.h"
30 #include "smu_v12_0.h"
31 #include "renoir_ppt.h"
35 * DO NOT use these for err/warn/info/debug messages.
36 * Use dev_err, dev_warn, dev_info and dev_dbg instead.
37 * They are more MGPU friendly.
44 #define mmMP1_SMN_C2PMSG_66 0x0282
45 #define mmMP1_SMN_C2PMSG_66_BASE_IDX 0
47 #define mmMP1_SMN_C2PMSG_82 0x0292
48 #define mmMP1_SMN_C2PMSG_82_BASE_IDX 0
50 #define mmMP1_SMN_C2PMSG_90 0x029a
51 #define mmMP1_SMN_C2PMSG_90_BASE_IDX 0
53 static struct cmn2asic_msg_mapping renoir_message_map[SMU_MSG_MAX_COUNT] = {
54 MSG_MAP(TestMessage, PPSMC_MSG_TestMessage, 1),
55 MSG_MAP(GetSmuVersion, PPSMC_MSG_GetSmuVersion, 1),
56 MSG_MAP(GetDriverIfVersion, PPSMC_MSG_GetDriverIfVersion, 1),
57 MSG_MAP(PowerUpGfx, PPSMC_MSG_PowerUpGfx, 1),
58 MSG_MAP(AllowGfxOff, PPSMC_MSG_EnableGfxOff, 1),
59 MSG_MAP(DisallowGfxOff, PPSMC_MSG_DisableGfxOff, 1),
60 MSG_MAP(PowerDownIspByTile, PPSMC_MSG_PowerDownIspByTile, 1),
61 MSG_MAP(PowerUpIspByTile, PPSMC_MSG_PowerUpIspByTile, 1),
62 MSG_MAP(PowerDownVcn, PPSMC_MSG_PowerDownVcn, 1),
63 MSG_MAP(PowerUpVcn, PPSMC_MSG_PowerUpVcn, 1),
64 MSG_MAP(PowerDownSdma, PPSMC_MSG_PowerDownSdma, 1),
65 MSG_MAP(PowerUpSdma, PPSMC_MSG_PowerUpSdma, 1),
66 MSG_MAP(SetHardMinIspclkByFreq, PPSMC_MSG_SetHardMinIspclkByFreq, 1),
67 MSG_MAP(SetHardMinVcn, PPSMC_MSG_SetHardMinVcn, 1),
68 MSG_MAP(SetAllowFclkSwitch, PPSMC_MSG_SetAllowFclkSwitch, 1),
69 MSG_MAP(SetMinVideoGfxclkFreq, PPSMC_MSG_SetMinVideoGfxclkFreq, 1),
70 MSG_MAP(ActiveProcessNotify, PPSMC_MSG_ActiveProcessNotify, 1),
71 MSG_MAP(SetCustomPolicy, PPSMC_MSG_SetCustomPolicy, 1),
72 MSG_MAP(SetVideoFps, PPSMC_MSG_SetVideoFps, 1),
73 MSG_MAP(NumOfDisplays, PPSMC_MSG_SetDisplayCount, 1),
74 MSG_MAP(QueryPowerLimit, PPSMC_MSG_QueryPowerLimit, 1),
75 MSG_MAP(SetDriverDramAddrHigh, PPSMC_MSG_SetDriverDramAddrHigh, 1),
76 MSG_MAP(SetDriverDramAddrLow, PPSMC_MSG_SetDriverDramAddrLow, 1),
77 MSG_MAP(TransferTableSmu2Dram, PPSMC_MSG_TransferTableSmu2Dram, 1),
78 MSG_MAP(TransferTableDram2Smu, PPSMC_MSG_TransferTableDram2Smu, 1),
79 MSG_MAP(GfxDeviceDriverReset, PPSMC_MSG_GfxDeviceDriverReset, 1),
80 MSG_MAP(SetGfxclkOverdriveByFreqVid, PPSMC_MSG_SetGfxclkOverdriveByFreqVid, 1),
81 MSG_MAP(SetHardMinDcfclkByFreq, PPSMC_MSG_SetHardMinDcfclkByFreq, 1),
82 MSG_MAP(SetHardMinSocclkByFreq, PPSMC_MSG_SetHardMinSocclkByFreq, 1),
83 MSG_MAP(ControlIgpuATS, PPSMC_MSG_ControlIgpuATS, 1),
84 MSG_MAP(SetMinVideoFclkFreq, PPSMC_MSG_SetMinVideoFclkFreq, 1),
85 MSG_MAP(SetMinDeepSleepDcfclk, PPSMC_MSG_SetMinDeepSleepDcfclk, 1),
86 MSG_MAP(ForcePowerDownGfx, PPSMC_MSG_ForcePowerDownGfx, 1),
87 MSG_MAP(SetPhyclkVoltageByFreq, PPSMC_MSG_SetPhyclkVoltageByFreq, 1),
88 MSG_MAP(SetDppclkVoltageByFreq, PPSMC_MSG_SetDppclkVoltageByFreq, 1),
89 MSG_MAP(SetSoftMinVcn, PPSMC_MSG_SetSoftMinVcn, 1),
90 MSG_MAP(EnablePostCode, PPSMC_MSG_EnablePostCode, 1),
91 MSG_MAP(GetGfxclkFrequency, PPSMC_MSG_GetGfxclkFrequency, 1),
92 MSG_MAP(GetFclkFrequency, PPSMC_MSG_GetFclkFrequency, 1),
93 MSG_MAP(GetMinGfxclkFrequency, PPSMC_MSG_GetMinGfxclkFrequency, 1),
94 MSG_MAP(GetMaxGfxclkFrequency, PPSMC_MSG_GetMaxGfxclkFrequency, 1),
95 MSG_MAP(SoftReset, PPSMC_MSG_SoftReset, 1),
96 MSG_MAP(SetGfxCGPG, PPSMC_MSG_SetGfxCGPG, 1),
97 MSG_MAP(SetSoftMaxGfxClk, PPSMC_MSG_SetSoftMaxGfxClk, 1),
98 MSG_MAP(SetHardMinGfxClk, PPSMC_MSG_SetHardMinGfxClk, 1),
99 MSG_MAP(SetSoftMaxSocclkByFreq, PPSMC_MSG_SetSoftMaxSocclkByFreq, 1),
100 MSG_MAP(SetSoftMaxFclkByFreq, PPSMC_MSG_SetSoftMaxFclkByFreq, 1),
101 MSG_MAP(SetSoftMaxVcn, PPSMC_MSG_SetSoftMaxVcn, 1),
102 MSG_MAP(PowerGateMmHub, PPSMC_MSG_PowerGateMmHub, 1),
103 MSG_MAP(UpdatePmeRestore, PPSMC_MSG_UpdatePmeRestore, 1),
104 MSG_MAP(GpuChangeState, PPSMC_MSG_GpuChangeState, 1),
105 MSG_MAP(SetPowerLimitPercentage, PPSMC_MSG_SetPowerLimitPercentage, 1),
106 MSG_MAP(ForceGfxContentSave, PPSMC_MSG_ForceGfxContentSave, 1),
107 MSG_MAP(EnableTmdp48MHzRefclkPwrDown, PPSMC_MSG_EnableTmdp48MHzRefclkPwrDown, 1),
108 MSG_MAP(PowerDownJpeg, PPSMC_MSG_PowerDownJpeg, 1),
109 MSG_MAP(PowerUpJpeg, PPSMC_MSG_PowerUpJpeg, 1),
110 MSG_MAP(PowerGateAtHub, PPSMC_MSG_PowerGateAtHub, 1),
111 MSG_MAP(SetSoftMinJpeg, PPSMC_MSG_SetSoftMinJpeg, 1),
112 MSG_MAP(SetHardMinFclkByFreq, PPSMC_MSG_SetHardMinFclkByFreq, 1),
115 static struct cmn2asic_mapping renoir_clk_map[SMU_CLK_COUNT] = {
116 CLK_MAP(GFXCLK, CLOCK_GFXCLK),
117 CLK_MAP(SCLK, CLOCK_GFXCLK),
118 CLK_MAP(SOCCLK, CLOCK_SOCCLK),
119 CLK_MAP(UCLK, CLOCK_FCLK),
120 CLK_MAP(MCLK, CLOCK_FCLK),
121 CLK_MAP(VCLK, CLOCK_VCLK),
122 CLK_MAP(DCLK, CLOCK_DCLK),
125 static struct cmn2asic_mapping renoir_table_map[SMU_TABLE_COUNT] = {
126 TAB_MAP_VALID(WATERMARKS),
127 TAB_MAP_INVALID(CUSTOM_DPM),
128 TAB_MAP_VALID(DPMCLOCKS),
129 TAB_MAP_VALID(SMU_METRICS),
132 static struct cmn2asic_mapping renoir_workload_map[PP_SMC_POWER_PROFILE_COUNT] = {
133 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_FULLSCREEN3D, WORKLOAD_PPLIB_FULL_SCREEN_3D_BIT),
134 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VIDEO, WORKLOAD_PPLIB_VIDEO_BIT),
135 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_VR, WORKLOAD_PPLIB_VR_BIT),
136 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_COMPUTE, WORKLOAD_PPLIB_COMPUTE_BIT),
137 WORKLOAD_MAP(PP_SMC_POWER_PROFILE_CUSTOM, WORKLOAD_PPLIB_CUSTOM_BIT),
140 static const uint8_t renoir_throttler_map[] = {
141 [THROTTLER_STATUS_BIT_SPL] = (SMU_THROTTLER_SPL_BIT),
142 [THROTTLER_STATUS_BIT_FPPT] = (SMU_THROTTLER_FPPT_BIT),
143 [THROTTLER_STATUS_BIT_SPPT] = (SMU_THROTTLER_SPPT_BIT),
144 [THROTTLER_STATUS_BIT_SPPT_APU] = (SMU_THROTTLER_SPPT_APU_BIT),
145 [THROTTLER_STATUS_BIT_THM_CORE] = (SMU_THROTTLER_TEMP_CORE_BIT),
146 [THROTTLER_STATUS_BIT_THM_GFX] = (SMU_THROTTLER_TEMP_GPU_BIT),
147 [THROTTLER_STATUS_BIT_THM_SOC] = (SMU_THROTTLER_TEMP_SOC_BIT),
148 [THROTTLER_STATUS_BIT_TDC_VDD] = (SMU_THROTTLER_TDC_VDD_BIT),
149 [THROTTLER_STATUS_BIT_TDC_SOC] = (SMU_THROTTLER_TDC_SOC_BIT),
150 [THROTTLER_STATUS_BIT_PROCHOT_CPU] = (SMU_THROTTLER_PROCHOT_CPU_BIT),
151 [THROTTLER_STATUS_BIT_PROCHOT_GFX] = (SMU_THROTTLER_PROCHOT_GFX_BIT),
152 [THROTTLER_STATUS_BIT_EDC_CPU] = (SMU_THROTTLER_EDC_CPU_BIT),
153 [THROTTLER_STATUS_BIT_EDC_GFX] = (SMU_THROTTLER_EDC_GFX_BIT),
156 static int renoir_init_smc_tables(struct smu_context *smu)
158 struct smu_table_context *smu_table = &smu->smu_table;
159 struct smu_table *tables = smu_table->tables;
161 SMU_TABLE_INIT(tables, SMU_TABLE_WATERMARKS, sizeof(Watermarks_t),
162 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
163 SMU_TABLE_INIT(tables, SMU_TABLE_DPMCLOCKS, sizeof(DpmClocks_t),
164 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
165 SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
166 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
168 smu_table->clocks_table = kzalloc(sizeof(DpmClocks_t), GFP_KERNEL);
169 if (!smu_table->clocks_table)
172 smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
173 if (!smu_table->metrics_table)
175 smu_table->metrics_time = 0;
177 smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
178 if (!smu_table->watermarks_table)
181 smu_table->gpu_metrics_table_size = sizeof(struct gpu_metrics_v2_2);
182 smu_table->gpu_metrics_table = kzalloc(smu_table->gpu_metrics_table_size, GFP_KERNEL);
183 if (!smu_table->gpu_metrics_table)
189 kfree(smu_table->watermarks_table);
191 kfree(smu_table->metrics_table);
193 kfree(smu_table->clocks_table);
199 * This interface just for getting uclk ultimate freq and should't introduce
200 * other likewise function result in overmuch callback.
202 static int renoir_get_dpm_clk_limited(struct smu_context *smu, enum smu_clk_type clk_type,
203 uint32_t dpm_level, uint32_t *freq)
205 DpmClocks_t *clk_table = smu->smu_table.clocks_table;
207 if (!clk_table || clk_type >= SMU_CLK_COUNT)
212 if (dpm_level >= NUM_SOCCLK_DPM_LEVELS)
214 *freq = clk_table->SocClocks[dpm_level].Freq;
218 if (dpm_level >= NUM_FCLK_DPM_LEVELS)
220 *freq = clk_table->FClocks[dpm_level].Freq;
223 if (dpm_level >= NUM_DCFCLK_DPM_LEVELS)
225 *freq = clk_table->DcfClocks[dpm_level].Freq;
228 if (dpm_level >= NUM_FCLK_DPM_LEVELS)
230 *freq = clk_table->FClocks[dpm_level].Freq;
233 if (dpm_level >= NUM_VCN_DPM_LEVELS)
235 *freq = clk_table->VClocks[dpm_level].Freq;
238 if (dpm_level >= NUM_VCN_DPM_LEVELS)
240 *freq = clk_table->DClocks[dpm_level].Freq;
250 static int renoir_get_profiling_clk_mask(struct smu_context *smu,
251 enum amd_dpm_forced_level level,
257 if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) {
260 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) {
262 /* mclk levels are in reverse order */
263 *mclk_mask = NUM_MEMCLK_DPM_LEVELS - 1;
264 } else if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) {
266 /* The sclk as gfxclk and has three level about max/min/current */
270 /* mclk levels are in reverse order */
274 *soc_mask = NUM_SOCCLK_DPM_LEVELS - 1;
280 static int renoir_get_dpm_ultimate_freq(struct smu_context *smu,
281 enum smu_clk_type clk_type,
286 uint32_t mclk_mask, soc_mask;
287 uint32_t clock_limit;
289 if (!smu_cmn_clk_dpm_is_enabled(smu, clk_type)) {
293 clock_limit = smu->smu_table.boot_values.uclk;
297 clock_limit = smu->smu_table.boot_values.gfxclk;
300 clock_limit = smu->smu_table.boot_values.socclk;
307 /* clock in Mhz unit */
309 *min = clock_limit / 100;
311 *max = clock_limit / 100;
317 ret = renoir_get_profiling_clk_mask(smu,
318 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK,
328 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_GetMaxGfxclkFrequency, max);
330 dev_err(smu->adev->dev, "Attempt to get max GX frequency from SMC Failed !\n");
337 ret = renoir_get_dpm_clk_limited(smu, clk_type, mclk_mask, max);
342 ret = renoir_get_dpm_clk_limited(smu, clk_type, soc_mask, max);
356 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_GetMinGfxclkFrequency, min);
358 dev_err(smu->adev->dev, "Attempt to get min GX frequency from SMC Failed !\n");
365 ret = renoir_get_dpm_clk_limited(smu, clk_type, NUM_MEMCLK_DPM_LEVELS - 1, min);
370 ret = renoir_get_dpm_clk_limited(smu, clk_type, 0, min);
383 static int renoir_od_edit_dpm_table(struct smu_context *smu,
384 enum PP_OD_DPM_TABLE_COMMAND type,
385 long input[], uint32_t size)
388 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
390 if (!(smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL)) {
391 dev_warn(smu->adev->dev,
392 "pp_od_clk_voltage is not accessible if power_dpm_force_performance_level is not in manual mode!\n");
397 case PP_OD_EDIT_SCLK_VDDC_TABLE:
399 dev_err(smu->adev->dev, "Input parameter number not correct\n");
404 if (input[1] < smu->gfx_default_hard_min_freq) {
405 dev_warn(smu->adev->dev,
406 "Fine grain setting minimum sclk (%ld) MHz is less than the minimum allowed (%d) MHz\n",
407 input[1], smu->gfx_default_hard_min_freq);
410 smu->gfx_actual_hard_min_freq = input[1];
411 } else if (input[0] == 1) {
412 if (input[1] > smu->gfx_default_soft_max_freq) {
413 dev_warn(smu->adev->dev,
414 "Fine grain setting maximum sclk (%ld) MHz is greater than the maximum allowed (%d) MHz\n",
415 input[1], smu->gfx_default_soft_max_freq);
418 smu->gfx_actual_soft_max_freq = input[1];
423 case PP_OD_RESTORE_DEFAULT_TABLE:
425 dev_err(smu->adev->dev, "Input parameter number not correct\n");
428 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
429 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
431 case PP_OD_COMMIT_DPM_TABLE:
433 dev_err(smu->adev->dev, "Input parameter number not correct\n");
436 if (smu->gfx_actual_hard_min_freq > smu->gfx_actual_soft_max_freq) {
437 dev_err(smu->adev->dev,
438 "The setting minimum sclk (%d) MHz is greater than the setting maximum sclk (%d) MHz\n",
439 smu->gfx_actual_hard_min_freq,
440 smu->gfx_actual_soft_max_freq);
444 ret = smu_cmn_send_smc_msg_with_param(smu,
445 SMU_MSG_SetHardMinGfxClk,
446 smu->gfx_actual_hard_min_freq,
449 dev_err(smu->adev->dev, "Set hard min sclk failed!");
453 ret = smu_cmn_send_smc_msg_with_param(smu,
454 SMU_MSG_SetSoftMaxGfxClk,
455 smu->gfx_actual_soft_max_freq,
458 dev_err(smu->adev->dev, "Set soft max sclk failed!");
470 static int renoir_set_fine_grain_gfx_freq_parameters(struct smu_context *smu)
472 uint32_t min = 0, max = 0;
475 ret = smu_cmn_send_smc_msg_with_param(smu,
476 SMU_MSG_GetMinGfxclkFrequency,
480 ret = smu_cmn_send_smc_msg_with_param(smu,
481 SMU_MSG_GetMaxGfxclkFrequency,
486 smu->gfx_default_hard_min_freq = min;
487 smu->gfx_default_soft_max_freq = max;
488 smu->gfx_actual_hard_min_freq = 0;
489 smu->gfx_actual_soft_max_freq = 0;
494 static int renoir_print_clk_levels(struct smu_context *smu,
495 enum smu_clk_type clk_type, char *buf)
497 int i, idx, size = 0, ret = 0;
498 uint32_t cur_value = 0, value = 0, count = 0, min = 0, max = 0;
499 SmuMetrics_t metrics;
500 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
501 bool cur_value_match_level = false;
503 memset(&metrics, 0, sizeof(metrics));
505 ret = smu_cmn_get_metrics_table(smu, &metrics, false);
509 smu_cmn_get_sysfs_buf(&buf, &size);
513 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) {
514 ret = smu_cmn_send_smc_msg_with_param(smu,
515 SMU_MSG_GetMinGfxclkFrequency,
519 ret = smu_cmn_send_smc_msg_with_param(smu,
520 SMU_MSG_GetMaxGfxclkFrequency,
524 size += sysfs_emit_at(buf, size, "OD_RANGE\nSCLK: %10uMhz %10uMhz\n", min, max);
528 if (smu_dpm_ctx->dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL) {
529 min = (smu->gfx_actual_hard_min_freq > 0) ? smu->gfx_actual_hard_min_freq : smu->gfx_default_hard_min_freq;
530 max = (smu->gfx_actual_soft_max_freq > 0) ? smu->gfx_actual_soft_max_freq : smu->gfx_default_soft_max_freq;
531 size += sysfs_emit_at(buf, size, "OD_SCLK\n");
532 size += sysfs_emit_at(buf, size, "0:%10uMhz\n", min);
533 size += sysfs_emit_at(buf, size, "1:%10uMhz\n", max);
538 /* retirve table returned paramters unit is MHz */
539 cur_value = metrics.ClockFrequency[CLOCK_GFXCLK];
540 ret = renoir_get_dpm_ultimate_freq(smu, SMU_GFXCLK, &min, &max);
542 /* driver only know min/max gfx_clk, Add level 1 for all other gfx clks */
543 if (cur_value == max)
545 else if (cur_value == min)
550 size += sysfs_emit_at(buf, size, "0: %uMhz %s\n", min,
552 size += sysfs_emit_at(buf, size, "1: %uMhz %s\n",
553 i == 1 ? cur_value : RENOIR_UMD_PSTATE_GFXCLK,
555 size += sysfs_emit_at(buf, size, "2: %uMhz %s\n", max,
560 count = NUM_SOCCLK_DPM_LEVELS;
561 cur_value = metrics.ClockFrequency[CLOCK_SOCCLK];
564 count = NUM_MEMCLK_DPM_LEVELS;
565 cur_value = metrics.ClockFrequency[CLOCK_FCLK];
568 count = NUM_DCFCLK_DPM_LEVELS;
569 cur_value = metrics.ClockFrequency[CLOCK_DCFCLK];
572 count = NUM_FCLK_DPM_LEVELS;
573 cur_value = metrics.ClockFrequency[CLOCK_FCLK];
576 count = NUM_VCN_DPM_LEVELS;
577 cur_value = metrics.ClockFrequency[CLOCK_VCLK];
580 count = NUM_VCN_DPM_LEVELS;
581 cur_value = metrics.ClockFrequency[CLOCK_DCLK];
596 for (i = 0; i < count; i++) {
597 idx = (clk_type == SMU_FCLK || clk_type == SMU_MCLK) ? (count - i - 1) : i;
598 ret = renoir_get_dpm_clk_limited(smu, clk_type, idx, &value);
603 size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, value,
604 cur_value == value ? "*" : "");
605 if (cur_value == value)
606 cur_value_match_level = true;
609 if (!cur_value_match_level)
610 size += sysfs_emit_at(buf, size, " %uMhz *\n", cur_value);
620 static enum amd_pm_state_type renoir_get_current_power_state(struct smu_context *smu)
622 enum amd_pm_state_type pm_type;
623 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
625 if (!smu_dpm_ctx->dpm_context ||
626 !smu_dpm_ctx->dpm_current_power_state)
629 switch (smu_dpm_ctx->dpm_current_power_state->classification.ui_label) {
630 case SMU_STATE_UI_LABEL_BATTERY:
631 pm_type = POWER_STATE_TYPE_BATTERY;
633 case SMU_STATE_UI_LABEL_BALLANCED:
634 pm_type = POWER_STATE_TYPE_BALANCED;
636 case SMU_STATE_UI_LABEL_PERFORMANCE:
637 pm_type = POWER_STATE_TYPE_PERFORMANCE;
640 if (smu_dpm_ctx->dpm_current_power_state->classification.flags & SMU_STATE_CLASSIFICATION_FLAG_BOOT)
641 pm_type = POWER_STATE_TYPE_INTERNAL_BOOT;
643 pm_type = POWER_STATE_TYPE_DEFAULT;
650 static int renoir_dpm_set_vcn_enable(struct smu_context *smu, bool enable)
655 /* vcn dpm on is a prerequisite for vcn power gate messages */
656 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
657 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_PowerUpVcn, 0, NULL);
662 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
663 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_PowerDownVcn, NULL);
672 static int renoir_dpm_set_jpeg_enable(struct smu_context *smu, bool enable)
677 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_JPEG_PG_BIT)) {
678 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_PowerUpJpeg, 0, NULL);
683 if (smu_cmn_feature_is_enabled(smu, SMU_FEATURE_JPEG_PG_BIT)) {
684 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_PowerDownJpeg, 0, NULL);
693 static int renoir_force_dpm_limit_value(struct smu_context *smu, bool highest)
696 uint32_t min_freq, max_freq, force_freq;
697 enum smu_clk_type clk_type;
699 enum smu_clk_type clks[] = {
705 for (i = 0; i < ARRAY_SIZE(clks); i++) {
707 ret = renoir_get_dpm_ultimate_freq(smu, clk_type, &min_freq, &max_freq);
711 force_freq = highest ? max_freq : min_freq;
712 ret = smu_v12_0_set_soft_freq_limited_range(smu, clk_type, force_freq, force_freq);
720 static int renoir_unforce_dpm_levels(struct smu_context *smu) {
723 uint32_t min_freq, max_freq;
724 enum smu_clk_type clk_type;
726 struct clk_feature_map {
727 enum smu_clk_type clk_type;
729 } clk_feature_map[] = {
730 {SMU_GFXCLK, SMU_FEATURE_DPM_GFXCLK_BIT},
731 {SMU_MCLK, SMU_FEATURE_DPM_UCLK_BIT},
732 {SMU_SOCCLK, SMU_FEATURE_DPM_SOCCLK_BIT},
735 for (i = 0; i < ARRAY_SIZE(clk_feature_map); i++) {
736 if (!smu_cmn_feature_is_enabled(smu, clk_feature_map[i].feature))
739 clk_type = clk_feature_map[i].clk_type;
741 ret = renoir_get_dpm_ultimate_freq(smu, clk_type, &min_freq, &max_freq);
745 ret = smu_v12_0_set_soft_freq_limited_range(smu, clk_type, min_freq, max_freq);
754 * This interface get dpm clock table for dc
756 static int renoir_get_dpm_clock_table(struct smu_context *smu, struct dpm_clocks *clock_table)
758 DpmClocks_t *table = smu->smu_table.clocks_table;
761 if (!clock_table || !table)
764 for (i = 0; i < NUM_DCFCLK_DPM_LEVELS; i++) {
765 clock_table->DcfClocks[i].Freq = table->DcfClocks[i].Freq;
766 clock_table->DcfClocks[i].Vol = table->DcfClocks[i].Vol;
769 for (i = 0; i < NUM_SOCCLK_DPM_LEVELS; i++) {
770 clock_table->SocClocks[i].Freq = table->SocClocks[i].Freq;
771 clock_table->SocClocks[i].Vol = table->SocClocks[i].Vol;
774 for (i = 0; i < NUM_FCLK_DPM_LEVELS; i++) {
775 clock_table->FClocks[i].Freq = table->FClocks[i].Freq;
776 clock_table->FClocks[i].Vol = table->FClocks[i].Vol;
779 for (i = 0; i< NUM_MEMCLK_DPM_LEVELS; i++) {
780 clock_table->MemClocks[i].Freq = table->MemClocks[i].Freq;
781 clock_table->MemClocks[i].Vol = table->MemClocks[i].Vol;
784 for (i = 0; i < NUM_VCN_DPM_LEVELS; i++) {
785 clock_table->VClocks[i].Freq = table->VClocks[i].Freq;
786 clock_table->VClocks[i].Vol = table->VClocks[i].Vol;
789 for (i = 0; i < NUM_VCN_DPM_LEVELS; i++) {
790 clock_table->DClocks[i].Freq = table->DClocks[i].Freq;
791 clock_table->DClocks[i].Vol = table->DClocks[i].Vol;
797 static int renoir_force_clk_levels(struct smu_context *smu,
798 enum smu_clk_type clk_type, uint32_t mask)
802 uint32_t soft_min_level = 0, soft_max_level = 0, min_freq = 0, max_freq = 0;
804 soft_min_level = mask ? (ffs(mask) - 1) : 0;
805 soft_max_level = mask ? (fls(mask) - 1) : 0;
810 if (soft_min_level > 2 || soft_max_level > 2) {
811 dev_info(smu->adev->dev, "Currently sclk only support 3 levels on APU\n");
815 ret = renoir_get_dpm_ultimate_freq(smu, SMU_GFXCLK, &min_freq, &max_freq);
818 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMaxGfxClk,
819 soft_max_level == 0 ? min_freq :
820 soft_max_level == 1 ? RENOIR_UMD_PSTATE_GFXCLK : max_freq,
824 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinGfxClk,
825 soft_min_level == 2 ? max_freq :
826 soft_min_level == 1 ? RENOIR_UMD_PSTATE_GFXCLK : min_freq,
832 ret = renoir_get_dpm_clk_limited(smu, clk_type, soft_min_level, &min_freq);
835 ret = renoir_get_dpm_clk_limited(smu, clk_type, soft_max_level, &max_freq);
838 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMaxSocclkByFreq, max_freq, NULL);
841 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinSocclkByFreq, min_freq, NULL);
847 ret = renoir_get_dpm_clk_limited(smu, clk_type, soft_min_level, &min_freq);
850 ret = renoir_get_dpm_clk_limited(smu, clk_type, soft_max_level, &max_freq);
853 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetSoftMaxFclkByFreq, max_freq, NULL);
856 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinFclkByFreq, min_freq, NULL);
867 static int renoir_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)
869 int workload_type, ret;
870 uint32_t profile_mode = input[size];
872 if (profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
873 dev_err(smu->adev->dev, "Invalid power profile mode %d\n", profile_mode);
877 if (profile_mode == PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT ||
878 profile_mode == PP_SMC_POWER_PROFILE_POWERSAVING)
881 /* conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT */
882 workload_type = smu_cmn_to_asic_specific_index(smu,
883 CMN2ASIC_MAPPING_WORKLOAD,
885 if (workload_type < 0) {
887 * TODO: If some case need switch to powersave/default power mode
888 * then can consider enter WORKLOAD_COMPUTE/WORKLOAD_CUSTOM for power saving.
890 dev_dbg(smu->adev->dev, "Unsupported power profile mode %d on RENOIR\n", profile_mode);
894 ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_ActiveProcessNotify,
898 dev_err_once(smu->adev->dev, "Fail to set workload type %d\n", workload_type);
902 smu->power_profile_mode = profile_mode;
907 static int renoir_set_peak_clock_by_device(struct smu_context *smu)
910 uint32_t sclk_freq = 0, uclk_freq = 0;
912 ret = renoir_get_dpm_ultimate_freq(smu, SMU_SCLK, NULL, &sclk_freq);
916 ret = smu_v12_0_set_soft_freq_limited_range(smu, SMU_SCLK, sclk_freq, sclk_freq);
920 ret = renoir_get_dpm_ultimate_freq(smu, SMU_UCLK, NULL, &uclk_freq);
924 ret = smu_v12_0_set_soft_freq_limited_range(smu, SMU_UCLK, uclk_freq, uclk_freq);
931 static int renoir_set_performance_level(struct smu_context *smu,
932 enum amd_dpm_forced_level level)
935 uint32_t sclk_mask, mclk_mask, soc_mask;
938 case AMD_DPM_FORCED_LEVEL_HIGH:
939 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
940 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
942 ret = renoir_force_dpm_limit_value(smu, true);
944 case AMD_DPM_FORCED_LEVEL_LOW:
945 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
946 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
948 ret = renoir_force_dpm_limit_value(smu, false);
950 case AMD_DPM_FORCED_LEVEL_AUTO:
951 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
952 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
954 ret = renoir_unforce_dpm_levels(smu);
956 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
957 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
958 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
960 ret = smu_cmn_send_smc_msg_with_param(smu,
961 SMU_MSG_SetHardMinGfxClk,
962 RENOIR_UMD_PSTATE_GFXCLK,
966 ret = smu_cmn_send_smc_msg_with_param(smu,
967 SMU_MSG_SetHardMinFclkByFreq,
968 RENOIR_UMD_PSTATE_FCLK,
972 ret = smu_cmn_send_smc_msg_with_param(smu,
973 SMU_MSG_SetHardMinSocclkByFreq,
974 RENOIR_UMD_PSTATE_SOCCLK,
978 ret = smu_cmn_send_smc_msg_with_param(smu,
979 SMU_MSG_SetHardMinVcn,
980 RENOIR_UMD_PSTATE_VCNCLK,
985 ret = smu_cmn_send_smc_msg_with_param(smu,
986 SMU_MSG_SetSoftMaxGfxClk,
987 RENOIR_UMD_PSTATE_GFXCLK,
991 ret = smu_cmn_send_smc_msg_with_param(smu,
992 SMU_MSG_SetSoftMaxFclkByFreq,
993 RENOIR_UMD_PSTATE_FCLK,
997 ret = smu_cmn_send_smc_msg_with_param(smu,
998 SMU_MSG_SetSoftMaxSocclkByFreq,
999 RENOIR_UMD_PSTATE_SOCCLK,
1003 ret = smu_cmn_send_smc_msg_with_param(smu,
1004 SMU_MSG_SetSoftMaxVcn,
1005 RENOIR_UMD_PSTATE_VCNCLK,
1010 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
1011 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
1012 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
1013 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
1015 ret = renoir_get_profiling_clk_mask(smu, level,
1021 renoir_force_clk_levels(smu, SMU_SCLK, 1 << sclk_mask);
1022 renoir_force_clk_levels(smu, SMU_MCLK, 1 << mclk_mask);
1023 renoir_force_clk_levels(smu, SMU_SOCCLK, 1 << soc_mask);
1025 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
1026 smu->gfx_actual_hard_min_freq = smu->gfx_default_hard_min_freq;
1027 smu->gfx_actual_soft_max_freq = smu->gfx_default_soft_max_freq;
1029 ret = renoir_set_peak_clock_by_device(smu);
1031 case AMD_DPM_FORCED_LEVEL_MANUAL:
1032 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
1039 /* save watermark settings into pplib smu structure,
1040 * also pass data to smu controller
1042 static int renoir_set_watermarks_table(
1043 struct smu_context *smu,
1044 struct pp_smu_wm_range_sets *clock_ranges)
1046 Watermarks_t *table = smu->smu_table.watermarks_table;
1051 if (clock_ranges->num_reader_wm_sets > NUM_WM_RANGES ||
1052 clock_ranges->num_writer_wm_sets > NUM_WM_RANGES)
1055 /* save into smu->smu_table.tables[SMU_TABLE_WATERMARKS]->cpu_addr*/
1056 for (i = 0; i < clock_ranges->num_reader_wm_sets; i++) {
1057 table->WatermarkRow[WM_DCFCLK][i].MinClock =
1058 clock_ranges->reader_wm_sets[i].min_drain_clk_mhz;
1059 table->WatermarkRow[WM_DCFCLK][i].MaxClock =
1060 clock_ranges->reader_wm_sets[i].max_drain_clk_mhz;
1061 table->WatermarkRow[WM_DCFCLK][i].MinMclk =
1062 clock_ranges->reader_wm_sets[i].min_fill_clk_mhz;
1063 table->WatermarkRow[WM_DCFCLK][i].MaxMclk =
1064 clock_ranges->reader_wm_sets[i].max_fill_clk_mhz;
1066 table->WatermarkRow[WM_DCFCLK][i].WmSetting =
1067 clock_ranges->reader_wm_sets[i].wm_inst;
1068 table->WatermarkRow[WM_DCFCLK][i].WmType =
1069 clock_ranges->reader_wm_sets[i].wm_type;
1072 for (i = 0; i < clock_ranges->num_writer_wm_sets; i++) {
1073 table->WatermarkRow[WM_SOCCLK][i].MinClock =
1074 clock_ranges->writer_wm_sets[i].min_fill_clk_mhz;
1075 table->WatermarkRow[WM_SOCCLK][i].MaxClock =
1076 clock_ranges->writer_wm_sets[i].max_fill_clk_mhz;
1077 table->WatermarkRow[WM_SOCCLK][i].MinMclk =
1078 clock_ranges->writer_wm_sets[i].min_drain_clk_mhz;
1079 table->WatermarkRow[WM_SOCCLK][i].MaxMclk =
1080 clock_ranges->writer_wm_sets[i].max_drain_clk_mhz;
1082 table->WatermarkRow[WM_SOCCLK][i].WmSetting =
1083 clock_ranges->writer_wm_sets[i].wm_inst;
1084 table->WatermarkRow[WM_SOCCLK][i].WmType =
1085 clock_ranges->writer_wm_sets[i].wm_type;
1088 smu->watermarks_bitmap |= WATERMARKS_EXIST;
1091 /* pass data to smu controller */
1092 if ((smu->watermarks_bitmap & WATERMARKS_EXIST) &&
1093 !(smu->watermarks_bitmap & WATERMARKS_LOADED)) {
1094 ret = smu_cmn_write_watermarks_table(smu);
1096 dev_err(smu->adev->dev, "Failed to update WMTABLE!");
1099 smu->watermarks_bitmap |= WATERMARKS_LOADED;
1105 static int renoir_get_power_profile_mode(struct smu_context *smu,
1108 uint32_t i, size = 0;
1109 int16_t workload_type = 0;
1114 for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
1116 * Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT
1117 * Not all profile modes are supported on arcturus.
1119 workload_type = smu_cmn_to_asic_specific_index(smu,
1120 CMN2ASIC_MAPPING_WORKLOAD,
1122 if (workload_type < 0)
1125 size += sysfs_emit_at(buf, size, "%2d %14s%s\n",
1126 i, amdgpu_pp_profile_name[i], (i == smu->power_profile_mode) ? "*" : " ");
1132 static void renoir_get_ss_power_percent(SmuMetrics_t *metrics,
1133 uint32_t *apu_percent, uint32_t *dgpu_percent)
1135 uint32_t apu_boost = 0;
1136 uint32_t dgpu_boost = 0;
1137 uint16_t apu_limit = 0;
1138 uint16_t dgpu_limit = 0;
1139 uint16_t apu_power = 0;
1140 uint16_t dgpu_power = 0;
1142 apu_power = metrics->ApuPower;
1143 apu_limit = metrics->StapmOriginalLimit;
1144 if (apu_power > apu_limit && apu_limit != 0)
1145 apu_boost = ((apu_power - apu_limit) * 100) / apu_limit;
1146 apu_boost = (apu_boost > 100) ? 100 : apu_boost;
1148 dgpu_power = metrics->dGpuPower;
1149 if (metrics->StapmCurrentLimit > metrics->StapmOriginalLimit)
1150 dgpu_limit = metrics->StapmCurrentLimit - metrics->StapmOriginalLimit;
1151 if (dgpu_power > dgpu_limit && dgpu_limit != 0)
1152 dgpu_boost = ((dgpu_power - dgpu_limit) * 100) / dgpu_limit;
1153 dgpu_boost = (dgpu_boost > 100) ? 100 : dgpu_boost;
1155 if (dgpu_boost >= apu_boost)
1160 *apu_percent = apu_boost;
1161 *dgpu_percent = dgpu_boost;
1165 static int renoir_get_smu_metrics_data(struct smu_context *smu,
1166 MetricsMember_t member,
1169 struct smu_table_context *smu_table = &smu->smu_table;
1171 SmuMetrics_t *metrics = (SmuMetrics_t *)smu_table->metrics_table;
1173 uint32_t apu_percent = 0;
1174 uint32_t dgpu_percent = 0;
1175 struct amdgpu_device *adev = smu->adev;
1178 ret = smu_cmn_get_metrics_table(smu,
1185 case METRICS_AVERAGE_GFXCLK:
1186 *value = metrics->ClockFrequency[CLOCK_GFXCLK];
1188 case METRICS_AVERAGE_SOCCLK:
1189 *value = metrics->ClockFrequency[CLOCK_SOCCLK];
1191 case METRICS_AVERAGE_UCLK:
1192 *value = metrics->ClockFrequency[CLOCK_FCLK];
1194 case METRICS_AVERAGE_GFXACTIVITY:
1195 *value = metrics->AverageGfxActivity / 100;
1197 case METRICS_AVERAGE_VCNACTIVITY:
1198 *value = metrics->AverageUvdActivity / 100;
1200 case METRICS_CURR_SOCKETPOWER:
1201 if (((adev->ip_versions[MP1_HWIP][0] == IP_VERSION(12, 0, 1)) && (adev->pm.fw_version >= 0x40000f)) ||
1202 ((adev->ip_versions[MP1_HWIP][0] == IP_VERSION(12, 0, 0)) && (adev->pm.fw_version >= 0x373200)))
1203 *value = metrics->CurrentSocketPower << 8;
1205 *value = (metrics->CurrentSocketPower << 8) / 1000;
1207 case METRICS_TEMPERATURE_EDGE:
1208 *value = (metrics->GfxTemperature / 100) *
1209 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1211 case METRICS_TEMPERATURE_HOTSPOT:
1212 *value = (metrics->SocTemperature / 100) *
1213 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
1215 case METRICS_THROTTLER_STATUS:
1216 *value = metrics->ThrottlerStatus;
1218 case METRICS_VOLTAGE_VDDGFX:
1219 *value = metrics->Voltage[0];
1221 case METRICS_VOLTAGE_VDDSOC:
1222 *value = metrics->Voltage[1];
1224 case METRICS_SS_APU_SHARE:
1225 /* return the percentage of APU power boost
1226 * with respect to APU's power limit.
1228 renoir_get_ss_power_percent(metrics, &apu_percent, &dgpu_percent);
1229 *value = apu_percent;
1231 case METRICS_SS_DGPU_SHARE:
1232 /* return the percentage of dGPU power boost
1233 * with respect to dGPU's power limit.
1235 renoir_get_ss_power_percent(metrics, &apu_percent, &dgpu_percent);
1236 *value = dgpu_percent;
1246 static int renoir_read_sensor(struct smu_context *smu,
1247 enum amd_pp_sensors sensor,
1248 void *data, uint32_t *size)
1256 case AMDGPU_PP_SENSOR_GPU_LOAD:
1257 ret = renoir_get_smu_metrics_data(smu,
1258 METRICS_AVERAGE_GFXACTIVITY,
1262 case AMDGPU_PP_SENSOR_EDGE_TEMP:
1263 ret = renoir_get_smu_metrics_data(smu,
1264 METRICS_TEMPERATURE_EDGE,
1268 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
1269 ret = renoir_get_smu_metrics_data(smu,
1270 METRICS_TEMPERATURE_HOTSPOT,
1274 case AMDGPU_PP_SENSOR_GFX_MCLK:
1275 ret = renoir_get_smu_metrics_data(smu,
1276 METRICS_AVERAGE_UCLK,
1278 *(uint32_t *)data *= 100;
1281 case AMDGPU_PP_SENSOR_GFX_SCLK:
1282 ret = renoir_get_smu_metrics_data(smu,
1283 METRICS_AVERAGE_GFXCLK,
1285 *(uint32_t *)data *= 100;
1288 case AMDGPU_PP_SENSOR_VDDGFX:
1289 ret = renoir_get_smu_metrics_data(smu,
1290 METRICS_VOLTAGE_VDDGFX,
1294 case AMDGPU_PP_SENSOR_VDDNB:
1295 ret = renoir_get_smu_metrics_data(smu,
1296 METRICS_VOLTAGE_VDDSOC,
1300 case AMDGPU_PP_SENSOR_GPU_INPUT_POWER:
1301 ret = renoir_get_smu_metrics_data(smu,
1302 METRICS_CURR_SOCKETPOWER,
1306 case AMDGPU_PP_SENSOR_SS_APU_SHARE:
1307 ret = renoir_get_smu_metrics_data(smu,
1308 METRICS_SS_APU_SHARE,
1312 case AMDGPU_PP_SENSOR_SS_DGPU_SHARE:
1313 ret = renoir_get_smu_metrics_data(smu,
1314 METRICS_SS_DGPU_SHARE,
1318 case AMDGPU_PP_SENSOR_GPU_AVG_POWER:
1327 static bool renoir_is_dpm_running(struct smu_context *smu)
1329 struct amdgpu_device *adev = smu->adev;
1332 * Until now, the pmfw hasn't exported the interface of SMU
1333 * feature mask to APU SKU so just force on all the feature
1334 * at early initial stage.
1336 if (adev->in_suspend)
1343 static ssize_t renoir_get_gpu_metrics(struct smu_context *smu,
1346 struct smu_table_context *smu_table = &smu->smu_table;
1347 struct gpu_metrics_v2_2 *gpu_metrics =
1348 (struct gpu_metrics_v2_2 *)smu_table->gpu_metrics_table;
1349 SmuMetrics_t metrics;
1352 ret = smu_cmn_get_metrics_table(smu, &metrics, true);
1356 smu_cmn_init_soft_gpu_metrics(gpu_metrics, 2, 2);
1358 gpu_metrics->temperature_gfx = metrics.GfxTemperature;
1359 gpu_metrics->temperature_soc = metrics.SocTemperature;
1360 memcpy(&gpu_metrics->temperature_core[0],
1361 &metrics.CoreTemperature[0],
1362 sizeof(uint16_t) * 8);
1363 gpu_metrics->temperature_l3[0] = metrics.L3Temperature[0];
1364 gpu_metrics->temperature_l3[1] = metrics.L3Temperature[1];
1366 gpu_metrics->average_gfx_activity = metrics.AverageGfxActivity;
1367 gpu_metrics->average_mm_activity = metrics.AverageUvdActivity;
1369 gpu_metrics->average_socket_power = metrics.CurrentSocketPower;
1370 gpu_metrics->average_cpu_power = metrics.Power[0];
1371 gpu_metrics->average_soc_power = metrics.Power[1];
1372 memcpy(&gpu_metrics->average_core_power[0],
1373 &metrics.CorePower[0],
1374 sizeof(uint16_t) * 8);
1376 gpu_metrics->average_gfxclk_frequency = metrics.AverageGfxclkFrequency;
1377 gpu_metrics->average_socclk_frequency = metrics.AverageSocclkFrequency;
1378 gpu_metrics->average_fclk_frequency = metrics.AverageFclkFrequency;
1379 gpu_metrics->average_vclk_frequency = metrics.AverageVclkFrequency;
1381 gpu_metrics->current_gfxclk = metrics.ClockFrequency[CLOCK_GFXCLK];
1382 gpu_metrics->current_socclk = metrics.ClockFrequency[CLOCK_SOCCLK];
1383 gpu_metrics->current_uclk = metrics.ClockFrequency[CLOCK_UMCCLK];
1384 gpu_metrics->current_fclk = metrics.ClockFrequency[CLOCK_FCLK];
1385 gpu_metrics->current_vclk = metrics.ClockFrequency[CLOCK_VCLK];
1386 gpu_metrics->current_dclk = metrics.ClockFrequency[CLOCK_DCLK];
1387 memcpy(&gpu_metrics->current_coreclk[0],
1388 &metrics.CoreFrequency[0],
1389 sizeof(uint16_t) * 8);
1390 gpu_metrics->current_l3clk[0] = metrics.L3Frequency[0];
1391 gpu_metrics->current_l3clk[1] = metrics.L3Frequency[1];
1393 gpu_metrics->throttle_status = metrics.ThrottlerStatus;
1394 gpu_metrics->indep_throttle_status =
1395 smu_cmn_get_indep_throttler_status(metrics.ThrottlerStatus,
1396 renoir_throttler_map);
1398 gpu_metrics->fan_pwm = metrics.FanPwm;
1400 gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
1402 *table = (void *)gpu_metrics;
1404 return sizeof(struct gpu_metrics_v2_2);
1407 static int renoir_gfx_state_change_set(struct smu_context *smu, uint32_t state)
1413 static int renoir_get_enabled_mask(struct smu_context *smu,
1414 uint64_t *feature_mask)
1418 memset(feature_mask, 0xff, sizeof(*feature_mask));
1423 static const struct pptable_funcs renoir_ppt_funcs = {
1424 .set_power_state = NULL,
1425 .print_clk_levels = renoir_print_clk_levels,
1426 .get_current_power_state = renoir_get_current_power_state,
1427 .dpm_set_vcn_enable = renoir_dpm_set_vcn_enable,
1428 .dpm_set_jpeg_enable = renoir_dpm_set_jpeg_enable,
1429 .force_clk_levels = renoir_force_clk_levels,
1430 .set_power_profile_mode = renoir_set_power_profile_mode,
1431 .set_performance_level = renoir_set_performance_level,
1432 .get_dpm_clock_table = renoir_get_dpm_clock_table,
1433 .set_watermarks_table = renoir_set_watermarks_table,
1434 .get_power_profile_mode = renoir_get_power_profile_mode,
1435 .read_sensor = renoir_read_sensor,
1436 .check_fw_status = smu_v12_0_check_fw_status,
1437 .check_fw_version = smu_v12_0_check_fw_version,
1438 .powergate_sdma = smu_v12_0_powergate_sdma,
1439 .send_smc_msg_with_param = smu_cmn_send_smc_msg_with_param,
1440 .send_smc_msg = smu_cmn_send_smc_msg,
1441 .set_gfx_cgpg = smu_v12_0_set_gfx_cgpg,
1442 .gfx_off_control = smu_v12_0_gfx_off_control,
1443 .get_gfx_off_status = smu_v12_0_get_gfxoff_status,
1444 .init_smc_tables = renoir_init_smc_tables,
1445 .fini_smc_tables = smu_v12_0_fini_smc_tables,
1446 .set_default_dpm_table = smu_v12_0_set_default_dpm_tables,
1447 .get_enabled_mask = renoir_get_enabled_mask,
1448 .feature_is_enabled = smu_cmn_feature_is_enabled,
1449 .disable_all_features_with_exception = smu_cmn_disable_all_features_with_exception,
1450 .get_dpm_ultimate_freq = renoir_get_dpm_ultimate_freq,
1451 .mode2_reset = smu_v12_0_mode2_reset,
1452 .set_soft_freq_limited_range = smu_v12_0_set_soft_freq_limited_range,
1453 .set_driver_table_location = smu_v12_0_set_driver_table_location,
1454 .is_dpm_running = renoir_is_dpm_running,
1455 .get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
1456 .set_pp_feature_mask = smu_cmn_set_pp_feature_mask,
1457 .get_gpu_metrics = renoir_get_gpu_metrics,
1458 .gfx_state_change_set = renoir_gfx_state_change_set,
1459 .set_fine_grain_gfx_freq_parameters = renoir_set_fine_grain_gfx_freq_parameters,
1460 .od_edit_dpm_table = renoir_od_edit_dpm_table,
1461 .get_vbios_bootup_values = smu_v12_0_get_vbios_bootup_values,
1464 void renoir_set_ppt_funcs(struct smu_context *smu)
1466 struct amdgpu_device *adev = smu->adev;
1468 smu->ppt_funcs = &renoir_ppt_funcs;
1469 smu->message_map = renoir_message_map;
1470 smu->clock_map = renoir_clk_map;
1471 smu->table_map = renoir_table_map;
1472 smu->workload_map = renoir_workload_map;
1473 smu->smc_driver_if_version = SMU12_DRIVER_IF_VERSION;
1475 smu->param_reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_82);
1476 smu->msg_reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_66);
1477 smu->resp_reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_90);