1/*
2 * Copyright 2016, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(D61_BSD)
11 */
12
13#ifndef _REFOS_UTIL_CSPACE_H_
14#define _REFOS_UTIL_CSPACE_H_
15
16/*! @file
17    @brief RefOS client cspace allocator.
18
19    Simple RefOS cspace allocator, used to manage RefOS client cslots. We avoid using the vka
20    interface here as most of it would not be relevant; we are not allocating kernel objects, just
21    managing cslots. Uses a simple free-list allocator.
22*/
23
24
25#include <refos/refos.h>
26
27/*! @brief Initialise the cspace allocator. Uses malloc() heap memory.
28    @param start The start of the cslot range to allocate from.
29    @param end The end of the cslot range to allocate from.
30*/
31void csalloc_init(seL4_CPtr start, seL4_CPtr end);
32
33/*! @brief Initialise the cspace allocator, using a static buffer.
34
35    Like csalloc_init(), but uses a static buffer instead of malloc(). This is used for RefOS user-
36    land processes which use a dynamic heap which itself needs a cspace allocator. Thus, we use a
37    static cspace allocator buffer in order to avoid this circular dependency. RefOS system proceses
38    use a static heap / mmap region and thus do not require static cspace allocator.
39
40    @param start The start of the cslot range to allocate from.
41    @param end The end of the cslot range to allocate from.
42    @param buffer The static buffer to use. Must be at least ( sizeof(seL4_CPtr) * (start - end) )
43                  bytes large. (No ownership)
44    @param bufferSz The size of the static buffer.
45*/
46void csalloc_init_static(seL4_CPtr start, seL4_CPtr end, char* buffer, uint32_t bufferSz);
47
48/*! @brief De-initialise the cspace allocator. If the allocator uses a static buffer, it would NOT
49           be released. */
50void csalloc_deinit(void);
51
52/*! @brief Allocate a cslot.
53    @return CPtr to the allocated cslot. (Ownership given)
54*/
55seL4_CPtr csalloc(void);
56
57/*! @brief Free an allocated cslot. Does NOT actually delete or revoke the cap, so do not do this
58           if there is still a capability at the given cslot. Use csfree_delete() in that case.
59    @param c The allocate cslot to free.
60*/
61void csfree(seL4_CPtr c);
62
63/*! @brief Free an allocated cslot, and delete the capability in it. Does NOT revoke the capability.
64    @param c The allocate cslot to delete and free.
65*/
66void csfree_delete(seL4_CPtr c);
67
68#endif /* _REFOS_UTIL_CSPACE_H_ */
69