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
8#ifndef ZEPHYR_LIB_REGIONS_MM_H_
9#define ZEPHYR_LIB_REGIONS_MM_H_
10
11#include <adsp_memory.h>
12#include <adsp_memory_regions.h>
13#include <ipc/topology.h>
14#include <rtos/alloc.h>
15#include <sof/list.h>
16#include <zephyr/drivers/mm/system_mm.h>
17#include <zephyr/init.h>
18#include <zephyr/sys/mem_blocks.h>
19
20/* Attributes for memory regions */
21#define VIRTUAL_REGION_SHARED_HEAP_ATTR 1U /*< region for shared virtual heap */
22#define VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR 2U /*< region for LLEXT libraries */
23#define VIRTUAL_REGION_VPAGES_ATTR 3U /*< region for virtual page allocator */
24
25/* Dependency on ipc/topology.h created due to memory capability definitions
26 * that are defined there
27 */
28
29/* API is NOT re-entry safe.
30 * This is due to our assumption that only management code will ever handle
31 * memory operations on heaps themselves.
32 */
33
34/* Defines maximum amount of memory block allocators in one heap
35 * since minimum realistic block should be cache line size
36 * and block sizes in allocator must be powers of 2
37 * so logically it gives limited block sizes
38 * eg allocator of block size 64 128 256 512 2048 4096 1024 8192
39 * would end up in 8 allocators.
40 * It is expected that allocations bigger than that would
41 * either be spanned on specifically configured heap or have
42 * individual configs with bigger block sizes.
43 */
44#define MAX_MEMORY_ALLOCATORS_COUNT 10
45
46/* vmh_get_default_heap_config() function will try to split the region
47 * down the given count. Only applicable when API client did not
48 * use its config.
49 */
50#define DEFAULT_CONFIG_ALOCATORS_COUNT 5
51
56
57/*
58 * Maybe this heap config should have small bundles first going up to max
59 * size or there should be a sorting mechanism for those ?
60 * Should we assume that bundles are given from smallest to biggest ?
61 */
62
74
75struct vmh_heap *vmh_init_heap(const struct vmh_heap_config *cfg, bool allocating_continuously);
76void *vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size);
77int vmh_free_heap(struct vmh_heap *heap);
78int vmh_free(struct vmh_heap *heap, void *ptr);
79void vmh_get_default_heap_config(const struct sys_mm_drv_region *region,
80 struct vmh_heap_config *cfg);
81#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
82void vmh_log_stats(struct vmh_heap *heap);
83#endif
94static inline bool vmh_is_ptr_in_memory_range(uintptr_t ptr, uintptr_t range_start,
95 size_t range_size)
96{
97 return ptr >= range_start && ptr < range_start + range_size;
98}
99
100#endif /* ZEPHYR_LIB_REGIONS_MM_H_ */
#define MAX_MEMORY_ALLOCATORS_COUNT
Definition regions_mm.h:44
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:94
void vmh_get_default_heap_config(const struct sys_mm_drv_region *region, struct vmh_heap_config *cfg)
int vmh_free_heap(struct vmh_heap *heap)
void * vmh_alloc(struct vmh_heap *heap, uint32_t alloc_size)
struct vmh_heap * vmh_init_heap(const struct vmh_heap_config *cfg, bool allocating_continuously)
int vmh_free(struct vmh_heap *heap, void *ptr)
Definition regions_mm.h:52
size_t number_of_blocks
number of memory blocks.
Definition regions_mm.h:54
size_t block_size
size of memory block.
Definition regions_mm.h:53
This is a struct that aggregates vmh_block_bundle_descriptor to create one cfg that can be passed to ...
Definition regions_mm.h:71
struct vmh_block_bundle_descriptor block_bundles_table[MAX_MEMORY_ALLOCATORS_COUNT]
Definition regions_mm.h:72