Sound Open Firmware
Loading...
Searching...
No Matches
regions_mm.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause */
2/*
3 * Copyright(c) 2022 - 2023 Intel Corporation. All rights reserved.
4 *
5 * Author: Jakub Dabek <jakub.dabek@intel.com>
6 */
7
14#ifndef ZEPHYR_LIB_REGIONS_MM_H_
15#define ZEPHYR_LIB_REGIONS_MM_H_
16
17#include <adsp_memory.h>
18#include <adsp_memory_regions.h>
19#include <ipc/topology.h>
20#include <rtos/alloc.h>
21#include <sof/list.h>
22#include <zephyr/drivers/mm/system_mm.h>
23#include <zephyr/init.h>
24#include <zephyr/sys/mem_blocks.h>
25
38#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U
40#define VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR 2U
42#define VIRTUAL_REGION_VPAGES_ATTR 3U
43
50#define MAX_MEMORY_ALLOCATORS_COUNT 10
51
55#define DEFAULT_CONFIG_ALOCATORS_COUNT 5
56
64
65/*
66 * Maybe this heap config should have small bundles first going up to max
67 * size or there should be a sorting mechanism for those ?
68 * Should we assume that bundles are given from smallest to biggest ?
69 */
70
82
91struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocating_continuously);
92
99void *vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size);
100
106int vmh_free_heap(struct vmh_heap *heap);
107
114int vmh_free(struct vmh_heap *heap, void *ptr);
115
121void vmh_get_default_heap_config(const struct sys_mm_drv_region *region,
122 struct vmh_heap_config *cfg);
123#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
128void vmh_log_stats(struct vmh_heap *heap);
129
134void vmh_log_alloc_stats(struct vmh_heap *heap);
135#endif
146static inline bool vmh_is_ptr_in_memory_range(uintptr_t ptr, uintptr_t range_start,
147 size_t range_size)
148{
149 return ptr >= range_start && ptr < range_start + range_size;
150}
151
154#endif /* ZEPHYR_LIB_REGIONS_MM_H_ */
Memory allocation API, zones, heaps, and alignment utilities.
#define MAX_MEMORY_ALLOCATORS_COUNT
Maximum amount of memory block allocators in one heap.
Definition regions_mm.h:50
static bool vmh_is_ptr_in_memory_range(uintptr_t ptr, uintptr_t range_start, size_t range_size)
Checks if ptr is in range of given memory range.
Definition regions_mm.h:146
void vmh_get_default_heap_config(const struct sys_mm_drv_region *region, struct vmh_heap_config *cfg)
Generate a default heap partition configuration for a memory driver region.
int vmh_free_heap(struct vmh_heap *heap)
Destroy a virtual memory heap and unmap all backing pages.
void * vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size)
Allocate a memory block from the virtual memory heap.
struct vmh_heap * vmh_init_heap(const struct vmh_heap_config *cfg, bool allocating_continuously)
Initialize a virtual memory heap with the given bundle configuration.
int vmh_free(struct vmh_heap *heap, void *ptr)
Free a memory block previously allocated from a virtual memory heap.
Descriptor for a power-of-2 block size bundle in a virtual memory heap.
Definition regions_mm.h:60
size_t number_of_blocks
Number of memory blocks in this bundle.
Definition regions_mm.h:62
size_t block_size
Size of memory block in bytes.
Definition regions_mm.h:61
This is a struct that aggregates vmh_block_bundle_descriptor to create one cfg that can be passed to ...
Definition regions_mm.h:79
struct vmh_block_bundle_descriptor block_bundles_table[MAX_MEMORY_ALLOCATORS_COUNT]
Definition regions_mm.h:80