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