Skip to content

Commit

Permalink
iadk_modules: module_init: checking type of module
Browse files Browse the repository at this point in the history
In manifest is information about version of API and
depending on it we load IADK or SOF module.
Flag is showing if module is loadable. According to this information
different api is being used in loading module.

Signed-off-by: Dobrowolski, PawelX <pawelx.dobrowolski@intel.com>
  • Loading branch information
pjdobrowolski authored and lgirdwood committed Jul 12, 2023
1 parent 2cdf38c commit c66ed3e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 11 deletions.
103 changes: 93 additions & 10 deletions src/audio/module_adapter/module/iadk_modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include <sof/audio/module_adapter/module/iadk_modules.h>
#include <utilities/array.h>
#include <system_agent.h>
#include <native_system_agent.h>
#include <sof/lib_manager.h>
#include <sof/audio/module_adapter/module/module_interface.h>
#include <module_api_ver.h>

/* 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
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/include/sof/audio/module_adapter/module/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 6 additions & 1 deletion src/include/sof/audio/module_adapter/module/iadk_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include <iadk_module_adapter.h>

/* 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.
Expand All @@ -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.
*/


Expand Down

0 comments on commit c66ed3e

Please sign in to comment.