Commit 62b9a88c authored by Kevin Wang's avatar Kevin Wang Committed by Alex Deucher

drm/amd/powerplay: move function get_metrics_table to vega20_ppt

the SmuMetrics_t table is asic related data structure.
so move vega20_ppt file to implement.
Signed-off-by: default avatarKevin Wang <kevin1.wang@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent a38470f0
...@@ -406,6 +406,8 @@ struct smu_table_context ...@@ -406,6 +406,8 @@ struct smu_table_context
void *power_play_table; void *power_play_table;
uint32_t power_play_table_size; uint32_t power_play_table_size;
void *hardcode_pptable; void *hardcode_pptable;
unsigned long metrics_time;
void *metrics_table;
void *max_sustainable_clocks; void *max_sustainable_clocks;
struct smu_bios_boot_up_values boot_values; struct smu_bios_boot_up_values boot_values;
...@@ -524,8 +526,6 @@ struct smu_context ...@@ -524,8 +526,6 @@ struct smu_context
uint32_t smc_if_version; uint32_t smc_if_version;
unsigned long metrics_time;
void *metrics_table;
}; };
struct pptable_funcs { struct pptable_funcs {
...@@ -589,7 +589,7 @@ struct pptable_funcs { ...@@ -589,7 +589,7 @@ struct pptable_funcs {
int (*set_ppfeature_status)(struct smu_context *smu, uint64_t ppfeatures); int (*set_ppfeature_status)(struct smu_context *smu, uint64_t ppfeatures);
int (*get_ppfeature_status)(struct smu_context *smu, char *buf); int (*get_ppfeature_status)(struct smu_context *smu, char *buf);
bool (*is_dpm_running)(struct smu_context *smu); 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 (*set_thermal_fan_table)(struct smu_context *smu);
int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t *speed); int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t *speed);
int (*set_watermarks_table)(struct smu_context *smu, void *watermarks, int (*set_watermarks_table)(struct smu_context *smu, void *watermarks,
......
...@@ -479,7 +479,7 @@ static int navi10_store_powerplay_table(struct smu_context *smu) ...@@ -479,7 +479,7 @@ static int navi10_store_powerplay_table(struct smu_context *smu)
return 0; 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), SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t),
PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM); PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
......
...@@ -407,7 +407,9 @@ static int smu_v11_0_init_smc_tables(struct smu_context *smu) ...@@ -407,7 +407,9 @@ static int smu_v11_0_init_smc_tables(struct smu_context *smu)
smu_table->tables = tables; 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); ret = smu_v11_0_init_dpm_context(smu);
if (ret) if (ret)
...@@ -425,8 +427,11 @@ static int smu_v11_0_fini_smc_tables(struct smu_context *smu) ...@@ -425,8 +427,11 @@ static int smu_v11_0_fini_smc_tables(struct smu_context *smu)
return -EINVAL; return -EINVAL;
kfree(smu_table->tables); kfree(smu_table->tables);
kfree(smu_table->metrics_table);
smu_table->tables = NULL; smu_table->tables = NULL;
smu_table->table_count = 0; smu_table->table_count = 0;
smu_table->metrics_table = NULL;
smu_table->metrics_time = 0;
ret = smu_v11_0_fini_dpm_context(smu); ret = smu_v11_0_fini_dpm_context(smu);
if (ret) if (ret)
...@@ -449,13 +454,6 @@ static int smu_v11_0_init_power(struct smu_context *smu) ...@@ -449,13 +454,6 @@ static int smu_v11_0_init_power(struct smu_context *smu)
return -ENOMEM; return -ENOMEM;
smu_power->power_context_size = sizeof(struct smu_11_0_dpm_context); 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; return 0;
} }
...@@ -468,9 +466,7 @@ static int smu_v11_0_fini_power(struct smu_context *smu) ...@@ -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) if (!smu_power->power_context || smu_power->power_context_size == 0)
return -EINVAL; return -EINVAL;
kfree(smu->metrics_table);
kfree(smu_power->power_context); kfree(smu_power->power_context);
smu->metrics_table = NULL;
smu_power->power_context = NULL; smu_power->power_context = NULL;
smu_power->power_context_size = 0; smu_power->power_context_size = 0;
...@@ -1227,26 +1223,6 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu) ...@@ -1227,26 +1223,6 @@ static int smu_v11_0_start_thermal_control(struct smu_context *smu)
return ret; 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, static int smu_v11_0_thermal_get_temperature(struct smu_context *smu,
enum amd_pp_sensors sensor, enum amd_pp_sensors sensor,
uint32_t *value) uint32_t *value)
......
...@@ -294,8 +294,10 @@ static int vega20_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER_P ...@@ -294,8 +294,10 @@ static int vega20_get_workload_type(struct smu_context *smu, enum PP_SMC_POWER_P
return val; 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), SMU_TABLE_INIT(tables, SMU_TABLE_PPTABLE, sizeof(PPTable_t),
PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM); PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM);
SMU_TABLE_INIT(tables, SMU_TABLE_WATERMARKS, sizeof(Watermarks_t), 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 ...@@ -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, SMU_TABLE_INIT(tables, SMU_TABLE_ACTIVITY_MONITOR_COEFF,
sizeof(DpmActivityMonitorCoeffInt_t), PAGE_SIZE, sizeof(DpmActivityMonitorCoeffInt_t), PAGE_SIZE,
AMDGPU_GEM_DOMAIN_VRAM); 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) 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) ...@@ -1654,6 +1663,26 @@ static int vega20_set_default_od8_setttings(struct smu_context *smu)
return 0; 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, static int vega20_get_od_percentage(struct smu_context *smu,
enum pp_clock_type type) enum pp_clock_type type)
{ {
...@@ -2933,8 +2962,7 @@ static int vega20_get_gpu_power(struct smu_context *smu, uint32_t *value) ...@@ -2933,8 +2962,7 @@ static int vega20_get_gpu_power(struct smu_context *smu, uint32_t *value)
if (!value) if (!value)
return -EINVAL; return -EINVAL;
ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, (void *)&metrics, ret = vega20_get_metrics_table(smu, &metrics);
false);
if (ret) if (ret)
return ret; return ret;
...@@ -2953,8 +2981,7 @@ static int vega20_get_current_activity_percent(struct smu_context *smu, ...@@ -2953,8 +2981,7 @@ static int vega20_get_current_activity_percent(struct smu_context *smu,
if (!value) if (!value)
return -EINVAL; return -EINVAL;
ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, ret = vega20_get_metrics_table(smu, &metrics);
(void *)&metrics, false);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment