Skip to content

Commit

Permalink
component: module_adapter: Move module_interface pointer to comp_driver
Browse files Browse the repository at this point in the history
Moved pointer to module_interface from struct module_data to comp_driver
structure. The change is aimed at clearing the module_data structure of
fields intended for exclusive use by sof. All modules are eventually use
module interface so this pointer will be in comp_driver anyway.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki committed Feb 23, 2024
1 parent 373fd8c commit fe0e9ff
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 92 deletions.
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 comp_driver *const drv = mod->dev->drv;

return md->ops->endpoint_ops->dai_ts_config(cd->dai_dev);
return drv->adapter_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 comp_driver *const drv = mod->dev->drv;

return md->ops->endpoint_ops->dai_ts_start(cd->dai_dev);
return drv->adapter_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 comp_driver *const drv = mod->dev->drv;

return md->ops->endpoint_ops->dai_ts_stop(cd->dai_dev);
return drv->adapter_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 comp_driver *const drv = mod->dev->drv;

return md->ops->endpoint_ops->dai_ts_get(cd->dai_dev, tsd);
return drv->adapter_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
52 changes: 30 additions & 22 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ int module_init(struct processing_module *mod, const struct module_interface *in
int ret;
struct module_data *md = &mod->priv;
struct comp_dev *dev = mod->dev;
struct comp_driver *const drv = dev->drv;

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

Expand All @@ -105,12 +106,12 @@ int module_init(struct processing_module *mod, const struct module_interface *in
}

/* Assign interface */
md->ops = interface;
drv->adapter_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 = drv->adapter_ops->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 +202,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 comp_driver *const drv = dev->drv;

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

Expand All @@ -210,8 +212,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 (drv->adapter_ops->prepare) {
ret = drv->adapter_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 +244,15 @@ int module_process_legacy(struct processing_module *mod,
int num_output_buffers)
{
struct comp_dev *dev = mod->dev;
const struct comp_driver *const drv = dev->drv;
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 +263,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 = drv->adapter_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 = drv->adapter_ops->process_raw_data(mod, input_buffers, num_input_buffers,
output_buffers, num_output_buffers);
else
ret = -EOPNOTSUPP;

Expand All @@ -288,13 +292,13 @@ int module_process_sink_src(struct processing_module *mod,

{
struct comp_dev *dev = mod->dev;
const struct comp_driver *const drv = dev->drv;
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 +308,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(drv->adapter_ops->process);
ret = drv->adapter_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 +329,16 @@ int module_process_sink_src(struct processing_module *mod,
int module_reset(struct processing_module *mod)
{
int ret;
const struct comp_driver *const drv = mod->dev->drv;
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 (drv->adapter_ops) {
ret = drv->adapter_ops->reset(mod);
if (ret) {
if (ret != PPL_STATUS_PATH_STOP)
comp_err(mod->dev,
Expand Down Expand Up @@ -375,11 +380,12 @@ void module_free_all_memory(struct processing_module *mod)

int module_free(struct processing_module *mod)
{
int ret = 0;
const struct comp_driver *const drv = mod->dev->drv;
struct module_data *md = &mod->priv;
int ret = 0;

if (md->ops->free) {
ret = md->ops->free(mod);
if (drv->adapter_ops->free) {
ret = drv->adapter_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 +514,21 @@ int module_set_configuration(struct processing_module *mod,

int module_bind(struct processing_module *mod, void *data)
{
const struct comp_driver *const drv = mod->dev->drv;
struct module_data *md = &mod->priv;

if (md->ops->bind)
return md->ops->bind(mod, data);
if (drv->adapter_ops->bind)
return drv->adapter_ops->bind(mod, data);
return 0;
}

int module_unbind(struct processing_module *mod, void *data)
{
const struct comp_driver *const drv = mod->dev->drv;
struct module_data *md = &mod->priv;

if (md->ops->unbind)
return md->ops->unbind(mod, data);
if (drv->adapter_ops->unbind)
return drv->adapter_ops->unbind(mod, data);
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static int modules_init(struct processing_module *mod)
uint32_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;
const struct ipc4_base_module_cfg *src_cfg = &md->cfg.base_cfg;
byte_array_t mod_cfg;
bool is_native_sof = false;
Expand Down Expand Up @@ -112,9 +113,9 @@ static int modules_init(struct processing_module *mod)
mod_buildinfo->api_version_number.full == SOF_MODULE_API_CURRENT_VERSION) {
/* If start agent for sof loadable */
is_native_sof = true;
md->ops = native_system_agent_start(mod->sys_service, md->module_entry_point,
module_id, instance_id, 0, log_handle,
&mod_cfg);
drv->adapter_ops = native_system_agent_start(mod->sys_service,
md->module_entry_point, module_id,
instance_id, 0, log_handle, &mod_cfg);
} else
return -ENOEXEC;

Expand All @@ -125,7 +126,7 @@ static int modules_init(struct processing_module *mod)

/* Call module specific init function if exists. */
if (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
44 changes: 22 additions & 22 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,13 +1255,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 comp_driver *const drv = mod->dev->drv;

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 drv->adapter_ops->endpoint_ops->trigger(dev, cmd);

/*
* If the module doesn't support pause, keep it active along with the rest of the
Expand All @@ -1271,8 +1271,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 (drv->adapter_ops->trigger)
return drv->adapter_ops->trigger(mod, cmd);

return module_adapter_set_state(mod, dev, cmd);
}
Expand Down Expand Up @@ -1394,10 +1394,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 comp_driver *const drv = mod->dev->drv;

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 (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_get_hw_params)
return drv->adapter_ops->endpoint_ops->dai_get_hw_params(dev, params, dir);

return -EOPNOTSUPP;
}
Expand All @@ -1415,10 +1415,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 comp_driver *const drv = mod->dev->drv;

if (md->ops->endpoint_ops && md->ops->endpoint_ops->position)
return md->ops->endpoint_ops->position(dev, posn);
if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->position)
return drv->adapter_ops->endpoint_ops->position(dev, posn);

return -EOPNOTSUPP;
}
Expand All @@ -1435,10 +1435,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 comp_driver *const drv = mod->dev->drv;

if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_config)
return md->ops->endpoint_ops->dai_ts_config(dev);
if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_config)
return drv->adapter_ops->endpoint_ops->dai_ts_config(dev);

return -EOPNOTSUPP;
}
Expand All @@ -1455,10 +1455,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 comp_driver *const drv = mod->dev->drv;

if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_start)
return md->ops->endpoint_ops->dai_ts_start(dev);
if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_start)
return drv->adapter_ops->endpoint_ops->dai_ts_start(dev);

return -EOPNOTSUPP;
}
Expand All @@ -1475,10 +1475,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 comp_driver *const drv = mod->dev->drv;

if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_stop)
return md->ops->endpoint_ops->dai_ts_stop(dev);
if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_stop)
return drv->adapter_ops->endpoint_ops->dai_ts_stop(dev);

return -EOPNOTSUPP;
}
Expand All @@ -1500,10 +1500,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 comp_driver *const drv = mod->dev->drv;

if (md->ops->endpoint_ops && md->ops->endpoint_ops->dai_ts_get)
return md->ops->endpoint_ops->dai_ts_get(dev, tsd);
if (drv->adapter_ops->endpoint_ops && drv->adapter_ops->endpoint_ops->dai_ts_get)
return drv->adapter_ops->endpoint_ops->dai_ts_get(dev, tsd);

return -EOPNOTSUPP;
}
Expand Down
Loading

0 comments on commit fe0e9ff

Please sign in to comment.