From: Felix Kuehling <[email protected]>

To query UALink configuration information from PSP.

Signed-off-by: Felix Kuehling <[email protected]>
Reviewed-by: Mukul Joshi <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 58 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  6 +++
 2 files changed, 64 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 5c82d1d808157..006ec1a241f48 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -829,6 +829,8 @@ static const char *psp_gfx_cmd_name(enum psp_gfx_cmd_id 
cmd_id)
                return "PERF MONITORING HW";
        case GFX_CMD_ID_UAL_GET_INTERFACE_VER:
                return "UAL_GET_INTERFACE_VER";
+       case GFX_CMD_ID_UAL_GET_CONFIG:
+               return "UAL_GET_CONFIG";
        default:
                return "UNKNOWN CMD";
        }
@@ -1212,6 +1214,62 @@ int psp_ual_get_interface_version(struct psp_context 
*psp, uint32_t *intf_ver)
        return ret;
 }
 
+int psp_ual_query_info(struct psp_context *psp, uint32_t intf_ver,
+                      struct amdgpu_ualink_info *info)
+{
+       struct psp_gfx_get_config_ual_v1 *ual_config;
+       struct psp_gfx_cmd_resp *cmd;
+       int ret;
+
+       /* TBD check interface version 1.x */
+       if (intf_ver > 0x1ffff) {
+               pr_warn("PSP UAL interface version mismatch: 0x%x\n", intf_ver);
+               return -EOPNOTSUPP;
+       }
+
+       cmd = acquire_psp_cmd_buf(psp);
+
+       ual_config = psp->cmd_ext_resp_mem;
+
+       cmd->cmd_id = GFX_CMD_ID_UAL_GET_CONFIG;
+       cmd->cmd.cmd_get_config_ual.ual_cfg_addr_lo = 
lower_32_bits(psp->cmd_ext_resp_mc_addr);
+       cmd->cmd.cmd_get_config_ual.ual_cfg_addr_hi = 
upper_32_bits(psp->cmd_ext_resp_mc_addr);
+       cmd->cmd.cmd_get_config_ual.ual_cfg_size = sizeof(*ual_config);
+
+       ret = psp_cmd_submit_buf(psp, NULL, cmd, psp->fence_buf_mc_addr);
+
+       if (!ret && !cmd->resp.status) {
+               WARN_ON(cmd->resp.uresp.get_config_ual.resp_size < 
sizeof(*ual_config));
+
+               info->link_type = (enum 
amdgpu_ualink_type)ual_config->link_type;
+
+               info->ppod.accel_id = ual_config->accelerator_id;
+               info->ppod.bandwidth = ual_config->bandwidth;
+               info->ppod.latency = ual_config->latency;
+               info->ppod.size = ual_config->ppod_size;
+               memcpy(&info->ppod.id, ual_config->ppod_id, 
sizeof(info->ppod.id));
+
+               info->vpod.id = ual_config->vpod_id;
+               info->vpod.size = ual_config->vpod_size;
+               info->vpod.addr_mode = ual_config->addr_mode;
+               bitmap_from_arr32(info->vpod.active_accel_bits,
+                                 ual_config->vpod_active_accelerators,
+                                 min(AMDGPU_UALINK_ACCEL_MAX, 
PSP_GFX_UAL_MAX_ACC_BIT_MASK*32));
+               /* Ensure no uninitialized data in the bitmap, even if these
+                * constants change in the future.
+                */
+               if (AMDGPU_UALINK_ACCEL_MAX > PSP_GFX_UAL_MAX_ACC_BIT_MASK*32)
+                       bitmap_clear(info->vpod.active_accel_bits, 
PSP_GFX_UAL_MAX_ACC_BIT_MASK*32,
+                                    AMDGPU_UALINK_ACCEL_MAX - 
PSP_GFX_UAL_MAX_ACC_BIT_MASK*32);
+       } else if (!ret) {
+               ret = -EINVAL;
+       }
+
+       release_psp_cmd_buf(psp);
+
+       return ret;
+}
+
 int psp_update_fw_reservation(struct psp_context *psp)
 {
        int ret;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
index 5968595647fef..66b57c871e1a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h
@@ -705,6 +705,12 @@ int amdgpu_psp_irq_mgr_register(
        struct amdgpu_psp_irq_mgr *mgr,
        const struct amdgpu_psp_irq_handler *handlers, int count,
        const struct amdgpu_psp_irq_handler *default_handler);
+
+struct amdgpu_ualink_info;
+
 int psp_ual_get_interface_version(struct psp_context *psp, uint32_t *intf_ver);
 
+int psp_ual_query_info(struct psp_context *psp, uint32_t intf_ver,
+                      struct amdgpu_ualink_info *info);
+
 #endif
-- 
2.55.0

Reply via email to