aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorGregor Haas <gregorhaas1997@gmail.com>2024-08-08 20:16:36 -0700
committerAnup Patel <anup@brainfault.org>2024-08-09 08:51:24 +0530
commit8b898c4e50d841d5d84d7d3f8240a35e78d25fb8 (patch)
tree5384f6710ab44f16dc98f05d5c6e3fc2247c5787 /include
parent6a090ee9dc687bb4f39c56a6fd77898257c0f6d7 (diff)
downloadopensbi-8b898c4e50d841d5d84d7d3f8240a35e78d25fb8.tar.gz
opensbi-8b898c4e50d841d5d84d7d3f8240a35e78d25fb8.tar.bz2
opensbi-8b898c4e50d841d5d84d7d3f8240a35e78d25fb8.zip
lib: sbi: Support multiple heaps
The upcoming SMMTT implementation will require some larger contiguous memory regions for the memory tracking tables. We plan to specify the memory region for these tables as a reserved-memory node in the device tree, and then dynamically allocate individual tables out of this region. These changes to the SBI heap allocator will allow us to explicitly create and allocate from a dedicated heap tied to the table memory region. Signed-off-by: Gregor Haas <gregorhaas1997@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include')
-rw-r--r--include/sbi/sbi_heap.h57
1 files changed, 51 insertions, 6 deletions
diff --git a/include/sbi/sbi_heap.h b/include/sbi/sbi_heap.h
index 16755ec9..9a670905 100644
--- a/include/sbi/sbi_heap.h
+++ b/include/sbi/sbi_heap.h
@@ -12,16 +12,32 @@
#include <sbi/sbi_types.h>
+/* Opaque declaration of heap control struct */
+struct sbi_heap_control;
+
+/* Global heap control structure */
+extern struct sbi_heap_control global_hpctrl;
+
/* Alignment of heap base address and size */
#define HEAP_BASE_ALIGN 1024
struct sbi_scratch;
/** Allocate from heap area */
-void *sbi_malloc(size_t size);
+void *sbi_malloc_from(struct sbi_heap_control *hpctrl, size_t size);
+
+static inline void *sbi_malloc(size_t size)
+{
+ return sbi_malloc_from(&global_hpctrl, size);
+}
/** Zero allocate from heap area */
-void *sbi_zalloc(size_t size);
+void *sbi_zalloc_from(struct sbi_heap_control *hpctrl, size_t size);
+
+static inline void *sbi_zalloc(size_t size)
+{
+ return sbi_zalloc_from(&global_hpctrl, size);
+}
/** Allocate array from heap area */
static inline void *sbi_calloc(size_t nitems, size_t size)
@@ -29,19 +45,48 @@ static inline void *sbi_calloc(size_t nitems, size_t size)
return sbi_zalloc(nitems * size);
}
+static inline void *sbi_calloc_from(struct sbi_heap_control *hpctrl,
+ size_t nitems, size_t size)
+{
+ return sbi_zalloc_from(hpctrl, nitems * size);
+}
+
/** Free-up to heap area */
-void sbi_free(void *ptr);
+void sbi_free_from(struct sbi_heap_control *hpctrl, void *ptr);
+
+static inline void sbi_free(void *ptr)
+{
+ return sbi_free_from(&global_hpctrl, ptr);
+}
/** Amount (in bytes) of free space in the heap area */
-unsigned long sbi_heap_free_space(void);
+unsigned long sbi_heap_free_space_from(struct sbi_heap_control *hpctrl);
+
+static inline unsigned long sbi_heap_free_space(void)
+{
+ return sbi_heap_free_space_from(&global_hpctrl);
+}
/** Amount (in bytes) of used space in the heap area */
-unsigned long sbi_heap_used_space(void);
+unsigned long sbi_heap_used_space_from(struct sbi_heap_control *hpctrl);
+
+static inline unsigned long sbi_heap_used_space(void)
+{
+ return sbi_heap_used_space_from(&global_hpctrl);
+}
/** Amount (in bytes) of reserved space in the heap area */
-unsigned long sbi_heap_reserved_space(void);
+unsigned long sbi_heap_reserved_space_from(struct sbi_heap_control *hpctrl);
+
+static inline unsigned long sbi_heap_reserved_space(void)
+{
+ return sbi_heap_reserved_space_from(&global_hpctrl);
+}
/** Initialize heap area */
int sbi_heap_init(struct sbi_scratch *scratch);
+int sbi_heap_init_new(struct sbi_heap_control *hpctrl, unsigned long base,
+ unsigned long size);
+int sbi_heap_alloc_new(struct sbi_heap_control **hpctrl);
#endif