diff mbox series

[5/8] ASoC: SOF: sof-client: Add support IPC4 message sending

Message ID 20220506132647.18690-6-peter.ujfalusi@linux.intel.com (mailing list archive)
State Accepted
Commit 100c9374318f881c3083573af9dc76afa229fd23
Headers show
Series ASoC: SOF: sof-client: Update for different IPC versions | expand

Commit Message

Peter Ujfalusi May 6, 2022, 1:26 p.m. UTC
In order to be able to send an IPC4 message, the
sof_client_ipc_tx_message() needs to parse the tx message differently to
extract the size.

The IPC notification registration is done by providing the notification
type and the whole message is passed to the client when a match is found.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
---
 sound/soc/sof/sof-client.c | 47 +++++++++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/sof/sof-client.c b/sound/soc/sof/sof-client.c
index ce002815aa44..a664e0eb81fe 100644
--- a/sound/soc/sof/sof-client.c
+++ b/sound/soc/sof/sof-client.c
@@ -12,6 +12,7 @@ 
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
+#include <sound/sof/ipc4/header.h>
 #include "ops.h"
 #include "sof-client.h"
 #include "sof-priv.h"
@@ -245,10 +246,19 @@  EXPORT_SYMBOL_NS_GPL(sof_client_dev_unregister, SND_SOC_SOF_CLIENT);
 int sof_client_ipc_tx_message(struct sof_client_dev *cdev, void *ipc_msg,
 			      void *reply_data, size_t reply_bytes)
 {
-	struct sof_ipc_cmd_hdr *hdr = ipc_msg;
+	if (cdev->sdev->pdata->ipc_type == SOF_IPC) {
+		struct sof_ipc_cmd_hdr *hdr = ipc_msg;
 
-	return sof_ipc_tx_message(cdev->sdev->ipc, ipc_msg, hdr->size,
-				  reply_data, reply_bytes);
+		return sof_ipc_tx_message(cdev->sdev->ipc, ipc_msg, hdr->size,
+					  reply_data, reply_bytes);
+	} else if (cdev->sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
+		struct sof_ipc4_msg *msg = ipc_msg;
+
+		return sof_ipc_tx_message(cdev->sdev->ipc, ipc_msg, msg->data_size,
+					  reply_data, reply_bytes);
+	}
+
+	return -EINVAL;
 }
 EXPORT_SYMBOL_NS_GPL(sof_client_ipc_tx_message, SND_SOC_SOF_CLIENT);
 
@@ -358,9 +368,22 @@  EXPORT_SYMBOL_NS_GPL(sof_client_core_module_put, SND_SOC_SOF_CLIENT);
 /* IPC event handling */
 void sof_client_ipc_rx_dispatcher(struct snd_sof_dev *sdev, void *msg_buf)
 {
-	struct sof_ipc_cmd_hdr *hdr = msg_buf;
-	u32 msg_type = hdr->cmd & SOF_GLB_TYPE_MASK;
 	struct sof_ipc_event_entry *event;
+	u32 msg_type;
+
+	if (sdev->pdata->ipc_type == SOF_IPC) {
+		struct sof_ipc_cmd_hdr *hdr = msg_buf;
+
+		msg_type = hdr->cmd & SOF_GLB_TYPE_MASK;
+	} else if (sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
+		struct sof_ipc4_msg *msg = msg_buf;
+
+		msg_type = SOF_IPC4_NOTIFICATION_TYPE_GET(msg->primary);
+	} else {
+		dev_dbg_once(sdev->dev, "%s: Not supported IPC version: %d\n",
+			     __func__, sdev->pdata->ipc_type);
+		return;
+	}
 
 	mutex_lock(&sdev->client_event_handler_mutex);
 
@@ -379,9 +402,21 @@  int sof_client_register_ipc_rx_handler(struct sof_client_dev *cdev,
 	struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
 	struct sof_ipc_event_entry *event;
 
-	if (!callback || !(ipc_msg_type & SOF_GLB_TYPE_MASK))
+	if (!callback)
 		return -EINVAL;
 
+	if (cdev->sdev->pdata->ipc_type == SOF_IPC) {
+		if (!(ipc_msg_type & SOF_GLB_TYPE_MASK))
+			return -EINVAL;
+	} else if (cdev->sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
+		if (!(ipc_msg_type & SOF_IPC4_NOTIFICATION_TYPE_MASK))
+			return -EINVAL;
+	} else {
+		dev_warn(sdev->dev, "%s: Not supported IPC version: %d\n",
+			 __func__, sdev->pdata->ipc_type);
+		return -EINVAL;
+	}
+
 	event = kmalloc(sizeof(*event), GFP_KERNEL);
 	if (!event)
 		return -ENOMEM;