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 <vka/vka.h> 16#include <vka/kobject_t.h> 17#include <utils/util.h> 18 19static inline int vka_alloc_page_global_directory(vka_t *vka, vka_object_t *result) 20{ 21 return vka_alloc_object(vka, kobject_get_type(KOBJECT_PAGE_GLOBAL_DIRECTORY, 0), seL4_PGDBits, result); 22} 23 24static inline int vka_alloc_page_upper_directory(vka_t *vka, vka_object_t *result) 25{ 26 return vka_alloc_object(vka, kobject_get_type(KOBJECT_PAGE_UPPER_DIRECTORY, 0), seL4_PUDBits, result); 27} 28 29LEAKY(page_global_directory) 30LEAKY(page_upper_directory) 31 32static inline int vka_alloc_vspace_root(vka_t *vka, vka_object_t *result) 33{ 34 if (config_set(CONFIG_ARM_HYPERVISOR_SUPPORT) && config_set(CONFIG_ARM_PA_SIZE_BITS_40)) { 35 return vka_alloc_page_upper_directory(vka, result); 36 } else { 37 return vka_alloc_page_global_directory(vka, result); 38 } 39} 40 41/* 42 * Get the size (in bits) of the untyped memory required to create an object of 43 * the given size. 44 */ 45static inline unsigned long 46vka_arm_mode_get_object_size(seL4_Word objectType) 47{ 48 switch (objectType) { 49 case seL4_ARM_HugePageObject: 50 return seL4_HugePageBits; 51 case seL4_ARM_PageGlobalDirectoryObject: 52 return seL4_PGDBits; 53 case seL4_ARM_PageUpperDirectoryObject: 54 return seL4_PUDBits; 55 default: 56 /* Unknown object type. */ 57 ZF_LOGE("Unknown object type"); 58 return -1; 59 } 60} 61 62