From 8cad5bea57325e3102cb3beb306e0bd0916922f2 Mon Sep 17 00:00:00 2001 From: Jaroslaw Stelter Date: Wed, 31 Jan 2024 11:24:55 +0100 Subject: [PATCH] lib: alloc: Use aligned allocation for L3_HEAP usage. L3_HEAP is used in library manager for library storage buffer allocation and in D3 enter/exit flows to allocate IMR context storage buffer. Both buffers should be aligned so use rballoc_align() routine to get correctly aligned buffers. Signed-off-by: Jaroslaw Stelter --- src/library_manager/lib_manager.c | 8 +++----- zephyr/lib/cpu.c | 14 ++++++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/library_manager/lib_manager.c b/src/library_manager/lib_manager.c index 9db92e8d4..1b74c3ce7 100644 --- a/src/library_manager/lib_manager.c +++ b/src/library_manager/lib_manager.c @@ -671,16 +671,14 @@ static void __sparse_cache *lib_manager_allocate_store_mem(uint32_t size, void __sparse_cache *local_add; #if CONFIG_L3_HEAP uint32_t caps = SOF_MEM_CAPS_L3 | SOF_MEM_CAPS_DMA; - - /* allocate new buffer: cached alias */ - local_add = (__sparse_force void __sparse_cache *)rmalloc(SOF_MEM_ZONE_SYS, 0, caps, size); #else - uint32_t addr_align = PAGE_SZ; uint32_t caps = SOF_MEM_CAPS_DMA; +#endif + uint32_t addr_align = PAGE_SZ; /* allocate new buffer: cached alias */ local_add = (__sparse_force void __sparse_cache *)rballoc_align(0, caps, size, addr_align); -#endif + if (!local_add) { tr_err(&lib_manager_tr, "lib_manager_allocate_store_mem(): alloc failed"); return NULL; diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 3dde19dc3..87ca92b9d 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -96,10 +96,16 @@ void cpu_notify_state_entry(enum pm_state state) storage_buffer_size += LP_SRAM_SIZE; /* allocate IMR buffer and store it in the global pointer */ - global_imr_ram_storage = rmalloc(SOF_MEM_ZONE_SYS_RUNTIME, - 0, - SOF_MEM_CAPS_L3, - storage_buffer_size); + global_imr_ram_storage = rballoc_align(0, SOF_MEM_CAPS_L3, + storage_buffer_size, + PLATFORM_DCACHE_ALIGN); + + /* If no IMR buffer we can not recover */ + if (!global_imr_ram_storage) { + tr_err(&zephyr_tr, "failed to allocate global_imr_ram_storage"); + k_panic(); + } + #endif /* CONFIG_ADSP_IMR_CONTEXT_SAVE */ } }