diff --git a/src/audio/asrc/asrc_ipc4.c b/src/audio/asrc/asrc_ipc4.c index b508238144d2..b0630865614f 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 module_interface *const ops = mod->dev->drv->adapter_ops; - return md->ops->endpoint_ops->dai_ts_config(cd->dai_dev); + return 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 module_interface *const ops = mod->dev->drv->adapter_ops; - return md->ops->endpoint_ops->dai_ts_start(cd->dai_dev); + return 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 module_interface *const ops = mod->dev->drv->adapter_ops; - return md->ops->endpoint_ops->dai_ts_stop(cd->dai_dev); + return 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 module_interface *const ops = mod->dev->drv->adapter_ops; - return md->ops->endpoint_ops->dai_ts_get(cd->dai_dev, tsd); + return 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..f593166f56a8 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 module_interface *const ops = dev->drv->adapter_ops; 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 (ops->prepare) { + ret = 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 module_interface *const ops = dev->drv->adapter_ops; 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 = 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 = 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 module_interface *const ops = dev->drv->adapter_ops; 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(ops->process); + ret = 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 module_interface *const ops = mod->dev->drv->adapter_ops; 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 (ops->reset) { + ret = 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 module_interface *const ops = mod->dev->drv->adapter_ops; struct module_data *md = &mod->priv; + int ret = 0; - if (md->ops->free) { - ret = md->ops->free(mod); + if (ops->free) { + ret = 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 module_interface *const ops = mod->dev->drv->adapter_ops; - if (md->ops->bind) - return md->ops->bind(mod, data); + if (ops->bind) + return ops->bind(mod, data); return 0; } int module_unbind(struct processing_module *mod, void *data) { - struct module_data *md = &mod->priv; + const struct module_interface *const ops = mod->dev->drv->adapter_ops; - if (md->ops->unbind) - return md->ops->unbind(mod, data); + if (ops->unbind) + return 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..832a0ca8b761 100644 --- a/src/audio/module_adapter/module/modules.c +++ b/src/audio/module_adapter/module/modules.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -50,13 +51,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 +98,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 +122,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 +137,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 +162,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 +199,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 { @@ -235,7 +237,7 @@ static int modules_process(struct processing_module *mod, 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 *const mod_in = mod->dev->drv->adapter_ops; return mod_in->process(mod, sources, num_of_sources, sinks, num_of_sinks); } @@ -249,7 +251,7 @@ static int modules_process_audio_stream(struct processing_module *mod, if (!mod->is_native_sof) return -EOPNOTSUPP; - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *const mod_in = mod->dev->drv->adapter_ops; return mod_in->process_audio_stream(mod, input_buffers, num_input_buffers, output_buffers, num_output_buffers); @@ -277,7 +279,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 *const mod_in = mod->dev->drv->adapter_ops; return mod_in->process_raw_data(mod, input_buffers, num_input_buffers, output_buffers, num_output_buffers); @@ -294,11 +296,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 { @@ -343,7 +346,7 @@ static int modules_set_configuration(struct processing_module *mod, uint32_t con size_t response_size) { if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *const mod_in = mod->dev->drv->adapter_ops; return mod_in->set_configuration(mod, config_id, pos, data_offset_size, fragment, fragment_size, response, response_size); @@ -370,7 +373,7 @@ static int modules_get_configuration(struct processing_module *mod, uint32_t con size_t fragment_size) { if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *const mod_in = mod->dev->drv->adapter_ops; return mod_in->get_configuration(mod, config_id, data_offset_size, fragment, fragment_size); @@ -391,7 +394,7 @@ static int modules_set_processing_mode(struct processing_module *mod, enum module_processing_mode mode) { if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *const mod_in = mod->dev->drv->adapter_ops; return mod_in->set_processing_mode(mod, mode); } @@ -419,7 +422,7 @@ static enum module_processing_mode modules_get_processing_mode(struct processing static int modules_reset(struct processing_module *mod) { if (mod->is_native_sof) { - const struct module_interface *mod_in = mod->priv.ops; + const struct module_interface *const mod_in = mod->dev->drv->adapter_ops; return mod_in->reset(mod); } @@ -427,7 +430,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 +461,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..5f09d23db24e 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 module_interface *const interface = mod->dev->drv->adapter_ops; 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 interface->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 (interface->trigger) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; - 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 (interface->endpoint_ops && interface->endpoint_ops->dai_get_hw_params) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->position) - return md->ops->endpoint_ops->position(dev, posn); + if (interface->endpoint_ops && interface->endpoint_ops->position) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_config) - return md->ops->endpoint_ops->dai_ts_config(dev); + if (interface->endpoint_ops && interface->endpoint_ops->dai_ts_config) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_start) - return md->ops->endpoint_ops->dai_ts_start(dev); + if (interface->endpoint_ops && interface->endpoint_ops->dai_ts_start) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_stop) - return md->ops->endpoint_ops->dai_ts_stop(dev); + if (interface->endpoint_ops && interface->endpoint_ops->dai_ts_stop) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; - if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_get) - return md->ops->endpoint_ops->dai_ts_get(dev, tsd); + if (interface->endpoint_ops && interface->endpoint_ops->dai_ts_get) + return interface->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..0f92ae7858ba 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 module_interface *const interface = mod->dev->drv->adapter_ops; 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 && interface->set_configuration) + return interface->set_configuration(mod, cdata->data[0].type, pos, + data_offset_size, (const uint8_t *)cdata, + cdata->num_elems, NULL, 0); + else if (!set && interface->get_configuration) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; 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 (interface->set_configuration) + ret = interface->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 (interface->get_configuration) + ret = interface->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..7ca28494af6a 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 module_interface *const interface = mod->dev->drv->adapter_ops; 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 (interface->set_configuration) + return interface->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 module_interface *const interface = mod->dev->drv->adapter_ops; 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 (interface->get_configuration) + return interface->get_configuration(mod, param_id, data_offset_size, + (uint8_t *)data, fragment_size); return 0; } EXPORT_SYMBOL(module_get_large_config); @@ -251,10 +253,10 @@ 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 module_interface *const interface = mod->dev->drv->adapter_ops; - 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 (interface->endpoint_ops && interface->endpoint_ops->get_total_data_processed) + return interface->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 module_interface *const ops = mod->dev->drv->adapter_ops; /* 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 (ops->is_ready_to_process) + return 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 +209,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 +285,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 module_interface *const ops = mod->dev->drv->adapter_ops; - return md->ops->process_audio_stream(mod, input_buffers, num_input_buffers, - output_buffers, num_output_buffers); + return 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..b718c1216d00 100644 --- a/src/include/sof/audio/module_adapter/module/modules.h +++ b/src/include/sof/audio/module_adapter/module/modules.h @@ -9,7 +9,6 @@ #define __SOF_AUDIO_MODULES__ #include -#include /* Intel module adapter is an extension to SOF module adapter component that allows to integrate * modules developed under IADK (Intel Audio Development Kit) @@ -40,41 +39,7 @@ * 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); - -static inline void declare_dynamic_module_adapter(struct comp_driver *drv, - enum sof_comp_type mtype, - const struct sof_uuid *uuid, - struct tr_ctx *tr) -{ - drv->type = mtype; - drv->uid = uuid; - drv->tctx = tr; - drv->ops.create = modules_shim_new; - drv->ops.prepare = module_adapter_prepare; - drv->ops.params = module_adapter_params; - drv->ops.copy = module_adapter_copy; -#if CONFIG_IPC_MAJOR_3 - drv->ops.cmd = module_adapter_cmd; -#endif - drv->ops.trigger = module_adapter_trigger; - drv->ops.reset = module_adapter_reset; - drv->ops.free = module_adapter_free; - drv->ops.set_large_config = module_set_large_config; - drv->ops.get_large_config = module_get_large_config; - drv->ops.get_attribute = module_adapter_get_attribute; - drv->ops.bind = module_adapter_bind; - drv->ops.unbind = module_adapter_unbind; - drv->ops.get_total_data_processed = module_adapter_get_total_data_processed; - drv->ops.dai_get_hw_params = module_adapter_get_hw_params; - drv->ops.position = module_adapter_position; - drv->ops.dai_ts_config = module_adapter_ts_config_op; - 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; -} +/* Processing Module Adapter API */ +extern const struct module_interface processing_module_adapter_interface; #endif /* __SOF_AUDIO_MODULES__ */ diff --git a/src/library_manager/lib_manager.c b/src/library_manager/lib_manager.c index 9c9474ed577d..59ecc2a4899b 100644 --- a/src/library_manager/lib_manager.c +++ b/src/library_manager/lib_manager.c @@ -485,6 +485,36 @@ static void lib_manager_update_sof_ctx(void *base_addr, uint32_t lib_id) } #if CONFIG_INTEL_MODULES +static void lib_manager_prepare_module_adapter(struct comp_driver *drv, const struct sof_uuid *uuid) +{ + drv->type = SOF_COMP_MODULE_ADAPTER; + drv->uid = uuid; + drv->tctx = &lib_manager_tr; + drv->ops.create = module_adapter_new; + drv->ops.prepare = module_adapter_prepare; + drv->ops.params = module_adapter_params; + drv->ops.copy = module_adapter_copy; +#if CONFIG_IPC_MAJOR_3 + drv->ops.cmd = module_adapter_cmd; +#endif + drv->ops.trigger = module_adapter_trigger; + drv->ops.reset = module_adapter_reset; + drv->ops.free = module_adapter_free; + drv->ops.set_large_config = module_set_large_config; + drv->ops.get_large_config = module_get_large_config; + drv->ops.get_attribute = module_adapter_get_attribute; + drv->ops.bind = module_adapter_bind; + drv->ops.unbind = module_adapter_unbind; + drv->ops.get_total_data_processed = module_adapter_get_total_data_processed; + drv->ops.dai_get_hw_params = module_adapter_get_hw_params; + drv->ops.position = module_adapter_position; + drv->ops.dai_ts_config = module_adapter_ts_config_op; + 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; +} + int lib_manager_register_module(const uint32_t component_id) { const struct lib_manager_mod_ctx *const ctx = lib_manager_get_mod_ctx(component_id); @@ -533,7 +563,7 @@ int lib_manager_register_module(const uint32_t component_id) mod = (struct sof_man_module *)((uint8_t *)desc + SOF_MAN_MODULE_OFFSET(entry_index)); const struct sof_uuid *uid = (struct sof_uuid *)&mod->uuid[0]; - declare_dynamic_module_adapter(drv, SOF_COMP_MODULE_ADAPTER, uid, &lib_manager_tr); + lib_manager_prepare_module_adapter(drv, uid); new_drv_info->drv = drv;