ASoC: SOF: IPC4: Add helper for looking up module by UUID
authorPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Thu, 20 Oct 2022 12:12:29 +0000 (15:12 +0300)
committerMark Brown <broonie@kernel.org>
Fri, 21 Oct 2022 12:05:02 +0000 (13:05 +0100)
Add a simple helper to walk the loaded libraries and their modules to make
the ipc4-topology not aware of the underlying infrastructure and simplify
the code.

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>
Reviewed-by: Chao Song <chao.song@intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20221020121238.18339-11-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc4-loader.c
sound/soc/sof/ipc4-priv.h
sound/soc/sof/ipc4-topology.c

index 5506ec997328a6946e5df1c1411dc6b5a27ba75d..b7e8b3f3d4f0af109685ec69749a8aae82e79612 100644 (file)
@@ -160,6 +160,27 @@ static size_t sof_ipc4_fw_parse_basefw_ext_man(struct snd_sof_dev *sdev)
        return payload_offset;
 }
 
+struct sof_ipc4_fw_module *sof_ipc4_find_module_by_uuid(struct snd_sof_dev *sdev,
+                                                       const guid_t *uuid)
+{
+       struct sof_ipc4_fw_data *ipc4_data = sdev->private;
+       struct sof_ipc4_fw_library *fw_lib;
+       unsigned long lib_id;
+       int i;
+
+       if (guid_is_null(uuid))
+               return NULL;
+
+       xa_for_each(&ipc4_data->fw_lib_xa, lib_id, fw_lib) {
+               for (i = 0; i < fw_lib->num_modules; i++) {
+                       if (guid_equal(uuid, &fw_lib->modules[i].man4_module_entry.uuid))
+                               return &fw_lib->modules[i];
+               }
+       }
+
+       return NULL;
+}
+
 static int sof_ipc4_validate_firmware(struct snd_sof_dev *sdev)
 {
        struct sof_ipc4_fw_data *ipc4_data = sdev->private;
index bce168083f09c9e21b189f54cbbd0b34183efb81..ecfa9f701ef119694485da2d9e1fc9e7612b1368 100644 (file)
@@ -84,4 +84,7 @@ extern const struct sof_ipc_fw_tracing_ops ipc4_mtrace_ops;
 
 int sof_ipc4_set_pipeline_state(struct snd_sof_dev *sdev, u32 id, u32 state);
 int sof_ipc4_mtrace_update_pos(struct snd_sof_dev *sdev, int core);
+
+struct sof_ipc4_fw_module *sof_ipc4_find_module_by_uuid(struct snd_sof_dev *sdev,
+                                                       const guid_t *uuid);
 #endif
index 98f7f5421ba58cec717e2846b82c5d0305246dd3..ab85dde4303be58b3d7c24f866f1b08c0718e295 100644 (file)
@@ -289,22 +289,11 @@ static int sof_ipc4_widget_set_module_info(struct snd_sof_widget *swidget)
 {
        struct snd_soc_component *scomp = swidget->scomp;
        struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
-       struct sof_ipc4_fw_data *ipc4_data = sdev->private;
-       struct sof_ipc4_fw_library *fw_lib;
-       unsigned long lib_id;
-       int i;
 
-       xa_for_each(&ipc4_data->fw_lib_xa, lib_id, fw_lib) {
-               /* set module info */
-               for (i = 0; i < fw_lib->num_modules; i++) {
-                       struct sof_ipc4_fw_module *module = &fw_lib->modules[i];
+       swidget->module_info = sof_ipc4_find_module_by_uuid(sdev, &swidget->uuid);
 
-                       if (guid_equal(&swidget->uuid, &module->man4_module_entry.uuid)) {
-                               swidget->module_info = module;
-                               return 0;
-                       }
-               }
-       }
+       if (swidget->module_info)
+               return 0;
 
        dev_err(sdev->dev, "failed to find module info for widget %s with UUID %pUL\n",
                swidget->widget->name, &swidget->uuid);