1/** 2 * \file 3 * \brief Vspace_Layout definitions 4 */ 5 6/* 7 * Copyright (c) 2010, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef LIBBARRELFISH_VSPACE_LAYOUT_H 16#define LIBBARRELFISH_VSPACE_LAYOUT_H 17 18#include <assert.h> 19#include <sys/cdefs.h> 20 21__BEGIN_DECLS 22 23struct vspace_layout; 24struct vspace_layout_funcs { 25 errval_t (*alloc)(struct vspace_layout *layout, genvaddr_t *addr); 26}; 27 28struct vspace_layout { 29 struct vspace_layout_funcs f; 30 lvaddr_t granularity; 31 genvaddr_t size; 32 genvaddr_t offset; 33}; 34 35 36/** 37 * \brief Get the granularity of minimum allocation 38 */ 39static inline lvaddr_t vspace_layout_get_granularity(struct vspace_layout *l) 40{ 41 return l->granularity; 42} 43 44/** 45 * \brief Get the size of the address space 46 */ 47static inline size_t vspace_layout_get_size(struct vspace_layout *l) 48{ 49 return l->size; 50} 51 52/** 53 * \brief Translate a lvaddr_t to genvaddr_t 54 */ 55static inline genvaddr_t vspace_layout_lvaddr_to_genvaddr(struct vspace_layout *l, 56 lvaddr_t lvaddr) 57{ 58 return ((genvaddr_t)lvaddr + l->offset); 59} 60 61/** 62 * \brief Translate a genvaddr_t to lvaddr_t 63 */ 64static inline lvaddr_t vspace_layout_genvaddr_to_lvaddr(struct vspace_layout *l, 65 genvaddr_t genvaddr) 66{ 67 assert(genvaddr >= l->offset && 68 genvaddr <= ((genvaddr_t)l->offset + l->size)); 69 return (lvaddr_t)(genvaddr - l->offset); 70} 71 72errval_t vspace_layout_init(struct vspace_layout *l); 73 74__END_DECLS 75 76#endif // LIBBARRELFISH_VSPACE_LAYOUT_H 77