Use uniras core to invoke ras command.

Changed from v1:
        use common function send_ras_ta_runtime_cmd in ras_psp_invoke_ras_ta

Signed-off-by: Stanley.Yang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 17 +++++++++
 drivers/gpu/drm/amd/ras/core/ras_psp.c     | 40 +++++++++++++++++-----
 drivers/gpu/drm/amd/ras/core/ras_psp.h     |  3 ++
 drivers/gpu/drm/amd/ras/core/ta_if.h       |  1 +
 4 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
index 8ae72c862d11..2d494ac57eb4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c
@@ -23,6 +23,7 @@
 
 #include "amdgpu.h"
 #include "amdgpu_psp_ta.h"
+#include "amdgpu_ras_mgr.h"
 
 #if defined(CONFIG_DEBUG_FS)
 
@@ -330,6 +331,22 @@ static ssize_t ta_if_invoke_debugfs_write(struct file *fp, 
const char *buf, size
        if (IS_ERR(shared_buf))
                return PTR_ERR(shared_buf);
 
+       if (ta_type == TA_TYPE_RAS && amdgpu_uniras_enabled(adev)) {
+               struct amdgpu_ras_mgr *ras_mgr = 
amdgpu_ras_mgr_get_context(adev);
+
+               if (!ras_mgr || !ras_mgr->ras_core) {
+                       ret = -EINVAL;
+                       goto free_shared_buf;
+               }
+
+               ret = ras_psp_invoke_ras_ta(ras_mgr->ras_core, ta_id, cmd_id,
+                                          shared_buf, shared_buf_len);
+               if (!ret && copy_to_user((char *)&buf[copy_pos], shared_buf, 
shared_buf_len))
+                       ret = -EFAULT;
+
+               goto free_shared_buf;
+       }
+
        set_ta_context_funcs(psp, ta_type, &context);
 
        if (!context || !context->initialized) {
diff --git a/drivers/gpu/drm/amd/ras/core/ras_psp.c 
b/drivers/gpu/drm/amd/ras/core/ras_psp.c
index ed53cd25d6bd..c3c6039bfe7a 100644
--- a/drivers/gpu/drm/amd/ras/core/ras_psp.c
+++ b/drivers/gpu/drm/amd/ras/core/ras_psp.c
@@ -426,7 +426,8 @@ static int __check_ras_ta_cmd_resp(struct ras_core_context 
*ras_core,
 }
 
 static int send_ras_ta_runtime_cmd(struct ras_core_context *ras_core,
-                       enum ras_ta_cmd_id cmd_id, void *in, uint32_t in_size,
+                       uint32_t session_id, enum ras_ta_cmd_id cmd_id,
+                       void *in, uint32_t in_size,
                        void *out, uint32_t out_size)
 {
        struct ras_ta_ctx *ta_ctx = &ras_core->ras_psp.ta_ctx;
@@ -467,7 +468,7 @@ static int send_ras_ta_runtime_cmd(struct ras_core_context 
*ras_core,
        memcpy(&ras_cmd->ras_in_message, in, in_size);
 
        invoke_cmd.ta_cmd_id = cmd_id;
-       invoke_cmd.session_id = ta_ctx->session_id;
+       invoke_cmd.session_id = session_id;
 
        ret = send_psp_cmd(ras_core, GFX_CMD_ID_INVOKE_CMD,
                        &invoke_cmd, sizeof(invoke_cmd), &resp);
@@ -494,10 +495,15 @@ static int send_ras_ta_runtime_cmd(struct 
ras_core_context *ras_core,
                goto unlock;
        }
 
-       if (!ras_cmd->ras_status && out && out_size)
+       /* Hand the TA output back regardless of status; ret carries the 
status. */
+       if (out && out_size)
                memcpy(out, &ras_cmd->ras_out_message, out_size);
 
-       ret = __check_ras_ta_cmd_resp(ras_core, ras_cmd);
+       /* cmd from user space requires special handling for 
CHECK_ACA_BANK_ERROR_TYPES */
+       if (cmd_id == RAS_TA_CMD_ID__CHECK_ACA_BANK_ERROR_TYPES)
+               __check_ras_ta_cmd_resp(ras_core, ras_cmd);
+       else
+               ret = __check_ras_ta_cmd_resp(ras_core, ras_cmd);
 
 unlock:
        mutex_unlock(&ta_ctx->ta_mutex);
@@ -536,7 +542,9 @@ static int trigger_ras_ta_error(struct ras_core_context 
*ras_core,
        dev_mask &= RAS_TA_INST_MASK;
        info->sub_block_index |= dev_mask;
 
-       return send_ras_ta_runtime_cmd(ras_core, RAS_TA_CMD_ID__TRIGGER_ERROR,
+       return send_ras_ta_runtime_cmd(ras_core,
+                               ras_core->ras_psp.ta_ctx.session_id,
+                               RAS_TA_CMD_ID__TRIGGER_ERROR,
                                info, sizeof(*info), NULL, 0);
 }
 
@@ -785,6 +793,21 @@ int ras_psp_unsideload_ras_ta(struct ras_core_context 
*ras_core,
        return unload_ras_ta_fw(ras_core, ras_ta_unload);
 }
 
+int ras_psp_invoke_ras_ta(struct ras_core_context *ras_core,
+               uint32_t session_id, uint32_t cmd_id,
+               void *shared_buf, uint32_t shared_buf_len)
+{
+       /* The debugfs caller hands over a full ras_ta_cmd shared buffer. */
+       struct ras_ta_cmd *ras_cmd = shared_buf;
+
+       if (!shared_buf || shared_buf_len < sizeof(*ras_cmd))
+               return -EINVAL;
+
+       return send_ras_ta_runtime_cmd(ras_core, session_id, cmd_id,
+                       &ras_cmd->ras_in_message, 
sizeof(ras_cmd->ras_in_message),
+                       &ras_cmd->ras_out_message, 
sizeof(ras_cmd->ras_out_message));
+}
+
 int ras_psp_reload_firmwares(struct ras_core_context *ras_core,
                uint32_t flags)
 {
@@ -810,7 +833,7 @@ int ras_psp_enable_features(struct ras_core_context 
*ras_core,
                return -ENOEXEC;
        }
 
-       return send_ras_ta_runtime_cmd(ras_core,
+       return send_ras_ta_runtime_cmd(ras_core, ta_ctx->session_id,
                        enable ? RAS_TA_CMD_ID__ENABLE_FEATURES :
                                 RAS_TA_CMD_ID__DISABLE_FEATURES,
                        info, sizeof(*info), NULL, 0);
@@ -846,8 +869,9 @@ int ras_psp_query_address(struct ras_core_context *ras_core,
        if (!addr_in || !addr_out)
                return -EINVAL;
 
-       return send_ras_ta_runtime_cmd(ras_core, RAS_TA_CMD_ID__QUERY_ADDRESS,
-               addr_in, sizeof(*addr_in), addr_out, sizeof(*addr_out));
+       return send_ras_ta_runtime_cmd(ras_core, ta_ctx->session_id,
+               RAS_TA_CMD_ID__QUERY_ADDRESS, addr_in, sizeof(*addr_in),
+               addr_out, sizeof(*addr_out));
 }
 
 int ras_psp_sw_init(struct ras_core_context *ras_core)
diff --git a/drivers/gpu/drm/amd/ras/core/ras_psp.h 
b/drivers/gpu/drm/amd/ras/core/ras_psp.h
index 4cc133c6a6d3..91d17fdd6bda 100644
--- a/drivers/gpu/drm/amd/ras/core/ras_psp.h
+++ b/drivers/gpu/drm/amd/ras/core/ras_psp.h
@@ -196,6 +196,9 @@ int ras_psp_sideload_ras_ta(struct ras_core_context 
*ras_core,
                struct ras_psp_ta_load *ta_load);
 int ras_psp_unsideload_ras_ta(struct ras_core_context *ras_core,
                struct ras_psp_ta_unload *ras_ta_unload);
+int ras_psp_invoke_ras_ta(struct ras_core_context *ras_core,
+               uint32_t session_id, uint32_t cmd_id,
+               void *shared_buf, uint32_t shared_buf_len);
 int ras_psp_enable_features(struct ras_core_context *ras_core,
        struct ras_ta_enable_features_input *info, bool enable);
 int ras_psp_trigger_error(struct ras_core_context *ras_core,
diff --git a/drivers/gpu/drm/amd/ras/core/ta_if.h 
b/drivers/gpu/drm/amd/ras/core/ta_if.h
index 30c058a524db..87d5aa3f8477 100644
--- a/drivers/gpu/drm/amd/ras/core/ta_if.h
+++ b/drivers/gpu/drm/amd/ras/core/ta_if.h
@@ -44,6 +44,7 @@ enum ras_ta_cmd_id {
        RAS_TA_CMD_ID__QUERY_BLOCK_INFO,
        RAS_TA_CMD_ID__QUERY_SUB_BLOCK_INFO,
        RAS_TA_CMD_ID__QUERY_ADDRESS,
+       RAS_TA_CMD_ID__CHECK_ACA_BANK_ERROR_TYPES = 10,
        MAX_RAS_TA_CMD_ID
 };
 
-- 
2.43.0

Reply via email to