Skip to content

Commit 94ac8e0

Browse files
committed
zephyr: userspace_helper: add method to add access to DMA devices
Add helper function to grant a user thread access to all system DMA devices. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 28afde6 commit 94ac8e0

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

zephyr/include/rtos/userspace_helper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ static inline uint32_t user_get_partition_attr(uintptr_t ptr)
133133
*/
134134
void user_grant_dai_access_all(struct k_thread *thread);
135135

136+
/**
137+
* Grant DMA device access to a user-space thread.
138+
*
139+
* @param thread user-space thread for which DMA access is granted
140+
*/
141+
void user_grant_dma_access_all(struct k_thread *thread);
142+
136143
#else
137144

138145
static inline int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id)

zephyr/lib/userspace_helper.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
#include <stdint.h>
1616

1717
#include <rtos/alloc.h>
18+
#include <rtos/sof.h>
1819
#include <rtos/userspace_helper.h>
1920
#include <sof/audio/module_adapter/module/generic.h>
2021
#include <sof/audio/module_adapter/library/userspace_proxy.h>
2122
#include <sof/lib/mailbox.h>
2223
#include <sof/lib/dai.h>
24+
#include <sof/lib/dma.h>
2325

2426
#define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED
2527

@@ -146,6 +148,17 @@ void user_grant_dai_access_all(struct k_thread *thread)
146148
LOG_DBG("Granted DAI access to thread %p for %zu devices", thread, count);
147149
}
148150

151+
void user_grant_dma_access_all(struct k_thread *thread)
152+
{
153+
const struct dma_info *info = dma_info_get();
154+
struct sof_dma *d;
155+
156+
for (d = info->dma_array; d < info->dma_array + info->num_dmas; d++) {
157+
k_thread_access_grant(thread, d->z_dev);
158+
LOG_DBG("Granted DMA device access: %s to thread %p", d->z_dev->name, thread);
159+
}
160+
}
161+
149162
#else /* CONFIG_USERSPACE */
150163

151164
void *user_stack_allocate(size_t stack_size, uint32_t options)

0 commit comments

Comments
 (0)