]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
drm/amd/powerplay: refine code to support no-dpm case
[linux.git] / drivers / gpu / drm / amd / powerplay / arcturus_ppt.c
index d493a3f8c07a63bd570b25905e965f854bf74e90..1c15c6fbe3b9fa535a0a7bd6c5cb8e6d7df920d0 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/firmware.h>
 #include "amdgpu.h"
 #include "amdgpu_smu.h"
+#include "smu_internal.h"
 #include "atomfirmware.h"
 #include "amdgpu_atomfirmware.h"
 #include "smu_v11_0.h"
 #include "smu_v11_0_pptable.h"
 #include "arcturus_ppsmc.h"
 #include "nbio/nbio_7_4_sh_mask.h"
+#include "amdgpu_xgmi.h"
+#include <linux/i2c.h>
+#include <linux/pci.h>
+#include "amdgpu_ras.h"
+
+#define to_amdgpu_device(x) (container_of(x, struct amdgpu_ras, eeprom_control.eeprom_accessor))->adev
 
 #define CTF_OFFSET_EDGE                        5
 #define CTF_OFFSET_HOTSPOT             5
@@ -112,8 +119,7 @@ static struct smu_11_0_cmn2aisc_mapping arcturus_message_map[SMU_MSG_MAX_COUNT]
        MSG_MAP(PrepareMp1ForShutdown,               PPSMC_MSG_PrepareMp1ForShutdown),
        MSG_MAP(SoftReset,                           PPSMC_MSG_SoftReset),
        MSG_MAP(RunAfllBtc,                          PPSMC_MSG_RunAfllBtc),
-       MSG_MAP(RunGfxDcBtc,                         PPSMC_MSG_RunGfxDcBtc),
-       MSG_MAP(RunSocDcBtc,                         PPSMC_MSG_RunSocDcBtc),
+       MSG_MAP(RunDcBtc,                            PPSMC_MSG_RunDcBtc),
        MSG_MAP(DramLogSetDramAddrHigh,              PPSMC_MSG_DramLogSetDramAddrHigh),
        MSG_MAP(DramLogSetDramAddrLow,               PPSMC_MSG_DramLogSetDramAddrLow),
        MSG_MAP(DramLogSetDramSize,                  PPSMC_MSG_DramLogSetDramSize),
@@ -172,6 +178,8 @@ static struct smu_11_0_cmn2aisc_mapping arcturus_table_map[SMU_TABLE_COUNT] = {
        TAB_MAP(SMU_METRICS),
        TAB_MAP(DRIVER_SMU_CONFIG),
        TAB_MAP(OVERDRIVE),
+       TAB_MAP(I2C_COMMANDS),
+       TAB_MAP(ACTIVITY_MONITOR_COEFF),
 };
 
 static struct smu_11_0_cmn2aisc_mapping arcturus_pwr_src_map[SMU_POWER_SOURCE_COUNT] = {
@@ -273,10 +281,8 @@ static int arcturus_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER
                return -EINVAL;
 
        mapping = arcturus_workload_map[profile];
-       if (!(mapping.valid_mapping)) {
-               pr_warn("Unsupported SMU power source: %d\n", profile);
+       if (!(mapping.valid_mapping))
                return -EINVAL;
-       }
 
        return mapping.map_to;
 }
@@ -294,6 +300,13 @@ static int arcturus_tables_init(struct smu_context *smu, struct smu_table *table
        SMU_TABLE_INIT(tables, SMU_TABLE_SMU_METRICS, sizeof(SmuMetrics_t),
                       PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
 
+       SMU_TABLE_INIT(tables, SMU_TABLE_I2C_COMMANDS, sizeof(SwI2cRequest_t),
+                              PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
+
+       SMU_TABLE_INIT(tables, SMU_TABLE_ACTIVITY_MONITOR_COEFF,
+                      sizeof(DpmActivityMonitorCoeffInt_t), PAGE_SIZE,
+                      AMDGPU_GEM_DOMAIN_VRAM);
+
        smu_table->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL);
        if (!smu_table->metrics_table)
                return -ENOMEM;
@@ -485,6 +498,7 @@ static int arcturus_store_powerplay_table(struct smu_context *smu)
 {
        struct smu_11_0_powerplay_table *powerplay_table = NULL;
        struct smu_table_context *table_context = &smu->smu_table;
+       struct smu_baco_context *smu_baco = &smu->smu_baco;
        int ret = 0;
 
        if (!table_context->power_play_table)
@@ -497,6 +511,12 @@ static int arcturus_store_powerplay_table(struct smu_context *smu)
 
        table_context->thermal_controller_type = powerplay_table->thermal_controller_type;
 
+       mutex_lock(&smu_baco->mutex);
+       if (powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_BACO ||
+           powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_MACO)
+               smu_baco->platform_support = true;
+       mutex_unlock(&smu_baco->mutex);
+
        return ret;
 }
 
@@ -528,9 +548,17 @@ static int arcturus_append_powerplay_table(struct smu_context *smu)
        return 0;
 }
 
-static int arcturus_run_btc_afll(struct smu_context *smu)
+static int arcturus_run_btc(struct smu_context *smu)
 {
-       return smu_send_smc_msg(smu, SMU_MSG_RunAfllBtc);
+       int ret = 0;
+
+       ret = smu_send_smc_msg(smu, SMU_MSG_RunAfllBtc);
+       if (ret) {
+               pr_err("RunAfllBtc failed!\n");
+               return ret;
+       }
+
+       return smu_send_smc_msg(smu, SMU_MSG_RunDcBtc);
 }
 
 static int arcturus_populate_umd_state_clk(struct smu_context *smu)
@@ -610,12 +638,17 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
                        return ret;
                }
 
+               /*
+                * For DPM disabled case, there will be only one clock level.
+                * And it's safe to assume that is always the current clock.
+                */
                for (i = 0; i < clocks.num_levels; i++)
                        size += sprintf(buf + size, "%d: %uMhz %s\n", i,
                                        clocks.data[i].clocks_in_khz / 1000,
-                                       arcturus_freqs_in_same_level(
+                                       (clocks.num_levels == 1) ? "*" :
+                                       (arcturus_freqs_in_same_level(
                                        clocks.data[i].clocks_in_khz / 1000,
-                                       now / 100) ? "*" : "");
+                                       now / 100) ? "*" : ""));
                break;
 
        case SMU_MCLK:
@@ -635,9 +668,10 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
                for (i = 0; i < clocks.num_levels; i++)
                        size += sprintf(buf + size, "%d: %uMhz %s\n",
                                i, clocks.data[i].clocks_in_khz / 1000,
-                               arcturus_freqs_in_same_level(
+                               (clocks.num_levels == 1) ? "*" :
+                               (arcturus_freqs_in_same_level(
                                clocks.data[i].clocks_in_khz / 1000,
-                               now / 100) ? "*" : "");
+                               now / 100) ? "*" : ""));
                break;
 
        case SMU_SOCCLK:
@@ -657,9 +691,10 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
                for (i = 0; i < clocks.num_levels; i++)
                        size += sprintf(buf + size, "%d: %uMhz %s\n",
                                i, clocks.data[i].clocks_in_khz / 1000,
-                               arcturus_freqs_in_same_level(
+                               (clocks.num_levels == 1) ? "*" :
+                               (arcturus_freqs_in_same_level(
                                clocks.data[i].clocks_in_khz / 1000,
-                               now / 100) ? "*" : "");
+                               now / 100) ? "*" : ""));
                break;
 
        case SMU_FCLK:
@@ -679,9 +714,10 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
                for (i = 0; i < single_dpm_table->count; i++)
                        size += sprintf(buf + size, "%d: %uMhz %s\n",
                                i, single_dpm_table->dpm_levels[i].value,
-                               arcturus_freqs_in_same_level(
+                               (clocks.num_levels == 1) ? "*" :
+                               (arcturus_freqs_in_same_level(
                                clocks.data[i].clocks_in_khz / 1000,
-                               now / 100) ? "*" : "");
+                               now / 100) ? "*" : ""));
                break;
 
        default:
@@ -756,8 +792,6 @@ static int arcturus_force_clk_levels(struct smu_context *smu,
        uint32_t soft_min_level, soft_max_level;
        int ret = 0;
 
-       mutex_lock(&(smu->mutex));
-
        soft_min_level = mask ? (ffs(mask) - 1) : 0;
        soft_max_level = mask ? (fls(mask) - 1) : 0;
 
@@ -792,91 +826,19 @@ static int arcturus_force_clk_levels(struct smu_context *smu,
                break;
 
        case SMU_MCLK:
-               single_dpm_table = &(dpm_table->mem_table);
-
-               if (soft_max_level >= single_dpm_table->count) {
-                       pr_err("Clock level specified %d is over max allowed %d\n",
-                                       soft_max_level, single_dpm_table->count - 1);
-                       ret = -EINVAL;
-                       break;
-               }
-
-               single_dpm_table->dpm_state.soft_min_level =
-                       single_dpm_table->dpm_levels[soft_min_level].value;
-               single_dpm_table->dpm_state.soft_max_level =
-                       single_dpm_table->dpm_levels[soft_max_level].value;
-
-               ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_UCLK_MASK);
-               if (ret) {
-                       pr_err("Failed to upload boot level to lowest!\n");
-                       break;
-               }
-
-               ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_UCLK_MASK);
-               if (ret)
-                       pr_err("Failed to upload dpm max level to highest!\n");
-
-               break;
-
        case SMU_SOCCLK:
-               single_dpm_table = &(dpm_table->soc_table);
-
-               if (soft_max_level >= single_dpm_table->count) {
-                       pr_err("Clock level specified %d is over max allowed %d\n",
-                                       soft_max_level, single_dpm_table->count - 1);
-                       ret = -EINVAL;
-                       break;
-               }
-
-               single_dpm_table->dpm_state.soft_min_level =
-                       single_dpm_table->dpm_levels[soft_min_level].value;
-               single_dpm_table->dpm_state.soft_max_level =
-                       single_dpm_table->dpm_levels[soft_max_level].value;
-
-               ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_SOCCLK_MASK);
-               if (ret) {
-                       pr_err("Failed to upload boot level to lowest!\n");
-                       break;
-               }
-
-               ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_SOCCLK_MASK);
-               if (ret)
-                       pr_err("Failed to upload dpm max level to highest!\n");
-
-               break;
-
        case SMU_FCLK:
-               single_dpm_table = &(dpm_table->fclk_table);
-
-               if (soft_max_level >= single_dpm_table->count) {
-                       pr_err("Clock level specified %d is over max allowed %d\n",
-                                       soft_max_level, single_dpm_table->count - 1);
-                       ret = -EINVAL;
-                       break;
-               }
-
-               single_dpm_table->dpm_state.soft_min_level =
-                       single_dpm_table->dpm_levels[soft_min_level].value;
-               single_dpm_table->dpm_state.soft_max_level =
-                       single_dpm_table->dpm_levels[soft_max_level].value;
-
-               ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_FCLK_MASK);
-               if (ret) {
-                       pr_err("Failed to upload boot level to lowest!\n");
-                       break;
-               }
-
-               ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_FCLK_MASK);
-               if (ret)
-                       pr_err("Failed to upload dpm max level to highest!\n");
-
+               /*
+                * Should not arrive here since Arcturus does not
+                * support mclk/socclk/fclk softmin/softmax settings
+                */
+               ret = -EINVAL;
                break;
 
        default:
                break;
        }
 
-       mutex_unlock(&(smu->mutex));
        return ret;
 }
 
@@ -910,18 +872,21 @@ static int arcturus_get_metrics_table(struct smu_context *smu,
        struct smu_table_context *smu_table= &smu->smu_table;
        int ret = 0;
 
+       mutex_lock(&smu->metrics_lock);
        if (!smu_table->metrics_time ||
             time_after(jiffies, smu_table->metrics_time + HZ / 1000)) {
                ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, 0,
                                (void *)smu_table->metrics_table, false);
                if (ret) {
                        pr_info("Failed to export SMU metrics table!\n");
+                       mutex_unlock(&smu->metrics_lock);
                        return ret;
                }
                smu_table->metrics_time = jiffies;
        }
 
        memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t));
+       mutex_unlock(&smu->metrics_lock);
 
        return ret;
 }
@@ -1043,7 +1008,7 @@ static int arcturus_read_sensor(struct smu_context *smu,
                *size = 4;
                break;
        default:
-               ret = smu_smc_read_sensor(smu, sensor, data, size);
+               ret = smu_v11_0_read_sensor(smu, sensor, data, size);
        }
        mutex_unlock(&smu->sensor_lock);
 
@@ -1186,6 +1151,7 @@ static int arcturus_force_dpm_limit_value(struct smu_context *smu, bool highest)
 {
        struct arcturus_dpm_table *dpm_table =
                (struct arcturus_dpm_table *)smu->smu_dpm.dpm_context;
+       struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(smu->adev, 0);
        uint32_t soft_level;
        int ret = 0;
 
@@ -1199,40 +1165,27 @@ static int arcturus_force_dpm_limit_value(struct smu_context *smu, bool highest)
                dpm_table->gfx_table.dpm_state.soft_max_level =
                dpm_table->gfx_table.dpm_levels[soft_level].value;
 
-       /* uclk */
-       if (highest)
-               soft_level = arcturus_find_highest_dpm_level(&(dpm_table->mem_table));
-       else
-               soft_level = arcturus_find_lowest_dpm_level(&(dpm_table->mem_table));
-
-       dpm_table->mem_table.dpm_state.soft_min_level =
-               dpm_table->mem_table.dpm_state.soft_max_level =
-               dpm_table->mem_table.dpm_levels[soft_level].value;
-
-       /* socclk */
-       if (highest)
-               soft_level = arcturus_find_highest_dpm_level(&(dpm_table->soc_table));
-       else
-               soft_level = arcturus_find_lowest_dpm_level(&(dpm_table->soc_table));
-
-       dpm_table->soc_table.dpm_state.soft_min_level =
-               dpm_table->soc_table.dpm_state.soft_max_level =
-               dpm_table->soc_table.dpm_levels[soft_level].value;
-
-       ret = arcturus_upload_dpm_level(smu, false, 0xFFFFFFFF);
+       ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
        if (ret) {
                pr_err("Failed to upload boot level to %s!\n",
                                highest ? "highest" : "lowest");
                return ret;
        }
 
-       ret = arcturus_upload_dpm_level(smu, true, 0xFFFFFFFF);
+       ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
        if (ret) {
                pr_err("Failed to upload dpm max level to %s!\n!",
                                highest ? "highest" : "lowest");
                return ret;
        }
 
+       if (hive)
+               /*
+                * Force XGMI Pstate to highest or lowest
+                * TODO: revise this when xgmi dpm is functional
+                */
+               ret = smu_v11_0_set_xgmi_pstate(smu, highest ? 1 : 0);
+
        return ret;
 }
 
@@ -1240,6 +1193,7 @@ static int arcturus_unforce_dpm_levels(struct smu_context *smu)
 {
        struct arcturus_dpm_table *dpm_table =
                (struct arcturus_dpm_table *)smu->smu_dpm.dpm_context;
+       struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(smu->adev, 0);
        uint32_t soft_min_level, soft_max_level;
        int ret = 0;
 
@@ -1251,34 +1205,25 @@ static int arcturus_unforce_dpm_levels(struct smu_context *smu)
        dpm_table->gfx_table.dpm_state.soft_max_level =
                dpm_table->gfx_table.dpm_levels[soft_max_level].value;
 
-       /* uclk */
-       soft_min_level = arcturus_find_lowest_dpm_level(&(dpm_table->mem_table));
-       soft_max_level = arcturus_find_highest_dpm_level(&(dpm_table->mem_table));
-       dpm_table->mem_table.dpm_state.soft_min_level =
-               dpm_table->gfx_table.dpm_levels[soft_min_level].value;
-       dpm_table->mem_table.dpm_state.soft_max_level =
-               dpm_table->gfx_table.dpm_levels[soft_max_level].value;
-
-       /* socclk */
-       soft_min_level = arcturus_find_lowest_dpm_level(&(dpm_table->soc_table));
-       soft_max_level = arcturus_find_highest_dpm_level(&(dpm_table->soc_table));
-       dpm_table->soc_table.dpm_state.soft_min_level =
-               dpm_table->soc_table.dpm_levels[soft_min_level].value;
-       dpm_table->soc_table.dpm_state.soft_max_level =
-               dpm_table->soc_table.dpm_levels[soft_max_level].value;
-
-       ret = arcturus_upload_dpm_level(smu, false, 0xFFFFFFFF);
+       ret = arcturus_upload_dpm_level(smu, false, FEATURE_DPM_GFXCLK_MASK);
        if (ret) {
                pr_err("Failed to upload DPM Bootup Levels!");
                return ret;
        }
 
-       ret = arcturus_upload_dpm_level(smu, true, 0xFFFFFFFF);
+       ret = arcturus_upload_dpm_level(smu, true, FEATURE_DPM_GFXCLK_MASK);
        if (ret) {
                pr_err("Failed to upload DPM Max Levels!");
                return ret;
        }
 
+       if (hive)
+               /*
+                * Reset XGMI Pstate back to default
+                * TODO: revise this when xgmi dpm is functional
+                */
+               ret = smu_v11_0_set_xgmi_pstate(smu, 0);
+
        return ret;
 }
 
@@ -1329,15 +1274,14 @@ arcturus_get_profiling_clk_mask(struct smu_context *smu,
 
 static int arcturus_get_power_limit(struct smu_context *smu,
                                     uint32_t *limit,
-                                    bool asic_default)
+                                    bool cap)
 {
        PPTable_t *pptable = smu->smu_table.driver_pptable;
        uint32_t asic_default_power_limit = 0;
        int ret = 0;
        int power_src;
 
-       if (!smu->default_power_limit ||
-           !smu->power_limit) {
+       if (!smu->power_limit) {
                if (smu_feature_is_enabled(smu, SMU_FEATURE_PPT_BIT)) {
                        power_src = smu_power_get_index(smu, SMU_POWER_SOURCE_AC);
                        if (power_src < 0)
@@ -1360,17 +1304,11 @@ static int arcturus_get_power_limit(struct smu_context *smu,
                                pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
                }
 
-               if (smu->od_enabled) {
-                       asic_default_power_limit *= (100 + smu->smu_table.TDPODLimit);
-                       asic_default_power_limit /= 100;
-               }
-
-               smu->default_power_limit = asic_default_power_limit;
                smu->power_limit = asic_default_power_limit;
        }
 
-       if (asic_default)
-               *limit = smu->default_power_limit;
+       if (cap)
+               *limit = smu_v11_0_get_max_power_limit(smu);
        else
                *limit = smu->power_limit;
 
@@ -1380,6 +1318,7 @@ static int arcturus_get_power_limit(struct smu_context *smu,
 static int arcturus_get_power_profile_mode(struct smu_context *smu,
                                           char *buf)
 {
+       DpmActivityMonitorCoeffInt_t activity_monitor;
        static const char *profile_name[] = {
                                        "BOOTUP_DEFAULT",
                                        "3D_FULL_SCREEN",
@@ -1388,12 +1327,38 @@ static int arcturus_get_power_profile_mode(struct smu_context *smu,
                                        "VR",
                                        "COMPUTE",
                                        "CUSTOM"};
+       static const char *title[] = {
+                       "PROFILE_INDEX(NAME)",
+                       "CLOCK_TYPE(NAME)",
+                       "FPS",
+                       "UseRlcBusy",
+                       "MinActiveFreqType",
+                       "MinActiveFreq",
+                       "BoosterFreqType",
+                       "BoosterFreq",
+                       "PD_Data_limit_c",
+                       "PD_Data_error_coeff",
+                       "PD_Data_error_rate_coeff"};
        uint32_t i, size = 0;
        int16_t workload_type = 0;
+       int result = 0;
+       uint32_t smu_version;
 
-       if (!smu->pm_enabled || !buf)
+       if (!buf)
                return -EINVAL;
 
+       result = smu_get_smc_version(smu, NULL, &smu_version);
+       if (result)
+               return result;
+
+       if (smu_version >= 0x360d00)
+               size += sprintf(buf + size, "%16s %s %s %s %s %s %s %s %s %s %s\n",
+                       title[0], title[1], title[2], title[3], title[4], title[5],
+                       title[6], title[7], title[8], title[9], title[10]);
+       else
+               size += sprintf(buf + size, "%16s\n",
+                       title[0]);
+
        for (i = 0; i <= PP_SMC_POWER_PROFILE_CUSTOM; i++) {
                /*
                 * Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT
@@ -1403,8 +1368,50 @@ static int arcturus_get_power_profile_mode(struct smu_context *smu,
                if (workload_type < 0)
                        continue;
 
+               if (smu_version >= 0x360d00) {
+                       result = smu_update_table(smu,
+                                                 SMU_TABLE_ACTIVITY_MONITOR_COEFF,
+                                                 workload_type,
+                                                 (void *)(&activity_monitor),
+                                                 false);
+                       if (result) {
+                               pr_err("[%s] Failed to get activity monitor!", __func__);
+                               return result;
+                       }
+               }
+
                size += sprintf(buf + size, "%2d %14s%s\n",
                        i, profile_name[i], (i == smu->power_profile_mode) ? "*" : " ");
+
+               if (smu_version >= 0x360d00) {
+                       size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
+                               " ",
+                               0,
+                               "GFXCLK",
+                               activity_monitor.Gfx_FPS,
+                               activity_monitor.Gfx_UseRlcBusy,
+                               activity_monitor.Gfx_MinActiveFreqType,
+                               activity_monitor.Gfx_MinActiveFreq,
+                               activity_monitor.Gfx_BoosterFreqType,
+                               activity_monitor.Gfx_BoosterFreq,
+                               activity_monitor.Gfx_PD_Data_limit_c,
+                               activity_monitor.Gfx_PD_Data_error_coeff,
+                               activity_monitor.Gfx_PD_Data_error_rate_coeff);
+
+                       size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
+                               " ",
+                               1,
+                               "UCLK",
+                               activity_monitor.Mem_FPS,
+                               activity_monitor.Mem_UseRlcBusy,
+                               activity_monitor.Mem_MinActiveFreqType,
+                               activity_monitor.Mem_MinActiveFreq,
+                               activity_monitor.Mem_BoosterFreqType,
+                               activity_monitor.Mem_BoosterFreq,
+                               activity_monitor.Mem_PD_Data_limit_c,
+                               activity_monitor.Mem_PD_Data_error_coeff,
+                               activity_monitor.Mem_PD_Data_error_rate_coeff);
+               }
        }
 
        return size;
@@ -1414,18 +1421,69 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
                                           long *input,
                                           uint32_t size)
 {
+       DpmActivityMonitorCoeffInt_t activity_monitor;
        int workload_type = 0;
        uint32_t profile_mode = input[size];
        int ret = 0;
-
-       if (!smu->pm_enabled)
-               return -EINVAL;
+       uint32_t smu_version;
 
        if (profile_mode > PP_SMC_POWER_PROFILE_CUSTOM) {
                pr_err("Invalid power profile mode %d\n", profile_mode);
                return -EINVAL;
        }
 
+       ret = smu_get_smc_version(smu, NULL, &smu_version);
+       if (ret)
+               return ret;
+
+       if ((profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) &&
+            (smu_version >=0x360d00)) {
+               ret = smu_update_table(smu,
+                                      SMU_TABLE_ACTIVITY_MONITOR_COEFF,
+                                      WORKLOAD_PPLIB_CUSTOM_BIT,
+                                      (void *)(&activity_monitor),
+                                      false);
+               if (ret) {
+                       pr_err("[%s] Failed to get activity monitor!", __func__);
+                       return ret;
+               }
+
+               switch (input[0]) {
+               case 0: /* Gfxclk */
+                       activity_monitor.Gfx_FPS = input[1];
+                       activity_monitor.Gfx_UseRlcBusy = input[2];
+                       activity_monitor.Gfx_MinActiveFreqType = input[3];
+                       activity_monitor.Gfx_MinActiveFreq = input[4];
+                       activity_monitor.Gfx_BoosterFreqType = input[5];
+                       activity_monitor.Gfx_BoosterFreq = input[6];
+                       activity_monitor.Gfx_PD_Data_limit_c = input[7];
+                       activity_monitor.Gfx_PD_Data_error_coeff = input[8];
+                       activity_monitor.Gfx_PD_Data_error_rate_coeff = input[9];
+                       break;
+               case 1: /* Uclk */
+                       activity_monitor.Mem_FPS = input[1];
+                       activity_monitor.Mem_UseRlcBusy = input[2];
+                       activity_monitor.Mem_MinActiveFreqType = input[3];
+                       activity_monitor.Mem_MinActiveFreq = input[4];
+                       activity_monitor.Mem_BoosterFreqType = input[5];
+                       activity_monitor.Mem_BoosterFreq = input[6];
+                       activity_monitor.Mem_PD_Data_limit_c = input[7];
+                       activity_monitor.Mem_PD_Data_error_coeff = input[8];
+                       activity_monitor.Mem_PD_Data_error_rate_coeff = input[9];
+                       break;
+               }
+
+               ret = smu_update_table(smu,
+                                      SMU_TABLE_ACTIVITY_MONITOR_COEFF,
+                                      WORKLOAD_PPLIB_CUSTOM_BIT,
+                                      (void *)(&activity_monitor),
+                                      true);
+               if (ret) {
+                       pr_err("[%s] Failed to set activity monitor!", __func__);
+                       return ret;
+               }
+       }
+
        /*
         * Conv PP_SMC_POWER_PROFILE* to WORKLOAD_PPLIB_*_BIT
         * Not all profile modes are supported on arcturus.
@@ -1891,6 +1949,270 @@ static bool arcturus_is_dpm_running(struct smu_context *smu)
        return !!(feature_enabled & SMC_DPM_FEATURE);
 }
 
+static int arcturus_dpm_set_uvd_enable(struct smu_context *smu, bool enable)
+{
+       struct smu_power_context *smu_power = &smu->smu_power;
+       struct smu_power_gate *power_gate = &smu_power->power_gate;
+       int ret = 0;
+
+       if (enable) {
+               if (!smu_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
+                       ret = smu_feature_set_enabled(smu, SMU_FEATURE_VCN_PG_BIT, 1);
+                       if (ret) {
+                               pr_err("[EnableVCNDPM] failed!\n");
+                               return ret;
+                       }
+               }
+               power_gate->vcn_gated = false;
+       } else {
+               if (smu_feature_is_enabled(smu, SMU_FEATURE_VCN_PG_BIT)) {
+                       ret = smu_feature_set_enabled(smu, SMU_FEATURE_VCN_PG_BIT, 0);
+                       if (ret) {
+                               pr_err("[DisableVCNDPM] failed!\n");
+                               return ret;
+                       }
+               }
+               power_gate->vcn_gated = true;
+       }
+
+       return ret;
+}
+
+
+static void arcturus_fill_eeprom_i2c_req(SwI2cRequest_t  *req, bool write,
+                                 uint8_t address, uint32_t numbytes,
+                                 uint8_t *data)
+{
+       int i;
+
+       BUG_ON(numbytes > MAX_SW_I2C_COMMANDS);
+
+       req->I2CcontrollerPort = 0;
+       req->I2CSpeed = 2;
+       req->SlaveAddress = address;
+       req->NumCmds = numbytes;
+
+       for (i = 0; i < numbytes; i++) {
+               SwI2cCmd_t *cmd =  &req->SwI2cCmds[i];
+
+               /* First 2 bytes are always write for lower 2b EEPROM address */
+               if (i < 2)
+                       cmd->Cmd = 1;
+               else
+                       cmd->Cmd = write;
+
+
+               /* Add RESTART for read  after address filled */
+               cmd->CmdConfig |= (i == 2 && !write) ? CMDCONFIG_RESTART_MASK : 0;
+
+               /* Add STOP in the end */
+               cmd->CmdConfig |= (i == (numbytes - 1)) ? CMDCONFIG_STOP_MASK : 0;
+
+               /* Fill with data regardless if read or write to simplify code */
+               cmd->RegisterAddr = data[i];
+       }
+}
+
+static int arcturus_i2c_eeprom_read_data(struct i2c_adapter *control,
+                                              uint8_t address,
+                                              uint8_t *data,
+                                              uint32_t numbytes)
+{
+       uint32_t  i, ret = 0;
+       SwI2cRequest_t req;
+       struct amdgpu_device *adev = to_amdgpu_device(control);
+       struct smu_table_context *smu_table = &adev->smu.smu_table;
+       struct smu_table *table = &smu_table->driver_table;
+
+       memset(&req, 0, sizeof(req));
+       arcturus_fill_eeprom_i2c_req(&req, false, address, numbytes, data);
+
+       mutex_lock(&adev->smu.mutex);
+       /* Now read data starting with that address */
+       ret = smu_update_table(&adev->smu, SMU_TABLE_I2C_COMMANDS, 0, &req,
+                                       true);
+       mutex_unlock(&adev->smu.mutex);
+
+       if (!ret) {
+               SwI2cRequest_t *res = (SwI2cRequest_t *)table->cpu_addr;
+
+               /* Assume SMU  fills res.SwI2cCmds[i].Data with read bytes */
+               for (i = 0; i < numbytes; i++)
+                       data[i] = res->SwI2cCmds[i].Data;
+
+               pr_debug("arcturus_i2c_eeprom_read_data, address = %x, bytes = %d, data :",
+                                 (uint16_t)address, numbytes);
+
+               print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE,
+                              8, 1, data, numbytes, false);
+       } else
+               pr_err("arcturus_i2c_eeprom_read_data - error occurred :%x", ret);
+
+       return ret;
+}
+
+static int arcturus_i2c_eeprom_write_data(struct i2c_adapter *control,
+                                               uint8_t address,
+                                               uint8_t *data,
+                                               uint32_t numbytes)
+{
+       uint32_t ret;
+       SwI2cRequest_t req;
+       struct amdgpu_device *adev = to_amdgpu_device(control);
+
+       memset(&req, 0, sizeof(req));
+       arcturus_fill_eeprom_i2c_req(&req, true, address, numbytes, data);
+
+       mutex_lock(&adev->smu.mutex);
+       ret = smu_update_table(&adev->smu, SMU_TABLE_I2C_COMMANDS, 0, &req, true);
+       mutex_unlock(&adev->smu.mutex);
+
+       if (!ret) {
+               pr_debug("arcturus_i2c_write(), address = %x, bytes = %d , data: ",
+                                        (uint16_t)address, numbytes);
+
+               print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE,
+                              8, 1, data, numbytes, false);
+               /*
+                * According to EEPROM spec there is a MAX of 10 ms required for
+                * EEPROM to flush internal RX buffer after STOP was issued at the
+                * end of write transaction. During this time the EEPROM will not be
+                * responsive to any more commands - so wait a bit more.
+                */
+               msleep(10);
+
+       } else
+               pr_err("arcturus_i2c_write- error occurred :%x", ret);
+
+       return ret;
+}
+
+static int arcturus_i2c_eeprom_i2c_xfer(struct i2c_adapter *i2c_adap,
+                             struct i2c_msg *msgs, int num)
+{
+       uint32_t  i, j, ret, data_size, data_chunk_size, next_eeprom_addr = 0;
+       uint8_t *data_ptr, data_chunk[MAX_SW_I2C_COMMANDS] = { 0 };
+
+       for (i = 0; i < num; i++) {
+               /*
+                * SMU interface allows at most MAX_SW_I2C_COMMANDS bytes of data at
+                * once and hence the data needs to be spliced into chunks and sent each
+                * chunk separately
+                */
+               data_size = msgs[i].len - 2;
+               data_chunk_size = MAX_SW_I2C_COMMANDS - 2;
+               next_eeprom_addr = (msgs[i].buf[0] << 8 & 0xff00) | (msgs[i].buf[1] & 0xff);
+               data_ptr = msgs[i].buf + 2;
+
+               for (j = 0; j < data_size / data_chunk_size; j++) {
+                       /* Insert the EEPROM dest addess, bits 0-15 */
+                       data_chunk[0] = ((next_eeprom_addr >> 8) & 0xff);
+                       data_chunk[1] = (next_eeprom_addr & 0xff);
+
+                       if (msgs[i].flags & I2C_M_RD) {
+                               ret = arcturus_i2c_eeprom_read_data(i2c_adap,
+                                                               (uint8_t)msgs[i].addr,
+                                                               data_chunk, MAX_SW_I2C_COMMANDS);
+
+                               memcpy(data_ptr, data_chunk + 2, data_chunk_size);
+                       } else {
+
+                               memcpy(data_chunk + 2, data_ptr, data_chunk_size);
+
+                               ret = arcturus_i2c_eeprom_write_data(i2c_adap,
+                                                                (uint8_t)msgs[i].addr,
+                                                                data_chunk, MAX_SW_I2C_COMMANDS);
+                       }
+
+                       if (ret) {
+                               num = -EIO;
+                               goto fail;
+                       }
+
+                       next_eeprom_addr += data_chunk_size;
+                       data_ptr += data_chunk_size;
+               }
+
+               if (data_size % data_chunk_size) {
+                       data_chunk[0] = ((next_eeprom_addr >> 8) & 0xff);
+                       data_chunk[1] = (next_eeprom_addr & 0xff);
+
+                       if (msgs[i].flags & I2C_M_RD) {
+                               ret = arcturus_i2c_eeprom_read_data(i2c_adap,
+                                                               (uint8_t)msgs[i].addr,
+                                                               data_chunk, (data_size % data_chunk_size) + 2);
+
+                               memcpy(data_ptr, data_chunk + 2, data_size % data_chunk_size);
+                       } else {
+                               memcpy(data_chunk + 2, data_ptr, data_size % data_chunk_size);
+
+                               ret = arcturus_i2c_eeprom_write_data(i2c_adap,
+                                                                (uint8_t)msgs[i].addr,
+                                                                data_chunk, (data_size % data_chunk_size) + 2);
+                       }
+
+                       if (ret) {
+                               num = -EIO;
+                               goto fail;
+                       }
+               }
+       }
+
+fail:
+       return num;
+}
+
+static u32 arcturus_i2c_eeprom_i2c_func(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+}
+
+
+static const struct i2c_algorithm arcturus_i2c_eeprom_i2c_algo = {
+       .master_xfer = arcturus_i2c_eeprom_i2c_xfer,
+       .functionality = arcturus_i2c_eeprom_i2c_func,
+};
+
+static int arcturus_i2c_eeprom_control_init(struct i2c_adapter *control)
+{
+       struct amdgpu_device *adev = to_amdgpu_device(control);
+       struct smu_context *smu = &adev->smu;
+       int res;
+
+       if (!smu->pm_enabled)
+               return -EOPNOTSUPP;
+
+       control->owner = THIS_MODULE;
+       control->class = I2C_CLASS_SPD;
+       control->dev.parent = &adev->pdev->dev;
+       control->algo = &arcturus_i2c_eeprom_i2c_algo;
+       snprintf(control->name, sizeof(control->name), "RAS EEPROM");
+
+       res = i2c_add_adapter(control);
+       if (res)
+               DRM_ERROR("Failed to register hw i2c, err: %d\n", res);
+
+       return res;
+}
+
+static void arcturus_i2c_eeprom_control_fini(struct i2c_adapter *control)
+{
+       struct amdgpu_device *adev = to_amdgpu_device(control);
+       struct smu_context *smu = &adev->smu;
+
+       if (!smu->pm_enabled)
+               return;
+
+       i2c_del_adapter(control);
+}
+
+static uint32_t arcturus_get_pptable_power_limit(struct smu_context *smu)
+{
+       PPTable_t *pptable = smu->smu_table.driver_pptable;
+
+       return pptable->SocketPowerLimitAc[PPT_THROTTLER_PPT0];
+}
+
 static const struct pptable_funcs arcturus_ppt_funcs = {
        /* translate smu index into arcturus specific index */
        .get_smu_msg_index = arcturus_get_smu_msg_index,
@@ -1909,7 +2231,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
        /* init dpm */
        .get_allowed_feature_mask = arcturus_get_allowed_feature_mask,
        /* btc */
-       .run_afll_btc = arcturus_run_btc_afll,
+       .run_btc = arcturus_run_btc,
        /* dpm/clk tables */
        .set_default_dpm_table = arcturus_set_default_dpm_table,
        .populate_umd_state_clk = arcturus_populate_umd_state_clk,
@@ -1925,16 +2247,68 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
        .get_profiling_clk_mask = arcturus_get_profiling_clk_mask,
        .get_power_profile_mode = arcturus_get_power_profile_mode,
        .set_power_profile_mode = arcturus_set_power_profile_mode,
+       .set_performance_level = smu_v11_0_set_performance_level,
        /* debug (internal used) */
        .dump_pptable = arcturus_dump_pptable,
        .get_power_limit = arcturus_get_power_limit,
        .is_dpm_running = arcturus_is_dpm_running,
+       .dpm_set_uvd_enable = arcturus_dpm_set_uvd_enable,
+       .i2c_eeprom_init = arcturus_i2c_eeprom_control_init,
+       .i2c_eeprom_fini = arcturus_i2c_eeprom_control_fini,
+       .init_microcode = smu_v11_0_init_microcode,
+       .load_microcode = smu_v11_0_load_microcode,
+       .init_smc_tables = smu_v11_0_init_smc_tables,
+       .fini_smc_tables = smu_v11_0_fini_smc_tables,
+       .init_power = smu_v11_0_init_power,
+       .fini_power = smu_v11_0_fini_power,
+       .check_fw_status = smu_v11_0_check_fw_status,
+       .setup_pptable = smu_v11_0_setup_pptable,
+       .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
+       .get_clk_info_from_vbios = smu_v11_0_get_clk_info_from_vbios,
+       .check_pptable = smu_v11_0_check_pptable,
+       .parse_pptable = smu_v11_0_parse_pptable,
+       .populate_smc_tables = smu_v11_0_populate_smc_pptable,
+       .check_fw_version = smu_v11_0_check_fw_version,
+       .write_pptable = smu_v11_0_write_pptable,
+       .set_min_dcef_deep_sleep = smu_v11_0_set_min_dcef_deep_sleep,
+       .set_driver_table_location = smu_v11_0_set_driver_table_location,
+       .set_tool_table_location = smu_v11_0_set_tool_table_location,
+       .notify_memory_pool_location = smu_v11_0_notify_memory_pool_location,
+       .system_features_control = smu_v11_0_system_features_control,
+       .send_smc_msg_with_param = smu_v11_0_send_msg_with_param,
+       .read_smc_arg = smu_v11_0_read_arg,
+       .init_display_count = smu_v11_0_init_display_count,
+       .set_allowed_mask = smu_v11_0_set_allowed_mask,
+       .get_enabled_mask = smu_v11_0_get_enabled_mask,
+       .notify_display_change = smu_v11_0_notify_display_change,
+       .set_power_limit = smu_v11_0_set_power_limit,
+       .get_current_clk_freq = smu_v11_0_get_current_clk_freq,
+       .init_max_sustainable_clocks = smu_v11_0_init_max_sustainable_clocks,
+       .start_thermal_control = smu_v11_0_start_thermal_control,
+       .stop_thermal_control = smu_v11_0_stop_thermal_control,
+       .set_deep_sleep_dcefclk = smu_v11_0_set_deep_sleep_dcefclk,
+       .display_clock_voltage_request = smu_v11_0_display_clock_voltage_request,
+       .get_fan_control_mode = smu_v11_0_get_fan_control_mode,
+       .set_fan_control_mode = smu_v11_0_set_fan_control_mode,
+       .set_fan_speed_percent = smu_v11_0_set_fan_speed_percent,
+       .set_fan_speed_rpm = smu_v11_0_set_fan_speed_rpm,
+       .set_xgmi_pstate = smu_v11_0_set_xgmi_pstate,
+       .gfx_off_control = smu_v11_0_gfx_off_control,
+       .register_irq_handler = smu_v11_0_register_irq_handler,
+       .set_azalia_d3_pme = smu_v11_0_set_azalia_d3_pme,
+       .get_max_sustainable_clocks_by_dc = smu_v11_0_get_max_sustainable_clocks_by_dc,
+       .baco_is_support= smu_v11_0_baco_is_support,
+       .baco_get_state = smu_v11_0_baco_get_state,
+       .baco_set_state = smu_v11_0_baco_set_state,
+       .baco_enter = smu_v11_0_baco_enter,
+       .baco_exit = smu_v11_0_baco_exit,
+       .get_dpm_ultimate_freq = smu_v11_0_get_dpm_ultimate_freq,
+       .set_soft_freq_limited_range = smu_v11_0_set_soft_freq_limited_range,
+       .override_pcie_parameters = smu_v11_0_override_pcie_parameters,
+       .get_pptable_power_limit = arcturus_get_pptable_power_limit,
 };
 
 void arcturus_set_ppt_funcs(struct smu_context *smu)
 {
-       struct smu_table_context *smu_table = &smu->smu_table;
-
        smu->ppt_funcs = &arcturus_ppt_funcs;
-       smu_table->table_count = TABLE_COUNT;
 }