~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to xen/include/xen/grant_table.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * include/xen/grant_table.h
 
3
 * 
 
4
 * Mechanism for granting foreign access to page frames, and receiving
 
5
 * page-ownership transfers.
 
6
 * 
 
7
 * Copyright (c) 2004-2005 K A Fraser
 
8
 * 
 
9
 * This program is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU General Public License as published by
 
11
 * the Free Software Foundation; either version 2 of the License, or
 
12
 * (at your option) any later version.
 
13
 * 
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 * 
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software
 
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
 */
 
23
 
 
24
#ifndef __XEN_GRANT_TABLE_H__
 
25
#define __XEN_GRANT_TABLE_H__
 
26
 
 
27
#include <xen/config.h>
 
28
#include <public/grant_table.h>
 
29
#include <asm/grant_table.h>
 
30
 
 
31
/* Active grant entry - used for shadowing GTF_permit_access grants. */
 
32
struct active_grant_entry {
 
33
    u32           pin;    /* Reference count information.             */
 
34
    domid_t       domid;  /* Domain being granted access.             */
 
35
    domid_t       trans_dom;
 
36
    uint32_t      trans_gref;
 
37
    unsigned long frame;  /* Frame being granted.                     */
 
38
    unsigned long gfn;    /* Guest's idea of the frame being granted. */
 
39
    unsigned      is_sub_page:1; /* True if this is a sub-page grant. */
 
40
    unsigned      start:15; /* For sub-page grants, the start offset
 
41
                               in the page.                           */
 
42
    unsigned      length:16; /* For sub-page grants, the length of the
 
43
                                grant.                                */
 
44
};
 
45
 
 
46
 /* Count of writable host-CPU mappings. */
 
47
#define GNTPIN_hstw_shift    (0)
 
48
#define GNTPIN_hstw_inc      (1 << GNTPIN_hstw_shift)
 
49
#define GNTPIN_hstw_mask     (0xFFU << GNTPIN_hstw_shift)
 
50
 /* Count of read-only host-CPU mappings. */
 
51
#define GNTPIN_hstr_shift    (8)
 
52
#define GNTPIN_hstr_inc      (1 << GNTPIN_hstr_shift)
 
53
#define GNTPIN_hstr_mask     (0xFFU << GNTPIN_hstr_shift)
 
54
 /* Count of writable device-bus mappings. */
 
55
#define GNTPIN_devw_shift    (16)
 
56
#define GNTPIN_devw_inc      (1 << GNTPIN_devw_shift)
 
57
#define GNTPIN_devw_mask     (0xFFU << GNTPIN_devw_shift)
 
58
 /* Count of read-only device-bus mappings. */
 
59
#define GNTPIN_devr_shift    (24)
 
60
#define GNTPIN_devr_inc      (1 << GNTPIN_devr_shift)
 
61
#define GNTPIN_devr_mask     (0xFFU << GNTPIN_devr_shift)
 
62
 
 
63
#ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */
 
64
/* Default maximum size of a grant table. [POLICY] */
 
65
#define DEFAULT_MAX_NR_GRANT_FRAMES   32
 
66
#endif
 
67
#ifndef max_nr_grant_frames /* to allow arch to override */
 
68
/* The maximum size of a grant table. */
 
69
extern unsigned int max_nr_grant_frames;
 
70
#endif
 
71
 
 
72
/*
 
73
 * Tracks a mapping of another domain's grant reference. Each domain has a
 
74
 * table of these, indexes into which are returned as a 'mapping handle'.
 
75
 */
 
76
struct grant_mapping {
 
77
    u32      ref;           /* grant ref */
 
78
    u16      flags;         /* 0-4: GNTMAP_* ; 5-15: unused */
 
79
    domid_t  domid;         /* granting domain */
 
80
};
 
81
 
 
82
/* Fairly arbitrary. [POLICY] */
 
83
#define MAPTRACK_MAX_ENTRIES 16384
 
84
 
 
85
/* Per-domain grant information. */
 
86
struct grant_table {
 
87
    /* Table size. Number of frames shared with guest */
 
88
    unsigned int          nr_grant_frames;
 
89
    /* Shared grant table (see include/public/grant_table.h). */
 
90
    union {
 
91
        void **shared_raw;
 
92
        struct grant_entry_v1 **shared_v1;
 
93
        union grant_entry_v2 **shared_v2;
 
94
    };
 
95
    /* Number of grant status frames shared with guest (for version 2) */
 
96
    unsigned int          nr_status_frames;
 
97
    /* State grant table (see include/public/grant_table.h). */
 
98
    grant_status_t       **status;
 
99
    /* Active grant table. */
 
100
    struct active_grant_entry **active;
 
101
    /* Mapping tracking table. */
 
102
    struct grant_mapping **maptrack;
 
103
    unsigned int          maptrack_head;
 
104
    unsigned int          maptrack_limit;
 
105
    /* Lock protecting updates to active and shared grant tables. */
 
106
    spinlock_t            lock;
 
107
    /* The defined versions are 1 and 2.  Set to 0 if we don't know
 
108
       what version to use yet. */
 
109
    unsigned              gt_version;
 
110
};
 
111
 
 
112
/* Create/destroy per-domain grant table context. */
 
113
int grant_table_create(
 
114
    struct domain *d);
 
115
void grant_table_destroy(
 
116
    struct domain *d);
 
117
 
 
118
/* Domain death release of granted mappings of other domains' memory. */
 
119
void
 
120
gnttab_release_mappings(
 
121
    struct domain *d);
 
122
 
 
123
/* Increase the size of a domain's grant table.
 
124
 * Caller must hold d's grant table lock.
 
125
 */
 
126
int
 
127
gnttab_grow_table(struct domain *d, unsigned int req_nr_frames);
 
128
 
 
129
/* Number of grant table frames. Caller must hold d's grant table lock. */
 
130
static inline unsigned int nr_grant_frames(struct grant_table *gt)
 
131
{
 
132
    return gt->nr_grant_frames;
 
133
}
 
134
 
 
135
/* Number of status grant table frames. Caller must hold d's gr. table lock.*/
 
136
static inline unsigned int nr_status_frames(struct grant_table *gt)
 
137
{
 
138
    return gt->nr_status_frames;
 
139
}
 
140
 
 
141
#define GRANT_STATUS_PER_PAGE (PAGE_SIZE / sizeof(grant_status_t))
 
142
#define GRANT_PER_PAGE (PAGE_SIZE / sizeof(grant_entry_v2_t))
 
143
/* Number of grant table status entries. Caller must hold d's gr. table lock.*/
 
144
static inline unsigned int grant_to_status_frames(int grant_frames)
 
145
{
 
146
    return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE - 1) /
 
147
        GRANT_STATUS_PER_PAGE;
 
148
}
 
149
 
 
150
static inline unsigned int
 
151
num_act_frames_from_sha_frames(const unsigned int num)
 
152
{
 
153
    /* How many frames are needed for the active grant table,
 
154
     * given the size of the shared grant table? */
 
155
    unsigned act_per_page = PAGE_SIZE / sizeof(struct active_grant_entry);
 
156
    unsigned sha_per_page = PAGE_SIZE / sizeof(grant_entry_v1_t);
 
157
    unsigned num_sha_entries = num * sha_per_page;
 
158
    unsigned num_act_frames =
 
159
        (num_sha_entries + (act_per_page-1)) / act_per_page;
 
160
    return num_act_frames;
 
161
}
 
162
 
 
163
static inline unsigned int
 
164
nr_active_grant_frames(struct grant_table *gt)
 
165
{
 
166
    return num_act_frames_from_sha_frames(nr_grant_frames(gt));
 
167
}
 
168
 
 
169
#endif /* __XEN_GRANT_TABLE_H__ */