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