Skip to content

Commit f56f51a

Browse files
committed
userspace: proxy: Add partition for k_heap struct
Add a memory partition for the module driver heap k_heap structure to the module's memory domain to allow it to be referenced by syscalls. When a new memory domain is created, only L2 entries mapped with OPTION_SAVE_ATTRS are copied. Memory mapped dynamically during firmware execution is not accessible in new memory domains by default. Update the code to reflect the removal of memory double mapping in Zephyr by replacing the CONFIG_XTENSA_MMU_DOUBLE_MAP with a simple CONFIG_SOF_ZEPHYR_HEAP_CACHED check. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 3533f3a commit f56f51a

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/audio/module_adapter/library/userspace_proxy.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,25 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
278278
tr_dbg(&userspace_proxy_tr, "Heap partition %#lx + %zx, attr = %u",
279279
heap_part.start, heap_part.size, heap_part.attr);
280280

281-
#if !defined(CONFIG_XTENSA_MMU_DOUBLE_MAP) && defined(CONFIG_SOF_ZEPHYR_HEAP_CACHED)
282-
#define HEAP_PART_CACHED
281+
/* When a new memory domain is created, only the "factory" entries from the L2 page
282+
* tables are copied. Memory that was dynamically mapped during firmware execution
283+
* will not be accessible from the new domain. The k_heap structure (drv->user_heap)
284+
* resides in such dynamically mapped memory, so we must explicitly add a partition
285+
* for it to ensure that syscalls can access this structure from the userspace domain.
286+
*/
287+
struct k_mem_partition heap_struct_part = {
288+
.attr = K_MEM_PARTITION_P_RW_U_NA |
289+
user_get_partition_cache_attr(POINTER_TO_UINT(drv->user_heap))
290+
};
291+
292+
k_mem_region_align(&heap_struct_part.start, &heap_struct_part.size,
293+
POINTER_TO_UINT(drv->user_heap),
294+
sizeof(*drv->user_heap), CONFIG_MM_DRV_PAGE_SIZE);
295+
296+
tr_dbg(&userspace_proxy_tr, "Heap struct partition %#lx + %zx, attr = %u",
297+
heap_struct_part.start, heap_struct_part.size, heap_struct_part.attr);
298+
299+
#if defined(CONFIG_SOF_ZEPHYR_HEAP_CACHED)
283300
/* Add cached module private heap to memory partitions */
284301
struct k_mem_partition heap_cached_part = {
285302
.attr = K_MEM_PARTITION_P_RW_U_RW | XTENSA_MMU_CACHED_WB
@@ -298,10 +315,11 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
298315
* These include ops structures marked with APP_TASK_DATA.
299316
*/
300317
&common_partition,
301-
#ifdef HEAP_PART_CACHED
318+
#ifdef CONFIG_SOF_ZEPHYR_HEAP_CACHED
302319
&heap_cached_part,
303320
#endif
304-
&heap_part
321+
&heap_part,
322+
&heap_struct_part
305323
};
306324

307325
tr_dbg(&userspace_proxy_tr, "Common partition %#lx + %zx, attr = %u",

zephyr/lib/userspace_helper.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <sof/lib/dai.h>
2424
#include <sof/lib/dma.h>
2525

26-
#define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED
27-
2826
/* Zephyr includes */
2927
#include <zephyr/kernel.h>
3028
#include <zephyr/app_memory/app_memdomain.h>

0 commit comments

Comments
 (0)