| 1 |
/****************************************************************************** |
| 2 |
* grant_table.h |
| 3 |
* |
| 4 |
* Interface for granting foreign access to page frames, and receiving |
| 5 |
* page-ownership transfers. |
| 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 |
* |
| 25 |
* Copyright (c) 2004, K A Fraser |
| 26 |
*/ |
| 27 |
|
| 28 |
#ifndef __XEN_PUBLIC_GRANT_TABLE_H__ |
| 29 |
#define __XEN_PUBLIC_GRANT_TABLE_H__ |
| 30 |
|
| 31 |
#include "xen.h" |
| 32 |
|
| 33 |
/* |
| 34 |
* `incontents 150 gnttab Grant Tables |
| 35 |
* |
| 36 |
* Xen's grant tables provide a generic mechanism to memory sharing |
| 37 |
* between domains. This shared memory interface underpins the split |
| 38 |
* device drivers for block and network IO. |
| 39 |
* |
| 40 |
* Each domain has its own grant table. This is a data structure that |
| 41 |
* is shared with Xen; it allows the domain to tell Xen what kind of |
| 42 |
* permissions other domains have on its pages. Entries in the grant |
| 43 |
* table are identified by grant references. A grant reference is an |
| 44 |
* integer, which indexes into the grant table. It acts as a |
| 45 |
* capability which the grantee can use to perform operations on the |
| 46 |
* granter’s memory. |
| 47 |
* |
| 48 |
* This capability-based system allows shared-memory communications |
| 49 |
* between unprivileged domains. A grant reference also encapsulates |
| 50 |
* the details of a shared page, removing the need for a domain to |
| 51 |
* know the real machine address of a page it is sharing. This makes |
| 52 |
* it possible to share memory correctly with domains running in |
| 53 |
* fully virtualised memory. |
| 54 |
*/ |
| 55 |
|
| 56 |
/*********************************** |
| 57 |
* GRANT TABLE REPRESENTATION |
| 58 |
*/ |
| 59 |
|
| 60 |
/* Some rough guidelines on accessing and updating grant-table entries |
| 61 |
* in a concurrency-safe manner. For more information, Linux contains a |
| 62 |
* reference implementation for guest OSes (drivers/xen/grant_table.c, see |
| 63 |
* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD |
| 64 |
* |
| 65 |
* NB. WMB is a no-op on current-generation x86 processors. However, a |
| 66 |
* compiler barrier will still be required. |
| 67 |
* |
| 68 |
* Introducing a valid entry into the grant table: |
| 69 |
* 1. Write ent->domid. |
| 70 |
* 2. Write ent->frame: |
| 71 |
* GTF_permit_access: Frame to which access is permitted. |
| 72 |
* GTF_accept_transfer: Pseudo-phys frame slot being filled by new |
| 73 |
* frame, or zero if none. |
| 74 |
* 3. Write memory barrier (WMB). |
| 75 |
* 4. Write ent->flags, inc. valid type. |
| 76 |
* |
| 77 |
* Invalidating an unused GTF_permit_access entry: |
| 78 |
* 1. flags = ent->flags. |
| 79 |
* 2. Observe that !(flags & (GTF_reading|GTF_writing)). |
| 80 |
* 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0). |
| 81 |
* NB. No need for WMB as reuse of entry is control-dependent on success of |
| 82 |
* step 3, and all architectures guarantee ordering of ctrl-dep writes. |
| 83 |
* |
| 84 |
* Invalidating an in-use GTF_permit_access entry: |
| 85 |
* This cannot be done directly. Request assistance from the domain controller |
| 86 |
* which can set a timeout on the use of a grant entry and take necessary |
| 87 |
* action. (NB. This is not yet implemented!). |
| 88 |
* |
| 89 |
* Invalidating an unused GTF_accept_transfer entry: |
| 90 |
* 1. flags = ent->flags. |
| 91 |
* 2. Observe that !(flags & GTF_transfer_committed). [*] |
| 92 |
* 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0). |
| 93 |
* NB. No need for WMB as reuse of entry is control-dependent on success of |
| 94 |
* step 3, and all architectures guarantee ordering of ctrl-dep writes. |
| 95 |
* [*] If GTF_transfer_committed is set then the grant entry is 'committed'. |
| 96 |
* The guest must /not/ modify the grant entry until the address of the |
| 97 |
* transferred frame is written. It is safe for the guest to spin waiting |
| 98 |
* for this to occur (detect by observing GTF_transfer_completed in |
| 99 |
* ent->flags). |
| 100 |
* |
| 101 |
* Invalidating a committed GTF_accept_transfer entry: |
| 102 |
* 1. Wait for (ent->flags & GTF_transfer_completed). |
| 103 |
* |
| 104 |
* Changing a GTF_permit_access from writable to read-only: |
| 105 |
* Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing. |
| 106 |
* |
| 107 |
* Changing a GTF_permit_access from read-only to writable: |
| 108 |
* Use SMP-safe bit-setting instruction. |
| 109 |
*/ |
| 110 |
|
| 111 |
/* |
| 112 |
* Reference to a grant entry in a specified domain's grant table. |
| 113 |
*/ |
| 114 |
typedef uint32_t grant_ref_t; |
| 115 |
|
| 116 |
/* |
| 117 |
* A grant table comprises a packed array of grant entries in one or more |
| 118 |
* page frames shared between Xen and a guest. |
| 119 |
* [XEN]: This field is written by Xen and read by the sharing guest. |
| 120 |
* [GST]: This field is written by the guest and read by Xen. |
| 121 |
*/ |
| 122 |
|
| 123 |
/* |
| 124 |
* Version 1 of the grant table entry structure is maintained purely |
| 125 |
* for backwards compatibility. New guests should use version 2. |
| 126 |
*/ |
| 127 |
#if __XEN_INTERFACE_VERSION__ < 0x0003020a |
| 128 |
#define grant_entry_v1 grant_entry |
| 129 |
#define grant_entry_v1_t grant_entry_t |
| 130 |
#endif |
| 131 |
struct grant_entry_v1 { |
| 132 |
/* GTF_xxx: various type and flag information. [XEN,GST] */ |
| 133 |
uint16_t flags; |
| 134 |
/* The domain being granted foreign privileges. [GST] */ |
| 135 |
domid_t domid; |
| 136 |
/* |
| 137 |
* GTF_permit_access: Frame that @domid is allowed to map and access. [GST] |
| 138 |
* GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN] |
| 139 |
*/ |
| 140 |
uint32_t frame; |
| 141 |
}; |
| 142 |
typedef struct grant_entry_v1 grant_entry_v1_t; |
| 143 |
|
| 144 |
/* The first few grant table entries will be preserved across grant table |
| 145 |
* version changes and may be pre-populated at domain creation by tools. |
| 146 |
*/ |
| 147 |
#define GNTTAB_NR_RESERVED_ENTRIES 8 |
| 148 |
#define GNTTAB_RESERVED_CONSOLE 0 |
| 149 |
#define GNTTAB_RESERVED_XENSTORE 1 |
| 150 |
|
| 151 |
/* |
| 152 |
* Type of grant entry. |
| 153 |
* GTF_invalid: This grant entry grants no privileges. |
| 154 |
* GTF_permit_access: Allow @domid to map/access @frame. |
| 155 |
* GTF_accept_transfer: Allow @domid to transfer ownership of one page frame |
| 156 |
* to this guest. Xen writes the page number to @frame. |
| 157 |
* GTF_transitive: Allow @domid to transitively access a subrange of |
| 158 |
* @trans_grant in @trans_domid. No mappings are allowed. |
| 159 |
*/ |
| 160 |
#define GTF_invalid (0U<<0) |
| 161 |
#define GTF_permit_access (1U<<0) |
| 162 |
#define GTF_accept_transfer (2U<<0) |
| 163 |
#define GTF_transitive (3U<<0) |
| 164 |
#define GTF_type_mask (3U<<0) |
| 165 |
|
| 166 |
/* |
| 167 |
* Subflags for GTF_permit_access. |
| 168 |
* GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST] |
| 169 |
* GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN] |
| 170 |
* GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN] |
| 171 |
* GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST] |
| 172 |
* GTF_sub_page: Grant access to only a subrange of the page. @domid |
| 173 |
* will only be allowed to copy from the grant, and not |
| 174 |
* map it. [GST] |
| 175 |
*/ |
| 176 |
#define _GTF_readonly (2) |
| 177 |
#define GTF_readonly (1U<<_GTF_readonly) |
| 178 |
#define _GTF_reading (3) |
| 179 |
#define GTF_reading (1U<<_GTF_reading) |
| 180 |
#define _GTF_writing (4) |
| 181 |
#define GTF_writing (1U<<_GTF_writing) |
| 182 |
#define _GTF_PWT (5) |
| 183 |
#define GTF_PWT (1U<<_GTF_PWT) |
| 184 |
#define _GTF_PCD (6) |
| 185 |
#define GTF_PCD (1U<<_GTF_PCD) |
| 186 |
#define _GTF_PAT (7) |
| 187 |
#define GTF_PAT (1U<<_GTF_PAT) |
| 188 |
#define _GTF_sub_page (8) |
| 189 |
#define GTF_sub_page (1U<<_GTF_sub_page) |
| 190 |
|
| 191 |
/* |
| 192 |
* Subflags for GTF_accept_transfer: |
| 193 |
* GTF_transfer_committed: Xen sets this flag to indicate that it is committed |
| 194 |
* to transferring ownership of a page frame. When a guest sees this flag |
| 195 |
* it must /not/ modify the grant entry until GTF_transfer_completed is |
| 196 |
* set by Xen. |
| 197 |
* GTF_transfer_completed: It is safe for the guest to spin-wait on this flag |
| 198 |
* after reading GTF_transfer_committed. Xen will always write the frame |
| 199 |
* address, followed by ORing this flag, in a timely manner. |
| 200 |
*/ |
| 201 |
#define _GTF_transfer_committed (2) |
| 202 |
#define GTF_transfer_committed (1U<<_GTF_transfer_committed) |
| 203 |
#define _GTF_transfer_completed (3) |
| 204 |
#define GTF_transfer_completed (1U<<_GTF_transfer_completed) |
| 205 |
|
| 206 |
/* |
| 207 |
* Version 2 grant table entries. These fulfil the same role as |
| 208 |
* version 1 entries, but can represent more complicated operations. |
| 209 |
* Any given domain will have either a version 1 or a version 2 table, |
| 210 |
* and every entry in the table will be the same version. |
| 211 |
* |
| 212 |
* The interface by which domains use grant references does not depend |
| 213 |
* on the grant table version in use by the other domain. |
| 214 |
*/ |
| 215 |
#if __XEN_INTERFACE_VERSION__ >= 0x0003020a |
| 216 |
/* |
| 217 |
* Version 1 and version 2 grant entries share a common prefix. The |
| 218 |
* fields of the prefix are documented as part of struct |
| 219 |
* grant_entry_v1. |
| 220 |
*/ |
| 221 |
struct grant_entry_header { |
| 222 |
uint16_t flags; |
| 223 |
domid_t domid; |
| 224 |
}; |
| 225 |
typedef struct grant_entry_header grant_entry_header_t; |
| 226 |
|
| 227 |
/* |
| 228 |
* Version 2 of the grant entry structure. |
| 229 |
*/ |
| 230 |
union grant_entry_v2 { |
| 231 |
grant_entry_header_t hdr; |
| 232 |
|
| 233 |
/* |
| 234 |
* This member is used for V1-style full page grants, where either: |
| 235 |
* |
| 236 |
* -- hdr.type is GTF_accept_transfer, or |
| 237 |
* -- hdr.type is GTF_permit_access and GTF_sub_page is not set. |
| 238 |
* |
| 239 |
* In that case, the frame field has the same semantics as the |
| 240 |
* field of the same name in the V1 entry structure. |
| 241 |
*/ |
| 242 |
struct { |
| 243 |
grant_entry_header_t hdr; |
| 244 |
uint32_t pad0; |
| 245 |
uint64_t frame; |
| 246 |
} full_page; |
| 247 |
|
| 248 |
/* |
| 249 |
* If the grant type is GTF_grant_access and GTF_sub_page is set, |
| 250 |
* @domid is allowed to access bytes [@page_off,@page_off+@length) |
| 251 |
* in frame @frame. |
| 252 |
*/ |
| 253 |
struct { |
| 254 |
grant_entry_header_t hdr; |
| 255 |
uint16_t page_off; |
| 256 |
uint16_t length; |
| 257 |
uint64_t frame; |
| 258 |
} sub_page; |
| 259 |
|
| 260 |
/* |
| 261 |
* If the grant is GTF_transitive, @domid is allowed to use the |
| 262 |
* grant @gref in domain @trans_domid, as if it was the local |
| 263 |
* domain. Obviously, the transitive access must be compatible |
| 264 |
* with the original grant. |
| 265 |
* |
| 266 |
* The current version of Xen does not allow transitive grants |
| 267 |
* to be mapped. |
| 268 |
*/ |
| 269 |
struct { |
| 270 |
grant_entry_header_t hdr; |
| 271 |
domid_t trans_domid; |
| 272 |
uint16_t pad0; |
| 273 |
grant_ref_t gref; |
| 274 |
} transitive; |
| 275 |
|
| 276 |
uint32_t __spacer[4]; /* Pad to a power of two */ |
| 277 |
}; |
| 278 |
typedef union grant_entry_v2 grant_entry_v2_t; |
| 279 |
|
| 280 |
typedef uint16_t grant_status_t; |
| 281 |
|
| 282 |
#endif /* __XEN_INTERFACE_VERSION__ */ |
| 283 |
|
| 284 |
/*********************************** |
| 285 |
* GRANT TABLE QUERIES AND USES |
| 286 |
*/ |
| 287 |
|
| 288 |
/* ` enum neg_errnoval |
| 289 |
* ` HYPERVISOR_grant_table_op(enum grant_table_op cmd, |
| 290 |
* ` void *args, |
| 291 |
* ` unsigned int count) |
| 292 |
* ` |
| 293 |
* |
| 294 |
* @args points to an array of a per-command data structure. The array |
| 295 |
* has @count members |
| 296 |
*/ |
| 297 |
|
| 298 |
/* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */ |
| 299 |
#define GNTTABOP_map_grant_ref 0 |
| 300 |
#define GNTTABOP_unmap_grant_ref 1 |
| 301 |
#define GNTTABOP_setup_table 2 |
| 302 |
#define GNTTABOP_dump_table 3 |
| 303 |
#define GNTTABOP_transfer 4 |
| 304 |
#define GNTTABOP_copy 5 |
| 305 |
#define GNTTABOP_query_size 6 |
| 306 |
#define GNTTABOP_unmap_and_replace 7 |
| 307 |
#if __XEN_INTERFACE_VERSION__ >= 0x0003020a |
| 308 |
#define GNTTABOP_set_version 8 |
| 309 |
#define GNTTABOP_get_status_frames 9 |
| 310 |
#define GNTTABOP_get_version 10 |
| 311 |
#define GNTTABOP_swap_grant_ref 11 |
| 312 |
#endif /* __XEN_INTERFACE_VERSION__ */ |
| 313 |
/* ` } */ |
| 314 |
|
| 315 |
/* |
| 316 |
* Handle to track a mapping created via a grant reference. |
| 317 |
*/ |
| 318 |
typedef uint32_t grant_handle_t; |
| 319 |
|
| 320 |
/* |
| 321 |
* GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access |
| 322 |
* by devices and/or host CPUs. If successful, <handle> is a tracking number |
| 323 |
* that must be presented later to destroy the mapping(s). On error, <handle> |
| 324 |
* is a negative status code. |
| 325 |
* NOTES: |
| 326 |
* 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address |
| 327 |
* via which I/O devices may access the granted frame. |
| 328 |
* 2. If GNTMAP_host_map is specified then a mapping will be added at |
| 329 |
* either a host virtual address in the current address space, or at |
| 330 |
* a PTE at the specified machine address. The type of mapping to |
| 331 |
* perform is selected through the GNTMAP_contains_pte flag, and the |
| 332 |
* address is specified in <host_addr>. |
| 333 |
* 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a |
| 334 |
* host mapping is destroyed by other means then it is *NOT* guaranteed |
| 335 |
* to be accounted to the correct grant reference! |
| 336 |
*/ |
| 337 |
struct gnttab_map_grant_ref { |
| 338 |
/* IN parameters. */ |
| 339 |
uint64_t host_addr; |
| 340 |
uint32_t flags; /* GNTMAP_* */ |
| 341 |
grant_ref_t ref; |
| 342 |
domid_t dom; |
| 343 |
/* OUT parameters. */ |
| 344 |
int16_t status; /* => enum grant_status */ |
| 345 |
grant_handle_t handle; |
| 346 |
uint64_t dev_bus_addr; |
| 347 |
}; |
| 348 |
typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t; |
| 349 |
DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t); |
| 350 |
|
| 351 |
/* |
| 352 |
* GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings |
| 353 |
* tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that |
| 354 |
* field is ignored. If non-zero, they must refer to a device/host mapping |
| 355 |
* that is tracked by <handle> |
| 356 |
* NOTES: |
| 357 |
* 1. The call may fail in an undefined manner if either mapping is not |
| 358 |
* tracked by <handle>. |
| 359 |
* 3. After executing a batch of unmaps, it is guaranteed that no stale |
| 360 |
* mappings will remain in the device or host TLBs. |
| 361 |
*/ |
| 362 |
struct gnttab_unmap_grant_ref { |
| 363 |
/* IN parameters. */ |
| 364 |
uint64_t host_addr; |
| 365 |
uint64_t dev_bus_addr; |
| 366 |
grant_handle_t handle; |
| 367 |
/* OUT parameters. */ |
| 368 |
int16_t status; /* => enum grant_status */ |
| 369 |
}; |
| 370 |
typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t; |
| 371 |
DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t); |
| 372 |
|
| 373 |
/* |
| 374 |
* GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least |
| 375 |
* <nr_frames> pages. The frame addresses are written to the <frame_list>. |
| 376 |
* Only <nr_frames> addresses are written, even if the table is larger. |
| 377 |
* NOTES: |
| 378 |
* 1. <dom> may be specified as DOMID_SELF. |
| 379 |
* 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. |
| 380 |
* 3. Xen may not support more than a single grant-table page per domain. |
| 381 |
*/ |
| 382 |
struct gnttab_setup_table { |
| 383 |
/* IN parameters. */ |
| 384 |
domid_t dom; |
| 385 |
uint32_t nr_frames; |
| 386 |
/* OUT parameters. */ |
| 387 |
int16_t status; /* => enum grant_status */ |
| 388 |
#if __XEN_INTERFACE_VERSION__ < 0x00040300 |
| 389 |
XEN_GUEST_HANDLE(ulong) frame_list; |
| 390 |
#else |
| 391 |
XEN_GUEST_HANDLE(xen_pfn_t) frame_list; |
| 392 |
#endif |
| 393 |
}; |
| 394 |
typedef struct gnttab_setup_table gnttab_setup_table_t; |
| 395 |
DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t); |
| 396 |
|
| 397 |
/* |
| 398 |
* GNTTABOP_dump_table: Dump the contents of the grant table to the |
| 399 |
* xen console. Debugging use only. |
| 400 |
*/ |
| 401 |
struct gnttab_dump_table { |
| 402 |
/* IN parameters. */ |
| 403 |
domid_t dom; |
| 404 |
/* OUT parameters. */ |
| 405 |
int16_t status; /* => enum grant_status */ |
| 406 |
}; |
| 407 |
typedef struct gnttab_dump_table gnttab_dump_table_t; |
| 408 |
DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t); |
| 409 |
|
| 410 |
/* |
| 411 |
* GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The |
| 412 |
* foreign domain has previously registered its interest in the transfer via |
| 413 |
* <domid, ref>. |
| 414 |
* |
| 415 |
* Note that, even if the transfer fails, the specified page no longer belongs |
| 416 |
* to the calling domain *unless* the error is GNTST_bad_page. |
| 417 |
*/ |
| 418 |
struct gnttab_transfer { |
| 419 |
/* IN parameters. */ |
| 420 |
xen_pfn_t mfn; |
| 421 |
domid_t domid; |
| 422 |
grant_ref_t ref; |
| 423 |
/* OUT parameters. */ |
| 424 |
int16_t status; |
| 425 |
}; |
| 426 |
typedef struct gnttab_transfer gnttab_transfer_t; |
| 427 |
DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t); |
| 428 |
|
| 429 |
|
| 430 |
/* |
| 431 |
* GNTTABOP_copy: Hypervisor based copy |
| 432 |
* source and destinations can be eithers MFNs or, for foreign domains, |
| 433 |
* grant references. the foreign domain has to grant read/write access |
| 434 |
* in its grant table. |
| 435 |
* |
| 436 |
* The flags specify what type source and destinations are (either MFN |
| 437 |
* or grant reference). |
| 438 |
* |
| 439 |
* Note that this can also be used to copy data between two domains |
| 440 |
* via a third party if the source and destination domains had previously |
| 441 |
* grant appropriate access to their pages to the third party. |
| 442 |
* |
| 443 |
* source_offset specifies an offset in the source frame, dest_offset |
| 444 |
* the offset in the target frame and len specifies the number of |
| 445 |
* bytes to be copied. |
| 446 |
*/ |
| 447 |
|
| 448 |
#define _GNTCOPY_source_gref (0) |
| 449 |
#define GNTCOPY_source_gref (1<<_GNTCOPY_source_gref) |
| 450 |
#define _GNTCOPY_dest_gref (1) |
| 451 |
#define GNTCOPY_dest_gref (1<<_GNTCOPY_dest_gref) |
| 452 |
|
| 453 |
struct gnttab_copy { |
| 454 |
/* IN parameters. */ |
| 455 |
struct { |
| 456 |
union { |
| 457 |
grant_ref_t ref; |
| 458 |
xen_pfn_t gmfn; |
| 459 |
} u; |
| 460 |
domid_t domid; |
| 461 |
uint16_t offset; |
| 462 |
} source, dest; |
| 463 |
uint16_t len; |
| 464 |
uint16_t flags; /* GNTCOPY_* */ |
| 465 |
/* OUT parameters. */ |
| 466 |
int16_t status; |
| 467 |
}; |
| 468 |
typedef struct gnttab_copy gnttab_copy_t; |
| 469 |
DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t); |
| 470 |
|
| 471 |
/* |
| 472 |
* GNTTABOP_query_size: Query the current and maximum sizes of the shared |
| 473 |
* grant table. |
| 474 |
* NOTES: |
| 475 |
* 1. <dom> may be specified as DOMID_SELF. |
| 476 |
* 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. |
| 477 |
*/ |
| 478 |
struct gnttab_query_size { |
| 479 |
/* IN parameters. */ |
| 480 |
domid_t dom; |
| 481 |
/* OUT parameters. */ |
| 482 |
uint32_t nr_frames; |
| 483 |
uint32_t max_nr_frames; |
| 484 |
int16_t status; /* => enum grant_status */ |
| 485 |
}; |
| 486 |
typedef struct gnttab_query_size gnttab_query_size_t; |
| 487 |
DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t); |
| 488 |
|
| 489 |
/* |
| 490 |
* GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings |
| 491 |
* tracked by <handle> but atomically replace the page table entry with one |
| 492 |
* pointing to the machine address under <new_addr>. <new_addr> will be |
| 493 |
* redirected to the null entry. |
| 494 |
* NOTES: |
| 495 |
* 1. The call may fail in an undefined manner if either mapping is not |
| 496 |
* tracked by <handle>. |
| 497 |
* 2. After executing a batch of unmaps, it is guaranteed that no stale |
| 498 |
* mappings will remain in the device or host TLBs. |
| 499 |
*/ |
| 500 |
struct gnttab_unmap_and_replace { |
| 501 |
/* IN parameters. */ |
| 502 |
uint64_t host_addr; |
| 503 |
uint64_t new_addr; |
| 504 |
grant_handle_t handle; |
| 505 |
/* OUT parameters. */ |
| 506 |
int16_t status; /* => enum grant_status */ |
| 507 |
}; |
| 508 |
typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t; |
| 509 |
DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t); |
| 510 |
|
| 511 |
#if __XEN_INTERFACE_VERSION__ >= 0x0003020a |
| 512 |
/* |
| 513 |
* GNTTABOP_set_version: Request a particular version of the grant |
| 514 |
* table shared table structure. This operation can only be performed |
| 515 |
* once in any given domain. It must be performed before any grants |
| 516 |
* are activated; otherwise, the domain will be stuck with version 1. |
| 517 |
* The only defined versions are 1 and 2. |
| 518 |
*/ |
| 519 |
struct gnttab_set_version { |
| 520 |
/* IN/OUT parameters */ |
| 521 |
uint32_t version; |
| 522 |
}; |
| 523 |
typedef struct gnttab_set_version gnttab_set_version_t; |
| 524 |
DEFINE_XEN_GUEST_HANDLE(gnttab_set_version_t); |
| 525 |
|
| 526 |
|
| 527 |
/* |
| 528 |
* GNTTABOP_get_status_frames: Get the list of frames used to store grant |
| 529 |
* status for <dom>. In grant format version 2, the status is separated |
| 530 |
* from the other shared grant fields to allow more efficient synchronization |
| 531 |
* using barriers instead of atomic cmpexch operations. |
| 532 |
* <nr_frames> specify the size of vector <frame_list>. |
| 533 |
* The frame addresses are returned in the <frame_list>. |
| 534 |
* Only <nr_frames> addresses are returned, even if the table is larger. |
| 535 |
* NOTES: |
| 536 |
* 1. <dom> may be specified as DOMID_SELF. |
| 537 |
* 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. |
| 538 |
*/ |
| 539 |
struct gnttab_get_status_frames { |
| 540 |
/* IN parameters. */ |
| 541 |
uint32_t nr_frames; |
| 542 |
domid_t dom; |
| 543 |
/* OUT parameters. */ |
| 544 |
int16_t status; /* => enum grant_status */ |
| 545 |
XEN_GUEST_HANDLE(uint64_t) frame_list; |
| 546 |
}; |
| 547 |
typedef struct gnttab_get_status_frames gnttab_get_status_frames_t; |
| 548 |
DEFINE_XEN_GUEST_HANDLE(gnttab_get_status_frames_t); |
| 549 |
|
| 550 |
/* |
| 551 |
* GNTTABOP_get_version: Get the grant table version which is in |
| 552 |
* effect for domain <dom>. |
| 553 |
*/ |
| 554 |
struct gnttab_get_version { |
| 555 |
/* IN parameters */ |
| 556 |
domid_t dom; |
| 557 |
uint16_t pad; |
| 558 |
/* OUT parameters */ |
| 559 |
uint32_t version; |
| 560 |
}; |
| 561 |
typedef struct gnttab_get_version gnttab_get_version_t; |
| 562 |
DEFINE_XEN_GUEST_HANDLE(gnttab_get_version_t); |
| 563 |
|
| 564 |
/* |
| 565 |
* GNTTABOP_swap_grant_ref: Swap the contents of two grant entries. |
| 566 |
*/ |
| 567 |
struct gnttab_swap_grant_ref { |
| 568 |
/* IN parameters */ |
| 569 |
grant_ref_t ref_a; |
| 570 |
grant_ref_t ref_b; |
| 571 |
/* OUT parameters */ |
| 572 |
int16_t status; /* => enum grant_status */ |
| 573 |
}; |
| 574 |
typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t; |
| 575 |
DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t); |
| 576 |
|
| 577 |
#endif /* __XEN_INTERFACE_VERSION__ */ |
| 578 |
|
| 579 |
/* |
| 580 |
* Bitfield values for gnttab_map_grant_ref.flags. |
| 581 |
*/ |
| 582 |
/* Map the grant entry for access by I/O devices. */ |
| 583 |
#define _GNTMAP_device_map (0) |
| 584 |
#define GNTMAP_device_map (1<<_GNTMAP_device_map) |
| 585 |
/* Map the grant entry for access by host CPUs. */ |
| 586 |
#define _GNTMAP_host_map (1) |
| 587 |
#define GNTMAP_host_map (1<<_GNTMAP_host_map) |
| 588 |
/* Accesses to the granted frame will be restricted to read-only access. */ |
| 589 |
#define _GNTMAP_readonly (2) |
| 590 |
#define GNTMAP_readonly (1<<_GNTMAP_readonly) |
| 591 |
/* |
| 592 |
* GNTMAP_host_map subflag: |
| 593 |
* 0 => The host mapping is usable only by the guest OS. |
| 594 |
* 1 => The host mapping is usable by guest OS + current application. |
| 595 |
*/ |
| 596 |
#define _GNTMAP_application_map (3) |
| 597 |
#define GNTMAP_application_map (1<<_GNTMAP_application_map) |
| 598 |
|
| 599 |
/* |
| 600 |
* GNTMAP_contains_pte subflag: |
| 601 |
* 0 => This map request contains a host virtual address. |
| 602 |
* 1 => This map request contains the machine addess of the PTE to update. |
| 603 |
*/ |
| 604 |
#define _GNTMAP_contains_pte (4) |
| 605 |
#define GNTMAP_contains_pte (1<<_GNTMAP_contains_pte) |
| 606 |
|
| 607 |
#define _GNTMAP_can_fail (5) |
| 608 |
#define GNTMAP_can_fail (1<<_GNTMAP_can_fail) |
| 609 |
|
| 610 |
/* |
| 611 |
* Bits to be placed in guest kernel available PTE bits (architecture |
| 612 |
* dependent; only supported when XENFEAT_gnttab_map_avail_bits is set). |
| 613 |
*/ |
| 614 |
#define _GNTMAP_guest_avail0 (16) |
| 615 |
#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0) |
| 616 |
|
| 617 |
/* |
| 618 |
* Values for error status returns. All errors are -ve. |
| 619 |
*/ |
| 620 |
/* ` enum grant_status { */ |
| 621 |
#define GNTST_okay (0) /* Normal return. */ |
| 622 |
#define GNTST_general_error (-1) /* General undefined error. */ |
| 623 |
#define GNTST_bad_domain (-2) /* Unrecognsed domain id. */ |
| 624 |
#define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */ |
| 625 |
#define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */ |
| 626 |
#define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */ |
| 627 |
#define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/ |
| 628 |
#define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */ |
| 629 |
#define GNTST_permission_denied (-8) /* Not enough privilege for operation. */ |
| 630 |
#define GNTST_bad_page (-9) /* Specified page was invalid for op. */ |
| 631 |
#define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */ |
| 632 |
#define GNTST_address_too_big (-11) /* transfer page address too large. */ |
| 633 |
#define GNTST_eagain (-12) /* Operation not done; try again. */ |
| 634 |
/* ` } */ |
| 635 |
|
| 636 |
#define GNTTABOP_error_msgs { \ |
| 637 |
"okay", \ |
| 638 |
"undefined error", \ |
| 639 |
"unrecognised domain id", \ |
| 640 |
"invalid grant reference", \ |
| 641 |
"invalid mapping handle", \ |
| 642 |
"invalid virtual address", \ |
| 643 |
"invalid device address", \ |
| 644 |
"no spare translation slot in the I/O MMU", \ |
| 645 |
"permission denied", \ |
| 646 |
"bad page", \ |
| 647 |
"copy arguments cross page boundary", \ |
| 648 |
"page address size too large", \ |
| 649 |
"operation not done; try again" \ |
| 650 |
} |
| 651 |
|
| 652 |
#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ |
| 653 |
|
| 654 |
/* |
| 655 |
* Local variables: |
| 656 |
* mode: C |
| 657 |
* c-file-style: "BSD" |
| 658 |
* c-basic-offset: 4 |
| 659 |
* tab-width: 4 |
| 660 |
* indent-tabs-mode: nil |
| 661 |
* End: |
| 662 |
*/ |