grant_table.h revision 251767
1181624Skmacy/****************************************************************************** 2181624Skmacy * grant_table.h 3251767Sgibbs * 4181624Skmacy * Interface for granting foreign access to page frames, and receiving 5181624Skmacy * page-ownership transfers. 6251767Sgibbs * 7181624Skmacy * Permission is hereby granted, free of charge, to any person obtaining a copy 8181624Skmacy * of this software and associated documentation files (the "Software"), to 9181624Skmacy * deal in the Software without restriction, including without limitation the 10181624Skmacy * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11181624Skmacy * sell copies of the Software, and to permit persons to whom the Software is 12181624Skmacy * furnished to do so, subject to the following conditions: 13181624Skmacy * 14181624Skmacy * The above copyright notice and this permission notice shall be included in 15181624Skmacy * all copies or substantial portions of the Software. 16181624Skmacy * 17181624Skmacy * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18181624Skmacy * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19181624Skmacy * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20181624Skmacy * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21181624Skmacy * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22181624Skmacy * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23181624Skmacy * DEALINGS IN THE SOFTWARE. 24181624Skmacy * 25181624Skmacy * Copyright (c) 2004, K A Fraser 26181624Skmacy */ 27181624Skmacy 28181624Skmacy#ifndef __XEN_PUBLIC_GRANT_TABLE_H__ 29181624Skmacy#define __XEN_PUBLIC_GRANT_TABLE_H__ 30181624Skmacy 31251767Sgibbs#include "xen.h" 32181624Skmacy 33251767Sgibbs/* 34251767Sgibbs * `incontents 150 gnttab Grant Tables 35251767Sgibbs * 36251767Sgibbs * Xen's grant tables provide a generic mechanism to memory sharing 37251767Sgibbs * between domains. This shared memory interface underpins the split 38251767Sgibbs * device drivers for block and network IO. 39251767Sgibbs * 40251767Sgibbs * Each domain has its own grant table. This is a data structure that 41251767Sgibbs * is shared with Xen; it allows the domain to tell Xen what kind of 42251767Sgibbs * permissions other domains have on its pages. Entries in the grant 43251767Sgibbs * table are identified by grant references. A grant reference is an 44251767Sgibbs * integer, which indexes into the grant table. It acts as a 45251767Sgibbs * capability which the grantee can use to perform operations on the 46251767Sgibbs * granter���s memory. 47251767Sgibbs * 48251767Sgibbs * This capability-based system allows shared-memory communications 49251767Sgibbs * between unprivileged domains. A grant reference also encapsulates 50251767Sgibbs * the details of a shared page, removing the need for a domain to 51251767Sgibbs * know the real machine address of a page it is sharing. This makes 52251767Sgibbs * it possible to share memory correctly with domains running in 53251767Sgibbs * fully virtualised memory. 54251767Sgibbs */ 55251767Sgibbs 56181624Skmacy/*********************************** 57181624Skmacy * GRANT TABLE REPRESENTATION 58181624Skmacy */ 59181624Skmacy 60181624Skmacy/* Some rough guidelines on accessing and updating grant-table entries 61181624Skmacy * in a concurrency-safe manner. For more information, Linux contains a 62251767Sgibbs * reference implementation for guest OSes (drivers/xen/grant_table.c, see 63251767Sgibbs * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD 64251767Sgibbs * 65181624Skmacy * NB. WMB is a no-op on current-generation x86 processors. However, a 66181624Skmacy * compiler barrier will still be required. 67251767Sgibbs * 68181624Skmacy * Introducing a valid entry into the grant table: 69181624Skmacy * 1. Write ent->domid. 70181624Skmacy * 2. Write ent->frame: 71181624Skmacy * GTF_permit_access: Frame to which access is permitted. 72181624Skmacy * GTF_accept_transfer: Pseudo-phys frame slot being filled by new 73181624Skmacy * frame, or zero if none. 74181624Skmacy * 3. Write memory barrier (WMB). 75181624Skmacy * 4. Write ent->flags, inc. valid type. 76251767Sgibbs * 77181624Skmacy * Invalidating an unused GTF_permit_access entry: 78181624Skmacy * 1. flags = ent->flags. 79181624Skmacy * 2. Observe that !(flags & (GTF_reading|GTF_writing)). 80181624Skmacy * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0). 81181624Skmacy * NB. No need for WMB as reuse of entry is control-dependent on success of 82181624Skmacy * step 3, and all architectures guarantee ordering of ctrl-dep writes. 83181624Skmacy * 84181624Skmacy * Invalidating an in-use GTF_permit_access entry: 85181624Skmacy * This cannot be done directly. Request assistance from the domain controller 86181624Skmacy * which can set a timeout on the use of a grant entry and take necessary 87181624Skmacy * action. (NB. This is not yet implemented!). 88251767Sgibbs * 89181624Skmacy * Invalidating an unused GTF_accept_transfer entry: 90181624Skmacy * 1. flags = ent->flags. 91181624Skmacy * 2. Observe that !(flags & GTF_transfer_committed). [*] 92181624Skmacy * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0). 93181624Skmacy * NB. No need for WMB as reuse of entry is control-dependent on success of 94181624Skmacy * step 3, and all architectures guarantee ordering of ctrl-dep writes. 95181624Skmacy * [*] If GTF_transfer_committed is set then the grant entry is 'committed'. 96181624Skmacy * The guest must /not/ modify the grant entry until the address of the 97181624Skmacy * transferred frame is written. It is safe for the guest to spin waiting 98181624Skmacy * for this to occur (detect by observing GTF_transfer_completed in 99181624Skmacy * ent->flags). 100181624Skmacy * 101181624Skmacy * Invalidating a committed GTF_accept_transfer entry: 102181624Skmacy * 1. Wait for (ent->flags & GTF_transfer_completed). 103181624Skmacy * 104181624Skmacy * Changing a GTF_permit_access from writable to read-only: 105181624Skmacy * Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing. 106251767Sgibbs * 107181624Skmacy * Changing a GTF_permit_access from read-only to writable: 108181624Skmacy * Use SMP-safe bit-setting instruction. 109181624Skmacy */ 110181624Skmacy 111181624Skmacy/* 112251767Sgibbs * Reference to a grant entry in a specified domain's grant table. 113251767Sgibbs */ 114251767Sgibbstypedef uint32_t grant_ref_t; 115251767Sgibbs 116251767Sgibbs/* 117181624Skmacy * A grant table comprises a packed array of grant entries in one or more 118181624Skmacy * page frames shared between Xen and a guest. 119181624Skmacy * [XEN]: This field is written by Xen and read by the sharing guest. 120181624Skmacy * [GST]: This field is written by the guest and read by Xen. 121181624Skmacy */ 122251767Sgibbs 123251767Sgibbs/* 124251767Sgibbs * Version 1 of the grant table entry structure is maintained purely 125251767Sgibbs * for backwards compatibility. New guests should use version 2. 126251767Sgibbs */ 127251767Sgibbs#if __XEN_INTERFACE_VERSION__ < 0x0003020a 128251767Sgibbs#define grant_entry_v1 grant_entry 129251767Sgibbs#define grant_entry_v1_t grant_entry_t 130251767Sgibbs#endif 131251767Sgibbsstruct grant_entry_v1 { 132181624Skmacy /* GTF_xxx: various type and flag information. [XEN,GST] */ 133181624Skmacy uint16_t flags; 134181624Skmacy /* The domain being granted foreign privileges. [GST] */ 135181624Skmacy domid_t domid; 136181624Skmacy /* 137181624Skmacy * GTF_permit_access: Frame that @domid is allowed to map and access. [GST] 138181624Skmacy * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN] 139181624Skmacy */ 140181624Skmacy uint32_t frame; 141181624Skmacy}; 142251767Sgibbstypedef struct grant_entry_v1 grant_entry_v1_t; 143181624Skmacy 144251767Sgibbs/* The first few grant table entries will be preserved across grant table 145251767Sgibbs * version changes and may be pre-populated at domain creation by tools. 146251767Sgibbs */ 147251767Sgibbs#define GNTTAB_NR_RESERVED_ENTRIES 8 148251767Sgibbs#define GNTTAB_RESERVED_CONSOLE 0 149251767Sgibbs#define GNTTAB_RESERVED_XENSTORE 1 150251767Sgibbs 151181624Skmacy/* 152181624Skmacy * Type of grant entry. 153181624Skmacy * GTF_invalid: This grant entry grants no privileges. 154181624Skmacy * GTF_permit_access: Allow @domid to map/access @frame. 155181624Skmacy * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame 156181624Skmacy * to this guest. Xen writes the page number to @frame. 157251767Sgibbs * GTF_transitive: Allow @domid to transitively access a subrange of 158251767Sgibbs * @trans_grant in @trans_domid. No mappings are allowed. 159181624Skmacy */ 160181624Skmacy#define GTF_invalid (0U<<0) 161181624Skmacy#define GTF_permit_access (1U<<0) 162181624Skmacy#define GTF_accept_transfer (2U<<0) 163251767Sgibbs#define GTF_transitive (3U<<0) 164181624Skmacy#define GTF_type_mask (3U<<0) 165181624Skmacy 166181624Skmacy/* 167181624Skmacy * Subflags for GTF_permit_access. 168181624Skmacy * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST] 169181624Skmacy * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN] 170181624Skmacy * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN] 171183340Skmacy * GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST] 172251767Sgibbs * GTF_sub_page: Grant access to only a subrange of the page. @domid 173251767Sgibbs * will only be allowed to copy from the grant, and not 174251767Sgibbs * map it. [GST] 175181624Skmacy */ 176181624Skmacy#define _GTF_readonly (2) 177181624Skmacy#define GTF_readonly (1U<<_GTF_readonly) 178181624Skmacy#define _GTF_reading (3) 179181624Skmacy#define GTF_reading (1U<<_GTF_reading) 180181624Skmacy#define _GTF_writing (4) 181181624Skmacy#define GTF_writing (1U<<_GTF_writing) 182183340Skmacy#define _GTF_PWT (5) 183183340Skmacy#define GTF_PWT (1U<<_GTF_PWT) 184183340Skmacy#define _GTF_PCD (6) 185183340Skmacy#define GTF_PCD (1U<<_GTF_PCD) 186183340Skmacy#define _GTF_PAT (7) 187183340Skmacy#define GTF_PAT (1U<<_GTF_PAT) 188251767Sgibbs#define _GTF_sub_page (8) 189251767Sgibbs#define GTF_sub_page (1U<<_GTF_sub_page) 190181624Skmacy 191181624Skmacy/* 192181624Skmacy * Subflags for GTF_accept_transfer: 193181624Skmacy * GTF_transfer_committed: Xen sets this flag to indicate that it is committed 194181624Skmacy * to transferring ownership of a page frame. When a guest sees this flag 195181624Skmacy * it must /not/ modify the grant entry until GTF_transfer_completed is 196181624Skmacy * set by Xen. 197181624Skmacy * GTF_transfer_completed: It is safe for the guest to spin-wait on this flag 198181624Skmacy * after reading GTF_transfer_committed. Xen will always write the frame 199181624Skmacy * address, followed by ORing this flag, in a timely manner. 200181624Skmacy */ 201181624Skmacy#define _GTF_transfer_committed (2) 202181624Skmacy#define GTF_transfer_committed (1U<<_GTF_transfer_committed) 203181624Skmacy#define _GTF_transfer_completed (3) 204181624Skmacy#define GTF_transfer_completed (1U<<_GTF_transfer_completed) 205181624Skmacy 206251767Sgibbs/* 207251767Sgibbs * Version 2 grant table entries. These fulfil the same role as 208251767Sgibbs * version 1 entries, but can represent more complicated operations. 209251767Sgibbs * Any given domain will have either a version 1 or a version 2 table, 210251767Sgibbs * and every entry in the table will be the same version. 211251767Sgibbs * 212251767Sgibbs * The interface by which domains use grant references does not depend 213251767Sgibbs * on the grant table version in use by the other domain. 214251767Sgibbs */ 215251767Sgibbs#if __XEN_INTERFACE_VERSION__ >= 0x0003020a 216251767Sgibbs/* 217251767Sgibbs * Version 1 and version 2 grant entries share a common prefix. The 218251767Sgibbs * fields of the prefix are documented as part of struct 219251767Sgibbs * grant_entry_v1. 220251767Sgibbs */ 221251767Sgibbsstruct grant_entry_header { 222251767Sgibbs uint16_t flags; 223251767Sgibbs domid_t domid; 224251767Sgibbs}; 225251767Sgibbstypedef struct grant_entry_header grant_entry_header_t; 226181624Skmacy 227251767Sgibbs/* 228251767Sgibbs * Version 2 of the grant entry structure. 229251767Sgibbs */ 230251767Sgibbsunion grant_entry_v2 { 231251767Sgibbs grant_entry_header_t hdr; 232251767Sgibbs 233251767Sgibbs /* 234251767Sgibbs * This member is used for V1-style full page grants, where either: 235251767Sgibbs * 236251767Sgibbs * -- hdr.type is GTF_accept_transfer, or 237251767Sgibbs * -- hdr.type is GTF_permit_access and GTF_sub_page is not set. 238251767Sgibbs * 239251767Sgibbs * In that case, the frame field has the same semantics as the 240251767Sgibbs * field of the same name in the V1 entry structure. 241251767Sgibbs */ 242251767Sgibbs struct { 243251767Sgibbs grant_entry_header_t hdr; 244251767Sgibbs uint32_t pad0; 245251767Sgibbs uint64_t frame; 246251767Sgibbs } full_page; 247251767Sgibbs 248251767Sgibbs /* 249251767Sgibbs * If the grant type is GTF_grant_access and GTF_sub_page is set, 250251767Sgibbs * @domid is allowed to access bytes [@page_off,@page_off+@length) 251251767Sgibbs * in frame @frame. 252251767Sgibbs */ 253251767Sgibbs struct { 254251767Sgibbs grant_entry_header_t hdr; 255251767Sgibbs uint16_t page_off; 256251767Sgibbs uint16_t length; 257251767Sgibbs uint64_t frame; 258251767Sgibbs } sub_page; 259251767Sgibbs 260251767Sgibbs /* 261251767Sgibbs * If the grant is GTF_transitive, @domid is allowed to use the 262251767Sgibbs * grant @gref in domain @trans_domid, as if it was the local 263251767Sgibbs * domain. Obviously, the transitive access must be compatible 264251767Sgibbs * with the original grant. 265251767Sgibbs * 266251767Sgibbs * The current version of Xen does not allow transitive grants 267251767Sgibbs * to be mapped. 268251767Sgibbs */ 269251767Sgibbs struct { 270251767Sgibbs grant_entry_header_t hdr; 271251767Sgibbs domid_t trans_domid; 272251767Sgibbs uint16_t pad0; 273251767Sgibbs grant_ref_t gref; 274251767Sgibbs } transitive; 275251767Sgibbs 276251767Sgibbs uint32_t __spacer[4]; /* Pad to a power of two */ 277251767Sgibbs}; 278251767Sgibbstypedef union grant_entry_v2 grant_entry_v2_t; 279251767Sgibbs 280251767Sgibbstypedef uint16_t grant_status_t; 281251767Sgibbs 282251767Sgibbs#endif /* __XEN_INTERFACE_VERSION__ */ 283251767Sgibbs 284181624Skmacy/*********************************** 285181624Skmacy * GRANT TABLE QUERIES AND USES 286181624Skmacy */ 287181624Skmacy 288251767Sgibbs/* ` enum neg_errnoval 289251767Sgibbs * ` HYPERVISOR_grant_table_op(enum grant_table_op cmd, 290251767Sgibbs * ` void *args, 291251767Sgibbs * ` unsigned int count) 292251767Sgibbs * ` 293251767Sgibbs * 294251767Sgibbs * @args points to an array of a per-command data structure. The array 295251767Sgibbs * has @count members 296181624Skmacy */ 297181624Skmacy 298251767Sgibbs/* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */ 299251767Sgibbs#define GNTTABOP_map_grant_ref 0 300251767Sgibbs#define GNTTABOP_unmap_grant_ref 1 301251767Sgibbs#define GNTTABOP_setup_table 2 302251767Sgibbs#define GNTTABOP_dump_table 3 303251767Sgibbs#define GNTTABOP_transfer 4 304251767Sgibbs#define GNTTABOP_copy 5 305251767Sgibbs#define GNTTABOP_query_size 6 306251767Sgibbs#define GNTTABOP_unmap_and_replace 7 307251767Sgibbs#if __XEN_INTERFACE_VERSION__ >= 0x0003020a 308251767Sgibbs#define GNTTABOP_set_version 8 309251767Sgibbs#define GNTTABOP_get_status_frames 9 310251767Sgibbs#define GNTTABOP_get_version 10 311251767Sgibbs#define GNTTABOP_swap_grant_ref 11 312251767Sgibbs#endif /* __XEN_INTERFACE_VERSION__ */ 313251767Sgibbs/* ` } */ 314214077Sgibbs 315181624Skmacy/* 316181624Skmacy * Handle to track a mapping created via a grant reference. 317181624Skmacy */ 318181624Skmacytypedef uint32_t grant_handle_t; 319181624Skmacy 320181624Skmacy/* 321181624Skmacy * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access 322181624Skmacy * by devices and/or host CPUs. If successful, <handle> is a tracking number 323181624Skmacy * that must be presented later to destroy the mapping(s). On error, <handle> 324181624Skmacy * is a negative status code. 325181624Skmacy * NOTES: 326181624Skmacy * 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address 327181624Skmacy * via which I/O devices may access the granted frame. 328181624Skmacy * 2. If GNTMAP_host_map is specified then a mapping will be added at 329181624Skmacy * either a host virtual address in the current address space, or at 330181624Skmacy * a PTE at the specified machine address. The type of mapping to 331251767Sgibbs * perform is selected through the GNTMAP_contains_pte flag, and the 332181624Skmacy * address is specified in <host_addr>. 333181624Skmacy * 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a 334181624Skmacy * host mapping is destroyed by other means then it is *NOT* guaranteed 335181624Skmacy * to be accounted to the correct grant reference! 336181624Skmacy */ 337181624Skmacystruct gnttab_map_grant_ref { 338181624Skmacy /* IN parameters. */ 339181624Skmacy uint64_t host_addr; 340181624Skmacy uint32_t flags; /* GNTMAP_* */ 341181624Skmacy grant_ref_t ref; 342181624Skmacy domid_t dom; 343181624Skmacy /* OUT parameters. */ 344251767Sgibbs int16_t status; /* => enum grant_status */ 345181624Skmacy grant_handle_t handle; 346181624Skmacy uint64_t dev_bus_addr; 347181624Skmacy}; 348181624Skmacytypedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t; 349181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t); 350181624Skmacy 351181624Skmacy/* 352181624Skmacy * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings 353181624Skmacy * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that 354181624Skmacy * field is ignored. If non-zero, they must refer to a device/host mapping 355181624Skmacy * that is tracked by <handle> 356181624Skmacy * NOTES: 357181624Skmacy * 1. The call may fail in an undefined manner if either mapping is not 358181624Skmacy * tracked by <handle>. 359181624Skmacy * 3. After executing a batch of unmaps, it is guaranteed that no stale 360181624Skmacy * mappings will remain in the device or host TLBs. 361181624Skmacy */ 362181624Skmacystruct gnttab_unmap_grant_ref { 363181624Skmacy /* IN parameters. */ 364181624Skmacy uint64_t host_addr; 365181624Skmacy uint64_t dev_bus_addr; 366181624Skmacy grant_handle_t handle; 367181624Skmacy /* OUT parameters. */ 368251767Sgibbs int16_t status; /* => enum grant_status */ 369181624Skmacy}; 370181624Skmacytypedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t; 371181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t); 372181624Skmacy 373181624Skmacy/* 374181624Skmacy * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least 375181624Skmacy * <nr_frames> pages. The frame addresses are written to the <frame_list>. 376181624Skmacy * Only <nr_frames> addresses are written, even if the table is larger. 377181624Skmacy * NOTES: 378181624Skmacy * 1. <dom> may be specified as DOMID_SELF. 379181624Skmacy * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. 380181624Skmacy * 3. Xen may not support more than a single grant-table page per domain. 381181624Skmacy */ 382181624Skmacystruct gnttab_setup_table { 383181624Skmacy /* IN parameters. */ 384181624Skmacy domid_t dom; 385181624Skmacy uint32_t nr_frames; 386181624Skmacy /* OUT parameters. */ 387251767Sgibbs int16_t status; /* => enum grant_status */ 388183375Skmacy XEN_GUEST_HANDLE(ulong) frame_list; 389181624Skmacy}; 390181624Skmacytypedef struct gnttab_setup_table gnttab_setup_table_t; 391181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t); 392181624Skmacy 393181624Skmacy/* 394181624Skmacy * GNTTABOP_dump_table: Dump the contents of the grant table to the 395181624Skmacy * xen console. Debugging use only. 396181624Skmacy */ 397181624Skmacystruct gnttab_dump_table { 398181624Skmacy /* IN parameters. */ 399181624Skmacy domid_t dom; 400181624Skmacy /* OUT parameters. */ 401251767Sgibbs int16_t status; /* => enum grant_status */ 402181624Skmacy}; 403181624Skmacytypedef struct gnttab_dump_table gnttab_dump_table_t; 404181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t); 405181624Skmacy 406181624Skmacy/* 407181624Skmacy * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The 408181624Skmacy * foreign domain has previously registered its interest in the transfer via 409181624Skmacy * <domid, ref>. 410251767Sgibbs * 411181624Skmacy * Note that, even if the transfer fails, the specified page no longer belongs 412181624Skmacy * to the calling domain *unless* the error is GNTST_bad_page. 413181624Skmacy */ 414181624Skmacystruct gnttab_transfer { 415181624Skmacy /* IN parameters. */ 416181624Skmacy xen_pfn_t mfn; 417181624Skmacy domid_t domid; 418181624Skmacy grant_ref_t ref; 419181624Skmacy /* OUT parameters. */ 420181624Skmacy int16_t status; 421181624Skmacy}; 422181624Skmacytypedef struct gnttab_transfer gnttab_transfer_t; 423181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t); 424181624Skmacy 425181624Skmacy 426181624Skmacy/* 427181624Skmacy * GNTTABOP_copy: Hypervisor based copy 428181624Skmacy * source and destinations can be eithers MFNs or, for foreign domains, 429181624Skmacy * grant references. the foreign domain has to grant read/write access 430181624Skmacy * in its grant table. 431181624Skmacy * 432181624Skmacy * The flags specify what type source and destinations are (either MFN 433181624Skmacy * or grant reference). 434181624Skmacy * 435181624Skmacy * Note that this can also be used to copy data between two domains 436181624Skmacy * via a third party if the source and destination domains had previously 437181624Skmacy * grant appropriate access to their pages to the third party. 438181624Skmacy * 439181624Skmacy * source_offset specifies an offset in the source frame, dest_offset 440181624Skmacy * the offset in the target frame and len specifies the number of 441181624Skmacy * bytes to be copied. 442181624Skmacy */ 443181624Skmacy 444181624Skmacy#define _GNTCOPY_source_gref (0) 445181624Skmacy#define GNTCOPY_source_gref (1<<_GNTCOPY_source_gref) 446181624Skmacy#define _GNTCOPY_dest_gref (1) 447181624Skmacy#define GNTCOPY_dest_gref (1<<_GNTCOPY_dest_gref) 448251767Sgibbs#define _GNTCOPY_can_fail (2) 449251767Sgibbs#define GNTCOPY_can_fail (1<<_GNTCOPY_can_fail) 450181624Skmacy 451251767Sgibbsstruct gnttab_copy { 452181624Skmacy /* IN parameters. */ 453181624Skmacy struct { 454181624Skmacy union { 455181624Skmacy grant_ref_t ref; 456181624Skmacy xen_pfn_t gmfn; 457181624Skmacy } u; 458181624Skmacy domid_t domid; 459181624Skmacy uint16_t offset; 460181624Skmacy } source, dest; 461181624Skmacy uint16_t len; 462181624Skmacy uint16_t flags; /* GNTCOPY_* */ 463181624Skmacy /* OUT parameters. */ 464181624Skmacy int16_t status; 465251767Sgibbs}; 466251767Sgibbstypedef struct gnttab_copy gnttab_copy_t; 467181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_copy_t); 468181624Skmacy 469181624Skmacy/* 470181624Skmacy * GNTTABOP_query_size: Query the current and maximum sizes of the shared 471181624Skmacy * grant table. 472181624Skmacy * NOTES: 473181624Skmacy * 1. <dom> may be specified as DOMID_SELF. 474181624Skmacy * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. 475181624Skmacy */ 476181624Skmacystruct gnttab_query_size { 477181624Skmacy /* IN parameters. */ 478181624Skmacy domid_t dom; 479181624Skmacy /* OUT parameters. */ 480181624Skmacy uint32_t nr_frames; 481181624Skmacy uint32_t max_nr_frames; 482251767Sgibbs int16_t status; /* => enum grant_status */ 483181624Skmacy}; 484181624Skmacytypedef struct gnttab_query_size gnttab_query_size_t; 485181624SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t); 486181624Skmacy 487183340Skmacy/* 488183340Skmacy * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings 489183340Skmacy * tracked by <handle> but atomically replace the page table entry with one 490183340Skmacy * pointing to the machine address under <new_addr>. <new_addr> will be 491183340Skmacy * redirected to the null entry. 492183340Skmacy * NOTES: 493183340Skmacy * 1. The call may fail in an undefined manner if either mapping is not 494183340Skmacy * tracked by <handle>. 495183340Skmacy * 2. After executing a batch of unmaps, it is guaranteed that no stale 496183340Skmacy * mappings will remain in the device or host TLBs. 497183340Skmacy */ 498183340Skmacystruct gnttab_unmap_and_replace { 499183340Skmacy /* IN parameters. */ 500183340Skmacy uint64_t host_addr; 501183340Skmacy uint64_t new_addr; 502183340Skmacy grant_handle_t handle; 503183340Skmacy /* OUT parameters. */ 504251767Sgibbs int16_t status; /* => enum grant_status */ 505183340Skmacy}; 506183340Skmacytypedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t; 507183340SkmacyDEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t); 508181624Skmacy 509251767Sgibbs#if __XEN_INTERFACE_VERSION__ >= 0x0003020a 510251767Sgibbs/* 511251767Sgibbs * GNTTABOP_set_version: Request a particular version of the grant 512251767Sgibbs * table shared table structure. This operation can only be performed 513251767Sgibbs * once in any given domain. It must be performed before any grants 514251767Sgibbs * are activated; otherwise, the domain will be stuck with version 1. 515251767Sgibbs * The only defined versions are 1 and 2. 516251767Sgibbs */ 517251767Sgibbsstruct gnttab_set_version { 518251767Sgibbs /* IN/OUT parameters */ 519251767Sgibbs uint32_t version; 520251767Sgibbs}; 521251767Sgibbstypedef struct gnttab_set_version gnttab_set_version_t; 522251767SgibbsDEFINE_XEN_GUEST_HANDLE(gnttab_set_version_t); 523183340Skmacy 524251767Sgibbs 525181624Skmacy/* 526251767Sgibbs * GNTTABOP_get_status_frames: Get the list of frames used to store grant 527251767Sgibbs * status for <dom>. In grant format version 2, the status is separated 528251767Sgibbs * from the other shared grant fields to allow more efficient synchronization 529251767Sgibbs * using barriers instead of atomic cmpexch operations. 530251767Sgibbs * <nr_frames> specify the size of vector <frame_list>. 531251767Sgibbs * The frame addresses are returned in the <frame_list>. 532251767Sgibbs * Only <nr_frames> addresses are returned, even if the table is larger. 533251767Sgibbs * NOTES: 534251767Sgibbs * 1. <dom> may be specified as DOMID_SELF. 535251767Sgibbs * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF. 536181624Skmacy */ 537251767Sgibbsstruct gnttab_get_status_frames { 538251767Sgibbs /* IN parameters. */ 539251767Sgibbs uint32_t nr_frames; 540251767Sgibbs domid_t dom; 541251767Sgibbs /* OUT parameters. */ 542251767Sgibbs int16_t status; /* => enum grant_status */ 543251767Sgibbs XEN_GUEST_HANDLE(uint64_t) frame_list; 544251767Sgibbs}; 545251767Sgibbstypedef struct gnttab_get_status_frames gnttab_get_status_frames_t; 546251767SgibbsDEFINE_XEN_GUEST_HANDLE(gnttab_get_status_frames_t); 547251767Sgibbs 548251767Sgibbs/* 549251767Sgibbs * GNTTABOP_get_version: Get the grant table version which is in 550251767Sgibbs * effect for domain <dom>. 551251767Sgibbs */ 552251767Sgibbsstruct gnttab_get_version { 553251767Sgibbs /* IN parameters */ 554251767Sgibbs domid_t dom; 555251767Sgibbs uint16_t pad; 556251767Sgibbs /* OUT parameters */ 557251767Sgibbs uint32_t version; 558251767Sgibbs}; 559251767Sgibbstypedef struct gnttab_get_version gnttab_get_version_t; 560251767SgibbsDEFINE_XEN_GUEST_HANDLE(gnttab_get_version_t); 561251767Sgibbs 562251767Sgibbs/* 563251767Sgibbs * GNTTABOP_swap_grant_ref: Swap the contents of two grant entries. 564251767Sgibbs */ 565251767Sgibbsstruct gnttab_swap_grant_ref { 566251767Sgibbs /* IN parameters */ 567251767Sgibbs grant_ref_t ref_a; 568251767Sgibbs grant_ref_t ref_b; 569251767Sgibbs /* OUT parameters */ 570251767Sgibbs int16_t status; /* => enum grant_status */ 571251767Sgibbs}; 572251767Sgibbstypedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t; 573251767SgibbsDEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t); 574251767Sgibbs 575251767Sgibbs#endif /* __XEN_INTERFACE_VERSION__ */ 576251767Sgibbs 577251767Sgibbs/* 578251767Sgibbs * Bitfield values for gnttab_map_grant_ref.flags. 579251767Sgibbs */ 580181624Skmacy /* Map the grant entry for access by I/O devices. */ 581181624Skmacy#define _GNTMAP_device_map (0) 582181624Skmacy#define GNTMAP_device_map (1<<_GNTMAP_device_map) 583181624Skmacy /* Map the grant entry for access by host CPUs. */ 584181624Skmacy#define _GNTMAP_host_map (1) 585181624Skmacy#define GNTMAP_host_map (1<<_GNTMAP_host_map) 586181624Skmacy /* Accesses to the granted frame will be restricted to read-only access. */ 587181624Skmacy#define _GNTMAP_readonly (2) 588181624Skmacy#define GNTMAP_readonly (1<<_GNTMAP_readonly) 589181624Skmacy /* 590181624Skmacy * GNTMAP_host_map subflag: 591181624Skmacy * 0 => The host mapping is usable only by the guest OS. 592181624Skmacy * 1 => The host mapping is usable by guest OS + current application. 593181624Skmacy */ 594181624Skmacy#define _GNTMAP_application_map (3) 595181624Skmacy#define GNTMAP_application_map (1<<_GNTMAP_application_map) 596181624Skmacy 597181624Skmacy /* 598181624Skmacy * GNTMAP_contains_pte subflag: 599181624Skmacy * 0 => This map request contains a host virtual address. 600181624Skmacy * 1 => This map request contains the machine addess of the PTE to update. 601181624Skmacy */ 602181624Skmacy#define _GNTMAP_contains_pte (4) 603181624Skmacy#define GNTMAP_contains_pte (1<<_GNTMAP_contains_pte) 604181624Skmacy 605251767Sgibbs#define _GNTMAP_can_fail (5) 606251767Sgibbs#define GNTMAP_can_fail (1<<_GNTMAP_can_fail) 607251767Sgibbs 608181624Skmacy/* 609251767Sgibbs * Bits to be placed in guest kernel available PTE bits (architecture 610251767Sgibbs * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set). 611251767Sgibbs */ 612251767Sgibbs#define _GNTMAP_guest_avail0 (16) 613251767Sgibbs#define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0) 614251767Sgibbs 615251767Sgibbs/* 616181624Skmacy * Values for error status returns. All errors are -ve. 617181624Skmacy */ 618251767Sgibbs/* ` enum grant_status { */ 619181624Skmacy#define GNTST_okay (0) /* Normal return. */ 620181624Skmacy#define GNTST_general_error (-1) /* General undefined error. */ 621181624Skmacy#define GNTST_bad_domain (-2) /* Unrecognsed domain id. */ 622181624Skmacy#define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */ 623181624Skmacy#define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */ 624181624Skmacy#define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */ 625181624Skmacy#define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/ 626181624Skmacy#define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */ 627181624Skmacy#define GNTST_permission_denied (-8) /* Not enough privilege for operation. */ 628181624Skmacy#define GNTST_bad_page (-9) /* Specified page was invalid for op. */ 629181624Skmacy#define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */ 630181624Skmacy#define GNTST_address_too_big (-11) /* transfer page address too large. */ 631251767Sgibbs#define GNTST_eagain (-12) /* Operation not done; try again. */ 632251767Sgibbs/* ` } */ 633181624Skmacy 634181624Skmacy#define GNTTABOP_error_msgs { \ 635181624Skmacy "okay", \ 636181624Skmacy "undefined error", \ 637181624Skmacy "unrecognised domain id", \ 638181624Skmacy "invalid grant reference", \ 639181624Skmacy "invalid mapping handle", \ 640181624Skmacy "invalid virtual address", \ 641181624Skmacy "invalid device address", \ 642181624Skmacy "no spare translation slot in the I/O MMU", \ 643181624Skmacy "permission denied", \ 644181624Skmacy "bad page", \ 645181624Skmacy "copy arguments cross page boundary", \ 646251767Sgibbs "page address size too large", \ 647251767Sgibbs "operation not done; try again" \ 648181624Skmacy} 649181624Skmacy 650181624Skmacy#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */ 651181624Skmacy 652181624Skmacy/* 653181624Skmacy * Local variables: 654181624Skmacy * mode: C 655181624Skmacy * c-set-style: "BSD" 656181624Skmacy * c-basic-offset: 4 657181624Skmacy * tab-width: 4 658181624Skmacy * indent-tabs-mode: nil 659181624Skmacy * End: 660181624Skmacy */ 661