1 /******************************************************************************
2 * Argo : Hypervisor-Mediated data eXchange
4 * Derived from v4v, the version 2 of v2v.
6 * Copyright (c) 2010, Citrix Systems
7 * Copyright (c) 2018-2019, BAE Systems
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
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.
29 #ifndef __XEN_PUBLIC_ARGO_H__
30 #define __XEN_PUBLIC_ARGO_H__
34 #define XEN_ARGO_DOMID_ANY DOMID_INVALID
36 /* The maximum size of an Argo ring is defined to be: 16MB (0x1000000 bytes). */
37 #define XEN_ARGO_MAX_RING_SIZE (0x1000000ULL)
39 /* Fixed-width type for "argo port" number. Nothing to do with evtchns. */
40 typedef uint32_t xen_argo_port_t;
42 /* gfn type: 64-bit fixed-width on all architectures */
43 typedef uint64_t xen_argo_gfn_t;
46 * XEN_ARGO_MAXIOV : maximum number of iovs accepted in a single sendv.
47 * Caution is required if this value is increased: this determines the size of
48 * an array of xen_argo_iov_t structs on the hypervisor stack, so could cause
49 * stack overflow if the value is too large.
50 * The Linux Argo driver never passes more than two iovs.
52 #define XEN_ARGO_MAXIOV 8U
54 typedef struct xen_argo_iov
56 XEN_GUEST_HANDLE(uint8) iov_hnd;
61 typedef struct xen_argo_addr
63 xen_argo_port_t aport;
68 typedef struct xen_argo_send_addr
70 struct xen_argo_addr src;
71 struct xen_argo_addr dst;
72 } xen_argo_send_addr_t;
74 typedef struct xen_argo_ring
76 /* Guests should use atomic operations to access rx_ptr */
78 /* Guests should use atomic operations to access tx_ptr */
81 * Header space reserved for later use. Align the start of the ring to a
82 * multiple of the message slot size.
85 uint8_t ring[XEN_FLEX_ARRAY_DIM];
88 typedef struct xen_argo_register_ring
90 xen_argo_port_t aport;
94 } xen_argo_register_ring_t;
96 typedef struct xen_argo_unregister_ring
98 xen_argo_port_t aport;
101 } xen_argo_unregister_ring_t;
103 /* Messages on the ring are padded to a multiple of this size. */
104 #define XEN_ARGO_MSG_SLOT_SIZE 0x10
110 #define XEN_ARGO_RING_EXISTS (1U << 0)
111 /* Ring is shared, not unicast */
112 #define XEN_ARGO_RING_SHARED (1U << 1)
114 #define XEN_ARGO_RING_EMPTY (1U << 2)
115 /* Sufficient space to queue space_required bytes might exist */
116 #define XEN_ARGO_RING_SUFFICIENT (1U << 3)
117 /* Insufficient ring size for space_required bytes */
118 #define XEN_ARGO_RING_EMSGSIZE (1U << 4)
119 /* Too many domains waiting for available space signals for this ring */
120 #define XEN_ARGO_RING_EBUSY (1U << 5)
122 typedef struct xen_argo_ring_data_ent
124 struct xen_argo_addr ring;
127 uint32_t space_required;
128 uint32_t max_message_size;
129 } xen_argo_ring_data_ent_t;
131 typedef struct xen_argo_ring_data
135 struct xen_argo_ring_data_ent data[XEN_FLEX_ARRAY_DIM];
136 } xen_argo_ring_data_t;
138 struct xen_argo_ring_message_header
141 struct xen_argo_addr source;
142 uint32_t message_type;
143 uint8_t data[XEN_FLEX_ARRAY_DIM];
147 * Hypercall operations
151 * XEN_ARGO_OP_register_ring
153 * Register a ring using the guest-supplied memory pages.
154 * Also used to reregister an existing ring (eg. after resume from hibernate).
156 * The first argument struct indicates the port number for the ring to register
157 * and the partner domain, if any, that is to be allowed to send to the ring.
158 * A wildcard (XEN_ARGO_DOMID_ANY) may be supplied instead of a partner domid,
159 * and if the hypervisor has wildcard sender rings enabled, this will allow
160 * any domain (XSM notwithstanding) to send to the ring.
162 * The second argument is an array of guest frame numbers and the third argument
163 * indicates the size of the array. This operation only supports 4K-sized pages.
165 * arg1: XEN_GUEST_HANDLE(xen_argo_register_ring_t)
166 * arg2: XEN_GUEST_HANDLE(xen_argo_gfn_t)
167 * arg3: unsigned long npages
168 * arg4: unsigned long flags (32-bit value)
170 #define XEN_ARGO_OP_register_ring 1
172 /* Register op flags */
175 * If set, reject attempts to (re)register an existing established ring.
176 * If clear, reregistration occurs if the ring exists, with the new ring
177 * taking the place of the old, preserving tx_ptr if it remains valid.
179 #define XEN_ARGO_REGISTER_FLAG_FAIL_EXIST 0x1
182 /* Mask for all defined flags. */
183 #define XEN_ARGO_REGISTER_FLAG_MASK XEN_ARGO_REGISTER_FLAG_FAIL_EXIST
187 * XEN_ARGO_OP_unregister_ring
189 * Unregister a previously-registered ring, ending communication.
191 * arg1: XEN_GUEST_HANDLE(xen_argo_unregister_ring_t)
196 #define XEN_ARGO_OP_unregister_ring 2
201 * Send a list of buffers contained in iovs.
203 * The send address struct specifies the source and destination addresses
204 * for the message being sent, which are used to find the destination ring:
205 * Xen first looks for a most-specific match with a registered ring with
206 * (id.addr == dst) and (id.partner == sending_domain) ;
207 * if that fails, it then looks for a wildcard match (aka multicast receiver)
208 * where (id.addr == dst) and (id.partner == DOMID_ANY).
210 * For each iov entry, send iov_len bytes from iov_base to the destination ring.
211 * If insufficient space exists in the destination ring, it will return -EAGAIN
212 * and Xen will notify the caller when sufficient space becomes available.
214 * The message type is a 32-bit data field available to communicate message
215 * context data (eg. kernel-to-kernel, rather than application layer).
217 * arg1: XEN_GUEST_HANDLE(xen_argo_send_addr_t) source and dest addresses
218 * arg2: XEN_GUEST_HANDLE(xen_argo_iov_t) iovs
219 * arg3: unsigned long niov
220 * arg4: unsigned long message type (32-bit value)
222 #define XEN_ARGO_OP_sendv 3
227 * Asks Xen for information about other rings in the system.
229 * ent->ring is the xen_argo_addr_t of the ring you want information on.
230 * Uses the same ring matching rules as XEN_ARGO_OP_sendv.
232 * ent->space_required : if this field is not null then Xen will check
233 * that there is space in the destination ring for this many bytes of payload.
234 * If the ring is too small for the requested space_required, it will set the
235 * XEN_ARGO_RING_EMSGSIZE flag on return.
236 * If sufficient space is available, it will set XEN_ARGO_RING_SUFFICIENT
237 * and CANCEL any pending notification for that ent->ring; otherwise it
238 * will schedule a notification event and the flag will not be set.
240 * These flags are set by Xen when notify replies:
241 * XEN_ARGO_RING_EXISTS ring exists
242 * XEN_ARGO_RING_SHARED ring is registered for wildcard partner
243 * XEN_ARGO_RING_EMPTY ring is empty
244 * XEN_ARGO_RING_SUFFICIENT sufficient space for space_required is there
245 * XEN_ARGO_RING_EMSGSIZE space_required is too large for the ring size
246 * XEN_ARGO_RING_EBUSY too many domains waiting for available space signals
248 * arg1: XEN_GUEST_HANDLE(xen_argo_ring_data_t) ring_data (may be NULL)
253 #define XEN_ARGO_OP_notify 4