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