Skip to content

Commit baf5041

Browse files
committed
dma: allocate on userspace heap when running in userspace
When initialising in userspace use the userspace heap for channel memory allocations. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent c0ee625 commit baf5041

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/lib/dma.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
66

77
#include <rtos/atomic.h>
8+
#include <rtos/kernel.h>
89
#include <sof/audio/audio_stream.h>
910
#include <sof/audio/buffer.h>
1011
#include <sof/audio/component.h>
@@ -134,7 +135,7 @@ void z_impl_sof_dma_put(struct sof_dma *dma)
134135

135136
key = k_spin_lock(&dma->lock);
136137
if (--dma->sref == 0) {
137-
rfree(dma->chan);
138+
sof_heap_free(dma->heap, dma->chan);
138139
dma->chan = NULL;
139140
}
140141

@@ -146,18 +147,20 @@ void z_impl_sof_dma_put(struct sof_dma *dma)
146147
static int dma_init(struct sof_dma *dma)
147148
{
148149
struct dma_chan_data *chan;
150+
struct k_heap *heap = thread_is_userspace(k_current_get()) ? sof_sys_user_heap_get() : NULL;
149151
int i;
150152

151153
/* allocate dma channels */
152-
dma->chan = rzalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
153-
sizeof(struct dma_chan_data) * dma->plat_data.channels);
154-
154+
dma->chan = sof_heap_alloc(heap, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT,
155+
sizeof(struct dma_chan_data) * dma->plat_data.channels, 0);
155156
if (!dma->chan) {
156-
tr_err(&dma_tr, "dma_probe_sof(): dma %d allocaction of channels failed",
157+
tr_err(&dma_tr, "dma %d allocaction of channels failed",
157158
dma->plat_data.id);
158159
return -ENOMEM;
159160
}
160161

162+
dma->heap = heap;
163+
memset(dma->chan, 0, sizeof(struct dma_chan_data) * dma->plat_data.channels);
161164
/* init work */
162165
for (i = 0, chan = dma->chan; i < dma->plat_data.channels;
163166
i++, chan++) {

zephyr/include/sof/lib/dma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ struct dma_plat_data {
200200
};
201201

202202
#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS
203+
struct k_heap;
203204
struct sof_dma {
205+
struct k_heap *heap;
204206
#else
205207
struct dma {
206208
#endif

0 commit comments

Comments
 (0)