From: Kevin Wang <kevin1.wang@xxxxxxx> the SmuMetrics_t table is asic related data structure. so move vega20_ppt file to implement. Signed-off-by: Kevin Wang <kevin1.wang@xxxxxxx> Signed-off-by: Alex Deucher <alexander.deucher@xxxxxxx> --- .../gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 6 +-- drivers/gpu/drm/amd/powerplay/navi10_ppt.c | 2 +- drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 36 +++--------------- drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 37 ++++++++++++++++--- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h index 4706eaf39cf7..0fd3d89386be 100644 --- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h +++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h @@ -406,6 +406,8 @@ struct smu_table_context void *power_play_table; uint32_t power_play_table_size; void *hardcode_pptable; + unsigned long metrics_time; + void *metrics_table; void *max_sustainable_clocks; struct smu_bios_boot_up_values boot_values; @@ -524,8 +526,6 @@ struct smu_context uint32_t smc_if_version; - unsigned long metrics_time; - void *metrics_table; }; struct pptable_funcs { @@ -589,7 +589,7 @@ struct pptable_funcs { int (*set_ppfeature_status)(struct smu_context *smu, uint64_t ppfeatures); int (*get_ppfeature_status)(struct smu_context *smu, char *buf); bool (*is_dpm_running)(struct smu_context *smu); - void (*tables_init)(struct smu_context *smu, struct smu_table *tables); + int (*tables_init)(struct smu_context *smu, struct smu_table *tables); int (*set_thermal_fan_table)(struct smu_context *smu); int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t *speed); int (*set_watermarks_table)(struct smu_context *smu, void *watermarks, diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c index d20d498af675..130719663566 100644 --- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c +++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c @@ -479,7 +479,7 @@ static int navi10_store_powerplay_table(struct smu_context *smu) return 0; } -static void navi10_tables_init(struct smu_context *smu, struct smu_table *tables) +static int navi10_tables_init(struct smu_context *smu, struct smu_table *tables) { SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t), PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM); diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c index 1896ce1ece6b..538f52ab4b72 100644 --- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c +++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c @@ -407,7 +407,9 @@ static int smu_v11_0_init_smc_tables(struct smu_context *smu) smu_table->tables = tables; - smu_tables_init(smu, tables); + ret = smu_tables_init(smu, tables); + if (ret) + return ret; ret = smu_v11_0_init_dpm_context(smu); if (ret) @@ -425,8 +427,11 @@ static int smu_v11_0_fini_smc_tables(struct smu_context *smu) return -EINVAL; kfree(smu_table->tables); + kfree(smu_table->metrics_table); smu_table->tables = NULL; smu_table->table_count = 0; + smu_table->metrics_table = NULL; + smu_table->metrics_time = 0; ret = smu_v11_0_fini_dpm_context(smu); if (ret) @@ -449,13 +454,6 @@ static int smu_v11_0_init_power(struct smu_context *smu) return -ENOMEM; smu_power->power_context_size = sizeof(struct smu_11_0_dpm_context); - smu->metrics_time = 0; - smu->metrics_table = kzalloc(sizeof(SmuMetrics_t), GFP_KERNEL); - if (!smu->metrics_table) { - kfree(smu_power->power_context); - return -ENOMEM; - } - return 0; } @@ -468,9 +466,7 @@ static int smu_v11_0_fini_power(struct smu_context *smu) if (!smu_power->power_context || smu_power->power_context_size == 0) return -EINVAL; - kfree(smu->metrics_table); kfree(smu_power->power_context); - smu->metrics_table = NULL; smu_power->power_context = NULL; smu_power->power_context_size = 0; @@ -1227,26 +1223,6 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu) return ret; } -static int smu_v11_0_get_metrics_table(struct smu_context *smu, - SmuMetrics_t *metrics_table) -{ - int ret = 0; - - if (!smu->metrics_time || time_after(jiffies, smu->metrics_time + HZ / 1000)) { - ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, - (void *)metrics_table, false); - if (ret) { - pr_info("Failed to export SMU metrics table!\n"); - return ret; - } - memcpy(smu->metrics_table, metrics_table, sizeof(SmuMetrics_t)); - smu->metrics_time = jiffies; - } else - memcpy(metrics_table, smu->metrics_table, sizeof(SmuMetrics_t)); - - return ret; -} - static int smu_v11_0_thermal_get_temperature(struct smu_context *smu, enum amd_pp_sensors sensor, uint32_t *value) diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c index 81fb5b5d76be..dd354a993bf1 100644 --- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c +++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c @@ -294,8 +294,10 @@ static int vega20_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER_P return val; } -static void vega20_tables_init(struct smu_context *smu, struct smu_table *tables) +static int vega20_tables_init(struct smu_context *smu, struct smu_table *tables) { + struct smu_table_context *smu_table = &smu->smu_table; + SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t), PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM); SMU_TABLE_INIT(tables, SMU_TABLE_WATERMARKS, sizeof(Watermarks_t), @@ -309,6 +311,13 @@ static void vega20_tables_init(struct smu_context *smu, struct smu_table *tables 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; + smu_table->metrics_time = 0; + + return 0; } static int vega20_allocate_dpm_context(struct smu_context *smu) @@ -1654,6 +1663,26 @@ static int vega20_set_default_od8_setttings(struct smu_context *smu) return 0; } +static int vega20_get_metrics_table(struct smu_context *smu, + SmuMetrics_t *metrics_table) +{ + struct smu_table_context *smu_table= &smu->smu_table; + int ret = 0; + + if (!smu_table->metrics_time || time_after(jiffies, smu_table->metrics_time + HZ / 1000)) { + ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, + (void *)smu_table->metrics_table, false); + if (ret) { + pr_info("Failed to export SMU metrics table!\n"); + return ret; + } + smu_table->metrics_time = jiffies; + } + + memcpy(metrics_table, smu_table->metrics_table, sizeof(SmuMetrics_t)); + + return ret; +} static int vega20_get_od_percentage(struct smu_context *smu, enum pp_clock_type type) { @@ -2933,8 +2962,7 @@ static int vega20_get_gpu_power(struct smu_context *smu, uint32_t *value) if (!value) return -EINVAL; - ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, (void *)&metrics, - false); + ret = vega20_get_metrics_table(smu, &metrics); if (ret) return ret; @@ -2953,8 +2981,7 @@ static int vega20_get_current_activity_percent(struct smu_context *smu, if (!value) return -EINVAL; - ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, - (void *)&metrics, false); + ret = vega20_get_metrics_table(smu, &metrics); if (ret) return ret; -- 2.20.1 _______________________________________________ amd-gfx mailing list amd-gfx@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/amd-gfx