1/**
2 * \file
3 * \brief Slot management for memory allocator
4 */
5
6/*
7 * Copyright (c) 2007, 2008, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef MM_SLOT_ALLOC_H
16#define MM_SLOT_ALLOC_H
17
18#include <sys/cdefs.h>
19#include <errors/errno.h>
20#include <barrelfish/caddr.h>
21
22__BEGIN_DECLS
23
24/// Generic interface to slot allocator function
25typedef errval_t (*slot_alloc_t)(void *inst, uint64_t nslots, struct capref *ret);
26typedef errval_t (*slot_refill_t)(void *inst);
27
28/// Implementations of above interface
29errval_t slot_alloc_prealloc(void *inst, uint64_t nslots, struct capref *ret);
30errval_t slot_alloc_basecn(void *inst, uint64_t nslots, struct capref *ret);
31errval_t slot_alloc_dynamic(void *inst, uint64_t nslots, struct capref *ret);
32errval_t slot_refill_dynamic(void *inst);
33
34struct mm; // forward declaration
35
36/// Instance data for pre-allocating slot allocator for 2 level cspace
37struct slot_prealloc {
38    uint8_t maxslotbits;            ///< Maximum number of slots per allocation
39
40    /// Metadata for next place from which to allocate slots
41    struct {
42        struct capref cap;        ///< Next cap to allocate
43        uint64_t free;              ///< Number of free slots including cap
44    } meta[2] __attribute__ ((aligned(4)));
45
46    /// Which entry in meta array we are currently allocating from
47    uint8_t current;
48
49    /// RAM allocator to allocate space for new cnodes
50    struct mm *mm;
51};
52
53/// Initialiser for the pre-allocating implementation
54errval_t slot_prealloc_init(struct slot_prealloc *slot_alloc,
55                            uint8_t maxslotbits, struct capref initial_cnode,
56                            uint64_t initial_space, struct mm *ram_mm);
57
58/// Refill function for the pre-allocating implementation
59errval_t slot_prealloc_refill(struct slot_prealloc *inst);
60
61/// Instance data for simple base-cnode allocator
62struct slot_alloc_basecn {
63    struct capref cap;          ///< Next cap to allocate
64    uint64_t free;              ///< Number of free slots including cap
65};
66
67/// Initialiser for the single-cnode implementation
68errval_t slot_alloc_basecn_init(struct slot_alloc_basecn *slot_alloc);
69
70__END_DECLS
71
72#endif // MM_SLOT_ALLOC_H
73