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};
122
123struct lib_manager_mod_ctx {
124 void *base_addr; /* library cold storage address (e.g. DRAM) */
125 unsigned int n_mod;
126 unsigned int load_type;
127 struct lib_manager_module *mod;
128};
129
130struct ext_library {
131 struct k_spinlock lock; /* last locking CPU record */
132 struct lib_manager_mod_ctx *desc[LIB_MANAGER_MAX_LIBS];
133#ifdef CONFIG_LIBCODE_MODULE_SUPPORT
134 uint32_t mods_exec_load_cnt;
135#endif
136 struct ipc_lib_msg *lib_notif_pool;
137 uint32_t lib_notif_count;
138
139 /* Only needed from SOF_IPC4_GLB_LOAD_LIBRARY_PREPARE to SOF_IPC4_GLB_LOAD_LIBRARY */
140 void *runtime_data;
141};
142
143/* lib manager context, used by lib_notification */
144extern struct tr_ctx lib_manager_tr;
145
146static inline struct ext_library *ext_lib_get(void)
147{
148 return sof_get()->ext_library;
149}
150
151static inline struct lib_manager_mod_ctx *lib_manager_get_mod_ctx(int module_id)
152{
153 uint32_t lib_id = LIB_MANAGER_GET_LIB_ID(module_id);
154 struct ext_library *_ext_lib = ext_lib_get();
155
156 if (!_ext_lib || lib_id >= LIB_MANAGER_MAX_LIBS)
157 return NULL;
158
159 return _ext_lib->desc[lib_id];
160}
161
162/*
163 * \brief Get module manifest for given module id
164 *
165 * param[in] module_id - used to get library manifest
166 *
167 * Gets library manifest descriptor using module_id to locate it
168 */
169const struct sof_man_module *lib_manager_get_module_manifest(const uint32_t module_id);
170#endif
171
172/*
173 * \brief Initialize library manager
174 */
176
177/*
178 * \brief Register module on driver list
179 *
180 * param[in] component_id - component id coming from ipc config. This function reguires valid
181 * lib_id and module_id fields of component id.
182 *
183 * Creates new comp_driver_info and initialize it for module from library
184 * Adds new module to sof_get()->comp_drivers list
185 */
186int lib_manager_register_module(const uint32_t component_id);
187
188/*
189 * \brief Get library module manifest descriptor
190 *
191 * param[in] module_id - used to get text manifest offset
192 *
193 * Gets firmware manifest descriptor using module_id to locate it
194 */
195const struct sof_man_fw_desc *lib_manager_get_library_manifest(int module_id);
196
197/*
198 * \brief Get address and size of the bss section for given module instance
199 *
200 * param[in] instance_id - instance id
201 * param[in] mod - module manifest
202 * param[out] va_addr - address of the bss section
203 * param[out] size - size of the bss section
204 */
205void lib_manager_get_instance_bss_address(uint32_t instance_id,
206 const struct sof_man_module *mod,
207 void __sparse_cache **va_addr, size_t *size);
208
209/*
210 * \brief Load library
211 *
212 * param[in] dma_id - channel used to transfer binary from host
213 * param[in] lib_id
214 * param[in] type - ipc command type
215 * (SOF_IPC4_GLB_LOAD_LIBRARY or SOF_IPC4_GLB_LOAD_LIBRARY_PREPARE)
216 *
217 * Function will load library manifest into temporary buffer.
218 * Then it will read library parameters, allocate memory for library and load it into
219 * destination memory region.
220 */
221int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t type);
222
223/*
224 * \brief Initialize message
225 *
226 * param[in] header - IPC header provided by caller
227 * param[in] size - size of data buffer for messege to be send
228 *
229 * Function search lib_notif_pool for free message handler.
230 * If not found allocates new message handle and returns it to
231 * caller.
232 */
233struct ipc_msg *lib_notif_msg_init(uint32_t header, uint32_t size);
234
235/*
236 * \brief Send message
237 *
238 * param[in] msg - IPC message handler
239 *
240 * Function sends IPC message and calls lib_notif_msg_clean() to
241 * free unused message handlers. Only single message handle will
242 * be kept in list while at least one loadable module is loaded.
243 */
244void lib_notif_msg_send(struct ipc_msg *msg);
245
246/*
247 * \brief Clean unused message handles
248 *
249 * param[in] leave_one_handle - remove all unused or keep one
250 *
251 * Function search lib_notif_pool list for unused message handles.
252 * Remove them keeping one if leave_one_handle == true.
253 */
254void lib_notif_msg_clean(bool leave_one_handle);
255
256#endif /* __SOF_LIB_MANAGER_H__ */
Component API definition.
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)
void lib_manager_get_instance_bss_address(uint32_t instance_id, const struct sof_man_module *mod, void __sparse_cache **va_addr, size_t *size)
#define LIB_MANAGER_GET_LIB_ID(module_id)
Definition lib_manager.h:78
void lib_manager_init(void)
#define list_item(item, type, member)
Definition list.h:80
struct sof * sof_get(void)
Definition msg.h:33
uint32_t header
Definition msg.h:34
Definition trace.h:135
uint32_t type
Definition tlv.h:0
#define __sparse_cache
Definition compiler_attributes.h:11