From bb7520457fadcf2be994c23031881e5722f0c3b1 Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Fri, 6 Jul 2018 12:09:58 +0200 Subject: [PATCH] alloc: share memory map with slave cores Adds cache operations in alloc, which allows to properly share memory map with other cores. Signed-off-by: Tomasz Lauda --- src/lib/alloc.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib/alloc.c b/src/lib/alloc.c index 3ca14c3f93e2..7844eb1985ca 100644 --- a/src/lib/alloc.c +++ b/src/lib/alloc.c @@ -117,6 +117,9 @@ static void *rmalloc_sys(size_t bytes) alloc_memset_region(ptr, bytes, DEBUG_BLOCK_ALLOC_VALUE); #endif + dcache_writeback_invalidate_region(&memmap.system, + sizeof(memmap.system)); + return ptr; } @@ -135,6 +138,7 @@ static void *alloc_block(struct mm_heap *heap, int level, hdr->used = 1; heap->info.used += map->block_size; heap->info.free -= map->block_size; + dcache_writeback_invalidate_region(hdr, sizeof(*hdr)); /* find next free */ for (i = map->first_free; i < map->count; ++i) { @@ -151,6 +155,9 @@ static void *alloc_block(struct mm_heap *heap, int level, alloc_memset_region(ptr, map->block_size, DEBUG_BLOCK_ALLOC_VALUE); #endif + dcache_writeback_invalidate_region(map, sizeof(*map)); + dcache_writeback_invalidate_region(heap, sizeof(*heap)); + return ptr; } @@ -201,11 +208,13 @@ static void *alloc_cont_blocks(struct mm_heap *heap, int level, hdr->size = count; heap->info.used += count * map->block_size; heap->info.free -= count * map->block_size; + dcache_writeback_invalidate_region(hdr, sizeof(*hdr)); /* allocate each block */ for (current = start; current < end; current++) { hdr = &map->block[current]; hdr->used = 1; + dcache_writeback_invalidate_region(hdr, sizeof(*hdr)); } /* do we need to find a new first free block ? */ @@ -227,6 +236,9 @@ static void *alloc_cont_blocks(struct mm_heap *heap, int level, alloc_memset_region(ptr, bytes, DEBUG_BLOCK_ALLOC_VALUE); #endif + dcache_writeback_invalidate_region(map, sizeof(*map)); + dcache_writeback_invalidate_region(heap, sizeof(*heap)); + return ptr; } @@ -334,6 +346,7 @@ static void free_block(void *ptr) block_map->free_count++; heap->info.used -= block_map->block_size; heap->info.free += block_map->block_size; + dcache_writeback_invalidate_region(hdr, sizeof(*hdr)); } /* set first free block */ @@ -343,6 +356,9 @@ static void free_block(void *ptr) #if DEBUG_BLOCK_FREE alloc_memset_region(ptr, block_map->block_size * (i - 1), DEBUG_BLOCK_FREE_VALUE); #endif + + dcache_writeback_invalidate_region(block_map, sizeof(*block_map)); + dcache_writeback_invalidate_region(heap, sizeof(*heap)); } /* allocate single block for runtime */ @@ -612,6 +628,8 @@ void init_heap(struct sof *sof) current_map = &heap->map[j]; current_map->base = heap->heap; + dcache_writeback_region(current_map, + sizeof(*current_map)); for (k = 1; k < heap->blocks; k++) { next_map = &heap->map[k]; @@ -619,6 +637,8 @@ void init_heap(struct sof *sof) current_map->block_size * current_map->count; current_map = &heap->map[k]; + dcache_writeback_region(current_map, + sizeof(*current_map)); } } } @@ -631,6 +651,8 @@ void init_heap(struct sof *sof) current_map = &heap->map[j]; current_map->base = heap->heap; + dcache_writeback_region(current_map, + sizeof(*current_map)); for (k = 1; k < heap->blocks; k++) { next_map = &heap->map[k]; @@ -638,6 +660,8 @@ void init_heap(struct sof *sof) current_map->block_size * current_map->count; current_map = &heap->map[k]; + dcache_writeback_region(current_map, + sizeof(*current_map)); } } }