1/**
2 * \file
3 * \brief Vregion definitions
4 */
5
6/*
7 * Copyright (c) 2009, 2010, ETH Zurich.
8 * Copyright (c) 2014 HP Labs.
9 * All rights reserved.
10 *
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, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
14 */
15
16#ifndef LIBBARRELFISH_VREGION_H
17#define LIBBARRELFISH_VREGION_H
18
19#include <barrelfish_kpi/types.h>
20#include <sys/cdefs.h>
21
22__BEGIN_DECLS
23
24#define VREGION_FLAGS_NONE     0x00 // No access
25#define VREGION_FLAGS_READ     0x01 // Reading allowed
26#define VREGION_FLAGS_WRITE    0x02 // Writing allowed
27#define VREGION_FLAGS_EXECUTE  0x04 // Execute allowed
28#define VREGION_FLAGS_NOCACHE  0x08 // Caching disabled
29#define VREGION_FLAGS_MPB      0x10 // Message passing buffer
30#define VREGION_FLAGS_GUARD    0x20 // Guard page
31// XXX: figure out how to do this arch-independent(?) -SG, 2014-06-16
32#define VREGION_FLAGS_LARGE    0x40 // Map large pages, if possible
33#define VREGION_FLAGS_HUGE     0x80 // Map huge pages, if possible
34#define VREGION_FLAGS_WRITE_COMBINING   0x100 // Write-combining caching
35#define VREGION_FLAGS_MASK     0x1ff // Mask of all individual VREGION_FLAGS
36#define VREGION_FLAGS_VTD_SNOOP  0x800 // Snooping (for pages) allowed by VT-d
37
38#define VREGION_FLAGS_READ_WRITE \
39    (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_VTD_SNOOP)
40#define VREGION_FLAGS_READ_EXECUTE \
41    (VREGION_FLAGS_READ | VREGION_FLAGS_EXECUTE | VREGION_FLAGS_VTD_SNOOP)
42#define VREGION_FLAGS_READ_WRITE_NOCACHE \
43    (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_NOCACHE | VREGION_FLAGS_VTD_SNOOP)
44#define VREGION_FLAGS_READ_WRITE_MPB \
45    (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_MPB | VREGION_FLAGS_VTD_SNOOP)
46
47struct vspace;
48struct memobj;
49
50struct vregion {
51    struct vspace *vspace;   ///< A vregion is always associated with one vspace
52    struct memobj *memobj;   ///< A vregion is always associated with one memobj
53    genvaddr_t offset;       ///< Offset into the memobj
54    genvaddr_t size;         ///< Size of the vregion
55    genvaddr_t base;         ///< Base address of the vregion
56    vregion_flags_t flags;   ///< Flags
57    struct vregion *next;    ///< Pointer for the list in vspace
58};
59
60/**
61 * \brief Get the vspace associated with the vregion
62 *
63 * \param vregion  The vregion
64 */
65static inline struct vspace *vregion_get_vspace(struct vregion *vregion)
66{
67    return vregion->vspace;
68}
69
70/**
71 * \brief Get the memory object associated with the region
72 *
73 * \param vregion  The region
74 */
75static inline struct memobj* vregion_get_memobj(struct vregion *vregion)
76{
77    return vregion->memobj;
78}
79
80/**
81 * \brief Get the base address of the region
82 *
83 * \param piont  The region
84 */
85static inline genvaddr_t vregion_get_base_addr(struct vregion *vregion)
86{
87    return vregion->base;
88}
89
90/**
91 * \brief Get the offset into the memory object the vregion has
92 *
93 * \param vregion  The region
94 */
95static inline size_t vregion_get_offset(struct vregion *vregion)
96{
97    return vregion->offset;
98}
99
100/**
101 * \brief Get the size of the region
102 *
103 * \param vregion  The region
104 */
105static inline size_t vregion_get_size(struct vregion *vregion)
106{
107    return vregion->size;
108}
109
110/**
111 * \brief Get the flags/attributes of the region
112 *
113 * \param vregion  The region
114 */
115static inline vregion_flags_t vregion_get_flags(struct vregion *vregion)
116{
117    return vregion->flags;
118}
119
120errval_t vregion_map(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
121                     size_t offset, size_t size, vregion_flags_t flags);
122errval_t vregion_map_aligned(struct vregion* point, struct vspace* vspace,
123                             struct memobj* memobj, size_t offset, size_t size,
124                             vregion_flags_t flags, size_t alignment);
125errval_t vregion_map_fixed(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
126                           size_t offset, size_t size, genvaddr_t addr,
127                           vregion_flags_t flags);
128errval_t vregion_destroy(struct vregion* region);
129errval_t vregion_pagefault_handler(struct vregion* region, genvaddr_t addr,
130                                   vm_fault_type_t type);
131
132__END_DECLS
133
134#endif // LIBBARRELFISH_VREGION_H
135