xref: /titanic_41/usr/src/uts/common/xen/public/grant_table.h (revision 349b53dd4e695e3d833b5380540385145b2d3ae8)
1843e1988Sjohnlev /******************************************************************************
2843e1988Sjohnlev  * grant_table.h
3843e1988Sjohnlev  *
4843e1988Sjohnlev  * Interface for granting foreign access to page frames, and receiving
5843e1988Sjohnlev  * page-ownership transfers.
6843e1988Sjohnlev  *
7843e1988Sjohnlev  * Permission is hereby granted, free of charge, to any person obtaining a copy
8843e1988Sjohnlev  * of this software and associated documentation files (the "Software"), to
9843e1988Sjohnlev  * deal in the Software without restriction, including without limitation the
10843e1988Sjohnlev  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11843e1988Sjohnlev  * sell copies of the Software, and to permit persons to whom the Software is
12843e1988Sjohnlev  * furnished to do so, subject to the following conditions:
13843e1988Sjohnlev  *
14843e1988Sjohnlev  * The above copyright notice and this permission notice shall be included in
15843e1988Sjohnlev  * all copies or substantial portions of the Software.
16843e1988Sjohnlev  *
17843e1988Sjohnlev  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18843e1988Sjohnlev  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19843e1988Sjohnlev  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20843e1988Sjohnlev  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21843e1988Sjohnlev  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22843e1988Sjohnlev  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23843e1988Sjohnlev  * DEALINGS IN THE SOFTWARE.
24843e1988Sjohnlev  *
25843e1988Sjohnlev  * Copyright (c) 2004, K A Fraser
26843e1988Sjohnlev  */
27843e1988Sjohnlev 
28843e1988Sjohnlev #ifndef __XEN_PUBLIC_GRANT_TABLE_H__
29843e1988Sjohnlev #define __XEN_PUBLIC_GRANT_TABLE_H__
30843e1988Sjohnlev 
31843e1988Sjohnlev 
32843e1988Sjohnlev /***********************************
33843e1988Sjohnlev  * GRANT TABLE REPRESENTATION
34843e1988Sjohnlev  */
35843e1988Sjohnlev 
36843e1988Sjohnlev /* Some rough guidelines on accessing and updating grant-table entries
37843e1988Sjohnlev  * in a concurrency-safe manner. For more information, Linux contains a
38843e1988Sjohnlev  * reference implementation for guest OSes (arch/xen/kernel/grant_table.c).
39843e1988Sjohnlev  *
40843e1988Sjohnlev  * NB. WMB is a no-op on current-generation x86 processors. However, a
41843e1988Sjohnlev  *     compiler barrier will still be required.
42843e1988Sjohnlev  *
43843e1988Sjohnlev  * Introducing a valid entry into the grant table:
44843e1988Sjohnlev  *  1. Write ent->domid.
45843e1988Sjohnlev  *  2. Write ent->frame:
46843e1988Sjohnlev  *      GTF_permit_access:   Frame to which access is permitted.
47843e1988Sjohnlev  *      GTF_accept_transfer: Pseudo-phys frame slot being filled by new
48843e1988Sjohnlev  *                           frame, or zero if none.
49843e1988Sjohnlev  *  3. Write memory barrier (WMB).
50843e1988Sjohnlev  *  4. Write ent->flags, inc. valid type.
51843e1988Sjohnlev  *
52843e1988Sjohnlev  * Invalidating an unused GTF_permit_access entry:
53843e1988Sjohnlev  *  1. flags = ent->flags.
54843e1988Sjohnlev  *  2. Observe that !(flags & (GTF_reading|GTF_writing)).
55843e1988Sjohnlev  *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
56843e1988Sjohnlev  *  NB. No need for WMB as reuse of entry is control-dependent on success of
57843e1988Sjohnlev  *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
58843e1988Sjohnlev  *
59843e1988Sjohnlev  * Invalidating an in-use GTF_permit_access entry:
60843e1988Sjohnlev  *  This cannot be done directly. Request assistance from the domain controller
61843e1988Sjohnlev  *  which can set a timeout on the use of a grant entry and take necessary
62843e1988Sjohnlev  *  action. (NB. This is not yet implemented!).
63843e1988Sjohnlev  *
64843e1988Sjohnlev  * Invalidating an unused GTF_accept_transfer entry:
65843e1988Sjohnlev  *  1. flags = ent->flags.
66843e1988Sjohnlev  *  2. Observe that !(flags & GTF_transfer_committed). [*]
67843e1988Sjohnlev  *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
68843e1988Sjohnlev  *  NB. No need for WMB as reuse of entry is control-dependent on success of
69843e1988Sjohnlev  *      step 3, and all architectures guarantee ordering of ctrl-dep writes.
70843e1988Sjohnlev  *  [*] If GTF_transfer_committed is set then the grant entry is 'committed'.
71843e1988Sjohnlev  *      The guest must /not/ modify the grant entry until the address of the
72843e1988Sjohnlev  *      transferred frame is written. It is safe for the guest to spin waiting
73843e1988Sjohnlev  *      for this to occur (detect by observing GTF_transfer_completed in
74843e1988Sjohnlev  *      ent->flags).
75843e1988Sjohnlev  *
76843e1988Sjohnlev  * Invalidating a committed GTF_accept_transfer entry:
77843e1988Sjohnlev  *  1. Wait for (ent->flags & GTF_transfer_completed).
78843e1988Sjohnlev  *
79843e1988Sjohnlev  * Changing a GTF_permit_access from writable to read-only:
80843e1988Sjohnlev  *  Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
81843e1988Sjohnlev  *
82843e1988Sjohnlev  * Changing a GTF_permit_access from read-only to writable:
83843e1988Sjohnlev  *  Use SMP-safe bit-setting instruction.
84843e1988Sjohnlev  */
85843e1988Sjohnlev 
86843e1988Sjohnlev /*
87843e1988Sjohnlev  * A grant table comprises a packed array of grant entries in one or more
88843e1988Sjohnlev  * page frames shared between Xen and a guest.
89843e1988Sjohnlev  * [XEN]: This field is written by Xen and read by the sharing guest.
90843e1988Sjohnlev  * [GST]: This field is written by the guest and read by Xen.
91843e1988Sjohnlev  */
92843e1988Sjohnlev struct grant_entry {
93843e1988Sjohnlev     /* GTF_xxx: various type and flag information.  [XEN,GST] */
94843e1988Sjohnlev     uint16_t flags;
95843e1988Sjohnlev     /* The domain being granted foreign privileges. [GST] */
96843e1988Sjohnlev     domid_t  domid;
97843e1988Sjohnlev     /*
98843e1988Sjohnlev      * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
99843e1988Sjohnlev      * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
100843e1988Sjohnlev      */
101843e1988Sjohnlev     uint32_t frame;
102843e1988Sjohnlev };
103843e1988Sjohnlev typedef struct grant_entry grant_entry_t;
104843e1988Sjohnlev 
105843e1988Sjohnlev /*
106843e1988Sjohnlev  * Type of grant entry.
107843e1988Sjohnlev  *  GTF_invalid: This grant entry grants no privileges.
108843e1988Sjohnlev  *  GTF_permit_access: Allow @domid to map/access @frame.
109843e1988Sjohnlev  *  GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
110843e1988Sjohnlev  *                       to this guest. Xen writes the page number to @frame.
111843e1988Sjohnlev  */
112843e1988Sjohnlev #define GTF_invalid         (0U<<0)
113843e1988Sjohnlev #define GTF_permit_access   (1U<<0)
114843e1988Sjohnlev #define GTF_accept_transfer (2U<<0)
115843e1988Sjohnlev #define GTF_type_mask       (3U<<0)
116843e1988Sjohnlev 
117843e1988Sjohnlev /*
118843e1988Sjohnlev  * Subflags for GTF_permit_access.
119843e1988Sjohnlev  *  GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
120843e1988Sjohnlev  *  GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
121843e1988Sjohnlev  *  GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
122*349b53ddSStuart Maybee  *  GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
123843e1988Sjohnlev  */
124843e1988Sjohnlev #define _GTF_readonly       (2)
125843e1988Sjohnlev #define GTF_readonly        (1U<<_GTF_readonly)
126843e1988Sjohnlev #define _GTF_reading        (3)
127843e1988Sjohnlev #define GTF_reading         (1U<<_GTF_reading)
128843e1988Sjohnlev #define _GTF_writing        (4)
129843e1988Sjohnlev #define GTF_writing         (1U<<_GTF_writing)
130*349b53ddSStuart Maybee #define _GTF_PWT            (5)
131*349b53ddSStuart Maybee #define GTF_PWT             (1U<<_GTF_PWT)
132*349b53ddSStuart Maybee #define _GTF_PCD            (6)
133*349b53ddSStuart Maybee #define GTF_PCD             (1U<<_GTF_PCD)
134*349b53ddSStuart Maybee #define _GTF_PAT            (7)
135*349b53ddSStuart Maybee #define GTF_PAT             (1U<<_GTF_PAT)
136843e1988Sjohnlev 
137843e1988Sjohnlev /*
138843e1988Sjohnlev  * Subflags for GTF_accept_transfer:
139843e1988Sjohnlev  *  GTF_transfer_committed: Xen sets this flag to indicate that it is committed
140843e1988Sjohnlev  *      to transferring ownership of a page frame. When a guest sees this flag
141843e1988Sjohnlev  *      it must /not/ modify the grant entry until GTF_transfer_completed is
142843e1988Sjohnlev  *      set by Xen.
143843e1988Sjohnlev  *  GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
144843e1988Sjohnlev  *      after reading GTF_transfer_committed. Xen will always write the frame
145843e1988Sjohnlev  *      address, followed by ORing this flag, in a timely manner.
146843e1988Sjohnlev  */
147843e1988Sjohnlev #define _GTF_transfer_committed (2)
148843e1988Sjohnlev #define GTF_transfer_committed  (1U<<_GTF_transfer_committed)
149843e1988Sjohnlev #define _GTF_transfer_completed (3)
150843e1988Sjohnlev #define GTF_transfer_completed  (1U<<_GTF_transfer_completed)
151843e1988Sjohnlev 
152843e1988Sjohnlev 
153843e1988Sjohnlev /***********************************
154843e1988Sjohnlev  * GRANT TABLE QUERIES AND USES
155843e1988Sjohnlev  */
156843e1988Sjohnlev 
157843e1988Sjohnlev /*
158843e1988Sjohnlev  * Reference to a grant entry in a specified domain's grant table.
159843e1988Sjohnlev  */
160843e1988Sjohnlev typedef uint32_t grant_ref_t;
161843e1988Sjohnlev 
162843e1988Sjohnlev /*
163843e1988Sjohnlev  * Handle to track a mapping created via a grant reference.
164843e1988Sjohnlev  */
165843e1988Sjohnlev typedef uint32_t grant_handle_t;
166843e1988Sjohnlev 
167843e1988Sjohnlev /*
168843e1988Sjohnlev  * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
169843e1988Sjohnlev  * by devices and/or host CPUs. If successful, <handle> is a tracking number
170843e1988Sjohnlev  * that must be presented later to destroy the mapping(s). On error, <handle>
171843e1988Sjohnlev  * is a negative status code.
172843e1988Sjohnlev  * NOTES:
173843e1988Sjohnlev  *  1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
174843e1988Sjohnlev  *     via which I/O devices may access the granted frame.
175843e1988Sjohnlev  *  2. If GNTMAP_host_map is specified then a mapping will be added at
176843e1988Sjohnlev  *     either a host virtual address in the current address space, or at
177843e1988Sjohnlev  *     a PTE at the specified machine address.  The type of mapping to
178843e1988Sjohnlev  *     perform is selected through the GNTMAP_contains_pte flag, and the
179843e1988Sjohnlev  *     address is specified in <host_addr>.
180843e1988Sjohnlev  *  3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
181843e1988Sjohnlev  *     host mapping is destroyed by other means then it is *NOT* guaranteed
182843e1988Sjohnlev  *     to be accounted to the correct grant reference!
183843e1988Sjohnlev  */
184843e1988Sjohnlev #define GNTTABOP_map_grant_ref        0
185843e1988Sjohnlev struct gnttab_map_grant_ref {
186843e1988Sjohnlev     /* IN parameters. */
187843e1988Sjohnlev     uint64_t host_addr;
188843e1988Sjohnlev     uint32_t flags;               /* GNTMAP_* */
189843e1988Sjohnlev     grant_ref_t ref;
190843e1988Sjohnlev     domid_t  dom;
191843e1988Sjohnlev     /* OUT parameters. */
192843e1988Sjohnlev     int16_t  status;              /* GNTST_* */
193843e1988Sjohnlev     grant_handle_t handle;
194843e1988Sjohnlev     uint64_t dev_bus_addr;
195843e1988Sjohnlev };
196843e1988Sjohnlev typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t;
197843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t);
198843e1988Sjohnlev 
199843e1988Sjohnlev /*
200843e1988Sjohnlev  * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
201843e1988Sjohnlev  * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
202843e1988Sjohnlev  * field is ignored. If non-zero, they must refer to a device/host mapping
203843e1988Sjohnlev  * that is tracked by <handle>
204843e1988Sjohnlev  * NOTES:
205843e1988Sjohnlev  *  1. The call may fail in an undefined manner if either mapping is not
206843e1988Sjohnlev  *     tracked by <handle>.
207843e1988Sjohnlev  *  3. After executing a batch of unmaps, it is guaranteed that no stale
208843e1988Sjohnlev  *     mappings will remain in the device or host TLBs.
209843e1988Sjohnlev  */
210843e1988Sjohnlev #define GNTTABOP_unmap_grant_ref      1
211843e1988Sjohnlev struct gnttab_unmap_grant_ref {
212843e1988Sjohnlev     /* IN parameters. */
213843e1988Sjohnlev     uint64_t host_addr;
214843e1988Sjohnlev     uint64_t dev_bus_addr;
215843e1988Sjohnlev     grant_handle_t handle;
216843e1988Sjohnlev     /* OUT parameters. */
217843e1988Sjohnlev     int16_t  status;              /* GNTST_* */
218843e1988Sjohnlev };
219843e1988Sjohnlev typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t;
220843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t);
221843e1988Sjohnlev 
222843e1988Sjohnlev /*
223843e1988Sjohnlev  * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
224843e1988Sjohnlev  * <nr_frames> pages. The frame addresses are written to the <frame_list>.
225843e1988Sjohnlev  * Only <nr_frames> addresses are written, even if the table is larger.
226843e1988Sjohnlev  * NOTES:
227843e1988Sjohnlev  *  1. <dom> may be specified as DOMID_SELF.
228843e1988Sjohnlev  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
229843e1988Sjohnlev  *  3. Xen may not support more than a single grant-table page per domain.
230843e1988Sjohnlev  */
231843e1988Sjohnlev #define GNTTABOP_setup_table          2
232843e1988Sjohnlev struct gnttab_setup_table {
233843e1988Sjohnlev     /* IN parameters. */
234843e1988Sjohnlev     domid_t  dom;
235843e1988Sjohnlev     uint32_t nr_frames;
236843e1988Sjohnlev     /* OUT parameters. */
237843e1988Sjohnlev     int16_t  status;              /* GNTST_* */
238843e1988Sjohnlev     XEN_GUEST_HANDLE(ulong) frame_list;
239843e1988Sjohnlev };
240843e1988Sjohnlev typedef struct gnttab_setup_table gnttab_setup_table_t;
241843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t);
242843e1988Sjohnlev 
243843e1988Sjohnlev /*
244843e1988Sjohnlev  * GNTTABOP_dump_table: Dump the contents of the grant table to the
245843e1988Sjohnlev  * xen console. Debugging use only.
246843e1988Sjohnlev  */
247843e1988Sjohnlev #define GNTTABOP_dump_table           3
248843e1988Sjohnlev struct gnttab_dump_table {
249843e1988Sjohnlev     /* IN parameters. */
250843e1988Sjohnlev     domid_t dom;
251843e1988Sjohnlev     /* OUT parameters. */
252843e1988Sjohnlev     int16_t status;               /* GNTST_* */
253843e1988Sjohnlev };
254843e1988Sjohnlev typedef struct gnttab_dump_table gnttab_dump_table_t;
255843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t);
256843e1988Sjohnlev 
257843e1988Sjohnlev /*
258843e1988Sjohnlev  * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The
259843e1988Sjohnlev  * foreign domain has previously registered its interest in the transfer via
260843e1988Sjohnlev  * <domid, ref>.
261843e1988Sjohnlev  *
262843e1988Sjohnlev  * Note that, even if the transfer fails, the specified page no longer belongs
263843e1988Sjohnlev  * to the calling domain *unless* the error is GNTST_bad_page.
264843e1988Sjohnlev  */
265843e1988Sjohnlev #define GNTTABOP_transfer                4
266843e1988Sjohnlev struct gnttab_transfer {
267843e1988Sjohnlev     /* IN parameters. */
268843e1988Sjohnlev     xen_pfn_t     mfn;
269843e1988Sjohnlev     domid_t       domid;
270843e1988Sjohnlev     grant_ref_t   ref;
271843e1988Sjohnlev     /* OUT parameters. */
272843e1988Sjohnlev     int16_t       status;
273843e1988Sjohnlev };
274843e1988Sjohnlev typedef struct gnttab_transfer gnttab_transfer_t;
275843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t);
276843e1988Sjohnlev 
277843e1988Sjohnlev 
278843e1988Sjohnlev /*
279843e1988Sjohnlev  * GNTTABOP_copy: Hypervisor based copy
280843e1988Sjohnlev  * source and destinations can be eithers MFNs or, for foreign domains,
281843e1988Sjohnlev  * grant references. the foreign domain has to grant read/write access
282843e1988Sjohnlev  * in its grant table.
283843e1988Sjohnlev  *
284843e1988Sjohnlev  * The flags specify what type source and destinations are (either MFN
285843e1988Sjohnlev  * or grant reference).
286843e1988Sjohnlev  *
287843e1988Sjohnlev  * Note that this can also be used to copy data between two domains
288843e1988Sjohnlev  * via a third party if the source and destination domains had previously
289843e1988Sjohnlev  * grant appropriate access to their pages to the third party.
290843e1988Sjohnlev  *
291843e1988Sjohnlev  * source_offset specifies an offset in the source frame, dest_offset
292843e1988Sjohnlev  * the offset in the target frame and  len specifies the number of
293843e1988Sjohnlev  * bytes to be copied.
294843e1988Sjohnlev  */
295843e1988Sjohnlev 
296843e1988Sjohnlev #define _GNTCOPY_source_gref      (0)
297843e1988Sjohnlev #define GNTCOPY_source_gref       (1<<_GNTCOPY_source_gref)
298843e1988Sjohnlev #define _GNTCOPY_dest_gref        (1)
299843e1988Sjohnlev #define GNTCOPY_dest_gref         (1<<_GNTCOPY_dest_gref)
300843e1988Sjohnlev 
301843e1988Sjohnlev #define GNTTABOP_copy                 5
302843e1988Sjohnlev typedef struct gnttab_copy {
303843e1988Sjohnlev     /* IN parameters. */
304843e1988Sjohnlev     struct {
305843e1988Sjohnlev         union {
306843e1988Sjohnlev             grant_ref_t ref;
307843e1988Sjohnlev             xen_pfn_t   gmfn;
308843e1988Sjohnlev         } u;
309843e1988Sjohnlev         domid_t  domid;
310843e1988Sjohnlev         uint16_t offset;
311843e1988Sjohnlev     } source, dest;
312843e1988Sjohnlev     uint16_t      len;
313843e1988Sjohnlev     uint16_t      flags;          /* GNTCOPY_* */
314843e1988Sjohnlev     /* OUT parameters. */
315843e1988Sjohnlev     int16_t       status;
316843e1988Sjohnlev } gnttab_copy_t;
317843e1988Sjohnlev DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t);
318843e1988Sjohnlev 
319a576ab5bSrab /*
320a576ab5bSrab  * GNTTABOP_query_size: Query the current and maximum sizes of the shared
321a576ab5bSrab  * grant table.
322a576ab5bSrab  * NOTES:
323a576ab5bSrab  *  1. <dom> may be specified as DOMID_SELF.
324a576ab5bSrab  *  2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
325a576ab5bSrab  */
326a576ab5bSrab #define GNTTABOP_query_size           6
327a576ab5bSrab struct gnttab_query_size {
328a576ab5bSrab     /* IN parameters. */
329a576ab5bSrab     domid_t  dom;
330a576ab5bSrab     /* OUT parameters. */
331a576ab5bSrab     uint32_t nr_frames;
332a576ab5bSrab     uint32_t max_nr_frames;
333a576ab5bSrab     int16_t  status;              /* GNTST_* */
334a576ab5bSrab };
335a576ab5bSrab typedef struct gnttab_query_size gnttab_query_size_t;
336a576ab5bSrab DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t);
337a576ab5bSrab 
338*349b53ddSStuart Maybee /*
339*349b53ddSStuart Maybee  * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
340*349b53ddSStuart Maybee  * tracked by <handle> but atomically replace the page table entry with one
341*349b53ddSStuart Maybee  * pointing to the machine address under <new_addr>.  <new_addr> will be
342*349b53ddSStuart Maybee  * redirected to the null entry.
343*349b53ddSStuart Maybee  * NOTES:
344*349b53ddSStuart Maybee  *  1. The call may fail in an undefined manner if either mapping is not
345*349b53ddSStuart Maybee  *     tracked by <handle>.
346*349b53ddSStuart Maybee  *  2. After executing a batch of unmaps, it is guaranteed that no stale
347*349b53ddSStuart Maybee  *     mappings will remain in the device or host TLBs.
348*349b53ddSStuart Maybee  */
349*349b53ddSStuart Maybee #define GNTTABOP_unmap_and_replace    7
350*349b53ddSStuart Maybee struct gnttab_unmap_and_replace {
351*349b53ddSStuart Maybee     /* IN parameters. */
352*349b53ddSStuart Maybee     uint64_t host_addr;
353*349b53ddSStuart Maybee     uint64_t new_addr;
354*349b53ddSStuart Maybee     grant_handle_t handle;
355*349b53ddSStuart Maybee     /* OUT parameters. */
356*349b53ddSStuart Maybee     int16_t  status;              /* GNTST_* */
357*349b53ddSStuart Maybee };
358*349b53ddSStuart Maybee typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t;
359*349b53ddSStuart Maybee DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t);
360*349b53ddSStuart Maybee 
361843e1988Sjohnlev 
362843e1988Sjohnlev /*
363*349b53ddSStuart Maybee  * Bitfield values for gnttab_map_grant_ref.flags.
364843e1988Sjohnlev  */
365843e1988Sjohnlev  /* Map the grant entry for access by I/O devices. */
366843e1988Sjohnlev #define _GNTMAP_device_map      (0)
367843e1988Sjohnlev #define GNTMAP_device_map       (1<<_GNTMAP_device_map)
368843e1988Sjohnlev  /* Map the grant entry for access by host CPUs. */
369843e1988Sjohnlev #define _GNTMAP_host_map        (1)
370843e1988Sjohnlev #define GNTMAP_host_map         (1<<_GNTMAP_host_map)
371843e1988Sjohnlev  /* Accesses to the granted frame will be restricted to read-only access. */
372843e1988Sjohnlev #define _GNTMAP_readonly        (2)
373843e1988Sjohnlev #define GNTMAP_readonly         (1<<_GNTMAP_readonly)
374843e1988Sjohnlev  /*
375843e1988Sjohnlev   * GNTMAP_host_map subflag:
376843e1988Sjohnlev   *  0 => The host mapping is usable only by the guest OS.
377843e1988Sjohnlev   *  1 => The host mapping is usable by guest OS + current application.
378843e1988Sjohnlev   */
379843e1988Sjohnlev #define _GNTMAP_application_map (3)
380843e1988Sjohnlev #define GNTMAP_application_map  (1<<_GNTMAP_application_map)
381843e1988Sjohnlev 
382843e1988Sjohnlev  /*
383843e1988Sjohnlev   * GNTMAP_contains_pte subflag:
384843e1988Sjohnlev   *  0 => This map request contains a host virtual address.
385843e1988Sjohnlev   *  1 => This map request contains the machine addess of the PTE to update.
386843e1988Sjohnlev   */
387843e1988Sjohnlev #define _GNTMAP_contains_pte    (4)
388843e1988Sjohnlev #define GNTMAP_contains_pte     (1<<_GNTMAP_contains_pte)
389843e1988Sjohnlev 
390843e1988Sjohnlev /*
391*349b53ddSStuart Maybee  * Bits to be placed in guest kernel available PTE bits (architecture
392*349b53ddSStuart Maybee  * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
393*349b53ddSStuart Maybee  */
394*349b53ddSStuart Maybee #define _GNTMAP_guest_avail0    (16)
395*349b53ddSStuart Maybee #define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
396*349b53ddSStuart Maybee 
397*349b53ddSStuart Maybee /*
398843e1988Sjohnlev  * Values for error status returns. All errors are -ve.
399843e1988Sjohnlev  */
400843e1988Sjohnlev #define GNTST_okay             (0)  /* Normal return.                        */
401843e1988Sjohnlev #define GNTST_general_error    (-1) /* General undefined error.              */
402843e1988Sjohnlev #define GNTST_bad_domain       (-2) /* Unrecognsed domain id.                */
403843e1988Sjohnlev #define GNTST_bad_gntref       (-3) /* Unrecognised or inappropriate gntref. */
404843e1988Sjohnlev #define GNTST_bad_handle       (-4) /* Unrecognised or inappropriate handle. */
405843e1988Sjohnlev #define GNTST_bad_virt_addr    (-5) /* Inappropriate virtual address to map. */
406843e1988Sjohnlev #define GNTST_bad_dev_addr     (-6) /* Inappropriate device address to unmap.*/
407843e1988Sjohnlev #define GNTST_no_device_space  (-7) /* Out of space in I/O MMU.              */
408843e1988Sjohnlev #define GNTST_permission_denied (-8) /* Not enough privilege for operation.  */
409843e1988Sjohnlev #define GNTST_bad_page         (-9) /* Specified page was invalid for op.    */
410*349b53ddSStuart Maybee #define GNTST_bad_copy_arg    (-10) /* copy arguments cross page boundary.   */
411*349b53ddSStuart Maybee #define GNTST_address_too_big (-11) /* transfer page address too large.      */
412843e1988Sjohnlev 
413843e1988Sjohnlev #define GNTTABOP_error_msgs {                   \
414843e1988Sjohnlev     "okay",                                     \
415843e1988Sjohnlev     "undefined error",                          \
416843e1988Sjohnlev     "unrecognised domain id",                   \
417843e1988Sjohnlev     "invalid grant reference",                  \
418843e1988Sjohnlev     "invalid mapping handle",                   \
419843e1988Sjohnlev     "invalid virtual address",                  \
420843e1988Sjohnlev     "invalid device address",                   \
421843e1988Sjohnlev     "no spare translation slot in the I/O MMU", \
422843e1988Sjohnlev     "permission denied",                        \
423843e1988Sjohnlev     "bad page",                                 \
424*349b53ddSStuart Maybee     "copy arguments cross page boundary",       \
425*349b53ddSStuart Maybee     "page address size too large"               \
426843e1988Sjohnlev }
427843e1988Sjohnlev 
428843e1988Sjohnlev #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
429843e1988Sjohnlev 
430843e1988Sjohnlev /*
431843e1988Sjohnlev  * Local variables:
432843e1988Sjohnlev  * mode: C
433843e1988Sjohnlev  * c-set-style: "BSD"
434843e1988Sjohnlev  * c-basic-offset: 4
435843e1988Sjohnlev  * tab-width: 4
436843e1988Sjohnlev  * indent-tabs-mode: nil
437843e1988Sjohnlev  * End:
438843e1988Sjohnlev  */
439