1/* 2 * Copyright 2018, 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#pragma once 13 14#include <sel4/types.h> 15#include <assert.h> 16#include <autoconf.h> 17#include <sel4vka/gen_config.h> 18#include <utils/util.h> 19 20#define seL4_PageDirBits seL4_PageTableBits 21 22enum _riscv_kobject_type { 23 KOBJECT_PAGE_DIRECTORY, 24 KOBJECT_PAGE_TABLE, 25 KOBJECT_FRAME, 26 KOBJECT_ARCH_NUM_TYPES, 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 arch_kobject_get_size(kobject_t type, seL4_Word objectSize) 35{ 36 switch (type) { 37 case KOBJECT_FRAME: 38 switch (objectSize) { 39 case seL4_PageBits: 40 case seL4_LargePageBits: 41 return objectSize; 42 } 43 /* If frame size was unknown fall through to default case as it 44 * might be a mode specific frame size */ 45 default: 46 ZF_LOGE("Unknown object type"); 47 return 0; 48 } 49} 50 51 52static inline seL4_Word arch_kobject_get_type(int type, seL4_Word objectSize) 53{ 54 switch (type) { 55 case KOBJECT_PAGE_DIRECTORY: 56 case KOBJECT_PAGE_TABLE: 57 return seL4_RISCV_PageTableObject; 58 case KOBJECT_FRAME: 59 switch (objectSize) { 60 case seL4_PageBits: 61 return seL4_RISCV_4K_Page; 62 case seL4_LargePageBits: 63 return seL4_RISCV_Mega_Page; 64#if CONFIG_PT_LEVELS > 2 65 case seL4_HugePageBits: 66 return seL4_RISCV_Giga_Page; 67#endif 68#if CONFIG_PT_LEVELS > 3 69 case seL4_TeraPageBits: 70 return seL4_RISCV_Tera_Page; 71#endif 72 default: 73 ZF_LOGE("Unknown frame size %zu", (size_t) objectSize); 74 return -1; 75 } 76 default: 77 ZF_LOGE("Unknown object type %d", type); 78 return -1; 79 } 80} 81 82 83