diff --git a/src/include/sof/lib/dai-zephyr.h b/src/include/sof/lib/dai-zephyr.h index 5a15399190ee..049adba4a656 100644 --- a/src/include/sof/lib/dai-zephyr.h +++ b/src/include/sof/lib/dai-zephyr.h @@ -306,6 +306,13 @@ void dai_release_llp_slot(struct dai_data *dd); * \brief Retrieve a pointer to the Zephyr device structure for a DAI of a given type and index. */ const struct device *dai_get_device(uint32_t type, uint32_t index); + +/** + * \brief Retrieve the list of all DAI devices. + * \param count Pointer to store the number of devices in the list. + * \return Pointer to the array of device pointers. + */ +const struct device **dai_get_device_list(size_t *count); /** @}*/ #endif /* __SOF_LIB_DAI_ZEPHYR_H__ */ diff --git a/src/lib/dai.c b/src/lib/dai.c index 0c11d25f9732..ca18b53a3e79 100644 --- a/src/lib/dai.c +++ b/src/lib/dai.c @@ -187,6 +187,14 @@ const struct device *zephyr_dev[] = { #endif }; +const struct device **dai_get_device_list(size_t *count) +{ + __ASSERT_NO_MSG(count); + *count = ARRAY_SIZE(zephyr_dev); + + return zephyr_dev; +} + /* convert sof_ipc_dai_type to Zephyr dai_type */ static int sof_dai_type_to_zephyr(uint32_t type) { diff --git a/src/schedule/zephyr_domain.c b/src/schedule/zephyr_domain.c index 9a3ef284fd30..6a5812353d9e 100644 --- a/src/schedule/zephyr_domain.c +++ b/src/schedule/zephyr_domain.c @@ -336,6 +336,8 @@ static int zephyr_domain_register_user(struct ll_schedule_domain *domain, k_mem_domain_add_thread(zephyr_ll_mem_domain(), thread); k_thread_access_grant(thread, dt->sem, domain->lock, zephyr_domain->timer); + user_grant_dai_access_all(thread); + user_grant_dma_access_all(thread); tr_dbg(&ll_tr, "granted LL access to thread %p (core %d)", thread, core); k_thread_start(thread); diff --git a/zephyr/include/rtos/userspace_helper.h b/zephyr/include/rtos/userspace_helper.h index e1b692ea4cbc..8cdcc4b291f6 100644 --- a/zephyr/include/rtos/userspace_helper.h +++ b/zephyr/include/rtos/userspace_helper.h @@ -126,6 +126,20 @@ static inline uint32_t user_get_partition_attr(uintptr_t ptr) return sys_cache_is_ptr_cached(UINT_TO_POINTER(ptr)) ? XTENSA_MMU_CACHED_WB : 0; } +/** + * Grant DAI device access to a user-space thread. + * + * @param thread user-space thread for which DAI access is granted + */ +void user_grant_dai_access_all(struct k_thread *thread); + +/** + * Grant DMA device access to a user-space thread. + * + * @param thread user-space thread for which DMA access is granted + */ +void user_grant_dma_access_all(struct k_thread *thread); + #else static inline int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id) diff --git a/zephyr/lib/userspace_helper.c b/zephyr/lib/userspace_helper.c index 22b4aa0e139a..0aecf7079256 100644 --- a/zephyr/lib/userspace_helper.c +++ b/zephyr/lib/userspace_helper.c @@ -15,16 +15,22 @@ #include #include +#include #include #include #include #include +#include +#include #define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED /* Zephyr includes */ #include #include +#include + +LOG_MODULE_REGISTER(userspace_helper, CONFIG_SOF_LOG_LEVEL); #if CONFIG_USERSPACE @@ -88,6 +94,8 @@ int user_memory_attach_common_partition(struct k_mem_domain *dom) return k_mem_domain_add_partition(dom, &common_partition); } +#ifdef CONFIG_SOF_USERSPACE_LL + int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id) { struct k_mem_partition mem_partition; @@ -128,6 +136,33 @@ int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id) return 0; } +void user_grant_dai_access_all(struct k_thread *thread) +{ + const struct device **devices; + size_t count; + size_t i; + + devices = dai_get_device_list(&count); + + for (i = 0; i < count; i++) + k_thread_access_grant(thread, devices[i]); + + LOG_DBG("Granted DAI access to thread %p for %zu devices", thread, count); +} + +void user_grant_dma_access_all(struct k_thread *thread) +{ + const struct dma_info *info = dma_info_get(); + struct sof_dma *d; + + for (d = info->dma_array; d < info->dma_array + info->num_dmas; d++) { + k_thread_access_grant(thread, d->z_dev); + LOG_DBG("Granted DMA device access: %s to thread %p", d->z_dev->name, thread); + } +} + +#endif /* CONFIG_SOF_USERSPACE_LL */ + #else /* CONFIG_USERSPACE */ void *user_stack_allocate(size_t stack_size, uint32_t options)