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.
23 #include <linux/firmware.h>
24 #include <linux/pci.h>
27 #include "amdgpu_smu.h"
28 #include "smu_internal.h"
29 #include "smu_v11_0.h"
30 #include "smu_v12_0.h"
32 #include "arcturus_ppt.h"
33 #include "navi10_ppt.h"
34 #include "sienna_cichlid_ppt.h"
35 #include "renoir_ppt.h"
38 * DO NOT use these for err/warn/info/debug messages.
39 * Use dev_err, dev_warn, dev_info and dev_dbg instead.
40 * They are more MGPU friendly.
47 #undef __SMU_DUMMY_MAP
48 #define __SMU_DUMMY_MAP(type) #type
49 static const char* __smu_message_names[] = {
53 const char *smu_get_message_name(struct smu_context *smu, enum smu_message_type type)
55 if (type < 0 || type >= SMU_MSG_MAX_COUNT)
56 return "unknown smu message";
57 return __smu_message_names[type];
60 #undef __SMU_DUMMY_MAP
61 #define __SMU_DUMMY_MAP(fea) #fea
62 static const char* __smu_feature_names[] = {
66 const char *smu_get_feature_name(struct smu_context *smu, enum smu_feature_mask feature)
68 if (feature < 0 || feature >= SMU_FEATURE_COUNT)
69 return "unknown smu feature";
70 return __smu_feature_names[feature];
73 size_t smu_sys_get_pp_feature_mask(struct smu_context *smu, char *buf)
77 uint32_t feature_mask[2] = { 0 };
78 int32_t feature_index = 0;
80 uint32_t sort_feature[SMU_FEATURE_COUNT];
81 uint64_t hw_feature_count = 0;
83 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
86 mutex_lock(&smu->mutex);
88 ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
92 size = sprintf(buf + size, "features high: 0x%08x low: 0x%08x\n",
93 feature_mask[1], feature_mask[0]);
95 for (i = 0; i < SMU_FEATURE_COUNT; i++) {
96 feature_index = smu_feature_get_index(smu, i);
97 if (feature_index < 0)
99 sort_feature[feature_index] = i;
103 for (i = 0; i < hw_feature_count; i++) {
104 size += sprintf(buf + size, "%02d. %-20s (%2d) : %s\n",
106 smu_get_feature_name(smu, sort_feature[i]),
108 !!smu_feature_is_enabled(smu, sort_feature[i]) ?
109 "enabled" : "disabled");
113 mutex_unlock(&smu->mutex);
118 static int smu_feature_update_enable_state(struct smu_context *smu,
119 uint64_t feature_mask,
122 struct smu_feature *feature = &smu->smu_feature;
126 ret = smu_send_smc_msg_with_param(smu,
127 SMU_MSG_EnableSmuFeaturesLow,
128 lower_32_bits(feature_mask),
132 ret = smu_send_smc_msg_with_param(smu,
133 SMU_MSG_EnableSmuFeaturesHigh,
134 upper_32_bits(feature_mask),
139 ret = smu_send_smc_msg_with_param(smu,
140 SMU_MSG_DisableSmuFeaturesLow,
141 lower_32_bits(feature_mask),
145 ret = smu_send_smc_msg_with_param(smu,
146 SMU_MSG_DisableSmuFeaturesHigh,
147 upper_32_bits(feature_mask),
153 mutex_lock(&feature->mutex);
155 bitmap_or(feature->enabled, feature->enabled,
156 (unsigned long *)(&feature_mask), SMU_FEATURE_MAX);
158 bitmap_andnot(feature->enabled, feature->enabled,
159 (unsigned long *)(&feature_mask), SMU_FEATURE_MAX);
160 mutex_unlock(&feature->mutex);
165 int smu_sys_set_pp_feature_mask(struct smu_context *smu, uint64_t new_mask)
168 uint32_t feature_mask[2] = { 0 };
169 uint64_t feature_2_enabled = 0;
170 uint64_t feature_2_disabled = 0;
171 uint64_t feature_enables = 0;
173 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
176 mutex_lock(&smu->mutex);
178 ret = smu_feature_get_enabled_mask(smu, feature_mask, 2);
182 feature_enables = ((uint64_t)feature_mask[1] << 32 | (uint64_t)feature_mask[0]);
184 feature_2_enabled = ~feature_enables & new_mask;
185 feature_2_disabled = feature_enables & ~new_mask;
187 if (feature_2_enabled) {
188 ret = smu_feature_update_enable_state(smu, feature_2_enabled, true);
192 if (feature_2_disabled) {
193 ret = smu_feature_update_enable_state(smu, feature_2_disabled, false);
199 mutex_unlock(&smu->mutex);
204 int smu_get_smc_version(struct smu_context *smu, uint32_t *if_version, uint32_t *smu_version)
208 if (!if_version && !smu_version)
211 if (smu->smc_fw_if_version && smu->smc_fw_version)
214 *if_version = smu->smc_fw_if_version;
217 *smu_version = smu->smc_fw_version;
223 ret = smu_send_smc_msg(smu, SMU_MSG_GetDriverIfVersion, if_version);
227 smu->smc_fw_if_version = *if_version;
231 ret = smu_send_smc_msg(smu, SMU_MSG_GetSmuVersion, smu_version);
235 smu->smc_fw_version = *smu_version;
241 int smu_set_soft_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
242 uint32_t min, uint32_t max, bool lock_needed)
246 if (!smu_clk_dpm_is_enabled(smu, clk_type))
250 mutex_lock(&smu->mutex);
251 ret = smu_set_soft_freq_limited_range(smu, clk_type, min, max);
253 mutex_unlock(&smu->mutex);
258 int smu_set_hard_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
259 uint32_t min, uint32_t max)
261 int ret = 0, clk_id = 0;
264 if (min <= 0 && max <= 0)
267 if (!smu_clk_dpm_is_enabled(smu, clk_type))
270 clk_id = smu_clk_get_index(smu, clk_type);
275 param = (uint32_t)((clk_id << 16) | (max & 0xffff));
276 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetHardMaxByFreq,
283 param = (uint32_t)((clk_id << 16) | (min & 0xffff));
284 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_SetHardMinByFreq,
294 int smu_get_dpm_freq_range(struct smu_context *smu, enum smu_clk_type clk_type,
295 uint32_t *min, uint32_t *max, bool lock_needed)
297 uint32_t clock_limit;
304 mutex_lock(&smu->mutex);
306 if (!smu_clk_dpm_is_enabled(smu, clk_type)) {
310 clock_limit = smu->smu_table.boot_values.uclk;
314 clock_limit = smu->smu_table.boot_values.gfxclk;
317 clock_limit = smu->smu_table.boot_values.socclk;
324 /* clock in Mhz unit */
326 *min = clock_limit / 100;
328 *max = clock_limit / 100;
331 * Todo: Use each asic(ASIC_ppt funcs) control the callbacks exposed to the
332 * core driver and then have helpers for stuff that is common(SMU_v11_x | SMU_v12_x funcs).
334 ret = smu_get_dpm_ultimate_freq(smu, clk_type, min, max);
338 mutex_unlock(&smu->mutex);
343 int smu_get_dpm_freq_by_index(struct smu_context *smu, enum smu_clk_type clk_type,
344 uint16_t level, uint32_t *value)
346 int ret = 0, clk_id = 0;
352 if (!smu_clk_dpm_is_enabled(smu, clk_type))
355 clk_id = smu_clk_get_index(smu, clk_type);
359 param = (uint32_t)(((clk_id & 0xffff) << 16) | (level & 0xffff));
361 ret = smu_send_smc_msg_with_param(smu, SMU_MSG_GetDpmFreqByIndex,
366 /* BIT31: 0 - Fine grained DPM, 1 - Dicrete DPM
367 * now, we un-support it */
368 *value = *value & 0x7fffffff;
373 int smu_get_dpm_level_count(struct smu_context *smu, enum smu_clk_type clk_type,
376 return smu_get_dpm_freq_by_index(smu, clk_type, 0xff, value);
379 int smu_get_dpm_level_range(struct smu_context *smu, enum smu_clk_type clk_type,
380 uint32_t *min_value, uint32_t *max_value)
383 uint32_t level_count = 0;
385 if (!min_value && !max_value)
389 /* by default, level 0 clock value as min value */
390 ret = smu_get_dpm_freq_by_index(smu, clk_type, 0, min_value);
396 ret = smu_get_dpm_level_count(smu, clk_type, &level_count);
400 ret = smu_get_dpm_freq_by_index(smu, clk_type, level_count - 1, max_value);
408 bool smu_clk_dpm_is_enabled(struct smu_context *smu, enum smu_clk_type clk_type)
410 enum smu_feature_mask feature_id = 0;
415 feature_id = SMU_FEATURE_DPM_UCLK_BIT;
419 feature_id = SMU_FEATURE_DPM_GFXCLK_BIT;
422 feature_id = SMU_FEATURE_DPM_SOCCLK_BIT;
428 if(!smu_feature_is_enabled(smu, feature_id)) {
436 * smu_dpm_set_power_gate - power gate/ungate the specific IP block
438 * @smu: smu_context pointer
439 * @block_type: the IP block to power gate/ungate
440 * @gate: to power gate if true, ungate otherwise
442 * This API uses no smu->mutex lock protection due to:
443 * 1. It is either called by other IP block(gfx/sdma/vcn/uvd/vce).
444 * This is guarded to be race condition free by the caller.
445 * 2. Or get called on user setting request of power_dpm_force_performance_level.
446 * Under this case, the smu->mutex lock protection is already enforced on
447 * the parent API smu_force_performance_level of the call path.
449 int smu_dpm_set_power_gate(struct smu_context *smu, uint32_t block_type,
454 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
457 switch (block_type) {
459 * Some legacy code of amdgpu_vcn.c and vcn_v2*.c still uses
460 * AMD_IP_BLOCK_TYPE_UVD for VCN. So, here both of them are kept.
462 case AMD_IP_BLOCK_TYPE_UVD:
463 case AMD_IP_BLOCK_TYPE_VCN:
464 ret = smu_dpm_set_vcn_enable(smu, !gate);
466 dev_err(smu->adev->dev, "Failed to power %s VCN!\n",
467 gate ? "gate" : "ungate");
469 case AMD_IP_BLOCK_TYPE_GFX:
470 ret = smu_gfx_off_control(smu, gate);
472 dev_err(smu->adev->dev, "Failed to %s gfxoff!\n",
473 gate ? "enable" : "disable");
475 case AMD_IP_BLOCK_TYPE_SDMA:
476 ret = smu_powergate_sdma(smu, gate);
478 dev_err(smu->adev->dev, "Failed to power %s SDMA!\n",
479 gate ? "gate" : "ungate");
481 case AMD_IP_BLOCK_TYPE_JPEG:
482 ret = smu_dpm_set_jpeg_enable(smu, !gate);
484 dev_err(smu->adev->dev, "Failed to power %s JPEG!\n",
485 gate ? "gate" : "ungate");
488 dev_err(smu->adev->dev, "Unsupported block type!\n");
495 int smu_get_power_num_states(struct smu_context *smu,
496 struct pp_states_info *state_info)
501 /* not support power state */
502 memset(state_info, 0, sizeof(struct pp_states_info));
503 state_info->nums = 1;
504 state_info->states[0] = POWER_STATE_TYPE_DEFAULT;
509 int smu_update_table(struct smu_context *smu, enum smu_table_id table_index, int argument,
510 void *table_data, bool drv2smu)
512 struct smu_table_context *smu_table = &smu->smu_table;
513 struct amdgpu_device *adev = smu->adev;
514 struct smu_table *table = &smu_table->driver_table;
515 int table_id = smu_table_get_index(smu, table_index);
518 if (!table_data || table_id >= SMU_TABLE_COUNT || table_id < 0)
521 table_size = smu_table->tables[table_index].size;
524 memcpy(table->cpu_addr, table_data, table_size);
526 * Flush hdp cache: to guard the content seen by
527 * GPU is consitent with CPU.
529 amdgpu_asic_flush_hdp(adev, NULL);
532 ret = smu_send_smc_msg_with_param(smu, drv2smu ?
533 SMU_MSG_TransferTableDram2Smu :
534 SMU_MSG_TransferTableSmu2Dram,
535 table_id | ((argument & 0xFFFF) << 16),
541 amdgpu_asic_flush_hdp(adev, NULL);
542 memcpy(table_data, table->cpu_addr, table_size);
548 bool is_support_sw_smu(struct amdgpu_device *adev)
550 if (adev->asic_type >= CHIP_ARCTURUS)
556 int smu_sys_get_pp_table(struct smu_context *smu, void **table)
558 struct smu_table_context *smu_table = &smu->smu_table;
559 uint32_t powerplay_table_size;
561 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
564 if (!smu_table->power_play_table && !smu_table->hardcode_pptable)
567 mutex_lock(&smu->mutex);
569 if (smu_table->hardcode_pptable)
570 *table = smu_table->hardcode_pptable;
572 *table = smu_table->power_play_table;
574 powerplay_table_size = smu_table->power_play_table_size;
576 mutex_unlock(&smu->mutex);
578 return powerplay_table_size;
581 int smu_sys_set_pp_table(struct smu_context *smu, void *buf, size_t size)
583 struct smu_table_context *smu_table = &smu->smu_table;
584 ATOM_COMMON_TABLE_HEADER *header = (ATOM_COMMON_TABLE_HEADER *)buf;
587 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
590 if (header->usStructureSize != size) {
591 dev_err(smu->adev->dev, "pp table size not matched !\n");
595 mutex_lock(&smu->mutex);
596 if (!smu_table->hardcode_pptable)
597 smu_table->hardcode_pptable = kzalloc(size, GFP_KERNEL);
598 if (!smu_table->hardcode_pptable) {
603 memcpy(smu_table->hardcode_pptable, buf, size);
604 smu_table->power_play_table = smu_table->hardcode_pptable;
605 smu_table->power_play_table_size = size;
608 * Special hw_fini action(for Navi1x, the DPMs disablement will be
609 * skipped) may be needed for custom pptable uploading.
611 smu->uploading_custom_pp_table = true;
613 ret = smu_reset(smu);
615 dev_info(smu->adev->dev, "smu reset failed, ret = %d\n", ret);
617 smu->uploading_custom_pp_table = false;
620 mutex_unlock(&smu->mutex);
624 static int smu_get_driver_allowed_feature_mask(struct smu_context *smu)
626 struct smu_feature *feature = &smu->smu_feature;
628 uint32_t allowed_feature_mask[SMU_FEATURE_MAX/32];
630 mutex_lock(&feature->mutex);
631 bitmap_zero(feature->allowed, SMU_FEATURE_MAX);
632 mutex_unlock(&feature->mutex);
634 ret = smu_get_allowed_feature_mask(smu, allowed_feature_mask,
639 mutex_lock(&feature->mutex);
640 bitmap_or(feature->allowed, feature->allowed,
641 (unsigned long *)allowed_feature_mask,
642 feature->feature_num);
643 mutex_unlock(&feature->mutex);
648 int smu_feature_is_enabled(struct smu_context *smu, enum smu_feature_mask mask)
650 struct smu_feature *feature = &smu->smu_feature;
656 feature_id = smu_feature_get_index(smu, mask);
660 WARN_ON(feature_id > feature->feature_num);
662 mutex_lock(&feature->mutex);
663 ret = test_bit(feature_id, feature->enabled);
664 mutex_unlock(&feature->mutex);
669 int smu_feature_set_enabled(struct smu_context *smu, enum smu_feature_mask mask,
672 struct smu_feature *feature = &smu->smu_feature;
675 feature_id = smu_feature_get_index(smu, mask);
679 WARN_ON(feature_id > feature->feature_num);
681 return smu_feature_update_enable_state(smu,
686 int smu_feature_is_supported(struct smu_context *smu, enum smu_feature_mask mask)
688 struct smu_feature *feature = &smu->smu_feature;
692 feature_id = smu_feature_get_index(smu, mask);
696 WARN_ON(feature_id > feature->feature_num);
698 mutex_lock(&feature->mutex);
699 ret = test_bit(feature_id, feature->supported);
700 mutex_unlock(&feature->mutex);
705 static int smu_set_funcs(struct amdgpu_device *adev)
707 struct smu_context *smu = &adev->smu;
709 if (adev->pm.pp_feature & PP_OVERDRIVE_MASK)
710 smu->od_enabled = true;
712 switch (adev->asic_type) {
716 navi10_set_ppt_funcs(smu);
719 adev->pm.pp_feature &= ~PP_GFXOFF_MASK;
720 arcturus_set_ppt_funcs(smu);
721 /* OD is not supported on Arcturus */
722 smu->od_enabled =false;
724 case CHIP_SIENNA_CICHLID:
725 sienna_cichlid_set_ppt_funcs(smu);
728 renoir_set_ppt_funcs(smu);
737 static int smu_early_init(void *handle)
739 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
740 struct smu_context *smu = &adev->smu;
743 smu->pm_enabled = !!amdgpu_dpm;
745 mutex_init(&smu->mutex);
747 return smu_set_funcs(adev);
750 static int smu_late_init(void *handle)
752 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
753 struct smu_context *smu = &adev->smu;
756 if (!smu->pm_enabled)
759 ret = smu_set_default_od_settings(smu);
761 dev_err(adev->dev, "Failed to setup default OD settings!\n");
766 * Set initialized values (get from vbios) to dpm tables context such as
767 * gfxclk, memclk, dcefclk, and etc. And enable the DPM feature for each
770 ret = smu_set_default_dpm_table(smu);
772 dev_err(adev->dev, "Failed to setup default dpm clock tables!\n");
776 ret = smu_populate_umd_state_clk(smu);
778 dev_err(adev->dev, "Failed to populate UMD state clocks!\n");
782 ret = smu_get_asic_power_limits(smu);
784 dev_err(adev->dev, "Failed to get asic power limits!\n");
788 smu_get_unique_id(smu);
790 smu_handle_task(&adev->smu,
791 smu->smu_dpm.dpm_level,
792 AMD_PP_TASK_COMPLETE_INIT,
798 int smu_get_atom_data_table(struct smu_context *smu, uint32_t table,
799 uint16_t *size, uint8_t *frev, uint8_t *crev,
802 struct amdgpu_device *adev = smu->adev;
805 if (!amdgpu_atom_parse_data_header(adev->mode_info.atom_context, table,
806 size, frev, crev, &data_start))
809 *addr = (uint8_t *)adev->mode_info.atom_context->bios + data_start;
814 static int smu_init_fb_allocations(struct smu_context *smu)
816 struct amdgpu_device *adev = smu->adev;
817 struct smu_table_context *smu_table = &smu->smu_table;
818 struct smu_table *tables = smu_table->tables;
819 struct smu_table *driver_table = &(smu_table->driver_table);
820 uint32_t max_table_size = 0;
823 /* VRAM allocation for tool table */
824 if (tables[SMU_TABLE_PMSTATUSLOG].size) {
825 ret = amdgpu_bo_create_kernel(adev,
826 tables[SMU_TABLE_PMSTATUSLOG].size,
827 tables[SMU_TABLE_PMSTATUSLOG].align,
828 tables[SMU_TABLE_PMSTATUSLOG].domain,
829 &tables[SMU_TABLE_PMSTATUSLOG].bo,
830 &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
831 &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
833 dev_err(adev->dev, "VRAM allocation for tool table failed!\n");
838 /* VRAM allocation for driver table */
839 for (i = 0; i < SMU_TABLE_COUNT; i++) {
840 if (tables[i].size == 0)
843 if (i == SMU_TABLE_PMSTATUSLOG)
846 if (max_table_size < tables[i].size)
847 max_table_size = tables[i].size;
850 driver_table->size = max_table_size;
851 driver_table->align = PAGE_SIZE;
852 driver_table->domain = AMDGPU_GEM_DOMAIN_VRAM;
854 ret = amdgpu_bo_create_kernel(adev,
857 driver_table->domain,
859 &driver_table->mc_address,
860 &driver_table->cpu_addr);
862 dev_err(adev->dev, "VRAM allocation for driver table failed!\n");
863 if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
864 amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
865 &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
866 &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
872 static int smu_fini_fb_allocations(struct smu_context *smu)
874 struct smu_table_context *smu_table = &smu->smu_table;
875 struct smu_table *tables = smu_table->tables;
876 struct smu_table *driver_table = &(smu_table->driver_table);
881 if (tables[SMU_TABLE_PMSTATUSLOG].mc_address)
882 amdgpu_bo_free_kernel(&tables[SMU_TABLE_PMSTATUSLOG].bo,
883 &tables[SMU_TABLE_PMSTATUSLOG].mc_address,
884 &tables[SMU_TABLE_PMSTATUSLOG].cpu_addr);
886 amdgpu_bo_free_kernel(&driver_table->bo,
887 &driver_table->mc_address,
888 &driver_table->cpu_addr);
894 * smu_alloc_memory_pool - allocate memory pool in the system memory
896 * @smu: amdgpu_device pointer
898 * This memory pool will be used for SMC use and msg SetSystemVirtualDramAddr
899 * and DramLogSetDramAddr can notify it changed.
901 * Returns 0 on success, error on failure.
903 static int smu_alloc_memory_pool(struct smu_context *smu)
905 struct amdgpu_device *adev = smu->adev;
906 struct smu_table_context *smu_table = &smu->smu_table;
907 struct smu_table *memory_pool = &smu_table->memory_pool;
908 uint64_t pool_size = smu->pool_size;
911 if (pool_size == SMU_MEMORY_POOL_SIZE_ZERO)
914 memory_pool->size = pool_size;
915 memory_pool->align = PAGE_SIZE;
916 memory_pool->domain = AMDGPU_GEM_DOMAIN_GTT;
919 case SMU_MEMORY_POOL_SIZE_256_MB:
920 case SMU_MEMORY_POOL_SIZE_512_MB:
921 case SMU_MEMORY_POOL_SIZE_1_GB:
922 case SMU_MEMORY_POOL_SIZE_2_GB:
923 ret = amdgpu_bo_create_kernel(adev,
928 &memory_pool->mc_address,
929 &memory_pool->cpu_addr);
931 dev_err(adev->dev, "VRAM allocation for dramlog failed!\n");
940 static int smu_free_memory_pool(struct smu_context *smu)
942 struct smu_table_context *smu_table = &smu->smu_table;
943 struct smu_table *memory_pool = &smu_table->memory_pool;
945 if (memory_pool->size == SMU_MEMORY_POOL_SIZE_ZERO)
948 amdgpu_bo_free_kernel(&memory_pool->bo,
949 &memory_pool->mc_address,
950 &memory_pool->cpu_addr);
952 memset(memory_pool, 0, sizeof(struct smu_table));
957 static int smu_smc_table_sw_init(struct smu_context *smu)
962 * Create smu_table structure, and init smc tables such as
963 * TABLE_PPTABLE, TABLE_WATERMARKS, TABLE_SMU_METRICS, and etc.
965 ret = smu_init_smc_tables(smu);
967 dev_err(smu->adev->dev, "Failed to init smc tables!\n");
972 * Create smu_power_context structure, and allocate smu_dpm_context and
973 * context size to fill the smu_power_context data.
975 ret = smu_init_power(smu);
977 dev_err(smu->adev->dev, "Failed to init smu_init_power!\n");
982 * allocate vram bos to store smc table contents.
984 ret = smu_init_fb_allocations(smu);
988 ret = smu_alloc_memory_pool(smu);
995 static int smu_smc_table_sw_fini(struct smu_context *smu)
999 ret = smu_free_memory_pool(smu);
1003 ret = smu_fini_fb_allocations(smu);
1007 ret = smu_fini_power(smu);
1009 dev_err(smu->adev->dev, "Failed to init smu_fini_power!\n");
1013 ret = smu_fini_smc_tables(smu);
1015 dev_err(smu->adev->dev, "Failed to smu_fini_smc_tables!\n");
1022 static void smu_throttling_logging_work_fn(struct work_struct *work)
1024 struct smu_context *smu = container_of(work, struct smu_context,
1025 throttling_logging_work);
1027 smu_log_thermal_throttling(smu);
1030 static int smu_sw_init(void *handle)
1032 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1033 struct smu_context *smu = &adev->smu;
1036 smu->pool_size = adev->pm.smu_prv_buffer_size;
1037 smu->smu_feature.feature_num = SMU_FEATURE_MAX;
1038 mutex_init(&smu->smu_feature.mutex);
1039 bitmap_zero(smu->smu_feature.supported, SMU_FEATURE_MAX);
1040 bitmap_zero(smu->smu_feature.enabled, SMU_FEATURE_MAX);
1041 bitmap_zero(smu->smu_feature.allowed, SMU_FEATURE_MAX);
1043 mutex_init(&smu->smu_baco.mutex);
1044 smu->smu_baco.state = SMU_BACO_STATE_EXIT;
1045 smu->smu_baco.platform_support = false;
1047 mutex_init(&smu->sensor_lock);
1048 mutex_init(&smu->metrics_lock);
1049 mutex_init(&smu->message_lock);
1051 INIT_WORK(&smu->throttling_logging_work, smu_throttling_logging_work_fn);
1052 smu->watermarks_bitmap = 0;
1053 smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
1054 smu->default_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
1056 smu->workload_mask = 1 << smu->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT];
1057 smu->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT] = 0;
1058 smu->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D] = 1;
1059 smu->workload_prority[PP_SMC_POWER_PROFILE_POWERSAVING] = 2;
1060 smu->workload_prority[PP_SMC_POWER_PROFILE_VIDEO] = 3;
1061 smu->workload_prority[PP_SMC_POWER_PROFILE_VR] = 4;
1062 smu->workload_prority[PP_SMC_POWER_PROFILE_COMPUTE] = 5;
1063 smu->workload_prority[PP_SMC_POWER_PROFILE_CUSTOM] = 6;
1065 smu->workload_setting[0] = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
1066 smu->workload_setting[1] = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1067 smu->workload_setting[2] = PP_SMC_POWER_PROFILE_POWERSAVING;
1068 smu->workload_setting[3] = PP_SMC_POWER_PROFILE_VIDEO;
1069 smu->workload_setting[4] = PP_SMC_POWER_PROFILE_VR;
1070 smu->workload_setting[5] = PP_SMC_POWER_PROFILE_COMPUTE;
1071 smu->workload_setting[6] = PP_SMC_POWER_PROFILE_CUSTOM;
1072 smu->display_config = &adev->pm.pm_display_cfg;
1074 smu->smu_dpm.dpm_level = AMD_DPM_FORCED_LEVEL_AUTO;
1075 smu->smu_dpm.requested_dpm_level = AMD_DPM_FORCED_LEVEL_AUTO;
1076 ret = smu_init_microcode(smu);
1078 dev_err(adev->dev, "Failed to load smu firmware!\n");
1082 ret = smu_smc_table_sw_init(smu);
1084 dev_err(adev->dev, "Failed to sw init smc table!\n");
1088 ret = smu_register_irq_handler(smu);
1090 dev_err(adev->dev, "Failed to register smc irq handler!\n");
1097 static int smu_sw_fini(void *handle)
1099 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1100 struct smu_context *smu = &adev->smu;
1103 ret = smu_smc_table_sw_fini(smu);
1105 dev_err(adev->dev, "Failed to sw fini smc table!\n");
1109 smu_fini_microcode(smu);
1114 static int smu_smc_hw_setup(struct smu_context *smu)
1116 struct amdgpu_device *adev = smu->adev;
1119 if (smu_is_dpm_running(smu) && adev->in_suspend) {
1120 dev_info(adev->dev, "dpm has been enabled\n");
1124 ret = smu_init_display_count(smu, 0);
1126 dev_info(adev->dev, "Failed to pre-set display count as 0!\n");
1130 ret = smu_set_driver_table_location(smu);
1132 dev_err(adev->dev, "Failed to SetDriverDramAddr!\n");
1137 * Set PMSTATUSLOG table bo address with SetToolsDramAddr MSG for tools.
1139 ret = smu_set_tool_table_location(smu);
1141 dev_err(adev->dev, "Failed to SetToolsDramAddr!\n");
1146 * Use msg SetSystemVirtualDramAddr and DramLogSetDramAddr can notify
1149 ret = smu_notify_memory_pool_location(smu);
1151 dev_err(adev->dev, "Failed to SetDramLogDramAddr!\n");
1155 /* smu_dump_pptable(smu); */
1157 * Copy pptable bo in the vram to smc with SMU MSGs such as
1158 * SetDriverDramAddr and TransferTableDram2Smu.
1160 ret = smu_write_pptable(smu);
1162 dev_err(adev->dev, "Failed to transfer pptable to SMC!\n");
1166 /* issue Run*Btc msg */
1167 ret = smu_run_btc(smu);
1171 ret = smu_feature_set_allowed_mask(smu);
1173 dev_err(adev->dev, "Failed to set driver allowed features mask!\n");
1177 ret = smu_system_features_control(smu, true);
1179 dev_err(adev->dev, "Failed to enable requested dpm features!\n");
1183 if (!smu_is_dpm_running(smu))
1184 dev_info(adev->dev, "dpm has been disabled\n");
1186 ret = smu_override_pcie_parameters(smu);
1190 ret = smu_enable_thermal_alert(smu);
1192 dev_err(adev->dev, "Failed to enable thermal alert!\n");
1196 ret = smu_i2c_eeprom_init(smu, &adev->pm.smu_i2c);
1200 ret = smu_disable_umc_cdr_12gbps_workaround(smu);
1202 dev_err(adev->dev, "Workaround failed to disable UMC CDR feature on 12Gbps SKU!\n");
1207 * For Navi1X, manually switch it to AC mode as PMFW
1208 * may boot it with DC mode.
1210 ret = smu_set_power_source(smu,
1211 adev->pm.ac_power ? SMU_POWER_SOURCE_AC :
1212 SMU_POWER_SOURCE_DC);
1214 dev_err(adev->dev, "Failed to switch to %s mode!\n", adev->pm.ac_power ? "AC" : "DC");
1218 ret = smu_notify_display_change(smu);
1223 * Set min deep sleep dce fclk with bootup value from vbios via
1224 * SetMinDeepSleepDcefclk MSG.
1226 ret = smu_set_min_dcef_deep_sleep(smu,
1227 smu->smu_table.boot_values.dcefclk / 100);
1234 static int smu_start_smc_engine(struct smu_context *smu)
1236 struct amdgpu_device *adev = smu->adev;
1239 if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
1240 if (adev->asic_type < CHIP_NAVI10) {
1241 if (smu->ppt_funcs->load_microcode) {
1242 ret = smu->ppt_funcs->load_microcode(smu);
1249 if (smu->ppt_funcs->check_fw_status) {
1250 ret = smu->ppt_funcs->check_fw_status(smu);
1252 dev_err(adev->dev, "SMC is not ready\n");
1258 * Send msg GetDriverIfVersion to check if the return value is equal
1259 * with DRIVER_IF_VERSION of smc header.
1261 ret = smu_check_fw_version(smu);
1268 static int smu_hw_init(void *handle)
1271 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1272 struct smu_context *smu = &adev->smu;
1274 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev)) {
1275 smu->pm_enabled = false;
1279 ret = smu_start_smc_engine(smu);
1281 dev_err(adev->dev, "SMC engine is not correctly up!\n");
1286 smu_powergate_sdma(&adev->smu, false);
1287 smu_dpm_set_vcn_enable(smu, true);
1288 smu_dpm_set_jpeg_enable(smu, true);
1289 smu_set_gfx_cgpg(&adev->smu, true);
1292 if (!smu->pm_enabled)
1295 /* get boot_values from vbios to set revision, gfxclk, and etc. */
1296 ret = smu_get_vbios_bootup_values(smu);
1298 dev_err(adev->dev, "Failed to get VBIOS boot clock values!\n");
1302 ret = smu_setup_pptable(smu);
1304 dev_err(adev->dev, "Failed to setup pptable!\n");
1308 ret = smu_get_driver_allowed_feature_mask(smu);
1312 ret = smu_smc_hw_setup(smu);
1314 dev_err(adev->dev, "Failed to setup smc hw!\n");
1319 * Move maximum sustainable clock retrieving here considering
1320 * 1. It is not needed on resume(from S3).
1321 * 2. DAL settings come between .hw_init and .late_init of SMU.
1322 * And DAL needs to know the maximum sustainable clocks. Thus
1323 * it cannot be put in .late_init().
1325 ret = smu_init_max_sustainable_clocks(smu);
1327 dev_err(adev->dev, "Failed to init max sustainable clocks!\n");
1331 adev->pm.dpm_enabled = true;
1333 dev_info(adev->dev, "SMU is initialized successfully!\n");
1338 static int smu_disable_dpms(struct smu_context *smu)
1340 struct amdgpu_device *adev = smu->adev;
1341 uint64_t features_to_disable;
1343 bool use_baco = !smu->is_apu &&
1344 ((adev->in_gpu_reset &&
1345 (amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO)) ||
1346 ((adev->in_runpm || adev->in_hibernate) && amdgpu_asic_supports_baco(adev)));
1349 * For custom pptable uploading, skip the DPM features
1350 * disable process on Navi1x ASICs.
1351 * - As the gfx related features are under control of
1352 * RLC on those ASICs. RLC reinitialization will be
1353 * needed to reenable them. That will cost much more
1356 * - SMU firmware can handle the DPM reenablement
1359 if (smu->uploading_custom_pp_table &&
1360 (adev->asic_type >= CHIP_NAVI10) &&
1361 (adev->asic_type <= CHIP_NAVI12))
1365 * For Sienna_Cichlid, PMFW will handle the features disablement properly
1366 * on BACO in. Driver involvement is unnecessary.
1368 if ((adev->asic_type == CHIP_SIENNA_CICHLID) &&
1373 * For gpu reset, runpm and hibernation through BACO,
1374 * BACO feature has to be kept enabled.
1376 if (use_baco && smu_feature_is_enabled(smu, SMU_FEATURE_BACO_BIT)) {
1377 features_to_disable = U64_MAX &
1378 ~(1ULL << smu_feature_get_index(smu, SMU_FEATURE_BACO_BIT));
1379 ret = smu_feature_update_enable_state(smu,
1380 features_to_disable,
1383 dev_err(adev->dev, "Failed to disable smu features except BACO.\n");
1385 ret = smu_system_features_control(smu, false);
1387 dev_err(adev->dev, "Failed to disable smu features.\n");
1390 if (adev->asic_type >= CHIP_NAVI10 &&
1391 adev->gfx.rlc.funcs->stop)
1392 adev->gfx.rlc.funcs->stop(adev);
1397 static int smu_smc_hw_cleanup(struct smu_context *smu)
1399 struct amdgpu_device *adev = smu->adev;
1402 smu_i2c_eeprom_fini(smu, &adev->pm.smu_i2c);
1404 cancel_work_sync(&smu->throttling_logging_work);
1406 ret = smu_disable_thermal_alert(smu);
1408 dev_err(adev->dev, "Fail to disable thermal alert!\n");
1412 ret = smu_disable_dpms(smu);
1414 dev_err(adev->dev, "Fail to disable dpm features!\n");
1421 static int smu_hw_fini(void *handle)
1423 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1424 struct smu_context *smu = &adev->smu;
1427 if (amdgpu_sriov_vf(adev)&& !amdgpu_sriov_is_pp_one_vf(adev))
1431 smu_powergate_sdma(&adev->smu, true);
1432 smu_dpm_set_vcn_enable(smu, false);
1433 smu_dpm_set_jpeg_enable(smu, false);
1436 if (!smu->pm_enabled)
1439 adev->pm.dpm_enabled = false;
1441 ret = smu_smc_hw_cleanup(smu);
1448 int smu_reset(struct smu_context *smu)
1450 struct amdgpu_device *adev = smu->adev;
1453 ret = smu_hw_fini(adev);
1457 ret = smu_hw_init(adev);
1461 ret = smu_late_init(adev);
1466 static int smu_suspend(void *handle)
1468 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1469 struct smu_context *smu = &adev->smu;
1472 if (amdgpu_sriov_vf(adev)&& !amdgpu_sriov_is_pp_one_vf(adev))
1475 if (!smu->pm_enabled)
1478 adev->pm.dpm_enabled = false;
1480 ret = smu_smc_hw_cleanup(smu);
1484 smu->watermarks_bitmap &= ~(WATERMARKS_LOADED);
1487 smu_set_gfx_cgpg(&adev->smu, false);
1492 static int smu_resume(void *handle)
1495 struct amdgpu_device *adev = (struct amdgpu_device *)handle;
1496 struct smu_context *smu = &adev->smu;
1498 if (amdgpu_sriov_vf(adev)&& !amdgpu_sriov_is_pp_one_vf(adev))
1501 if (!smu->pm_enabled)
1504 dev_info(adev->dev, "SMU is resuming...\n");
1506 ret = smu_start_smc_engine(smu);
1508 dev_err(adev->dev, "SMC engine is not correctly up!\n");
1512 ret = smu_smc_hw_setup(smu);
1514 dev_err(adev->dev, "Failed to setup smc hw!\n");
1519 smu_set_gfx_cgpg(&adev->smu, true);
1521 smu->disable_uclk_switch = 0;
1523 adev->pm.dpm_enabled = true;
1525 dev_info(adev->dev, "SMU is resumed successfully!\n");
1530 int smu_display_configuration_change(struct smu_context *smu,
1531 const struct amd_pp_display_configuration *display_config)
1534 int num_of_active_display = 0;
1536 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1539 if (!display_config)
1542 mutex_lock(&smu->mutex);
1544 smu_set_min_dcef_deep_sleep(smu,
1545 display_config->min_dcef_deep_sleep_set_clk / 100);
1547 for (index = 0; index < display_config->num_path_including_non_display; index++) {
1548 if (display_config->displays[index].controller_id != 0)
1549 num_of_active_display++;
1552 smu_set_active_display_count(smu, num_of_active_display);
1554 smu_store_cc6_data(smu, display_config->cpu_pstate_separation_time,
1555 display_config->cpu_cc6_disable,
1556 display_config->cpu_pstate_disable,
1557 display_config->nb_pstate_switch_disable);
1559 mutex_unlock(&smu->mutex);
1564 static int smu_get_clock_info(struct smu_context *smu,
1565 struct smu_clock_info *clk_info,
1566 enum smu_perf_level_designation designation)
1569 struct smu_performance_level level = {0};
1574 ret = smu_get_perf_level(smu, PERF_LEVEL_ACTIVITY, &level);
1578 clk_info->min_mem_clk = level.memory_clock;
1579 clk_info->min_eng_clk = level.core_clock;
1580 clk_info->min_bus_bandwidth = level.non_local_mem_freq * level.non_local_mem_width;
1582 ret = smu_get_perf_level(smu, designation, &level);
1586 clk_info->min_mem_clk = level.memory_clock;
1587 clk_info->min_eng_clk = level.core_clock;
1588 clk_info->min_bus_bandwidth = level.non_local_mem_freq * level.non_local_mem_width;
1593 int smu_get_current_clocks(struct smu_context *smu,
1594 struct amd_pp_clock_info *clocks)
1596 struct amd_pp_simple_clock_info simple_clocks = {0};
1597 struct smu_clock_info hw_clocks;
1600 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1603 mutex_lock(&smu->mutex);
1605 smu_get_dal_power_level(smu, &simple_clocks);
1607 if (smu->support_power_containment)
1608 ret = smu_get_clock_info(smu, &hw_clocks,
1609 PERF_LEVEL_POWER_CONTAINMENT);
1611 ret = smu_get_clock_info(smu, &hw_clocks, PERF_LEVEL_ACTIVITY);
1614 dev_err(smu->adev->dev, "Error in smu_get_clock_info\n");
1618 clocks->min_engine_clock = hw_clocks.min_eng_clk;
1619 clocks->max_engine_clock = hw_clocks.max_eng_clk;
1620 clocks->min_memory_clock = hw_clocks.min_mem_clk;
1621 clocks->max_memory_clock = hw_clocks.max_mem_clk;
1622 clocks->min_bus_bandwidth = hw_clocks.min_bus_bandwidth;
1623 clocks->max_bus_bandwidth = hw_clocks.max_bus_bandwidth;
1624 clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk;
1625 clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk;
1627 if (simple_clocks.level == 0)
1628 clocks->max_clocks_state = PP_DAL_POWERLEVEL_7;
1630 clocks->max_clocks_state = simple_clocks.level;
1632 if (!smu_get_current_shallow_sleep_clocks(smu, &hw_clocks)) {
1633 clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk;
1634 clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk;
1638 mutex_unlock(&smu->mutex);
1642 static int smu_set_clockgating_state(void *handle,
1643 enum amd_clockgating_state state)
1648 static int smu_set_powergating_state(void *handle,
1649 enum amd_powergating_state state)
1654 static int smu_enable_umd_pstate(void *handle,
1655 enum amd_dpm_forced_level *level)
1657 uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
1658 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
1659 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
1660 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
1662 struct smu_context *smu = (struct smu_context*)(handle);
1663 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
1665 if (!smu->is_apu && !smu_dpm_ctx->dpm_context)
1668 if (!(smu_dpm_ctx->dpm_level & profile_mode_mask)) {
1669 /* enter umd pstate, save current level, disable gfx cg*/
1670 if (*level & profile_mode_mask) {
1671 smu_dpm_ctx->saved_dpm_level = smu_dpm_ctx->dpm_level;
1672 smu_dpm_ctx->enable_umd_pstate = true;
1673 amdgpu_device_ip_set_powergating_state(smu->adev,
1674 AMD_IP_BLOCK_TYPE_GFX,
1675 AMD_PG_STATE_UNGATE);
1676 amdgpu_device_ip_set_clockgating_state(smu->adev,
1677 AMD_IP_BLOCK_TYPE_GFX,
1678 AMD_CG_STATE_UNGATE);
1681 /* exit umd pstate, restore level, enable gfx cg*/
1682 if (!(*level & profile_mode_mask)) {
1683 if (*level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)
1684 *level = smu_dpm_ctx->saved_dpm_level;
1685 smu_dpm_ctx->enable_umd_pstate = false;
1686 amdgpu_device_ip_set_clockgating_state(smu->adev,
1687 AMD_IP_BLOCK_TYPE_GFX,
1689 amdgpu_device_ip_set_powergating_state(smu->adev,
1690 AMD_IP_BLOCK_TYPE_GFX,
1698 int smu_adjust_power_state_dynamic(struct smu_context *smu,
1699 enum amd_dpm_forced_level level,
1700 bool skip_display_settings)
1705 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
1707 if (!skip_display_settings) {
1708 ret = smu_display_config_changed(smu);
1710 dev_err(smu->adev->dev, "Failed to change display config!");
1715 ret = smu_apply_clocks_adjust_rules(smu);
1717 dev_err(smu->adev->dev, "Failed to apply clocks adjust rules!");
1721 if (!skip_display_settings) {
1722 ret = smu_notify_smc_display_config(smu);
1724 dev_err(smu->adev->dev, "Failed to notify smc display config!");
1729 if (smu_dpm_ctx->dpm_level != level) {
1730 ret = smu_asic_set_performance_level(smu, level);
1732 dev_err(smu->adev->dev, "Failed to set performance level!");
1736 /* update the saved copy */
1737 smu_dpm_ctx->dpm_level = level;
1740 if (smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
1741 index = fls(smu->workload_mask);
1742 index = index > 0 && index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
1743 workload = smu->workload_setting[index];
1745 if (smu->power_profile_mode != workload)
1746 smu_set_power_profile_mode(smu, &workload, 0, false);
1752 int smu_handle_task(struct smu_context *smu,
1753 enum amd_dpm_forced_level level,
1754 enum amd_pp_task task_id,
1759 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1763 mutex_lock(&smu->mutex);
1766 case AMD_PP_TASK_DISPLAY_CONFIG_CHANGE:
1767 ret = smu_pre_display_config_changed(smu);
1770 ret = smu_set_cpu_power_state(smu);
1773 ret = smu_adjust_power_state_dynamic(smu, level, false);
1775 case AMD_PP_TASK_COMPLETE_INIT:
1776 case AMD_PP_TASK_READJUST_POWER_STATE:
1777 ret = smu_adjust_power_state_dynamic(smu, level, true);
1785 mutex_unlock(&smu->mutex);
1790 int smu_switch_power_profile(struct smu_context *smu,
1791 enum PP_SMC_POWER_PROFILE type,
1794 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
1798 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1801 if (!(type < PP_SMC_POWER_PROFILE_CUSTOM))
1804 mutex_lock(&smu->mutex);
1807 smu->workload_mask &= ~(1 << smu->workload_prority[type]);
1808 index = fls(smu->workload_mask);
1809 index = index > 0 && index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
1810 workload = smu->workload_setting[index];
1812 smu->workload_mask |= (1 << smu->workload_prority[type]);
1813 index = fls(smu->workload_mask);
1814 index = index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
1815 workload = smu->workload_setting[index];
1818 if (smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
1819 smu_set_power_profile_mode(smu, &workload, 0, false);
1821 mutex_unlock(&smu->mutex);
1826 enum amd_dpm_forced_level smu_get_performance_level(struct smu_context *smu)
1828 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
1829 enum amd_dpm_forced_level level;
1831 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1834 if (!smu->is_apu && !smu_dpm_ctx->dpm_context)
1837 mutex_lock(&(smu->mutex));
1838 level = smu_dpm_ctx->dpm_level;
1839 mutex_unlock(&(smu->mutex));
1844 int smu_force_performance_level(struct smu_context *smu, enum amd_dpm_forced_level level)
1846 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
1849 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1852 if (!smu->is_apu && !smu_dpm_ctx->dpm_context)
1855 mutex_lock(&smu->mutex);
1857 ret = smu_enable_umd_pstate(smu, &level);
1859 mutex_unlock(&smu->mutex);
1863 ret = smu_handle_task(smu, level,
1864 AMD_PP_TASK_READJUST_POWER_STATE,
1867 mutex_unlock(&smu->mutex);
1872 int smu_set_display_count(struct smu_context *smu, uint32_t count)
1876 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1879 mutex_lock(&smu->mutex);
1880 ret = smu_init_display_count(smu, count);
1881 mutex_unlock(&smu->mutex);
1886 int smu_force_clk_levels(struct smu_context *smu,
1887 enum smu_clk_type clk_type,
1891 struct smu_dpm_context *smu_dpm_ctx = &(smu->smu_dpm);
1894 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1897 if (smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL) {
1898 dev_dbg(smu->adev->dev, "force clock level is for dpm manual mode only.\n");
1903 mutex_lock(&smu->mutex);
1905 if (smu->ppt_funcs && smu->ppt_funcs->force_clk_levels)
1906 ret = smu->ppt_funcs->force_clk_levels(smu, clk_type, mask);
1909 mutex_unlock(&smu->mutex);
1915 * On system suspending or resetting, the dpm_enabled
1916 * flag will be cleared. So that those SMU services which
1917 * are not supported will be gated.
1918 * However, the mp1 state setting should still be granted
1919 * even if the dpm_enabled cleared.
1921 int smu_set_mp1_state(struct smu_context *smu,
1922 enum pp_mp1_state mp1_state)
1927 if (!smu->pm_enabled)
1930 mutex_lock(&smu->mutex);
1932 switch (mp1_state) {
1933 case PP_MP1_STATE_SHUTDOWN:
1934 msg = SMU_MSG_PrepareMp1ForShutdown;
1936 case PP_MP1_STATE_UNLOAD:
1937 msg = SMU_MSG_PrepareMp1ForUnload;
1939 case PP_MP1_STATE_RESET:
1940 msg = SMU_MSG_PrepareMp1ForReset;
1942 case PP_MP1_STATE_NONE:
1944 mutex_unlock(&smu->mutex);
1948 /* some asics may not support those messages */
1949 if (smu_msg_get_index(smu, msg) < 0) {
1950 mutex_unlock(&smu->mutex);
1954 ret = smu_send_smc_msg(smu, msg, NULL);
1956 dev_err(smu->adev->dev, "[PrepareMp1] Failed!\n");
1958 mutex_unlock(&smu->mutex);
1963 int smu_set_df_cstate(struct smu_context *smu,
1964 enum pp_df_cstate state)
1968 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1971 if (!smu->ppt_funcs || !smu->ppt_funcs->set_df_cstate)
1974 mutex_lock(&smu->mutex);
1976 ret = smu->ppt_funcs->set_df_cstate(smu, state);
1978 dev_err(smu->adev->dev, "[SetDfCstate] failed!\n");
1980 mutex_unlock(&smu->mutex);
1985 int smu_allow_xgmi_power_down(struct smu_context *smu, bool en)
1989 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
1992 if (!smu->ppt_funcs || !smu->ppt_funcs->allow_xgmi_power_down)
1995 mutex_lock(&smu->mutex);
1997 ret = smu->ppt_funcs->allow_xgmi_power_down(smu, en);
1999 dev_err(smu->adev->dev, "[AllowXgmiPowerDown] failed!\n");
2001 mutex_unlock(&smu->mutex);
2006 int smu_write_watermarks_table(struct smu_context *smu)
2008 void *watermarks_table = smu->smu_table.watermarks_table;
2010 if (!watermarks_table)
2013 return smu_update_table(smu,
2014 SMU_TABLE_WATERMARKS,
2020 int smu_set_watermarks_for_clock_ranges(struct smu_context *smu,
2021 struct dm_pp_wm_sets_with_clock_ranges_soc15 *clock_ranges)
2023 void *table = smu->smu_table.watermarks_table;
2025 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2031 mutex_lock(&smu->mutex);
2033 if (!smu->disable_watermark &&
2034 smu_feature_is_enabled(smu, SMU_FEATURE_DPM_DCEFCLK_BIT) &&
2035 smu_feature_is_enabled(smu, SMU_FEATURE_DPM_SOCCLK_BIT)) {
2036 smu_set_watermarks_table(smu, table, clock_ranges);
2038 if (!(smu->watermarks_bitmap & WATERMARKS_EXIST)) {
2039 smu->watermarks_bitmap |= WATERMARKS_EXIST;
2040 smu->watermarks_bitmap &= ~WATERMARKS_LOADED;
2044 mutex_unlock(&smu->mutex);
2049 int smu_set_ac_dc(struct smu_context *smu)
2053 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2056 /* controlled by firmware */
2057 if (smu->dc_controlled_by_gpio)
2060 mutex_lock(&smu->mutex);
2061 ret = smu_set_power_source(smu,
2062 smu->adev->pm.ac_power ? SMU_POWER_SOURCE_AC :
2063 SMU_POWER_SOURCE_DC);
2065 dev_err(smu->adev->dev, "Failed to switch to %s mode!\n",
2066 smu->adev->pm.ac_power ? "AC" : "DC");
2067 mutex_unlock(&smu->mutex);
2072 const struct amd_ip_funcs smu_ip_funcs = {
2074 .early_init = smu_early_init,
2075 .late_init = smu_late_init,
2076 .sw_init = smu_sw_init,
2077 .sw_fini = smu_sw_fini,
2078 .hw_init = smu_hw_init,
2079 .hw_fini = smu_hw_fini,
2080 .suspend = smu_suspend,
2081 .resume = smu_resume,
2083 .check_soft_reset = NULL,
2084 .wait_for_idle = NULL,
2086 .set_clockgating_state = smu_set_clockgating_state,
2087 .set_powergating_state = smu_set_powergating_state,
2088 .enable_umd_pstate = smu_enable_umd_pstate,
2091 const struct amdgpu_ip_block_version smu_v11_0_ip_block =
2093 .type = AMD_IP_BLOCK_TYPE_SMC,
2097 .funcs = &smu_ip_funcs,
2100 const struct amdgpu_ip_block_version smu_v12_0_ip_block =
2102 .type = AMD_IP_BLOCK_TYPE_SMC,
2106 .funcs = &smu_ip_funcs,
2109 int smu_load_microcode(struct smu_context *smu)
2113 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2116 mutex_lock(&smu->mutex);
2118 if (smu->ppt_funcs->load_microcode)
2119 ret = smu->ppt_funcs->load_microcode(smu);
2121 mutex_unlock(&smu->mutex);
2126 int smu_check_fw_status(struct smu_context *smu)
2130 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2133 mutex_lock(&smu->mutex);
2135 if (smu->ppt_funcs->check_fw_status)
2136 ret = smu->ppt_funcs->check_fw_status(smu);
2138 mutex_unlock(&smu->mutex);
2143 int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled)
2147 mutex_lock(&smu->mutex);
2149 if (smu->ppt_funcs->set_gfx_cgpg)
2150 ret = smu->ppt_funcs->set_gfx_cgpg(smu, enabled);
2152 mutex_unlock(&smu->mutex);
2157 int smu_set_fan_speed_rpm(struct smu_context *smu, uint32_t speed)
2161 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2164 mutex_lock(&smu->mutex);
2166 if (smu->ppt_funcs->set_fan_speed_rpm)
2167 ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
2169 mutex_unlock(&smu->mutex);
2174 int smu_get_power_limit(struct smu_context *smu,
2178 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2181 mutex_lock(&smu->mutex);
2183 *limit = (max_setting ? smu->max_power_limit : smu->current_power_limit);
2185 mutex_unlock(&smu->mutex);
2190 int smu_set_power_limit(struct smu_context *smu, uint32_t limit)
2194 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2197 mutex_lock(&smu->mutex);
2199 if (limit > smu->max_power_limit) {
2200 dev_err(smu->adev->dev,
2201 "New power limit (%d) is over the max allowed %d\n",
2202 limit, smu->max_power_limit);
2207 limit = smu->current_power_limit;
2209 if (smu->ppt_funcs->set_power_limit)
2210 ret = smu->ppt_funcs->set_power_limit(smu, limit);
2213 mutex_unlock(&smu->mutex);
2218 int smu_print_clk_levels(struct smu_context *smu, enum smu_clk_type clk_type, char *buf)
2222 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2225 mutex_lock(&smu->mutex);
2227 if (smu->ppt_funcs->print_clk_levels)
2228 ret = smu->ppt_funcs->print_clk_levels(smu, clk_type, buf);
2230 mutex_unlock(&smu->mutex);
2235 int smu_get_od_percentage(struct smu_context *smu, enum smu_clk_type type)
2239 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2242 mutex_lock(&smu->mutex);
2244 if (smu->ppt_funcs->get_od_percentage)
2245 ret = smu->ppt_funcs->get_od_percentage(smu, type);
2247 mutex_unlock(&smu->mutex);
2252 int smu_set_od_percentage(struct smu_context *smu, enum smu_clk_type type, uint32_t value)
2256 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2259 mutex_lock(&smu->mutex);
2261 if (smu->ppt_funcs->set_od_percentage)
2262 ret = smu->ppt_funcs->set_od_percentage(smu, type, value);
2264 mutex_unlock(&smu->mutex);
2269 int smu_od_edit_dpm_table(struct smu_context *smu,
2270 enum PP_OD_DPM_TABLE_COMMAND type,
2271 long *input, uint32_t size)
2275 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2278 mutex_lock(&smu->mutex);
2280 if (smu->ppt_funcs->od_edit_dpm_table)
2281 ret = smu->ppt_funcs->od_edit_dpm_table(smu, type, input, size);
2283 mutex_unlock(&smu->mutex);
2288 int smu_read_sensor(struct smu_context *smu,
2289 enum amd_pp_sensors sensor,
2290 void *data, uint32_t *size)
2294 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2300 mutex_lock(&smu->mutex);
2303 case AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK:
2304 *((uint32_t *)data) = smu->pstate_sclk;
2307 case AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK:
2308 *((uint32_t *)data) = smu->pstate_mclk;
2311 case AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK:
2312 ret = smu_feature_get_enabled_mask(smu, (uint32_t *)data, 2);
2315 case AMDGPU_PP_SENSOR_UVD_POWER:
2316 *(uint32_t *)data = smu_feature_is_enabled(smu, SMU_FEATURE_DPM_UVD_BIT) ? 1 : 0;
2319 case AMDGPU_PP_SENSOR_VCE_POWER:
2320 *(uint32_t *)data = smu_feature_is_enabled(smu, SMU_FEATURE_DPM_VCE_BIT) ? 1 : 0;
2323 case AMDGPU_PP_SENSOR_VCN_POWER_STATE:
2324 *(uint32_t *)data = smu->smu_power.power_gate.vcn_gated ? 0 : 1;
2327 case AMDGPU_PP_SENSOR_MIN_FAN_RPM:
2328 *(uint32_t *)data = 0;
2332 if (smu->ppt_funcs->read_sensor)
2333 ret = smu->ppt_funcs->read_sensor(smu, sensor, data, size);
2337 mutex_unlock(&smu->mutex);
2342 int smu_get_power_profile_mode(struct smu_context *smu, char *buf)
2346 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2349 mutex_lock(&smu->mutex);
2351 if (smu->ppt_funcs->get_power_profile_mode)
2352 ret = smu->ppt_funcs->get_power_profile_mode(smu, buf);
2354 mutex_unlock(&smu->mutex);
2359 int smu_set_power_profile_mode(struct smu_context *smu,
2361 uint32_t param_size,
2366 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2370 mutex_lock(&smu->mutex);
2372 if (smu->ppt_funcs->set_power_profile_mode)
2373 ret = smu->ppt_funcs->set_power_profile_mode(smu, param, param_size);
2376 mutex_unlock(&smu->mutex);
2382 int smu_get_fan_control_mode(struct smu_context *smu)
2386 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2389 mutex_lock(&smu->mutex);
2391 if (smu->ppt_funcs->get_fan_control_mode)
2392 ret = smu->ppt_funcs->get_fan_control_mode(smu);
2394 mutex_unlock(&smu->mutex);
2399 int smu_set_fan_control_mode(struct smu_context *smu, int value)
2403 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2406 mutex_lock(&smu->mutex);
2408 if (smu->ppt_funcs->set_fan_control_mode)
2409 ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
2411 mutex_unlock(&smu->mutex);
2416 int smu_get_fan_speed_percent(struct smu_context *smu, uint32_t *speed)
2420 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2423 mutex_lock(&smu->mutex);
2425 if (smu->ppt_funcs->get_fan_speed_percent)
2426 ret = smu->ppt_funcs->get_fan_speed_percent(smu, speed);
2428 mutex_unlock(&smu->mutex);
2433 int smu_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)
2437 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2440 mutex_lock(&smu->mutex);
2442 if (smu->ppt_funcs->set_fan_speed_percent)
2443 ret = smu->ppt_funcs->set_fan_speed_percent(smu, speed);
2445 mutex_unlock(&smu->mutex);
2450 int smu_get_fan_speed_rpm(struct smu_context *smu, uint32_t *speed)
2454 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2457 mutex_lock(&smu->mutex);
2459 if (smu->ppt_funcs->get_fan_speed_rpm)
2460 ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
2462 mutex_unlock(&smu->mutex);
2467 int smu_set_deep_sleep_dcefclk(struct smu_context *smu, int clk)
2471 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2474 mutex_lock(&smu->mutex);
2476 ret = smu_set_min_dcef_deep_sleep(smu, clk);
2478 mutex_unlock(&smu->mutex);
2483 int smu_set_active_display_count(struct smu_context *smu, uint32_t count)
2487 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2490 if (smu->ppt_funcs->set_active_display_count)
2491 ret = smu->ppt_funcs->set_active_display_count(smu, count);
2496 int smu_get_clock_by_type(struct smu_context *smu,
2497 enum amd_pp_clock_type type,
2498 struct amd_pp_clocks *clocks)
2502 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2505 mutex_lock(&smu->mutex);
2507 if (smu->ppt_funcs->get_clock_by_type)
2508 ret = smu->ppt_funcs->get_clock_by_type(smu, type, clocks);
2510 mutex_unlock(&smu->mutex);
2515 int smu_get_max_high_clocks(struct smu_context *smu,
2516 struct amd_pp_simple_clock_info *clocks)
2520 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2523 mutex_lock(&smu->mutex);
2525 if (smu->ppt_funcs->get_max_high_clocks)
2526 ret = smu->ppt_funcs->get_max_high_clocks(smu, clocks);
2528 mutex_unlock(&smu->mutex);
2533 int smu_get_clock_by_type_with_latency(struct smu_context *smu,
2534 enum smu_clk_type clk_type,
2535 struct pp_clock_levels_with_latency *clocks)
2539 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2542 mutex_lock(&smu->mutex);
2544 if (smu->ppt_funcs->get_clock_by_type_with_latency)
2545 ret = smu->ppt_funcs->get_clock_by_type_with_latency(smu, clk_type, clocks);
2547 mutex_unlock(&smu->mutex);
2552 int smu_get_clock_by_type_with_voltage(struct smu_context *smu,
2553 enum amd_pp_clock_type type,
2554 struct pp_clock_levels_with_voltage *clocks)
2558 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2561 mutex_lock(&smu->mutex);
2563 if (smu->ppt_funcs->get_clock_by_type_with_voltage)
2564 ret = smu->ppt_funcs->get_clock_by_type_with_voltage(smu, type, clocks);
2566 mutex_unlock(&smu->mutex);
2572 int smu_display_clock_voltage_request(struct smu_context *smu,
2573 struct pp_display_clock_request *clock_req)
2577 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2580 mutex_lock(&smu->mutex);
2582 if (smu->ppt_funcs->display_clock_voltage_request)
2583 ret = smu->ppt_funcs->display_clock_voltage_request(smu, clock_req);
2585 mutex_unlock(&smu->mutex);
2591 int smu_display_disable_memory_clock_switch(struct smu_context *smu, bool disable_memory_clock_switch)
2595 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2598 mutex_lock(&smu->mutex);
2600 if (smu->ppt_funcs->display_disable_memory_clock_switch)
2601 ret = smu->ppt_funcs->display_disable_memory_clock_switch(smu, disable_memory_clock_switch);
2603 mutex_unlock(&smu->mutex);
2608 int smu_notify_smu_enable_pwe(struct smu_context *smu)
2612 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2615 mutex_lock(&smu->mutex);
2617 if (smu->ppt_funcs->notify_smu_enable_pwe)
2618 ret = smu->ppt_funcs->notify_smu_enable_pwe(smu);
2620 mutex_unlock(&smu->mutex);
2625 int smu_set_xgmi_pstate(struct smu_context *smu,
2630 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2633 mutex_lock(&smu->mutex);
2635 if (smu->ppt_funcs->set_xgmi_pstate)
2636 ret = smu->ppt_funcs->set_xgmi_pstate(smu, pstate);
2638 mutex_unlock(&smu->mutex);
2641 dev_err(smu->adev->dev, "Failed to set XGMI pstate!\n");
2646 int smu_set_azalia_d3_pme(struct smu_context *smu)
2650 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2653 mutex_lock(&smu->mutex);
2655 if (smu->ppt_funcs->set_azalia_d3_pme)
2656 ret = smu->ppt_funcs->set_azalia_d3_pme(smu);
2658 mutex_unlock(&smu->mutex);
2664 * On system suspending or resetting, the dpm_enabled
2665 * flag will be cleared. So that those SMU services which
2666 * are not supported will be gated.
2668 * However, the baco/mode1 reset should still be granted
2669 * as they are still supported and necessary.
2671 bool smu_baco_is_support(struct smu_context *smu)
2675 if (!smu->pm_enabled)
2678 mutex_lock(&smu->mutex);
2680 if (smu->ppt_funcs && smu->ppt_funcs->baco_is_support)
2681 ret = smu->ppt_funcs->baco_is_support(smu);
2683 mutex_unlock(&smu->mutex);
2688 int smu_baco_get_state(struct smu_context *smu, enum smu_baco_state *state)
2690 if (smu->ppt_funcs->baco_get_state)
2693 mutex_lock(&smu->mutex);
2694 *state = smu->ppt_funcs->baco_get_state(smu);
2695 mutex_unlock(&smu->mutex);
2700 int smu_baco_enter(struct smu_context *smu)
2704 if (!smu->pm_enabled)
2707 mutex_lock(&smu->mutex);
2709 if (smu->ppt_funcs->baco_enter)
2710 ret = smu->ppt_funcs->baco_enter(smu);
2712 mutex_unlock(&smu->mutex);
2715 dev_err(smu->adev->dev, "Failed to enter BACO state!\n");
2720 int smu_baco_exit(struct smu_context *smu)
2724 if (!smu->pm_enabled)
2727 mutex_lock(&smu->mutex);
2729 if (smu->ppt_funcs->baco_exit)
2730 ret = smu->ppt_funcs->baco_exit(smu);
2732 mutex_unlock(&smu->mutex);
2735 dev_err(smu->adev->dev, "Failed to exit BACO state!\n");
2740 int smu_mode2_reset(struct smu_context *smu)
2744 if (!smu->pm_enabled)
2747 mutex_lock(&smu->mutex);
2749 if (smu->ppt_funcs->mode2_reset)
2750 ret = smu->ppt_funcs->mode2_reset(smu);
2752 mutex_unlock(&smu->mutex);
2755 dev_err(smu->adev->dev, "Mode2 reset failed!\n");
2760 int smu_get_max_sustainable_clocks_by_dc(struct smu_context *smu,
2761 struct pp_smu_nv_clock_table *max_clocks)
2765 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2768 mutex_lock(&smu->mutex);
2770 if (smu->ppt_funcs->get_max_sustainable_clocks_by_dc)
2771 ret = smu->ppt_funcs->get_max_sustainable_clocks_by_dc(smu, max_clocks);
2773 mutex_unlock(&smu->mutex);
2778 int smu_get_uclk_dpm_states(struct smu_context *smu,
2779 unsigned int *clock_values_in_khz,
2780 unsigned int *num_states)
2784 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2787 mutex_lock(&smu->mutex);
2789 if (smu->ppt_funcs->get_uclk_dpm_states)
2790 ret = smu->ppt_funcs->get_uclk_dpm_states(smu, clock_values_in_khz, num_states);
2792 mutex_unlock(&smu->mutex);
2797 enum amd_pm_state_type smu_get_current_power_state(struct smu_context *smu)
2799 enum amd_pm_state_type pm_state = POWER_STATE_TYPE_DEFAULT;
2801 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2804 mutex_lock(&smu->mutex);
2806 if (smu->ppt_funcs->get_current_power_state)
2807 pm_state = smu->ppt_funcs->get_current_power_state(smu);
2809 mutex_unlock(&smu->mutex);
2814 int smu_get_dpm_clock_table(struct smu_context *smu,
2815 struct dpm_clocks *clock_table)
2819 if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
2822 mutex_lock(&smu->mutex);
2824 if (smu->ppt_funcs->get_dpm_clock_table)
2825 ret = smu->ppt_funcs->get_dpm_clock_table(smu, clock_table);
2827 mutex_unlock(&smu->mutex);