Skip to content
52 changes: 46 additions & 6 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ EXPORT_SYMBOL(mod_balloc_align);
*
* The allocated memory is automatically freed when the module is unloaded.
*/
void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size, size_t alignment)
void *z_impl_mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
size_t alignment)
{
struct module_resources *res = &mod->priv.resources;
struct module_resource *container;
Expand Down Expand Up @@ -281,7 +282,7 @@ void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,

return ptr;
}
EXPORT_SYMBOL(mod_alloc_ext);
EXPORT_SYMBOL(z_impl_mod_alloc_ext);

/**
* Creates a blob handler and releases it when the module is unloaded
Expand Down Expand Up @@ -327,7 +328,8 @@ EXPORT_SYMBOL(mod_data_blob_handler_new);
* Like fast_get() but the handler is automatically freed.
*/
#if CONFIG_FAST_GET
const void *mod_fast_get(struct processing_module *mod, const void * const dram_ptr, size_t size)
const void *z_impl_mod_fast_get(struct processing_module *mod, const void * const dram_ptr,
size_t size)
{
struct module_resources *res = &mod->priv.resources;
struct module_resource *container;
Expand All @@ -352,7 +354,7 @@ const void *mod_fast_get(struct processing_module *mod, const void * const dram_

return ptr;
}
EXPORT_SYMBOL(mod_fast_get);
EXPORT_SYMBOL(z_impl_mod_fast_get);
#endif

static int free_contents(struct processing_module *mod, struct module_resource *container)
Expand Down Expand Up @@ -385,7 +387,7 @@ static int free_contents(struct processing_module *mod, struct module_resource *
* @param mod Pointer to module this memory block was allocated for.
* @param ptr Pointer to the memory block.
*/
int mod_free(struct processing_module *mod, const void *ptr)
int z_impl_mod_free(struct processing_module *mod, const void *ptr)
{
struct module_resources *res = &mod->priv.resources;
struct module_resource *container;
Expand All @@ -411,7 +413,45 @@ int mod_free(struct processing_module *mod, const void *ptr)

return -EINVAL;
}
EXPORT_SYMBOL(mod_free);
EXPORT_SYMBOL(z_impl_mod_free);

#ifdef CONFIG_USERSPACE
const void *z_vrfy_mod_fast_get(struct processing_module *mod, const void * const dram_ptr,
size_t size)
{
struct module_resources *res = &mod->priv.resources;

K_OOPS(K_SYSCALL_MEMORY_WRITE(mod, sizeof(*mod)));
K_OOPS(K_SYSCALL_MEMORY_WRITE(res->heap, sizeof(*res->heap)));
K_OOPS(K_SYSCALL_MEMORY_READ(dram_ptr, size));

return z_impl_mod_fast_get(mod, dram_ptr, size);
}
#include <zephyr/syscalls/mod_fast_get_mrsh.c>

void *z_vrfy_mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
size_t alignment)
{
struct module_resources *res = &mod->priv.resources;

K_OOPS(K_SYSCALL_MEMORY_WRITE(mod, sizeof(*mod)));
K_OOPS(K_SYSCALL_MEMORY_WRITE(res->heap, sizeof(*res->heap)));

return z_impl_mod_alloc_ext(mod, flags, size, alignment);
}
#include <zephyr/syscalls/mod_alloc_ext_mrsh.c>

int z_vrfy_mod_free(struct processing_module *mod, const void *ptr)
{
struct module_resources *res = &mod->priv.resources;

K_OOPS(K_SYSCALL_MEMORY_WRITE(mod, sizeof(*mod)));
K_OOPS(K_SYSCALL_MEMORY_WRITE(res->heap, sizeof(*res->heap)));

return z_impl_mod_free(mod, ptr);
}
#include <zephyr/syscalls/mod_free_mrsh.c>
#endif

#if CONFIG_COMP_BLOB
void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_blob_handler *dbh)
Expand Down
11 changes: 8 additions & 3 deletions src/include/sof/audio/module_adapter/module/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#if CONFIG_MODULE_MEMORY_API_DEBUG && defined(__ZEPHYR__)
#include <zephyr/kernel/thread.h>
#endif
#include <sof/compiler_attributes.h>

/*
* helpers to determine processing type
Expand Down Expand Up @@ -190,7 +191,9 @@ struct module_processing_data {
int module_load_config(struct comp_dev *dev, const void *cfg, size_t size);
int module_init(struct processing_module *mod);
void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignment);
void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size, size_t alignment);
__syscall void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
size_t alignment);
__syscall int mod_free(struct processing_module *mod, const void *ptr);

/**
* Allocates aligned memory block for module.
Expand Down Expand Up @@ -226,20 +229,22 @@ static inline void *mod_zalloc(struct processing_module *mod, size_t size)
return ret;
}

int mod_free(struct processing_module *mod, const void *ptr);
#if CONFIG_COMP_BLOB
struct comp_data_blob_handler *mod_data_blob_handler_new(struct processing_module *mod);
void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_blob_handler *dbh);
#endif
#if CONFIG_FAST_GET
const void *mod_fast_get(struct processing_module *mod, const void * const dram_ptr, size_t size);
__syscall const void *mod_fast_get(struct processing_module *mod, const void * const dram_ptr,
size_t size);
void mod_fast_put(struct processing_module *mod, const void *sram_ptr);
#endif
void mod_free_all(struct processing_module *mod);
int module_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks);

#include <zephyr/syscalls/generic.h>

static inline
bool generic_module_is_ready_to_process(struct processing_module *mod,
struct sof_source **sources,
Expand Down
1 change: 1 addition & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ zephyr_library_sources_ifdef(CONFIG_SHELL
sof_shell.c
)

zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/audio/module_adapter/module/generic.h)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/lib/fast-get.h)

zephyr_library_link_libraries(SOF)
Expand Down