drm/amd/pm: Add interface to get FW private buffer
authorLijo Lazar <lijo.lazar@amd.com>
Thu, 15 Apr 2021 07:22:28 +0000 (15:22 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 10 May 2021 22:06:45 +0000 (18:06 -0400)
v1: Add new interface to get FW private buffer details
v2: Drop domain check
v3: Use amdgpu_bo_kmap to get cpu address

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Suggested-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/include/kgd_pp_interface.h
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

index 3534686670362964e61ad3037982b23e414f341c..abd5a9d41d4c58bb3340acf976bbfc88b56d8824 100644 (file)
@@ -350,6 +350,7 @@ struct amd_pm_funcs {
                                   unsigned int *num_states);
        int (*get_dpm_clock_table)(void *handle,
                                   struct dpm_clocks *clock_table);
+       int (*get_smu_prv_buf_details)(void *handle, void **addr, size_t *size);
 };
 
 struct metrics_table_header {
index ee6340c6f921e51f89db050ddfe9fab1f70c4502..c73504e998e54ae3ecaec8d6a1dcb45f744e220a 100644 (file)
@@ -1651,6 +1651,26 @@ static int pp_gfx_state_change_set(void *handle, uint32_t state)
        return 0;
 }
 
+static int pp_get_prv_buffer_details(void *handle, void **addr, size_t *size)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       struct amdgpu_device *adev = hwmgr->adev;
+
+       if (!addr || !size)
+               return -EINVAL;
+
+       *addr = NULL;
+       *size = 0;
+       mutex_lock(&hwmgr->smu_lock);
+       if (adev->pm.smu_prv_buffer) {
+               amdgpu_bo_kmap(adev->pm.smu_prv_buffer, addr);
+               *size = adev->pm.smu_prv_buffer_size;
+       }
+       mutex_unlock(&hwmgr->smu_lock);
+
+       return 0;
+}
+
 static const struct amd_pm_funcs pp_dpm_funcs = {
        .load_firmware = pp_dpm_load_fw,
        .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete,
@@ -1714,4 +1734,5 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
        .set_xgmi_pstate = pp_set_xgmi_pstate,
        .get_gpu_metrics = pp_get_gpu_metrics,
        .gfx_state_change_set = pp_gfx_state_change_set,
+       .get_smu_prv_buf_details = pp_get_prv_buffer_details,
 };
index c29d8b3131b7eaaf2cecf04313f6d8a7517e4168..32dadeee9514895cd191f7a3e9852de524794e4a 100644 (file)
@@ -2933,6 +2933,26 @@ int smu_set_light_sbr(struct smu_context *smu, bool enable)
        return ret;
 }
 
+static int smu_get_prv_buffer_details(void *handle, void **addr, size_t *size)
+{
+       struct smu_context *smu = handle;
+       struct smu_table_context *smu_table = &smu->smu_table;
+       struct smu_table *memory_pool = &smu_table->memory_pool;
+
+       if (!addr || !size)
+               return -EINVAL;
+
+       *addr = NULL;
+       *size = 0;
+       mutex_lock(&smu->mutex);
+       if (memory_pool->bo) {
+               *addr = memory_pool->cpu_addr;
+               *size = memory_pool->size;
+       }
+       mutex_unlock(&smu->mutex);
+
+       return 0;
+}
 
 static const struct amd_pm_funcs swsmu_pm_funcs = {
        /* export for sysfs */
@@ -2984,6 +3004,7 @@ static const struct amd_pm_funcs swsmu_pm_funcs = {
        .get_max_sustainable_clocks_by_dc    = smu_get_max_sustainable_clocks_by_dc,
        .load_firmware           = smu_load_microcode,
        .gfx_state_change_set    = smu_gfx_state_change_set,
+       .get_smu_prv_buf_details = smu_get_prv_buffer_details,
 };
 
 int smu_wait_for_event(struct amdgpu_device *adev, enum smu_event_type event,