diff --git a/src/audio/module_adapter/module/iadk_modules.c b/src/audio/module_adapter/module/iadk_modules.c index bf7e9aa1cb45..c7ec8c03a2a2 100644 --- a/src/audio/module_adapter/module/iadk_modules.c +++ b/src/audio/module_adapter/module/iadk_modules.c @@ -8,7 +8,10 @@ #include #include #include +#include #include +#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) Framework. IADK modules uses uniform @@ -80,8 +83,34 @@ static int iadk_modules_init(struct processing_module *mod) uint32_t instance_id = IPC4_INST_ID(mod->dev->ipc_config.id); uint32_t log_handle = (uint32_t) mod->dev->drv->tctx; /* Connect loadable module interfaces with module adapter entity. */ - void *mod_adp = system_agent_start(md->module_entry_point, module_id, - instance_id, 0, log_handle, &mod_cfg); + /* Check if native Zephyr lib is loaded */ + struct sof_man_fw_desc *desc; + + desc = lib_manager_get_library_module_desc(module_id); + if (!desc) { + comp_err(dev, "iadk_modules_init(): Failed to load manifest"); + return -ENOMEM; + } + struct sof_man_module *module_entry = + (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(0)); + + struct sof_module_api_build_info *mod_buildinfo = + (struct sof_module_api_build_info *) + (module_entry->segment[SOF_MAN_SEGMENT_TEXT].v_base_addr); + + void *mod_adp; + + /* Check if module is FDK*/ + if (mod_buildinfo->api_version_number.fields.major < SOF_MODULE_API_MAJOR_VERSION) { + mod_adp = system_agent_start(md->module_entry_point, module_id, + instance_id, 0, log_handle, &mod_cfg); + } else { + /* If not start agent for sof loadable */ + mod->is_native_sof = true; + mod_adp = native_system_agent_start(mod->sys_service, md->module_entry_point, + module_id, instance_id, 0, log_handle, + &mod_cfg); + } md->module_adapter = mod_adp; @@ -102,7 +131,14 @@ static int iadk_modules_init(struct processing_module *mod) md->mpd.out_buff_size = src_cfg->obs; /* Call module specific init function if exists. */ - ret = iadk_wrapper_init(md->module_adapter); + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)md->module_adapter; + + ret = mod_in->init(mod); + } else { + ret = iadk_wrapper_init(md->module_adapter); + } return ret; } @@ -127,8 +163,15 @@ static int iadk_modules_prepare(struct processing_module *mod, comp_info(dev, "iadk_modules_prepare()"); /* Call module specific prepare function if exists. */ - ret = iadk_wrapper_prepare(mod->priv.module_adapter); - return 0; + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + ret = mod_in->prepare(mod, NULL, 0, NULL, 0); + } else { + ret = iadk_wrapper_prepare(mod->priv.module_adapter); + } + return ret; } static int iadk_modules_init_process(struct processing_module *mod) @@ -173,10 +216,17 @@ static int iadk_modules_process(struct processing_module *mod, i++; } /* Call module specific process function. */ - ret = iadk_wrapper_process(mod->priv.module_adapter, - input_buffers, num_input_buffers, - output_buffers, num_output_buffers); - + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + ret = mod_in->process_raw_data(mod, input_buffers, num_input_buffers, + output_buffers, num_output_buffers); + } else { + ret = iadk_wrapper_process(mod->priv.module_adapter, input_buffers, + num_input_buffers, output_buffers, + num_output_buffers); + } return ret; } @@ -195,7 +245,14 @@ static int iadk_modules_free(struct processing_module *mod) int ret = 0; comp_info(dev, "iadk_modules_free()"); - ret = iadk_wrapper_free(mod->priv.module_adapter); + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + ret = mod_in->free(mod); + } else { + ret = iadk_wrapper_free(mod->priv.module_adapter); + } rfree(md->mpd.in_buff); rfree(md->mpd.out_buff); @@ -228,6 +285,13 @@ static int iadk_modules_set_configuration(struct processing_module *mod, uint32_ size_t fragment_size, uint8_t *response, size_t response_size) { + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + return mod_in->set_configuration(mod, config_id, pos, data_offset_size, fragment, + fragment_size, response, response_size); + } return iadk_wrapper_set_configuration(mod->priv.module_adapter, config_id, pos, data_offset_size, fragment, fragment_size, response, response_size); @@ -249,6 +313,13 @@ static int iadk_modules_get_configuration(struct processing_module *mod, uint32_ uint32_t *data_offset_size, uint8_t *fragment, size_t fragment_size) { + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + return mod_in->get_configuration(mod, config_id, data_offset_size, + fragment, fragment_size); + } return iadk_wrapper_get_configuration(mod->priv.module_adapter, config_id, MODULE_CFG_FRAGMENT_SINGLE, *data_offset_size, fragment, fragment_size); @@ -264,6 +335,12 @@ static int iadk_modules_get_configuration(struct processing_module *mod, uint32_ static int iadk_modules_set_processing_mode(struct processing_module *mod, enum module_processing_mode mode) { + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + return mod_in->set_processing_mode(mod, mode); + } return iadk_wrapper_set_processing_mode(mod->priv.module_adapter, mode); } @@ -287,6 +364,12 @@ static enum module_processing_mode iadk_modules_get_processing_mode(struct proce */ static int iadk_modules_reset(struct processing_module *mod) { + if (mod->is_native_sof) { + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; + + return mod_in->reset(mod); + } return iadk_wrapper_reset(mod->priv.module_adapter); } diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index 54c8172c4263..da74134aef9a 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -212,6 +212,9 @@ struct processing_module { */ bool stream_copy_single_to_single; + /* flag to insure that module is loadable */ + bool is_native_sof; + /* pointer to system services for loadable modules */ uint32_t *sys_service; diff --git a/src/include/sof/audio/module_adapter/module/iadk_modules.h b/src/include/sof/audio/module_adapter/module/iadk_modules.h index 712b85d55d44..d2718652d219 100644 --- a/src/include/sof/audio/module_adapter/module/iadk_modules.h +++ b/src/include/sof/audio/module_adapter/module/iadk_modules.h @@ -11,7 +11,8 @@ #include /* Intel module adapter is an extension to SOF module adapter component that allows to integrate - * modules developed under IADK (Intel Audio Development Kit) Framework. IADK modules uses uniform + * modules developed under IADK (Intel Audio Development Kit) + * and LMDK (Loadable Modules Dev Kit) Framework. Modules uses uniform * set of interfaces and are linked into separate library. These modules are loaded in runtime * through library_manager and then after registration into SOF component infrastructure are * interfaced through module adapter API. @@ -32,6 +33,10 @@ * connect both sides of ProcessingModuleInterface and System Service. * - System Service - exposes of SOF base FW services to the module. * - Processing Module Adapter - SOF base FW side of ProcessingModuleInterface API + * + * Using the same philosofy loadable modules are using module adapter to interact with SOF FW. + * Module recognision is done by checking module API version defined in module_api_ver.h + * with version read from elf file. */