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 Mar 5, 2024
1 parent a904357 commit c43b8e6
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 146 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
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;

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 comp_driver *const drv = dev->drv;

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 (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 +242,14 @@ 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 +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 = 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 +289,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 +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(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 +326,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 +377,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 +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 comp_driver *const drv = mod->dev->drv;

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)
{
struct module_data *md = &mod->priv;
const struct comp_driver *const drv = mod->dev->drv;

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
49 changes: 15 additions & 34 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;

Expand Down Expand Up @@ -111,9 +112,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 */
mod->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 @@ -137,7 +138,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 @@ -180,7 +181,7 @@ static int modules_prepare(struct processing_module *mod,

/* 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 = dev->drv->adapter_ops;

ret = mod_in->prepare(mod, sources, num_of_sources, sinks, num_of_sinks);
} else {
Expand Down Expand Up @@ -211,7 +212,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 *mod_in = mod->dev->drv->adapter_ops;

return mod_in->process(mod, sources, num_of_sources, sinks, num_of_sinks);
}
Expand All @@ -225,7 +226,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 *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 @@ -253,7 +254,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 *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 @@ -275,7 +276,7 @@ static int modules_free(struct processing_module *mod)

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 = mod->dev->drv->adapter_ops;

ret = mod_in->free(mod);
} else {
Expand Down Expand Up @@ -314,7 +315,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 *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 @@ -341,7 +342,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 *mod_in = mod->dev->drv->adapter_ops;

return mod_in->get_configuration(mod, config_id, data_offset_size,
fragment, fragment_size);
Expand All @@ -362,7 +363,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 *mod_in = mod->dev->drv->adapter_ops;

return mod_in->set_processing_mode(mod, mode);
}
Expand Down Expand Up @@ -390,15 +391,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 *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 All @@ -411,23 +412,3 @@ static const struct module_interface interface = {
.reset = modules_reset,
.free = modules_free,
};

/**
* \brief Create a module adapter component.
* \param[in] drv - component driver pointer.
* \param[in] config - component ipc descriptor pointer.
* \param[in] spec - pointer to module configuration data
*
* \return: a pointer to newly created module adapter component on success. NULL on error.
*
* \note: For dynamically loaded module the spec size is not known by base FW, since this is
* loaded module specific information. Therefore configuration size is required here.
* New module details are discovered during its loading, therefore comp_driver initialisation
* happens at this point.
*/
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);
}
Loading

0 comments on commit c43b8e6

Please sign in to comment.