Skip to content

Commit bd79a8d

Browse files
committed
ipc: ipc4: Centralize component list and perf data initialization
Move the initialization of `bsource_list`, `bsink_list`, and performance tracking telemetry data from `comp_new_ipc4()` directly into `ipc4_add_comp_dev()`. This refactoring centralizes core component setup logic deeper into the device addition routine, allowing it to be directly leveraged by mock component setups (like the Zephyr usermode IPC pipeline tests). This ensures manual test components correctly initialize their data structures via core infrastructure APIs instead of relying on redundant manual list tracking, promoting better API safety and reusability. As a result, `ipc4_add_comp_dev()` is now defined in `component_ext.h` as a globally accessible symbol, dropping its static scope. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 82e5e63 commit bd79a8d

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/include/sof/audio/component_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct comp_driver_list {
3939
struct comp_dev *comp_new(struct sof_ipc_comp *comp);
4040
#elif CONFIG_IPC_MAJOR_4
4141
struct comp_dev *comp_new_ipc4(struct ipc4_module_init_instance *module_init);
42+
int ipc4_add_comp_dev(struct comp_dev *dev);
4243
#endif
4344

4445
/** See comp_ops::free */

src/ipc/ipc4/helper.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
6363
extern struct tr_ctx comp_tr;
6464

6565
static const struct comp_driver *ipc4_get_drv(const void *uuid);
66-
static int ipc4_add_comp_dev(struct comp_dev *dev);
66+
int ipc4_add_comp_dev(struct comp_dev *dev);
6767

6868
void ipc_build_stream_posn(struct sof_ipc_stream_posn *posn, uint32_t type,
6969
uint32_t id)
@@ -184,23 +184,6 @@ __cold struct comp_dev *comp_new_ipc4(struct ipc4_module_init_instance *module_i
184184
} else {
185185
dev = drv->ops.create(drv, &ipc_config, (const void *)data);
186186
}
187-
if (!dev)
188-
return NULL;
189-
190-
list_init(&dev->bsource_list);
191-
list_init(&dev->bsink_list);
192-
193-
#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
194-
/* init global performance measurement */
195-
dev->perf_data.perf_data_item = perf_data_getnext();
196-
/* this can be null, just no performance measurements in this case */
197-
if (dev->perf_data.perf_data_item) {
198-
dev->perf_data.perf_data_item->item.resource_id = comp_id;
199-
if (perf_meas_get_state() != IPC4_PERF_MEASUREMENTS_DISABLED)
200-
comp_init_performance_data(dev);
201-
}
202-
#endif
203-
204187
ipc4_add_comp_dev(dev);
205188

206189
comp_update_ibs_obs_cpc(dev);
@@ -1245,13 +1228,27 @@ struct comp_dev *ipc4_get_comp_dev(uint32_t comp_id)
12451228
}
12461229
EXPORT_SYMBOL(ipc4_get_comp_dev);
12471230

1248-
__cold static int ipc4_add_comp_dev(struct comp_dev *dev)
1231+
__cold int ipc4_add_comp_dev(struct comp_dev *dev)
12491232
{
12501233
struct ipc *ipc = ipc_get();
12511234
struct ipc_comp_dev *icd;
12521235

12531236
assert_can_be_cold();
12541237

1238+
list_init(&dev->bsource_list);
1239+
list_init(&dev->bsink_list);
1240+
1241+
#ifdef CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS
1242+
/* init global performance measurement */
1243+
dev->perf_data.perf_data_item = perf_data_getnext();
1244+
/* this can be null, just no performance measurements in this case */
1245+
if (dev->perf_data.perf_data_item) {
1246+
dev->perf_data.perf_data_item->item.resource_id = dev->ipc_config.id;
1247+
if (perf_meas_get_state() != IPC4_PERF_MEASUREMENTS_DISABLED)
1248+
comp_init_performance_data(dev);
1249+
}
1250+
#endif
1251+
12551252
/* check id for duplicates */
12561253
icd = ipc_get_comp_by_id(ipc, dev->ipc_config.id);
12571254
if (icd) {

0 commit comments

Comments
 (0)