ia64/xen-unstable

view xen/include/public/grant_table.h @ 19836:d9890e67d2b7

tools: add SHAREDIR to buildmakevars2file

c/s 19818 dropped SHAREDIR from xen/util/path.py, which broke the "xm
new" command. This patch adds SHAREDIR back to the new
buildmakevars2file-closure function.

Signed-off-by: Ryan O'Connor <rjo@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 25 13:05:10 2009 +0100 (2009-06-25)
parents aaab04808ee7
children
line source
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 */
28 #ifndef __XEN_PUBLIC_GRANT_TABLE_H__
29 #define __XEN_PUBLIC_GRANT_TABLE_H__
31 #include "xen.h"
33 /***********************************
34 * GRANT TABLE REPRESENTATION
35 */
37 /* Some rough guidelines on accessing and updating grant-table entries
38 * in a concurrency-safe manner. For more information, Linux contains a
39 * reference implementation for guest OSes (arch/xen/kernel/grant_table.c).
40 *
41 * NB. WMB is a no-op on current-generation x86 processors. However, a
42 * compiler barrier will still be required.
43 *
44 * Introducing a valid entry into the grant table:
45 * 1. Write ent->domid.
46 * 2. Write ent->frame:
47 * GTF_permit_access: Frame to which access is permitted.
48 * GTF_accept_transfer: Pseudo-phys frame slot being filled by new
49 * frame, or zero if none.
50 * 3. Write memory barrier (WMB).
51 * 4. Write ent->flags, inc. valid type.
52 *
53 * Invalidating an unused GTF_permit_access entry:
54 * 1. flags = ent->flags.
55 * 2. Observe that !(flags & (GTF_reading|GTF_writing)).
56 * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
57 * NB. No need for WMB as reuse of entry is control-dependent on success of
58 * step 3, and all architectures guarantee ordering of ctrl-dep writes.
59 *
60 * Invalidating an in-use GTF_permit_access entry:
61 * This cannot be done directly. Request assistance from the domain controller
62 * which can set a timeout on the use of a grant entry and take necessary
63 * action. (NB. This is not yet implemented!).
64 *
65 * Invalidating an unused GTF_accept_transfer entry:
66 * 1. flags = ent->flags.
67 * 2. Observe that !(flags & GTF_transfer_committed). [*]
68 * 3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
69 * NB. No need for WMB as reuse of entry is control-dependent on success of
70 * step 3, and all architectures guarantee ordering of ctrl-dep writes.
71 * [*] If GTF_transfer_committed is set then the grant entry is 'committed'.
72 * The guest must /not/ modify the grant entry until the address of the
73 * transferred frame is written. It is safe for the guest to spin waiting
74 * for this to occur (detect by observing GTF_transfer_completed in
75 * ent->flags).
76 *
77 * Invalidating a committed GTF_accept_transfer entry:
78 * 1. Wait for (ent->flags & GTF_transfer_completed).
79 *
80 * Changing a GTF_permit_access from writable to read-only:
81 * Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
82 *
83 * Changing a GTF_permit_access from read-only to writable:
84 * Use SMP-safe bit-setting instruction.
85 */
87 /*
88 * A grant table comprises a packed array of grant entries in one or more
89 * page frames shared between Xen and a guest.
90 * [XEN]: This field is written by Xen and read by the sharing guest.
91 * [GST]: This field is written by the guest and read by Xen.
92 */
93 struct grant_entry {
94 /* GTF_xxx: various type and flag information. [XEN,GST] */
95 uint16_t flags;
96 /* The domain being granted foreign privileges. [GST] */
97 domid_t domid;
98 /*
99 * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
100 * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
101 */
102 uint32_t frame;
103 };
104 typedef struct grant_entry grant_entry_t;
106 /*
107 * Type of grant entry.
108 * GTF_invalid: This grant entry grants no privileges.
109 * GTF_permit_access: Allow @domid to map/access @frame.
110 * GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
111 * to this guest. Xen writes the page number to @frame.
112 */
113 #define GTF_invalid (0U<<0)
114 #define GTF_permit_access (1U<<0)
115 #define GTF_accept_transfer (2U<<0)
116 #define GTF_type_mask (3U<<0)
118 /*
119 * Subflags for GTF_permit_access.
120 * GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
121 * GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
122 * GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
123 * GTF_PAT, GTF_PWT, GTF_PCD: (x86) cache attribute flags for the grant [GST]
124 */
125 #define _GTF_readonly (2)
126 #define GTF_readonly (1U<<_GTF_readonly)
127 #define _GTF_reading (3)
128 #define GTF_reading (1U<<_GTF_reading)
129 #define _GTF_writing (4)
130 #define GTF_writing (1U<<_GTF_writing)
131 #define _GTF_PWT (5)
132 #define GTF_PWT (1U<<_GTF_PWT)
133 #define _GTF_PCD (6)
134 #define GTF_PCD (1U<<_GTF_PCD)
135 #define _GTF_PAT (7)
136 #define GTF_PAT (1U<<_GTF_PAT)
138 /*
139 * Subflags for GTF_accept_transfer:
140 * GTF_transfer_committed: Xen sets this flag to indicate that it is committed
141 * to transferring ownership of a page frame. When a guest sees this flag
142 * it must /not/ modify the grant entry until GTF_transfer_completed is
143 * set by Xen.
144 * GTF_transfer_completed: It is safe for the guest to spin-wait on this flag
145 * after reading GTF_transfer_committed. Xen will always write the frame
146 * address, followed by ORing this flag, in a timely manner.
147 */
148 #define _GTF_transfer_committed (2)
149 #define GTF_transfer_committed (1U<<_GTF_transfer_committed)
150 #define _GTF_transfer_completed (3)
151 #define GTF_transfer_completed (1U<<_GTF_transfer_completed)
154 /***********************************
155 * GRANT TABLE QUERIES AND USES
156 */
158 /*
159 * Reference to a grant entry in a specified domain's grant table.
160 */
161 typedef uint32_t grant_ref_t;
163 /*
164 * Handle to track a mapping created via a grant reference.
165 */
166 typedef uint32_t grant_handle_t;
168 /*
169 * GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
170 * by devices and/or host CPUs. If successful, <handle> is a tracking number
171 * that must be presented later to destroy the mapping(s). On error, <handle>
172 * is a negative status code.
173 * NOTES:
174 * 1. If GNTMAP_device_map is specified then <dev_bus_addr> is the address
175 * via which I/O devices may access the granted frame.
176 * 2. If GNTMAP_host_map is specified then a mapping will be added at
177 * either a host virtual address in the current address space, or at
178 * a PTE at the specified machine address. The type of mapping to
179 * perform is selected through the GNTMAP_contains_pte flag, and the
180 * address is specified in <host_addr>.
181 * 3. Mappings should only be destroyed via GNTTABOP_unmap_grant_ref. If a
182 * host mapping is destroyed by other means then it is *NOT* guaranteed
183 * to be accounted to the correct grant reference!
184 */
185 #define GNTTABOP_map_grant_ref 0
186 struct gnttab_map_grant_ref {
187 /* IN parameters. */
188 uint64_t host_addr;
189 uint32_t flags; /* GNTMAP_* */
190 grant_ref_t ref;
191 domid_t dom;
192 /* OUT parameters. */
193 int16_t status; /* GNTST_* */
194 grant_handle_t handle;
195 uint64_t dev_bus_addr;
196 };
197 typedef struct gnttab_map_grant_ref gnttab_map_grant_ref_t;
198 DEFINE_XEN_GUEST_HANDLE(gnttab_map_grant_ref_t);
200 /*
201 * GNTTABOP_unmap_grant_ref: Destroy one or more grant-reference mappings
202 * tracked by <handle>. If <host_addr> or <dev_bus_addr> is zero, that
203 * field is ignored. If non-zero, they must refer to a device/host mapping
204 * that is tracked by <handle>
205 * NOTES:
206 * 1. The call may fail in an undefined manner if either mapping is not
207 * tracked by <handle>.
208 * 3. After executing a batch of unmaps, it is guaranteed that no stale
209 * mappings will remain in the device or host TLBs.
210 */
211 #define GNTTABOP_unmap_grant_ref 1
212 struct gnttab_unmap_grant_ref {
213 /* IN parameters. */
214 uint64_t host_addr;
215 uint64_t dev_bus_addr;
216 grant_handle_t handle;
217 /* OUT parameters. */
218 int16_t status; /* GNTST_* */
219 };
220 typedef struct gnttab_unmap_grant_ref gnttab_unmap_grant_ref_t;
221 DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_grant_ref_t);
223 /*
224 * GNTTABOP_setup_table: Set up a grant table for <dom> comprising at least
225 * <nr_frames> pages. The frame addresses are written to the <frame_list>.
226 * Only <nr_frames> addresses are written, even if the table is larger.
227 * NOTES:
228 * 1. <dom> may be specified as DOMID_SELF.
229 * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
230 * 3. Xen may not support more than a single grant-table page per domain.
231 */
232 #define GNTTABOP_setup_table 2
233 struct gnttab_setup_table {
234 /* IN parameters. */
235 domid_t dom;
236 uint32_t nr_frames;
237 /* OUT parameters. */
238 int16_t status; /* GNTST_* */
239 XEN_GUEST_HANDLE(ulong) frame_list;
240 };
241 typedef struct gnttab_setup_table gnttab_setup_table_t;
242 DEFINE_XEN_GUEST_HANDLE(gnttab_setup_table_t);
244 /*
245 * GNTTABOP_dump_table: Dump the contents of the grant table to the
246 * xen console. Debugging use only.
247 */
248 #define GNTTABOP_dump_table 3
249 struct gnttab_dump_table {
250 /* IN parameters. */
251 domid_t dom;
252 /* OUT parameters. */
253 int16_t status; /* GNTST_* */
254 };
255 typedef struct gnttab_dump_table gnttab_dump_table_t;
256 DEFINE_XEN_GUEST_HANDLE(gnttab_dump_table_t);
258 /*
259 * GNTTABOP_transfer_grant_ref: Transfer <frame> to a foreign domain. The
260 * foreign domain has previously registered its interest in the transfer via
261 * <domid, ref>.
262 *
263 * Note that, even if the transfer fails, the specified page no longer belongs
264 * to the calling domain *unless* the error is GNTST_bad_page.
265 */
266 #define GNTTABOP_transfer 4
267 struct gnttab_transfer {
268 /* IN parameters. */
269 xen_pfn_t mfn;
270 domid_t domid;
271 grant_ref_t ref;
272 /* OUT parameters. */
273 int16_t status;
274 };
275 typedef struct gnttab_transfer gnttab_transfer_t;
276 DEFINE_XEN_GUEST_HANDLE(gnttab_transfer_t);
279 /*
280 * GNTTABOP_copy: Hypervisor based copy
281 * source and destinations can be eithers MFNs or, for foreign domains,
282 * grant references. the foreign domain has to grant read/write access
283 * in its grant table.
284 *
285 * The flags specify what type source and destinations are (either MFN
286 * or grant reference).
287 *
288 * Note that this can also be used to copy data between two domains
289 * via a third party if the source and destination domains had previously
290 * grant appropriate access to their pages to the third party.
291 *
292 * source_offset specifies an offset in the source frame, dest_offset
293 * the offset in the target frame and len specifies the number of
294 * bytes to be copied.
295 */
297 #define _GNTCOPY_source_gref (0)
298 #define GNTCOPY_source_gref (1<<_GNTCOPY_source_gref)
299 #define _GNTCOPY_dest_gref (1)
300 #define GNTCOPY_dest_gref (1<<_GNTCOPY_dest_gref)
302 #define GNTTABOP_copy 5
303 typedef struct gnttab_copy {
304 /* IN parameters. */
305 struct {
306 union {
307 grant_ref_t ref;
308 xen_pfn_t gmfn;
309 } u;
310 domid_t domid;
311 uint16_t offset;
312 } source, dest;
313 uint16_t len;
314 uint16_t flags; /* GNTCOPY_* */
315 /* OUT parameters. */
316 int16_t status;
317 } gnttab_copy_t;
318 DEFINE_XEN_GUEST_HANDLE(gnttab_copy_t);
320 /*
321 * GNTTABOP_query_size: Query the current and maximum sizes of the shared
322 * grant table.
323 * NOTES:
324 * 1. <dom> may be specified as DOMID_SELF.
325 * 2. Only a sufficiently-privileged domain may specify <dom> != DOMID_SELF.
326 */
327 #define GNTTABOP_query_size 6
328 struct gnttab_query_size {
329 /* IN parameters. */
330 domid_t dom;
331 /* OUT parameters. */
332 uint32_t nr_frames;
333 uint32_t max_nr_frames;
334 int16_t status; /* GNTST_* */
335 };
336 typedef struct gnttab_query_size gnttab_query_size_t;
337 DEFINE_XEN_GUEST_HANDLE(gnttab_query_size_t);
339 /*
340 * GNTTABOP_unmap_and_replace: Destroy one or more grant-reference mappings
341 * tracked by <handle> but atomically replace the page table entry with one
342 * pointing to the machine address under <new_addr>. <new_addr> will be
343 * redirected to the null entry.
344 * NOTES:
345 * 1. The call may fail in an undefined manner if either mapping is not
346 * tracked by <handle>.
347 * 2. After executing a batch of unmaps, it is guaranteed that no stale
348 * mappings will remain in the device or host TLBs.
349 */
350 #define GNTTABOP_unmap_and_replace 7
351 struct gnttab_unmap_and_replace {
352 /* IN parameters. */
353 uint64_t host_addr;
354 uint64_t new_addr;
355 grant_handle_t handle;
356 /* OUT parameters. */
357 int16_t status; /* GNTST_* */
358 };
359 typedef struct gnttab_unmap_and_replace gnttab_unmap_and_replace_t;
360 DEFINE_XEN_GUEST_HANDLE(gnttab_unmap_and_replace_t);
363 /*
364 * Bitfield values for gnttab_map_grant_ref.flags.
365 */
366 /* Map the grant entry for access by I/O devices. */
367 #define _GNTMAP_device_map (0)
368 #define GNTMAP_device_map (1<<_GNTMAP_device_map)
369 /* Map the grant entry for access by host CPUs. */
370 #define _GNTMAP_host_map (1)
371 #define GNTMAP_host_map (1<<_GNTMAP_host_map)
372 /* Accesses to the granted frame will be restricted to read-only access. */
373 #define _GNTMAP_readonly (2)
374 #define GNTMAP_readonly (1<<_GNTMAP_readonly)
375 /*
376 * GNTMAP_host_map subflag:
377 * 0 => The host mapping is usable only by the guest OS.
378 * 1 => The host mapping is usable by guest OS + current application.
379 */
380 #define _GNTMAP_application_map (3)
381 #define GNTMAP_application_map (1<<_GNTMAP_application_map)
383 /*
384 * GNTMAP_contains_pte subflag:
385 * 0 => This map request contains a host virtual address.
386 * 1 => This map request contains the machine addess of the PTE to update.
387 */
388 #define _GNTMAP_contains_pte (4)
389 #define GNTMAP_contains_pte (1<<_GNTMAP_contains_pte)
391 /*
392 * Bits to be placed in guest kernel available PTE bits (architecture
393 * dependent; only supported when XENFEAT_gnttab_map_avail_bits is set).
394 */
395 #define _GNTMAP_guest_avail0 (16)
396 #define GNTMAP_guest_avail_mask ((uint32_t)~0 << _GNTMAP_guest_avail0)
398 /*
399 * Values for error status returns. All errors are -ve.
400 */
401 #define GNTST_okay (0) /* Normal return. */
402 #define GNTST_general_error (-1) /* General undefined error. */
403 #define GNTST_bad_domain (-2) /* Unrecognsed domain id. */
404 #define GNTST_bad_gntref (-3) /* Unrecognised or inappropriate gntref. */
405 #define GNTST_bad_handle (-4) /* Unrecognised or inappropriate handle. */
406 #define GNTST_bad_virt_addr (-5) /* Inappropriate virtual address to map. */
407 #define GNTST_bad_dev_addr (-6) /* Inappropriate device address to unmap.*/
408 #define GNTST_no_device_space (-7) /* Out of space in I/O MMU. */
409 #define GNTST_permission_denied (-8) /* Not enough privilege for operation. */
410 #define GNTST_bad_page (-9) /* Specified page was invalid for op. */
411 #define GNTST_bad_copy_arg (-10) /* copy arguments cross page boundary. */
412 #define GNTST_address_too_big (-11) /* transfer page address too large. */
414 #define GNTTABOP_error_msgs { \
415 "okay", \
416 "undefined error", \
417 "unrecognised domain id", \
418 "invalid grant reference", \
419 "invalid mapping handle", \
420 "invalid virtual address", \
421 "invalid device address", \
422 "no spare translation slot in the I/O MMU", \
423 "permission denied", \
424 "bad page", \
425 "copy arguments cross page boundary", \
426 "page address size too large" \
427 }
429 #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
431 /*
432 * Local variables:
433 * mode: C
434 * c-set-style: "BSD"
435 * c-basic-offset: 4
436 * tab-width: 4
437 * indent-tabs-mode: nil
438 * End:
439 */