iPXE
grant_table.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * grant_table.h
00003  *
00004  * Interface for granting foreign access to page frames, and receiving
00005  * page-ownership transfers.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to
00009  * deal in the Software without restriction, including without limitation the
00010  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00011  * sell copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00023  * DEALINGS IN THE SOFTWARE.
00024  *
00025  * Copyright (c) 2004, K A Fraser
00026  */
00027 
00028 #ifndef __XEN_PUBLIC_GRANT_TABLE_H__
00029 #define __XEN_PUBLIC_GRANT_TABLE_H__
00030 
00031 FILE_LICENCE ( MIT );
00032 
00033 #include "xen.h"
00034 
00035 /*
00036  * `incontents 150 gnttab Grant Tables
00037  *
00038  * Xen's grant tables provide a generic mechanism to memory sharing
00039  * between domains. This shared memory interface underpins the split
00040  * device drivers for block and network IO.
00041  *
00042  * Each domain has its own grant table. This is a data structure that
00043  * is shared with Xen; it allows the domain to tell Xen what kind of
00044  * permissions other domains have on its pages. Entries in the grant
00045  * table are identified by grant references. A grant reference is an
00046  * integer, which indexes into the grant table. It acts as a
00047  * capability which the grantee can use to perform operations on the
00048  * granter’s memory.
00049  *
00050  * This capability-based system allows shared-memory communications
00051  * between unprivileged domains. A grant reference also encapsulates
00052  * the details of a shared page, removing the need for a domain to
00053  * know the real machine address of a page it is sharing. This makes
00054  * it possible to share memory correctly with domains running in
00055  * fully virtualised memory.
00056  */
00057 
00058 /***********************************
00059  * GRANT TABLE REPRESENTATION
00060  */
00061 
00062 /* Some rough guidelines on accessing and updating grant-table entries
00063  * in a concurrency-safe manner. For more information, Linux contains a
00064  * reference implementation for guest OSes (drivers/xen/grant_table.c, see
00065  * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=drivers/xen/grant-table.c;hb=HEAD
00066  *
00067  * NB. WMB is a no-op on current-generation x86 processors. However, a
00068  *     compiler barrier will still be required.
00069  *
00070  * Introducing a valid entry into the grant table:
00071  *  1. Write ent->domid.
00072  *  2. Write ent->frame:
00073  *      GTF_permit_access:   Frame to which access is permitted.
00074  *      GTF_accept_transfer: Pseudo-phys frame slot being filled by new
00075  *                           frame, or zero if none.
00076  *  3. Write memory barrier (WMB).
00077  *  4. Write ent->flags, inc. valid type.
00078  *
00079  * Invalidating an unused GTF_permit_access entry:
00080  *  1. flags = ent->flags.
00081  *  2. Observe that !(flags & (GTF_reading|GTF_writing)).
00082  *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
00083  *  NB. No need for WMB as reuse of entry is control-dependent on success of
00084  *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
00085  *
00086  * Invalidating an in-use GTF_permit_access entry:
00087  *  This cannot be done directly. Request assistance from the domain controller
00088  *  which can set a timeout on the use of a grant entry and take necessary
00089  *  action. (NB. This is not yet implemented!).
00090  *
00091  * Invalidating an unused GTF_accept_transfer entry:
00092  *  1. flags = ent->flags.
00093  *  2. Observe that !(flags & GTF_transfer_committed). [*]
00094  *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
00095  *  NB. No need for WMB as reuse of entry is control-dependent on success of
00096  *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
00097  *  [*] If GTF_transfer_committed is set then the grant entry is 'committed'.
00098  *      The guest must /not/ modify the grant entry until the address of the
00099  *      transferred frame is written. It is safe for the guest to spin waiting
00100  *      for this to occur (detect by observing GTF_transfer_completed in
00101  *      ent->flags).
00102  *
00103  * Invalidating a committed GTF_accept_transfer entry:
00104  *  1. Wait for (ent->flags & GTF_transfer_completed).
00105  *
00106  * Changing a GTF_permit_access from writable to read-only:
00107  *  Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
00108  *
00109  * Changing a GTF_permit_access from read-only to writable:
00110  *  Use SMP-safe bit-setting instruction.
00111  */
00112 
00113 /*
00114  * Reference to a grant entry in a specified domain's grant table.
00115  */
00116 typedef uint32_t grant_ref_t;
00117 
00118 /*
00119  * A grant table comprises a packed array of grant entries in one or more
00120  * page frames shared between Xen and a guest.
00121  * [XEN]: This field is written by Xen and read by the sharing guest.
00122  * [GST]: This field is written by the guest and read by Xen.
00123  */
00124 
00125 /*
00126  * Version 1 of the grant table entry structure is maintained purely
00127  * for backwards compatibility.  New guests should use version 2.
00128  */
00129 #if __XEN_INTERFACE_VERSION__ < 0x0003020a
00130 #define grant_entry_v1 grant_entry
00131 #define grant_entry_v1_t grant_entry_t
00132 #endif
00133 struct grant_entry_v1 {
00134     /* GTF_xxx: various type and flag information.  [XEN,GST] */
00135     uint16_t flags;
00136     /* The domain being granted foreign privileges. [GST] */
00137     domid_t  domid;
00138     /*
00139      * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
00140      * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
00141      */
00142     uint32_t frame;
00143 };
00144 typedef struct grant_entry_v1 grant_entry_v1_t;
00145 
00146 /* The first few grant table entries will be preserved across grant table
00147  * version changes and may be pre-populated at domain creation by tools.
00148  */
00149 #define GNTTAB_NR_RESERVED_ENTRIES     8
00150 #define GNTTAB_RESERVED_CONSOLE        0
00151 #define GNTTAB_RESERVED_XENSTORE       1
00152 
00153 /*
00154  * Type of grant entry.
00155  *  GTF_invalid: This grant entry grants no privileges.
00156  *  GTF_permit_access: Allow @domid to map/access @frame.
00157  *  GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
00158  *                       to this guest. Xen writes the page number to @frame.
00159  *  GTF_transitive: Allow @domid to transitively access a subrange of
00160  *                  @trans_grant in @trans_domid.  No mappings are allowed.
00161  */
00162 #define GTF_invalid         (0U<<0)
00163 #define GTF_permit_access   (1U<<0)
00164 #define GTF_accept_transfer (2U<<0)
00165 #define GTF_transitive      (3U<<0)
00166 #define GTF_type_mask       (3U<<0)
00167 
00168 /*
00169  * Subflags for GTF_permit_access.
00170  *  GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
00171  *  GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
00172  *  GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
00173  *  GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
00174  *  GTF_sub_page: Grant access to only a subrange of the page.  @domid
00175  *                will only be allowed to copy from the grant, and not
00176  *                map it. [GST]
00177  */
00178 #define _GTF_readonly       (2)
00179 #define GTF_readonly        (1U<<_GTF_readonly)
00180 #define _GTF_reading        (3)
00181 #define GTF_reading         (1U<<_GTF_reading)
00182 #define _GTF_writing        (4)
00183 #define GTF_writing         (1U<<_GTF_writing)
00184 #define _GTF_PWT            (5)
00185 #define GTF_PWT             (1U<<_GTF_PWT)
00186 #define _GTF_PCD            (6)
00187 #define GTF_PCD             (1U<<_GTF_PCD)
00188 #define _GTF_PAT            (7)
00189 #define GTF_PAT             (1U<<_GTF_PAT)
00190 #define _GTF_sub_page       (8)
00191 #define GTF_sub_page        (1U<<_GTF_sub_page)
00192 
00193 /*
00194  * Subflags for GTF_accept_transfer:
00195  *  GTF_transfer_committed: Xen sets this flag to indicate that it is committed
00196  *      to transferring ownership of a page frame. When a guest sees this flag
00197  *      it must /not/ modify the grant entry until GTF_transfer_completed is
00198  *      set by Xen.
00199  *  GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
00200  *      after reading GTF_transfer_committed. Xen will always write the frame
00201  *      address, followed by ORing this flag, in a timely manner.
00202  */
00203 #define _GTF_transfer_committed (2)
00204 #define GTF_transfer_committed  (1U<<_GTF_transfer_committed)
00205 #define _GTF_transfer_completed (3)
00206 #define GTF_transfer_completed  (1U<<_GTF_transfer_completed)
00207 
00208 /*
00209  * Version 2 grant table entries.  These fulfil the same role as
00210  * version 1 entries, but can represent more complicated operations.
00211  * Any given domain will have either a version 1 or a version 2 table,
00212  * and every entry in the table will be the same version.
00213  *
00214  * The interface by which domains use grant references does not depend
00215  * on the grant table version in use by the other domain.
00216  */
00217 #if __XEN_INTERFACE_VERSION__ >= 0x0003020a
00218 /*
00219  * Version 1 and version 2 grant entries share a common prefix.  The
00220  * fields of the prefix are documented as part of struct
00221  * grant_entry_v1.
00222  */
00223 struct grant_entry_header {
00224     uint16_t flags;
00225     domid_t  domid;
00226 };
00227 typedef struct grant_entry_header grant_entry_header_t;
00228 
00229 /*
00230  * Version 2 of the grant entry structure.
00231  */
00232 union grant_entry_v2 {
00233     grant_entry_header_t hdr;
00234 
00235     /*
00236      * This member is used for V1-style full page grants, where either:
00237      *
00238      * -- hdr.type is GTF_accept_transfer, or
00239      * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
00240      *
00241      * In that case, the frame field has the same semantics as the
00242      * field of the same name in the V1 entry structure.
00243      */
00244     struct {
00245         grant_entry_header_t hdr;
00246         uint32_t pad0;
00247         uint64_t frame;
00248     } full_page;
00249 
00250     /*
00251      * If the grant type is GTF_grant_access and GTF_sub_page is set,
00252      * @domid is allowed to access bytes [@page_off,@page_off+@length)
00253      * in frame @frame.
00254      */
00255     struct {
00256         grant_entry_header_t hdr;
00257         uint16_t page_off;
00258         uint16_t length;
00259         uint64_t frame;
00260     } sub_page;
00261 
00262     /*
00263      * If the grant is GTF_transitive, @domid is allowed to use the
00264      * grant @gref in domain @trans_domid, as if it was the local
00265      * domain.  Obviously, the transitive access must be compatible
00266      * with the original grant.
00267      *
00268      * The current version of Xen does not allow transitive grants
00269      * to be mapped.
00270      */
00271     struct {
00272         grant_entry_header_t hdr;
00273         domid_t trans_domid;
00274         uint16_t pad0;
00275         grant_ref_t gref;
00276     } transitive;
00277 
00278     uint32_t __spacer[4]; /* Pad to a power of two */
00279 };
00280 typedef union grant_entry_v2 grant_entry_v2_t;
00281 
00282 typedef uint16_t grant_status_t;
00283 
00284 #endif /* __XEN_INTERFACE_VERSION__ */
00285 
00286 /***********************************
00287  * GRANT TABLE QUERIES AND USES
00288  */
00289 
00290 /* ` enum neg_errnoval
00291  * ` HYPERVISOR_grant_table_op(enum grant_table_op cmd,
00292  * `                           void *args,
00293  * `                           unsigned int count)
00294  * `
00295  *
00296  * @args points to an array of a per-command data structure. The array
00297  * has @count members
00298  */
00299 
00300 /* ` enum grant_table_op { // GNTTABOP_* => struct gnttab_* */
00301 #define GNTTABOP_map_grant_ref        0
00302 #define GNTTABOP_unmap_grant_ref      1
00303 #define GNTTABOP_setup_table          2
00304 #define GNTTABOP_dump_table           3
00305 #define GNTTABOP_transfer             4
00306 #define GNTTABOP_copy                 5
00307 #define GNTTABOP_query_size           6
00308 #define GNTTABOP_unmap_and_replace    7
00309 #if __XEN_INTERFACE_VERSION__ >= 0x0003020a
00310 #define GNTTABOP_set_version          8
00311 #define GNTTABOP_get_status_frames    9
00312 #define GNTTABOP_get_version          10
00313 #define GNTTABOP_swap_grant_ref       11
00314 #endif /* __XEN_INTERFACE_VERSION__ */
00315 /* ` } */
00316 
00317 /*
00318  * Handle to track a mapping created via a grant reference.
00319  */
00320 typedef uint32_t grant_handle_t;
00321 
00322 /*
00323  * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
00324  * by devices and/or host CPUs. If successful, <handle> is a tracking number
00325  * that must be presented later to destroy the mapping(s). On error, <handle>
00326  * is a negative status code.
00327  * NOTES:
00328  *  1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
00329  *     via which I/O devices may access the granted frame.
00330  *  2. If GNTMAP_host_map is specified then a mapping will be added at
00331  *     either a host virtual address in the current address space, or at
00332  *     a PTE at the specified machine address.  The type of mapping to
00333  *     perform is selected through the GNTMAP_contains_pte flag, and the
00334  *     address is specified in <host_addr>.
00335  *  3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
00336  *     host mapping is destroyed by other means then it is *NOT* guaranteed
00337  *     to be accounted to the correct grant reference!
00338  */
00339 struct gnttab_map_grant_ref {
00340     /* IN parameters. */
00341     uint64_t host_addr;
00342     uint32_t flags;               /* GNTMAP_* */
00343     grant_ref_t ref;
00344     domid_t  dom;
00345     /* OUT parameters. */
00346     int16_t  status;              /* => enum grant_status */
00347     grant_handle_t handle;
00348     uint64_t dev_bus_addr;
00349 };
00350 typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t;
00351 DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t);
00352 
00353 /*
00354  * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
00355  * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
00356  * field is ignored. If non-zero, they must refer to a device/host mapping
00357  * that is tracked by <handle>
00358  * NOTES:
00359  *  1. The call may fail in an undefined manner if either mapping is not
00360  *     tracked by <handle>.
00361  *  3. After executing a batch of unmaps, it is guaranteed that no stale
00362  *     mappings will remain in the device or host TLBs.
00363  */
00364 struct gnttab_unmap_grant_ref {
00365     /* IN parameters. */
00366     uint64_t host_addr;
00367     uint64_t dev_bus_addr;
00368     grant_handle_t handle;
00369     /* OUT parameters. */
00370     int16_t  status;              /* => enum grant_status */
00371 };
00372 typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t;
00373 DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t);
00374 
00375 /*
00376  * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
00377  * <nr_frames> pages. The frame addresses are written to the <frame_list>.
00378  * Only <nr_frames> addresses are written, even if the table is larger.
00379  * NOTES:
00380  *  1. <dom> may be specified as DOMID_SELF.
00381  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
00382  *  3. Xen may not support more than a single grant-table page per domain.
00383  */
00384 struct gnttab_setup_table {
00385     /* IN parameters. */
00386     domid_t  dom;
00387     uint32_t nr_frames;
00388     /* OUT parameters. */
00389     int16_t  status;              /* => enum grant_status */
00390 #if __XEN_INTERFACE_VERSION__ < 0x00040300
00391     XEN_GUEST_HANDLE(ulong) frame_list;
00392 #else
00393     XEN_GUEST_HANDLE(xen_pfn_t) frame_list;
00394 #endif
00395 };
00396 typedef struct gnttab_setup_table gnttab_setup_table_t;
00397 DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t);
00398 
00399 /*
00400  * GNTTABOP_dump_table: Dump the contents of the grant table to the
00401  * xen console. Debugging use only.
00402  */
00403 struct gnttab_dump_table {
00404     /* IN parameters. */
00405     domid_t dom;
00406     /* OUT parameters. */
00407     int16_t status;               /* => enum grant_status */
00408 };
00409 typedef struct gnttab_dump_table gnttab_dump_table_t;
00410 DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t);
00411 
00412 /*
00413  * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The
00414  * foreign domain has previously registered its interest in the transfer via
00415  * <domid, ref>.
00416  *
00417  * Note that, even if the transfer fails, the specified page no longer belongs
00418  * to the calling domain *unless* the error is GNTST_bad_page.
00419  */
00420 struct gnttab_transfer {
00421     /* IN parameters. */
00422     xen_pfn_t     mfn;
00423     domid_t       domid;
00424     grant_ref_t   ref;
00425     /* OUT parameters. */
00426     int16_t       status;
00427 };
00428 typedef struct gnttab_transfer gnttab_transfer_t;
00429 DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t);
00430 
00431 
00432 /*
00433  * GNTTABOP_copy: Hypervisor based copy
00434  * source and destinations can be eithers MFNs or, for foreign domains,
00435  * grant references. the foreign domain has to grant read/write access
00436  * in its grant table.
00437  *
00438  * The flags specify what type source and destinations are (either MFN
00439  * or grant reference).
00440  *
00441  * Note that this can also be used to copy data between two domains
00442  * via a third party if the source and destination domains had previously
00443  * grant appropriate access to their pages to the third party.
00444  *
00445  * source_offset specifies an offset in the source frame, dest_offset
00446  * the offset in the target frame and  len specifies the number of
00447  * bytes to be copied.
00448  */
00449 
00450 #define _GNTCOPY_source_gref      (0)
00451 #define GNTCOPY_source_gref       (1<<_GNTCOPY_source_gref)
00452 #define _GNTCOPY_dest_gref        (1)
00453 #define GNTCOPY_dest_gref         (1<<_GNTCOPY_dest_gref)
00454 
00455 struct gnttab_copy {
00456     /* IN parameters. */
00457     struct {
00458         union {
00459             grant_ref_t ref;
00460             xen_pfn_t   gmfn;
00461         } u;
00462         domid_t  domid;
00463         uint16_t offset;
00464     } source, dest;
00465     uint16_t      len;
00466     uint16_t      flags;          /* GNTCOPY_* */
00467     /* OUT parameters. */
00468     int16_t       status;
00469 };
00470 typedef struct gnttab_copy  gnttab_copy_t;
00471 DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t);
00472 
00473 /*
00474  * GNTTABOP_query_size: Query the current and maximum sizes of the shared
00475  * grant table.
00476  * NOTES:
00477  *  1. <dom> may be specified as DOMID_SELF.
00478  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
00479  */
00480 struct gnttab_query_size {
00481     /* IN parameters. */
00482     domid_t  dom;
00483     /* OUT parameters. */
00484     uint32_t nr_frames;
00485     uint32_t max_nr_frames;
00486     int16_t  status;              /* => enum grant_status */
00487 };
00488 typedef struct gnttab_query_size gnttab_query_size_t;
00489 DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t);
00490 
00491 /*
00492  * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
00493  * tracked by <handle> but atomically replace the page table entry with one
00494  * pointing to the machine address under <new_addr>.  <new_addr> will be
00495  * redirected to the null entry.
00496  * NOTES:
00497  *  1. The call may fail in an undefined manner if either mapping is not
00498  *     tracked by <handle>.
00499  *  2. After executing a batch of unmaps, it is guaranteed that no stale
00500  *     mappings will remain in the device or host TLBs.
00501  */
00502 struct gnttab_unmap_and_replace {
00503     /* IN parameters. */
00504     uint64_t host_addr;
00505     uint64_t new_addr;
00506     grant_handle_t handle;
00507     /* OUT parameters. */
00508     int16_t  status;              /* => enum grant_status */
00509 };
00510 typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t;
00511 DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t);
00512 
00513 #if __XEN_INTERFACE_VERSION__ >= 0x0003020a
00514 /*
00515  * GNTTABOP_set_version: Request a particular version of the grant
00516  * table shared table structure.  This operation can only be performed
00517  * once in any given domain.  It must be performed before any grants
00518  * are activated; otherwise, the domain will be stuck with version 1.
00519  * The only defined versions are 1 and 2.
00520  */
00521 struct gnttab_set_version {
00522     /* IN/OUT parameters */
00523     uint32_t version;
00524 };
00525 typedef struct gnttab_set_version gnttab_set_version_t;
00526 DEFINE_XEN_GUEST_HANDLE(gnttab_set_version_t);
00527 
00528 
00529 /*
00530  * GNTTABOP_get_status_frames: Get the list of frames used to store grant
00531  * status for <dom>. In grant format version 2, the status is separated
00532  * from the other shared grant fields to allow more efficient synchronization
00533  * using barriers instead of atomic cmpexch operations.
00534  * <nr_frames> specify the size of vector <frame_list>.
00535  * The frame addresses are returned in the <frame_list>.
00536  * Only <nr_frames> addresses are returned, even if the table is larger.
00537  * NOTES:
00538  *  1. <dom> may be specified as DOMID_SELF.
00539  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
00540  */
00541 struct gnttab_get_status_frames {
00542     /* IN parameters. */
00543     uint32_t nr_frames;
00544     domid_t  dom;
00545     /* OUT parameters. */
00546     int16_t  status;              /* => enum grant_status */
00547     XEN_GUEST_HANDLE(uint64_t) frame_list;
00548 };
00549 typedef struct gnttab_get_status_frames gnttab_get_status_frames_t;
00550 DEFINE_XEN_GUEST_HANDLE(gnttab_get_status_frames_t);
00551 
00552 /*
00553  * GNTTABOP_get_version: Get the grant table version which is in
00554  * effect for domain <dom>.
00555  */
00556 struct gnttab_get_version {
00557     /* IN parameters */
00558     domid_t dom;
00559     uint16_t pad;
00560     /* OUT parameters */
00561     uint32_t version;
00562 };
00563 typedef struct gnttab_get_version gnttab_get_version_t;
00564 DEFINE_XEN_GUEST_HANDLE(gnttab_get_version_t);
00565 
00566 /*
00567  * GNTTABOP_swap_grant_ref: Swap the contents of two grant entries.
00568  */
00569 struct gnttab_swap_grant_ref {
00570     /* IN parameters */
00571     grant_ref_t ref_a;
00572     grant_ref_t ref_b;
00573     /* OUT parameters */
00574     int16_t status;             /* => enum grant_status */
00575 };
00576 typedef struct gnttab_swap_grant_ref gnttab_swap_grant_ref_t;
00577 DEFINE_XEN_GUEST_HANDLE(gnttab_swap_grant_ref_t);
00578 
00579 #endif /* __XEN_INTERFACE_VERSION__ */
00580 
00581 /*
00582  * Bitfield values for gnttab_map_grant_ref.flags.
00583  */
00584  /* Map the grant entry for access by I/O devices. */
00585 #define _GNTMAP_device_map      (0)
00586 #define GNTMAP_device_map       (1<<_GNTMAP_device_map)
00587  /* Map the grant entry for access by host CPUs. */
00588 #define _GNTMAP_host_map        (1)
00589 #define GNTMAP_host_map         (1<<_GNTMAP_host_map)
00590  /* Accesses to the granted frame will be restricted to read-only access. */
00591 #define _GNTMAP_readonly        (2)
00592 #define GNTMAP_readonly         (1<<_GNTMAP_readonly)
00593  /*
00594   * GNTMAP_host_map subflag:
00595   *  0 => The host mapping is usable only by the guest OS.
00596   *  1 => The host mapping is usable by guest OS + current application.
00597   */
00598 #define _GNTMAP_application_map (3)
00599 #define GNTMAP_application_map  (1<<_GNTMAP_application_map)
00600 
00601  /*
00602   * GNTMAP_contains_pte subflag:
00603   *  0 => This map request contains a host virtual address.
00604   *  1 => This map request contains the machine addess of the PTE to update.
00605   */
00606 #define _GNTMAP_contains_pte    (4)
00607 #define GNTMAP_contains_pte     (1<<_GNTMAP_contains_pte)
00608 
00609 #define _GNTMAP_can_fail        (5)
00610 #define GNTMAP_can_fail         (1<<_GNTMAP_can_fail)
00611 
00612 /*
00613  * Bits to be placed in guest kernel available PTE bits (architecture
00614  * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
00615  */
00616 #define _GNTMAP_guest_avail0    (16)
00617 #define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
00618 
00619 /*
00620  * Values for error status returns. All errors are -ve.
00621  */
00622 /* ` enum grant_status { */
00623 #define GNTST_okay             (0)  /* Normal return.                        */
00624 #define GNTST_general_error    (-1) /* General undefined error.              */
00625 #define GNTST_bad_domain       (-2) /* Unrecognsed domain id.                */
00626 #define GNTST_bad_gntref       (-3) /* Unrecognised or inappropriate gntref. */
00627 #define GNTST_bad_handle       (-4) /* Unrecognised or inappropriate handle. */
00628 #define GNTST_bad_virt_addr    (-5) /* Inappropriate virtual address to map. */
00629 #define GNTST_bad_dev_addr     (-6) /* Inappropriate device address to unmap.*/
00630 #define GNTST_no_device_space  (-7) /* Out of space in I/O MMU.              */
00631 #define GNTST_permission_denied (-8) /* Not enough privilege for operation.  */
00632 #define GNTST_bad_page         (-9) /* Specified page was invalid for op.    */
00633 #define GNTST_bad_copy_arg    (-10) /* copy arguments cross page boundary.   */
00634 #define GNTST_address_too_big (-11) /* transfer page address too large.      */
00635 #define GNTST_eagain          (-12) /* Operation not done; try again.        */
00636 /* ` } */
00637 
00638 #define GNTTABOP_error_msgs {                   \
00639     "okay",                                     \
00640     "undefined error",                          \
00641     "unrecognised domain id",                   \
00642     "invalid grant reference",                  \
00643     "invalid mapping handle",                   \
00644     "invalid virtual address",                  \
00645     "invalid device address",                   \
00646     "no spare translation slot in the I/O MMU", \
00647     "permission denied",                        \
00648     "bad page",                                 \
00649     "copy arguments cross page boundary",       \
00650     "page address size too large",              \
00651     "operation not done; try again"             \
00652 }
00653 
00654 #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
00655 
00656 /*
00657  * Local variables:
00658  * mode: C
00659  * c-file-style: "BSD"
00660  * c-basic-offset: 4
00661  * tab-width: 4
00662  * indent-tabs-mode: nil
00663  * End:
00664  */