]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
drm/amd/powerplay: refine smumgr code
authorRex Zhu <Rex.Zhu@amd.com>
Thu, 29 Dec 2016 07:23:44 +0000 (15:23 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 27 Jan 2017 16:13:01 +0000 (11:13 -0500)
1. delete asic_smum_init functions, export asic private functions
   to smumgr directly, make code more readable.
2. create asic private data in asic_init_func.

Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/inc/smumgr.h
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.c
drivers/gpu/drm/amd/powerplay/smumgr/cz_smumgr.h
drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c
drivers/gpu/drm/amd/powerplay/smumgr/polaris10_smumgr.c
drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c
drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c

index 0e593729583587b1a52f3c50bb3ff7a1510a9c14..9b6531bd63503a8601d231021603a8f6241004b3 100644 (file)
@@ -33,6 +33,12 @@ struct pp_hwmgr;
 #define smu_lower_32_bits(n) ((uint32_t)(n))
 #define smu_upper_32_bits(n) ((uint32_t)(((n)>>16)>>16))
 
+extern const struct pp_smumgr_func cz_smu_funcs;
+extern const struct pp_smumgr_func iceland_smu_funcs;
+extern const struct pp_smumgr_func tonga_smu_funcs;
+extern const struct pp_smumgr_func fiji_smu_funcs;
+extern const struct pp_smumgr_func polaris10_smu_funcs;
+
 enum AVFS_BTC_STATUS {
        AVFS_BTC_BOOT = 0,
        AVFS_BTC_BOOT_STARTEDSMU,
@@ -168,13 +174,6 @@ extern int smu_allocate_memory(void *device, uint32_t size,
                         void **kptr, void *handle);
 
 extern int smu_free_memory(void *device, void *handle);
-
-extern int cz_smum_init(struct pp_smumgr *smumgr);
-extern int iceland_smum_init(struct pp_smumgr *smumgr);
-extern int tonga_smum_init(struct pp_smumgr *smumgr);
-extern int fiji_smum_init(struct pp_smumgr *smumgr);
-extern int polaris10_smum_init(struct pp_smumgr *smumgr);
-
 extern int smum_update_sclk_threshold(struct pp_hwmgr *hwmgr);
 
 extern int smum_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type);
index 2d4cf2c77c4084632a9c96c444ce8a1f9b6b8893..1f6744a443d4ec410eabedf8c89234a45e4c3e90 100644 (file)
@@ -737,9 +737,15 @@ static int cz_start_smu(struct pp_smumgr *smumgr)
 
 static int cz_smu_init(struct pp_smumgr *smumgr)
 {
-       struct cz_smumgr *cz_smu = (struct cz_smumgr *)smumgr->backend;
        uint64_t mc_addr = 0;
        int ret = 0;
+       struct cz_smumgr *cz_smu;
+
+       cz_smu = kzalloc(sizeof(struct cz_smumgr), GFP_KERNEL);
+       if (cz_smu == NULL)
+               return -ENOMEM;
+
+       smumgr->backend = cz_smu;
 
        cz_smu->toc_buffer.data_size = 4096;
        cz_smu->smu_buffer.data_size =
@@ -836,7 +842,7 @@ static int cz_smu_fini(struct pp_smumgr *smumgr)
        return 0;
 }
 
-static const struct pp_smumgr_func cz_smu_funcs = {
+const struct pp_smumgr_func cz_smu_funcs = {
        .smu_init = cz_smu_init,
        .smu_fini = cz_smu_fini,
        .start_smu = cz_start_smu,
@@ -850,15 +856,3 @@ static const struct pp_smumgr_func cz_smu_funcs = {
        .upload_pptable_settings = cz_upload_pptable_settings,
 };
 
-int cz_smum_init(struct pp_smumgr *smumgr)
-{
-       struct cz_smumgr *cz_smu;
-
-       cz_smu = kzalloc(sizeof(struct cz_smumgr), GFP_KERNEL);
-       if (cz_smu == NULL)
-               return -ENOMEM;
-
-       smumgr->backend = cz_smu;
-       smumgr->smumgr_funcs = &cz_smu_funcs;
-       return 0;
-}
index 8838180392483db66df4caf8c11a903b5dcfe78e..7c3a290c8957d4aa1bc85dcaaff9d59d7f610340 100644 (file)
@@ -95,8 +95,4 @@ struct cz_smumgr {
        struct cz_buffer_entry scratch_buffer[MAX_NUM_SCRATCH];
 };
 
-struct pp_smumgr;
-
-extern int cz_smum_init(struct pp_smumgr *smumgr);
-
 #endif
index 71ff0bc09bb2b72b23430f9fd2582670c3b86260..54b347366b5d15e5591827612ee685175c128edf 100644 (file)
@@ -464,13 +464,20 @@ static bool fiji_is_hw_avfs_present(struct pp_smumgr *smumgr)
 */
 static int fiji_smu_init(struct pp_smumgr *smumgr)
 {
-       struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
        int i;
+       struct fiji_smumgr *fiji_priv = NULL;
+
+       fiji_priv = kzalloc(sizeof(struct fiji_smumgr), GFP_KERNEL);
+
+       if (fiji_priv == NULL)
+               return -ENOMEM;
+
+       smumgr->backend = fiji_priv;
 
        if (smu7_init(smumgr))
                return -EINVAL;
 
-       priv->avfs.AvfsBtcStatus = AVFS_BTC_BOOT;
+       fiji_priv->avfs.AvfsBtcStatus = AVFS_BTC_BOOT;
        if (fiji_is_hw_avfs_present(smumgr))
                /* AVFS Parameter
                 * 0 - BTC DC disabled, BTC AC disabled
@@ -479,18 +486,18 @@ static int fiji_smu_init(struct pp_smumgr *smumgr)
                 * 3 - BTC DC enabled,  BTC AC enabled
                 * Default is 0 - BTC DC disabled, BTC AC disabled
                 */
-               priv->avfs.AvfsBtcParam = 0;
+               fiji_priv->avfs.AvfsBtcParam = 0;
        else
-               priv->avfs.AvfsBtcStatus = AVFS_BTC_NOTSUPPORTED;
+               fiji_priv->avfs.AvfsBtcStatus = AVFS_BTC_NOTSUPPORTED;
 
        for (i = 0; i < SMU73_MAX_LEVELS_GRAPHICS; i++)
-               priv->activity_target[i] = 30;
+               fiji_priv->activity_target[i] = 30;
 
        return 0;
 }
 
 
-static const struct pp_smumgr_func fiji_smu_funcs = {
+const struct pp_smumgr_func fiji_smu_funcs = {
        .smu_init = &fiji_smu_init,
        .smu_fini = &smu7_smu_fini,
        .start_smu = &fiji_start_smu,
@@ -513,18 +520,3 @@ static const struct pp_smumgr_func fiji_smu_funcs = {
        .initialize_mc_reg_table = fiji_initialize_mc_reg_table,
        .is_dpm_running = fiji_is_dpm_running,
 };
-
-int fiji_smum_init(struct pp_smumgr *smumgr)
-{
-       struct fiji_smumgr *fiji_smu = NULL;
-
-       fiji_smu = kzalloc(sizeof(struct fiji_smumgr), GFP_KERNEL);
-
-       if (fiji_smu == NULL)
-               return -ENOMEM;
-
-       smumgr->backend = fiji_smu;
-       smumgr->smumgr_funcs = &fiji_smu_funcs;
-
-       return 0;
-}
index c830ea363575a00ad6c90fa596de85a4ddaa35db..0bf2def3b6592dca44c5eeae1b6ae48f51da119f 100644 (file)
@@ -201,17 +201,25 @@ static int iceland_start_smu(struct pp_smumgr *smumgr)
 static int iceland_smu_init(struct pp_smumgr *smumgr)
 {
        int i;
-       struct iceland_smumgr *smu_data = (struct iceland_smumgr *)(smumgr->backend);
+       struct iceland_smumgr *iceland_priv = NULL;
+
+       iceland_priv = kzalloc(sizeof(struct iceland_smumgr), GFP_KERNEL);
+
+       if (iceland_priv == NULL)
+               return -ENOMEM;
+
+       smumgr->backend = iceland_priv;
+
        if (smu7_init(smumgr))
                return -EINVAL;
 
        for (i = 0; i < SMU71_MAX_LEVELS_GRAPHICS; i++)
-               smu_data->activity_target[i] = 30;
+               iceland_priv->activity_target[i] = 30;
 
        return 0;
 }
 
-static const struct pp_smumgr_func iceland_smu_funcs = {
+const struct pp_smumgr_func iceland_smu_funcs = {
        .smu_init = &iceland_smu_init,
        .smu_fini = &smu7_smu_fini,
        .start_smu = &iceland_start_smu,
@@ -234,17 +242,3 @@ static const struct pp_smumgr_func iceland_smu_funcs = {
        .is_dpm_running = iceland_is_dpm_running,
 };
 
-int iceland_smum_init(struct pp_smumgr *smumgr)
-{
-       struct iceland_smumgr *iceland_smu = NULL;
-
-       iceland_smu = kzalloc(sizeof(struct iceland_smumgr), GFP_KERNEL);
-
-       if (iceland_smu == NULL)
-               return -ENOMEM;
-
-       smumgr->backend = iceland_smu;
-       smumgr->smumgr_funcs = &iceland_smu_funcs;
-
-       return 0;
-}
index 47fbc733ab55cf0d59a842bd195c4d0554bdddc9..ce20ae2e520eca7a683db1d5fb1894023d08f517 100644 (file)
@@ -364,9 +364,15 @@ static bool polaris10_is_hw_avfs_present(struct pp_smumgr *smumgr)
 
 static int polaris10_smu_init(struct pp_smumgr *smumgr)
 {
-       struct polaris10_smumgr *smu_data = (struct polaris10_smumgr *)(smumgr->backend);
+       struct polaris10_smumgr *smu_data;
        int i;
 
+       smu_data = kzalloc(sizeof(struct polaris10_smumgr), GFP_KERNEL);
+       if (smu_data == NULL)
+               return -ENOMEM;
+
+       smumgr->backend = smu_data;
+
        if (smu7_init(smumgr))
                return -EINVAL;
 
@@ -381,7 +387,7 @@ static int polaris10_smu_init(struct pp_smumgr *smumgr)
        return 0;
 }
 
-static const struct pp_smumgr_func polaris10_smu_funcs = {
+const struct pp_smumgr_func polaris10_smu_funcs = {
        .smu_init = polaris10_smu_init,
        .smu_fini = smu7_smu_fini,
        .start_smu = polaris10_start_smu,
@@ -404,18 +410,3 @@ static const struct pp_smumgr_func polaris10_smu_funcs = {
        .get_mac_definition = polaris10_get_mac_definition,
        .is_dpm_running = polaris10_is_dpm_running,
 };
-
-int polaris10_smum_init(struct pp_smumgr *smumgr)
-{
-       struct polaris10_smumgr *polaris10_smu = NULL;
-
-       polaris10_smu = kzalloc(sizeof(struct polaris10_smumgr), GFP_KERNEL);
-
-       if (polaris10_smu == NULL)
-               return -EINVAL;
-
-       smumgr->backend = polaris10_smu;
-       smumgr->smumgr_funcs = &polaris10_smu_funcs;
-
-       return 0;
-}
index d5244c16d2d5fb40e5dd7ddce3a6e7ceca19eec2..60c36928284cad7a4d5f59f38b29e0d3cad8e16d 100644 (file)
@@ -41,6 +41,7 @@ MODULE_FIRMWARE("amdgpu/polaris11_smc.bin");
 MODULE_FIRMWARE("amdgpu/polaris11_smc_sk.bin");
 MODULE_FIRMWARE("amdgpu/polaris12_smc.bin");
 
+
 int smum_early_init(struct pp_instance *handle)
 {
        struct pp_smumgr *smumgr;
@@ -61,23 +62,23 @@ int smum_early_init(struct pp_instance *handle)
 
        switch (smumgr->chip_family) {
        case AMDGPU_FAMILY_CZ:
-               cz_smum_init(smumgr);
+               smumgr->smumgr_funcs = &cz_smu_funcs;
                break;
        case AMDGPU_FAMILY_VI:
                switch (smumgr->chip_id) {
                case CHIP_TOPAZ:
-                       iceland_smum_init(smumgr);
+                       smumgr->smumgr_funcs = &iceland_smu_funcs;
                        break;
                case CHIP_TONGA:
-                       tonga_smum_init(smumgr);
+                       smumgr->smumgr_funcs = &tonga_smu_funcs;
                        break;
                case CHIP_FIJI:
-                       fiji_smum_init(smumgr);
+                       smumgr->smumgr_funcs = &fiji_smu_funcs;
                        break;
                case CHIP_POLARIS11:
                case CHIP_POLARIS10:
                case CHIP_POLARIS12:
-                       polaris10_smum_init(smumgr);
+                       smumgr->smumgr_funcs = &polaris10_smu_funcs;
                        break;
                default:
                        return -EINVAL;
index 858568b8c980fa951b9e3f14fd4355c42300f3f6..a7d55366f2d2c3514e4b0580b03d0bd2f605afb0 100644 (file)
@@ -169,20 +169,25 @@ static int tonga_start_smu(struct pp_smumgr *smumgr)
  */
 static int tonga_smu_init(struct pp_smumgr *smumgr)
 {
-       struct tonga_smumgr *smu_data = (struct tonga_smumgr *)(smumgr->backend);
+       struct tonga_smumgr *tonga_priv = NULL;
+       int  i;
 
-       int i;
+       tonga_priv = kzalloc(sizeof(struct tonga_smumgr), GFP_KERNEL);
+       if (tonga_priv == NULL)
+               return -ENOMEM;
+
+       smumgr->backend = tonga_priv;
 
        if (smu7_init(smumgr))
                return -EINVAL;
 
        for (i = 0; i < SMU72_MAX_LEVELS_GRAPHICS; i++)
-               smu_data->activity_target[i] = 30;
+               tonga_priv->activity_target[i] = 30;
 
        return 0;
 }
 
-static const struct pp_smumgr_func tonga_smu_funcs = {
+const struct pp_smumgr_func tonga_smu_funcs = {
        .smu_init = &tonga_smu_init,
        .smu_fini = &smu7_smu_fini,
        .start_smu = &tonga_start_smu,
@@ -205,18 +210,3 @@ static const struct pp_smumgr_func tonga_smu_funcs = {
        .initialize_mc_reg_table = tonga_initialize_mc_reg_table,
        .is_dpm_running = tonga_is_dpm_running,
 };
-
-int tonga_smum_init(struct pp_smumgr *smumgr)
-{
-       struct tonga_smumgr *tonga_smu = NULL;
-
-       tonga_smu = kzalloc(sizeof(struct tonga_smumgr), GFP_KERNEL);
-
-       if (tonga_smu == NULL)
-               return -ENOMEM;
-
-       smumgr->backend = tonga_smu;
-       smumgr->smumgr_funcs = &tonga_smu_funcs;
-
-       return 0;
-}