From e6ebda860ee68c1b48bb3878d6ccb10c22b94e14 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 14 Dec 2021 12:55:36 +0200 Subject: [PATCH 1/6] ASoC: SOF: ipc4: Check sizes early in sof_ipc4_tx_message_unlocked The message and reply size can be checked earlier to fail early in case the requested size can not be sent due to it's length. Signed-off-by: Peter Ujfalusi --- sound/soc/sof/ipc4.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sound/soc/sof/ipc4.c b/sound/soc/sof/ipc4.c index 5e975b7d935eac..89484187e4d3b5 100644 --- a/sound/soc/sof/ipc4.c +++ b/sound/soc/sof/ipc4.c @@ -127,6 +127,9 @@ static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, if (ipc->disable_ipc_tx || sdev->fw_state != SOF_FW_BOOT_COMPLETE) return -ENODEV; + if (msg_bytes > ipc->max_payload_size || reply_bytes > ipc->max_payload_size) + return -EINVAL; + /* * The spin-lock is also still needed to protect message objects against * other atomic contexts. @@ -136,18 +139,13 @@ static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, /* initialise the message */ msg = &ipc->msg; + /* attach any data */ msg->header = header; msg->extension = extension; msg->msg_size = msg_bytes; msg->reply_size = reply_bytes; msg->reply_error = 0; - /* attach any data */ - if (msg_bytes > ipc->max_payload_size || reply_bytes > ipc->max_payload_size) { - spin_unlock_irq(&sdev->ipc_lock); - return -EINVAL; - } - memcpy(msg->msg_data, msg_data, msg_bytes); sdev->msg = msg; From 6244c43d151df9b2f5777779a068443b35318917 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 14 Dec 2021 13:00:05 +0200 Subject: [PATCH 2/6] ASoC: SOF: ipc4: Do not allocate buffer for msg_data The sof_ipc4_tx_message (and _unlocked) does not have support for async operations. There is no need to allocate a buffer and copy each message to it to be sent to the DSP, we can use the passed message data pointer directly. Signed-off-by: Peter Ujfalusi --- sound/soc/sof/ipc4.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sound/soc/sof/ipc4.c b/sound/soc/sof/ipc4.c index 89484187e4d3b5..b05af758a5695f 100644 --- a/sound/soc/sof/ipc4.c +++ b/sound/soc/sof/ipc4.c @@ -142,12 +142,11 @@ static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, /* attach any data */ msg->header = header; msg->extension = extension; + msg->msg_data = msg_data; msg->msg_size = msg_bytes; msg->reply_size = reply_bytes; msg->reply_error = 0; - memcpy(msg->msg_data, msg_data, msg_bytes); - sdev->msg = msg; ret = snd_sof_dsp_send_msg(sdev, msg); @@ -221,11 +220,6 @@ int sof_ipc4_init_msg_memory(struct snd_sof_dev *sdev) /* TODO: get max_payload_size from firmware */ sdev->ipc->max_payload_size = SOF_IPC4_MSG_MAX_SIZE; - msg->msg_data = devm_kzalloc(sdev->dev, sdev->ipc->max_payload_size, - GFP_KERNEL); - if (!msg->msg_data) - return -ENOMEM; - msg->reply_data = devm_kzalloc(sdev->dev, sdev->ipc->max_payload_size, GFP_KERNEL); if (!msg->reply_data) From 2173f18af3cad65df3ac5495b72ab8034702ac3c Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 14 Dec 2021 13:38:31 +0200 Subject: [PATCH 3/6] ASoC: SOF: ipc4: Add structure to describe an IPC4 message The struct sof_ipc4_msg encapsulates an IPC4 message for easier handling. In IPC4 the header (u64) is treated differently compared to IPC3. IPC4 gives the option that the header can bypass the mailbox memory where only the optional data part of the message is sent. Signed-off-by: Peter Ujfalusi --- include/sound/sof/ipc4/header.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/sound/sof/ipc4/header.h b/include/sound/sof/ipc4/header.h index 79da9280a21de3..97faa0ed0e4832 100644 --- a/include/sound/sof/ipc4/header.h +++ b/include/sound/sof/ipc4/header.h @@ -17,6 +17,28 @@ * @{ */ +/** + * struct sof_ipc4_msg - Placeholder of an IPC4 message + * @header_u64: IPC4 header as single u64 number + * @primary: Primary, mandatory part of the header + * @extension: Extended part of the header, if not used it should be + * set to 0 + * @data_size: Size of data in bytes pointed by @data_ptr + * @data_ptr: Pointer to the optional payload of a message + */ +struct sof_ipc4_msg { + union { + u64 header_u64; + struct { + u32 primary; + u32 extension; + }; + }; + + size_t data_size; + void *data_ptr; +}; + /* * IPC4 messages have two 32 bit identifier made up as follows :- * From 428be23c4dbe5f51133a87cc211d48a51514c7d1 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 15 Dec 2021 14:42:06 +0200 Subject: [PATCH 4/6] ASoC: SOF: ipc4: Require struct sof_ipc4_msg for message tx and rx IPC4 related code must use the struct sof_ipc4_msg to pass the message to be sent to the firmware. Similarly on message reception, the platform code must make sure that the ipc4 message container is updated before calling the handler. For message sending the msg_data is mandatory and must point to the ipc4 message container while the msg_bytes is the size of the optional data part of the message (data_bytes == ipc4_msg->data_size). On message reception, platform code is responsible to update the ipc4 struct's header (primary and extension) before calling the handler. Signed-off-by: Peter Ujfalusi --- sound/soc/sof/ipc4.c | 36 ++++++++++++++++++++++-------------- sound/soc/sof/sof-priv.h | 7 +++---- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/sound/soc/sof/ipc4.c b/sound/soc/sof/ipc4.c index b05af758a5695f..3479a7b3f13d2c 100644 --- a/sound/soc/sof/ipc4.c +++ b/sound/soc/sof/ipc4.c @@ -97,6 +97,7 @@ EXPORT_SYMBOL(sof_ipc4_process_reply); static int ipc4_tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg, void *reply_data) { + struct sof_ipc4_msg *ipc4_msg = msg->msg_data; struct snd_sof_dev *sdev = ipc->sdev; int ret; @@ -105,19 +106,19 @@ static int ipc4_tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *ms msecs_to_jiffies(sdev->ipc_timeout)); if (ret == 0) { dev_err(sdev->dev, "ipc timed out for header:0x%x extension:0x%x", - msg->header, msg->extension); + ipc4_msg->primary, ipc4_msg->extension); return -ETIMEDOUT; } else if (msg->reply_error) { dev_err(sdev->dev, "ipc error for msg 0x%x : 0x%x\n", - msg->header, msg->extension); + ipc4_msg->primary, ipc4_msg->extension); return -EIO; } return 0; } -static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, - u32 extension, void *msg_data, size_t msg_bytes, +static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, + void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes) { struct snd_sof_dev *sdev = ipc->sdev; @@ -140,8 +141,6 @@ static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, msg = &ipc->msg; /* attach any data */ - msg->header = header; - msg->extension = extension; msg->msg_data = msg_data; msg->msg_size = msg_bytes; msg->reply_size = reply_bytes; @@ -165,16 +164,19 @@ static int sof_ipc4_tx_message_unlocked(struct snd_sof_ipc *ipc, u32 header, return ipc4_tx_wait_done(ipc, msg, reply_data); } -int sof_ipc4_tx_message(struct snd_sof_ipc *ipc, u32 header, u32 extension, +int sof_ipc4_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes) { int ret; + if (!msg_data) + return -EINVAL; + /* Serialise IPC TX */ mutex_lock(&ipc->tx_mutex); - ret = sof_ipc4_tx_message_unlocked(ipc, header, extension, msg_data, msg_bytes, + ret = sof_ipc4_tx_message_unlocked(ipc, msg_data, msg_bytes, reply_data, reply_bytes); mutex_unlock(&ipc->tx_mutex); @@ -183,18 +185,19 @@ int sof_ipc4_tx_message(struct snd_sof_ipc *ipc, u32 header, u32 extension, } EXPORT_SYMBOL(sof_ipc4_tx_message); -void snd_sof_ipc4_msgs_rx(struct snd_sof_dev *sdev, u32 msg, u32 msg_ext) +void snd_sof_ipc4_msgs_rx(struct snd_sof_dev *sdev) { + struct sof_ipc4_msg *ipc4_msg = sdev->ipc->msg.reply_data; int err; - if (!SOF_IPC4_GLB_NOTIFY_MSG_TYPE(msg)) + if (!SOF_IPC4_GLB_NOTIFY_MSG_TYPE(ipc4_msg->primary)) return; - switch (SOF_IPC4_GLB_NOTIFY_TYPE(msg)) { + switch (SOF_IPC4_GLB_NOTIFY_TYPE(ipc4_msg->primary)) { case SOF_IPC4_GLB_NOTIFY_FW_READY: /* check for FW boot completion */ if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS) { - err = sof_ops(sdev)->fw_ready(sdev, msg); + err = sof_ops(sdev)->fw_ready(sdev, ipc4_msg->primary); if (err < 0) sof_set_fw_state(sdev, SOF_FW_BOOT_READY_FAILED); else @@ -213,6 +216,7 @@ EXPORT_SYMBOL(snd_sof_ipc4_msgs_rx); int sof_ipc4_init_msg_memory(struct snd_sof_dev *sdev) { + struct sof_ipc4_msg *ipc4_msg; struct snd_sof_ipc_msg *msg; msg = &sdev->ipc->msg; @@ -220,11 +224,15 @@ int sof_ipc4_init_msg_memory(struct snd_sof_dev *sdev) /* TODO: get max_payload_size from firmware */ sdev->ipc->max_payload_size = SOF_IPC4_MSG_MAX_SIZE; - msg->reply_data = devm_kzalloc(sdev->dev, sdev->ipc->max_payload_size, - GFP_KERNEL); + /* Allocate memory for the ipc4 container and the maximum payload */ + msg->reply_data = devm_kzalloc(sdev->dev, sdev->ipc->max_payload_size + + sizeof(struct sof_ipc4_msg), GFP_KERNEL); if (!msg->reply_data) return -ENOMEM; + ipc4_msg = msg->reply_data; + ipc4_msg->data_ptr = msg->reply_data + sizeof(struct sof_ipc4_msg); + /* * TODO: Currently we are not able to wake DSP up once it is suspended. * Calling pm_runtime_get_sync() here to prevent it from entering diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 7cbc393e1692bb..34df7dd814a5e4 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -577,14 +577,13 @@ void snd_sof_ipc_free(struct snd_sof_dev *sdev); void snd_sof_ipc_get_reply(struct snd_sof_dev *sdev); void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id); void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev); -void snd_sof_ipc4_msgs_rx(struct snd_sof_dev *sdev, u32 msg, u32 msg_ext); +void snd_sof_ipc4_msgs_rx(struct snd_sof_dev *sdev); int snd_sof_ipc_valid(struct snd_sof_dev *sdev); int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header, void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes); -int sof_ipc4_tx_message(struct snd_sof_ipc *ipc, u32 header, u32 extension, - void *msg_data, size_t msg_bytes, void *reply_data, - size_t reply_bytes); +int sof_ipc4_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, + void *reply_data, size_t reply_bytes); int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header, void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes); From 17ebb66744c303b3e2ea810052721eaebe97933d Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 15 Dec 2021 15:13:28 +0200 Subject: [PATCH 5/6] ASoC: SOF: Drop 'header' parameter from tx_message() API The header parameter is not used anymore and now it can be dropped from the parameter list of tx_message(). Signed-off-by: Peter Ujfalusi --- sound/soc/sof/debug.c | 2 +- sound/soc/sof/intel/hda-dsp.c | 8 +++----- sound/soc/sof/intel/tgl.c | 6 ++---- sound/soc/sof/ipc.c | 18 +++++++----------- sound/soc/sof/ipc3-pcm.c | 8 +++----- sound/soc/sof/ipc3-topology.c | 25 +++++++++++-------------- sound/soc/sof/ipc3.c | 4 ++-- sound/soc/sof/sof-client.c | 2 +- sound/soc/sof/sof-priv.h | 8 +++----- sound/soc/sof/trace.c | 9 +++------ 10 files changed, 36 insertions(+), 54 deletions(-) diff --git a/sound/soc/sof/debug.c b/sound/soc/sof/debug.c index 7b1139961a99aa..8a77245b51825f 100644 --- a/sound/soc/sof/debug.c +++ b/sound/soc/sof/debug.c @@ -236,7 +236,7 @@ static int memory_info_update(struct snd_sof_dev *sdev, char *buf, size_t buff_s goto error; } - ret = sof_ipc_tx_message(sdev->ipc, msg.cmd, &msg, msg.size, reply, SOF_IPC_MSG_MAX_SIZE); + ret = sof_ipc_tx_message(sdev->ipc, &msg, msg.size, reply, SOF_IPC_MSG_MAX_SIZE); pm_runtime_mark_last_busy(sdev->dev); pm_runtime_put_autosuspend(sdev->dev); if (ret < 0 || reply->rhdr.error < 0) { diff --git a/sound/soc/sof/intel/hda-dsp.c b/sound/soc/sof/intel/hda-dsp.c index 8ddde60c56b3f5..ad11df345be75d 100644 --- a/sound/soc/sof/intel/hda-dsp.c +++ b/sound/soc/sof/intel/hda-dsp.c @@ -363,9 +363,8 @@ static int hda_dsp_send_pm_gate_ipc(struct snd_sof_dev *sdev, u32 flags) pm_gate.flags = flags; /* send pm_gate ipc to dsp */ - return sof_ipc_tx_message_no_pm(sdev->ipc, pm_gate.hdr.cmd, - &pm_gate, sizeof(pm_gate), &reply, - sizeof(reply)); + return sof_ipc_tx_message_no_pm(sdev->ipc, &pm_gate, sizeof(pm_gate), + &reply, sizeof(reply)); } static int hda_dsp_update_d0i3c_register(struct snd_sof_dev *sdev, u8 value) @@ -985,8 +984,7 @@ int hda_dsp_core_get(struct snd_sof_dev *sdev, int core) return 0; /* Now notify DSP for secondary cores */ - ret = sof_ipc_tx_message(sdev->ipc, pm_core_config.hdr.cmd, - &pm_core_config, sizeof(pm_core_config), + ret = sof_ipc_tx_message(sdev->ipc, &pm_core_config, sizeof(pm_core_config), &pm_core_config, sizeof(pm_core_config)); if (ret < 0) { dev_err(sdev->dev, "failed to enable secondary core '%d' failed with %d\n", diff --git a/sound/soc/sof/intel/tgl.c b/sound/soc/sof/intel/tgl.c index cb1c319d5bee6f..72d92ff6cef5a8 100644 --- a/sound/soc/sof/intel/tgl.c +++ b/sound/soc/sof/intel/tgl.c @@ -35,8 +35,7 @@ static int tgl_dsp_core_get(struct snd_sof_dev *sdev, int core) return hda_dsp_enable_core(sdev, BIT(core)); /* notify DSP for secondary cores */ - return sof_ipc_tx_message(sdev->ipc, pm_core_config.hdr.cmd, - &pm_core_config, sizeof(pm_core_config), + return sof_ipc_tx_message(sdev->ipc, &pm_core_config, sizeof(pm_core_config), &pm_core_config, sizeof(pm_core_config)); } @@ -55,8 +54,7 @@ static int tgl_dsp_core_put(struct snd_sof_dev *sdev, int core) return hda_dsp_core_reset_power_down(sdev, BIT(core)); /* notify DSP for secondary cores */ - return sof_ipc_tx_message(sdev->ipc, pm_core_config.hdr.cmd, - &pm_core_config, sizeof(pm_core_config), + return sof_ipc_tx_message(sdev->ipc, &pm_core_config, sizeof(pm_core_config), &pm_core_config, sizeof(pm_core_config)); } diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index 4e1d566ee99568..3cdf779383abcd 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -341,9 +341,8 @@ static int sof_ipc_tx_message_unlocked(struct snd_sof_ipc *ipc, } /* send IPC message from host to DSP */ -int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header, - void *msg_data, size_t msg_bytes, void *reply_data, - size_t reply_bytes) +int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, + void *reply_data, size_t reply_bytes) { const struct sof_dsp_power_state target_state = { .state = SOF_DSP_PM_D0, @@ -357,7 +356,7 @@ int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header, return ret; } - return sof_ipc_tx_message_no_pm(ipc, header, msg_data, msg_bytes, + return sof_ipc_tx_message_no_pm(ipc, msg_data, msg_bytes, reply_data, reply_bytes); } EXPORT_SYMBOL(sof_ipc_tx_message); @@ -367,8 +366,7 @@ EXPORT_SYMBOL(sof_ipc_tx_message); * This will be used for IPC's that can be handled by the DSP * even in a low-power D0 substate. */ -int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header, - void *msg_data, size_t msg_bytes, +int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes) { int ret; @@ -701,8 +699,7 @@ int snd_sof_ipc_stream_posn(struct snd_soc_component *scomp, stream.comp_id = spcm->stream[direction].comp_id; /* send IPC to the DSP */ - err = sof_ipc_tx_message(sdev->ipc, - stream.hdr.cmd, &stream, sizeof(stream), posn, + err = sof_ipc_tx_message(sdev->ipc, &stream, sizeof(stream), posn, sizeof(*posn)); if (err < 0) { dev_err(sdev->dev, "error: failed to get stream %d position\n", @@ -893,9 +890,8 @@ int snd_sof_ipc_set_get_comp_data(struct snd_sof_control *scontrol, bool set) /* send normal size ipc in one part */ if (cdata->rhdr.hdr.size <= SOF_IPC_MSG_MAX_SIZE) { - err = sof_ipc_tx_message(sdev->ipc, cdata->rhdr.hdr.cmd, cdata, - cdata->rhdr.hdr.size, cdata, - cdata->rhdr.hdr.size); + err = sof_ipc_tx_message(sdev->ipc, cdata, cdata->rhdr.hdr.size, + cdata, cdata->rhdr.hdr.size); if (err < 0) dev_err(sdev->dev, "error: set/get ctrl ipc comp %d\n", diff --git a/sound/soc/sof/ipc3-pcm.c b/sound/soc/sof/ipc3-pcm.c index 030fe3ff657a96..89a294abe1d928 100644 --- a/sound/soc/sof/ipc3-pcm.c +++ b/sound/soc/sof/ipc3-pcm.c @@ -34,8 +34,7 @@ static int sof_ipc3_pcm_hw_free(struct snd_soc_component *component, stream.comp_id = spcm->stream[substream->stream].comp_id; /* send IPC to the DSP */ - return sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, - sizeof(stream), &reply, sizeof(reply)); + return sof_ipc_tx_message(sdev->ipc, &stream, sizeof(stream), &reply, sizeof(reply)); } static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component, @@ -119,7 +118,7 @@ static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component, dev_dbg(component->dev, "stream_tag %d", pcm.params.stream_tag); /* send hw_params IPC to the DSP */ - ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm), + ret = sof_ipc_tx_message(sdev->ipc, &pcm, sizeof(pcm), &ipc_params_reply, sizeof(ipc_params_reply)); if (ret < 0) { dev_err(component->dev, "HW params ipc failed for stream %d\n", @@ -175,8 +174,7 @@ static int sof_ipc3_pcm_trigger(struct snd_soc_component *component, } /* send IPC to the DSP */ - return sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, - sizeof(stream), &reply, sizeof(reply)); + return sof_ipc_tx_message(sdev->ipc, &stream, sizeof(stream), &reply, sizeof(reply)); } static void ssp_dai_config_pcm_params_match(struct snd_sof_dev *sdev, const char *link_name, diff --git a/sound/soc/sof/ipc3-topology.c b/sound/soc/sof/ipc3-topology.c index 50348a0794edc2..95599aa8cf0b2a 100644 --- a/sound/soc/sof/ipc3-topology.c +++ b/sound/soc/sof/ipc3-topology.c @@ -1556,8 +1556,7 @@ static int sof_ipc3_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route * sroute->sink_widget->widget->name); /* send ipc */ - ret = sof_ipc_tx_message(sdev->ipc, connect.hdr.cmd, &connect, sizeof(connect), - &reply, sizeof(reply)); + ret = sof_ipc_tx_message(sdev->ipc, &connect, sizeof(connect), &reply, sizeof(reply)); if (ret < 0) dev_err(sdev->dev, "%s: route %s -> %s failed\n", __func__, sroute->src_widget->widget->name, sroute->sink_widget->widget->name); @@ -1702,7 +1701,7 @@ static int sof_ipc3_control_free(struct snd_sof_dev *sdev, struct snd_sof_contro fcomp.id = scontrol->comp_id; /* send IPC to the DSP */ - return sof_ipc_tx_message(sdev->ipc, fcomp.hdr.cmd, &fcomp, sizeof(fcomp), NULL, 0); + return sof_ipc_tx_message(sdev->ipc, &fcomp, sizeof(fcomp), NULL, 0); } /* send pcm params ipc */ @@ -1754,7 +1753,7 @@ static int sof_ipc3_keyword_detect_pcm_params(struct snd_sof_widget *swidget, in } /* send IPC to the DSP */ - ret = sof_ipc_tx_message(sdev->ipc, pcm.hdr.cmd, &pcm, sizeof(pcm), + ret = sof_ipc_tx_message(sdev->ipc, &pcm, sizeof(pcm), &ipc_params_reply, sizeof(ipc_params_reply)); if (ret < 0) dev_err(scomp->dev, "%s: PCM params failed for %s\n", __func__, @@ -1778,8 +1777,7 @@ static int sof_ipc3_keyword_detect_trigger(struct snd_sof_widget *swidget, int c stream.comp_id = swidget->comp_id; /* send IPC to the DSP */ - ret = sof_ipc_tx_message(sdev->ipc, stream.hdr.cmd, &stream, - sizeof(stream), &reply, sizeof(reply)); + ret = sof_ipc_tx_message(sdev->ipc, &stream, sizeof(stream), &reply, sizeof(reply)); if (ret < 0) dev_err(scomp->dev, "%s: Failed to trigger %s\n", __func__, swidget->widget->name); @@ -1907,8 +1905,7 @@ static int sof_ipc3_complete_pipeline(struct snd_sof_dev *sdev, struct snd_sof_w ready.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_COMPLETE; ready.comp_id = swidget->comp_id; - ret = sof_ipc_tx_message(sdev->ipc, ready.hdr.cmd, &ready, sizeof(ready), &reply, - sizeof(reply)); + ret = sof_ipc_tx_message(sdev->ipc, &ready, sizeof(ready), &reply, sizeof(reply)); if (ret < 0) return ret; @@ -1944,7 +1941,7 @@ static int sof_ipc3_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget break; } - ret = sof_ipc_tx_message(sdev->ipc, ipc_free.hdr.cmd, &ipc_free, sizeof(ipc_free), + ret = sof_ipc_tx_message(sdev->ipc, &ipc_free, sizeof(ipc_free), &reply, sizeof(reply)); if (ret < 0) dev_err(sdev->dev, "failed to free widget %s\n", swidget->widget->name); @@ -1989,7 +1986,7 @@ static int sof_ipc3_dai_config(struct snd_sof_dev *sdev, struct snd_sof_widget * config->flags = flags; - ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, + ret = sof_ipc_tx_message(sdev->ipc, config, config->hdr.size, &reply, sizeof(reply)); if (ret < 0) dev_err(sdev->dev, "Failed to set dai config for %s\n", dai->name); @@ -2013,7 +2010,7 @@ static int sof_ipc3_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget struct sof_dai_private_data *dai_data = dai->private; struct sof_ipc_comp *comp = &dai_data->comp_dai->comp; - ret = sof_ipc_tx_message(sdev->ipc, comp->hdr.cmd, dai_data->comp_dai, + ret = sof_ipc_tx_message(sdev->ipc, dai_data->comp_dai, comp->hdr.size, &reply, sizeof(reply)); break; } @@ -2022,8 +2019,8 @@ static int sof_ipc3_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget struct sof_ipc_pipe_new *pipeline; pipeline = swidget->private; - ret = sof_ipc_tx_message(sdev->ipc, pipeline->hdr.cmd, pipeline, - sizeof(*pipeline), &reply, sizeof(reply)); + ret = sof_ipc_tx_message(sdev->ipc, pipeline, sizeof(*pipeline), + &reply, sizeof(reply)); break; } default: @@ -2031,7 +2028,7 @@ static int sof_ipc3_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget struct sof_ipc_cmd_hdr *hdr; hdr = swidget->private; - ret = sof_ipc_tx_message(sdev->ipc, hdr->cmd, swidget->private, hdr->size, + ret = sof_ipc_tx_message(sdev->ipc, swidget->private, hdr->size, &reply, sizeof(reply)); break; } diff --git a/sound/soc/sof/ipc3.c b/sound/soc/sof/ipc3.c index d9cdf940291bde..093f4cae1531b8 100644 --- a/sound/soc/sof/ipc3.c +++ b/sound/soc/sof/ipc3.c @@ -19,8 +19,8 @@ static int sof_ipc3_ctx_ipc(struct snd_sof_dev *sdev, int cmd) struct sof_ipc_reply reply; /* send ctx save ipc to dsp */ - return sof_ipc_tx_message(sdev->ipc, pm_ctx.hdr.cmd, &pm_ctx, - sizeof(pm_ctx), &reply, sizeof(reply)); + return sof_ipc_tx_message(sdev->ipc, &pm_ctx, sizeof(pm_ctx), + &reply, sizeof(reply)); } static int sof_ipc3_ctx_save(struct snd_sof_dev *sdev) diff --git a/sound/soc/sof/sof-client.c b/sound/soc/sof/sof-client.c index 90139049c6584a..8907ba81da3626 100644 --- a/sound/soc/sof/sof-client.c +++ b/sound/soc/sof/sof-client.c @@ -247,7 +247,7 @@ int sof_client_ipc_tx_message(struct sof_client_dev *cdev, void *ipc_msg, { struct sof_ipc_cmd_hdr *hdr = ipc_msg; - return sof_ipc_tx_message(cdev->sdev->ipc, hdr->cmd, ipc_msg, hdr->size, + return sof_ipc_tx_message(cdev->sdev->ipc, ipc_msg, hdr->size, reply_data, reply_bytes); } EXPORT_SYMBOL_NS_GPL(sof_client_ipc_tx_message, SND_SOC_SOF_CLIENT); diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 34df7dd814a5e4..a8ec82b90d9bc7 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -579,13 +579,11 @@ void snd_sof_ipc_reply(struct snd_sof_dev *sdev, u32 msg_id); void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev); void snd_sof_ipc4_msgs_rx(struct snd_sof_dev *sdev); int snd_sof_ipc_valid(struct snd_sof_dev *sdev); -int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header, - void *msg_data, size_t msg_bytes, void *reply_data, - size_t reply_bytes); +int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, + void *reply_data, size_t reply_bytes); int sof_ipc4_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes); -int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, u32 header, - void *msg_data, size_t msg_bytes, +int sof_ipc_tx_message_no_pm(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes, void *reply_data, size_t reply_bytes); int sof_ipc_init_msg_memory(struct snd_sof_dev *sdev); int sof_ipc4_init_msg_memory(struct snd_sof_dev *sdev); diff --git a/sound/soc/sof/trace.c b/sound/soc/sof/trace.c index 72c8afa2c1b4ea..1eff662d35f065 100644 --- a/sound/soc/sof/trace.c +++ b/sound/soc/sof/trace.c @@ -152,8 +152,7 @@ static int sof_ipc_trace_update_filter(struct snd_sof_dev *sdev, int num_elems, dev_err(sdev->dev, "error: enabling device failed: %d\n", ret); goto error; } - ret = sof_ipc_tx_message(sdev->ipc, msg->hdr.cmd, msg, msg->hdr.size, - &reply, sizeof(reply)); + ret = sof_ipc_tx_message(sdev->ipc, msg, msg->hdr.size, &reply, sizeof(reply)); pm_runtime_mark_last_busy(sdev->dev); pm_runtime_put_autosuspend(sdev->dev); @@ -423,9 +422,7 @@ static int snd_sof_enable_trace(struct snd_sof_dev *sdev) dev_dbg(sdev->dev, "%s: stream_tag: %d\n", __func__, params.stream_tag); /* send IPC to the DSP */ - ret = sof_ipc_tx_message(sdev->ipc, - params.hdr.cmd, ¶ms, sizeof(params), - &ipc_reply, sizeof(ipc_reply)); + ret = sof_ipc_tx_message(sdev->ipc, ¶ms, sizeof(params), &ipc_reply, sizeof(ipc_reply)); if (ret < 0) { dev_err(sdev->dev, "error: can't set params for DMA for trace %d\n", ret); @@ -567,7 +564,7 @@ static void snd_sof_release_trace(struct snd_sof_dev *sdev, bool only_stop) hdr.size = sizeof(hdr); hdr.cmd = SOF_IPC_GLB_TRACE_MSG | SOF_IPC_TRACE_DMA_FREE; - ret = sof_ipc_tx_message(sdev->ipc, hdr.cmd, &hdr, hdr.size, + ret = sof_ipc_tx_message(sdev->ipc, &hdr, hdr.size, &ipc_reply, sizeof(ipc_reply)); if (ret < 0) dev_err(sdev->dev, "DMA_TRACE_FREE failed with error: %d\n", ret); From 732697332f9e9523ab7242e7ce2be37914118112 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Thu, 16 Dec 2021 13:59:06 +0200 Subject: [PATCH 6/6] ASoC: SOF: Remove header and extension from struct snd_sof_ipc_msg Neither the header or the extension is used by the underlying code, they can be dropped from the snd_sof_ipc_msg struct. Signed-off-by: Peter Ujfalusi --- sound/soc/sof/sof-priv.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index a8ec82b90d9bc7..7b250c86453c66 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -347,8 +347,6 @@ struct snd_sof_mailbox { /* IPC message descriptor for host <-> DSP IO */ struct snd_sof_ipc_msg { /* message data */ - u32 header; - u32 extension; void *msg_data; void *reply_data; size_t msg_size;