grant_table.h 24 KB

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