]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amd/pm: add read_sensor function for yellow carp
authorXiaomeng Hou <Xiaomeng.Hou@amd.com>
Wed, 27 Jan 2021 05:22:23 +0000 (13:22 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 4 Jun 2021 20:03:19 +0000 (16:03 -0400)
Add callback function read_sensor for yellow carp.

Acked-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Xiaomeng Hou <Xiaomeng.Hou@amd.com>
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c

index 8cc0f8c28263bb9fa94ba75db16d4728398b5ea5..373abe8376c95dfe774ff99625272c045741b862 100644 (file)
@@ -183,6 +183,145 @@ static int yellow_carp_post_smu_init(struct smu_context *smu)
        return ret;
 }
 
+static int yellow_carp_get_smu_metrics_data(struct smu_context *smu,
+                                                       MetricsMember_t member,
+                                                       uint32_t *value)
+{
+       struct smu_table_context *smu_table = &smu->smu_table;
+
+       SmuMetrics_t *metrics = (SmuMetrics_t *)smu_table->metrics_table;
+       int ret = 0;
+
+       mutex_lock(&smu->metrics_lock);
+
+       ret = smu_cmn_get_metrics_table_locked(smu, NULL, false);
+       if (ret) {
+               mutex_unlock(&smu->metrics_lock);
+               return ret;
+       }
+
+       switch (member) {
+       case METRICS_AVERAGE_GFXCLK:
+               *value = metrics->GfxclkFrequency;
+               break;
+       case METRICS_AVERAGE_SOCCLK:
+               *value = metrics->SocclkFrequency;
+               break;
+       case METRICS_AVERAGE_VCLK:
+               *value = metrics->VclkFrequency;
+               break;
+       case METRICS_AVERAGE_DCLK:
+               *value = metrics->DclkFrequency;
+               break;
+       case METRICS_AVERAGE_UCLK:
+               *value = metrics->MemclkFrequency;
+               break;
+       case METRICS_AVERAGE_GFXACTIVITY:
+               *value = metrics->GfxActivity / 100;
+               break;
+       case METRICS_AVERAGE_VCNACTIVITY:
+               *value = metrics->UvdActivity;
+               break;
+       case METRICS_AVERAGE_SOCKETPOWER:
+               *value = (metrics->CurrentSocketPower << 8) / 1000;
+               break;
+       case METRICS_TEMPERATURE_EDGE:
+               *value = metrics->GfxTemperature / 100 *
+               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
+               break;
+       case METRICS_TEMPERATURE_HOTSPOT:
+               *value = metrics->SocTemperature / 100 *
+               SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;
+               break;
+       case METRICS_THROTTLER_STATUS:
+               *value = metrics->ThrottlerStatus;
+               break;
+       case METRICS_VOLTAGE_VDDGFX:
+               *value = metrics->Voltage[0];
+               break;
+       case METRICS_VOLTAGE_VDDSOC:
+               *value = metrics->Voltage[1];
+               break;
+       default:
+               *value = UINT_MAX;
+               break;
+       }
+
+       mutex_unlock(&smu->metrics_lock);
+
+       return ret;
+}
+
+static int yellow_carp_read_sensor(struct smu_context *smu,
+                                       enum amd_pp_sensors sensor,
+                                       void *data, uint32_t *size)
+{
+       int ret = 0;
+
+       if (!data || !size)
+               return -EINVAL;
+
+       mutex_lock(&smu->sensor_lock);
+       switch (sensor) {
+       case AMDGPU_PP_SENSOR_GPU_LOAD:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_AVERAGE_GFXACTIVITY,
+                                                               (uint32_t *)data);
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_GPU_POWER:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_AVERAGE_SOCKETPOWER,
+                                                               (uint32_t *)data);
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_EDGE_TEMP:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_TEMPERATURE_EDGE,
+                                                               (uint32_t *)data);
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_HOTSPOT_TEMP:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_TEMPERATURE_HOTSPOT,
+                                                               (uint32_t *)data);
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_GFX_MCLK:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_AVERAGE_UCLK,
+                                                               (uint32_t *)data);
+               *(uint32_t *)data *= 100;
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_GFX_SCLK:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_AVERAGE_GFXCLK,
+                                                               (uint32_t *)data);
+               *(uint32_t *)data *= 100;
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_VDDGFX:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_VOLTAGE_VDDGFX,
+                                                               (uint32_t *)data);
+               *size = 4;
+               break;
+       case AMDGPU_PP_SENSOR_VDDNB:
+               ret = yellow_carp_get_smu_metrics_data(smu,
+                                                               METRICS_VOLTAGE_VDDSOC,
+                                                               (uint32_t *)data);
+               *size = 4;
+               break;
+       default:
+               ret = -EOPNOTSUPP;
+               break;
+       }
+       mutex_unlock(&smu->sensor_lock);
+
+       return ret;
+}
+
 static const struct pptable_funcs yellow_carp_ppt_funcs = {
        .check_fw_status = smu_v13_0_1_check_fw_status,
        .check_fw_version = smu_v13_0_1_check_fw_version,
@@ -193,6 +332,7 @@ static const struct pptable_funcs yellow_carp_ppt_funcs = {
        .dpm_set_vcn_enable = yellow_carp_dpm_set_vcn_enable,
        .dpm_set_jpeg_enable = yellow_carp_dpm_set_jpeg_enable,
        .set_default_dpm_table = smu_v13_0_1_set_default_dpm_tables,
+       .read_sensor = yellow_carp_read_sensor,
        .is_dpm_running = yellow_carp_is_dpm_running,
        .get_enabled_mask = smu_cmn_get_enabled_32_bits_mask,
        .get_pp_feature_mask = smu_cmn_get_pp_feature_mask,