]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amd/powerplay: clean up the APIs for pptable setup
authorEvan Quan <evan.quan@amd.com>
Thu, 28 May 2020 10:50:00 +0000 (18:50 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 1 Jul 2020 05:59:16 +0000 (01:59 -0400)
Combine and simplify the logics for setup pptable.

Signed-off-by: Evan Quan <evan.quan@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c
drivers/gpu/drm/amd/powerplay/arcturus_ppt.c
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
drivers/gpu/drm/amd/powerplay/inc/smu_v11_0.h
drivers/gpu/drm/amd/powerplay/navi10_ppt.c
drivers/gpu/drm/amd/powerplay/sienna_cichlid_ppt.c
drivers/gpu/drm/amd/powerplay/smu_internal.h
drivers/gpu/drm/amd/powerplay/smu_v11_0.c

index b3ef3947a38d8675b7576f1aadb4ea0b7871c40b..f753be756eac5b05532075bc78e7e7b4ee2cfdcd 100644 (file)
@@ -1114,23 +1114,6 @@ static int smu_smc_table_hw_init(struct smu_context *smu,
                if (ret)
                        return ret;
 
-               /*
-                * check if the format_revision in vbios is up to pptable header
-                * version, and the structure size is not 0.
-                */
-               ret = smu_check_pptable(smu);
-               if (ret)
-                       return ret;
-
-               /*
-                * Parse pptable format and fill PPTable_t smc_pptable to
-                * smu_table_context structure. And read the smc_dpm_table from vbios,
-                * then fill it into smc_pptable.
-                */
-               ret = smu_parse_pptable(smu);
-               if (ret)
-                       return ret;
-
                /*
                 * Send msg GetDriverIfVersion to check if the return value is equal
                 * with DRIVER_IF_VERSION of smc header.
index 747fdd315575c8cc84a5d95ef0d7c4ceab8f5dea..9eb57bec27e19a37601a7fff074afb5631c5a12f 100644 (file)
@@ -489,33 +489,33 @@ static int arcturus_set_default_dpm_table(struct smu_context *smu)
 
 static int arcturus_check_powerplay_table(struct smu_context *smu)
 {
+       struct smu_table_context *table_context = &smu->smu_table;
+       struct smu_11_0_powerplay_table *powerplay_table =
+               table_context->power_play_table;
+       struct smu_baco_context *smu_baco = &smu->smu_baco;
+
+       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);
+
+       table_context->thermal_controller_type =
+               powerplay_table->thermal_controller_type;
+
        return 0;
 }
 
 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)
-               return -EINVAL;
-
-       powerplay_table = table_context->power_play_table;
+       struct smu_11_0_powerplay_table *powerplay_table =
+               table_context->power_play_table;
 
        memcpy(table_context->driver_pptable, &powerplay_table->smc_pptable,
               sizeof(PPTable_t));
 
-       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;
+       return 0;
 }
 
 static int arcturus_append_powerplay_table(struct smu_context *smu)
@@ -546,6 +546,29 @@ static int arcturus_append_powerplay_table(struct smu_context *smu)
        return 0;
 }
 
+static int arcturus_setup_pptable(struct smu_context *smu)
+{
+       int ret = 0;
+
+       ret = smu_v11_0_setup_pptable(smu);
+       if (ret)
+               return ret;
+
+       ret = arcturus_store_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       ret = arcturus_append_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       ret = arcturus_check_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       return ret;
+}
+
 static int arcturus_run_btc(struct smu_context *smu)
 {
        int ret = 0;
@@ -2416,10 +2439,6 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
        /* internal structurs allocations */
        .tables_init = arcturus_tables_init,
        .alloc_dpm_context = arcturus_allocate_dpm_context,
-       /* pptable related */
-       .check_powerplay_table = arcturus_check_powerplay_table,
-       .store_powerplay_table = arcturus_store_powerplay_table,
-       .append_powerplay_table = arcturus_append_powerplay_table,
        /* init dpm */
        .get_allowed_feature_mask = arcturus_get_allowed_feature_mask,
        /* btc */
@@ -2455,10 +2474,9 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
        .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,
+       /* pptable related */
+       .setup_pptable = arcturus_setup_pptable,
        .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
-       .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,
index db30facfd799597464ce6c66935277f91a51d958..e21bdad16b3c34978ba9bab9b9b58eab85c36975 100644 (file)
@@ -417,9 +417,6 @@ struct i2c_adapter;
 
 struct pptable_funcs {
        int (*alloc_dpm_context)(struct smu_context *smu);
-       int (*store_powerplay_table)(struct smu_context *smu);
-       int (*check_powerplay_table)(struct smu_context *smu);
-       int (*append_powerplay_table)(struct smu_context *smu);
        int (*get_smu_msg_index)(struct smu_context *smu, uint32_t index);
        int (*get_smu_clk_index)(struct smu_context *smu, uint32_t index);
        int (*get_smu_feature_index)(struct smu_context *smu, uint32_t index);
@@ -506,8 +503,6 @@ struct pptable_funcs {
        int (*check_fw_status)(struct smu_context *smu);
        int (*setup_pptable)(struct smu_context *smu);
        int (*get_vbios_bootup_values)(struct smu_context *smu);
-       int (*check_pptable)(struct smu_context *smu);
-       int (*parse_pptable)(struct smu_context *smu);
        int (*populate_smc_tables)(struct smu_context *smu);
        int (*check_fw_version)(struct smu_context *smu);
        int (*powergate_sdma)(struct smu_context *smu, bool gate);
index 79736b1e35062d5b6ecce448247178561f62577d..e9c71e5a809300046cd530b90bc01fcce4bcad45 100644 (file)
@@ -162,10 +162,6 @@ int smu_v11_0_setup_pptable(struct smu_context *smu);
 
 int smu_v11_0_get_vbios_bootup_values(struct smu_context *smu);
 
-int smu_v11_0_check_pptable(struct smu_context *smu);
-
-int smu_v11_0_parse_pptable(struct smu_context *smu);
-
 int smu_v11_0_populate_smc_pptable(struct smu_context *smu);
 
 int smu_v11_0_check_fw_version(struct smu_context *smu);
index 85c7cceef9dc76ea344808e7f6ad6e60b34e78be..110845922724c36f42f71d05daac736a8e207065 100644 (file)
@@ -417,6 +417,29 @@ navi10_get_allowed_feature_mask(struct smu_context *smu,
 
 static int navi10_check_powerplay_table(struct smu_context *smu)
 {
+       struct smu_table_context *table_context = &smu->smu_table;
+       struct smu_11_0_powerplay_table *powerplay_table =
+               table_context->power_play_table;
+       struct smu_baco_context *smu_baco = &smu->smu_baco;
+
+       if (powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_HARDWAREDC)
+               smu->dc_controlled_by_gpio = true;
+
+       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);
+
+       table_context->thermal_controller_type =
+               powerplay_table->thermal_controller_type;
+
+       /*
+        * Instead of having its own buffer space and get overdrive_table copied,
+        * smu->od_settings just points to the actual overdrive_table
+        */
+       smu->od_settings = &powerplay_table->overdrive_table;
+
        return 0;
 }
 
@@ -475,30 +498,37 @@ static int navi10_append_powerplay_table(struct smu_context *smu)
 
 static int navi10_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;
-
-       if (!table_context->power_play_table)
-               return -EINVAL;
-
-       powerplay_table = table_context->power_play_table;
+       struct smu_11_0_powerplay_table *powerplay_table =
+               table_context->power_play_table;
 
        memcpy(table_context->driver_pptable, &powerplay_table->smc_pptable,
               sizeof(PPTable_t));
 
-       table_context->thermal_controller_type = powerplay_table->thermal_controller_type;
+       return 0;
+}
 
-       if (powerplay_table->platform_caps & SMU_11_0_PP_PLATFORM_CAP_HARDWAREDC)
-               smu->dc_controlled_by_gpio = true;
+static int navi10_setup_pptable(struct smu_context *smu)
+{
+       int ret = 0;
 
-       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);
+       ret = smu_v11_0_setup_pptable(smu);
+       if (ret)
+               return ret;
 
-       return 0;
+       ret = navi10_store_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       ret = navi10_append_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       ret = navi10_check_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       return ret;
 }
 
 static int navi10_tables_init(struct smu_context *smu, struct smu_table *tables)
@@ -1927,24 +1957,6 @@ static int navi10_overdrive_get_gfx_clk_base_voltage(struct smu_context *smu,
        return 0;
 }
 
-static int navi10_setup_od_limits(struct smu_context *smu) {
-       struct smu_11_0_overdrive_table *overdrive_table = NULL;
-       struct smu_11_0_powerplay_table *powerplay_table = NULL;
-
-       if (!smu->smu_table.power_play_table) {
-               pr_err("powerplay table uninitialized!\n");
-               return -ENOENT;
-       }
-       powerplay_table = (struct smu_11_0_powerplay_table *)smu->smu_table.power_play_table;
-       overdrive_table = &powerplay_table->overdrive_table;
-       if (!smu->od_settings) {
-               smu->od_settings = kmemdup(overdrive_table, sizeof(struct smu_11_0_overdrive_table), GFP_KERNEL);
-       } else {
-               memcpy(smu->od_settings, overdrive_table, sizeof(struct smu_11_0_overdrive_table));
-       }
-       return 0;
-}
-
 static bool navi10_is_baco_supported(struct smu_context *smu)
 {
        struct amdgpu_device *adev = smu->adev;
@@ -1968,11 +1980,6 @@ static int navi10_set_default_od_settings(struct smu_context *smu, bool initiali
        od_table = (OverDriveTable_t *)smu->smu_table.overdrive_table;
        boot_od_table = (OverDriveTable_t *)smu->smu_table.boot_overdrive_table;
        if (initialize) {
-               ret = navi10_setup_od_limits(smu);
-               if (ret) {
-                       pr_err("Failed to retrieve board OD limits\n");
-                       return ret;
-               }
                if (od_table) {
                        if (!od_table->GfxclkVolt1) {
                                ret = navi10_overdrive_get_gfx_clk_base_voltage(smu,
@@ -2273,9 +2280,6 @@ static int navi10_disable_umc_cdr_12gbps_workaround(struct smu_context *smu)
 static const struct pptable_funcs navi10_ppt_funcs = {
        .tables_init = navi10_tables_init,
        .alloc_dpm_context = navi10_allocate_dpm_context,
-       .store_powerplay_table = navi10_store_powerplay_table,
-       .check_powerplay_table = navi10_check_powerplay_table,
-       .append_powerplay_table = navi10_append_powerplay_table,
        .get_smu_msg_index = navi10_get_smu_msg_index,
        .get_smu_clk_index = navi10_get_smu_clk_index,
        .get_smu_feature_index = navi10_get_smu_feature_index,
@@ -2317,10 +2321,8 @@ static const struct pptable_funcs navi10_ppt_funcs = {
        .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,
+       .setup_pptable = navi10_setup_pptable,
        .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
-       .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,
index 3405bdcbfbd91cb2953e9ec34a4d749c0858fd39..d637fc4b72ac54a4f006302c71d475162bd5e66c 100644 (file)
@@ -359,6 +359,20 @@ sienna_cichlid_get_allowed_feature_mask(struct smu_context *smu,
 
 static int sienna_cichlid_check_powerplay_table(struct smu_context *smu)
 {
+       struct smu_table_context *table_context = &smu->smu_table;
+       struct smu_11_0_powerplay_table *powerplay_table =
+               table_context->power_play_table;
+       struct smu_baco_context *smu_baco = &smu->smu_baco;
+
+       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);
+
+       table_context->thermal_controller_type =
+               powerplay_table->thermal_controller_type;
+
        return 0;
 }
 
@@ -470,27 +484,37 @@ static int sienna_cichlid_append_powerplay_table(struct smu_context *smu)
 
 static int sienna_cichlid_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;
-
-       if (!table_context->power_play_table)
-               return -EINVAL;
-
-       powerplay_table = table_context->power_play_table;
+       struct smu_11_0_powerplay_table *powerplay_table =
+               table_context->power_play_table;
 
        memcpy(table_context->driver_pptable, &powerplay_table->smc_pptable,
               sizeof(PPTable_t));
 
-       table_context->thermal_controller_type = powerplay_table->thermal_controller_type;
+       return 0;
+}
 
-       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);
+static int sienna_cichlid_setup_pptable(struct smu_context *smu)
+{
+       int ret = 0;
 
-       return 0;
+       ret = smu_v11_0_setup_pptable(smu);
+       if (ret)
+               return ret;
+
+       ret = sienna_cichlid_store_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       ret = sienna_cichlid_append_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       ret = sienna_cichlid_check_powerplay_table(smu);
+       if (ret)
+               return ret;
+
+       return ret;
 }
 
 static int sienna_cichlid_tables_init(struct smu_context *smu, struct smu_table *tables)
@@ -2411,9 +2435,6 @@ static void sienna_cichlid_dump_pptable(struct smu_context *smu)
 static const struct pptable_funcs sienna_cichlid_ppt_funcs = {
        .tables_init = sienna_cichlid_tables_init,
        .alloc_dpm_context = sienna_cichlid_allocate_dpm_context,
-       .store_powerplay_table = sienna_cichlid_store_powerplay_table,
-       .check_powerplay_table = sienna_cichlid_check_powerplay_table,
-       .append_powerplay_table = sienna_cichlid_append_powerplay_table,
        .get_smu_msg_index = sienna_cichlid_get_smu_msg_index,
        .get_smu_clk_index = sienna_cichlid_get_smu_clk_index,
        .get_smu_feature_index = sienna_cichlid_get_smu_feature_index,
@@ -2455,10 +2476,8 @@ static const struct pptable_funcs sienna_cichlid_ppt_funcs = {
        .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,
+       .setup_pptable = sienna_cichlid_setup_pptable,
        .get_vbios_bootup_values = smu_v11_0_get_vbios_bootup_values,
-       .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,
index e11784268a7668558103aeb30b0682574d00c792..493a3a55fead92fe16e782fbc5475f4623784ba3 100644 (file)
 
 #define smu_get_vbios_bootup_values(smu) \
        ((smu)->ppt_funcs->get_vbios_bootup_values ? (smu)->ppt_funcs->get_vbios_bootup_values((smu)) : 0)
-#define smu_check_pptable(smu) \
-       ((smu)->ppt_funcs->check_pptable ? (smu)->ppt_funcs->check_pptable((smu)) : 0)
-#define smu_parse_pptable(smu) \
-       ((smu)->ppt_funcs->parse_pptable ? (smu)->ppt_funcs->parse_pptable((smu)) : 0)
 #define smu_populate_smc_tables(smu) \
        ((smu)->ppt_funcs->populate_smc_tables ? (smu)->ppt_funcs->populate_smc_tables((smu)) : 0)
 #define smu_check_fw_version(smu) \
@@ -92,12 +88,6 @@ static inline int smu_send_smc_msg(struct smu_context *smu, enum smu_message_typ
        ((smu)->ppt_funcs->is_dpm_running ? (smu)->ppt_funcs->is_dpm_running((smu)) : 0)
 #define smu_notify_display_change(smu) \
        ((smu)->ppt_funcs->notify_display_change? (smu)->ppt_funcs->notify_display_change((smu)) : 0)
-#define smu_store_powerplay_table(smu) \
-       ((smu)->ppt_funcs->store_powerplay_table ? (smu)->ppt_funcs->store_powerplay_table((smu)) : 0)
-#define smu_check_powerplay_table(smu) \
-       ((smu)->ppt_funcs->check_powerplay_table ? (smu)->ppt_funcs->check_powerplay_table((smu)) : 0)
-#define smu_append_powerplay_table(smu) \
-       ((smu)->ppt_funcs->append_powerplay_table ? (smu)->ppt_funcs->append_powerplay_table((smu)) : 0)
 #define smu_set_default_dpm_table(smu) \
        ((smu)->ppt_funcs->set_default_dpm_table ? (smu)->ppt_funcs->set_default_dpm_table((smu)) : 0)
 #define smu_populate_umd_state_clk(smu) \
index 65479c73de34ffd2215d4f7b4fc4e7d7be9d6a8f..fa95c89b5dc807ecbd2921d7f3fef7330bdc44ff 100644 (file)
@@ -732,27 +732,6 @@ int smu_v11_0_notify_memory_pool_location(struct smu_context *smu)
        return ret;
 }
 
-int smu_v11_0_check_pptable(struct smu_context *smu)
-{
-       int ret;
-
-       ret = smu_check_powerplay_table(smu);
-       return ret;
-}
-
-int smu_v11_0_parse_pptable(struct smu_context *smu)
-{
-       int ret;
-
-       ret = smu_store_powerplay_table(smu);
-       if (ret)
-               return -EINVAL;
-
-       ret = smu_append_powerplay_table(smu);
-
-       return ret;
-}
-
 int smu_v11_0_populate_smc_pptable(struct smu_context *smu)
 {
        int ret;