]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amd/pm: add SMU multi-msgs helpers
authorYang Wang <kevinyang.wang@amd.com>
Mon, 27 Apr 2026 07:09:37 +0000 (15:09 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 11 May 2026 20:06:16 +0000 (16:06 -0400)
SMU15 driver messages can carry multiple input parameters and return
values, but callers still have to build struct smu_msg_args directly.

Add common SMU multi-msgs helpers in smu_cmn and reuse them in the
single-parameter wrapper and the shared table transfer path.

Keep smu_cmn_send_smc_msg() semantics unchanged for older callers.

No functional change intended.

Signed-off-by: Yang Wang <kevinyang.wang@amd.com>
Reviewed-by: Kenneth Feng <kenneth.feng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h

index 90c7127beabffc46dbefc3c80ad4db01b44e15a4..546e64e3ba9c878e5466599e8cfc91de967f7c67 100644 (file)
@@ -127,6 +127,61 @@ int smu_cmn_wait_for_response(struct smu_context *smu)
        return smu_msg_wait_response(&smu->msg_ctl, 0);
 }
 
+/**
+ * smu_cmn_send_smc_msg_with_params_ext - send an SMU message with 0..N args
+ * @smu: pointer to an SMU context
+ * @msg: message to send
+ * @params: optional input argument array
+ * @num_params: number of input arguments in @params
+ * @read_args: optional output argument array
+ * @num_read_args: number of output arguments to read back
+ * @flags: message flags (SMU_MSG_FLAG_*)
+ * @timeout: per-message timeout in us (0 = use default)
+ *
+ * This helper keeps the raw protocol semantics of struct smu_msg_args while
+ * hiding the per-call boilerplate. It is intended for true multi-parameter
+ * messages. Legacy wrappers such as smu_cmn_send_smc_msg() retain their
+ * existing single-zero-parameter behavior for compatibility.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+int smu_cmn_send_smc_msg_with_params_ext(struct smu_context *smu,
+                                        enum smu_message_type msg,
+                                        const uint32_t *params,
+                                        size_t num_params,
+                                        uint32_t *read_args,
+                                        size_t num_read_args,
+                                        uint32_t flags,
+                                        uint32_t timeout)
+{
+       struct smu_msg_ctl *ctl = &smu->msg_ctl;
+       struct smu_msg_args args = {
+               .msg = msg,
+               .num_args = num_params,
+               .num_out_args = num_read_args,
+               .flags = flags,
+               .timeout = timeout,
+       };
+       int ret;
+
+       if ((num_params && !params) || (num_read_args && !read_args))
+               return -EINVAL;
+
+       if (num_params > SMU_MSG_MAX_ARGS || num_read_args > SMU_MSG_MAX_ARGS)
+               return -EINVAL;
+
+       if (num_params)
+               memcpy(args.args, params, num_params * sizeof(*params));
+
+       ret = ctl->ops->send_msg(ctl, &args);
+
+       if (num_read_args)
+               memcpy(read_args, args.out_args,
+                      num_read_args * sizeof(*read_args));
+
+       return ret;
+}
+
 /**
  * smu_cmn_send_smc_msg_with_param -- send a message with parameter
  * @smu: pointer to an SMU context
@@ -164,23 +219,9 @@ int smu_cmn_send_smc_msg_with_param(struct smu_context *smu,
                                    uint32_t param,
                                    uint32_t *read_arg)
 {
-       struct smu_msg_ctl *ctl = &smu->msg_ctl;
-       struct smu_msg_args args = {
-               .msg = msg,
-               .args[0] = param,
-               .num_args = 1,
-               .num_out_args = read_arg ? 1 : 0,
-               .flags = 0,
-               .timeout = 0,
-       };
-       int ret;
-
-       ret = ctl->ops->send_msg(ctl, &args);
-
-       if (read_arg)
-               *read_arg = args.out_args[0];
-
-       return ret;
+       return smu_cmn_send_smc_msg_with_params(smu, msg,
+                                               &param, 1,
+                                               read_arg, read_arg ? 1 : 0);
 }
 
 int smu_cmn_send_smc_msg(struct smu_context *smu,
@@ -1071,13 +1112,12 @@ int smu_cmn_update_table_read_arg(struct smu_context *smu,
        struct amdgpu_device *adev = smu->adev;
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *table = &smu_table->driver_table;
-       struct smu_msg_ctl *ctl = &smu->msg_ctl;
-       struct smu_msg_args args;
        int table_id = smu_cmn_to_asic_specific_index(smu,
                                                      CMN2ASIC_MAPPING_TABLE,
                                                      table_index);
        uint32_t table_size;
        int ret = 0;
+       uint32_t param;
 
        if (!table_data || table_index >= SMU_TABLE_COUNT || table_id < 0)
                return -EINVAL;
@@ -1093,18 +1133,14 @@ int smu_cmn_update_table_read_arg(struct smu_context *smu,
                amdgpu_hdp_flush(adev, NULL);
        }
 
-       args.msg = drv2smu ? SMU_MSG_TransferTableDram2Smu : SMU_MSG_TransferTableSmu2Dram;
-       args.args[0] = ((argument & 0xFFFF) << 16) | (table_id  & 0xffff);
-       args.num_args = 1;
-       args.out_args[0] = 0;
-       args.num_out_args = read_arg ? 1 : 0;
-       args.flags = read_arg ? SMU_MSG_FLAG_FORCE_READ_ARG : 0;
-       args.timeout = 0;
-
-       ret = ctl->ops->send_msg(ctl, &args);
+       param = ((argument & 0xFFFF) << 16) | (table_id & 0xffff);
 
-       if (read_arg)
-               *read_arg = args.out_args[0];
+       ret = smu_cmn_send_smc_msg_with_params_ext(
+               smu,
+               drv2smu ? SMU_MSG_TransferTableDram2Smu :
+                         SMU_MSG_TransferTableSmu2Dram,
+               &param, 1, read_arg, read_arg ? 1 : 0,
+               read_arg ? SMU_MSG_FLAG_FORCE_READ_ARG : 0, 0);
 
        if (ret)
                return ret;
index c6ac0e876aeabee9072b3dee7d4ee1a4ae32329c..0e119965ce13110ce64067a7e571ec078d2438a1 100644 (file)
@@ -118,6 +118,28 @@ int smu_cmn_send_smc_msg_with_param(struct smu_context *smu,
                                    uint32_t param,
                                    uint32_t *read_arg);
 
+int smu_cmn_send_smc_msg_with_params_ext(struct smu_context *smu,
+                                        enum smu_message_type msg,
+                                        const uint32_t *params,
+                                        size_t num_params,
+                                        uint32_t *read_args,
+                                        size_t num_read_args,
+                                        uint32_t flags,
+                                        uint32_t timeout);
+
+static inline int smu_cmn_send_smc_msg_with_params(struct smu_context *smu,
+                                                  enum smu_message_type msg,
+                                                  const uint32_t *params,
+                                                  size_t num_params,
+                                                  uint32_t *read_args,
+                                                  size_t num_read_args)
+{
+       return smu_cmn_send_smc_msg_with_params_ext(smu, msg,
+                                                   params, num_params,
+                                                   read_args, num_read_args,
+                                                   0, 0);
+}
+
 int smu_cmn_send_smc_msg(struct smu_context *smu,
                         enum smu_message_type msg,
                         uint32_t *read_arg);