Skip to content

Commit 80ee3da

Browse files
Jyri Sarhakv2019i
authored andcommitted
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(). The sram-copy allocated with mod_fast_get() should not be freed with regular fast_put(), but mod_fast_put() should be used. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 1b1e8f1 commit 80ee3da

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/audio/module_adapter/module/generic.c

Lines changed: 47 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_resource *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->sram_ptr = ptr;
297+
container->size = 0;
298+
container->type = MOD_RES_FAST_GET;
299+
list_item_prepend(&container->list, &res->res_list);
300+
301+
return ptr;
302+
}
303+
EXPORT_SYMBOL(mod_fast_get);
304+
#endif
305+
272306
static int free_contents(struct processing_module *mod, struct module_resource *container)
273307
{
274308
struct module_resources *res = &mod->priv.resources;
@@ -282,6 +316,11 @@ static int free_contents(struct processing_module *mod, struct module_resource *
282316
case MOD_RES_BLOB_HANDLER:
283317
comp_data_blob_handler_free(container->bhp);
284318
return 0;
319+
#endif
320+
#if CONFIG_FAST_GET
321+
case MOD_RES_FAST_GET:
322+
fast_put(container->sram_ptr);
323+
return 0;
285324
#endif
286325
default:
287326
comp_err(mod->dev, "Unknown resource type: %d", container->type);
@@ -331,6 +370,14 @@ void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_
331370
EXPORT_SYMBOL(mod_data_blob_handler_free);
332371
#endif
333372

373+
#if CONFIG_FAST_GET
374+
void mod_fast_put(struct processing_module *mod, const void *sram_ptr)
375+
{
376+
mod_free(mod, sram_ptr);
377+
}
378+
EXPORT_SYMBOL(mod_fast_put);
379+
#endif
380+
334381
int module_prepare(struct processing_module *mod,
335382
struct sof_source **sources, int num_of_sources,
336383
struct sof_sink **sinks, int num_of_sinks)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ enum mod_resource_type {
133133
MOD_RES_UNINITIALIZED = 0,
134134
MOD_RES_HEAP,
135135
MOD_RES_BLOB_HANDLER,
136+
MOD_RES_FAST_GET,
136137
};
137138

138139
/**
@@ -143,6 +144,7 @@ struct module_resource {
143144
union {
144145
void *ptr; /**< Pointer to heap allocated memory */
145146
struct comp_data_blob_handler *bhp; /**< Blob handler ptr */
147+
const void *sram_ptr; /**< SRAM ptr from fast_get() */
146148
};
147149
struct list_item list; /**< list element */
148150
size_t size; /**< Size of allocated heap memory, 0 if not from heap */
@@ -186,6 +188,10 @@ int mod_free(struct processing_module *mod, const void *ptr);
186188
struct comp_data_blob_handler *mod_data_blob_handler_new(struct processing_module *mod);
187189
void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_blob_handler *dbh);
188190
#endif
191+
#if CONFIG_FAST_GET
192+
const void *mod_fast_get(struct processing_module *mod, const void * const dram_ptr, size_t size);
193+
void mod_fast_put(struct processing_module *mod, const void *sram_ptr);
194+
#endif
189195
void mod_free_all(struct processing_module *mod);
190196
int module_prepare(struct processing_module *mod,
191197
struct sof_source **sources, int num_of_sources,

0 commit comments

Comments
 (0)