3 * \brief Vregion definitions
7 * Copyright (c) 2009, 2010, ETH Zurich.
8 * Copyright (c) 2014 HP Labs.
11 * This file is distributed under the terms in the attached LICENSE file.
12 * If you do not find this file, copies can be found by writing to:
13 * ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
16 #ifndef LIBBARRELFISH_VREGION_H
17 #define LIBBARRELFISH_VREGION_H
19 #include <barrelfish_kpi/types.h>
20 #include <sys/cdefs.h>
24 #define VREGION_FLAGS_READ 0x01 // Reading allowed
25 #define VREGION_FLAGS_WRITE 0x02 // Writing allowed
26 #define VREGION_FLAGS_EXECUTE 0x04 // Execute allowed
27 #define VREGION_FLAGS_NOCACHE 0x08 // Caching disabled
28 #define VREGION_FLAGS_MPB 0x10 // Message passing buffer
29 #define VREGION_FLAGS_GUARD 0x20 // Guard page
30 // XXX: figure out how to do this arch-independent(?) -SG, 2014-06-16
31 #define VREGION_FLAGS_LARGE 0x40 // Map large pages, if possible
32 #define VREGION_FLAGS_HUGE 0x80 // Map huge pages, if possible
33 #define VREGION_FLAGS_MASK 0xff // Mask of all individual VREGION_FLAGS
35 #define VREGION_FLAGS_READ_WRITE \
36 (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE)
37 #define VREGION_FLAGS_READ_EXECUTE \
38 (VREGION_FLAGS_READ | VREGION_FLAGS_EXECUTE)
39 #define VREGION_FLAGS_READ_WRITE_NOCACHE \
40 (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_NOCACHE)
41 #define VREGION_FLAGS_READ_WRITE_MPB \
42 (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_MPB)
48 struct vspace *vspace; ///< A vregion is always associated with one vspace
49 struct memobj *memobj; ///< A vregion is always associated with one memobj
50 genvaddr_t offset; ///< Offset into the memobj
51 genvaddr_t size; ///< Size of the vregion
52 genvaddr_t base; ///< Base address of the vregion
53 vregion_flags_t flags; ///< Flags
54 struct vregion *next; ///< Pointer for the list in vspace
58 * \brief Get the vspace associated with the vregion
60 * \param vregion The vregion
62 static inline struct vspace *vregion_get_vspace(struct vregion *vregion)
64 return vregion->vspace;
68 * \brief Get the memory object associated with the region
70 * \param vregion The region
72 static inline struct memobj* vregion_get_memobj(struct vregion *vregion)
74 return vregion->memobj;
78 * \brief Get the base address of the region
80 * \param piont The region
82 static inline genvaddr_t vregion_get_base_addr(struct vregion *vregion)
88 * \brief Get the offset into the memory object the vregion has
90 * \param vregion The region
92 static inline size_t vregion_get_offset(struct vregion *vregion)
94 return vregion->offset;
98 * \brief Get the size of the region
100 * \param vregion The region
102 static inline size_t vregion_get_size(struct vregion *vregion)
104 return vregion->size;
108 * \brief Get the flags/attributes of the region
110 * \param vregion The region
112 static inline vregion_flags_t vregion_get_flags(struct vregion *vregion)
114 return vregion->flags;
117 errval_t vregion_map(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
118 size_t offset, size_t size, vregion_flags_t flags);
119 errval_t vregion_map_aligned(struct vregion* point, struct vspace* vspace,
120 struct memobj* memobj, size_t offset, size_t size,
121 vregion_flags_t flags, size_t alignment);
122 errval_t vregion_map_fixed(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
123 size_t offset, size_t size, genvaddr_t addr,
124 vregion_flags_t flags);
125 errval_t vregion_destroy(struct vregion* region);
126 errval_t vregion_pagefault_handler(struct vregion* region, genvaddr_t addr,
127 vm_fault_type_t type);
131 #endif // LIBBARRELFISH_VREGION_H