13#ifndef ZEPHYR_INCLUDE_SYS_MEM_BLOCKS_H_
14#define ZEPHYR_INCLUDE_SYS_MEM_BLOCKS_H_
28#define MAX_MULTI_ALLOCATORS 8
44struct sys_multi_mem_blocks;
79 (
struct sys_multi_mem_blocks *
group,
void *cfg);
85struct sys_mem_blocks_info {
88#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
94struct sys_mem_blocks {
95 struct sys_mem_blocks_info info;
103#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
107#ifdef CONFIG_OBJ_CORE_SYS_MEM_BLOCKS
112struct sys_multi_mem_blocks {
128#define _SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, blk_sz, num_blks, buf, mbmod) \
129 _SYS_BITARRAY_DEFINE(_sys_mem_blocks_bitmap_##name, \
131 mbmod struct sys_mem_blocks name = { \
132 .info = {num_blks, ilog2(blk_sz)}, \
134 .bitmap = &_sys_mem_blocks_bitmap_##name, \
136 STRUCT_SECTION_ITERABLE_ALTERNATE(sys_mem_blocks_ptr, \
138 __##name##_ptr) = &name; \
139 LINKER_KEEP(__##name##_ptr);
150#define _SYS_MEM_BLOCKS_DEFINE(name, blk_sz, num_blks, balign, mbmod) \
151 mbmod uint8_t __noinit_named(sys_mem_blocks_buf_##name) \
152 __aligned(WB_UP(balign)) \
153 _sys_mem_blocks_buf_##name[num_blks * WB_UP(blk_sz)]; \
154 _SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, blk_sz, num_blks, \
155 _sys_mem_blocks_buf_##name, \
170#define SYS_MEM_BLOCKS_DEFINE(name, blk_sz, num_blks, buf_align) \
171 _SYS_MEM_BLOCKS_DEFINE(name, blk_sz, num_blks, buf_align,)
181#define SYS_MEM_BLOCKS_DEFINE_STATIC(name, blk_sz, num_blks, buf_align) \
182 _SYS_MEM_BLOCKS_DEFINE(name, blk_sz, num_blks, buf_align, static)
193#define SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, blk_sz, num_blks, buf) \
194 _SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, blk_sz, num_blks, buf,)
204#define SYS_MEM_BLOCKS_DEFINE_STATIC_WITH_EXT_BUF(name, blk_sz, num_blks, buf) \
205 _SYS_MEM_BLOCKS_DEFINE_WITH_EXT_BUF(name, blk_sz, num_blks, buf, static)
305#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
381 void *cfg,
size_t count,
401 size_t count,
void **in_blocks);
struct sys_bitarray sys_bitarray_t
Bitarray structure.
Definition bitarray.h:48
struct sys_multi_mem_blocks sys_multi_mem_blocks_t
Multi Memory Blocks Allocator.
Definition mem_blocks.h:58
void sys_multi_mem_blocks_add_allocator(sys_multi_mem_blocks_t *group, sys_mem_blocks_t *alloc)
Add an allocator to an allocator group.
int sys_mem_blocks_get(sys_mem_blocks_t *mem_block, void *in_block, size_t count)
Force allocation of a specified blocks in a memory block object.
sys_mem_blocks_t *(* sys_multi_mem_blocks_choice_fn_t)(struct sys_multi_mem_blocks *group, void *cfg)
Multi memory blocks allocator choice function.
Definition mem_blocks.h:79
int sys_mem_blocks_free_contiguous(sys_mem_blocks_t *mem_block, void *block, size_t count)
Free contiguous multiple memory blocks.
int sys_mem_blocks_alloc(sys_mem_blocks_t *mem_block, size_t count, void **out_blocks)
Allocate multiple memory blocks.
struct sys_mem_blocks sys_mem_blocks_t
Memory Blocks Allocator.
Definition mem_blocks.h:51
int sys_mem_blocks_alloc_contiguous(sys_mem_blocks_t *mem_block, size_t count, void **out_block)
Allocate a contiguous set of memory blocks.
int sys_mem_blocks_is_region_free(sys_mem_blocks_t *mem_block, void *in_block, size_t count)
check if the region is free
int sys_multi_mem_blocks_free(sys_multi_mem_blocks_t *group, size_t count, void **in_blocks)
Free memory allocated from multi memory blocks allocator group.
void sys_multi_mem_blocks_init(sys_multi_mem_blocks_t *group, sys_multi_mem_blocks_choice_fn_t choice_fn)
Initialize multi memory blocks allocator group.
int sys_mem_blocks_free(sys_mem_blocks_t *mem_block, size_t count, void **in_blocks)
Free multiple memory blocks.
int sys_multi_mem_blocks_alloc(sys_multi_mem_blocks_t *group, void *cfg, size_t count, void **out_blocks, size_t *blk_size)
Allocate memory from multi memory blocks allocator group.
Provide ilog2() function.
#define MAX_MULTI_ALLOCATORS
Definition mem_blocks.h:28
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Group structure.
Definition grp.h:18
Object core structure.
Definition obj_core.h:121
Kernel Spin Lock.
Definition spinlock.h:45
Definition mem_stats.h:24