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..2b2d5707a84a 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) +{ + if (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 30326946eda5..64460b791aa6 100644 --- a/zephyr/include/rtos/userspace_helper.h +++ b/zephyr/include/rtos/userspace_helper.h @@ -113,6 +113,20 @@ void module_driver_heap_remove(struct k_heap *mod_drv_heap); */ int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id); +/** + * 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/include/sof/lib/dma.h b/zephyr/include/sof/lib/dma.h index b13f3c25221b..dbec5f88b1f9 100644 --- a/zephyr/include/sof/lib/dma.h +++ b/zephyr/include/sof/lib/dma.h @@ -343,6 +343,13 @@ static inline const struct dma_info *dma_info_get(void) return sof_get()->dma_info; } +/** + * \brief Retrieve the list of all DMA devices. + * \param count Pointer to store the number of devices in the list. + * \return Pointer to the array of device pointers. + */ +const struct device **dma_get_device_list(size_t *count); + /** @}*/ #endif /* __SOF_LIB_DMA_H__ */ diff --git a/zephyr/lib/dma.c b/zephyr/lib/dma.c index 7452459f8b0a..bb7edacfa674 100644 --- a/zephyr/lib/dma.c +++ b/zephyr/lib/dma.c @@ -219,6 +219,20 @@ const struct dma_info lib_dma = { .num_dmas = ARRAY_SIZE(dma) }; +const struct device **dma_get_device_list(size_t *count) +{ + static const struct device *device_list[ARRAY_SIZE(dma)]; + int i; + + if (count) + *count = ARRAY_SIZE(dma); + + for (i = 0; i < ARRAY_SIZE(dma); i++) + device_list[i] = dma[i].z_dev; + + return device_list; +} + /* Initialize all platform DMAC's */ int dmac_init(struct sof *sof) { diff --git a/zephyr/lib/userspace_helper.c b/zephyr/lib/userspace_helper.c index 22b4aa0e139a..7657f3abbc6d 100644 --- a/zephyr/lib/userspace_helper.c +++ b/zephyr/lib/userspace_helper.c @@ -19,12 +19,17 @@ #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 +93,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 +135,37 @@ 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 device **devices; + size_t count; + size_t i; + + devices = dma_get_device_list(&count); + + for (i = 0; i < count; i++) { + k_thread_access_grant(thread, devices[i]); + LOG_DBG("Granted DMA device access: %d %s to thread %p", + i, devices[i]->name, thread); + } +} + +#endif /* CONFIG_SOF_USERSPACE_LL */ + #else /* CONFIG_USERSPACE */ void *user_stack_allocate(size_t stack_size, uint32_t options)