Skip to content

Commit a63f4fa

Browse files
committed
userspace: helper: Add helper to derive partition attribute from pointer
Add function user_get_partition_attr() that returns the appropriate memory partition attribute based on the address. The function returns attribute XTENSA_MMU_CACHED_WB for cacheable addresses so that user space and kernel space threads access memory in a consistent way. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 913f507 commit a63f4fa

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/audio/module_adapter/library/userspace_proxy.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
6161
#if !defined(CONFIG_XTENSA_MMU_DOUBLE_MAP) && defined(CONFIG_SOF_ZEPHYR_HEAP_CACHED)
6262
#define HEAP_PART_CACHED
6363
/* Add cached module private heap to memory partitions */
64-
struct k_mem_partition heap_cached_part = { .attr = K_MEM_PARTITION_P_RW_U_RW };
64+
struct k_mem_partition heap_cached_part = {
65+
.attr = K_MEM_PARTITION_P_RW_U_RW | XTENSA_MMU_CACHED_WB
66+
};
6567

6668
k_mem_region_align(&heap_cached_part.start, &heap_cached_part.size,
6769
POINTER_TO_UINT(sys_cache_cached_ptr_get(heap->init_mem)),
@@ -102,6 +104,7 @@ static int userspace_proxy_add_sections(struct userspace_context *user_ctx, uint
102104

103105
mem_partition.start = mod->segment[idx].v_base_addr;
104106
mem_partition.size = mod->segment[idx].flags.r.length * CONFIG_MM_DRV_PAGE_SIZE;
107+
mem_partition.attr |= user_get_partition_attr(mem_partition.start);
105108

106109
ret = k_mem_domain_add_partition(user_ctx->comp_dom, &mem_partition);
107110

@@ -115,7 +118,8 @@ static int userspace_proxy_add_sections(struct userspace_context *user_ctx, uint
115118

116119
lib_manager_get_instance_bss_address(instance_id, mod, &va_base, &mem_partition.size);
117120
mem_partition.start = POINTER_TO_UINT(va_base);
118-
mem_partition.attr = K_MEM_PARTITION_P_RW_U_RW;
121+
mem_partition.attr = user_get_partition_attr(mem_partition.start) |
122+
K_MEM_PARTITION_P_RW_U_RW;
119123
ret = k_mem_domain_add_partition(user_ctx->comp_dom, &mem_partition);
120124

121125
tr_dbg(&userspace_proxy_tr, "Add bss partition %p + %zx, attr = %u, ret = %d",

zephyr/include/rtos/userspace_helper.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define APP_TASK_BSS
1717
#define APP_TASK_DATA
1818
#else
19-
19+
#include <zephyr/cache.h>
2020
#include <zephyr/app_memory/app_memdomain.h>
2121

2222
#define USER_MOD_HEAP_SIZE ALIGN_UP(CONFIG_SOF_ZEPHYR_USERSPACE_MODULE_HEAP_SIZE, \
@@ -113,6 +113,17 @@ void module_driver_heap_remove(struct k_heap *mod_drv_heap);
113113
*/
114114
int user_access_to_mailbox(struct k_mem_domain *domain, k_tid_t thread_id);
115115

116+
/**
117+
* Derive partition attribute from the pointer. If the address is cacheable, sets the cacheable
118+
* attribute.
119+
*
120+
* @param ptr Address of the partition start
121+
*/
122+
static inline uint32_t user_get_partition_attr(uintptr_t ptr)
123+
{
124+
return sys_cache_is_ptr_cached(UINT_TO_POINTER(ptr)) ? XTENSA_MMU_CACHED_WB : 0;
125+
}
126+
116127
#else
117128

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

0 commit comments

Comments
 (0)