Skip to content
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
66 changes: 39 additions & 27 deletions src/audio/data_blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct comp_data_blob_handler {
uint32_t single_blob:1; /**< Allocate only one blob. Module can not
* be active while reconfguring.
*/
void *(*alloc)(size_t size); /**< alternate allocator, maybe null */
void (*free)(void *buf); /**< alternate free(), maybe null */
void *(*alloc)(struct comp_data_blob_handler *, size_t);/**< allocator, maybe null */
void (*free)(struct comp_data_blob_handler *, void *); /**< deallocator, maybe null */

/** validator for new data, maybe null */
int (*validator)(struct comp_dev *dev, void *new_data, uint32_t new_data_size);
Expand All @@ -43,8 +43,8 @@ static void comp_free_data_blob(struct comp_data_blob_handler *blob_handler)
if (!blob_handler->data)
return;

blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler->data_new);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data_new);
blob_handler->data = NULL;
blob_handler->data_new = NULL;
blob_handler->data_size = 0;
Expand Down Expand Up @@ -75,7 +75,7 @@ void *comp_get_data_blob(struct comp_data_blob_handler *blob_handler,
comp_dbg(blob_handler->dev, "new data available");

/* Free "old" data blob and set data to data_new pointer */
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = blob_handler->data_new;
blob_handler->data_size = blob_handler->new_data_size;

Expand Down Expand Up @@ -143,7 +143,7 @@ int comp_init_data_blob(struct comp_data_blob_handler *blob_handler,
return 0;

/* Data blob allocation */
blob_handler->data = blob_handler->alloc(size);
blob_handler->data = blob_handler->alloc(blob_handler, size);
if (!blob_handler->data) {
comp_err(blob_handler->dev, "model->data allocation failed");
return -ENOMEM;
Expand Down Expand Up @@ -232,7 +232,7 @@ int comp_data_blob_set(struct comp_data_blob_handler *blob_handler,

if (blob_handler->single_blob) {
if (data_offset_size != blob_handler->data_size) {
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = NULL;
} else {
blob_handler->data_new = blob_handler->data;
Expand All @@ -241,7 +241,7 @@ int comp_data_blob_set(struct comp_data_blob_handler *blob_handler,
}

if (!blob_handler->data_new) {
blob_handler->data_new = blob_handler->alloc(data_offset_size);
blob_handler->data_new = blob_handler->alloc(blob_handler, data_offset_size);
if (!blob_handler->data_new) {
comp_err(blob_handler->dev, "blob_handler->data_new allocation failed.");
return -ENOMEM;
Expand Down Expand Up @@ -277,7 +277,7 @@ int comp_data_blob_set(struct comp_data_blob_handler *blob_handler,
blob_handler->new_data_size);
if (ret < 0) {
comp_err(blob_handler->dev, "new data is invalid! discarding it...");
blob_handler->free(blob_handler->data_new);
blob_handler->free(blob_handler, blob_handler->data_new);
blob_handler->data_new = NULL;
return ret;
}
Expand All @@ -288,7 +288,7 @@ int comp_data_blob_set(struct comp_data_blob_handler *blob_handler,
* the new configuration presence is checked in copy().
*/
if (blob_handler->dev->state == COMP_STATE_READY) {
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = NULL;
}

Expand Down Expand Up @@ -347,7 +347,7 @@ int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler,

if (blob_handler->single_blob) {
if (data_offset != blob_handler->data_size) {
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = NULL;
} else {
blob_handler->data_new = blob_handler->data;
Expand All @@ -357,7 +357,7 @@ int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler,

if (!blob_handler->data_new) {
blob_handler->data_new =
blob_handler->alloc(data_offset);
blob_handler->alloc(blob_handler, data_offset);

if (!blob_handler->data_new) {
comp_err(blob_handler->dev,
Expand All @@ -376,7 +376,7 @@ int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler,
blob_handler->new_data_size, data, valid_data_size);
if (ret) {
comp_err(blob_handler->dev, "failed to copy fragment");
blob_handler->free(blob_handler->data_new);
blob_handler->free(blob_handler, blob_handler->data_new);
blob_handler->data_new = NULL;
blob_handler->new_data_size = 0;
blob_handler->data_pos = 0;
Expand Down Expand Up @@ -411,7 +411,7 @@ int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler,
data, valid_data_size);
if (ret) {
comp_err(blob_handler->dev, "failed to copy fragment");
blob_handler->free(blob_handler->data_new);
blob_handler->free(blob_handler, blob_handler->data_new);
blob_handler->data_new = NULL;
blob_handler->new_data_size = 0;
blob_handler->data_pos = 0;
Expand All @@ -431,7 +431,7 @@ int ipc4_comp_data_blob_set(struct comp_data_blob_handler *blob_handler,
* the new configuration presence is checked in copy().
*/
if (blob_handler->dev->state == COMP_STATE_READY) {
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = NULL;
}

Expand Down Expand Up @@ -510,7 +510,7 @@ int comp_data_blob_set_cmd(struct comp_data_blob_handler *blob_handler,

if (blob_handler->single_blob) {
if (cdata->data->size != blob_handler->data_size) {
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = NULL;
} else {
blob_handler->data_new = blob_handler->data;
Expand All @@ -520,7 +520,7 @@ int comp_data_blob_set_cmd(struct comp_data_blob_handler *blob_handler,

if (!blob_handler->data_new) {
blob_handler->data_new =
blob_handler->alloc(cdata->data->size);
blob_handler->alloc(blob_handler, cdata->data->size);
if (!blob_handler->data_new) {
comp_err(blob_handler->dev, "blob_handler->data_new allocation failed.");
return -ENOMEM;
Expand Down Expand Up @@ -556,7 +556,7 @@ int comp_data_blob_set_cmd(struct comp_data_blob_handler *blob_handler,
blob_handler->new_data_size);
if (ret < 0) {
comp_err(blob_handler->dev, "new data blob invalid, discarding");
blob_handler->free(blob_handler->data_new);
blob_handler->free(blob_handler, blob_handler->data_new);
blob_handler->data_new = NULL;
return ret;
}
Expand All @@ -567,7 +567,7 @@ int comp_data_blob_set_cmd(struct comp_data_blob_handler *blob_handler,
* the new configuration presence is checked in copy().
*/
if (blob_handler->dev->state == COMP_STATE_READY) {
blob_handler->free(blob_handler->data);
blob_handler->free(blob_handler, blob_handler->data);
blob_handler->data = NULL;
}

Expand Down Expand Up @@ -659,28 +659,37 @@ int comp_data_blob_get_cmd(struct comp_data_blob_handler *blob_handler,
}
EXPORT_SYMBOL(comp_data_blob_get_cmd);

static void *default_alloc(size_t size)
static void *default_alloc(struct comp_data_blob_handler *handler, size_t size)
{
if (handler->dev->mod)
return mod_alloc_ext(handler->dev->mod,
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_LARGE_BUFFER, size, 0);
return sof_heap_alloc(sof_sys_user_heap_get(),
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_LARGE_BUFFER, size, 0);
}

static void default_free(void *buf)
static void default_free(struct comp_data_blob_handler *handler, void *buf)
{
sof_heap_free(sof_sys_user_heap_get(), buf);
if (handler->dev->mod)
mod_free(handler->dev->mod, buf);
else
sof_heap_free(sof_sys_user_heap_get(), buf);
}

struct comp_data_blob_handler *
comp_data_blob_handler_new_ext(struct comp_dev *dev, bool single_blob,
void *(*alloc)(size_t size),
void (*free)(void *buf))
void *(*alloc)(struct comp_data_blob_handler *, size_t),
void (*free)(struct comp_data_blob_handler *, void *))
{
struct comp_data_blob_handler *handler;

comp_dbg(dev, "entry");

handler = sof_heap_alloc(sof_sys_user_heap_get(), SOF_MEM_FLAG_USER,
sizeof(struct comp_data_blob_handler), 0);
if (dev->mod)
handler = mod_alloc(dev->mod, sizeof(struct comp_data_blob_handler));
else
handler = sof_heap_alloc(sof_sys_user_heap_get(), SOF_MEM_FLAG_USER,
sizeof(struct comp_data_blob_handler), 0);

if (handler) {
memset(handler, 0, sizeof(*handler));
Expand All @@ -701,6 +710,9 @@ void comp_data_blob_handler_free(struct comp_data_blob_handler *blob_handler)

comp_free_data_blob(blob_handler);

sof_heap_free(sof_sys_user_heap_get(), blob_handler);
if (blob_handler->dev->mod)
mod_free(blob_handler->dev->mod, blob_handler);
else
sof_heap_free(sof_sys_user_heap_get(), blob_handler);
}
EXPORT_SYMBOL(comp_data_blob_handler_free);
30 changes: 21 additions & 9 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ int module_prepare(struct processing_module *mod,

#if CONFIG_SOF_USERSPACE_APPLICATION
if (dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
const union scheduler_dp_thread_ipc_param param = {
union scheduler_dp_thread_ipc_param param = {
.pipeline_state = {
.trigger_cmd = COMP_TRIGGER_PREPARE,
.state = SOF_IPC4_PIPELINE_STATE_RUNNING,
Expand Down Expand Up @@ -722,7 +722,7 @@ int module_reset(struct processing_module *mod)
if (ops->reset) {
#if CONFIG_SOF_USERSPACE_APPLICATION
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
const union scheduler_dp_thread_ipc_param param = {
union scheduler_dp_thread_ipc_param param = {
.pipeline_state.trigger_cmd = COMP_TRIGGER_STOP,
};
ret = scheduler_dp_thread_ipc(mod, SOF_IPC4_GLB_SET_PIPELINE_STATE, &param);
Expand Down Expand Up @@ -781,11 +781,23 @@ int module_free(struct processing_module *mod)
struct module_data *md = &mod->priv;
int ret = 0;

if (ops->free && (mod->dev->ipc_config.proc_domain != COMP_PROCESSING_DOMAIN_DP ||
!IS_ENABLED(CONFIG_SOF_USERSPACE_APPLICATION))) {
ret = ops->free(mod);
if (ret)
comp_warn(mod->dev, "error: %d", ret);
if (ops->free) {
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL ||
!IS_ENABLED(CONFIG_SOF_USERSPACE_APPLICATION)) {
ret = ops->free(mod);
if (ret)
comp_warn(mod->dev, "error: %d", ret);
#if CONFIG_SOF_USERSPACE_APPLICATION
} else {
/*
* Run DP module's .free() method in its thread context.
* Unlike with other IPCs we first run module's .free()
* in thread context, then cancel the thread, and then
* execute final clean up
*/
scheduler_dp_thread_ipc(mod, SOF_IPC4_MOD_DELETE_INSTANCE, NULL);
#endif
}
}

/* Free all memory shared by module_adapter & module */
Expand Down Expand Up @@ -939,7 +951,7 @@ int module_bind(struct processing_module *mod, const struct bind_info *bind_data
if (ops->bind) {
#if CONFIG_SOF_USERSPACE_APPLICATION
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
const union scheduler_dp_thread_ipc_param param = {
union scheduler_dp_thread_ipc_param param = {
.bind_data = bind_data,
};
ret = scheduler_dp_thread_ipc(mod, SOF_IPC4_MOD_BIND, &param);
Expand Down Expand Up @@ -972,7 +984,7 @@ int module_unbind(struct processing_module *mod, const struct bind_info *unbind_
if (ops->unbind) {
#if CONFIG_SOF_USERSPACE_APPLICATION
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
const union scheduler_dp_thread_ipc_param param = {
union scheduler_dp_thread_ipc_param param = {
.bind_data = unbind_data,
};
ret = scheduler_dp_thread_ipc(mod, SOF_IPC4_MOD_UNBIND, &param);
Expand Down
13 changes: 1 addition & 12 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ int module_adapter_trigger(struct comp_dev *dev, int cmd)
#if CONFIG_SOF_USERSPACE_APPLICATION
if (dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
/* Process DP module's trigger */
const union scheduler_dp_thread_ipc_param param = {
union scheduler_dp_thread_ipc_param param = {
.pipeline_state.trigger_cmd = cmd,
};
return scheduler_dp_thread_ipc(mod, SOF_IPC4_GLB_SET_PIPELINE_STATE,
Expand Down Expand Up @@ -1483,17 +1483,6 @@ void module_adapter_free(struct comp_dev *dev)

comp_dbg(dev, "start");

#if CONFIG_SOF_USERSPACE_APPLICATION
if (dev->task)
/*
* Run DP module's .free() method in its thread context.
* Unlike with other IPCs we first run module's .free() in
* thread context, then cancel the thread, and then execute
* final clean up
*/
scheduler_dp_thread_ipc(mod, SOF_IPC4_MOD_DELETE_INSTANCE, NULL);
#endif

ret = module_free(mod);
if (ret)
comp_err(dev, "failed with error: %d", ret);
Expand Down
52 changes: 45 additions & 7 deletions src/audio/module_adapter/module_adapter_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <sof/lib/mailbox.h>
#include <sof/platform.h>
#include <sof/ut.h>
#include <sof/schedule/dp_schedule.h>
#include <module/module/interface.h>
#include <rtos/interrupt.h>
#include <rtos/symbol.h>
#include <ipc4/base_fw.h>
Expand Down Expand Up @@ -263,10 +265,27 @@ int module_set_large_config(struct comp_dev *dev, uint32_t param_id, bool first_
return -EINVAL;
}

if (interface->set_configuration)
return interface->set_configuration(mod, param_id, pos, data_offset_size,
(const uint8_t *)data, fragment_size,
NULL, 0);
if (interface->set_configuration) {
#if CONFIG_SOF_USERSPACE_APPLICATION
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
union scheduler_dp_thread_ipc_param param = {
.set_config = {
.param_id = param_id,
.position = pos,
.data_offset_size = data_offset_size,
.data = data,
.fragment_size = fragment_size,
},
};

return scheduler_dp_thread_ipc(mod, SOF_IPC4_MOD_LARGE_CONFIG_SET, &param);
} else
#endif
return interface->set_configuration(mod, param_id, pos, data_offset_size,
(const uint8_t *)data, fragment_size,
NULL, 0);
}

return 0;
}

Expand Down Expand Up @@ -297,9 +316,28 @@ int module_get_large_config(struct comp_dev *dev, uint32_t param_id, bool first_
}
}

if (interface->get_configuration)
return interface->get_configuration(mod, param_id, data_offset_size,
(uint8_t *)data, fragment_size);
if (interface->get_configuration) {
#if CONFIG_SOF_USERSPACE_APPLICATION
if (mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
union scheduler_dp_thread_ipc_param param = {
.get_config = {
.param_id = param_id,
.data_offset_size = *data_offset_size,
.data = data,
.fragment_size = fragment_size,
},
};

int ret = scheduler_dp_thread_ipc(mod, SOF_IPC4_MOD_LARGE_CONFIG_SET,
&param);
if (!ret)
*data_offset_size = param.get_config.data_offset_size;
} else
#endif
return interface->get_configuration(mod, param_id, data_offset_size,
(uint8_t *)data, fragment_size);
}

/*
* Return error if getter is not implemented. Otherwise, the host will suppose
* the GET_VALUE command is successful, but the received cdata is not filled.
Expand Down
13 changes: 0 additions & 13 deletions src/include/ipc4/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ int ipc4_user_module_load(const struct comp_driver *drv,
int ipc4_process_module_config(struct ipc4_message_request *ipc4,
bool set, uint32_t *reply_ext);

/**
* @brief Process MOD_LARGE_CONFIG_GET in any execution context.
* @param[in] ipc4 IPC4 message request.
* @param[out] reply_ext Receives extension value for reply.
* @param[out] reply_tx_size Receives TX data size for reply.
* @param[out] reply_tx_data Receives TX data pointer for reply.
* @return IPC4 status code (0 on success).
*/
int ipc4_process_large_config_get(struct ipc4_message_request *ipc4,
uint32_t *reply_ext,
uint32_t *reply_tx_size,
void **reply_tx_data);

/**
* @brief Process MOD_LARGE_CONFIG_SET in any execution context.
* @param[in] ipc4 IPC4 message request.
Expand Down
Loading
Loading