Skip to content

Commit 5efb6f9

Browse files
committed
ipc4: base_fw: send modules info of libraries
Currently SOF sends info about built-in modules only while handling MODULES_INFO_GET property of LargeConfigGet msg. However, the IPC4 spec says the message should contain info about all the available modules. This change removes this gap. Additionally, a check for max payload size is added. Signed-off-by: Wojciech Jablonski <wojciech.jablonski@intel.com>
1 parent 295fc90 commit 5efb6f9

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/audio/base_fw_intel.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <zephyr/pm/device_runtime.h>
2323

2424
#include <sof/lib/memory.h>
25+
#include <sof/lib_manager.h>
2526

2627
#include <ipc4/base_fw.h>
2728
#include <ipc4/alh.h>
@@ -37,6 +38,9 @@ struct ipc4_modules_info {
3738
struct sof_man_module modules[0];
3839
} __packed __aligned(4);
3940

41+
/* Sanity check because a subtraction of those sizes is performed later on */
42+
STATIC_ASSERT(sizeof(struct ipc4_modules_info) < SOF_IPC_MSG_MAX_SIZE,
43+
invalid_modules_info_struct_size);
4044
/*
4145
* TODO: default to value of ACE1.x platforms. This is defined
4246
* in multiple places in Zephyr, mm_drv_intel_adsp.h and
@@ -137,22 +141,42 @@ __cold int basefw_vendor_modules_info_get(uint32_t *data_offset, char *data)
137141
{
138142
assert_can_be_cold();
139143

140-
struct sof_man_fw_desc *desc = basefw_vendor_get_manifest();
144+
struct ipc4_modules_info *const module_info = (struct ipc4_modules_info *)data;
145+
const struct sof_man_fw_desc *desc;
146+
uint32_t curr_mod_cnt, curr_cpy_size, total_mod_cnt = 0;
147+
uint32_t total_size_left = SOF_IPC_MSG_MAX_SIZE - sizeof(struct ipc4_modules_info);
148+
int ret;
149+
150+
for (int lib_id = 0; lib_id < LIB_MANAGER_MAX_LIBS; ++lib_id) {
151+
if (lib_id == 0) {
152+
desc = basefw_vendor_get_manifest();
153+
} else {
154+
#if CONFIG_LIBRARY_MANAGER
155+
desc = lib_manager_get_library_manifest(LIB_MANAGER_PACK_LIB_ID(lib_id));
156+
#else
157+
desc = NULL;
158+
#endif
159+
}
141160

142-
if (!desc)
143-
return IPC4_ERROR_INVALID_PARAM;
161+
if (!desc)
162+
continue;
144163

145-
struct ipc4_modules_info *const module_info = (struct ipc4_modules_info *)data;
164+
curr_mod_cnt = desc->header.num_module_entries;
165+
curr_cpy_size = sizeof(struct sof_man_module) * curr_mod_cnt;
146166

147-
module_info->modules_count = desc->header.num_module_entries;
167+
ret = memcpy_s(&module_info->modules[total_mod_cnt], total_size_left,
168+
(char *)desc + SOF_MAN_MODULE_OFFSET(0), curr_cpy_size);
169+
if (ret) {
170+
tr_err(&basefw_comp_tr, "Couldn't copy module info for %d lib", lib_id);
171+
return IPC4_OUT_OF_MEMORY;
172+
}
148173

149-
for (int idx = 0; idx < module_info->modules_count; ++idx) {
150-
struct sof_man_module *module_entry =
151-
(struct sof_man_module *)((char *)desc + SOF_MAN_MODULE_OFFSET(idx));
152-
memcpy_s(&module_info->modules[idx], sizeof(module_info->modules[idx]),
153-
module_entry, sizeof(struct sof_man_module));
174+
total_mod_cnt += curr_mod_cnt;
175+
total_size_left -= curr_cpy_size;
154176
}
155177

178+
module_info->modules_count = total_mod_cnt;
179+
156180
*data_offset = sizeof(*module_info) +
157181
module_info->modules_count * sizeof(module_info->modules[0]);
158182
return IPC4_SUCCESS;

0 commit comments

Comments
 (0)