Skip to content

Commit 04bca06

Browse files
author
Jyri Sarha
committed
modules: Add mod_fast_get() and mod_fast_put()
Add module API versions of fast_get() and fast_put(). The SRAM copies reserved with mod_fast_get() are released automatically when the module unloads, and those SRAM copies should not be freed with the regular fast_put(). Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 9f4544e commit 04bca06

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <sof/audio/module_adapter/module/generic.h>
1717
#include <sof/audio/data_blob.h>
18+
#include <sof/lib/fast-get.h>
1819

1920
LOG_MODULE_DECLARE(module_adapter, CONFIG_SOF_LOG_LEVEL);
2021

@@ -269,6 +270,39 @@ mod_data_blob_handler_new(struct processing_module *mod)
269270
EXPORT_SYMBOL(mod_data_blob_handler_new);
270271
#endif
271272

273+
/**
274+
* Make a module associated shared SRAM copy of DRAM read-only data.
275+
* @param mod Pointer to module this copy is allocated for.
276+
* @return Pointer to the SRAM copy.
277+
*
278+
* Like fast_get() but the handler is automatically freed.
279+
*/
280+
#if CONFIG_FAST_GET
281+
const void *mod_fast_get(struct processing_module *mod, const void * const dram_ptr, size_t size)
282+
{
283+
struct module_resources *res = &mod->priv.resources;
284+
struct module_memory *container = container_get(mod);
285+
const void *ptr;
286+
287+
if (!container)
288+
return NULL;
289+
290+
ptr = fast_get(dram_ptr, size);
291+
if (!ptr) {
292+
container_put(mod, container);
293+
return NULL;
294+
}
295+
296+
container->ptr = (void *)ptr;
297+
container->size = 0;
298+
container->free = (void (*)(void *))fast_put;
299+
list_item_prepend(&container->mem_list, &res->mem_list);
300+
301+
return ptr;
302+
}
303+
EXPORT_SYMBOL(mod_fast_get);
304+
#endif
305+
272306
/**
273307
* Frees the memory block removes it from module's book keeping.
274308
* @param mod Pointer to module this memory block was allocated for.
@@ -315,6 +349,14 @@ void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_
315349
EXPORT_SYMBOL(mod_data_blob_handler_free);
316350
#endif
317351

352+
#if CONFIG_FAST_GET
353+
void mod_fast_put(struct processing_module *mod, const void *sram_ptr)
354+
{
355+
mod_free(mod, (void *)sram_ptr);
356+
}
357+
EXPORT_SYMBOL(mod_fast_put);
358+
#endif
359+
318360
int module_prepare(struct processing_module *mod,
319361
struct sof_source **sources, int num_of_sources,
320362
struct sof_sink **sinks, int num_of_sinks)

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ int mod_free(struct processing_module *mod, void *ptr);
175175
struct comp_data_blob_handler *mod_data_blob_handler_new(struct processing_module *mod);
176176
void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_blob_handler *dbh);
177177
#endif
178+
#if CONFIG_FAST_GET
179+
const void *mod_fast_get(struct processing_module *mod, const void * const dram_ptr, size_t size);
180+
void mod_fast_put(struct processing_module *mod, const void *sram_ptr);
181+
#endif
178182
void mod_free_all(struct processing_module *mod);
179183
int module_prepare(struct processing_module *mod,
180184
struct sof_source **sources, int num_of_sources,

0 commit comments

Comments
 (0)