1212#ifndef __ZEPHYR_LIB_USERSPACE_HELPER_H__
1313#define __ZEPHYR_LIB_USERSPACE_HELPER_H__
1414
15- #ifdef CONFIG_USERSPACE
15+ #include <zephyr/sys/sys_heap.h>
16+ #include <zephyr/sys/sem.h>
17+ #include <zephyr/app_memory/app_memdomain.h>
18+
19+ #ifndef CONFIG_USERSPACE
20+ #define APP_TASK_DATA
21+ #else
1622#define DRV_HEAP_SIZE ALIGN_UP(CONFIG_SOF_ZEPHYR_USERSPACE_MODULE_HEAP_SIZE, \
1723 CONFIG_MM_DRV_PAGE_SIZE)
1824
25+ #define APP_TASK_BSS K_APP_BMEM(common_partition)
26+ #define APP_TASK_DATA K_APP_DMEM(common_partition)
27+
1928struct processing_module ;
2029struct userspace_context ;
2130
@@ -33,6 +42,40 @@ struct userspace_context;
3342 */
3443struct sys_heap * drv_heap_init (void );
3544
45+ void * drv_heap_alloc (struct sys_heap * drv_heap , size_t bytes );
46+
47+ /**
48+ * Add memory region to non-privileged module memory domain.
49+ * @param domain - pointer to the modules memory domain.
50+ * @param addr - pointer to memory region start
51+ * @param size - size of the memory region
52+ * @param attr - memory region access attributes
53+ *
54+ * @return 0 for success, error otherwise.
55+ *
56+ * @note
57+ * Function used only when CONFIG_USERSPACE is set.
58+ * Function adds page aligned region to the memory domain.
59+ * Caller should take care to not expose other data than these
60+ * intended to be shared with the module.
61+ */
62+ int user_add_memory (struct k_mem_domain * domain , uintptr_t addr , size_t size , uint32_t attr );
63+
64+ /**
65+ * Remove memory region from non-privileged module memory domain.
66+ * @param domain - pointer to the modules memory domain.
67+ * @param addr - pointer to memory region start
68+ * @param size - size of the memory region
69+ *
70+ * @return 0 for success, error otherwise.
71+ *
72+ * @note
73+ * Function used only when CONFIG_USERSPACE is set.
74+ * Function removes previously added page aligned region
75+ * from the memory domain.
76+ */
77+ int user_remove_memory (struct k_mem_domain * domain , uintptr_t addr , size_t size );
78+
3679/**
3780 * Add DP scheduler created thread to module memory domain.
3881 * @param thread_id - id of thread to be added to memory domain.
0 commit comments