Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4929754

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 <[email protected]>
1 parent aa1a021 commit 4929754

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

zephyr/lib/alloc.c

Lines changed: 17 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,9 @@ 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+
size_t offset = IMR_L3_HEAP_BASE - L3_MEM_BASE_ADDR;
166+
167+
return ROUND_DOWN(ace_imr_get_mem_size() - offset, L3_MEM_PAGE_SIZE);
162168
}
163169

164170
void l3_heap_save(void)
@@ -557,11 +563,17 @@ static int heap_init(void)
557563
sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE);
558564

559565
#if CONFIG_L3_HEAP
560-
if (l3_heap_copy.heap.heap)
566+
if (l3_heap_copy.heap.heap) {
561567
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());
568+
} else if (ace_imr_used()) {
569+
#if CONFIG_MMU
570+
void *cached_ptr = sys_cache_cached_ptr_get(UINT_TO_POINTER(get_l3_heap_start()));
571+
uintptr_t va = POINTER_TO_UINT(cached_ptr);
572+
573+
arch_mem_map(UINT_TO_POINTER(get_l3_heap_start()), va, get_l3_heap_size(), K_MEM_PERM_RW | K_MEM_CACHE_WB);
574+
#endif
575+
sys_heap_init(&l3_heap.heap, UINT_TO_POINTER(get_l3_heap_start()), get_l3_heap_size());
576+
}
565577
#endif
566578

567579
return 0;

0 commit comments

Comments
 (0)