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 <sel4/types.h>
16#include <assert.h>
17#include <autoconf.h>
18#include <sel4vka/gen_config.h>
19#include <utils/util.h>
20
21enum _arm_mode_kobject_type {
22    KOBJECT_FRAME = 0,
23    KOBJECT_PAGE_GLOBAL_DIRECTORY,
24    KOBJECT_PAGE_UPPER_DIRECTORY,
25    KOBJECT_MODE_NUM_TYPES,
26};
27
28typedef int kobject_t;
29
30/*
31 * Get the size (in bits) of the untyped memory required to
32 * create an object of the given size
33 */
34static inline seL4_Word arm_mode_kobject_get_size(kobject_t type, seL4_Word objectSize)
35{
36    switch (type) {
37    /* ARM-specific frames. */
38    case KOBJECT_FRAME:
39        switch (objectSize) {
40        case seL4_HugePageBits:
41            return objectSize;
42        default:
43            return 0;
44        }
45    case KOBJECT_PAGE_UPPER_DIRECTORY:
46        return seL4_PUDBits;
47    default:
48        /* Unknown object type. */
49        ZF_LOGE("Unknown object type");
50        return 0;
51    }
52}
53
54static inline seL4_Word arm_mode_kobject_get_type(kobject_t type, seL4_Word objectSize)
55{
56    switch (type) {
57    case KOBJECT_FRAME:
58        switch (objectSize) {
59        case seL4_HugePageBits:
60            return seL4_ARM_HugePageObject;
61        default:
62            return -1;
63        }
64    case KOBJECT_PAGE_GLOBAL_DIRECTORY:
65        return seL4_ARM_PageGlobalDirectoryObject;
66    case KOBJECT_PAGE_UPPER_DIRECTORY:
67        return seL4_ARM_PageUpperDirectoryObject;
68    default:
69        /* Unknown object type. */
70        ZF_LOGE("Unknown object type %d", type);
71        return -1;
72    }
73}
74
75