diff options
| author | Anup Patel <[email protected]> | 2023-04-18 18:38:21 +0530 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2023-06-05 15:46:09 +0530 |
| commit | 40d36a6673131e36075b1df78af4d7ab92e8cc01 (patch) | |
| tree | 41243bf53570e943d7f6cad5116674fe3ab33c5f /include | |
| parent | 5cf9a540164a018a31a679578a27eb964af0340d (diff) | |
lib: sbi: Introduce simple heap allocator
We provide simple heap allocator to manage the heap space provided
by OpenSBI firmware and platform.
Signed-off-by: Anup Patel <[email protected]>
Reviewed-by: Andrew Jones <[email protected]>
Diffstat (limited to 'include')
| -rw-r--r-- | include/sbi/sbi_heap.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/sbi/sbi_heap.h b/include/sbi/sbi_heap.h new file mode 100644 index 00000000..88d176ef --- /dev/null +++ b/include/sbi/sbi_heap.h @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2023 Ventana Micro Systems Inc. + * + * Authors: + * Anup Patel<[email protected]> + */ + +#ifndef __SBI_HEAP_H__ +#define __SBI_HEAP_H__ + +#include <sbi/sbi_types.h> + +struct sbi_scratch; + +/** Allocate from heap area */ +void *sbi_malloc(size_t size); + +/** Zero allocate from heap area */ +void *sbi_zalloc(size_t size); + +/** Allocate array from heap area */ +static inline void *sbi_calloc(size_t nitems, size_t size) +{ + return sbi_zalloc(nitems * size); +} + +/** Free-up to heap area */ +void sbi_free(void *ptr); + +/** Amount (in bytes) of free space in the heap area */ +unsigned long sbi_heap_free_space(void); + +/** Amount (in bytes) of used space in the heap area */ +unsigned long sbi_heap_used_space(void); + +/** Amount (in bytes) of reserved space in the heap area */ +unsigned long sbi_heap_reserved_space(void); + +/** Initialize heap area */ +int sbi_heap_init(struct sbi_scratch *scratch); + +#endif |
