1
/******************************************************************************
2
* include/xen/grant_table.h
4
* Mechanism for granting foreign access to page frames, and receiving
5
* page-ownership transfers.
7
* Copyright (c) 2004-2005 K A Fraser
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.
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.
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
24
#ifndef __XEN_GRANT_TABLE_H__
25
#define __XEN_GRANT_TABLE_H__
27
#include <xen/config.h>
28
#include <public/grant_table.h>
29
#include <asm/grant_table.h>
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. */
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
42
unsigned length:16; /* For sub-page grants, the length of the
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)
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
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;
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'.
76
struct grant_mapping {
77
u32 ref; /* grant ref */
78
u16 flags; /* 0-4: GNTMAP_* ; 5-15: unused */
79
domid_t domid; /* granting domain */
82
/* Fairly arbitrary. [POLICY] */
83
#define MAPTRACK_MAX_ENTRIES 16384
85
/* Per-domain grant information. */
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). */
92
struct grant_entry_v1 **shared_v1;
93
union grant_entry_v2 **shared_v2;
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. */
107
/* The defined versions are 1 and 2. Set to 0 if we don't know
108
what version to use yet. */
112
/* Create/destroy per-domain grant table context. */
113
int grant_table_create(
115
void grant_table_destroy(
118
/* Domain death release of granted mappings of other domains' memory. */
120
gnttab_release_mappings(
123
/* Increase the size of a domain's grant table.
124
* Caller must hold d's grant table lock.
127
gnttab_grow_table(struct domain *d, unsigned int req_nr_frames);
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)
132
return gt->nr_grant_frames;
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)
138
return gt->nr_status_frames;
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)
146
return (grant_frames * GRANT_PER_PAGE + GRANT_STATUS_PER_PAGE - 1) /
147
GRANT_STATUS_PER_PAGE;
150
static inline unsigned int
151
num_act_frames_from_sha_frames(const unsigned int num)
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;
163
static inline unsigned int
164
nr_active_grant_frames(struct grant_table *gt)
166
return num_act_frames_from_sha_frames(nr_grant_frames(gt));
169
#endif /* __XEN_GRANT_TABLE_H__ */