Skip to content

Commit e5620c5

Browse files
committed
add memory partition
1 parent 57cfcdc commit e5620c5

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

src/audio/module_adapter/library/userspace_proxy.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
297297
tr_err(&userspace_proxy_tr, "Heap partition %#lx + %zx, attr = %u",
298298
heap_part.start, heap_part.size, heap_part.attr);
299299

300+
/* When a new memory domain is created, only the "factory" entries from the L2 page
301+
* tables are copied. Memory that was dynamically mapped during firmware execution
302+
* will not be accessible from the new domain. The k_heap structure (drv->user_heap)
303+
* resides in such dynamically mapped memory, so we must explicitly add a partition
304+
* for it to ensure that syscalls can access this structure from the userspace domain.
305+
*/
306+
struct k_mem_partition heap_struct_part;
307+
308+
k_mem_region_align(&heap_struct_part.start, &heap_struct_part.size,
309+
POINTER_TO_UINT(drv->user_heap),
310+
sizeof(*drv->user_heap), CONFIG_MM_DRV_PAGE_SIZE);
311+
heap_struct_part.attr = K_MEM_PARTITION_P_RW_U_NA |
312+
user_get_partition_attr(heap_struct_part.start) | XTENSA_MMU_PERM_W;
313+
314+
tr_err(&userspace_proxy_tr, "Heap struct partition %#lx + %zx, attr = %u",
315+
heap_struct_part.start, heap_struct_part.size, heap_struct_part.attr);
316+
300317
#if defined(CONFIG_SOF_ZEPHYR_HEAP_CACHED)
301318
/* Add cached module private heap to memory partitions */
302319
struct k_mem_partition heap_cached_part = {
@@ -319,7 +336,8 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
319336
#ifdef CONFIG_SOF_ZEPHYR_HEAP_CACHED
320337
&heap_cached_part,
321338
#endif
322-
&heap_part
339+
&heap_part,
340+
&heap_struct_part
323341
};
324342

325343
tr_err(&userspace_proxy_tr, "Common partition %#lx + %zx, attr = %u",
@@ -510,9 +528,8 @@ static int userspace_proxy_init(struct processing_module *mod)
510528
comp_dbg(mod->dev, "start");
511529
DEBUG(mod);
512530

513-
//dump_domain_page_tables(mod->user_ctx->comp_dom, mod->priv.resources.heap, true);
531+
dump_domain_page_tables(mod->user_ctx->comp_dom, mod->priv.resources.heap, false);
514532
//dump_domain_page_tables(mod->user_ctx->comp_dom, mod->priv.resources.heap->heap.heap, true);
515-
return -EINVAL;
516533

517534
#if IS_ENABLED(CONFIG_SOF_USERSPACE_MOD_IPC_BY_DP_THREAD)
518535
/* Start the system agent, if provided. Params is already filled by

0 commit comments

Comments
 (0)