diff options
Diffstat (limited to 'include/xen')
-rw-r--r-- | include/xen/grant_table.h | 107 | ||||
-rw-r--r-- | include/xen/interface/grant_table.h | 94 |
2 files changed, 191 insertions, 10 deletions
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h new file mode 100644 index 000000000000..761c83498e03 --- /dev/null +++ b/include/xen/grant_table.h | |||
@@ -0,0 +1,107 @@ | |||
1 | /****************************************************************************** | ||
2 | * grant_table.h | ||
3 | * | ||
4 | * Two sets of functionality: | ||
5 | * 1. Granting foreign access to our memory reservation. | ||
6 | * 2. Accessing others' memory reservations via grant references. | ||
7 | * (i.e., mechanisms for both sender and recipient of grant references) | ||
8 | * | ||
9 | * Copyright (c) 2004-2005, K A Fraser | ||
10 | * Copyright (c) 2005, Christopher Clark | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License version 2 | ||
14 | * as published by the Free Software Foundation; or, when distributed | ||
15 | * separately from the Linux kernel or incorporated into other | ||
16 | * software packages, subject to the following license: | ||
17 | * | ||
18 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
19 | * of this source file (the "Software"), to deal in the Software without | ||
20 | * restriction, including without limitation the rights to use, copy, modify, | ||
21 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
22 | * and to permit persons to whom the Software is furnished to do so, subject to | ||
23 | * the following conditions: | ||
24 | * | ||
25 | * The above copyright notice and this permission notice shall be included in | ||
26 | * all copies or substantial portions of the Software. | ||
27 | * | ||
28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
31 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
34 | * IN THE SOFTWARE. | ||
35 | */ | ||
36 | |||
37 | #ifndef __ASM_GNTTAB_H__ | ||
38 | #define __ASM_GNTTAB_H__ | ||
39 | |||
40 | #include <asm/xen/hypervisor.h> | ||
41 | #include <xen/interface/grant_table.h> | ||
42 | |||
43 | /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */ | ||
44 | #define NR_GRANT_FRAMES 4 | ||
45 | |||
46 | struct gnttab_free_callback { | ||
47 | struct gnttab_free_callback *next; | ||
48 | void (*fn)(void *); | ||
49 | void *arg; | ||
50 | u16 count; | ||
51 | }; | ||
52 | |||
53 | int gnttab_grant_foreign_access(domid_t domid, unsigned long frame, | ||
54 | int readonly); | ||
55 | |||
56 | /* | ||
57 | * End access through the given grant reference, iff the grant entry is no | ||
58 | * longer in use. Return 1 if the grant entry was freed, 0 if it is still in | ||
59 | * use. | ||
60 | */ | ||
61 | int gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly); | ||
62 | |||
63 | /* | ||
64 | * Eventually end access through the given grant reference, and once that | ||
65 | * access has been ended, free the given page too. Access will be ended | ||
66 | * immediately iff the grant entry is not in use, otherwise it will happen | ||
67 | * some time later. page may be 0, in which case no freeing will occur. | ||
68 | */ | ||
69 | void gnttab_end_foreign_access(grant_ref_t ref, int readonly, | ||
70 | unsigned long page); | ||
71 | |||
72 | int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn); | ||
73 | |||
74 | unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref); | ||
75 | unsigned long gnttab_end_foreign_transfer(grant_ref_t ref); | ||
76 | |||
77 | int gnttab_query_foreign_access(grant_ref_t ref); | ||
78 | |||
79 | /* | ||
80 | * operations on reserved batches of grant references | ||
81 | */ | ||
82 | int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head); | ||
83 | |||
84 | void gnttab_free_grant_reference(grant_ref_t ref); | ||
85 | |||
86 | void gnttab_free_grant_references(grant_ref_t head); | ||
87 | |||
88 | int gnttab_empty_grant_references(const grant_ref_t *pprivate_head); | ||
89 | |||
90 | int gnttab_claim_grant_reference(grant_ref_t *pprivate_head); | ||
91 | |||
92 | void gnttab_release_grant_reference(grant_ref_t *private_head, | ||
93 | grant_ref_t release); | ||
94 | |||
95 | void gnttab_request_free_callback(struct gnttab_free_callback *callback, | ||
96 | void (*fn)(void *), void *arg, u16 count); | ||
97 | void gnttab_cancel_free_callback(struct gnttab_free_callback *callback); | ||
98 | |||
99 | void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid, | ||
100 | unsigned long frame, int readonly); | ||
101 | |||
102 | void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid, | ||
103 | unsigned long pfn); | ||
104 | |||
105 | #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr)) | ||
106 | |||
107 | #endif /* __ASM_GNTTAB_H__ */ | ||
diff --git a/include/xen/interface/grant_table.h b/include/xen/interface/grant_table.h index e9e06695ed52..219049802cf2 100644 --- a/include/xen/interface/grant_table.h +++ b/include/xen/interface/grant_table.h | |||
@@ -4,6 +4,24 @@ | |||
4 | * Interface for granting foreign access to page frames, and receiving | 4 | * Interface for granting foreign access to page frames, and receiving |
5 | * page-ownership transfers. | 5 | * page-ownership transfers. |
6 | * | 6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
8 | * of this software and associated documentation files (the "Software"), to | ||
9 | * deal in the Software without restriction, including without limitation the | ||
10 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
11 | * sell copies of the Software, and to permit persons to whom the Software is | ||
12 | * furnished to do so, subject to the following conditions: | ||
13 | * | ||
14 | * The above copyright notice and this permission notice shall be included in | ||
15 | * all copies or substantial portions of the Software. | ||
16 | * | ||
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
23 | * DEALINGS IN THE SOFTWARE. | ||
24 | * | ||
7 | * Copyright (c) 2004, K A Fraser | 25 | * Copyright (c) 2004, K A Fraser |
8 | */ | 26 | */ |
9 | 27 | ||
@@ -17,7 +35,7 @@ | |||
17 | 35 | ||
18 | /* Some rough guidelines on accessing and updating grant-table entries | 36 | /* Some rough guidelines on accessing and updating grant-table entries |
19 | * in a concurrency-safe manner. For more information, Linux contains a | 37 | * in a concurrency-safe manner. For more information, Linux contains a |
20 | * reference implementation for guest OSes (arch/i386/mach-xen/grant_table.c). | 38 | * reference implementation for guest OSes (arch/xen/kernel/grant_table.c). |
21 | * | 39 | * |
22 | * NB. WMB is a no-op on current-generation x86 processors. However, a | 40 | * NB. WMB is a no-op on current-generation x86 processors. However, a |
23 | * compiler barrier will still be required. | 41 | * compiler barrier will still be required. |
@@ -144,9 +162,9 @@ typedef uint32_t grant_handle_t; | |||
144 | * that must be presented later to destroy the mapping(s). On error, <handle> | 162 | * that must be presented later to destroy the mapping(s). On error, <handle> |
145 | * is a negative status code. | 163 | * is a negative status code. |
146 | * NOTES: | 164 | * NOTES: |
147 | * 1. If GNTPIN_map_for_dev is specified then <dev_bus_addr> is the address | 165 | * 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address |
148 | * via which I/O devices may access the granted frame. | 166 | * via which I/O devices may access the granted frame. |
149 | * 2. If GNTPIN_map_for_host is specified then a mapping will be added at | 167 | * 2. If GNTMAP_host_map is specified then a mapping will be added at |
150 | * either a host virtual address in the current address space, or at | 168 | * either a host virtual address in the current address space, or at |
151 | * a PTE at the specified machine address. The type of mapping to | 169 | * a PTE at the specified machine address. The type of mapping to |
152 | * perform is selected through the GNTMAP_contains_pte flag, and the | 170 | * perform is selected through the GNTMAP_contains_pte flag, and the |
@@ -167,7 +185,6 @@ struct gnttab_map_grant_ref { | |||
167 | grant_handle_t handle; | 185 | grant_handle_t handle; |
168 | uint64_t dev_bus_addr; | 186 | uint64_t dev_bus_addr; |
169 | }; | 187 | }; |
170 | DEFINE_GUEST_HANDLE_STRUCT(gnttab_map_grant_ref); | ||
171 | 188 | ||
172 | /* | 189 | /* |
173 | * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings | 190 | * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings |
@@ -189,7 +206,6 @@ struct gnttab_unmap_grant_ref { | |||
189 | /* OUT parameters. */ | 206 | /* OUT parameters. */ |
190 | int16_t status; /* GNTST_* */ | 207 | int16_t status; /* GNTST_* */ |
191 | }; | 208 | }; |
192 | DEFINE_GUEST_HANDLE_STRUCT(gnttab_unmap_grant_ref); | ||
193 | 209 | ||
194 | /* | 210 | /* |
195 | * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least | 211 | * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least |
@@ -207,9 +223,8 @@ struct gnttab_setup_table { | |||
207 | uint32_t nr_frames; | 223 | uint32_t nr_frames; |
208 | /* OUT parameters. */ | 224 | /* OUT parameters. */ |
209 | int16_t status; /* GNTST_* */ | 225 | int16_t status; /* GNTST_* */ |
210 | GUEST_HANDLE(ulong) frame_list; | 226 | ulong *frame_list; |
211 | }; | 227 | }; |
212 | DEFINE_GUEST_HANDLE_STRUCT(gnttab_setup_table); | ||
213 | 228 | ||
214 | /* | 229 | /* |
215 | * GNTTABOP_dump_table: Dump the contents of the grant table to the | 230 | * GNTTABOP_dump_table: Dump the contents of the grant table to the |
@@ -222,7 +237,6 @@ struct gnttab_dump_table { | |||
222 | /* OUT parameters. */ | 237 | /* OUT parameters. */ |
223 | int16_t status; /* GNTST_* */ | 238 | int16_t status; /* GNTST_* */ |
224 | }; | 239 | }; |
225 | DEFINE_GUEST_HANDLE_STRUCT(gnttab_dump_table); | ||
226 | 240 | ||
227 | /* | 241 | /* |
228 | * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The | 242 | * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The |
@@ -241,7 +255,65 @@ struct gnttab_transfer { | |||
241 | /* OUT parameters. */ | 255 | /* OUT parameters. */ |
242 | int16_t status; | 256 | int16_t status; |
243 | }; | 257 | }; |
244 | DEFINE_GUEST_HANDLE_STRUCT(gnttab_transfer); | 258 | |
259 | |||
260 | /* | ||
261 | * GNTTABOP_copy: Hypervisor based copy | ||
262 | * source and destinations can be eithers MFNs or, for foreign domains, | ||
263 | * grant references. the foreign domain has to grant read/write access | ||
264 | * in its grant table. | ||
265 | * | ||
266 | * The flags specify what type source and destinations are (either MFN | ||
267 | * or grant reference). | ||
268 | * | ||
269 | * Note that this can also be used to copy data between two domains | ||
270 | * via a third party if the source and destination domains had previously | ||
271 | * grant appropriate access to their pages to the third party. | ||
272 | * | ||
273 | * source_offset specifies an offset in the source frame, dest_offset | ||
274 | * the offset in the target frame and len specifies the number of | ||
275 | * bytes to be copied. | ||
276 | */ | ||
277 | |||
278 | #define _GNTCOPY_source_gref (0) | ||
279 | #define GNTCOPY_source_gref (1<<_GNTCOPY_source_gref) | ||
280 | #define _GNTCOPY_dest_gref (1) | ||
281 | #define GNTCOPY_dest_gref (1<<_GNTCOPY_dest_gref) | ||
282 | |||
283 | #define GNTTABOP_copy 5 | ||
284 | struct gnttab_copy { | ||
285 | /* IN parameters. */ | ||
286 | struct { | ||
287 | union { | ||
288 | grant_ref_t ref; | ||
289 | unsigned long gmfn; | ||
290 | } u; | ||
291 | domid_t domid; | ||
292 | uint16_t offset; | ||
293 | } source, dest; | ||
294 | uint16_t len; | ||
295 | uint16_t flags; /* GNTCOPY_* */ | ||
296 | /* OUT parameters. */ | ||
297 | int16_t status; | ||
298 | }; | ||
299 | |||
300 | /* | ||
301 | * GNTTABOP_query_size: Query the current and maximum sizes of the shared | ||
302 | * grant table. | ||
303 | * NOTES: | ||
304 | * 1. <dom> may be specified as DOMID_SELF. | ||
305 | * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. | ||
306 | */ | ||
307 | #define GNTTABOP_query_size 6 | ||
308 | struct gnttab_query_size { | ||
309 | /* IN parameters. */ | ||
310 | domid_t dom; | ||
311 | /* OUT parameters. */ | ||
312 | uint32_t nr_frames; | ||
313 | uint32_t max_nr_frames; | ||
314 | int16_t status; /* GNTST_* */ | ||
315 | }; | ||
316 | |||
245 | 317 | ||
246 | /* | 318 | /* |
247 | * Bitfield values for update_pin_status.flags. | 319 | * Bitfield values for update_pin_status.flags. |
@@ -284,6 +356,7 @@ DEFINE_GUEST_HANDLE_STRUCT(gnttab_transfer); | |||
284 | #define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */ | 356 | #define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */ |
285 | #define GNTST_permission_denied (-8) /* Not enough privilege for operation. */ | 357 | #define GNTST_permission_denied (-8) /* Not enough privilege for operation. */ |
286 | #define GNTST_bad_page (-9) /* Specified page was invalid for op. */ | 358 | #define GNTST_bad_page (-9) /* Specified page was invalid for op. */ |
359 | #define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary */ | ||
287 | 360 | ||
288 | #define GNTTABOP_error_msgs { \ | 361 | #define GNTTABOP_error_msgs { \ |
289 | "okay", \ | 362 | "okay", \ |
@@ -295,7 +368,8 @@ DEFINE_GUEST_HANDLE_STRUCT(gnttab_transfer); | |||
295 | "invalid device address", \ | 368 | "invalid device address", \ |
296 | "no spare translation slot in the I/O MMU", \ | 369 | "no spare translation slot in the I/O MMU", \ |
297 | "permission denied", \ | 370 | "permission denied", \ |
298 | "bad page" \ | 371 | "bad page", \ |
372 | "copy arguments cross page boundary" \ | ||
299 | } | 373 | } |
300 | 374 | ||
301 | #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ | 375 | #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ |