TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 1 | /* |
Gerwin Klein | 600fe15 | 2021-02-10 19:19:17 +1100 | [diff] [blame] | 2 | * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230) |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 3 | * |
Gerwin Klein | 600fe15 | 2021-02-10 19:19:17 +1100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-2-Clause |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 5 | */ |
| 6 | |
Anna Lyons | 135c651 | 2017-09-28 12:16:03 +1000 | [diff] [blame] | 7 | #pragma once |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 8 | |
| 9 | #include <autoconf.h> |
Adrian Danis | 4076790 | 2015-11-19 09:10:17 +1100 | [diff] [blame] | 10 | #include <stdlib.h> |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 11 | #include <sel4/types.h> |
| 12 | #include <allocman/cspace/cspace.h> |
| 13 | |
| 14 | struct 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 Danis | 14ab04c | 2015-11-13 16:35:23 +1100 | [diff] [blame] | 18 | size_t cnode_size_bits; |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 19 | /* Guard depth added to this cspace. */ |
Adrian Danis | 14ab04c | 2015-11-13 16:35:23 +1100 | [diff] [blame] | 20 | size_t cnode_guard_bits; |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 21 | /* First valid slot (as an index) */ |
Adrian Danis | 14ab04c | 2015-11-13 16:35:23 +1100 | [diff] [blame] | 22 | size_t first_slot; |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 23 | /* Last valid slot + 1 (as an index) */ |
Adrian Danis | 14ab04c | 2015-11-13 16:35:23 +1100 | [diff] [blame] | 24 | size_t end_slot; |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | typedef struct cspace_single_level { |
| 28 | struct cspace_single_level_config config; |
Adrian Danis | 14ab04c | 2015-11-13 16:35:23 +1100 | [diff] [blame] | 29 | size_t *bitmap; |
| 30 | size_t bitmap_length; |
| 31 | size_t last_entry; |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 32 | } cspace_single_level_t; |
| 33 | |
| 34 | int 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 */ |
| 37 | void cspace_single_level_destroy(struct allocman *alloc, cspace_single_level_t *cspace); |
| 38 | |
| 39 | int _cspace_single_level_alloc(struct allocman *alloc, void *_cspace, cspacepath_t *slot); |
| 40 | int _cspace_single_level_alloc_at(struct allocman *alloc, void *_cspace, seL4_CPtr slot); |
Adrian Danis | bd03ee5 | 2015-04-21 15:17:01 +1000 | [diff] [blame] | 41 | void _cspace_single_level_free(struct allocman *alloc, void *_cspace, const cspacepath_t *slot); |
TrustworthySystems | 1621d7b | 2014-07-22 14:12:00 +1000 | [diff] [blame] | 42 | |
| 43 | static 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 | |
| 57 | static 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 | |