Skip to content

Commit

Permalink
lib_manager: Add lib_manager_get_module_manifest function
Browse files Browse the repository at this point in the history
Added the lib_manager_get_module_manifest function that returns manifest
of selected module based on its id. It was performed in many places and
moving it into function simplified the code and increased its readability.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki committed Mar 22, 2024
1 parent 11d8a42 commit ca42dff
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 38 deletions.
15 changes: 7 additions & 8 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@ static int modules_new(struct processing_module *mod, const void *buildinfo,
uint32_t log_handle = (uint32_t) dev->drv->tctx;
/* Connect loadable module interfaces with module adapter entity. */
/* Check if native Zephyr lib is loaded */
struct sof_man_fw_desc *desc = lib_manager_get_library_module_desc(module_id);

if (!desc) {
comp_err(dev, "modules_init(): Failed to load manifest");
return -ENOMEM;
}

const struct sof_module_api_build_info *mod_buildinfo;

if (buildinfo) {
mod_buildinfo = buildinfo;
} else {
struct sof_man_module *module_entry =
(struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(0));
const struct sof_man_module *const module_entry =
lib_manager_get_module_manifest(module_id);

if (!module_entry) {
comp_err(dev, "modules_new(): Failed to load manifest");
return -ENODATA;
}

mod_buildinfo =
(struct sof_module_api_build_info *)
Expand Down
9 changes: 9 additions & 0 deletions src/include/sof/lib_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ static inline struct lib_manager_mod_ctx *lib_manager_get_mod_ctx(int module_id)

return _ext_lib->desc[lib_id];
}

/*
* \brief Get module manifest for given module id
*
* param[in] module_id - used to get library manifest
*
* Gets library manifest descriptor using module_id to locate it
*/
const struct sof_man_module *lib_manager_get_module_manifest(const uint32_t module_id);
#endif

/*
Expand Down
28 changes: 20 additions & 8 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,20 +944,20 @@ static const struct comp_driver *ipc4_library_get_drv(int module_id)

const struct comp_driver *ipc4_get_comp_drv(uint32_t module_id)
{
struct sof_man_fw_desc *desc = NULL;
const struct sof_man_fw_desc *desc = NULL;
const struct comp_driver *drv;
struct sof_man_module *mod;
const struct sof_man_module *mod;
uint32_t entry_index;

#if CONFIG_LIBRARY
return ipc4_library_get_drv(module_id);
#endif

#ifdef RIMAGE_MANIFEST
desc = (struct sof_man_fw_desc *)IMR_BOOT_LDR_MANIFEST_BASE;
desc = (const struct sof_man_fw_desc *)IMR_BOOT_LDR_MANIFEST_BASE;
#else
/* Non-rimage platforms have no component facility yet. This
* needs to move to the platform layer.
/* Non-rimage platforms have no component facility yet.
* This needs to move to the platform layer.
*/
return NULL;
#endif
Expand All @@ -970,21 +970,33 @@ const struct comp_driver *ipc4_get_comp_drv(uint32_t module_id)
entry_index = 1;
else
entry_index = module_id;

if (entry_index >= desc->header.num_module_entries) {
tr_err(&comp_tr, "Error: entry index %d out of bounds.", entry_index);
return NULL;
}

mod = (const struct sof_man_module *)((const char *)desc +
SOF_MAN_MODULE_OFFSET(entry_index));
} else {
/* Library index greater than 0 possible only when LIBRARY_MANAGER
* support enabled.
*/
#if CONFIG_LIBRARY_MANAGER
desc = lib_manager_get_library_module_desc(module_id);
entry_index = LIB_MANAGER_GET_MODULE_INDEX(module_id);
mod = lib_manager_get_module_manifest(module_id);

if (!mod) {
tr_err(&comp_tr, "Error: Couldn't find loadable module with id %d.",
module_id);
return NULL;
}
#else
tr_err(&comp_tr, "Error: lib index:%d, while loadable libraries are not supported!!!",
lib_idx);
return NULL;
#endif
}
/* Check already registered components */
mod = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(entry_index));
drv = ipc4_get_drv(mod->uuid);

#if CONFIG_LIBRARY_MANAGER
Expand Down
50 changes: 32 additions & 18 deletions src/library_manager/lib_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ static int lib_manager_unload_module(const struct sof_man_module *const mod)
/* There are modules marked as lib_code. This is code shared between several modules inside
* the library. Load all lib_code modules with first none lib_code module load.
*/
static int lib_manager_load_libcode_modules(const uint32_t module_id,
const struct sof_man_fw_desc *const desc)
static int lib_manager_load_libcode_modules(const uint32_t module_id)
{
const struct sof_man_fw_desc *const desc = lib_manager_get_library_module_desc(module_id);
struct ext_library *const ext_lib = ext_lib_get();
const struct sof_man_module *module_entry = (struct sof_man_module *)
((char *)desc + SOF_MAN_MODULE_OFFSET(0));
Expand Down Expand Up @@ -250,12 +250,12 @@ static int lib_manager_load_libcode_modules(const uint32_t module_id,
/* There are modules marked as lib_code. This is code shared between several modules inside
* the library. Unload all lib_code modules with last none lib_code module unload.
*/
static int lib_manager_unload_libcode_modules(const uint32_t module_id,
const struct sof_man_fw_desc *const desc)
static int lib_manager_unload_libcode_modules(const uint32_t module_id)
{
struct ext_library *const ext_lib = ext_lib_get();
const struct sof_man_fw_desc *const desc = lib_manager_get_library_module_desc(module_id);
const struct sof_man_module *module_entry = (struct sof_man_module *)
((char *)desc + SOF_MAN_MODULE_OFFSET(0));
struct ext_library *const ext_lib = ext_lib_get();
int ret, idx;

if (--ext_lib->mods_exec_load_cnt > 0)
Expand Down Expand Up @@ -342,25 +342,21 @@ uintptr_t lib_manager_allocate_module(struct processing_module *proc,
const struct comp_ipc_config *ipc_config,
const void *ipc_specific_config, const void **buildinfo)
{
struct sof_man_fw_desc *desc;
const struct sof_man_module *mod;
const struct ipc4_base_module_cfg *base_cfg = ipc_specific_config;
int ret;
uint32_t module_id = IPC4_MOD_ID(ipc_config->id);
uint32_t entry_index = LIB_MANAGER_GET_MODULE_INDEX(module_id);

tr_dbg(&lib_manager_tr, "lib_manager_allocate_module(): mod_id: %#x",
ipc_config->id);

desc = lib_manager_get_library_module_desc(module_id);
if (!desc) {
mod = lib_manager_get_module_manifest(module_id);
if (!mod) {
tr_err(&lib_manager_tr,
"lib_manager_allocate_module(): failed to get module descriptor");
return 0;
}

mod = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(entry_index));

if (module_is_llext(mod))
return llext_manager_allocate_module(proc, ipc_config, ipc_specific_config,
buildinfo);
Expand All @@ -370,7 +366,7 @@ uintptr_t lib_manager_allocate_module(struct processing_module *proc,
return 0;

#ifdef CONFIG_LIBCODE_MODULE_SUPPORT
ret = lib_manager_load_libcode_modules(module_id, desc);
ret = lib_manager_load_libcode_modules(module_id);
if (ret < 0)
goto err;
#endif /* CONFIG_LIBCODE_MODULE_SUPPORT */
Expand All @@ -381,7 +377,7 @@ uintptr_t lib_manager_allocate_module(struct processing_module *proc,
tr_err(&lib_manager_tr,
"lib_manager_allocate_module(): module allocation failed: %d", ret);
#ifdef CONFIG_LIBCODE_MODULE_SUPPORT
lib_manager_unload_libcode_modules(module_id, desc);
lib_manager_unload_libcode_modules(module_id);
#endif /* CONFIG_LIBCODE_MODULE_SUPPORT */
goto err;
}
Expand All @@ -394,16 +390,13 @@ uintptr_t lib_manager_allocate_module(struct processing_module *proc,

int lib_manager_free_module(const uint32_t component_id)
{
struct sof_man_fw_desc *desc;
const struct sof_man_module *mod;
const uint32_t module_id = IPC4_MOD_ID(component_id);
uint32_t entry_index = LIB_MANAGER_GET_MODULE_INDEX(module_id);
int ret;

tr_dbg(&lib_manager_tr, "lib_manager_free_module(): mod_id: %#x", component_id);

desc = lib_manager_get_library_module_desc(module_id);
mod = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(entry_index));
mod = lib_manager_get_module_manifest(module_id);

if (module_is_llext(mod))
return llext_manager_free_module(component_id);
Expand All @@ -413,7 +406,7 @@ int lib_manager_free_module(const uint32_t component_id)
return ret;

#ifdef CONFIG_LIBCODE_MODULE_SUPPORT
ret = lib_manager_unload_libcode_modules(module_id, desc);
ret = lib_manager_unload_libcode_modules(module_id);
if (ret < 0)
return ret;
#endif /* CONFIG_LIBCODE_MODULE_SUPPORT */
Expand Down Expand Up @@ -480,6 +473,27 @@ static void lib_manager_update_sof_ctx(void *base_addr, uint32_t lib_id)
/* TODO: maybe need to call dcache_writeback here? */
}

const struct sof_man_module *lib_manager_get_module_manifest(const uint32_t module_id)
{
const uint32_t entry_index = LIB_MANAGER_GET_MODULE_INDEX(module_id);
const struct lib_manager_mod_ctx *const ctx = lib_manager_get_mod_ctx(module_id);
const struct sof_man_fw_desc *desc;

if (!ctx || !ctx->base_addr)
return NULL;

desc = (const struct sof_man_fw_desc *)((const char *)ctx->base_addr +
SOF_MAN_ELF_TEXT_OFFSET);

if (entry_index >= desc->header.num_module_entries) {
tr_err(&lib_manager_tr, "Entry index %d out of bounds.", entry_index);
return NULL;
}

return (const struct sof_man_module *)((const char *)desc +
SOF_MAN_MODULE_OFFSET(entry_index));
}

#if CONFIG_INTEL_MODULES
static void lib_manager_prepare_module_adapter(struct comp_driver *drv, const struct sof_uuid *uuid)
{
Expand Down
5 changes: 1 addition & 4 deletions src/library_manager/llext_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,13 @@ uintptr_t llext_manager_allocate_module(struct processing_module *proc,

int llext_manager_free_module(const uint32_t component_id)
{
struct sof_man_fw_desc *desc;
const struct sof_man_module *mod;
const uint32_t module_id = IPC4_MOD_ID(component_id);
uint32_t entry_index = LIB_MANAGER_GET_MODULE_INDEX(module_id);
int ret;

tr_dbg(&lib_manager_tr, "llext_manager_free_module(): mod_id: %#x", component_id);

desc = lib_manager_get_library_module_desc(module_id);
mod = (struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(entry_index));
mod = lib_manager_get_module_manifest(module_id);

ret = llext_manager_unload_module(module_id, mod);
if (ret < 0)
Expand Down

0 comments on commit ca42dff

Please sign in to comment.