Skip to content

Commit 997bf96

Browse files
committed
zephyr: alloc: ace: calculate L3 heap size based on actual IMR size
Updates the L3 heap management to dynamically calculate heap size based on the actual IMR size reported by hardware registers instead of using hardcoded values. Only initializes the L3 heap when the IMR is actually available and being used, as determined by the ace_imr_used() function, improving robustness by preventing the initialization of unavailable memory regions. Adds proper memory mapping when MMU is enabled, which maps the physical L3 heap memory to a virtual address with appropriate permissions (read/write with write-back caching). MMU mapping is required because it is no longer a fixed region with fixed mapping in Zephyr. This change makes the L3 heap allocation more flexible and adaptable to different hardware configurations. Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
1 parent aa1a021 commit 997bf96

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

zephyr/lib/alloc.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <rtos/symbol.h>
2020
#include <rtos/wait.h>
2121

22+
#if CONFIG_L3_HEAP && CONFIG_MMU
23+
#include <kernel_arch_interface.h>
24+
#endif
25+
2226
#if CONFIG_VIRTUAL_HEAP
2327
#include <sof/lib/regions_mm.h>
2428
#include <zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h>
@@ -158,7 +162,7 @@ static inline size_t get_l3_heap_size(void)
158162
* - IMR base address
159163
* - actual IMR heap start
160164
*/
161-
return ROUND_DOWN(IMR_L3_HEAP_SIZE, L3_MEM_PAGE_SIZE);
165+
return ROUND_DOWN((ace_imr_get_mem_size() - (IMR_L3_HEAP_BASE - L3_MEM_BASE_ADDR)), L3_MEM_PAGE_SIZE);
162166
}
163167

164168
void l3_heap_save(void)
@@ -557,11 +561,16 @@ static int heap_init(void)
557561
sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE);
558562

559563
#if CONFIG_L3_HEAP
560-
if (l3_heap_copy.heap.heap)
564+
if (l3_heap_copy.heap.heap) {
561565
l3_heap = l3_heap_copy;
562-
else
563-
sys_heap_init(&l3_heap.heap, UINT_TO_POINTER(get_l3_heap_start()),
564-
get_l3_heap_size());
566+
} else if (ace_imr_used()) {
567+
#if CONFIG_MMU
568+
uintptr_t va = POINTER_TO_UINT(sys_cache_cached_ptr_get(UINT_TO_POINTER(get_l3_heap_start())));
569+
570+
arch_mem_map(UINT_TO_POINTER(get_l3_heap_start()), va, get_l3_heap_size(), K_MEM_PERM_RW | K_MEM_CACHE_WB);
571+
#endif
572+
sys_heap_init(&l3_heap.heap, UINT_TO_POINTER(get_l3_heap_start()), get_l3_heap_size());
573+
}
565574
#endif
566575

567576
return 0;

0 commit comments

Comments
 (0)