Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component: module_adapter: Move module_interface pointer to comp_driver #8905

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/audio/asrc/asrc_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
59 changes: 31 additions & 28 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
softwarecki marked this conversation as resolved.
Show resolved Hide resolved

comp_dbg(dev, "module_init() start");

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

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

Expand All @@ -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);
Expand All @@ -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",
Expand All @@ -325,15 +326,16 @@ 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
/* if the module was never prepared, no need to reset */
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,
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down
39 changes: 21 additions & 18 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/module_adapter/module/modules.h>
#include <utilities/array.h>
#include <iadk_module_adapter.h>
#include <system_agent.h>
#include <native_system_agent.h>
#include <api_version.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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. */
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -419,15 +422,15 @@ 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);
}
return iadk_wrapper_reset(mod->priv.module_adapter);
}

/* 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,
Expand Down Expand Up @@ -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);
}
Loading
Loading