-
Notifications
You must be signed in to change notification settings - Fork 350
user-space ll: grant access to DAIs and DMAs #10533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cffaeae
b36268a
947349e
b18e8ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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); | ||||||||||||||||||
|
Comment on lines
338
to
+340
|
||||||||||||||||||
| k_thread_access_grant(thread, dt->sem, domain->lock, zephyr_domain->timer); | |
| user_grant_dai_access_all(thread); | |
| user_grant_dma_access_all(thread); | |
| k_thread_access_grant(thread, dt->sem, domain->lock, zephyr_domain->timer); | |
| #if CONFIG_USERSPACE && CONFIG_SOF_USERSPACE_LL | |
| user_grant_dai_access_all(thread); | |
| user_grant_dma_access_all(thread); | |
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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); | ||||||
|
||||||
| const struct device **dma_get_device_list(size_t *count); | |
| const struct device * const *dma_get_device_list(size_t *count); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+222
to
+225
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| *count = ARRAY_SIZE(dma); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (i = 0; i < ARRAY_SIZE(dma); i++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| device_list[i] = dma[i].z_dev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+225
to
+232
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| int i; | |
| if (count) | |
| *count = ARRAY_SIZE(dma); | |
| for (i = 0; i < ARRAY_SIZE(dma); i++) | |
| device_list[i] = dma[i].z_dev; | |
| static struct k_spinlock device_list_lock; | |
| static int device_list_initialized; | |
| int i; | |
| k_spinlock_key_t key; | |
| if (count) | |
| *count = ARRAY_SIZE(dma); | |
| key = k_spin_lock(&device_list_lock); | |
| if (!device_list_initialized) { | |
| for (i = 0; i < ARRAY_SIZE(dma); i++) | |
| device_list[i] = dma[i].z_dev; | |
| device_list_initialized = 1; | |
| } | |
| k_spin_unlock(&device_list_lock, key); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,12 +19,17 @@ | |||||||||||||||||||||||
| #include <sof/audio/module_adapter/module/generic.h> | ||||||||||||||||||||||||
| #include <sof/audio/module_adapter/library/userspace_proxy.h> | ||||||||||||||||||||||||
| #include <sof/lib/mailbox.h> | ||||||||||||||||||||||||
| #include <sof/lib/dai.h> | ||||||||||||||||||||||||
| #include <sof/lib/dma.h> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /* Zephyr includes */ | ||||||||||||||||||||||||
| #include <zephyr/kernel.h> | ||||||||||||||||||||||||
| #include <zephyr/app_memory/app_memdomain.h> | ||||||||||||||||||||||||
| #include <zephyr/logging/log.h> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| 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) | ||||||||||||||||||||||||
|
Comment on lines
+96
to
98
|
||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| 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); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+160
to
+166
|
||||||||||||||||||||||||
| 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); | |
| } | |
| } | |
| for (i = 0; i < count; i++) | |
| k_thread_access_grant(thread, devices[i]); | |
| LOG_DBG("Granted DMA access to thread %p for %zu devices", thread, count); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems count is mandatory ? assert ?