Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * grant_table.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Interface for granting foreign access to page frames, and receiving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * page-ownership transfers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Permission is hereby granted, free of charge, to any person obtaining a copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * of this software and associated documentation files (the "Software"), to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * deal in the Software without restriction, including without limitation the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * sell copies of the Software, and to permit persons to whom the Software is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * furnished to do so, subject to the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * The above copyright notice and this permission notice shall be included in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * all copies or substantial portions of the Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * DEALINGS IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Copyright (c) 2004, K A Fraser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #ifndef __XEN_PUBLIC_GRANT_TABLE_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define __XEN_PUBLIC_GRANT_TABLE_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <xen/interface/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /***********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * GRANT TABLE REPRESENTATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /* Some rough guidelines on accessing and updating grant-table entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * in a concurrency-safe manner. For more information, Linux contains a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * reference implementation for guest OSes (arch/xen/kernel/grant_table.c).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * NB. WMB is a no-op on current-generation x86 processors. However, a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *     compiler barrier will still be required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * Introducing a valid entry into the grant table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *  1. Write ent->domid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *  2. Write ent->frame:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *      GTF_permit_access:   Frame to which access is permitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *      GTF_accept_transfer: Pseudo-phys frame slot being filled by new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *                           frame, or zero if none.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *  3. Write memory barrier (WMB).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *  4. Write ent->flags, inc. valid type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Invalidating an unused GTF_permit_access entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *  1. flags = ent->flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *  2. Observe that !(flags & (GTF_reading|GTF_writing)).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *  NB. No need for WMB as reuse of entry is control-dependent on success of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * Invalidating an in-use GTF_permit_access entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *  This cannot be done directly. Request assistance from the domain controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *  which can set a timeout on the use of a grant entry and take necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  *  action. (NB. This is not yet implemented!).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * Invalidating an unused GTF_accept_transfer entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  *  1. flags = ent->flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  *  2. Observe that !(flags & GTF_transfer_committed). [*]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  *  NB. No need for WMB as reuse of entry is control-dependent on success of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *  [*] If GTF_transfer_committed is set then the grant entry is 'committed'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *      The guest must /not/ modify the grant entry until the address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *      transferred frame is written. It is safe for the guest to spin waiting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  *      for this to occur (detect by observing GTF_transfer_completed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *      ent->flags).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * Invalidating a committed GTF_accept_transfer entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *  1. Wait for (ent->flags & GTF_transfer_completed).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * Changing a GTF_permit_access from writable to read-only:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  *  Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * Changing a GTF_permit_access from read-only to writable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  *  Use SMP-safe bit-setting instruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * Reference to a grant entry in a specified domain's grant table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) typedef uint32_t grant_ref_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)  * A grant table comprises a packed array of grant entries in one or more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * page frames shared between Xen and a guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  * [XEN]: This field is written by Xen and read by the sharing guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * [GST]: This field is written by the guest and read by Xen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * Version 1 of the grant table entry structure is maintained purely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * for backwards compatibility.  New guests should use version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct grant_entry_v1 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)     /* GTF_xxx: various type and flag information.  [XEN,GST] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)     uint16_t flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)     /* The domain being granted foreign privileges. [GST] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)     domid_t  domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)      * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)      * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)     uint32_t frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * Type of grant entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *  GTF_invalid: This grant entry grants no privileges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *  GTF_permit_access: Allow @domid to map/access @frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *  GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *                       to this guest. Xen writes the page number to @frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *  GTF_transitive: Allow @domid to transitively access a subrange of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  *                  @trans_grant in @trans_domid.  No mappings are allowed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define GTF_invalid         (0U<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define GTF_permit_access   (1U<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define GTF_accept_transfer (2U<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #define GTF_transitive      (3U<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define GTF_type_mask       (3U<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * Subflags for GTF_permit_access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *  GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *  GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  *  GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *  GTF_sub_page: Grant access to only a subrange of the page.  @domid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *                will only be allowed to copy from the grant, and not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *                map it. [GST]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define _GTF_readonly       (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define GTF_readonly        (1U<<_GTF_readonly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define _GTF_reading        (3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define GTF_reading         (1U<<_GTF_reading)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define _GTF_writing        (4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define GTF_writing         (1U<<_GTF_writing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define _GTF_sub_page       (8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define GTF_sub_page        (1U<<_GTF_sub_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * Subflags for GTF_accept_transfer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  *  GTF_transfer_committed: Xen sets this flag to indicate that it is committed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  *      to transferring ownership of a page frame. When a guest sees this flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  *      it must /not/ modify the grant entry until GTF_transfer_completed is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  *      set by Xen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  *  GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *      after reading GTF_transfer_committed. Xen will always write the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  *      address, followed by ORing this flag, in a timely manner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define _GTF_transfer_committed (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #define GTF_transfer_committed  (1U<<_GTF_transfer_committed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define _GTF_transfer_completed (3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #define GTF_transfer_completed  (1U<<_GTF_transfer_completed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * Version 2 grant table entries.  These fulfil the same role as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * version 1 entries, but can represent more complicated operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * Any given domain will have either a version 1 or a version 2 table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * and every entry in the table will be the same version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * The interface by which domains use grant references does not depend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  * on the grant table version in use by the other domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * Version 1 and version 2 grant entries share a common prefix.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * fields of the prefix are documented as part of struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * grant_entry_v1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct grant_entry_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)     uint16_t flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)     domid_t  domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * Version 2 of the grant entry structure, here is a union because three
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * different types are suppotted: full_page, sub_page and transitive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) union grant_entry_v2 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)     struct grant_entry_header hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)      * This member is used for V1-style full page grants, where either:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)      *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)      * -- hdr.type is GTF_accept_transfer, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)      * -- hdr.type is GTF_permit_access and GTF_sub_page is not set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)      *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)      * In that case, the frame field has the same semantics as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)      * field of the same name in the V1 entry structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)     struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct grant_entry_header hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	uint32_t pad0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	uint64_t frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)     } full_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)      * If the grant type is GTF_grant_access and GTF_sub_page is set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)      * @domid is allowed to access bytes [@page_off,@page_off+@length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)      * in frame @frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)     struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct grant_entry_header hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	uint16_t page_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	uint16_t length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	uint64_t frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)     } sub_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)      * If the grant is GTF_transitive, @domid is allowed to use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)      * grant @gref in domain @trans_domid, as if it was the local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)      * domain.  Obviously, the transitive access must be compatible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)      * with the original grant.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)     struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct grant_entry_header hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	domid_t trans_domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	uint16_t pad0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	grant_ref_t gref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)     } transitive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)     uint32_t __spacer[4]; /* Pad to a power of two */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) typedef uint16_t grant_status_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /***********************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * GRANT TABLE QUERIES AND USES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Handle to track a mapping created via a grant reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) typedef uint32_t grant_handle_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * by devices and/or host CPUs. If successful, <handle> is a tracking number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * that must be presented later to destroy the mapping(s). On error, <handle>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * is a negative status code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * NOTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *  1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  *     via which I/O devices may access the granted frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  *  2. If GNTMAP_host_map is specified then a mapping will be added at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  *     either a host virtual address in the current address space, or at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  *     a PTE at the specified machine address.  The type of mapping to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  *     perform is selected through the GNTMAP_contains_pte flag, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  *     address is specified in <host_addr>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  *  3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  *     host mapping is destroyed by other means then it is *NOT* guaranteed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  *     to be accounted to the correct grant reference!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #define GNTTABOP_map_grant_ref        0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct gnttab_map_grant_ref {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)     uint64_t host_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)     uint32_t flags;               /* GNTMAP_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)     grant_ref_t ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)     domid_t  dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)     int16_t  status;              /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)     grant_handle_t handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)     uint64_t dev_bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) DEFINE_GUEST_HANDLE_STRUCT(gnttab_map_grant_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * field is ignored. If non-zero, they must refer to a device/host mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * that is tracked by <handle>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * NOTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  *  1. The call may fail in an undefined manner if either mapping is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  *     tracked by <handle>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  *  3. After executing a batch of unmaps, it is guaranteed that no stale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  *     mappings will remain in the device or host TLBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define GNTTABOP_unmap_grant_ref      1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct gnttab_unmap_grant_ref {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)     uint64_t host_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)     uint64_t dev_bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)     grant_handle_t handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)     int16_t  status;              /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) DEFINE_GUEST_HANDLE_STRUCT(gnttab_unmap_grant_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  * <nr_frames> pages. The frame addresses are written to the <frame_list>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * Only <nr_frames> addresses are written, even if the table is larger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  * NOTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)  *  1. <dom> may be specified as DOMID_SELF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  *  3. Xen may not support more than a single grant-table page per domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #define GNTTABOP_setup_table          2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct gnttab_setup_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)     domid_t  dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)     uint32_t nr_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)     int16_t  status;              /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)     GUEST_HANDLE(xen_pfn_t) frame_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) DEFINE_GUEST_HANDLE_STRUCT(gnttab_setup_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * GNTTABOP_dump_table: Dump the contents of the grant table to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * xen console. Debugging use only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define GNTTABOP_dump_table           3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct gnttab_dump_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)     domid_t dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)     int16_t status;               /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) DEFINE_GUEST_HANDLE_STRUCT(gnttab_dump_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * foreign domain has previously registered its interest in the transfer via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  * <domid, ref>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)  * Note that, even if the transfer fails, the specified page no longer belongs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * to the calling domain *unless* the error is GNTST_bad_page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #define GNTTABOP_transfer                4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) struct gnttab_transfer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)     xen_pfn_t mfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)     domid_t       domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)     grant_ref_t   ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)     int16_t       status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) DEFINE_GUEST_HANDLE_STRUCT(gnttab_transfer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * GNTTABOP_copy: Hypervisor based copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * source and destinations can be eithers MFNs or, for foreign domains,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * grant references. the foreign domain has to grant read/write access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * in its grant table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * The flags specify what type source and destinations are (either MFN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * or grant reference).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * Note that this can also be used to copy data between two domains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * via a third party if the source and destination domains had previously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * grant appropriate access to their pages to the third party.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * source_offset specifies an offset in the source frame, dest_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  * the offset in the target frame and  len specifies the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  * bytes to be copied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) #define _GNTCOPY_source_gref      (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #define GNTCOPY_source_gref       (1<<_GNTCOPY_source_gref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #define _GNTCOPY_dest_gref        (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define GNTCOPY_dest_gref         (1<<_GNTCOPY_dest_gref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) #define GNTTABOP_copy                 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) struct gnttab_copy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			grant_ref_t ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			xen_pfn_t   gmfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		} u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		domid_t  domid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		uint16_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	} source, dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	uint16_t      len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	uint16_t      flags;          /* GNTCOPY_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	int16_t       status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) DEFINE_GUEST_HANDLE_STRUCT(gnttab_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * GNTTABOP_query_size: Query the current and maximum sizes of the shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * grant table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  * NOTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  *  1. <dom> may be specified as DOMID_SELF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) #define GNTTABOP_query_size           6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct gnttab_query_size {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)     domid_t  dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)     uint32_t nr_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)     uint32_t max_nr_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)     int16_t  status;              /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) DEFINE_GUEST_HANDLE_STRUCT(gnttab_query_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * tracked by <handle> but atomically replace the page table entry with one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * pointing to the machine address under <new_addr>.  <new_addr> will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  * redirected to the null entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * NOTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  *  1. The call may fail in an undefined manner if either mapping is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  *     tracked by <handle>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  *  2. After executing a batch of unmaps, it is guaranteed that no stale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  *     mappings will remain in the device or host TLBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #define GNTTABOP_unmap_and_replace    7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct gnttab_unmap_and_replace {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)     uint64_t host_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)     uint64_t new_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)     grant_handle_t handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)     int16_t  status;              /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) DEFINE_GUEST_HANDLE_STRUCT(gnttab_unmap_and_replace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  * GNTTABOP_set_version: Request a particular version of the grant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  * table shared table structure.  This operation can only be performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  * once in any given domain.  It must be performed before any grants
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)  * are activated; otherwise, the domain will be stuck with version 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * The only defined versions are 1 and 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) #define GNTTABOP_set_version          8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct gnttab_set_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)     /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)     uint32_t version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) DEFINE_GUEST_HANDLE_STRUCT(gnttab_set_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * GNTTABOP_get_status_frames: Get the list of frames used to store grant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * status for <dom>. In grant format version 2, the status is separated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  * from the other shared grant fields to allow more efficient synchronization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  * using barriers instead of atomic cmpexch operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)  * <nr_frames> specify the size of vector <frame_list>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)  * The frame addresses are returned in the <frame_list>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  * Only <nr_frames> addresses are returned, even if the table is larger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  * NOTES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  *  1. <dom> may be specified as DOMID_SELF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #define GNTTABOP_get_status_frames     9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct gnttab_get_status_frames {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)     /* IN parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)     uint32_t nr_frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)     domid_t  dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)     /* OUT parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)     int16_t  status;              /* GNTST_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)     GUEST_HANDLE(uint64_t) frame_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) DEFINE_GUEST_HANDLE_STRUCT(gnttab_get_status_frames);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)  * GNTTABOP_get_version: Get the grant table version which is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)  * effect for domain <dom>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define GNTTABOP_get_version          10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct gnttab_get_version {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)     /* IN parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)     domid_t dom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)     uint16_t pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)     /* OUT parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)     uint32_t version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) DEFINE_GUEST_HANDLE_STRUCT(gnttab_get_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  * Issue one or more cache maintenance operations on a portion of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  * page granted to the calling domain by a foreign domain.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) #define GNTTABOP_cache_flush          12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct gnttab_cache_flush {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)     union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)         uint64_t dev_bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)         grant_ref_t ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)     } a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)     uint16_t offset;   /* offset from start of grant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)     uint16_t length;   /* size within the grant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) #define GNTTAB_CACHE_CLEAN          (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #define GNTTAB_CACHE_INVAL          (1<<1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) #define GNTTAB_CACHE_SOURCE_GREF    (1<<31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)     uint32_t op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) DEFINE_GUEST_HANDLE_STRUCT(gnttab_cache_flush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  * Bitfield values for update_pin_status.flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  /* Map the grant entry for access by I/O devices. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) #define _GNTMAP_device_map      (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) #define GNTMAP_device_map       (1<<_GNTMAP_device_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  /* Map the grant entry for access by host CPUs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) #define _GNTMAP_host_map        (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) #define GNTMAP_host_map         (1<<_GNTMAP_host_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  /* Accesses to the granted frame will be restricted to read-only access. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) #define _GNTMAP_readonly        (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) #define GNTMAP_readonly         (1<<_GNTMAP_readonly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)   * GNTMAP_host_map subflag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)   *  0 => The host mapping is usable only by the guest OS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)   *  1 => The host mapping is usable by guest OS + current application.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) #define _GNTMAP_application_map (3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) #define GNTMAP_application_map  (1<<_GNTMAP_application_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)   * GNTMAP_contains_pte subflag:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)   *  0 => This map request contains a host virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)   *  1 => This map request contains the machine addess of the PTE to update.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) #define _GNTMAP_contains_pte    (4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #define GNTMAP_contains_pte     (1<<_GNTMAP_contains_pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  * Bits to be placed in guest kernel available PTE bits (architecture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) #define _GNTMAP_guest_avail0    (16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) #define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)  * Values for error status returns. All errors are -ve.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) #define GNTST_okay             (0)  /* Normal return.                        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) #define GNTST_general_error    (-1) /* General undefined error.              */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) #define GNTST_bad_domain       (-2) /* Unrecognsed domain id.                */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) #define GNTST_bad_gntref       (-3) /* Unrecognised or inappropriate gntref. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) #define GNTST_bad_handle       (-4) /* Unrecognised or inappropriate handle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #define GNTST_bad_virt_addr    (-5) /* Inappropriate virtual address to map. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) #define GNTST_bad_dev_addr     (-6) /* Inappropriate device address to unmap.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) #define GNTST_no_device_space  (-7) /* Out of space in I/O MMU.              */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) #define GNTST_permission_denied (-8) /* Not enough privilege for operation.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) #define GNTST_bad_page         (-9) /* Specified page was invalid for op.    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) #define GNTST_bad_copy_arg    (-10) /* copy arguments cross page boundary.   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #define GNTST_address_too_big (-11) /* transfer page address too large.      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) #define GNTST_eagain          (-12) /* Operation not done; try again.        */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) #define GNTTABOP_error_msgs {                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)     "okay",                                     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)     "undefined error",                          \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)     "unrecognised domain id",                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)     "invalid grant reference",                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)     "invalid mapping handle",                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)     "invalid virtual address",                  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)     "invalid device address",                   \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)     "no spare translation slot in the I/O MMU", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)     "permission denied",                        \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)     "bad page",                                 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)     "copy arguments cross page boundary",       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)     "page address size too large",              \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)     "operation not done; try again"             \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */