From f27cfcd6f23603ee6aa256317f11347d2f11fea0 Mon Sep 17 00:00:00 2001 From: Adrian Warecki Date: Fri, 23 Feb 2024 11:38:42 +0100 Subject: [PATCH] component: module_adapter: Move module_interface pointer to comp_driver Moved pointer to module_interface from struct module_data to comp_driver structure. The change is aimed at clearing the module_data structure of fields intended for exclusive use by sof. All modules are eventually use module interface so this pointer will be in comp_driver anyway. Signed-off-by: Adrian Warecki --- src/audio/asrc/asrc_ipc4.c | 16 ++--- src/audio/module_adapter/module/generic.c | 59 ++++++++++--------- src/audio/module_adapter/module/modules.c | 51 ++++++++++------ src/audio/module_adapter/module_adapter.c | 49 +++++++-------- .../module_adapter/module_adapter_ipc3.c | 30 +++++----- .../module_adapter/module_adapter_ipc4.c | 24 ++++---- src/include/module/module/base.h | 1 - src/include/sof/audio/component.h | 12 ++-- .../sof/audio/module_adapter/module/generic.h | 29 ++++----- .../sof/audio/module_adapter/module/modules.h | 9 ++- 10 files changed, 150 insertions(+), 130 deletions(-) diff --git a/src/audio/asrc/asrc_ipc4.c b/src/audio/asrc/asrc_ipc4.c index b508238144d2..52877fd926e3 100644 --- a/src/audio/asrc/asrc_ipc4.c +++ b/src/audio/asrc/asrc_ipc4.c @@ -28,9 +28,9 @@ int asrc_dai_configure_timestamp(struct comp_data *cd) return -ENODEV; struct processing_module *mod = comp_get_drvdata(cd->dai_dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - return md->ops->endpoint_ops->dai_ts_config(cd->dai_dev); + return drv->adapter_ops->endpoint_ops->dai_ts_config(cd->dai_dev); } int asrc_dai_start_timestamp(struct comp_data *cd) @@ -39,9 +39,9 @@ int asrc_dai_start_timestamp(struct comp_data *cd) return -ENODEV; struct processing_module *mod = comp_get_drvdata(cd->dai_dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - return md->ops->endpoint_ops->dai_ts_start(cd->dai_dev); + return drv->adapter_ops->endpoint_ops->dai_ts_start(cd->dai_dev); } int asrc_dai_stop_timestamp(struct comp_data *cd) @@ -50,9 +50,9 @@ int asrc_dai_stop_timestamp(struct comp_data *cd) return -ENODEV; struct processing_module *mod = comp_get_drvdata(cd->dai_dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - return md->ops->endpoint_ops->dai_ts_stop(cd->dai_dev); + return drv->adapter_ops->endpoint_ops->dai_ts_stop(cd->dai_dev); } #if CONFIG_ZEPHYR_NATIVE_DRIVERS @@ -65,9 +65,9 @@ int asrc_dai_get_timestamp(struct comp_data *cd, struct timestamp_data *tsd) return -ENODEV; struct processing_module *mod = comp_get_drvdata(cd->dai_dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - return md->ops->endpoint_ops->dai_ts_get(cd->dai_dev, tsd); + return drv->adapter_ops->endpoint_ops->dai_ts_get(cd->dai_dev, tsd); } void asrc_update_buffer_format(struct comp_buffer *buf_c, struct comp_data *cd) diff --git a/src/audio/module_adapter/module/generic.c b/src/audio/module_adapter/module/generic.c index b0efd63febde..da3346757206 100644 --- a/src/audio/module_adapter/module/generic.c +++ b/src/audio/module_adapter/module/generic.c @@ -75,11 +75,12 @@ int module_load_config(struct comp_dev *dev, const void *cfg, size_t size) return ret; } -int module_init(struct processing_module *mod, const struct module_interface *interface) +int module_init(struct processing_module *mod) { int ret; struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; + const struct module_interface *const interface = dev->drv->adapter_ops; comp_dbg(dev, "module_init() start"); @@ -90,7 +91,7 @@ int module_init(struct processing_module *mod, const struct module_interface *in return -EPERM; #endif if (!interface) { - comp_err(dev, "module_init(): could not find module interface for comp id %d", + comp_err(dev, "module_init(): module interface not defined for comp id %d", dev_comp_id(dev)); return -EIO; } @@ -104,13 +105,11 @@ int module_init(struct processing_module *mod, const struct module_interface *in return -EIO; } - /* Assign interface */ - md->ops = interface; /* Init memory list */ list_init(&md->memory.mem_list); /* Now we can proceed with module specific initialization */ - ret = md->ops->init(mod); + ret = interface->init(mod); if (ret) { comp_err(dev, "module_init() error %d: module specific init failed, comp id %d", ret, dev_comp_id(dev)); @@ -201,6 +200,7 @@ int module_prepare(struct processing_module *mod, int ret = 0; struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; + const struct comp_driver *const drv = dev->drv; comp_dbg(dev, "module_prepare() start"); @@ -210,8 +210,8 @@ int module_prepare(struct processing_module *mod, if (mod->priv.state < MODULE_INITIALIZED) return -EPERM; #endif - if (md->ops->prepare) { - ret = md->ops->prepare(mod, sources, num_of_sources, sinks, num_of_sinks); + if (drv->adapter_ops->prepare) { + ret = drv->adapter_ops->prepare(mod, sources, num_of_sources, sinks, num_of_sinks); if (ret) { comp_err(dev, "module_prepare() error %d: module specific prepare failed, comp_id %d", ret, dev_comp_id(dev)); @@ -242,13 +242,14 @@ int module_process_legacy(struct processing_module *mod, int num_output_buffers) { struct comp_dev *dev = mod->dev; + const struct comp_driver *const drv = dev->drv; int ret; - struct module_data *md = &mod->priv; - comp_dbg(dev, "module_process_legacy() start"); #if CONFIG_IPC_MAJOR_3 + struct module_data *md = &mod->priv; + if (md->state != MODULE_IDLE) { comp_err(dev, "module_process(): wrong state of comp_id %x, state %d", dev_comp_id(dev), md->state); @@ -259,11 +260,11 @@ int module_process_legacy(struct processing_module *mod, md->state = MODULE_PROCESSING; #endif if (IS_PROCESSING_MODE_AUDIO_STREAM(mod)) - ret = md->ops->process_audio_stream(mod, input_buffers, num_input_buffers, - output_buffers, num_output_buffers); + ret = drv->adapter_ops->process_audio_stream(mod, input_buffers, num_input_buffers, + output_buffers, num_output_buffers); else if (IS_PROCESSING_MODE_RAW_DATA(mod)) - ret = md->ops->process_raw_data(mod, input_buffers, num_input_buffers, - output_buffers, num_output_buffers); + ret = drv->adapter_ops->process_raw_data(mod, input_buffers, num_input_buffers, + output_buffers, num_output_buffers); else ret = -EOPNOTSUPP; @@ -288,13 +289,13 @@ int module_process_sink_src(struct processing_module *mod, { struct comp_dev *dev = mod->dev; + const struct comp_driver *const drv = dev->drv; int ret; - struct module_data *md = &mod->priv; - comp_dbg(dev, "module_process sink src() start"); #if CONFIG_IPC_MAJOR_3 + struct module_data *md = &mod->priv; if (md->state != MODULE_IDLE) { comp_err(dev, "module_process(): wrong state of comp_id %x, state %d", dev_comp_id(dev), md->state); @@ -304,8 +305,8 @@ int module_process_sink_src(struct processing_module *mod, /* set state to processing */ md->state = MODULE_PROCESSING; #endif - assert(md->ops->process); - ret = md->ops->process(mod, sources, num_of_sources, sinks, num_of_sinks); + assert(drv->adapter_ops->process); + ret = drv->adapter_ops->process(mod, sources, num_of_sources, sinks, num_of_sinks); if (ret && ret != -ENOSPC && ret != -ENODATA) { comp_err(dev, "module_process() error %d: for comp %d", @@ -325,6 +326,7 @@ int module_process_sink_src(struct processing_module *mod, int module_reset(struct processing_module *mod) { int ret; + const struct comp_driver *const drv = mod->dev->drv; struct module_data *md = &mod->priv; #if CONFIG_IPC_MAJOR_3 @@ -332,8 +334,8 @@ int module_reset(struct processing_module *mod) if (md->state < MODULE_IDLE) return 0; #endif - if (md->ops->reset) { - ret = md->ops->reset(mod); + if (drv->adapter_ops) { + ret = drv->adapter_ops->reset(mod); if (ret) { if (ret != PPL_STATUS_PATH_STOP) comp_err(mod->dev, @@ -375,11 +377,12 @@ void module_free_all_memory(struct processing_module *mod) int module_free(struct processing_module *mod) { - int ret = 0; + const struct comp_driver *const drv = mod->dev->drv; struct module_data *md = &mod->priv; + int ret = 0; - if (md->ops->free) { - ret = md->ops->free(mod); + if (drv->adapter_ops->free) { + ret = drv->adapter_ops->free(mod); if (ret) comp_warn(mod->dev, "module_free(): error: %d for %d", ret, dev_comp_id(mod->dev)); @@ -508,19 +511,19 @@ int module_set_configuration(struct processing_module *mod, int module_bind(struct processing_module *mod, void *data) { - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->bind) - return md->ops->bind(mod, data); + if (drv->adapter_ops->bind) + return drv->adapter_ops->bind(mod, data); return 0; } int module_unbind(struct processing_module *mod, void *data) { - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->unbind) - return md->ops->unbind(mod, data); + if (drv->adapter_ops->unbind) + return drv->adapter_ops->unbind(mod, data); return 0; } diff --git a/src/audio/module_adapter/module/modules.c b/src/audio/module_adapter/module/modules.c index 0671b4603d81..a9ec0a74b8e5 100644 --- a/src/audio/module_adapter/module/modules.c +++ b/src/audio/module_adapter/module/modules.c @@ -50,13 +50,12 @@ DECLARE_SOF_RT_UUID("modules", intel_uuid, 0xee2585f2, 0xe7d8, 0x43dc, 0x90, 0xab, 0x42, 0x24, 0xe0, 0x0c, 0x3e, 0x84); DECLARE_TR_CTX(intel_codec_tr, SOF_UUID(intel_uuid), LOG_LEVEL_INFO); -static const struct module_interface interface; - static int modules_new(struct processing_module *mod, const void *buildinfo, uintptr_t module_entry_point) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; + struct comp_driver *drv = (struct comp_driver *)dev->drv; uint32_t module_id = IPC4_MOD_ID(dev->ipc_config.id); uint32_t instance_id = IPC4_INST_ID(dev->ipc_config.id); uint32_t log_handle = (uint32_t) dev->drv->tctx; @@ -98,9 +97,9 @@ static int modules_new(struct processing_module *mod, const void *buildinfo, mod_buildinfo->api_version_number.full == SOF_MODULE_API_CURRENT_VERSION) { /* The module is native: start agent for sof loadable */ mod->is_native_sof = true; - md->ops = native_system_agent_start(mod->sys_service, module_entry_point, - module_id, instance_id, - 0, log_handle, &mod_cfg); + drv->adapter_ops = native_system_agent_start(mod->sys_service, module_entry_point, + module_id, instance_id, + 0, log_handle, &mod_cfg); } else { return -ENOEXEC; } @@ -122,6 +121,7 @@ static int modules_init(struct processing_module *mod) { struct module_data *md = &mod->priv; struct comp_dev *dev = mod->dev; + const struct comp_driver *const drv = dev->drv; const struct ipc4_base_module_cfg *src_cfg = &md->cfg.base_cfg; struct comp_ipc_config *config = &(dev->ipc_config); /* At this point module resources are allocated and it is moved to L2 memory. */ @@ -136,7 +136,7 @@ static int modules_init(struct processing_module *mod) } comp_info(dev, "modules_init() start"); - if (!md->module_adapter && md->ops == &interface) { + if (!md->module_adapter && drv->adapter_ops == &processing_module_adapter_interface) { /* First load */ ret = modules_new(mod, buildinfo, module_entry_point); if (ret < 0) @@ -161,7 +161,7 @@ static int modules_init(struct processing_module *mod) /* Call module specific init function if exists. */ if (mod->is_native_sof) { - const struct module_interface *mod_in = md->ops; + const struct module_interface *mod_in = drv->adapter_ops; /* The order of preference */ if (mod_in->process) @@ -198,13 +198,14 @@ static int modules_prepare(struct processing_module *mod, struct sof_sink **sinks, int num_of_sinks) { struct comp_dev *dev = mod->dev; + const struct comp_driver *const drv = dev->drv; int ret = 0; comp_info(dev, "modules_prepare()"); /* Call module specific prepare function if exists. */ if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; ret = mod_in->prepare(mod, sources, num_of_sources, sinks, num_of_sinks); } else { @@ -231,11 +232,13 @@ static int modules_process(struct processing_module *mod, struct sof_source **sources, int num_of_sources, struct sof_sink **sinks, int num_of_sinks) { + const struct comp_driver *const drv = mod->dev->drv; + if (!mod->is_native_sof) return iadk_wrapper_process(mod->priv.module_adapter, sources, num_of_sources, sinks, num_of_sinks); - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->process(mod, sources, num_of_sources, sinks, num_of_sinks); } @@ -246,10 +249,12 @@ static int modules_process_audio_stream(struct processing_module *mod, struct output_stream_buffer *output_buffers, int num_output_buffers) { + const struct comp_driver *const drv = mod->dev->drv; + if (!mod->is_native_sof) return -EOPNOTSUPP; - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->process_audio_stream(mod, input_buffers, num_input_buffers, output_buffers, num_output_buffers); @@ -268,6 +273,7 @@ static int modules_process_raw(struct processing_module *mod, struct output_stream_buffer *output_buffers, int num_output_buffers) { + const struct comp_driver *const drv = mod->dev->drv; struct module_data *md = &mod->priv; if (!mod->is_native_sof) @@ -277,7 +283,7 @@ static int modules_process_raw(struct processing_module *mod, modules_init_process(mod); /* Call module specific process function. */ - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->process_raw_data(mod, input_buffers, num_input_buffers, output_buffers, num_output_buffers); @@ -294,11 +300,12 @@ static int modules_free(struct processing_module *mod) { struct comp_dev *dev = mod->dev; struct module_data *md = &mod->priv; + const struct comp_driver *const drv = dev->drv; int ret; comp_info(dev, "modules_free()"); if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; ret = mod_in->free(mod); } else { @@ -342,8 +349,10 @@ static int modules_set_configuration(struct processing_module *mod, uint32_t con size_t fragment_size, uint8_t *response, size_t response_size) { + const struct comp_driver *const drv = mod->dev->drv; + if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->set_configuration(mod, config_id, pos, data_offset_size, fragment, fragment_size, response, response_size); @@ -369,8 +378,10 @@ static int modules_get_configuration(struct processing_module *mod, uint32_t con uint32_t *data_offset_size, uint8_t *fragment, size_t fragment_size) { + const struct comp_driver *const drv = mod->dev->drv; + if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->get_configuration(mod, config_id, data_offset_size, fragment, fragment_size); @@ -390,8 +401,10 @@ static int modules_get_configuration(struct processing_module *mod, uint32_t con static int modules_set_processing_mode(struct processing_module *mod, enum module_processing_mode mode) { + const struct comp_driver *const drv = mod->dev->drv; + if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->set_processing_mode(mod, mode); } @@ -418,8 +431,10 @@ static enum module_processing_mode modules_get_processing_mode(struct processing */ static int modules_reset(struct processing_module *mod) { + const struct comp_driver *const drv = mod->dev->drv; + if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *mod_in = drv->adapter_ops; return mod_in->reset(mod); } @@ -427,7 +442,7 @@ static int modules_reset(struct processing_module *mod) } /* Processing Module Adapter API*/ -static const struct module_interface interface = { +const struct module_interface processing_module_adapter_interface = { .init = modules_init, .prepare = modules_prepare, .process_raw_data = modules_process_raw, @@ -458,5 +473,5 @@ struct comp_dev *modules_shim_new(const struct comp_driver *drv, const struct comp_ipc_config *config, const void *spec) { - return module_adapter_new(drv, config, &interface, spec); + return module_adapter_new(drv, config, spec); } diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 7faf515603bf..a8fec507c86a 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -38,12 +38,13 @@ LOG_MODULE_REGISTER(module_adapter, CONFIG_SOF_LOG_LEVEL); */ struct comp_dev *module_adapter_new(const struct comp_driver *drv, const struct comp_ipc_config *config, - const struct module_interface *interface, const void *spec) + const void *spec) { int ret; struct comp_dev *dev; struct processing_module *mod; struct module_config *dst; + const struct module_interface *const interface = drv->adapter_ops; comp_cl_dbg(drv, "module_adapter_new() start"); @@ -104,7 +105,7 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv, goto err; /* Init processing module */ - ret = module_init(mod, interface); + ret = module_init(mod); if (ret) { comp_err(dev, "module_adapter_new() %d: module initialization failed", ret); @@ -1255,13 +1256,13 @@ EXPORT_SYMBOL(module_adapter_copy); int module_adapter_trigger(struct comp_dev *dev, int cmd) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; comp_dbg(dev, "module_adapter_trigger(): cmd %d", cmd); /* handle host/DAI gateway modules separately */ if (dev->ipc_config.type == SOF_COMP_HOST || dev->ipc_config.type == SOF_COMP_DAI) - return md->ops->endpoint_ops->trigger(dev, cmd); + return drv->adapter_ops->endpoint_ops->trigger(dev, cmd); /* * If the module doesn't support pause, keep it active along with the rest of the @@ -1271,8 +1272,8 @@ int module_adapter_trigger(struct comp_dev *dev, int cmd) dev->state = COMP_STATE_ACTIVE; return PPL_STATUS_PATH_STOP; } - if (md->ops->trigger) - return md->ops->trigger(mod, cmd); + if (drv->adapter_ops->trigger) + return drv->adapter_ops->trigger(mod, cmd); return module_adapter_set_state(mod, dev, cmd); } @@ -1394,10 +1395,10 @@ int module_adapter_get_hw_params(struct comp_dev *dev, struct sof_ipc_stream_par int dir) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_get_hw_params) - return md->ops->endpoint_ops->dai_get_hw_params(dev, params, dir); + if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_get_hw_params) + return drv->adapter_ops->endpoint_ops->dai_get_hw_params(dev, params, dir); return -EOPNOTSUPP; } @@ -1415,10 +1416,10 @@ EXPORT_SYMBOL(module_adapter_get_hw_params); int module_adapter_position(struct comp_dev *dev, struct sof_ipc_stream_posn *posn) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->position) - return md->ops->endpoint_ops->position(dev, posn); + if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->position) + return drv->adapter_ops->endpoint_ops->position(dev, posn); return -EOPNOTSUPP; } @@ -1435,10 +1436,10 @@ EXPORT_SYMBOL(module_adapter_position); int module_adapter_ts_config_op(struct comp_dev *dev) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_config) - return md->ops->endpoint_ops->dai_ts_config(dev); + if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_config) + return drv->adapter_ops->endpoint_ops->dai_ts_config(dev); return -EOPNOTSUPP; } @@ -1455,10 +1456,10 @@ EXPORT_SYMBOL(module_adapter_ts_config_op); int module_adapter_ts_start_op(struct comp_dev *dev) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_start) - return md->ops->endpoint_ops->dai_ts_start(dev); + if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_start) + return drv->adapter_ops->endpoint_ops->dai_ts_start(dev); return -EOPNOTSUPP; } @@ -1475,10 +1476,10 @@ EXPORT_SYMBOL(module_adapter_ts_start_op); int module_adapter_ts_stop_op(struct comp_dev *dev) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_stop) - return md->ops->endpoint_ops->dai_ts_stop(dev); + if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_stop) + return drv->adapter_ops->endpoint_ops->dai_ts_stop(dev); return -EOPNOTSUPP; } @@ -1500,10 +1501,10 @@ int module_adapter_ts_get_op(struct comp_dev *dev, struct timestamp_data *tsd) #endif { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_get) - return md->ops->endpoint_ops->dai_ts_get(dev, tsd); + if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_get) + return drv->adapter_ops->endpoint_ops->dai_ts_get(dev, tsd); return -EOPNOTSUPP; } diff --git a/src/audio/module_adapter/module_adapter_ipc3.c b/src/audio/module_adapter/module_adapter_ipc3.c index 920eb4f0f169..f82eec045ac3 100644 --- a/src/audio/module_adapter/module_adapter_ipc3.c +++ b/src/audio/module_adapter/module_adapter_ipc3.c @@ -169,7 +169,7 @@ static int module_adapter_get_set_params(struct comp_dev *dev, struct sof_ipc_ct bool set) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; enum module_cfg_fragment_position pos; uint32_t data_offset_size; static uint32_t size; @@ -197,13 +197,13 @@ static int module_adapter_get_set_params(struct comp_dev *dev, struct sof_ipc_ct * The type member in struct sof_abi_hdr is used for component's specific blob type * for IPC3, just like it is used for component's specific blob param_id for IPC4. */ - if (set && md->ops->set_configuration) - return md->ops->set_configuration(mod, cdata->data[0].type, pos, data_offset_size, - (const uint8_t *)cdata, cdata->num_elems, - NULL, 0); - else if (!set && md->ops->get_configuration) - return md->ops->get_configuration(mod, pos, &data_offset_size, - (uint8_t *)cdata, cdata->num_elems); + if (set && drv->adapter_ops->set_configuration) + return drv->adapter_ops->set_configuration(mod, cdata->data[0].type, pos, + data_offset_size, (const uint8_t *)cdata, + cdata->num_elems, NULL, 0); + else if (!set && drv->adapter_ops->get_configuration) + return drv->adapter_ops->get_configuration(mod, pos, &data_offset_size, + (uint8_t *)cdata, cdata->num_elems); comp_warn(dev, "module_adapter_get_set_params(): no configuration op set for %d", dev_comp_id(dev)); @@ -247,7 +247,7 @@ int module_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_s { struct sof_ipc_ctrl_data *cdata = ASSUME_ALIGNED(data, 4); struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; int ret = 0; comp_dbg(dev, "module_adapter_cmd() %d start", cmd); @@ -265,9 +265,11 @@ int module_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_s * anyway. Also, pass the 0 as the fragment size as it is not relevant for the * SET_VALUE command. */ - if (md->ops->set_configuration) - ret = md->ops->set_configuration(mod, 0, MODULE_CFG_FRAGMENT_SINGLE, 0, - (const uint8_t *)cdata, 0, NULL, 0); + if (drv->adapter_ops->set_configuration) + ret = drv->adapter_ops->set_configuration(mod, 0, + MODULE_CFG_FRAGMENT_SINGLE, 0, + (const uint8_t *)cdata, 0, NULL, + 0); break; case COMP_CMD_GET_VALUE: /* @@ -275,8 +277,8 @@ int module_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_s * anyway. Also, pass the 0 as the fragment size and data offset as they are not * relevant for the GET_VALUE command. */ - if (md->ops->get_configuration) - ret = md->ops->get_configuration(mod, 0, 0, (uint8_t *)cdata, 0); + if (drv->adapter_ops->get_configuration) + ret = drv->adapter_ops->get_configuration(mod, 0, 0, (uint8_t *)cdata, 0); break; default: comp_err(dev, "module_adapter_cmd() error: unknown command"); diff --git a/src/audio/module_adapter/module_adapter_ipc4.c b/src/audio/module_adapter/module_adapter_ipc4.c index 5d2fb045eccb..f70958d2dd8b 100644 --- a/src/audio/module_adapter/module_adapter_ipc4.c +++ b/src/audio/module_adapter/module_adapter_ipc4.c @@ -100,6 +100,7 @@ int module_set_large_config(struct comp_dev *dev, uint32_t param_id, bool first_ bool last_block, uint32_t data_offset_size, const char *data) { struct processing_module *mod = comp_get_drvdata(dev); + const struct comp_driver *const drv = mod->dev->drv; struct module_data *md = &mod->priv; enum module_cfg_fragment_position pos; size_t fragment_size; @@ -126,10 +127,10 @@ int module_set_large_config(struct comp_dev *dev, uint32_t param_id, bool first_ return -EINVAL; } - if (md->ops->set_configuration) - return md->ops->set_configuration(mod, param_id, pos, data_offset_size, - (const uint8_t *)data, - fragment_size, NULL, 0); + if (drv->adapter_ops->set_configuration) + return drv->adapter_ops->set_configuration(mod, param_id, pos, data_offset_size, + (const uint8_t *)data, fragment_size, + NULL, 0); return 0; } EXPORT_SYMBOL(module_set_large_config); @@ -138,6 +139,7 @@ int module_get_large_config(struct comp_dev *dev, uint32_t param_id, bool first_ bool last_block, uint32_t *data_offset_size, char *data) { struct processing_module *mod = comp_get_drvdata(dev); + const struct comp_driver *const drv = mod->dev->drv; struct module_data *md = &mod->priv; size_t fragment_size; @@ -154,9 +156,9 @@ int module_get_large_config(struct comp_dev *dev, uint32_t param_id, bool first_ fragment_size = md->cfg.size - *data_offset_size; } - if (md->ops->get_configuration) - return md->ops->get_configuration(mod, param_id, data_offset_size, - (uint8_t *)data, fragment_size); + if (drv->adapter_ops->get_configuration) + return drv->adapter_ops->get_configuration(mod, param_id, data_offset_size, + (uint8_t *)data, fragment_size); return 0; } EXPORT_SYMBOL(module_get_large_config); @@ -251,10 +253,12 @@ uint64_t module_adapter_get_total_data_processed(struct comp_dev *dev, uint32_t stream_no, bool input) { struct processing_module *mod = comp_get_drvdata(dev); - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->get_total_data_processed) - return md->ops->endpoint_ops->get_total_data_processed(dev, stream_no, input); + if (drv->adapter_ops->endpoint_ops && + drv->adapter_ops->endpoint_ops->get_total_data_processed) + return drv->adapter_ops->endpoint_ops->get_total_data_processed(dev, stream_no, + input); if (input) return mod->total_data_produced; diff --git a/src/include/module/module/base.h b/src/include/module/module/base.h index 69e216435033..e16a1f737fc3 100644 --- a/src/include/module/module/base.h +++ b/src/include/module/module/base.h @@ -58,7 +58,6 @@ struct module_data { enum module_state state; size_t new_cfg_size; /**< size of new module config data */ void *runtime_params; - const struct module_interface *ops; /**< module specific operations */ struct module_memory memory; /**< memory allocated by module */ struct module_processing_data mpd; /**< shared data comp <-> module */ void *module_adapter; /**priv; + const struct comp_driver *const drv = mod->dev->drv; /* LL module has to be always ready for processing */ if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL) return true; - if (md->ops->is_ready_to_process) - return md->ops->is_ready_to_process(mod, sources, num_of_sources, - sinks, num_of_sinks); + if (drv->adapter_ops->is_ready_to_process) + return drv->adapter_ops->is_ready_to_process(mod, sources, num_of_sources, + sinks, num_of_sinks); /* default action - the module is ready if there's enough data for processing and enough * space to store result. IBS/OBS as declared in init_instance */ @@ -216,8 +210,7 @@ int module_bind(struct processing_module *mod, void *data); int module_unbind(struct processing_module *mod, void *data); struct comp_dev *module_adapter_new(const struct comp_driver *drv, - const struct comp_ipc_config *config, - const struct module_interface *interface, const void *spec); + const struct comp_ipc_config *config, const void *spec); int module_adapter_prepare(struct comp_dev *dev); int module_adapter_params(struct comp_dev *dev, struct sof_ipc_stream_params *params); int module_adapter_copy(struct comp_dev *dev); @@ -293,10 +286,10 @@ static inline int module_process_endpoint(struct processing_module *mod, struct output_stream_buffer *output_buffers, int num_output_buffers) { - struct module_data *md = &mod->priv; + const struct comp_driver *const drv = mod->dev->drv; - return md->ops->process_audio_stream(mod, input_buffers, num_input_buffers, - output_buffers, num_output_buffers); + return drv->adapter_ops->process_audio_stream(mod, input_buffers, num_input_buffers, + output_buffers, num_output_buffers); } #endif diff --git a/src/include/sof/audio/module_adapter/module/modules.h b/src/include/sof/audio/module_adapter/module/modules.h index 6e56793f6d70..b36c02078272 100644 --- a/src/include/sof/audio/module_adapter/module/modules.h +++ b/src/include/sof/audio/module_adapter/module/modules.h @@ -40,10 +40,8 @@ * with version read from elf file. */ - -struct comp_dev *modules_shim_new(const struct comp_driver *drv, - const struct comp_ipc_config *config, - const void *spec); +/* Processing Module Adapter API */ +extern const struct module_interface processing_module_adapter_interface; static inline void declare_dynamic_module_adapter(struct comp_driver *drv, enum sof_comp_type mtype, @@ -53,7 +51,7 @@ static inline void declare_dynamic_module_adapter(struct comp_driver *drv, drv->type = mtype; drv->uid = uuid; drv->tctx = tr; - drv->ops.create = modules_shim_new; + drv->ops.create = module_adapter_new; drv->ops.prepare = module_adapter_prepare; drv->ops.params = module_adapter_params; drv->ops.copy = module_adapter_copy; @@ -75,6 +73,7 @@ static inline void declare_dynamic_module_adapter(struct comp_driver *drv, drv->ops.dai_ts_start = module_adapter_ts_start_op; drv->ops.dai_ts_stop = module_adapter_ts_stop_op; drv->ops.dai_ts_get = module_adapter_ts_get_op; + drv->adapter_ops = &processing_module_adapter_interface; } #endif /* __SOF_AUDIO_MODULES__ */