Skip to content

Commit

Permalink
modules: Remove unnecessary functions from Processing Module Adapter
Browse files Browse the repository at this point in the history
To ensure proper operation of native loadable modules it is necessary to
bypass Processing Module Adapter used by FDK modules. This is currently
done by overriding the pointer to module_interface used by the Module
Adapter. Thanks to this, the Module Adapter directly calls functions
provided by native module. As in this case the Processing Module Adapter
functions are omitted, support for native libraries are removed from it as
it is no longer needed. This leads to remove is_native_sof variable and
modules_process_raw, modules_process_audio_stream functions.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki committed Apr 3, 2024
1 parent 97182d0 commit 93198aa
Showing 1 changed file with 22 additions and 68 deletions.
90 changes: 22 additions & 68 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
#include <utilities/array.h>
#include <iadk_module_adapter.h>
#include <system_agent.h>
#include <native_system_agent.h>
#include <api_version.h>
#include <sof/lib_manager.h>
#include <sof/audio/module_adapter/module/module_interface.h>
#include <module/module/api_ver.h>
#include <zephyr/llext/llext.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 @@ -51,32 +47,6 @@ 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 int modules_new(struct processing_module *mod, 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;
/* Connect loadable module interfaces with module adapter entity. */
/* Check if native Zephyr lib is loaded */
void *system_agent;

byte_array_t mod_cfg = {
.data = (uint8_t *)md->cfg.init_data,
/* Intel modules expects DW size here */
.size = md->cfg.size >> 2,
};

system_agent = system_agent_start(module_entry_point, module_id, instance_id, 0, log_handle,
&mod_cfg);

module_set_private_data(mod, system_agent);

return 0;
}

/**
* \brief modules_init.
* \param[in] mod - processing module pointer.
Expand All @@ -90,50 +60,38 @@ static int modules_init(struct processing_module *mod)
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. */
const struct comp_ipc_config *config = &(dev->ipc_config);
void *system_agent;

int ret;
uintptr_t module_entry_point = lib_manager_allocate_module(mod, config, src_cfg);
/* At this point module resources are allocated and it is moved to L2 memory. */

if (module_entry_point == 0) {
comp_err(dev, "modules_init(), lib_manager_allocate_module() failed!");
return -EINVAL;
}
comp_info(dev, "modules_init() start");

if (!module_get_private_data(mod) &&
drv->adapter_ops == &processing_module_adapter_interface) {
/* First load */
ret = modules_new(mod, module_entry_point);
if (ret < 0)
return ret;
}
const uint32_t module_id = IPC4_MOD_ID(config->id);
const uint32_t instance_id = IPC4_INST_ID(config->id);
const uint32_t log_handle = (uint32_t)drv->tctx;

md->mpd.in_buff_size = src_cfg->ibs;
md->mpd.out_buff_size = src_cfg->obs;
byte_array_t mod_cfg = {
.data = (uint8_t *)md->cfg.init_data,
/* Intel modules expects DW size here */
.size = md->cfg.size >> 2,
};

/* Call module specific init function if exists. */
if (mod->is_native_sof) {
const struct module_interface *mod_in = drv->adapter_ops;
system_agent = system_agent_start(module_entry_point, module_id, instance_id, 0, log_handle,
&mod_cfg);

/* The order of preference */
if (mod_in->process)
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
else if (mod_in->process_audio_stream)
mod->proc_type = MODULE_PROCESS_TYPE_STREAM;
else if (mod_in->process_raw_data)
mod->proc_type = MODULE_PROCESS_TYPE_RAW;
else
return -EINVAL;
module_set_private_data(mod, system_agent);

ret = mod_in->init(mod);
} else {
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
ret = iadk_wrapper_init(module_get_private_data(mod));
}
md->mpd.in_buff_size = src_cfg->ibs;
md->mpd.out_buff_size = src_cfg->obs;

return ret;
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
return iadk_wrapper_init(system_agent);
}

/**
Expand Down Expand Up @@ -176,21 +134,17 @@ static int modules_process(struct processing_module *mod,
static int modules_free(struct processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *md = &mod->priv;
int ret;

comp_info(dev, "modules_free()");
ret = iadk_wrapper_free(module_get_private_data(mod));
if (ret)
comp_err(dev, "modules_free(): iadk_wrapper_free failed with error: %d", ret);


if (!md->llext || !llext_unload(&md->llext)) {
/* Free module resources allocated in L2 memory. */
ret = lib_manager_free_module(dev->ipc_config.id);
if (ret < 0)
comp_err(dev, "modules_free(), lib_manager_free_module() failed!");
}
/* Free module resources allocated in L2 memory. */
ret = lib_manager_free_module(dev->ipc_config.id);
if (ret < 0)
comp_err(dev, "modules_free(), lib_manager_free_module() failed!");

return ret;
}
Expand Down

0 comments on commit 93198aa

Please sign in to comment.