regions_mm: Invalidate cache when freeing memory

Platforms based on xtensa have a non-coherent cache between cores. Before
releasing a memory block, it is necessary to invalidate the cache. This
memory block can be allocated by another core and performing cache
writeback by the previous owner will destroy current content of the main
memory.

Invalidate cache when freeing allocated memory block.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
This commit is contained in:
Adrian Warecki 2024-10-02 15:54:11 +02:00 committed by Kai Vehmanen
parent af55b454a1
commit 4570e53f00
1 changed files with 10 additions and 0 deletions

View File

@ -617,6 +617,16 @@ int vmh_free(struct vmh_heap *heap, void *ptr)
if (retval)
return retval;
/* Platforms based on xtensa have a non-coherent cache between cores. Before releasing
* a memory block, it is necessary to invalidate the cache. This memory block can be
* allocated by another core and performing cache writeback by the previous owner will
* destroy current content of the main memory. The cache is invalidated by the
* sys_mm_drv_unmap_region function, when a memory page is unmapped. There is no need to
* invalidate it when releasing buffers of at least a page in size.
*/
if (size_to_free < CONFIG_MM_DRV_PAGE_SIZE)
sys_cache_data_invd_range(ptr, size_to_free);
return vmh_unmap_region(heap->physical_blocks_allocators[mem_block_iter], ptr,
size_to_free);
}