1 /*
2 * Copyright (c) 2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * @brief Driver handling memory regions related
10 * functions
11 */
12
13 #include "mm_drv_intel_adsp.h"
14
15 struct sys_mm_drv_region
16 virtual_memory_regions[CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT] = { {0} };
17
sys_mm_drv_query_memory_regions(void)18 const struct sys_mm_drv_region *sys_mm_drv_query_memory_regions(void)
19 {
20 return (const struct sys_mm_drv_region *) virtual_memory_regions;
21 }
22
append_region(void * address,uint32_t mem_size,uint32_t attributes,uint32_t position,uint32_t * total_size)23 static inline void append_region(void *address, uint32_t mem_size,
24 uint32_t attributes, uint32_t position, uint32_t *total_size)
25 {
26 virtual_memory_regions[position].addr = address;
27 virtual_memory_regions[position].size = mem_size;
28 virtual_memory_regions[position].attr = attributes;
29 total_size += mem_size;
30 }
31
calculate_memory_regions(uintptr_t static_alloc_end_ptr)32 int calculate_memory_regions(uintptr_t static_alloc_end_ptr)
33 {
34 int i, total_size = 0;
35
36 for (i = 0; i < CONFIG_MP_MAX_NUM_CPUS; i++) {
37 append_region((void *)(static_alloc_end_ptr + i * CORE_HEAP_SIZE),
38 CORE_HEAP_SIZE, MEM_REG_ATTR_CORE_HEAP, i, &total_size);
39 }
40
41 append_region((void *)((uintptr_t)virtual_memory_regions[i - 1].addr +
42 virtual_memory_regions[i - 1].size),
43 CORE_HEAP_SIZE, MEM_REG_ATTR_SHARED_HEAP, i, &total_size);
44 i++;
45 append_region((void *)((uintptr_t)virtual_memory_regions[i - 1].addr +
46 virtual_memory_regions[i - 1].size),
47 OPPORTUNISTIC_REGION_SIZE, MEM_REG_ATTR_OPPORTUNISTIC_MEMORY, i, &total_size);
48 i++;
49 /* Apending last region as 0 so iterators know where table is over
50 * check is for size = 0;
51 */
52 append_region(NULL, 0, 0, i, &total_size);
53
54 if (total_size > L2_VIRTUAL_SRAM_SIZE) {
55 return -EINVAL;
56 }
57
58 return 0;
59 }
60