Skip to content

Commit e418357

Browse files
committed
lib: dai: make dai_get() and dai_put() compatible with user-space
The dai_get()/dai_put() provide a helper to access DAI devices. When used in user-space, the wrapper struct should be created in user-space memory. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 8576b65 commit e418357

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/lib/dai.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sof/lib/uuid.h>
1212
#include <rtos/spinlock.h>
1313
#include <sof/trace/trace.h>
14+
#include <sof/schedule/ll_schedule_domain.h> /* for zephyr_ll_user_heap() */
1415
#include <ipc/topology.h>
1516
#include <ipc/dai.h>
1617
#include <user/trace.h>
@@ -317,6 +318,11 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
317318
{
318319
const struct device *dev;
319320
struct dai *d;
321+
struct k_heap *heap = NULL;
322+
323+
#ifdef CONFIG_SOF_USERSPACE_LL
324+
heap = zephyr_ll_user_heap();
325+
#endif
320326

321327
dev = dai_get_device(type, index);
322328
if (!dev) {
@@ -325,10 +331,12 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
325331
return NULL;
326332
}
327333

328-
d = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct dai));
334+
d = sof_heap_alloc(heap, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct dai), 0);
329335
if (!d)
330336
return NULL;
331337

338+
memset(d, 0, sizeof(struct dai));
339+
332340
d->index = index;
333341
d->type = type;
334342
d->dev = dev;
@@ -338,7 +346,7 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
338346
if (dai_probe(d->dev)) {
339347
tr_err(&dai_tr, "dai_get: failed to probe dai with index %d type %d",
340348
index, type);
341-
rfree(d);
349+
sof_heap_free(heap, d);
342350
return NULL;
343351
}
344352

@@ -349,14 +357,19 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
349357
void dai_put(struct dai *dai)
350358
{
351359
int ret;
360+
struct k_heap *heap = NULL;
361+
362+
#ifdef CONFIG_SOF_USERSPACE_LL
363+
heap = zephyr_ll_user_heap();
364+
#endif
352365

353366
ret = dai_remove(dai->dev);
354367
if (ret < 0) {
355368
tr_err(&dai_tr, "index %d failed ret = %d",
356369
dai->index, ret);
357370
}
358371

359-
rfree(dai);
372+
sof_heap_free(heap, dai);
360373
}
361374
#else
362375
static inline const struct dai_type_info *dai_find_type(uint32_t type)

0 commit comments

Comments
 (0)