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 <stdbool.h> 16#include <sel4/types.h> 17#include <allocman/properties.h> 18#include <allocman/cspace/cspace.h> 19#include <vka/vka.h> 20#include <vka/object.h> 21 22/* 23 * Marks an untyped as being usable for creating arbitrary kernel objects. Objects 24 * created from such untypeds have no restrictions and can be used for anything 25 */ 26#define ALLOCMAN_UT_KERNEL 0 27/* 28 * Marks an untyped as being a device region. Device regions will never be used 29 * for an allocation unless explicitly requested by physical address 30 */ 31#define ALLOCMAN_UT_DEV 1 32/* 33 * Marks an untyped as being from a device region, but also usable RAM. Objects can 34 * be created from these untypeds if the 'canBeDev' parameter in 'alloc' is set 35 * to true. An object created from one of these untypeds may have restrictions 36 * in what it can be used for and may not be zeroed, as it cannot be written by 37 * the kernel. 38 */ 39#define ALLOCMAN_UT_DEV_MEM 2 40 41/* Use the value of 1 internally to indicate the absence of a physical address. 42 * This is chosen because the zero frame might actually be valid physical memory, 43 * and 1 is not a valid alignment of any seL4 object, so it should never be 44 * a valid physical address you can request */ 45#define ALLOCMAN_NO_PADDR 1 46 47/* Convert from size of an untyped object in bytes, to the size as acceptable to a call to 48 * untyped retype */ 49static inline size_t get_sel4_object_size(seL4_Word type, size_t size_bits) { 50 if (type == seL4_CapTableObject) { 51 return size_bits - seL4_SlotBits; 52 } else { 53 return vka_get_object_size(type, size_bits); 54 } 55} 56 57struct allocman; 58 59typedef struct utspace_interface { 60 /* size_bits is always the size in memory of allocated object. This differs to the untypedretype 61 semantics of size_bits when cnodes are involved */ 62 seL4_Word (*alloc)(struct allocman *alloc, void *utspace, size_t size_bits, seL4_Word object_type, const cspacepath_t *slot, uintptr_t paddr, bool canBeDevice, int *error); 63 void (*free)(struct allocman *alloc, void *utspace, seL4_Word cookie, size_t size_bits); 64 int (*add_uts)(struct allocman *alloc, void *utspace, size_t num, const cspacepath_t *uts, size_t *size_bits, uintptr_t *paddr, int utType); 65 uintptr_t (*paddr)(void *utspace, seL4_Word cookie, size_t size_bits); 66 struct allocman_properties properties; 67 void *utspace; 68}utspace_interface_t; 69 70