blob: dd313d10635c2168a89661e1effc7a3ac424d1c8 [file] [log] [blame]
TrustworthySystems1621d7b2014-07-22 14:12:00 +10001/*
Gerwin Klein600fe152021-02-10 19:19:17 +11002 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
TrustworthySystems1621d7b2014-07-22 14:12:00 +10003 *
Gerwin Klein600fe152021-02-10 19:19:17 +11004 * SPDX-License-Identifier: BSD-2-Clause
TrustworthySystems1621d7b2014-07-22 14:12:00 +10005 */
6
Anna Lyons135c6512017-09-28 12:16:03 +10007#pragma once
TrustworthySystems1621d7b2014-07-22 14:12:00 +10008
9#include <autoconf.h>
Adrian Danis40767902015-11-19 09:10:17 +110010#include <stdlib.h>
TrustworthySystems1621d7b2014-07-22 14:12:00 +100011#include <sel4/types.h>
12#include <allocman/cspace/cspace.h>
13
14struct cspace_single_level_config {
15 /* A cptr to the cnode that we are managing slots in */
16 seL4_CPtr cnode;
17 /* Size in bits of the cnode */
Adrian Danis14ab04c2015-11-13 16:35:23 +110018 size_t cnode_size_bits;
TrustworthySystems1621d7b2014-07-22 14:12:00 +100019 /* Guard depth added to this cspace. */
Adrian Danis14ab04c2015-11-13 16:35:23 +110020 size_t cnode_guard_bits;
TrustworthySystems1621d7b2014-07-22 14:12:00 +100021 /* First valid slot (as an index) */
Adrian Danis14ab04c2015-11-13 16:35:23 +110022 size_t first_slot;
TrustworthySystems1621d7b2014-07-22 14:12:00 +100023 /* Last valid slot + 1 (as an index) */
Adrian Danis14ab04c2015-11-13 16:35:23 +110024 size_t end_slot;
TrustworthySystems1621d7b2014-07-22 14:12:00 +100025};
26
27typedef struct cspace_single_level {
28 struct cspace_single_level_config config;
Adrian Danis14ab04c2015-11-13 16:35:23 +110029 size_t *bitmap;
30 size_t bitmap_length;
31 size_t last_entry;
TrustworthySystems1621d7b2014-07-22 14:12:00 +100032} cspace_single_level_t;
33
34int cspace_single_level_create(struct allocman *alloc, cspace_single_level_t *cspace, struct cspace_single_level_config config);
35
36/* Frees any allocated resources back to the given allocation manager */
37void cspace_single_level_destroy(struct allocman *alloc, cspace_single_level_t *cspace);
38
39int _cspace_single_level_alloc(struct allocman *alloc, void *_cspace, cspacepath_t *slot);
40int _cspace_single_level_alloc_at(struct allocman *alloc, void *_cspace, seL4_CPtr slot);
Adrian Danisbd03ee52015-04-21 15:17:01 +100041void _cspace_single_level_free(struct allocman *alloc, void *_cspace, const cspacepath_t *slot);
TrustworthySystems1621d7b2014-07-22 14:12:00 +100042
43static inline cspacepath_t _cspace_single_level_make_path(void *_cspace, seL4_CPtr slot)
44{
45 cspace_single_level_t *cspace = (cspace_single_level_t*) _cspace;
46 return (cspacepath_t) {
47 .root = cspace->config.cnode,
48 .capPtr = slot,
49 .capDepth = cspace->config.cnode_size_bits + cspace->config.cnode_guard_bits,
50 .dest = 0,
51 .destDepth = 0,
52 .offset = slot,
53 .window = 1
54 };
55}
56
57static inline cspace_interface_t cspace_single_level_make_interface(cspace_single_level_t *cspace) {
58 return (cspace_interface_t) {
59 .alloc = _cspace_single_level_alloc,
60 .free = _cspace_single_level_free,
61 .make_path = _cspace_single_level_make_path,
62 /* We do not want to handle recursion, as it shouldn't happen */
63 .properties = ALLOCMAN_DEFAULT_PROPERTIES,
64 .cspace = cspace
65 };
66}
67