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, Universitaetstr. 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_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
35#define VREGION_FLAGS_VTD_SNOOP  0x800 // Snooping (for pages) allowed by VT-d
36
37#define VREGION_FLAGS_READ_WRITE \
38    (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_VTD_SNOOP)
39#define VREGION_FLAGS_READ_EXECUTE \
40    (VREGION_FLAGS_READ | VREGION_FLAGS_EXECUTE | VREGION_FLAGS_VTD_SNOOP)
41#define VREGION_FLAGS_READ_WRITE_NOCACHE \
42    (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_NOCACHE | VREGION_FLAGS_VTD_SNOOP)
43#define VREGION_FLAGS_READ_WRITE_MPB \
44    (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE | VREGION_FLAGS_MPB | VREGION_FLAGS_VTD_SNOOP)
45
46struct vspace;
47struct memobj;
48
49struct vregion {
50    struct vspace *vspace;   ///< A vregion is always associated with one vspace
51    struct memobj *memobj;   ///< A vregion is always associated with one memobj
52    genvaddr_t offset;       ///< Offset into the memobj
53    genvaddr_t size;         ///< Size of the vregion
54    genvaddr_t base;         ///< Base address of the vregion
55    vregion_flags_t flags;   ///< Flags
56    struct vregion *next;    ///< Pointer for the list in vspace
57};
58
59/**
60 * \brief Get the vspace associated with the vregion
61 *
62 * \param vregion  The vregion
63 */
64static inline struct vspace *vregion_get_vspace(struct vregion *vregion)
65{
66    return vregion->vspace;
67}
68
69/**
70 * \brief Get the memory object associated with the region
71 *
72 * \param vregion  The region
73 */
74static inline struct memobj* vregion_get_memobj(struct vregion *vregion)
75{
76    return vregion->memobj;
77}
78
79/**
80 * \brief Get the base address of the region
81 *
82 * \param piont  The region
83 */
84static inline genvaddr_t vregion_get_base_addr(struct vregion *vregion)
85{
86    return vregion->base;
87}
88
89/**
90 * \brief Get the offset into the memory object the vregion has
91 *
92 * \param vregion  The region
93 */
94static inline size_t vregion_get_offset(struct vregion *vregion)
95{
96    return vregion->offset;
97}
98
99/**
100 * \brief Get the size of the region
101 *
102 * \param vregion  The region
103 */
104static inline size_t vregion_get_size(struct vregion *vregion)
105{
106    return vregion->size;
107}
108
109/**
110 * \brief Get the flags/attributes of the region
111 *
112 * \param vregion  The region
113 */
114static inline vregion_flags_t vregion_get_flags(struct vregion *vregion)
115{
116    return vregion->flags;
117}
118
119errval_t vregion_map(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
120                     size_t offset, size_t size, vregion_flags_t flags);
121errval_t vregion_map_aligned(struct vregion* point, struct vspace* vspace,
122                             struct memobj* memobj, size_t offset, size_t size,
123                             vregion_flags_t flags, size_t alignment);
124errval_t vregion_map_fixed(struct vregion* point, struct vspace* vspace, struct memobj* memobj,
125                           size_t offset, size_t size, genvaddr_t addr,
126                           vregion_flags_t flags);
127errval_t vregion_destroy(struct vregion* region);
128errval_t vregion_pagefault_handler(struct vregion* region, genvaddr_t addr,
129                                   vm_fault_type_t type);
130
131__END_DECLS
132
133#endif // LIBBARRELFISH_VREGION_H
134