diff --git a/zephyr/Kconfig b/zephyr/Kconfig index d29ad00ad180..d034cd5aa1db 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -50,6 +50,13 @@ config SOF_ZEPHYR_VIRTUAL_HEAP_SIZE NOTE: Keep in mind that the heap size should not be greater than the physical memory size of the system defined in DT (and this includes baseFW text/data). +config SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE + hex "Size in bytes of virtual memory region for virtual heap shared for all cores" + depends on MM_DRV_INTEL_ADSP_MTL_TLB + default 0x100000 + help + This config defines size of virtual heap region shared between all cores + config ZEPHYR_NATIVE_DRIVERS bool "Use Zephyr native drivers" default n diff --git a/zephyr/include/sof/lib/regions_mm.h b/zephyr/include/sof/lib/regions_mm.h index fcd738414470..6c93a2521a93 100644 --- a/zephyr/include/sof/lib/regions_mm.h +++ b/zephyr/include/sof/lib/regions_mm.h @@ -17,6 +17,9 @@ #include #include +/* Attributes for memory regions */ +#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U /*< region dedicated for shared virtual heap */ + /* Dependency on ipc/topology.h created due to memory capability definitions * that are defined there */ diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 77c5aaeccf3e..ff5551881125 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -21,6 +21,7 @@ #if CONFIG_VIRTUAL_HEAP #include +#include struct vmh_heap; struct vmh_heap *virtual_buffers_heap; @@ -288,8 +289,39 @@ static const struct vmh_heap_config static_hp_buffers = { }, }; +/* WA Stubs begin + * + * in order to merge a PR that moves initialization of virtual regions from Zephyr to SOF, + * we need to create weak stubs for 2 functions that will need to be called once the PR is merged + */ + +__weak +uintptr_t adsp_mm_get_unused_l2_start_aligned(void) +{ + return 0; +} + +__weak +int adsp_add_virtual_memory_region(uintptr_t region_address, uint32_t region_size, uint32_t attr) +{ + return 0; +} +/* WA Stubs end */ + static int virtual_heap_init(void) { + int ret; + + if (virtual_buffers_heap) + return -EEXIST; + + /* add a virtual memory region */ + ret = adsp_add_virtual_memory_region(adsp_mm_get_unused_l2_start_aligned(), + CONFIG_SOF_ZEPHYR_VIRTUAL_HEAP_REGION_SIZE, + VIRTUAL_REGION_SHARED_HEAP_ATTR); + if (ret) + return ret; + virtual_buffers_heap = vmh_init_heap(&static_hp_buffers, false); if (!virtual_buffers_heap) { tr_err(&zephyr_tr, "Unable to init virtual heap"); diff --git a/zephyr/lib/regions_mm.c b/zephyr/lib/regions_mm.c index df4989c37106..500f751de96d 100644 --- a/zephyr/lib/regions_mm.c +++ b/zephyr/lib/regions_mm.c @@ -49,10 +49,7 @@ struct vmh_heap { */ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocating_continuously) { - const struct sys_mm_drv_region *virtual_memory_regions = - sys_mm_drv_query_memory_regions(); int i; - struct vmh_heap *new_heap = rzalloc(SOF_MEM_FLAG_KERNEL | SOF_MEM_FLAG_COHERENT, sizeof(*new_heap)); @@ -61,15 +58,14 @@ struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocatin k_mutex_init(&new_heap->lock); struct vmh_heap_config new_config = {0}; - const struct sys_mm_drv_region *region; - SYS_MM_DRV_MEMORY_REGION_FOREACH(virtual_memory_regions, region) { - if (region->attr == MEM_REG_ATTR_SHARED_HEAP) { - new_heap->virtual_region = region; - break; - } - } - if (!new_heap->virtual_region) + /* Workaround - use the very first virtual memory region because of virt addresses + * collision. + * Fix will be provided ASAP, but removing MEM_REG_ATTR_SHARED_HEAP from SOF is required + * to merge Zephyr changes + */ + new_heap->virtual_region = sys_mm_drv_query_memory_regions(); + if (!new_heap->virtual_region || !new_heap->virtual_region->size) goto fail; /* If no config was specified we will use default one */