grant_table.h 24 KB

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