argo.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /******************************************************************************
  2. * Argo : Hypervisor-Mediated data eXchange
  3. *
  4. * Derived from v4v, the version 2 of v2v.
  5. *
  6. * Copyright (c) 2010, Citrix Systems
  7. * Copyright (c) 2018-2019, BAE Systems
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to
  11. * deal in the Software without restriction, including without limitation the
  12. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  13. * sell copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. */
  28. #ifndef __XEN_PUBLIC_ARGO_H__
  29. #define __XEN_PUBLIC_ARGO_H__
  30. #include "xen.h"
  31. #define XEN_ARGO_DOMID_ANY DOMID_INVALID
  32. /* The maximum size of an Argo ring is defined to be: 16MB (0x1000000 bytes). */
  33. #define XEN_ARGO_MAX_RING_SIZE (0x1000000ULL)
  34. /* Fixed-width type for "argo port" number. Nothing to do with evtchns. */
  35. typedef uint32_t xen_argo_port_t;
  36. /* gfn type: 64-bit fixed-width on all architectures */
  37. typedef uint64_t xen_argo_gfn_t;
  38. /*
  39. * XEN_ARGO_MAXIOV : maximum number of iovs accepted in a single sendv.
  40. * Caution is required if this value is increased: this determines the size of
  41. * an array of xen_argo_iov_t structs on the hypervisor stack, so could cause
  42. * stack overflow if the value is too large.
  43. * The Linux Argo driver never passes more than two iovs.
  44. */
  45. #define XEN_ARGO_MAXIOV 8U
  46. typedef struct xen_argo_iov
  47. {
  48. XEN_GUEST_HANDLE(uint8) iov_hnd;
  49. uint32_t iov_len;
  50. uint32_t pad;
  51. } xen_argo_iov_t;
  52. typedef struct xen_argo_addr
  53. {
  54. xen_argo_port_t aport;
  55. domid_t domain_id;
  56. uint16_t pad;
  57. } xen_argo_addr_t;
  58. typedef struct xen_argo_send_addr
  59. {
  60. struct xen_argo_addr src;
  61. struct xen_argo_addr dst;
  62. } xen_argo_send_addr_t;
  63. typedef struct xen_argo_ring
  64. {
  65. /* Guests should use atomic operations to access rx_ptr */
  66. uint32_t rx_ptr;
  67. /* Guests should use atomic operations to access tx_ptr */
  68. uint32_t tx_ptr;
  69. /*
  70. * Header space reserved for later use. Align the start of the ring to a
  71. * multiple of the message slot size.
  72. */
  73. uint8_t reserved[56];
  74. uint8_t ring[XEN_FLEX_ARRAY_DIM];
  75. } xen_argo_ring_t;
  76. typedef struct xen_argo_register_ring
  77. {
  78. xen_argo_port_t aport;
  79. domid_t partner_id;
  80. uint16_t pad;
  81. uint32_t len;
  82. } xen_argo_register_ring_t;
  83. typedef struct xen_argo_unregister_ring
  84. {
  85. xen_argo_port_t aport;
  86. domid_t partner_id;
  87. uint16_t pad;
  88. } xen_argo_unregister_ring_t;
  89. /* Messages on the ring are padded to a multiple of this size. */
  90. #define XEN_ARGO_MSG_SLOT_SIZE 0x10
  91. /*
  92. * Notify flags
  93. */
  94. /* Ring exists */
  95. #define XEN_ARGO_RING_EXISTS (1U << 0)
  96. /* Ring is shared, not unicast */
  97. #define XEN_ARGO_RING_SHARED (1U << 1)
  98. /* Ring is empty */
  99. #define XEN_ARGO_RING_EMPTY (1U << 2)
  100. /* Sufficient space to queue space_required bytes might exist */
  101. #define XEN_ARGO_RING_SUFFICIENT (1U << 3)
  102. /* Insufficient ring size for space_required bytes */
  103. #define XEN_ARGO_RING_EMSGSIZE (1U << 4)
  104. /* Too many domains waiting for available space signals for this ring */
  105. #define XEN_ARGO_RING_EBUSY (1U << 5)
  106. typedef struct xen_argo_ring_data_ent
  107. {
  108. struct xen_argo_addr ring;
  109. uint16_t flags;
  110. uint16_t pad;
  111. uint32_t space_required;
  112. uint32_t max_message_size;
  113. } xen_argo_ring_data_ent_t;
  114. typedef struct xen_argo_ring_data
  115. {
  116. uint32_t nent;
  117. uint32_t pad;
  118. struct xen_argo_ring_data_ent data[XEN_FLEX_ARRAY_DIM];
  119. } xen_argo_ring_data_t;
  120. struct xen_argo_ring_message_header
  121. {
  122. uint32_t len;
  123. struct xen_argo_addr source;
  124. uint32_t message_type;
  125. uint8_t data[XEN_FLEX_ARRAY_DIM];
  126. };
  127. /*
  128. * Hypercall operations
  129. */
  130. /*
  131. * XEN_ARGO_OP_register_ring
  132. *
  133. * Register a ring using the guest-supplied memory pages.
  134. * Also used to reregister an existing ring (eg. after resume from hibernate).
  135. *
  136. * The first argument struct indicates the port number for the ring to register
  137. * and the partner domain, if any, that is to be allowed to send to the ring.
  138. * A wildcard (XEN_ARGO_DOMID_ANY) may be supplied instead of a partner domid,
  139. * and if the hypervisor has wildcard sender rings enabled, this will allow
  140. * any domain (XSM notwithstanding) to send to the ring.
  141. *
  142. * The second argument is an array of guest frame numbers and the third argument
  143. * indicates the size of the array. This operation only supports 4K-sized pages.
  144. *
  145. * arg1: XEN_GUEST_HANDLE(xen_argo_register_ring_t)
  146. * arg2: XEN_GUEST_HANDLE(xen_argo_gfn_t)
  147. * arg3: unsigned long npages
  148. * arg4: unsigned long flags (32-bit value)
  149. */
  150. #define XEN_ARGO_OP_register_ring 1
  151. /* Register op flags */
  152. /*
  153. * Fail exist:
  154. * If set, reject attempts to (re)register an existing established ring.
  155. * If clear, reregistration occurs if the ring exists, with the new ring
  156. * taking the place of the old, preserving tx_ptr if it remains valid.
  157. */
  158. #define XEN_ARGO_REGISTER_FLAG_FAIL_EXIST 0x1
  159. #ifdef __XEN__
  160. /* Mask for all defined flags. */
  161. #define XEN_ARGO_REGISTER_FLAG_MASK XEN_ARGO_REGISTER_FLAG_FAIL_EXIST
  162. #endif
  163. /*
  164. * XEN_ARGO_OP_unregister_ring
  165. *
  166. * Unregister a previously-registered ring, ending communication.
  167. *
  168. * arg1: XEN_GUEST_HANDLE(xen_argo_unregister_ring_t)
  169. * arg2: NULL
  170. * arg3: 0 (ZERO)
  171. * arg4: 0 (ZERO)
  172. */
  173. #define XEN_ARGO_OP_unregister_ring 2
  174. /*
  175. * XEN_ARGO_OP_sendv
  176. *
  177. * Send a list of buffers contained in iovs.
  178. *
  179. * The send address struct specifies the source and destination addresses
  180. * for the message being sent, which are used to find the destination ring:
  181. * Xen first looks for a most-specific match with a registered ring with
  182. * (id.addr == dst) and (id.partner == sending_domain) ;
  183. * if that fails, it then looks for a wildcard match (aka multicast receiver)
  184. * where (id.addr == dst) and (id.partner == DOMID_ANY).
  185. *
  186. * For each iov entry, send iov_len bytes from iov_base to the destination ring.
  187. * If insufficient space exists in the destination ring, it will return -EAGAIN
  188. * and Xen will notify the caller when sufficient space becomes available.
  189. *
  190. * The message type is a 32-bit data field available to communicate message
  191. * context data (eg. kernel-to-kernel, rather than application layer).
  192. *
  193. * arg1: XEN_GUEST_HANDLE(xen_argo_send_addr_t) source and dest addresses
  194. * arg2: XEN_GUEST_HANDLE(xen_argo_iov_t) iovs
  195. * arg3: unsigned long niov
  196. * arg4: unsigned long message type (32-bit value)
  197. */
  198. #define XEN_ARGO_OP_sendv 3
  199. /*
  200. * XEN_ARGO_OP_notify
  201. *
  202. * Asks Xen for information about other rings in the system.
  203. *
  204. * ent->ring is the xen_argo_addr_t of the ring you want information on.
  205. * Uses the same ring matching rules as XEN_ARGO_OP_sendv.
  206. *
  207. * ent->space_required : if this field is not null then Xen will check
  208. * that there is space in the destination ring for this many bytes of payload.
  209. * If the ring is too small for the requested space_required, it will set the
  210. * XEN_ARGO_RING_EMSGSIZE flag on return.
  211. * If sufficient space is available, it will set XEN_ARGO_RING_SUFFICIENT
  212. * and CANCEL any pending notification for that ent->ring; otherwise it
  213. * will schedule a notification event and the flag will not be set.
  214. *
  215. * These flags are set by Xen when notify replies:
  216. * XEN_ARGO_RING_EXISTS ring exists
  217. * XEN_ARGO_RING_SHARED ring is registered for wildcard partner
  218. * XEN_ARGO_RING_EMPTY ring is empty
  219. * XEN_ARGO_RING_SUFFICIENT sufficient space for space_required is there
  220. * XEN_ARGO_RING_EMSGSIZE space_required is too large for the ring size
  221. * XEN_ARGO_RING_EBUSY too many domains waiting for available space signals
  222. *
  223. * arg1: XEN_GUEST_HANDLE(xen_argo_ring_data_t) ring_data (may be NULL)
  224. * arg2: NULL
  225. * arg3: 0 (ZERO)
  226. * arg4: 0 (ZERO)
  227. */
  228. #define XEN_ARGO_OP_notify 4
  229. #endif