Skip to content

Commit 28afde6

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

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/include/sof/lib/dai-zephyr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ void dai_release_llp_slot(struct dai_data *dd);
306306
* \brief Retrieve a pointer to the Zephyr device structure for a DAI of a given type and index.
307307
*/
308308
const struct device *dai_get_device(uint32_t type, uint32_t index);
309+
310+
/**
311+
* \brief Retrieve the list of all DAI devices.
312+
* \param count Pointer to store the number of devices in the list.
313+
* \return Pointer to the array of device pointers.
314+
*/
315+
const struct device **dai_get_device_list(size_t *count);
309316
/** @}*/
310317

311318
#endif /* __SOF_LIB_DAI_ZEPHYR_H__ */

src/lib/dai.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ const struct device *zephyr_dev[] = {
187187
#endif
188188
};
189189

190+
const struct device **dai_get_device_list(size_t *count)
191+
{
192+
__ASSERT_NO_MSG(count);
193+
*count = ARRAY_SIZE(zephyr_dev);
194+
195+
return zephyr_dev;
196+
}
197+
190198
/* convert sof_ipc_dai_type to Zephyr dai_type */
191199
static int sof_dai_type_to_zephyr(uint32_t type)
192200
{

zephyr/include/rtos/userspace_helper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ static inline uint32_t user_get_partition_attr(uintptr_t ptr)
126126
return sys_cache_is_ptr_cached(UINT_TO_POINTER(ptr)) ? XTENSA_MMU_CACHED_WB : 0;
127127
}
128128

129+
/**
130+
* Grant DAI device access to a user-space thread.
131+
*
132+
* @param thread user-space thread for which DAI access is granted
133+
*/
134+
void user_grant_dai_access_all(struct k_thread *thread);
135+
129136
#else
130137

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

zephyr/lib/userspace_helper.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
#include <sof/audio/module_adapter/module/generic.h>
2020
#include <sof/audio/module_adapter/library/userspace_proxy.h>
2121
#include <sof/lib/mailbox.h>
22+
#include <sof/lib/dai.h>
2223

2324
#define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED
2425

2526
/* Zephyr includes */
2627
#include <zephyr/kernel.h>
2728
#include <zephyr/app_memory/app_memdomain.h>
29+
#include <zephyr/logging/log.h>
30+
31+
LOG_MODULE_REGISTER(userspace_helper, CONFIG_SOF_LOG_LEVEL);
2832

2933
#if CONFIG_USERSPACE
3034

@@ -128,6 +132,20 @@ int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id)
128132
return 0;
129133
}
130134

135+
void user_grant_dai_access_all(struct k_thread *thread)
136+
{
137+
const struct device **devices;
138+
size_t count;
139+
size_t i;
140+
141+
devices = dai_get_device_list(&count);
142+
143+
for (i = 0; i < count; i++)
144+
k_thread_access_grant(thread, devices[i]);
145+
146+
LOG_DBG("Granted DAI access to thread %p for %zu devices", thread, count);
147+
}
148+
131149
#else /* CONFIG_USERSPACE */
132150

133151
void *user_stack_allocate(size_t stack_size, uint32_t options)

0 commit comments

Comments
 (0)