Skip to content

Commit 64d23f4

Browse files
committed
ipc: allocate IPC objects from the user-accessible system heap
The pipeline, component and chain-DMA bookkeeping objects must be reachable from the user-space IPC thread, so allocate them from the system user heap via sof_heap_alloc()/sof_heap_free() instead of the generic rzalloc()/rfree(). As sof_heap_alloc() does not zero the allocation, add an explicit memset() to preserve the previous behaviour. Give ipc4_add_comp_dev() external linkage (declared in topology.h) so the user thread can register a created component, and skip the buffer tr_ctx copy for user-space LL builds where the kernel tr_ctx is not mapped. No functional change for non-userspace builds. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 52198d1 commit 64d23f4

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/include/sof/ipc/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef uint32_t ipc_comp;
4949
struct ipc_comp_dev;
5050
const struct comp_driver *ipc4_get_comp_drv(uint32_t module_id);
5151
struct comp_dev *ipc4_get_comp_dev(uint32_t comp_id);
52+
int ipc4_add_comp_dev(struct comp_dev *dev);
5253
int ipc4_chain_manager_create(struct ipc4_chain_dma *cdma);
5354
int ipc4_chain_dma_state(struct comp_dev *dev, struct ipc4_chain_dma *cdma);
5455
int ipc4_create_chain_dma(struct ipc *ipc, struct ipc4_chain_dma *cdma);

src/ipc/ipc-helper.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ __cold struct comp_buffer *buffer_new(struct mod_alloc_ctx *alloc,
8989
buffer->stream.runtime_stream_params.pipeline_id = desc->comp.pipeline_id;
9090
buffer->core = desc->comp.core;
9191

92+
#if !defined(CONFIG_SOF_USERSPACE_LL)
9293
memcpy_s(&buffer->tctx, sizeof(struct tr_ctx),
9394
&buffer_tr, sizeof(struct tr_ctx));
95+
#endif
9496
}
9597

9698
return buffer;
@@ -388,7 +390,7 @@ __cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id)
388390
icd->cd = NULL;
389391

390392
list_item_del(&icd->list);
391-
rfree(icd);
393+
sof_heap_free(sof_sys_user_heap_get(), icd);
392394

393395
return 0;
394396
}

src/ipc/ipc4/helper.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ LOG_MODULE_DECLARE(ipc, CONFIG_SOF_LOG_LEVEL);
6464
extern struct tr_ctx comp_tr;
6565

6666
static const struct comp_driver *ipc4_get_drv(const void *uuid);
67-
static int ipc4_add_comp_dev(struct comp_dev *dev);
6867

6968
void ipc_build_stream_posn(struct sof_ipc_stream_posn *posn, uint32_t type,
7069
uint32_t id)
@@ -341,6 +340,7 @@ __cold static int ipc4_create_pipeline(struct ipc4_pipeline_create *pipe_desc,
341340
struct ipc_comp_dev *ipc_pipe;
342341
struct pipeline *pipe;
343342
struct ipc *ipc = ipc_get();
343+
struct k_heap *heap = sof_sys_user_heap_get();
344344

345345
assert_can_be_cold();
346346

@@ -353,7 +353,7 @@ __cold static int ipc4_create_pipeline(struct ipc4_pipeline_create *pipe_desc,
353353
}
354354

355355
/* create the pipeline */
356-
pipe = pipeline_new(NULL, pipe_desc->primary.r.instance_id,
356+
pipe = pipeline_new(heap, pipe_desc->primary.r.instance_id,
357357
pipe_desc->primary.r.ppl_priority, 0, pparams);
358358
if (!pipe) {
359359
tr_err(&ipc_tr, "ipc: pipeline_new() failed");
@@ -369,12 +369,13 @@ __cold static int ipc4_create_pipeline(struct ipc4_pipeline_create *pipe_desc,
369369
pipe->core = pipe_desc->extension.r.core_id;
370370

371371
/* allocate the IPC pipeline container */
372-
ipc_pipe = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
373-
sizeof(struct ipc_comp_dev));
372+
ipc_pipe = sof_heap_alloc(heap, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
373+
sizeof(struct ipc_comp_dev), 0);
374374
if (!ipc_pipe) {
375375
pipeline_free(pipe);
376376
return IPC4_OUT_OF_MEMORY;
377377
}
378+
memset(ipc_pipe, 0, sizeof(*ipc_pipe));
378379

379380
ipc_pipe->pipeline = pipe;
380381
ipc_pipe->type = COMP_TYPE_PIPELINE;
@@ -541,7 +542,7 @@ __cold int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id)
541542

542543
ipc_pipe->pipeline = NULL;
543544
list_item_del(&ipc_pipe->list);
544-
rfree(ipc_pipe);
545+
sof_heap_free(sof_sys_user_heap_get(), ipc_pipe);
545546

546547
return IPC4_SUCCESS;
547548
}
@@ -1089,7 +1090,7 @@ __cold int ipc4_chain_dma_state(struct comp_dev *dev, struct ipc4_chain_dma *cdm
10891090
if (icd->cd != dev)
10901091
continue;
10911092
list_item_del(&icd->list);
1092-
rfree(icd);
1093+
sof_heap_free(sof_sys_user_heap_get(), icd);
10931094
break;
10941095
}
10951096
comp_free(dev);
@@ -1305,7 +1306,7 @@ struct comp_dev *ipc4_get_comp_dev(uint32_t comp_id)
13051306
}
13061307
EXPORT_SYMBOL(ipc4_get_comp_dev);
13071308

1308-
__cold static int ipc4_add_comp_dev(struct comp_dev *dev)
1309+
__cold int ipc4_add_comp_dev(struct comp_dev *dev)
13091310
{
13101311
struct ipc *ipc = ipc_get();
13111312
struct ipc_comp_dev *icd;
@@ -1320,12 +1321,13 @@ __cold static int ipc4_add_comp_dev(struct comp_dev *dev)
13201321
}
13211322

13221323
/* allocate the IPC component container */
1323-
icd = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
1324-
sizeof(struct ipc_comp_dev));
1324+
icd = sof_heap_alloc(sof_sys_user_heap_get(), SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
1325+
sizeof(struct ipc_comp_dev), 0);
13251326
if (!icd) {
13261327
tr_err(&ipc_tr, "alloc failed");
13271328
return IPC4_OUT_OF_MEMORY;
13281329
}
1330+
memset(icd, 0, sizeof(*icd));
13291331

13301332
icd->cd = dev;
13311333
icd->type = COMP_TYPE_COMPONENT;

0 commit comments

Comments
 (0)