Sound Open Firmware
Loading...
Searching...
No Matches
lib_manager.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2022 Intel Corporation. All rights reserved.
4 *
5 * Author: Jaroslaw Stelter <jaroslaw.stelter@intel.com>
6 * Pawel Dobrowolski <pawelx.dobrowolski@intel.com>
7 */
8
9/*
10 * Library manager implementation for SOF is using module adapter API for
11 * loadable native and external libraries. Depends of information received from
12 * it manages memory and locate accordingly to available space.
13 *
14 * Driver IPC4 Library MEMORY ENTITY
15 * Handler Manager VERIF.
16 * | | | | |
17 * | IPC4_GLB_LOAD_LIBRARY | | | |
18 * | --------------------> | lib_manager_load_library() | | |
19 * | | -------------------------> | Prepare DMA transfer | |
20 * | | | ------- | |
21 * | | | | | |
22 * | | | <------ | |
23 * | | | -----------------------> | |
24 * | | | | |
25 * | | | (IF AUTH_API_ENABLED) | |
26 * | | | Verify Manifest | |
27 * | | | -------------------------|-------> |
28 * | | | results | |
29 * | | | <------------------------|-------- |
30 * | | | (IF AUTH_API_ENABLED) | |
31 * | | | | |
32 * | | | Parse Manifest | |
33 * | | | Prepare Storage Memory | |
34 * | | | ------- | |
35 * | | | | | |
36 * | | | <------ | |
37 * | | | | |
38 * | | | Copy Library Data | |
39 * | | | -----------------------> | |
40 * | | | | |
41 * | | | (IF AUTH_API_ENABLED) | |
42 * | | | Verify Manifest | |
43 * | | | -------------------------|-------> |
44 * | | | results | |
45 * | | | <------------------------|-------- |
46 * | | | (IF AUTH_API_ENABLED) | |
47 * | | | | |
48 * | | | Update Library | |
49 * | | | descriptors table | |
50 * | | | ------- | |
51 * | | | | | |
52 * | | | <------ | |
53 * | | return status | | |
54 * | | <------------------------- | | |
55 * | Complete IPC request | | | |
56 * | <------------------- | | | |
57 *
58 * Driver IPC4 Library MEMORY ENTITY
59 * Handler Manager VERIF.
60 */
61
62#ifndef __SOF_LIB_MANAGER_H__
63#define __SOF_LIB_MANAGER_H__
64
65#include <stdint.h>
66#include <sof/list.h>
67#include <sof/audio/component.h>
68#include <rimage/sof/user/manifest.h>
69#if CONFIG_LIBRARY_AUTH_SUPPORT
70#include <sof/auth_api_iface.h>
71#endif
72#include <sof/list.h>
73
74#define LIB_MANAGER_MAX_LIBS 16
75#define LIB_MANAGER_LIB_ID_SHIFT 12
76#define LIB_MANAGER_LIB_NOTIX_MAX_COUNT 4
77
78#define LIB_MANAGER_GET_LIB_ID(module_id) (((module_id) & 0xF000) >> LIB_MANAGER_LIB_ID_SHIFT)
79#define LIB_MANAGER_GET_MODULE_INDEX(module_id) ((module_id) & 0xFFF)
80#define LIB_MANAGER_PACK_MODULE_ID(lib_index, module_index) (((module_index) & 0xFFF) | \
81 (((lib_index) << LIB_MANAGER_LIB_ID_SHIFT) & 0xF000))
82#define LIB_MANAGER_PACK_LIB_ID(lib_index) LIB_MANAGER_PACK_MODULE_ID(lib_index, 0x0)
83
84#ifdef CONFIG_LIBRARY_MANAGER
85struct ipc_lib_msg {
86 struct ipc_msg *msg;
87 struct list_item list;
88};
89
90struct sof_man_module_manifest;
91
92enum {
93 LIB_MANAGER_TEXT,
94 LIB_MANAGER_DATA,
95 LIB_MANAGER_RODATA,
96 LIB_MANAGER_BSS,
97 LIB_MANAGER_COLD,
98 LIB_MANAGER_COLDRODATA,
99 LIB_MANAGER_N_SEGMENTS,
100};
101
102struct lib_manager_segment_desc {
103 uintptr_t addr;
104 size_t size;
105};
106
107struct llext;
108struct llext_buf_loader;
109
110struct lib_manager_module {
111 unsigned int start_idx; /* Index of the first driver from this module in
112 * the library-global driver list */
113 const struct sof_man_module_manifest *mod_manifest;
114 struct llext *llext; /* Zephyr loadable extension context */
115 struct llext_buf_loader *ebl; /* Zephyr loadable extension buffer loader */
116 unsigned int n_dependent; /* For auxiliary modules: number of dependents */
117 unsigned int n_mod;
118 bool mapped;
119 bool domain_dp;
120 struct lib_manager_segment_desc segment[LIB_MANAGER_N_SEGMENTS];
121 struct lib_manager_segment_desc writable_merged;
122};
123
124struct lib_manager_mod_ctx {
125 void *base_addr; /* library cold storage address (e.g. DRAM) */
126 unsigned int n_mod;
127 unsigned int load_type;
128 struct lib_manager_module *mod;
129};
130
131struct ext_library {
132 struct k_spinlock lock; /* last locking CPU record */
133 struct lib_manager_mod_ctx *desc[LIB_MANAGER_MAX_LIBS];
134#ifdef CONFIG_LIBCODE_MODULE_SUPPORT
135 uint32_t mods_exec_load_cnt;
136#endif
137 struct ipc_lib_msg *lib_notif_pool;
138 uint32_t lib_notif_count;
139
140 /* Only needed from SOF_IPC4_GLB_LOAD_LIBRARY_PREPARE to SOF_IPC4_GLB_LOAD_LIBRARY */
141 void *runtime_data;
142};
143
144/* lib manager context, used by lib_notification */
145extern struct tr_ctx lib_manager_tr;
146
147static inline struct ext_library *ext_lib_get(void)
148{
149 return sof_get()->ext_library;
150}
151
152static inline struct lib_manager_mod_ctx *lib_manager_get_mod_ctx(int module_id)
153{
154 uint32_t lib_id = LIB_MANAGER_GET_LIB_ID(module_id);
155 struct ext_library *_ext_lib = ext_lib_get();
156
157 if (!_ext_lib || lib_id >= LIB_MANAGER_MAX_LIBS)
158 return NULL;
159
160 return _ext_lib->desc[lib_id];
161}
162
163/*
164 * \brief Get module manifest for given module id
165 *
166 * param[in] module_id - used to get library manifest
167 *
168 * Gets library manifest descriptor using module_id to locate it
169 */
170const struct sof_man_module *lib_manager_get_module_manifest(const uint32_t module_id);
171#endif
172
173/*
174 * \brief Initialize library manager
175 */
177
178/*
179 * \brief Register module on driver list
180 *
181 * param[in] component_id - component id coming from ipc config. This function reguires valid
182 * lib_id and module_id fields of component id.
183 *
184 * Creates new comp_driver_info and initialize it for module from library
185 * Adds new module to sof_get()->comp_drivers list
186 */
187int lib_manager_register_module(const uint32_t component_id);
188
189/*
190 * \brief Get library module manifest descriptor
191 *
192 * param[in] module_id - used to get text manifest offset
193 *
194 * Gets firmware manifest descriptor using module_id to locate it
195 */
196const struct sof_man_fw_desc *lib_manager_get_library_manifest(int module_id);
197
198/*
199 * \brief Get address and size of the bss section for given module instance
200 *
201 * param[in] instance_id - instance id
202 * param[in] mod - module manifest
203 * param[out] va_addr - address of the bss section
204 * param[out] size - size of the bss section
205 */
207 const struct sof_man_module *mod,
208 void __sparse_cache **va_addr, size_t *size);
209
210/*
211 * \brief Load library
212 *
213 * param[in] dma_id - channel used to transfer binary from host
214 * param[in] lib_id
215 * param[in] type - ipc command type
216 * (SOF_IPC4_GLB_LOAD_LIBRARY or SOF_IPC4_GLB_LOAD_LIBRARY_PREPARE)
217 *
218 * Function will load library manifest into temporary buffer.
219 * Then it will read library parameters, allocate memory for library and load it into
220 * destination memory region.
221 */
222int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t type);
223
224struct userspace_context;
225/*
226 * \brief Allocate the module and start the agent if needed
227 */
229 const struct comp_ipc_config *config,
230 const void *spec, void **adapter_priv,
231 struct userspace_context **userspace,
232 const struct module_interface **ops);
233
234#if defined(__ZEPHYR__) && defined(CONFIG_SOF_FULL_ZEPHYR_APPLICATION)
235__syscall int lib_manager_free_module(const uint32_t component_id);
236
237#include <zephyr/syscalls/lib_manager.h>
238#else
239int z_impl_lib_manager_free_module(const uint32_t component_id);
240#define lib_manager_free_module z_impl_lib_manager_free_module
241#endif
242
243/*
244 * \brief Initialize message
245 *
246 * param[in] header - IPC header provided by caller
247 * param[in] size - size of data buffer for messege to be send
248 *
249 * Function search lib_notif_pool for free message handler.
250 * If not found allocates new message handle and returns it to
251 * caller.
252 */
253struct ipc_msg *lib_notif_msg_init(uint32_t header, uint32_t size);
254
255/*
256 * \brief Send message
257 *
258 * param[in] msg - IPC message handler
259 *
260 * Function sends IPC message and calls lib_notif_msg_clean() to
261 * free unused message handlers. Only single message handle will
262 * be kept in list while at least one loadable module is loaded.
263 */
264void lib_notif_msg_send(struct ipc_msg *msg);
265
266/*
267 * \brief Clean unused message handles
268 *
269 * param[in] leave_one_handle - remove all unused or keep one
270 *
271 * Function search lib_notif_pool list for unused message handles.
272 * Remove them keeping one if leave_one_handle == true.
273 */
274void lib_notif_msg_clean(bool leave_one_handle);
275
276#endif /* __SOF_LIB_MANAGER_H__ */
Component API definition.
uint16_t module_id
Module ID of the originator of the notification.
Definition header.h:1
uint16_t instance_id
Instance ID of the originator module of the notification.
Definition header.h:0
uint32_t type
Message type, symmetric to the incoming request.
Definition header.h:8
void lib_manager_get_instance_bss_address(uint32_t instance_id, const struct sof_man_module *mod, void **va_addr, size_t *size)
int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t type)
void lib_notif_msg_send(struct ipc_msg *msg)
int lib_manager_register_module(const uint32_t component_id)
const struct sof_man_fw_desc * lib_manager_get_library_manifest(int module_id)
void lib_notif_msg_clean(bool leave_one_handle)
#define LIB_MANAGER_MAX_LIBS
Definition lib_manager.h:74
struct ipc_msg * lib_notif_msg_init(uint32_t header, uint32_t size)
int lib_manager_mod_create_priv(const struct comp_driver *drv, const struct comp_ipc_config *config, const void *spec, void **adapter_priv, struct userspace_context **userspace, const struct module_interface **ops)
int lib_manager_free_module(const uint32_t component_id)
#define LIB_MANAGER_GET_LIB_ID(module_id)
Definition lib_manager.h:78
void lib_manager_init(void)
struct sof * sof_get(void)
Get the global Sound Open Firmware runtime instance pointer.
Audio component base driver "class".
Definition component.h:528
Audio component base configuration from IPC at creation.
Definition component.h:560
Definition msg.h:34
uint32_t header
Definition msg.h:35
Definition list.h:16
3rd party processing module interface
Definition interface.h:102
Definition trace.h:132