You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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