Skip to content

Commit bc82b88

Browse files
committed
llext: move the llext pointer to struct lib_manager_mod_ctx
The LLEXT context is currently bound to the Module Adapter API which shouldn't be the case because we also need generic LLEXT-based loadable SOF objects. This patch moves the context to struct lib_manager_mod_ctx which is safe, because the library manager is always needed when dynamically loading modules. Signed-off-by: Guennadi Liakhovetski <[email protected]>
1 parent 2cd9308 commit bc82b88

File tree

6 files changed

+17
-28
lines changed

6 files changed

+17
-28
lines changed

src/audio/module_adapter/module/modules.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static int modules_init(struct processing_module *mod)
6161
const struct comp_ipc_config *config = &dev->ipc_config;
6262
void *system_agent;
6363

64-
uintptr_t module_entry_point = lib_manager_allocate_module(mod, config, src_cfg);
64+
uintptr_t module_entry_point = lib_manager_allocate_module(config, src_cfg);
6565

6666
if (module_entry_point == 0) {
6767
comp_err(dev, "modules_init(), lib_manager_allocate_module() failed!");

src/include/module/module/base.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ struct module_config {
3737
#endif
3838
};
3939

40-
struct llext;
41-
4240
/*
4341
* A structure containing a module's private data, intended for its exclusive use.
4442
*
@@ -60,7 +58,6 @@ struct module_data {
6058
void *runtime_params;
6159
struct module_memory memory; /**< memory allocated by module */
6260
struct module_processing_data mpd; /**< shared data comp <-> module */
63-
struct llext *llext; /**< Zephyr loadable extension context */
6461
#endif /* SOF_MODULE_PRIVATE */
6562
};
6663

src/include/sof/lib_manager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ struct lib_manager_segment_desc {
9797
size_t file_offset;
9898
};
9999

100+
struct llext;
101+
100102
struct lib_manager_mod_ctx {
101103
void *base_addr;
102104
const struct sof_man_module_manifest *mod_manifest;
105+
struct llext *llext; /**< Zephyr loadable extension context */
103106
struct lib_manager_segment_desc segment[LIB_MANAGER_N_SEGMENTS];
104107
};
105108

@@ -184,8 +187,7 @@ struct processing_module;
184187
* Function is responsible to allocate module in available free memory and assigning proper address.
185188
* (WIP) These feature will contain module validation and proper memory management.
186189
*/
187-
uintptr_t lib_manager_allocate_module(struct processing_module *proc,
188-
const struct comp_ipc_config *ipc_config,
190+
uintptr_t lib_manager_allocate_module(const struct comp_ipc_config *ipc_config,
189191
const void *ipc_specific_config);
190192

191193
/*

src/include/sof/llext_manager.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ static inline bool module_is_llext(const struct sof_man_module *mod)
2222
mod->type.load_type == SOF_MAN_MOD_TYPE_LLEXT_AUX;
2323
}
2424

25-
uintptr_t llext_manager_allocate_module(struct processing_module *proc,
26-
const struct comp_ipc_config *ipc_config,
25+
uintptr_t llext_manager_allocate_module(const struct comp_ipc_config *ipc_config,
2726
const void *ipc_specific_config);
2827

2928
int llext_manager_free_module(const uint32_t component_id);
3029

3130
bool comp_is_llext(struct comp_dev *comp);
3231
#else
3332
#define module_is_llext(mod) false
34-
#define llext_manager_allocate_module(proc, ipc_config, ipc_specific_config) 0
33+
#define llext_manager_allocate_module(ipc_config, ipc_specific_config) 0
3534
#define llext_manager_free_module(component_id) 0
3635
#define llext_unload(ext) 0
3736
#define comp_is_llext(comp) false

src/library_manager/lib_manager.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ static int lib_manager_free_module_instance(uint32_t module_id, uint32_t instanc
339339
return sys_mm_drv_unmap_region((__sparse_force void *)va_base, bss_size);
340340
}
341341

342-
uintptr_t lib_manager_allocate_module(struct processing_module *proc,
343-
const struct comp_ipc_config *ipc_config,
342+
uintptr_t lib_manager_allocate_module(const struct comp_ipc_config *ipc_config,
344343
const void *ipc_specific_config)
345344
{
346345
const struct sof_man_module *mod;
@@ -359,7 +358,7 @@ uintptr_t lib_manager_allocate_module(struct processing_module *proc,
359358
}
360359

361360
if (module_is_llext(mod))
362-
return llext_manager_allocate_module(proc, ipc_config, ipc_specific_config);
361+
return llext_manager_allocate_module(ipc_config, ipc_specific_config);
363362

364363
ret = lib_manager_load_module(module_id, mod);
365364
if (ret < 0)
@@ -424,8 +423,7 @@ int lib_manager_free_module(const uint32_t component_id)
424423

425424
#define PAGE_SZ 4096 /* equals to MAN_PAGE_SIZE used by rimage */
426425

427-
uintptr_t lib_manager_allocate_module(struct processing_module *proc,
428-
const struct comp_ipc_config *ipc_config,
426+
uintptr_t lib_manager_allocate_module(const struct comp_ipc_config *ipc_config,
429427
const void *ipc_specific_config, const void **buildinfo)
430428
{
431429
tr_err(&lib_manager_tr,
@@ -517,12 +515,10 @@ static struct comp_dev *lib_manager_module_create(const struct comp_driver *drv,
517515
* Variable used by llext_manager to temporary store llext handle before creation
518516
* a instance of processing_module.
519517
*/
520-
struct processing_module tmp_proc;
521518
struct comp_dev *dev;
522519

523520
/* At this point module resources are allocated and it is moved to L2 memory. */
524-
tmp_proc.priv.llext = NULL;
525-
const uint32_t module_entry_point = lib_manager_allocate_module(&tmp_proc, config,
521+
const uint32_t module_entry_point = lib_manager_allocate_module(config,
526522
args->data);
527523

528524
if (!module_entry_point) {
@@ -549,28 +545,24 @@ static struct comp_dev *lib_manager_module_create(const struct comp_driver *drv,
549545
}
550546

551547
dev = module_adapter_new(drv, config, spec);
552-
if (dev) {
553-
struct processing_module *mod = comp_mod(dev);
554-
555-
mod->priv.llext = tmp_proc.priv.llext;
556-
} else {
548+
if (!dev)
557549
lib_manager_free_module(module_id);
558-
}
550+
559551
return dev;
560552
}
561553

562554
static void lib_manager_module_free(struct comp_dev *dev)
563555
{
564556
struct processing_module *mod = comp_mod(dev);
565-
struct llext *llext = mod->priv.llext;
566557
const struct comp_ipc_config *const config = &mod->dev->ipc_config;
567558
const uint32_t module_id = config->id;
559+
struct lib_manager_mod_ctx *ctx = lib_manager_get_mod_ctx(module_id);
568560
int ret;
569561

570562
/* This call invalidates dev, mod and config pointers! */
571563
module_adapter_free(dev);
572564

573-
if (!llext || !llext_unload(&llext)) {
565+
if (!ctx->llext || !llext_unload(&ctx->llext)) {
574566
/* Free module resources allocated in L2 memory. */
575567
ret = lib_manager_free_module(module_id);
576568
if (ret < 0)

src/library_manager/llext_manager.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ static int llext_manager_link(struct sof_man_fw_desc *desc, struct sof_man_modul
291291
return binfo_o >= 0 && mod_o >= 0 ? 0 : -EPROTO;
292292
}
293293

294-
uintptr_t llext_manager_allocate_module(struct processing_module *proc,
295-
const struct comp_ipc_config *ipc_config,
294+
uintptr_t llext_manager_allocate_module(const struct comp_ipc_config *ipc_config,
296295
const void *ipc_specific_config)
297296
{
298297
struct sof_man_fw_desc *desc;
@@ -317,7 +316,7 @@ uintptr_t llext_manager_allocate_module(struct processing_module *proc,
317316
mod_array = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(0));
318317

319318
/* LLEXT linking is only needed once for all the modules in the library */
320-
ret = llext_manager_link(desc, mod_array, module_id, &proc->priv.llext,
319+
ret = llext_manager_link(desc, mod_array, module_id, &ctx->llext,
321320
(const void **)&buildinfo, &mod_manifest);
322321
if (ret < 0)
323322
return 0;

0 commit comments

Comments
 (0)