1 // SPDX-License-Identifier: BSD-3-Clause 2 /* 3 * Copyright(c) 2022 Intel Corporation. All rights reserved. 4 * 5 * Author: Jakub Dabek <jakub.dabek@intel.com> 6 */ 7 8 #include <sof/lib/regions_mm.h> 9 10 struct virtual_memory_heap 11 vm_heaps[CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT]; 12 13 /** 14 * @brief Fill vm_heaps array with information from zephyr. 15 * 16 * Virtual memory regions calculated in zephyr are translated here 17 * to a struct that will keep all information on current allocations 18 * and virtual to physical mappings that are related to heaps. 19 * System heap is not a part of this information. It only refers to 20 * virtual first heaps. 21 * Has to be initialized after calculations for regions is done in zephyr. 22 */ virtual_heaps_init(void)23static int virtual_heaps_init(void) 24 { 25 26 struct sys_mm_drv_region *virtual_memory_regions = 27 (struct sys_mm_drv_region *)sys_mm_drv_query_memory_regions(); 28 29 for (size_t i = 0; 30 i < CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT; 31 i++) { 32 vm_heaps[i].virtual_region = &virtual_memory_regions[i]; 33 34 switch (virtual_memory_regions[i].attr) { 35 case MEM_REG_ATTR_CORE_HEAP: 36 vm_heaps[i].memory_caps = 37 SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP | SOF_MEM_CAPS_CACHE; 38 break; 39 case MEM_REG_ATTR_SHARED_HEAP: 40 vm_heaps[i].memory_caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP; 41 break; 42 case MEM_REG_ATTR_OPPORTUNISTIC_MEMORY: 43 vm_heaps[i].memory_caps = SOF_MEM_CAPS_RAM | SOF_MEM_CAPS_HP; 44 break; 45 default: 46 return -EINVAL; 47 } 48 } 49 50 return 0; 51 } 52 53 SYS_INIT(virtual_heaps_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); 54