Skip to content

Commit b36268a

Browse files
committed
dma: add functionality to grant access to DMA devices
Add helper functions to provide a list of all Zephyr DMA devices and to grant a user thread access to them. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent cffaeae commit b36268a

4 files changed

Lines changed: 44 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
@@ -120,6 +120,13 @@ int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id);
120120
*/
121121
void user_grant_dai_access_all(struct k_thread *thread);
122122

123+
/**
124+
* Grant DMA device access to a user-space thread.
125+
*
126+
* @param thread user-space thread for which DMA access is granted
127+
*/
128+
void user_grant_dma_access_all(struct k_thread *thread);
129+
123130
#else
124131

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

zephyr/include/sof/lib/dma.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ static inline const struct dma_info *dma_info_get(void)
343343
return sof_get()->dma_info;
344344
}
345345

346+
/**
347+
* \brief Retrieve the list of all DMA devices.
348+
* \param count Pointer to store the number of devices in the list.
349+
* \return Pointer to the array of device pointers.
350+
*/
351+
const struct device **dma_get_device_list(size_t *count);
352+
346353
/** @}*/
347354

348355
#endif /* __SOF_LIB_DMA_H__ */

zephyr/lib/dma.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ const struct dma_info lib_dma = {
219219
.num_dmas = ARRAY_SIZE(dma)
220220
};
221221

222+
const struct device **dma_get_device_list(size_t *count)
223+
{
224+
static const struct device *device_list[ARRAY_SIZE(dma)];
225+
int i;
226+
227+
if (count)
228+
*count = ARRAY_SIZE(dma);
229+
230+
for (i = 0; i < ARRAY_SIZE(dma); i++)
231+
device_list[i] = dma[i].z_dev;
232+
233+
return device_list;
234+
}
235+
222236
/* Initialize all platform DMAC's */
223237
int dmac_init(struct sof *sof)
224238
{

zephyr/lib/userspace_helper.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sof/audio/module_adapter/library/userspace_proxy.h>
2121
#include <sof/lib/mailbox.h>
2222
#include <sof/lib/dai.h>
23+
#include <sof/lib/dma.h>
2324

2425
#define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED
2526

@@ -146,6 +147,21 @@ void user_grant_dai_access_all(struct k_thread *thread)
146147
LOG_DBG("Granted DAI access to thread %p for %zu devices", thread, count);
147148
}
148149

150+
void user_grant_dma_access_all(struct k_thread *thread)
151+
{
152+
const struct device **devices;
153+
size_t count;
154+
size_t i;
155+
156+
devices = dma_get_device_list(&count);
157+
158+
for (i = 0; i < count; i++) {
159+
k_thread_access_grant(thread, devices[i]);
160+
LOG_DBG("Granted DMA device access: %d %s to thread %p",
161+
i, devices[i]->name, thread);
162+
}
163+
}
164+
149165
#else /* CONFIG_USERSPACE */
150166

151167
void *user_stack_allocate(size_t stack_size, uint32_t options)

0 commit comments

Comments
 (0)