Xen Test Framework
include
xen
grant_table.h
Go to the documentation of this file.
1
/*
2
* Xen public Grant Table hypercall interface
3
*/
4
5
#ifndef XEN_PUBLIC_GRANT_TABLE_H
6
#define XEN_PUBLIC_GRANT_TABLE_H
7
8
#include "
xen.h
"
9
10
#define GNTST_okay (0)
/* Normal return. */
11
#define GNTST_general_error (-1)
/* General undefined error. */
12
#define GNTST_bad_domain (-2)
/* Unrecognsed domain id. */
13
#define GNTST_bad_gntref (-3)
/* Unrecognised or inappropriate gntref. */
14
#define GNTST_bad_handle (-4)
/* Unrecognised or inappropriate handle. */
15
#define GNTST_bad_virt_addr (-5)
/* Inappropriate virtual address to map. */
16
#define GNTST_bad_dev_addr (-6)
/* Inappropriate device address to unmap.*/
17
#define GNTST_no_device_space (-7)
/* Out of space in I/O MMU. */
18
#define GNTST_permission_denied (-8)
/* Not enough privilege for operation. */
19
#define GNTST_bad_page (-9)
/* Specified page was invalid for op. */
20
#define GNTST_bad_copy_arg (-10)
/* copy arguments cross page boundary. */
21
#define GNTST_address_too_big (-11)
/* transfer page address too large. */
22
#define GNTST_eagain (-12)
/* Operation not done; try again. */
23
24
#define GNTTABOP_error_msgs { \
25
"okay"
, \
26
"undefined error", \
27
"unrecognised domain id", \
28
"invalid grant reference", \
29
"invalid mapping handle", \
30
"invalid virtual address", \
31
"invalid device address", \
32
"no spare translation slot in the I/O MMU", \
33
"permission denied", \
34
"bad page", \
35
"copy arguments cross page boundary", \
36
"page address size too large", \
37
"operation not done; try again", \
38
}
39
40
/*
41
* Type of grant entry.
42
* GTF_invalid: This grant entry grants no privileges.
43
* GTF_permit_access: Allow @domid to map/access @frame.
44
* GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
45
* to this guest. Xen writes the page number to @frame.
46
* GTF_transitive: Allow @domid to transitively access a subrange of
47
* @trans_grant in @trans_domid. No mappings are allowed.
48
*/
49
#define GTF_invalid (0 << 0)
50
#define GTF_permit_access (1 << 0)
51
#define GTF_accept_transfer (2 << 0)
52
#define GTF_transitive (3 << 0)
53
#define GTF_type_mask (3 << 0)
54
55
/*
56
* Subflags for GTF_permit_access.
57
* GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
58
* GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
59
* GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
60
* GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
61
* GTF_sub_page: Grant access to only a subrange of the page. @domid
62
* will only be allowed to copy from the grant, and not
63
* map it. [GST]
64
*/
65
#define _GTF_readonly 2
66
#define GTF_readonly (1 << _GTF_readonly)
67
68
#define _GTF_reading 3
69
#define GTF_reading (1 << _GTF_reading)
70
71
#define _GTF_writing 4
72
#define GTF_writing (1 << _GTF_writing)
73
74
#define _GTF_PWT 5
75
#define GTF_PWT (1 << _GTF_PWT)
76
77
#define _GTF_PCD 6
78
#define GTF_PCD (1 << _GTF_PCD)
79
80
#define _GTF_PAT 7
81
#define GTF_PAT (1 << _GTF_PAT)
82
83
#define _GTF_sub_page 8
84
#define GTF_sub_page (1 << _GTF_sub_page)
85
86
/*
87
* Subflags for GTF_accept_transfer:
88
* GTF_transfer_committed: Xen sets this flag to indicate that it is committed
89
* to transferring ownership of a page frame. When a guest sees this flag
90
* it must /not/ modify the grant entry until GTF_transfer_completed is
91
* set by Xen.
92
* GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
93
* after reading GTF_transfer_committed. Xen will always write the frame
94
* address, followed by ORing this flag, in a timely manner.
95
*/
96
#define _GTF_transfer_committed 2
97
#define GTF_transfer_committed (1 << _GTF_transfer_committed)
98
99
#define _GTF_transfer_completed 3
100
#define GTF_transfer_completed (1 << _GTF_transfer_completed)
101
102
typedef
uint32_t
grant_ref_t
;
103
typedef
uint32_t
grant_handle_t
;
104
105
typedef
struct
106
{
107
/* GTF_xxx: various type and flag information. [XEN,GST] */
108
uint16_t
flags
;
109
/* The domain being granted foreign privileges. [GST] */
110
domid_t
domid
;
111
/*
112
* GTF_permit_access: GFN that @domid is allowed to map and access. [GST]
113
* GTF_accept_transfer: GFN that @domid is allowed to transfer into. [GST]
114
* GTF_transfer_completed: MFN whose ownership transferred by @domid
115
* (non-translated guests only). [XEN]
116
*/
117
uint32_t
frame
;
118
}
grant_entry_v1_t
;
119
120
typedef
struct
{
121
uint16_t
flags
;
122
domid_t
domid
;
123
}
grant_entry_header_t
;
124
125
typedef
union
{
126
grant_entry_header_t
hdr
;
127
128
/*
129
* This member is used for V1-style full page grants, where either:
130
*
131
* -- hdr.type is GTF_accept_transfer, or
132
* -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
133
*
134
* In that case, the frame field has the same semantics as the
135
* field of the same name in the V1 entry structure.
136
*/
137
struct
{
138
grant_entry_header_t
hdr;
139
uint32_t
pad0
;
140
uint64_t
frame
;
141
} full_page;
142
143
/*
144
* If the grant type is GTF_grant_access and GTF_sub_page is set,
145
* @domid is allowed to access bytes [@page_off,@page_off+@length)
146
* in frame @frame.
147
*/
148
struct
{
149
grant_entry_header_t
hdr;
150
uint16_t
page_off
;
151
uint16_t
length
;
152
uint64_t
frame
;
153
} sub_page;
154
155
/*
156
* If the grant is GTF_transitive, @domid is allowed to use the
157
* grant @gref in domain @trans_domid, as if it was the local
158
* domain. Obviously, the transitive access must be compatible
159
* with the original grant.
160
*
161
* The current version of Xen does not allow transitive grants
162
* to be mapped.
163
*/
164
struct
{
165
grant_entry_header_t
hdr;
166
domid_t
trans_domid
;
167
uint16_t
pad0
;
168
grant_ref_t
gref
;
169
} transitive;
170
171
uint32_t
__spacer[4];
/* Pad to a power of two */
172
}
grant_entry_v2_t
;
173
174
/* Map the grant entry for access by I/O devices. */
175
#define _GNTMAP_device_map 0
176
#define GNTMAP_device_map (1 << _GNTMAP_device_map)
177
/* Map the grant entry for access by host CPUs. */
178
#define _GNTMAP_host_map 1
179
#define GNTMAP_host_map (1 << _GNTMAP_host_map)
180
/* Accesses to the granted frame will be restricted to read-only access. */
181
#define _GNTMAP_readonly 2
182
#define GNTMAP_readonly (1 << _GNTMAP_readonly)
183
/*
184
* GNTMAP_host_map subflag:
185
* 0 => The host mapping is usable only by the guest OS.
186
* 1 => The host mapping is usable by guest OS + current application.
187
*/
188
#define _GNTMAP_application_map 3
189
#define GNTMAP_application_map (1 << _GNTMAP_application_map)
190
191
/*
192
* GNTMAP_contains_pte subflag:
193
* 0 => This map request contains a host virtual address.
194
* 1 => This map request contains the machine addess of the PTE to update.
195
*/
196
#define _GNTMAP_contains_pte 4
197
#define GNTMAP_contains_pte (1 << _GNTMAP_contains_pte)
198
199
/*
200
* Bits to be placed in guest kernel available PTE bits (architecture
201
* dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
202
*/
203
#define _GNTMAP_guest_avail0 16
204
#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
205
206
/*
207
* GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
208
* by devices and/or host CPUs. If successful, <handle> is a tracking number
209
* that must be presented later to destroy the mapping(s). On error, <status>
210
* is a negative status code.
211
* NOTES:
212
* 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
213
* via which I/O devices may access the granted frame.
214
* 2. If GNTMAP_host_map is specified then a mapping will be added at
215
* either a host virtual address in the current address space, or at
216
* a PTE at the specified machine address. The type of mapping to
217
* perform is selected through the GNTMAP_contains_pte flag, and the
218
* address is specified in <host_addr>.
219
* 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
220
* host mapping is destroyed by other means then it is *NOT* guaranteed
221
* to be accounted to the correct grant reference!
222
*/
223
#define GNTTABOP_map_grant_ref 0
224
struct
gnttab_map_grant_ref
{
225
/* IN parameters. */
226
uint64_t
host_addr
;
227
uint32_t
flags
;
/* GNTMAP_* */
228
grant_ref_t
ref
;
229
domid_t
dom
;
230
/* OUT parameters. */
231
int16_t
status
;
/* => enum grant_status */
232
grant_handle_t
handle
;
233
uint64_t
dev_bus_addr
;
234
};
235
236
/*
237
* GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
238
* tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
239
* field is ignored. If non-zero, they must refer to a device/host mapping
240
* that is tracked by <handle>
241
* NOTES:
242
* 1. The call may fail in an undefined manner if either mapping is not
243
* tracked by <handle>.
244
* 3. After executing a batch of unmaps, it is guaranteed that no stale
245
* mappings will remain in the device or host TLBs.
246
*/
247
#define GNTTABOP_unmap_grant_ref 1
248
struct
gnttab_unmap_grant_ref
{
249
/* IN parameters. */
250
uint64_t
host_addr
;
251
uint64_t
dev_bus_addr
;
252
grant_handle_t
handle
;
253
/* OUT parameters. */
254
int16_t
status
;
/* => enum grant_status */
255
};
256
257
/*
258
* GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
259
* <nr_frames> pages. The frame addresses are written to the <frame_list>.
260
* Only <nr_frames> addresses are written, even if the table is larger.
261
* NOTES:
262
* 1. <dom> may be specified as DOMID_SELF.
263
* 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
264
* 3. Xen may not support more than a single grant-table page per domain.
265
*/
266
#define GNTTABOP_setup_table 2
267
struct
gnttab_setup_table
268
{
269
/* IN parameters. */
270
domid_t
dom
;
271
uint32_t
nr_frames
;
272
/* OUT parameters. */
273
int16_t
status
;
274
unsigned
long
*
frame_list
;
275
};
276
277
/*
278
* GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
279
* tracked by <handle> but atomically replace the page table entry with one
280
* pointing to the machine address under <new_addr>. <new_addr> will be
281
* redirected to the null entry.
282
* NOTES:
283
* 1. The call may fail in an undefined manner if either mapping is not
284
* tracked by <handle>.
285
* 2. After executing a batch of unmaps, it is guaranteed that no stale
286
* mappings will remain in the device or host TLBs.
287
*/
288
#define GNTTABOP_unmap_and_replace 7
289
struct
gnttab_unmap_and_replace
{
290
/* IN parameters. */
291
uint64_t
host_addr
;
292
uint64_t
new_addr
;
293
grant_handle_t
handle
;
294
/* OUT parameters. */
295
int16_t
status
;
/* => enum grant_status */
296
};
297
298
/*
299
* GNTTABOP_set_version: Request a particular version of the grant
300
* table shared table structure. This operation may be used to toggle
301
* between different versions, but must be performed while no grants
302
* are active. The only defined versions are 1 and 2.
303
*/
304
#define GNTTABOP_set_version 8
305
struct
gnttab_set_version
{
306
/* IN/OUT parameters */
307
uint32_t
version
;
308
};
309
310
/*
311
* GNTTABOP_get_status_frames: Get the list of frames used to store grant
312
* status for <dom>. In grant format version 2, the status is separated
313
* from the other shared grant fields to allow more efficient synchronization
314
* using barriers instead of atomic cmpxchg operations.
315
*/
316
#define GNTTABOP_get_status_frames 9
317
struct
gnttab_get_status_frames
{
318
/* IN parameters. */
319
uint32_t
nr_frames
;
320
domid_t
dom
;
321
/* OUT parameters. */
322
int16_t
status
;
/* => enum grant_status */
323
uint64_t
*
frame_list
;
324
};
325
326
/*
327
* Issue one or more cache maintenance operations on a portion of a
328
* page granted to the calling domain by a foreign domain.
329
*/
330
#define GNTTABOP_cache_flush 12
331
struct
gnttab_cache_flush
{
332
union
{
333
uint64_t
dev_bus_addr
;
334
grant_ref_t
ref
;
335
}
a
;
336
uint16_t
offset
;
/* offset from start of grant */
337
uint16_t
length
;
/* size within the grant */
338
#define GNTTAB_CACHE_CLEAN (1<<0)
339
#define GNTTAB_CACHE_INVAL (1<<1)
340
#define GNTTAB_CACHE_SOURCE_GREF (1<<31)
341
uint32_t
op
;
342
};
343
344
#endif
/* XEN_PUBLIC_GRANT_TABLE_H */
345
346
/*
347
* Local variables:
348
* mode: C
349
* c-file-style: "BSD"
350
* c-basic-offset: 4
351
* tab-width: 4
352
* indent-tabs-mode: nil
353
* End:
354
*/
uint32_t
__UINT32_TYPE__ uint32_t
Definition:
stdint.h:16
uint64_t
__UINT64_TYPE__ uint64_t
Definition:
stdint.h:17
uint16_t
__UINT16_TYPE__ uint16_t
Definition:
stdint.h:15
int16_t
__INT16_TYPE__ int16_t
Definition:
stdint.h:10
gnttab_cache_flush
Definition:
grant_table.h:331
gnttab_cache_flush::op
uint32_t op
Definition:
grant_table.h:341
gnttab_cache_flush::length
uint16_t length
Definition:
grant_table.h:337
gnttab_cache_flush::ref
grant_ref_t ref
Definition:
grant_table.h:334
gnttab_cache_flush::offset
uint16_t offset
Definition:
grant_table.h:336
gnttab_cache_flush::a
union gnttab_cache_flush::@45 a
gnttab_cache_flush::dev_bus_addr
uint64_t dev_bus_addr
Definition:
grant_table.h:333
gnttab_get_status_frames
Definition:
grant_table.h:317
gnttab_get_status_frames::status
int16_t status
Definition:
grant_table.h:322
gnttab_get_status_frames::frame_list
uint64_t * frame_list
Definition:
grant_table.h:323
gnttab_get_status_frames::nr_frames
uint32_t nr_frames
Definition:
grant_table.h:319
gnttab_get_status_frames::dom
domid_t dom
Definition:
grant_table.h:320
gnttab_map_grant_ref
Definition:
grant_table.h:224
gnttab_map_grant_ref::ref
grant_ref_t ref
Definition:
grant_table.h:228
gnttab_map_grant_ref::status
int16_t status
Definition:
grant_table.h:231
gnttab_map_grant_ref::flags
uint32_t flags
Definition:
grant_table.h:227
gnttab_map_grant_ref::handle
grant_handle_t handle
Definition:
grant_table.h:232
gnttab_map_grant_ref::host_addr
uint64_t host_addr
Definition:
grant_table.h:226
gnttab_map_grant_ref::dom
domid_t dom
Definition:
grant_table.h:229
gnttab_map_grant_ref::dev_bus_addr
uint64_t dev_bus_addr
Definition:
grant_table.h:233
gnttab_set_version
Definition:
grant_table.h:305
gnttab_set_version::version
uint32_t version
Definition:
grant_table.h:307
gnttab_setup_table
Definition:
grant_table.h:268
gnttab_setup_table::status
int16_t status
Definition:
grant_table.h:273
gnttab_setup_table::nr_frames
uint32_t nr_frames
Definition:
grant_table.h:271
gnttab_setup_table::dom
domid_t dom
Definition:
grant_table.h:270
gnttab_setup_table::frame_list
unsigned long * frame_list
Definition:
grant_table.h:274
gnttab_unmap_and_replace
Definition:
grant_table.h:289
gnttab_unmap_and_replace::status
int16_t status
Definition:
grant_table.h:295
gnttab_unmap_and_replace::handle
grant_handle_t handle
Definition:
grant_table.h:293
gnttab_unmap_and_replace::host_addr
uint64_t host_addr
Definition:
grant_table.h:291
gnttab_unmap_and_replace::new_addr
uint64_t new_addr
Definition:
grant_table.h:292
gnttab_unmap_grant_ref
Definition:
grant_table.h:248
gnttab_unmap_grant_ref::status
int16_t status
Definition:
grant_table.h:254
gnttab_unmap_grant_ref::handle
grant_handle_t handle
Definition:
grant_table.h:252
gnttab_unmap_grant_ref::host_addr
uint64_t host_addr
Definition:
grant_table.h:250
gnttab_unmap_grant_ref::dev_bus_addr
uint64_t dev_bus_addr
Definition:
grant_table.h:251
grant_entry_header_t
Definition:
grant_table.h:120
grant_entry_header_t::flags
uint16_t flags
Definition:
grant_table.h:121
grant_entry_header_t::domid
domid_t domid
Definition:
grant_table.h:122
grant_entry_v1_t
Definition:
grant_table.h:106
grant_entry_v1_t::flags
uint16_t flags
Definition:
grant_table.h:108
grant_entry_v1_t::frame
uint32_t frame
Definition:
grant_table.h:117
grant_entry_v1_t::domid
domid_t domid
Definition:
grant_table.h:110
grant_entry_v2_t
Definition:
grant_table.h:125
grant_entry_v2_t::pad0
uint16_t pad0
Definition:
grant_table.h:167
grant_entry_v2_t::length
uint16_t length
Definition:
grant_table.h:151
grant_entry_v2_t::trans_domid
domid_t trans_domid
Definition:
grant_table.h:166
grant_entry_v2_t::frame
uint64_t frame
Definition:
grant_table.h:140
grant_entry_v2_t::page_off
uint16_t page_off
Definition:
grant_table.h:150
grant_entry_v2_t::hdr
grant_entry_header_t hdr
Definition:
grant_table.h:126
grant_entry_v2_t::gref
grant_ref_t gref
Definition:
grant_table.h:168
grant_entry_v2_t::pad0
uint32_t pad0
Definition:
grant_table.h:139
grant_handle_t
uint32_t grant_handle_t
Definition:
grant_table.h:103
grant_ref_t
uint32_t grant_ref_t
Definition:
grant_table.h:102
xen.h
domid_t
uint16_t domid_t
Definition:
xen.h:66
frame
static uint8_t frame[PAGE_SIZE]
Definition:
main.c:23
Generated by
1.9.4