From d220beeefe0b525023f4512c56d6dc0320f2b6f0 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Jul 2025 14:49:17 +0100 Subject: [PATCH 1/4] modules: adapter: move API_CALL macro to cadence header. API_CALL only used to wrap Cadence API calls so move to correct header. Signed-off-by: Liam Girdwood --- src/include/sof/audio/module_adapter/module/cadence.h | 8 ++++++++ src/include/sof/audio/module_adapter/module/generic.h | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/include/sof/audio/module_adapter/module/cadence.h b/src/include/sof/audio/module_adapter/module/cadence.h index 954594f80aa3..a4ad3d9482f8 100644 --- a/src/include/sof/audio/module_adapter/module/cadence.h +++ b/src/include/sof/audio/module_adapter/module/cadence.h @@ -32,6 +32,14 @@ extern xa_codec_func_t xa_sbc_dec; extern xa_codec_func_t xa_vorbis_dec; extern xa_codec_func_t xa_src_pp; +#define API_CALL(cd, cmd, sub_cmd, value, ret) \ + do { \ + ret = (cd)->api((cd)->self, \ + (cmd), \ + (sub_cmd), \ + (value)); \ + } while (0) + /*****************************************************************************/ /* Cadence private data types */ /*****************************************************************************/ diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index fb7f4ca02202..6a364da818f1 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -30,14 +30,6 @@ #define MAX_BLOB_SIZE 8192 #define MODULE_MAX_SOURCES 8 -#define API_CALL(cd, cmd, sub_cmd, value, ret) \ - do { \ - ret = (cd)->api((cd)->self, \ - (cmd), \ - (sub_cmd), \ - (value)); \ - } while (0) - #if CONFIG_IPC_MAJOR_4 #define IPC_MOD_CMD(v) #elif CONFIG_IPC_MAJOR_3 From dc941ddd48573ba3a0cecc9450ab12b4fe6fb1c3 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Jul 2025 15:59:22 +0100 Subject: [PATCH 2/4] modules: adapter: make max module sinks/source a Kconfig setting Currently max number of connected sources and sinks is hard coded. Make this Kconfig to support different connections counts and validate the count is within limits. Signed-off-by: Liam Girdwood --- src/audio/Kconfig | 7 +++++++ src/audio/module_adapter/module_adapter.c | 6 ++++++ src/include/module/module/base.h | 4 ++-- src/include/sof/audio/module_adapter/module/generic.h | 1 - 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/audio/Kconfig b/src/audio/Kconfig index 46e44c3b5236..8a1a81a3587c 100644 --- a/src/audio/Kconfig +++ b/src/audio/Kconfig @@ -72,6 +72,13 @@ config IPC4_GATEWAY host and DSP without using DMA: via memory window (audio payload) and IPC4 messages (set/get/flush commands). +config MODULE_MAX_CONNECTIONS + int "Module maximum number of connected sink/source modules" + default 8 + help + Specifies the maximum number of sink and source connections a module + may have to other modules. + rsource "up_down_mixer/Kconfig" config COMP_BLOB diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 7311bbcf87e9..30926bfe02cf 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -272,6 +272,12 @@ int module_adapter_prepare(struct comp_dev *dev) comp_err(dev, "module_adapter_prepare(): no source and sink buffers connected!"); return -EINVAL; } + if (mod->num_of_sources > CONFIG_MODULE_MAX_CONNECTIONS || + mod->num_of_sinks > CONFIG_MODULE_MAX_CONNECTIONS) { + comp_err(dev, "module_adapter_prepare(): too many connected sinks %d or sources %d!", + mod->num_of_sinks, mod->num_of_sources); + return -EINVAL; + } /* check processing mode */ if (IS_PROCESSING_MODE_AUDIO_STREAM(mod) && mod->max_sources > 1 && mod->max_sinks > 1) { diff --git a/src/include/module/module/base.h b/src/include/module/module/base.h index f4da3252f4e3..5be7a5e2ef91 100644 --- a/src/include/module/module/base.h +++ b/src/include/module/module/base.h @@ -101,8 +101,8 @@ struct processing_module { uint32_t num_of_sinks; /* sink and source handlers for the module */ - struct sof_sink *sinks[MODULE_MAX_SOURCES]; - struct sof_source *sources[MODULE_MAX_SOURCES]; + struct sof_sink *sinks[CONFIG_MODULE_MAX_CONNECTIONS]; + struct sof_source *sources[CONFIG_MODULE_MAX_CONNECTIONS]; /* this is used in case of raw data or audio_stream mode * number of buffers described by fields: diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index 6a364da818f1..b98fa54f42a8 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -28,7 +28,6 @@ #define IS_PROCESSING_MODE_SINK_SOURCE(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_SOURCE_SINK) #define MAX_BLOB_SIZE 8192 -#define MODULE_MAX_SOURCES 8 #if CONFIG_IPC_MAJOR_4 #define IPC_MOD_CMD(v) From 391b2c7f73eb4ee853f8015884a2ae6678adf192 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Jul 2025 16:09:02 +0100 Subject: [PATCH 3/4] modules: blob size: add Kconfig for max module blob size Currently max blob size is hard coded. make it a kconfig so it can be tuned for needs. Signed-off-by: Liam Girdwood --- src/audio/Kconfig | 7 +++++++ src/audio/module_adapter/module/generic.c | 4 ++-- src/include/sof/audio/module_adapter/module/generic.h | 2 -- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/audio/Kconfig b/src/audio/Kconfig index 8a1a81a3587c..62dc9938b92b 100644 --- a/src/audio/Kconfig +++ b/src/audio/Kconfig @@ -89,6 +89,13 @@ config COMP_BLOB multiple IPC messages. Not all components or modules need this. If unsure, say yes. +config MODULE_MAX_BLOB_SIZE + int "Maximum IPC blob size in bytes" + default 8192 + help + Specify the maximum size of IPC4 module blob data that can be + appended to each message. + rsource "src/Kconfig" config COMP_STUBS diff --git a/src/audio/module_adapter/module/generic.c b/src/audio/module_adapter/module/generic.c index 1e806a1d4915..9e2974acec39 100644 --- a/src/audio/module_adapter/module/generic.c +++ b/src/audio/module_adapter/module/generic.c @@ -437,9 +437,9 @@ int module_set_configuration(struct processing_module *mod, if (!md->new_cfg_size) return 0; - if (md->new_cfg_size > MAX_BLOB_SIZE) { + if (md->new_cfg_size > CONFIG_MODULE_MAX_BLOB_SIZE) { comp_err(dev, "module_set_configuration(): error: blob size is too big cfg size %zu, allowed %d", - md->new_cfg_size, MAX_BLOB_SIZE); + md->new_cfg_size, CONFIG_MODULE_MAX_BLOB_SIZE); return -EINVAL; } diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index b98fa54f42a8..1f51558f5b42 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -27,8 +27,6 @@ #define IS_PROCESSING_MODE_RAW_DATA(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_RAW) #define IS_PROCESSING_MODE_SINK_SOURCE(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_SOURCE_SINK) -#define MAX_BLOB_SIZE 8192 - #if CONFIG_IPC_MAJOR_4 #define IPC_MOD_CMD(v) #elif CONFIG_IPC_MAJOR_3 From 4f51c43885dd67da3b0290de4f9f84ef0dcdc287 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Jul 2025 21:10:19 +0100 Subject: [PATCH 4/4] module: generic.h: add some comments and align doxygen comments Add a descriptive comment and align some doxygen comments. Signed-off-by: Liam Girdwood --- .../sof/audio/module_adapter/module/generic.h | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index 1f51558f5b42..bff6aa420629 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -33,6 +33,16 @@ #define IPC_MOD_CMD(v) .cmd = v, #endif +/* + * \brief Macro to declare a module adapter component. + * \param adapter - name of the module. + * \param uuid - UUID of the module. + * \param tr - trace context for the module. + * + * This macro declares a module component with the specified name, UUID, and trace context. + * It initializes the component module structure with the appropriate type, UID, and + * struct module_interface operations. + */ #define DECLARE_MODULE_ADAPTER(adapter, uuid, tr) \ static const struct comp_driver comp_##adapter##_module = { \ .type = SOF_COMP_MODULE_ADAPTER, \ @@ -81,10 +91,10 @@ DECLARE_MODULE(sys_comp_module_##adapter##_init) * \brief Module-specific states */ enum module_state { - MODULE_DISABLED, /**< Module isn't initialized yet or has been freed.*/ - MODULE_INITIALIZED, /**< Module initialized or reset. */ - MODULE_IDLE, /**< Module is idle now. */ - MODULE_PROCESSING, /**< Module is processing samples now. */ + MODULE_DISABLED, /**< Module isn't initialized yet or has been freed.*/ + MODULE_INITIALIZED, /**< Module initialized or reset. */ + MODULE_IDLE, /**< Module is idle now. */ + MODULE_PROCESSING, /**< Module is processing samples now. */ }; /** @@ -101,8 +111,8 @@ struct module_param { * sample_rate may have an id of 0x01. */ uint32_t id; - uint32_t size; /**< The size of whole parameter - id + size + data */ - int32_t data[]; /**< A pointer to memory where config is stored.*/ + uint32_t size; /**< The size of whole parameter - id + size + data */ + int32_t data[]; /**< A pointer to memory where config is stored.*/ }; /**