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_WRITE_COMBINING 0x100 // Write-combining caching
34 #define VREGION_FLAGS_MASK 0x1ff // Mask of all individual VREGION_FLAGS
36 #define VREGION_FLAGS_READ_WRITE \
37 (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE)
38 #define VREGION_FLAGS_READ_EXECUTE \
39 (VREGION_FLAGS_READ | VREGION_FLAGS_EXECUTE)
40 #define VREGION_FLAGS_READ_WRITE_NOCACHE \
41 (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_NOCACHE)
42 #define VREGION_FLAGS_READ_WRITE_MPB \
43 (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_MPB)
49 struct vspace *vspace; ///< A vregion is always associated with one vspace
50 struct memobj *memobj; ///< A vregion is always associated with one memobj
51 genvaddr_t offset; ///< Offset into the memobj
52 genvaddr_t size; ///< Size of the vregion
53 genvaddr_t base; ///< Base address of the vregion
54 vregion_flags_t flags; ///< Flags
55 struct vregion *next; ///< Pointer for the list in vspace
59 * \brief Get the vspace associated with the vregion
61 * \param vregion The vregion
63 static inline struct vspace *vregion_get_vspace(struct vregion *vregion)
65 return vregion->vspace;
69 * \brief Get the memory object associated with the region
71 * \param vregion The region
73 static inline struct memobj* vregion_get_memobj(struct vregion *vregion)
75 return vregion->memobj;
79 * \brief Get the base address of the region
81 * \param piont The region
83 static inline genvaddr_t vregion_get_base_addr(struct vregion *vregion)
89 * \brief Get the offset into the memory object the vregion has
91 * \param vregion The region
93 static inline size_t vregion_get_offset(struct vregion *vregion)
95 return vregion->offset;
99 * \brief Get the size of the region
101 * \param vregion The region
103 static inline size_t vregion_get_size(struct vregion *vregion)
105 return vregion->size;
109 * \brief Get the flags/attributes of the region
111 * \param vregion The region
113 static inline vregion_flags_t vregion_get_flags(struct vregion *vregion)
115 return vregion->flags;
118 errval_t vregion_map(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
119 size_t offset, size_t size, vregion_flags_t flags);
120 errval_t vregion_map_aligned(struct vregion* point, struct vspace* vspace,
121 struct memobj* memobj, size_t offset, size_t size,
122 vregion_flags_t flags, size_t alignment);
123 errval_t vregion_map_fixed(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
124 size_t offset, size_t size, genvaddr_t addr,
125 vregion_flags_t flags);
126 errval_t vregion_destroy(struct vregion* region);
127 errval_t vregion_pagefault_handler(struct vregion* region, genvaddr_t addr,
128 vm_fault_type_t type);
132 #endif // LIBBARRELFISH_VREGION_H