Skip to content

Commit

Permalink
lib_manager: lib_manager_get_library_manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarecki committed Feb 29, 2024
1 parent 9d6705d commit 3bbe5ec
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 54 deletions.
11 changes: 5 additions & 6 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ static int modules_init(struct processing_module *mod)
uint32_t log_handle = (uint32_t) mod->dev->drv->tctx;
/* Connect loadable module interfaces with module adapter entity. */
/* Check if native Zephyr lib is loaded */
struct sof_man_fw_desc *desc;

desc = lib_manager_get_library_module_desc(module_id);
if (!desc) {
const struct sof_man_module *const module_entry =
lib_manager_get_library_manifest(module_id);

if (!module_entry) {
comp_err(dev, "modules_init(): Failed to load manifest");
return -ENOMEM;
}
struct sof_man_module *module_entry =
(struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(0));

struct sof_module_api_build_info *mod_buildinfo =
const struct sof_module_api_build_info *const mod_buildinfo =
(struct sof_module_api_build_info *)
(module_entry->segment[SOF_MAN_SEGMENT_TEXT].v_base_addr);

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

return _ext_lib->desc[lib_id];
}

/*
* \brief Get library manifest for given module id
*
* param[in] module_id - used to get library manifest
*
* Gets library manifest descriptor using module_id to locate it
*/
static inline const struct sof_man_module *lib_manager_get_library_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);

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

return (const struct sof_man_module *)((const char *)ctx->desc +
SOF_MAN_ELF_TEXT_OFFSET +
SOF_MAN_MODULE_OFFSET(entry_index));
}
#endif

/*
Expand All @@ -134,15 +155,6 @@ void lib_manager_init(void);
*/
int lib_manager_register_module(const struct sof_man_module *const mod);

/*
* \brief Get library module manifest descriptor
*
* param[in] module_id - used to get text manifest offset
*
* Gets firmware manifest descriptor using module_id to locate it
*/
struct sof_man_fw_desc *lib_manager_get_library_module_desc(int module_id);

/*
* \brief Allocate module
*
Expand Down
30 changes: 21 additions & 9 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(int 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;
int entry_index;
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(int 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_library_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
23 changes: 3 additions & 20 deletions src/library_manager/lib_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,25 +346,21 @@ uint32_t lib_manager_allocate_module(const struct comp_driver *drv,
struct comp_ipc_config *ipc_config,
const void *ipc_specific_config)
{
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_library_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(drv, ipc_config, ipc_specific_config);

Expand Down Expand Up @@ -398,16 +394,13 @@ uint32_t lib_manager_allocate_module(const struct comp_driver *drv,
int lib_manager_free_module(const struct comp_driver *drv,
struct comp_ipc_config *ipc_config)
{
struct sof_man_fw_desc *desc;
const struct sof_man_module *mod;
uint32_t module_id = IPC4_MOD_ID(ipc_config->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", ipc_config->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_library_manifest(module_id);

if (module_is_llext(mod))
return llext_manager_free_module(drv, ipc_config);
Expand Down Expand Up @@ -462,16 +455,6 @@ void lib_manager_init(void)
sof->ext_library = &loader_ext_lib;
}

struct sof_man_fw_desc *lib_manager_get_library_module_desc(int module_id)
{
struct lib_manager_mod_ctx *ctx = lib_manager_get_mod_ctx(module_id);
uint8_t *buffptr = (uint8_t *)(ctx ? ctx->desc : NULL);

if (!buffptr)
return NULL;
return (struct sof_man_fw_desc *)(buffptr + SOF_MAN_ELF_TEXT_OFFSET);
}

static void lib_manager_update_sof_ctx(struct sof_man_fw_desc *desc, uint32_t lib_id)
{
struct ext_library *_ext_lib = ext_lib_get();
Expand Down
13 changes: 3 additions & 10 deletions src/library_manager/llext_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,22 @@ uint32_t llext_manager_allocate_module(const struct comp_driver *drv,
struct comp_ipc_config *ipc_config,
const void *ipc_specific_config)
{
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);
struct lib_manager_mod_ctx *ctx = lib_manager_get_mod_ctx(module_id);

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

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

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

for (unsigned int i = 0; i < ARRAY_SIZE(ctx->segment_size); i++)
ctx->segment_size[i] = mod->segment[i].flags.r.length * PAGE_SZ;

Expand All @@ -211,16 +207,13 @@ uint32_t llext_manager_allocate_module(const struct comp_driver *drv,
int llext_manager_free_module(const struct comp_driver *drv,
struct comp_ipc_config *ipc_config)
{
struct sof_man_fw_desc *desc;
const struct sof_man_module *mod;
uint32_t module_id = IPC4_MOD_ID(ipc_config->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", ipc_config->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_library_manifest(module_id);

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

0 comments on commit 3bbe5ec

Please sign in to comment.