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

ipc: move all init parsing to components/modules #9535

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
29 changes: 28 additions & 1 deletion src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,35 @@ static int asrc_reset(struct processing_module *mod)
return 0;
}

#if CONFIG_IPC_MAJOR_3
static int asrc_init_shim(struct processing_module *mod)
{
struct ipc_config_asrc *ipc_asrc;
struct module_data *mod_data = &mod->priv;
const struct sof_ipc_comp_asrc *asrc =
(const struct sof_ipc_comp_asrc *)mod_data->cfg.init_data;

if (IPC_TAIL_IS_SIZE_INVALID(*asrc))
return -EBADMSG;

ipc_asrc = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(*ipc_asrc));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the configuration so large or why rballoc()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rballoc is what is used module_load_config to alloc the same region. Used it to reduce the number of changes.

if (!ipc_asrc)
return -ENOMEM;

ipc_asrc->source_rate = asrc->source_rate;
ipc_asrc->sink_rate = asrc->sink_rate;
ipc_asrc->asynchronous_mode = asrc->asynchronous_mode;
ipc_asrc->operation_mode = asrc->operation_mode;

rfree(mod_data->cfg.data);
mod_data->cfg.init_data = ipc_asrc;
mod_data->cfg.data = ipc_asrc;
return asrc_init(mod);
}
cujomalainey marked this conversation as resolved.
Show resolved Hide resolved
#endif

static const struct module_interface asrc_interface = {
.init = asrc_init,
.init = IPC3_SHIM(asrc_init),
.prepare = asrc_prepare,
.process_audio_stream = asrc_process,
.trigger = asrc_trigger,
Expand Down
21 changes: 20 additions & 1 deletion src/audio/dai-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,25 @@ static struct comp_dev *dai_new(const struct comp_driver *drv,
return NULL;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *dai_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
const struct sof_ipc_comp_dai *comp = spec;
struct ipc_config_dai dai;

if (IPC_TAIL_IS_SIZE_INVALID(*comp))
return NULL;

dai.dai_index = comp->dai_index;
dai.direction = comp->direction;
dai.type = comp->type;

return dai_new(drv, config, &dai);
}
#endif

void dai_common_free(struct dai_data *dd)
{
if (dd->group)
Expand Down Expand Up @@ -1109,7 +1128,7 @@ static const struct comp_driver comp_dai = {
.uid = SOF_RT_UUID(dai_uuid),
.tctx = &dai_comp_tr,
.ops = {
.create = dai_new,
.create = IPC3_SHIM(dai_new),
.free = dai_free,
.params = dai_params,
.dai_get_hw_params = dai_comp_get_hw_params,
Expand Down
21 changes: 20 additions & 1 deletion src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,25 @@ static struct comp_dev *dai_new(const struct comp_driver *drv,
return NULL;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *dai_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
const struct sof_ipc_comp_dai *comp = spec;
struct ipc_config_dai dai;

if (IPC_TAIL_IS_SIZE_INVALID(*comp))
return NULL;

dai.dai_index = comp->dai_index;
dai.direction = comp->direction;
dai.type = comp->type;

return dai_new(drv, config, &dai);
}
#endif

void dai_common_free(struct dai_data *dd)
{
#ifdef CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS
Expand Down Expand Up @@ -1919,7 +1938,7 @@ static const struct comp_driver comp_dai = {
.uid = SOF_RT_UUID(dai_uuid),
.tctx = &dai_comp_tr,
.ops = {
.create = dai_new,
.create = IPC3_SHIM(dai_new),
.free = dai_free,
.params = dai_params,
.dai_get_hw_params = dai_comp_get_hw_params,
Expand Down
2 changes: 1 addition & 1 deletion src/audio/google/google_ctc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static int ctc_process(struct processing_module *mod,
return 0;
}

static struct module_interface google_ctc_audio_processing_interface = {
static const struct module_interface google_ctc_audio_processing_interface = {
.init = ctc_init,
.free = ctc_free,
.process_audio_stream = ctc_process,
Expand Down
2 changes: 1 addition & 1 deletion src/audio/google/google_rtc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ static int mod_process(struct processing_module *mod, struct sof_source **source
return 0;
}

static struct module_interface google_rtc_audio_processing_interface = {
static const struct module_interface google_rtc_audio_processing_interface = {
.init = google_rtc_audio_processing_init,
.free = google_rtc_audio_processing_free,
.process = mod_process,
Expand Down
21 changes: 20 additions & 1 deletion src/audio/host-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,25 @@ static struct comp_dev *host_new(const struct comp_driver *drv,
return NULL;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *host_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
const struct sof_ipc_comp_host *comp = spec;
struct ipc_config_host host;

if (IPC_TAIL_IS_SIZE_INVALID(*comp))
return NULL;

host.direction = comp->direction;
host.no_irq = comp->no_irq;
host.dmac_config = comp->dmac_config;

return host_new(drv, config, &host);
}
#endif

void host_common_free(struct host_data *hd)
{
dma_put(hd->dma);
Expand Down Expand Up @@ -1004,7 +1023,7 @@ static const struct comp_driver comp_host = {
.uid = SOF_RT_UUID(host_uuid),
.tctx = &host_tr,
.ops = {
.create = host_new,
.create = IPC3_SHIM(host_new),
.free = host_free,
.params = host_params,
.reset = host_reset,
Expand Down
18 changes: 17 additions & 1 deletion src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,22 @@ static struct comp_dev *host_new(const struct comp_driver *drv,
return NULL;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *host_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
const struct sof_ipc_comp_host *comp = spec;
struct ipc_config_host host;

host.direction = comp->direction;
host.no_irq = comp->no_irq;
host.dmac_config = comp->dmac_config;

return host_new(drv, config, &host);
}
#endif

void host_common_free(struct host_data *hd)
{
dma_put(hd->dma);
Expand Down Expand Up @@ -1150,7 +1166,7 @@ static const struct comp_driver comp_host = {
.uid = SOF_RT_UUID(host_uuid),
.tctx = &host_tr,
.ops = {
.create = host_new,
.create = IPC3_SHIM(host_new),
.free = host_free,
.params = host_params,
.reset = host_reset,
Expand Down
16 changes: 15 additions & 1 deletion src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,20 @@ static struct comp_dev *kpb_new(const struct comp_driver *drv,
return dev;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *kpb_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
struct ipc_config_process proc;

if (comp_sof_process_to_ipc_process(spec, &proc) < 0)
return NULL;

return kpb_new(drv, config, &proc);
}
#endif

/**
* \brief Allocate history buffer.
* \param[in] kpb - KPB component data pointer.
Expand Down Expand Up @@ -2591,7 +2605,7 @@ static const struct comp_driver comp_kpb = {
.uid = SOF_RT_UUID(KPB_UUID),
.tctx = &kpb_tr,
.ops = {
.create = kpb_new,
.create = IPC3_SHIM(kpb_new),
.free = kpb_free,
.trigger = kpb_trigger,
.copy = kpb_copy,
Expand Down
69 changes: 2 additions & 67 deletions src/audio/module_adapter/module_adapter_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,73 +38,8 @@ int module_adapter_init_data(struct comp_dev *dev,
const struct comp_ipc_config *config,
const void *spec)
{
int ret;

const unsigned char *data = NULL;
uint32_t size = 0;

switch (config->type) {
case SOF_COMP_VOLUME:
{
const struct ipc_config_volume *ipc_volume = spec;

size = sizeof(*ipc_volume);
data = spec;
break;
}
case SOF_COMP_SRC:
{
const struct ipc_config_src *ipc_src = spec;

size = sizeof(*ipc_src);
data = spec;
break;
}
case SOF_COMP_ASRC:
{
const struct ipc_config_asrc *ipc_asrc = spec;

size = sizeof(*ipc_asrc);
data = spec;
break;
}
case SOF_COMP_MIXER:
break;
case SOF_COMP_EQ_IIR:
case SOF_COMP_EQ_FIR:
case SOF_COMP_KEYWORD_DETECT:
case SOF_COMP_KPB:
case SOF_COMP_SELECTOR:
case SOF_COMP_DEMUX:
case SOF_COMP_MUX:
case SOF_COMP_DCBLOCK:
case SOF_COMP_SMART_AMP:
case SOF_COMP_MODULE_ADAPTER:
case SOF_COMP_FILEREAD:
case SOF_COMP_FILEWRITE:
case SOF_COMP_NONE:
{
const struct ipc_config_process *ipc_module_adapter = spec;

size = ipc_module_adapter->size;
data = ipc_module_adapter->data;
break;
}
default:
comp_err(dev, "module_adapter_init_data() unsupported comp type %d", config->type);
return -EINVAL;
}

/* Copy initial config */
if (size) {
ret = module_load_config(dev, data, size);
if (ret < 0) {
comp_err(dev, "module_adapter_init_data() error %d: config loading has failed.",
ret);
return ret;
}
dst->init_data = dst->data;
}
// Downstream shim will copy and alloc the correct data
dst->init_data = dst->data;

return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions src/audio/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ static struct comp_dev *selector_new(const struct comp_driver *drv,
return dev;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *selector_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
struct ipc_config_process proc;

if (comp_sof_process_to_ipc_process(spec, &proc) < 0)
return NULL;

return selector_new(drv, config, &proc);
}
#endif

/**
* \brief Frees selector component.
* \param[in,out] dev Selector base component device.
Expand Down
16 changes: 15 additions & 1 deletion src/audio/smart_amp/smart_amp.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ static struct comp_dev *smart_amp_new(const struct comp_driver *drv,
return NULL;
}

#if CONFIG_IPC_MAJOR_3
static struct comp_dev *smart_amp_new_shim(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
struct ipc_config_process proc;

if (comp_sof_process_to_ipc_process(spec, &proc) < 0)
return NULL;

return smart_amp_new(drv, config, &proc);
}
#endif

static int smart_amp_set_config(struct comp_dev *dev,
struct sof_ipc_ctrl_data *cdata)
{
Expand Down Expand Up @@ -813,7 +827,7 @@ static const struct comp_driver comp_smart_amp = {
.uid = SOF_RT_UUID(UUID_SYM),
.tctx = &smart_amp_comp_tr,
.ops = {
.create = smart_amp_new,
.create = IPC3_SHIM(smart_amp_new),
.free = smart_amp_free,
.params = smart_amp_params,
.prepare = smart_amp_prepare,
Expand Down
28 changes: 27 additions & 1 deletion src/audio/src/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,34 @@ static int src_prepare(struct processing_module *mod,
return src_prepare_general(mod, sources[0], sinks[0]);
}

#if CONFIG_IPC_MAJOR_3
static int src_init_shim(struct processing_module *mod)
{
struct ipc_config_src *ipc_src;
struct module_data *mod_data = &mod->priv;
const struct sof_ipc_comp_src *src =
(const struct sof_ipc_comp_src *)mod_data->cfg.init_data;

if (IPC_TAIL_IS_SIZE_INVALID(*src))
return -EBADMSG;

ipc_src = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(*ipc_src));
if (!ipc_src)
return -ENOMEM;

ipc_src->source_rate = src->source_rate;
ipc_src->sink_rate = src->sink_rate;
ipc_src->rate_mask = src->rate_mask;

rfree(mod_data->cfg.data);
mod_data->cfg.init_data = ipc_src;
mod_data->cfg.data = ipc_src;
return src_init(mod);
}
#endif

static const struct module_interface src_interface = {
.init = src_init,
.init = IPC3_SHIM(src_init),
.prepare = src_prepare,
.process = src_process,
.is_ready_to_process = src_is_ready_to_process,
Expand Down
Loading
Loading