Skip to content

Commit d85a793

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 8fe5c62 commit d85a793

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>
@@ -298,6 +299,11 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
298299
{
299300
const struct device *dev;
300301
struct dai *d;
302+
struct k_heap *heap = NULL;
303+
304+
#ifdef CONFIG_SOF_USERSPACE_LL
305+
heap = zephyr_ll_user_heap();
306+
#endif
301307

302308
dev = dai_get_device(type, index);
303309
if (!dev) {
@@ -306,10 +312,12 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
306312
return NULL;
307313
}
308314

309-
d = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct dai));
315+
d = sof_heap_alloc(heap, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT, sizeof(struct dai), 0);
310316
if (!d)
311317
return NULL;
312318

319+
memset(d, 0, sizeof(struct dai));
320+
313321
d->index = index;
314322
d->type = type;
315323
d->dev = dev;
@@ -319,7 +327,7 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
319327
if (dai_probe(d->dev)) {
320328
tr_err(&dai_tr, "dai_get: failed to probe dai with index %d type %d",
321329
index, type);
322-
rfree(d);
330+
sof_heap_free(heap, d);
323331
return NULL;
324332
}
325333

@@ -330,14 +338,19 @@ struct dai *dai_get(uint32_t type, uint32_t index, uint32_t flags)
330338
void dai_put(struct dai *dai)
331339
{
332340
int ret;
341+
struct k_heap *heap = NULL;
342+
343+
#ifdef CONFIG_SOF_USERSPACE_LL
344+
heap = zephyr_ll_user_heap();
345+
#endif
333346

334347
ret = dai_remove(dai->dev);
335348
if (ret < 0) {
336349
tr_err(&dai_tr, "index %d failed ret = %d",
337350
dai->index, ret);
338351
}
339352

340-
rfree(dai);
353+
sof_heap_free(heap, dai);
341354
}
342355
#else
343356
static inline const struct dai_type_info *dai_find_type(uint32_t type)

0 commit comments

Comments
 (0)