aboutsummaryrefslogtreecommitdiff
path: root/include/sbi/sbi_heap.h
blob: 16755ec9b56b505e9dbd162c24e5d4ecf5b40b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2023 Ventana Micro Systems Inc.
 *
 * Authors:
 *   Anup Patel<apatel@ventanamicro.com>
 */

#ifndef __SBI_HEAP_H__
#define __SBI_HEAP_H__

#include <sbi/sbi_types.h>

/* 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);

/** 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