ASoC: SOF: ipc4: Handle ALSA kcontrol change notification from firmware
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Fri, 24 Nov 2023 15:08:53 +0000 (17:08 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 24 Nov 2023 15:38:01 +0000 (15:38 +0000)
The control change notification is sent as module notification with a
standardized event_id (higher 16 bit is 0xA15A).
Add generic code to handle the module notification and invoke the control
update callback if the notification is an ALSA kcontrol change message.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20231124150853.18648-5-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc4.c

index 8441f4ae4065682d4dbe55768768e662daabd781..a9d9800d2fcc9876f5b2ffc55c178c49f475522a 100644 (file)
@@ -78,6 +78,9 @@ static const struct sof_ipc4_fw_status {
        {165, "Reserved (ADSP_IPC_PIPELINE_ALREADY_EXISTS removed)"},
 };
 
+typedef void (*ipc4_notification_handler)(struct snd_sof_dev *sdev,
+                                         struct sof_ipc4_msg *msg);
+
 static int sof_ipc4_check_reply_status(struct snd_sof_dev *sdev, u32 status)
 {
        int i, ret;
@@ -610,9 +613,55 @@ static int ipc4_fw_ready(struct snd_sof_dev *sdev, struct sof_ipc4_msg *ipc4_msg
        return sof_ipc4_init_msg_memory(sdev);
 }
 
+static void sof_ipc4_module_notification_handler(struct snd_sof_dev *sdev,
+                                                struct sof_ipc4_msg *ipc4_msg)
+{
+       struct sof_ipc4_notify_module_data *data = ipc4_msg->data_ptr;
+
+       /*
+        * If the notification includes additional, module specific data, then
+        * we need to re-allocate the buffer and re-read the whole payload,
+        * including the event_data
+        */
+       if (data->event_data_size) {
+               void *new;
+               int ret;
+
+               ipc4_msg->data_size += data->event_data_size;
+
+               new = krealloc(ipc4_msg->data_ptr, ipc4_msg->data_size, GFP_KERNEL);
+               if (!new) {
+                       ipc4_msg->data_size -= data->event_data_size;
+                       return;
+               }
+
+               /* re-read the whole payload */
+               ipc4_msg->data_ptr = new;
+               ret = snd_sof_ipc_msg_data(sdev, NULL, ipc4_msg->data_ptr,
+                                          ipc4_msg->data_size);
+               if (ret < 0) {
+                       dev_err(sdev->dev,
+                               "Failed to read the full module notification: %d\n",
+                               ret);
+                       return;
+               }
+               data = ipc4_msg->data_ptr;
+       }
+
+       /* Handle ALSA kcontrol notification */
+       if ((data->event_id & SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_MASK) ==
+           SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL) {
+               const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
+
+               if (tplg_ops->control->update)
+                       tplg_ops->control->update(sdev, ipc4_msg);
+       }
+}
+
 static void sof_ipc4_rx_msg(struct snd_sof_dev *sdev)
 {
        struct sof_ipc4_msg *ipc4_msg = sdev->ipc->msg.rx_data;
+       ipc4_notification_handler handler_func = NULL;
        size_t data_size = 0;
        int err;
 
@@ -648,6 +697,10 @@ static void sof_ipc4_rx_msg(struct snd_sof_dev *sdev)
        case SOF_IPC4_NOTIFY_EXCEPTION_CAUGHT:
                snd_sof_dsp_panic(sdev, 0, true);
                break;
+       case SOF_IPC4_NOTIFY_MODULE_NOTIFICATION:
+               data_size = sizeof(struct sof_ipc4_notify_module_data);
+               handler_func = sof_ipc4_module_notification_handler;
+               break;
        default:
                dev_dbg(sdev->dev, "Unhandled DSP message: %#x|%#x\n",
                        ipc4_msg->primary, ipc4_msg->extension);
@@ -663,6 +716,10 @@ static void sof_ipc4_rx_msg(struct snd_sof_dev *sdev)
                snd_sof_ipc_msg_data(sdev, NULL, ipc4_msg->data_ptr, ipc4_msg->data_size);
        }
 
+       /* Handle notifications with payload */
+       if (handler_func)
+               handler_func(sdev, ipc4_msg);
+
        sof_ipc4_log_header(sdev->dev, "ipc rx done ", ipc4_msg, true);
 
        if (data_size) {