2 * Copyright 2022 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 "smu_types.h"
25 #define SWSMU_CODE_LAYER_L2
28 #include "amdgpu_smu.h"
29 #include "smu_v13_0.h"
30 #include "smu13_driver_if_v13_0_4.h"
31 #include "smu_v13_0_4_ppt.h"
32 #include "smu_v13_0_4_ppsmc.h"
33 #include "smu_v13_0_4_pmfw.h"
37 * DO NOT use these for err/warn/info/debug messages.
38 * Use dev_err, dev_warn, dev_info and dev_dbg instead.
39 * They are more MGPU friendly.
46 #define mmMP1_SMN_C2PMSG_66 0x0282
47 #define mmMP1_SMN_C2PMSG_66_BASE_IDX 1
49 #define mmMP1_SMN_C2PMSG_82 0x0292
50 #define mmMP1_SMN_C2PMSG_82_BASE_IDX 1
52 #define mmMP1_SMN_C2PMSG_90 0x029a
53 #define mmMP1_SMN_C2PMSG_90_BASE_IDX 1
55 #define FEATURE_MASK(feature) (1ULL << feature)
57 #define SMC_DPM_FEATURE ( \
58 FEATURE_MASK(FEATURE_CCLK_DPM_BIT) | \
59 FEATURE_MASK(FEATURE_VCN_DPM_BIT) | \
60 FEATURE_MASK(FEATURE_FCLK_DPM_BIT) | \
61 FEATURE_MASK(FEATURE_SOCCLK_DPM_BIT) | \
62 FEATURE_MASK(FEATURE_MP0CLK_DPM_BIT) | \
63 FEATURE_MASK(FEATURE_LCLK_DPM_BIT) | \
64 FEATURE_MASK(FEATURE_SHUBCLK_DPM_BIT) | \
65 FEATURE_MASK(FEATURE_DCFCLK_DPM_BIT) | \
66 FEATURE_MASK(FEATURE_ISP_DPM_BIT) | \
67 FEATURE_MASK(FEATURE_IPU_DPM_BIT) | \
68 FEATURE_MASK(FEATURE_GFX_DPM_BIT))
70 static struct cmn2asic_msg_mapping smu_v13_0_4_message_map[SMU_MSG_MAX_COUNT] = {
71 MSG_MAP(TestMessage, PPSMC_MSG_TestMessage, 1),
72 MSG_MAP(GetSmuVersion, PPSMC_MSG_GetPmfwVersion, 1),
73 MSG_MAP(GetDriverIfVersion, PPSMC_MSG_GetDriverIfVersion, 1),
74 MSG_MAP(AllowGfxOff, PPSMC_MSG_AllowGfxOff, 1),
75 MSG_MAP(DisallowGfxOff, PPSMC_MSG_DisallowGfxOff, 1),
76 MSG_MAP(PowerDownVcn, PPSMC_MSG_PowerDownVcn, 1),
77 MSG_MAP(PowerUpVcn, PPSMC_MSG_PowerUpVcn, 1),
78 MSG_MAP(SetHardMinVcn, PPSMC_MSG_SetHardMinVcn, 1),
79 MSG_MAP(PrepareMp1ForUnload, PPSMC_MSG_PrepareMp1ForUnload, 1),
80 MSG_MAP(SetDriverDramAddrHigh, PPSMC_MSG_SetDriverDramAddrHigh, 1),
81 MSG_MAP(SetDriverDramAddrLow, PPSMC_MSG_SetDriverDramAddrLow, 1),
82 MSG_MAP(TransferTableSmu2Dram, PPSMC_MSG_TransferTableSmu2Dram, 1),
83 MSG_MAP(TransferTableDram2Smu, PPSMC_MSG_TransferTableDram2Smu, 1),
84 MSG_MAP(GfxDeviceDriverReset, PPSMC_MSG_GfxDeviceDriverReset, 1),
85 MSG_MAP(GetEnabledSmuFeatures, PPSMC_MSG_GetEnabledSmuFeatures, 1),
86 MSG_MAP(SetHardMinSocclkByFreq, PPSMC_MSG_SetHardMinSocclkByFreq, 1),
87 MSG_MAP(SetSoftMinVcn, PPSMC_MSG_SetSoftMinVcn, 1),
88 MSG_MAP(GetGfxclkFrequency, PPSMC_MSG_GetGfxclkFrequency, 1),
89 MSG_MAP(GetFclkFrequency, PPSMC_MSG_GetFclkFrequency, 1),
90 MSG_MAP(SetSoftMaxGfxClk, PPSMC_MSG_SetSoftMaxGfxClk, 1),
91 MSG_MAP(SetHardMinGfxClk, PPSMC_MSG_SetHardMinGfxClk, 1),
92 MSG_MAP(SetSoftMaxSocclkByFreq, PPSMC_MSG_SetSoftMaxSocclkByFreq, 1),
93 MSG_MAP(SetSoftMaxFclkByFreq, PPSMC_MSG_SetSoftMaxFclkByFreq, 1),
94 MSG_MAP(SetSoftMaxVcn, PPSMC_MSG_SetSoftMaxVcn, 1),
95 MSG_MAP(SetPowerLimitPercentage, PPSMC_MSG_SetPowerLimitPercentage, 1),
96 MSG_MAP(PowerDownJpeg, PPSMC_MSG_PowerDownJpeg, 1),
97 MSG_MAP(PowerUpJpeg, PPSMC_MSG_PowerUpJpeg, 1),
98 MSG_MAP(SetHardMinFclkByFreq, PPSMC_MSG_SetHardMinFclkByFreq, 1),
99 MSG_MAP(SetSoftMinSocclkByFreq, PPSMC_MSG_SetSoftMinSocclkByFreq, 1),
100 MSG_MAP(EnableGfxImu, PPSMC_MSG_EnableGfxImu, 1),
101 MSG_MAP(PowerUpIspByTile, PPSMC_MSG_PowerUpIspByTile, 1),
102 MSG_MAP(PowerDownIspByTile, PPSMC_MSG_PowerDownIspByTile, 1),
105 static struct cmn2asic_mapping smu_v13_0_4_feature_mask_map[SMU_FEATURE_COUNT] = {
107 FEA_MAP(FAN_CONTROLLER),
112 FEA_MAP_REVERSE(FCLK),
113 FEA_MAP_REVERSE(SOCCLK),
115 FEA_MAP(SHUBCLK_DPM),
117 FEA_MAP_HALF_REVERSE(GFX),
139 static struct cmn2asic_mapping smu_v13_0_4_table_map[SMU_TABLE_COUNT] = {
140 TAB_MAP_VALID(WATERMARKS),
141 TAB_MAP_VALID(SMU_METRICS),
142 TAB_MAP_VALID(CUSTOM_DPM),
143 TAB_MAP_VALID(DPMCLOCKS),
146 static int smu_v13_0_4_init_smc_tables(struct smu_context *smu)
148 struct smu_table_context *smu_table = &smu->smu_table;
149 struct smu_table *tables = smu_table->tables;
151 SMU_TABLE_INIT(tables, SMU_TABLE_WATERMARKS, sizeof(Watermarks_t),
152 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
153 SMU_TABLE_INIT(tables, SMU_TABLE_DPMCLOCKS, sizeof(DpmClocks_t),
154 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
155 SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
156 PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
158 smu_table->clocks_table = kzalloc(sizeof(DpmClocks_t), GFP_KERNEL);
159 if (!smu_table->clocks_table)
162 smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
163 if (!smu_table->metrics_table)
165 smu_table->metrics_time = 0;
167 smu_table->watermarks_table = kzalloc(sizeof(Watermarks_t), GFP_KERNEL);
168 if (!smu_table->watermarks_table)
171 smu_table->gpu_metrics_table_size = sizeof(struct gpu_metrics_v2_1);
172 smu_table->gpu_metrics_table = kzalloc(smu_table->gpu_metrics_table_size, GFP_KERNEL);
173 if (!smu_table->gpu_metrics_table)
179 kfree(smu_table->watermarks_table);
181 kfree(smu_table->metrics_table);
183 kfree(smu_table->clocks_table);
188 static int smu_v13_0_4_fini_smc_tables(struct smu_context *smu)
190 struct smu_table_context *smu_table = &smu->smu_table;
192 kfree(smu_table->clocks_table);
193 smu_table->clocks_table = NULL;
195 kfree(smu_table->metrics_table);
196 smu_table->metrics_table = NULL;
198 kfree(smu_table->watermarks_table);
199 smu_table->watermarks_table = NULL;
201 kfree(smu_table->gpu_metrics_table);
202 smu_table->gpu_metrics_table = NULL;
207 static bool smu_v13_0_4_is_dpm_running(struct smu_context *smu)
210 uint64_t feature_enabled;
212 ret = smu_cmn_get_enabled_mask(smu, &feature_enabled);
217 return !!(feature_enabled & SMC_DPM_FEATURE);
220 static int smu_v13_0_4_system_features_control(struct smu_context *smu, bool en)
222 struct amdgpu_device *adev = smu->adev;
225 if (!en && !adev->in_s0ix)
226 ret = smu_cmn_send_smc_msg(smu, SMU_MSG_PrepareMp1ForUnload, NULL);
231 static ssize_t smu_v13_0_4_get_gpu_metrics(struct smu_context *smu,
234 struct smu_table_context *smu_table = &smu->smu_table;
235 struct gpu_metrics_v2_1 *gpu_metrics =
236 (struct gpu_metrics_v2_1 *)smu_table->gpu_metrics_table;
237 SmuMetrics_t metrics;
240 ret = smu_cmn_get_metrics_table(smu, &metrics, true);
244 smu_cmn_init_soft_gpu_metrics(gpu_metrics, 2, 1);
246 gpu_metrics->temperature_gfx = metrics.GfxTemperature;
247 gpu_metrics->temperature_soc = metrics.SocTemperature;
248 memcpy(&gpu_metrics->temperature_core[0],
249 &metrics.CoreTemperature[0],
250 sizeof(uint16_t) * 8);
251 gpu_metrics->temperature_l3[0] = metrics.L3Temperature;
253 gpu_metrics->average_gfx_activity = metrics.GfxActivity;
254 gpu_metrics->average_mm_activity = metrics.UvdActivity;
256 gpu_metrics->average_socket_power = metrics.CurrentSocketPower;
257 gpu_metrics->average_gfx_power = metrics.Power[0];
258 gpu_metrics->average_soc_power = metrics.Power[1];
259 memcpy(&gpu_metrics->average_core_power[0],
260 &metrics.CorePower[0],
261 sizeof(uint16_t) * 8);
263 gpu_metrics->average_gfxclk_frequency = metrics.GfxclkFrequency;
264 gpu_metrics->average_socclk_frequency = metrics.SocclkFrequency;
265 gpu_metrics->average_uclk_frequency = metrics.MemclkFrequency;
266 gpu_metrics->average_fclk_frequency = metrics.MemclkFrequency;
267 gpu_metrics->average_vclk_frequency = metrics.VclkFrequency;
268 gpu_metrics->average_dclk_frequency = metrics.DclkFrequency;
270 memcpy(&gpu_metrics->current_coreclk[0],
271 &metrics.CoreFrequency[0],
272 sizeof(uint16_t) * 8);
273 gpu_metrics->current_l3clk[0] = metrics.L3Frequency;
275 gpu_metrics->throttle_status = metrics.ThrottlerStatus;
277 gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
279 *table = (void *)gpu_metrics;
281 return sizeof(struct gpu_metrics_v2_1);
284 static int smu_v13_0_4_get_smu_metrics_data(struct smu_context *smu,
285 MetricsMember_t member,
288 struct smu_table_context *smu_table = &smu->smu_table;
290 SmuMetrics_t *metrics = (SmuMetrics_t *)smu_table->metrics_table;
293 ret = smu_cmn_get_metrics_table(smu, NULL, false);
298 case METRICS_AVERAGE_GFXCLK:
299 *value = metrics->GfxclkFrequency;
301 case METRICS_AVERAGE_SOCCLK:
302 *value = metrics->SocclkFrequency;
304 case METRICS_AVERAGE_VCLK:
305 *value = metrics->VclkFrequency;
307 case METRICS_AVERAGE_DCLK:
308 *value = metrics->DclkFrequency;
310 case METRICS_AVERAGE_UCLK:
311 *value = metrics->MemclkFrequency;
313 case METRICS_AVERAGE_GFXACTIVITY:
314 *value = metrics->GfxActivity / 100;
316 case METRICS_AVERAGE_VCNACTIVITY:
317 *value = metrics->UvdActivity;
319 case METRICS_AVERAGE_SOCKETPOWER:
320 *value = (metrics->CurrentSocketPower << 8) / 1000;
322 case METRICS_TEMPERATURE_EDGE:
323 *value = metrics->GfxTemperature / 100 *
324 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
326 case METRICS_TEMPERATURE_HOTSPOT:
327 *value = metrics->SocTemperature / 100 *
328 SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
330 case METRICS_THROTTLER_STATUS:
331 *value = metrics->ThrottlerStatus;
333 case METRICS_VOLTAGE_VDDGFX:
334 *value = metrics->Voltage[0];
336 case METRICS_VOLTAGE_VDDSOC:
337 *value = metrics->Voltage[1];
339 case METRICS_SS_APU_SHARE:
340 /* return the percentage of APU power with respect to APU's power limit.
341 * percentage is reported, this isn't boost value. Smartshift power
342 * boost/shift is only when the percentage is more than 100.
344 if (metrics->StapmOpnLimit > 0)
345 *value = (metrics->ApuPower * 100) / metrics->StapmOpnLimit;
349 case METRICS_SS_DGPU_SHARE:
350 /* return the percentage of dGPU power with respect to dGPU's power limit.
351 * percentage is reported, this isn't boost value. Smartshift power
352 * boost/shift is only when the percentage is more than 100.
354 if ((metrics->dGpuPower > 0) &&
355 (metrics->StapmCurrentLimit > metrics->StapmOpnLimit))
356 *value = (metrics->dGpuPower * 100) /
357 (metrics->StapmCurrentLimit - metrics->StapmOpnLimit);
369 static int smu_v13_0_4_get_current_clk_freq(struct smu_context *smu,
370 enum smu_clk_type clk_type,
373 MetricsMember_t member_type;
377 member_type = METRICS_AVERAGE_SOCCLK;
380 member_type = METRICS_AVERAGE_VCLK;
383 member_type = METRICS_AVERAGE_DCLK;
386 member_type = METRICS_AVERAGE_UCLK;
389 return smu_cmn_send_smc_msg_with_param(smu,
390 SMU_MSG_GetFclkFrequency,
394 return smu_cmn_send_smc_msg_with_param(smu,
395 SMU_MSG_GetGfxclkFrequency,
402 return smu_v13_0_4_get_smu_metrics_data(smu, member_type, value);
405 static int smu_v13_0_4_get_dpm_freq_by_index(struct smu_context *smu,
406 enum smu_clk_type clk_type,
410 DpmClocks_t *clk_table = smu->smu_table.clocks_table;
412 if (!clk_table || clk_type >= SMU_CLK_COUNT)
417 if (dpm_level >= clk_table->NumSocClkLevelsEnabled)
419 *freq = clk_table->SocClocks[dpm_level];
422 if (dpm_level >= clk_table->VcnClkLevelsEnabled)
424 *freq = clk_table->VClocks[dpm_level];
427 if (dpm_level >= clk_table->VcnClkLevelsEnabled)
429 *freq = clk_table->DClocks[dpm_level];
433 if (dpm_level >= clk_table->NumDfPstatesEnabled)
435 *freq = clk_table->DfPstateTable[dpm_level].MemClk;
438 if (dpm_level >= clk_table->NumDfPstatesEnabled)
440 *freq = clk_table->DfPstateTable[dpm_level].FClk;
449 static int smu_v13_0_4_get_dpm_level_count(struct smu_context *smu,
450 enum smu_clk_type clk_type,
453 DpmClocks_t *clk_table = smu->smu_table.clocks_table;
457 *count = clk_table->NumSocClkLevelsEnabled;
460 *count = clk_table->VcnClkLevelsEnabled;
463 *count = clk_table->VcnClkLevelsEnabled;
466 *count = clk_table->NumDfPstatesEnabled;
469 *count = clk_table->NumDfPstatesEnabled;
478 static int smu_v13_0_4_print_clk_levels(struct smu_context *smu,
479 enum smu_clk_type clk_type, char *buf)
481 int i, size = 0, ret = 0;
482 uint32_t cur_value = 0, value = 0, count = 0;
485 smu_cmn_get_sysfs_buf(&buf, &size);
489 size += sysfs_emit_at(buf, size, "%s:\n", "OD_SCLK");
490 size += sysfs_emit_at(buf, size, "0: %10uMhz\n",
491 (smu->gfx_actual_hard_min_freq > 0) ? smu->gfx_actual_hard_min_freq : smu->gfx_default_hard_min_freq);
492 size += sysfs_emit_at(buf, size, "1: %10uMhz\n",
493 (smu->gfx_actual_soft_max_freq > 0) ? smu->gfx_actual_soft_max_freq : smu->gfx_default_soft_max_freq);
496 size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
497 size += sysfs_emit_at(buf, size, "SCLK: %7uMhz %10uMhz\n",
498 smu->gfx_default_hard_min_freq,
499 smu->gfx_default_soft_max_freq);
506 ret = smu_v13_0_4_get_current_clk_freq(smu, clk_type, &cur_value);
510 ret = smu_v13_0_4_get_dpm_level_count(smu, clk_type, &count);
514 for (i = 0; i < count; i++) {
515 ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type, i, &value);
519 size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, value,
520 cur_value == value ? "*" : "");
525 ret = smu_v13_0_4_get_current_clk_freq(smu, clk_type, &cur_value);
528 min = (smu->gfx_actual_hard_min_freq > 0) ? smu->gfx_actual_hard_min_freq : smu->gfx_default_hard_min_freq;
529 max = (smu->gfx_actual_soft_max_freq > 0) ? smu->gfx_actual_soft_max_freq : smu->gfx_default_soft_max_freq;
530 if (cur_value == max)
532 else if (cur_value == min)
536 size += sysfs_emit_at(buf, size, "0: %uMhz %s\n", min,
538 size += sysfs_emit_at(buf, size, "1: %uMhz %s\n",
539 i == 1 ? cur_value : 1100, /* UMD PSTATE GFXCLK 1100 */
541 size += sysfs_emit_at(buf, size, "2: %uMhz %s\n", max,
551 static int smu_v13_0_4_read_sensor(struct smu_context *smu,
552 enum amd_pp_sensors sensor,
553 void *data, uint32_t *size)
561 case AMDGPU_PP_SENSOR_GPU_LOAD:
562 ret = smu_v13_0_4_get_smu_metrics_data(smu,
563 METRICS_AVERAGE_GFXACTIVITY,
567 case AMDGPU_PP_SENSOR_GPU_POWER:
568 ret = smu_v13_0_4_get_smu_metrics_data(smu,
569 METRICS_AVERAGE_SOCKETPOWER,
573 case AMDGPU_PP_SENSOR_EDGE_TEMP:
574 ret = smu_v13_0_4_get_smu_metrics_data(smu,
575 METRICS_TEMPERATURE_EDGE,
579 case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
580 ret = smu_v13_0_4_get_smu_metrics_data(smu,
581 METRICS_TEMPERATURE_HOTSPOT,
585 case AMDGPU_PP_SENSOR_GFX_MCLK:
586 ret = smu_v13_0_4_get_smu_metrics_data(smu,
587 METRICS_AVERAGE_UCLK,
589 *(uint32_t *)data *= 100;
592 case AMDGPU_PP_SENSOR_GFX_SCLK:
593 ret = smu_v13_0_4_get_smu_metrics_data(smu,
594 METRICS_AVERAGE_GFXCLK,
596 *(uint32_t *)data *= 100;
599 case AMDGPU_PP_SENSOR_VDDGFX:
600 ret = smu_v13_0_4_get_smu_metrics_data(smu,
601 METRICS_VOLTAGE_VDDGFX,
605 case AMDGPU_PP_SENSOR_VDDNB:
606 ret = smu_v13_0_4_get_smu_metrics_data(smu,
607 METRICS_VOLTAGE_VDDSOC,
611 case AMDGPU_PP_SENSOR_SS_APU_SHARE:
612 ret = smu_v13_0_4_get_smu_metrics_data(smu,
613 METRICS_SS_APU_SHARE,
617 case AMDGPU_PP_SENSOR_SS_DGPU_SHARE:
618 ret = smu_v13_0_4_get_smu_metrics_data(smu,
619 METRICS_SS_DGPU_SHARE,
631 static int smu_v13_0_4_set_watermarks_table(struct smu_context *smu,
632 struct pp_smu_wm_range_sets *clock_ranges)
636 Watermarks_t *table = smu->smu_table.watermarks_table;
638 if (!table || !clock_ranges)
641 if (clock_ranges->num_reader_wm_sets > NUM_WM_RANGES ||
642 clock_ranges->num_writer_wm_sets > NUM_WM_RANGES)
645 for (i = 0; i < clock_ranges->num_reader_wm_sets; i++) {
646 table->WatermarkRow[WM_DCFCLK][i].MinClock =
647 clock_ranges->reader_wm_sets[i].min_drain_clk_mhz;
648 table->WatermarkRow[WM_DCFCLK][i].MaxClock =
649 clock_ranges->reader_wm_sets[i].max_drain_clk_mhz;
650 table->WatermarkRow[WM_DCFCLK][i].MinMclk =
651 clock_ranges->reader_wm_sets[i].min_fill_clk_mhz;
652 table->WatermarkRow[WM_DCFCLK][i].MaxMclk =
653 clock_ranges->reader_wm_sets[i].max_fill_clk_mhz;
655 table->WatermarkRow[WM_DCFCLK][i].WmSetting =
656 clock_ranges->reader_wm_sets[i].wm_inst;
659 for (i = 0; i < clock_ranges->num_writer_wm_sets; i++) {
660 table->WatermarkRow[WM_SOCCLK][i].MinClock =
661 clock_ranges->writer_wm_sets[i].min_fill_clk_mhz;
662 table->WatermarkRow[WM_SOCCLK][i].MaxClock =
663 clock_ranges->writer_wm_sets[i].max_fill_clk_mhz;
664 table->WatermarkRow[WM_SOCCLK][i].MinMclk =
665 clock_ranges->writer_wm_sets[i].min_drain_clk_mhz;
666 table->WatermarkRow[WM_SOCCLK][i].MaxMclk =
667 clock_ranges->writer_wm_sets[i].max_drain_clk_mhz;
669 table->WatermarkRow[WM_SOCCLK][i].WmSetting =
670 clock_ranges->writer_wm_sets[i].wm_inst;
673 smu->watermarks_bitmap |= WATERMARKS_EXIST;
675 /* pass data to smu controller */
676 if ((smu->watermarks_bitmap & WATERMARKS_EXIST) &&
677 !(smu->watermarks_bitmap & WATERMARKS_LOADED)) {
678 ret = smu_cmn_write_watermarks_table(smu);
680 dev_err(smu->adev->dev, "Failed to update WMTABLE!");
683 smu->watermarks_bitmap |= WATERMARKS_LOADED;
689 static bool smu_v13_0_4_clk_dpm_is_enabled(struct smu_context *smu,
690 enum smu_clk_type clk_type)
692 enum smu_feature_mask feature_id = 0;
698 feature_id = SMU_FEATURE_DPM_FCLK_BIT;
702 feature_id = SMU_FEATURE_DPM_GFXCLK_BIT;
705 feature_id = SMU_FEATURE_DPM_SOCCLK_BIT;
709 feature_id = SMU_FEATURE_VCN_DPM_BIT;
715 return smu_cmn_feature_is_enabled(smu, feature_id);
718 static int smu_v13_0_4_get_dpm_ultimate_freq(struct smu_context *smu,
719 enum smu_clk_type clk_type,
723 DpmClocks_t *clk_table = smu->smu_table.clocks_table;
724 uint32_t clock_limit;
725 uint32_t max_dpm_level, min_dpm_level;
728 if (!smu_v13_0_4_clk_dpm_is_enabled(smu, clk_type)) {
732 clock_limit = smu->smu_table.boot_values.uclk;
735 clock_limit = smu->smu_table.boot_values.fclk;
739 clock_limit = smu->smu_table.boot_values.gfxclk;
742 clock_limit = smu->smu_table.boot_values.socclk;
745 clock_limit = smu->smu_table.boot_values.vclk;
748 clock_limit = smu->smu_table.boot_values.dclk;
755 /* clock in Mhz unit */
757 *min = clock_limit / 100;
759 *max = clock_limit / 100;
768 *max = clk_table->MaxGfxClk;
776 max_dpm_level = clk_table->NumSocClkLevelsEnabled - 1;
780 max_dpm_level = clk_table->VcnClkLevelsEnabled - 1;
786 if (clk_type != SMU_GFXCLK && clk_type != SMU_SCLK) {
787 ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type,
799 *min = clk_table->MinGfxClk;
804 min_dpm_level = clk_table->NumDfPstatesEnabled - 1;
817 if (clk_type != SMU_GFXCLK && clk_type != SMU_SCLK) {
818 ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type,
827 static int smu_v13_0_4_set_soft_freq_limited_range(struct smu_context *smu,
828 enum smu_clk_type clk_type,
832 enum smu_message_type msg_set_min, msg_set_max;
835 if (!smu_v13_0_4_clk_dpm_is_enabled(smu, clk_type))
841 msg_set_min = SMU_MSG_SetHardMinGfxClk;
842 msg_set_max = SMU_MSG_SetSoftMaxGfxClk;
845 msg_set_min = SMU_MSG_SetHardMinFclkByFreq;
846 msg_set_max = SMU_MSG_SetSoftMaxFclkByFreq;
849 msg_set_min = SMU_MSG_SetHardMinSocclkByFreq;
850 msg_set_max = SMU_MSG_SetSoftMaxSocclkByFreq;
854 msg_set_min = SMU_MSG_SetHardMinVcn;
855 msg_set_max = SMU_MSG_SetSoftMaxVcn;
861 ret = smu_cmn_send_smc_msg_with_param(smu, msg_set_min, min, NULL);
865 return smu_cmn_send_smc_msg_with_param(smu, msg_set_max,
869 static int smu_v13_0_4_force_clk_levels(struct smu_context *smu,
870 enum smu_clk_type clk_type,
873 uint32_t soft_min_level = 0, soft_max_level = 0;
874 uint32_t min_freq = 0, max_freq = 0;
877 soft_min_level = mask ? (ffs(mask) - 1) : 0;
878 soft_max_level = mask ? (fls(mask) - 1) : 0;
885 ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type, soft_min_level, &min_freq);
889 ret = smu_v13_0_4_get_dpm_freq_by_index(smu, clk_type, soft_max_level, &max_freq);
893 ret = smu_v13_0_4_set_soft_freq_limited_range(smu, clk_type, min_freq, max_freq);
903 static int smu_v13_0_4_set_performance_level(struct smu_context *smu,
904 enum amd_dpm_forced_level level)
906 struct amdgpu_device *adev = smu->adev;
907 uint32_t sclk_min = 0, sclk_max = 0;
908 uint32_t fclk_min = 0, fclk_max = 0;
909 uint32_t socclk_min = 0, socclk_max = 0;
913 case AMD_DPM_FORCED_LEVEL_HIGH:
914 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, NULL, &sclk_max);
915 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, NULL, &fclk_max);
916 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, NULL, &socclk_max);
919 socclk_min = socclk_max;
921 case AMD_DPM_FORCED_LEVEL_LOW:
922 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, &sclk_min, NULL);
923 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, &fclk_min, NULL);
924 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, &socclk_min, NULL);
927 socclk_max = socclk_min;
929 case AMD_DPM_FORCED_LEVEL_AUTO:
930 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SCLK, &sclk_min, &sclk_max);
931 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_FCLK, &fclk_min, &fclk_max);
932 smu_v13_0_4_get_dpm_ultimate_freq(smu, SMU_SOCCLK, &socclk_min, &socclk_max);
934 case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
935 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
936 case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK:
937 case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
938 /* Temporarily do nothing since the optimal clocks haven't been provided yet */
940 case AMD_DPM_FORCED_LEVEL_MANUAL:
941 case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
944 dev_err(adev->dev, "Invalid performance level %d\n", level);
948 if (sclk_min && sclk_max) {
949 ret = smu_v13_0_4_set_soft_freq_limited_range(smu,
956 smu->gfx_actual_hard_min_freq = sclk_min;
957 smu->gfx_actual_soft_max_freq = sclk_max;
960 if (fclk_min && fclk_max) {
961 ret = smu_v13_0_4_set_soft_freq_limited_range(smu,
969 if (socclk_min && socclk_max) {
970 ret = smu_v13_0_4_set_soft_freq_limited_range(smu,
981 static int smu_v13_0_4_mode2_reset(struct smu_context *smu)
983 return smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_GfxDeviceDriverReset,
984 SMU_RESET_MODE_2, NULL);
987 static int smu_v13_0_4_set_fine_grain_gfx_freq_parameters(struct smu_context *smu)
989 DpmClocks_t *clk_table = smu->smu_table.clocks_table;
991 smu->gfx_default_hard_min_freq = clk_table->MinGfxClk;
992 smu->gfx_default_soft_max_freq = clk_table->MaxGfxClk;
993 smu->gfx_actual_hard_min_freq = 0;
994 smu->gfx_actual_soft_max_freq = 0;
999 static const struct pptable_funcs smu_v13_0_4_ppt_funcs = {
1000 .check_fw_status = smu_v13_0_check_fw_status,
1001 .check_fw_version = smu_v13_0_check_fw_version,
1002 .init_smc_tables = smu_v13_0_4_init_smc_tables,
1003 .fini_smc_tables = smu_v13_0_4_fini_smc_tables,
1004 .get_vbios_bootup_values = smu_v13_0_get_vbios_bootup_values,
1005 .system_features_control = smu_v13_0_4_system_features_control,
1006 .send_smc_msg_with_param = smu_cmn_send_smc_msg_with_param,
1007 .send_smc_msg = smu_cmn_send_smc_msg,
1008 .dpm_set_vcn_enable = smu_v13_0_set_vcn_enable,
1009 .dpm_set_jpeg_enable = smu_v13_0_set_jpeg_enable,
1010 .set_default_dpm_table = smu_v13_0_set_default_dpm_tables,
1011 .read_sensor = smu_v13_0_4_read_sensor,
1012 .is_dpm_running = smu_v13_0_4_is_dpm_running,
1013 .set_watermarks_table = smu_v13_0_4_set_watermarks_table,
1014 .get_gpu_metrics = smu_v13_0_4_get_gpu_metrics,
1015 .get_enabled_mask = smu_cmn_get_enabled_mask,
1016 .get_pp_feature_mask = smu_cmn_get_pp_feature_mask,
1017 .set_driver_table_location = smu_v13_0_set_driver_table_location,
1018 .gfx_off_control = smu_v13_0_gfx_off_control,
1019 .mode2_reset = smu_v13_0_4_mode2_reset,
1020 .get_dpm_ultimate_freq = smu_v13_0_4_get_dpm_ultimate_freq,
1021 .od_edit_dpm_table = smu_v13_0_od_edit_dpm_table,
1022 .print_clk_levels = smu_v13_0_4_print_clk_levels,
1023 .force_clk_levels = smu_v13_0_4_force_clk_levels,
1024 .set_performance_level = smu_v13_0_4_set_performance_level,
1025 .set_fine_grain_gfx_freq_parameters = smu_v13_0_4_set_fine_grain_gfx_freq_parameters,
1026 .set_gfx_power_up_by_imu = smu_v13_0_set_gfx_power_up_by_imu,
1029 static void smu_v13_0_4_set_smu_mailbox_registers(struct smu_context *smu)
1031 struct amdgpu_device *adev = smu->adev;
1033 smu->param_reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_82);
1034 smu->msg_reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_66);
1035 smu->resp_reg = SOC15_REG_OFFSET(MP1, 0, mmMP1_SMN_C2PMSG_90);
1038 void smu_v13_0_4_set_ppt_funcs(struct smu_context *smu)
1040 struct amdgpu_device *adev = smu->adev;
1042 smu->ppt_funcs = &smu_v13_0_4_ppt_funcs;
1043 smu->message_map = smu_v13_0_4_message_map;
1044 smu->feature_map = smu_v13_0_4_feature_mask_map;
1045 smu->table_map = smu_v13_0_4_table_map;
1048 if (adev->ip_versions[MP1_HWIP][0] == IP_VERSION(13, 0, 4))
1049 smu_v13_0_4_set_smu_mailbox_registers(smu);
1051 smu_v13_0_set_smu_mailbox_registers(smu);