1/*
2 * Copyright 2017, 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(DATA61_BSD)
11 */
12
13#pragma once
14
15#include <autoconf.h>
16#include <stdlib.h>
17#include <sel4/types.h>
18#include <allocman/mspace/mspace.h>
19#include <allocman/mspace/k_r_malloc.h>
20
21/* Performs allocation from a pool of virtual memory */
22
23struct mspace_virtual_pool_config {
24    void *vstart;
25    size_t size;
26    seL4_CPtr pd;
27};
28
29typedef struct mspace_virtual_pool {
30    void *pool_ptr;
31    void *pool_top;
32    void *pool_limit;
33    seL4_CPtr pd;
34    mspace_k_r_malloc_t k_r_malloc;
35    struct allocman *morecore_alloc;
36} mspace_virtual_pool_t;
37
38void mspace_virtual_pool_create(mspace_virtual_pool_t *virtual_pool, struct mspace_virtual_pool_config config);
39
40void *_mspace_virtual_pool_alloc(struct allocman *alloc, void *_virtual_pool, size_t bytes, int *error);
41void _mspace_virtual_pool_free(struct allocman *alloc, void *_virtual_pool, void *ptr, size_t bytes);
42
43static inline struct mspace_interface mspace_virtual_pool_make_interface(mspace_virtual_pool_t *virtual_pool) {
44    return (struct mspace_interface){
45        .alloc = _mspace_virtual_pool_alloc,
46        .free = _mspace_virtual_pool_free,
47        .properties = ALLOCMAN_DEFAULT_PROPERTIES,
48        .mspace = virtual_pool
49    };
50}
51
52