xref: /freebsd/sys/contrib/xen/io/libxenvchan.h (revision 3a9fd8242b35884921dfc4e886f284a75870a536)
1*3a9fd824SRoger Pau Monné /**
2*3a9fd824SRoger Pau Monné  * @file
3*3a9fd824SRoger Pau Monné  * @section AUTHORS
4*3a9fd824SRoger Pau Monné  *
5*3a9fd824SRoger Pau Monné  * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
6*3a9fd824SRoger Pau Monné  *
7*3a9fd824SRoger Pau Monné  *  Authors:
8*3a9fd824SRoger Pau Monné  *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
9*3a9fd824SRoger Pau Monné  *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
10*3a9fd824SRoger Pau Monné  *
11*3a9fd824SRoger Pau Monné  * @section LICENSE
12*3a9fd824SRoger Pau Monné  *
13*3a9fd824SRoger Pau Monné  * Permission is hereby granted, free of charge, to any person obtaining a copy
14*3a9fd824SRoger Pau Monné  * of this software and associated documentation files (the "Software"), to
15*3a9fd824SRoger Pau Monné  * deal in the Software without restriction, including without limitation the
16*3a9fd824SRoger Pau Monné  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
17*3a9fd824SRoger Pau Monné  * sell copies of the Software, and to permit persons to whom the Software is
18*3a9fd824SRoger Pau Monné  * furnished to do so, subject to the following conditions:
19*3a9fd824SRoger Pau Monné  *
20*3a9fd824SRoger Pau Monné  * The above copyright notice and this permission notice shall be included in
21*3a9fd824SRoger Pau Monné  * all copies or substantial portions of the Software.
22*3a9fd824SRoger Pau Monné  *
23*3a9fd824SRoger Pau Monné  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24*3a9fd824SRoger Pau Monné  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25*3a9fd824SRoger Pau Monné  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26*3a9fd824SRoger Pau Monné  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27*3a9fd824SRoger Pau Monné  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28*3a9fd824SRoger Pau Monné  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29*3a9fd824SRoger Pau Monné  * DEALINGS IN THE SOFTWARE.
30*3a9fd824SRoger Pau Monné  *
31*3a9fd824SRoger Pau Monné  * @section DESCRIPTION
32*3a9fd824SRoger Pau Monné  *
33*3a9fd824SRoger Pau Monné  *  Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,
34*3a9fd824SRoger Pau Monné  *  this code has been substantially rewritten to use the gntdev and gntalloc
35*3a9fd824SRoger Pau Monné  *  devices instead of raw MFNs and map_foreign_range.
36*3a9fd824SRoger Pau Monné  *
37*3a9fd824SRoger Pau Monné  *  This is a library for inter-domain communication.  A standard Xen ring
38*3a9fd824SRoger Pau Monné  *  buffer is used, with a datagram-based interface built on top.  The grant
39*3a9fd824SRoger Pau Monné  *  reference and event channels are shared in XenStore under a user-specified
40*3a9fd824SRoger Pau Monné  *  path.
41*3a9fd824SRoger Pau Monné  *
42*3a9fd824SRoger Pau Monné  *  The ring.h macros define an asymmetric interface to a shared data structure
43*3a9fd824SRoger Pau Monné  *  that assumes all rings reside in a single contiguous memory space. This is
44*3a9fd824SRoger Pau Monné  *  not suitable for vchan because the interface to the ring is symmetric except
45*3a9fd824SRoger Pau Monné  *  for the setup. Unlike the producer-consumer rings defined in ring.h, the
46*3a9fd824SRoger Pau Monné  *  size of the rings used in vchan are determined at execution time instead of
47*3a9fd824SRoger Pau Monné  *  compile time, so the macros in ring.h cannot be used to access the rings.
48*3a9fd824SRoger Pau Monné  */
49*3a9fd824SRoger Pau Monné 
50*3a9fd824SRoger Pau Monné #include <stdint.h>
51*3a9fd824SRoger Pau Monné #include <sys/types.h>
52*3a9fd824SRoger Pau Monné 
53*3a9fd824SRoger Pau Monné struct ring_shared {
54*3a9fd824SRoger Pau Monné 	uint32_t cons, prod;
55*3a9fd824SRoger Pau Monné };
56*3a9fd824SRoger Pau Monné 
57*3a9fd824SRoger Pau Monné #define VCHAN_NOTIFY_WRITE 0x1
58*3a9fd824SRoger Pau Monné #define VCHAN_NOTIFY_READ 0x2
59*3a9fd824SRoger Pau Monné 
60*3a9fd824SRoger Pau Monné /**
61*3a9fd824SRoger Pau Monné  * vchan_interface: primary shared data structure
62*3a9fd824SRoger Pau Monné  */
63*3a9fd824SRoger Pau Monné struct vchan_interface {
64*3a9fd824SRoger Pau Monné 	/**
65*3a9fd824SRoger Pau Monné 	 * Standard consumer/producer interface, one pair per buffer
66*3a9fd824SRoger Pau Monné 	 * left is client write, server read
67*3a9fd824SRoger Pau Monné 	 * right is client read, server write
68*3a9fd824SRoger Pau Monné 	 */
69*3a9fd824SRoger Pau Monné 	struct ring_shared left, right;
70*3a9fd824SRoger Pau Monné 	/**
71*3a9fd824SRoger Pau Monné 	 * size of the rings, which determines their location
72*3a9fd824SRoger Pau Monné 	 * 10   - at offset 1024 in ring's page
73*3a9fd824SRoger Pau Monné 	 * 11   - at offset 2048 in ring's page
74*3a9fd824SRoger Pau Monné 	 * 12+  - uses 2^(N-12) grants to describe the multi-page ring
75*3a9fd824SRoger Pau Monné 	 * These should remain constant once the page is shared.
76*3a9fd824SRoger Pau Monné 	 * Only one of the two orders can be 10 (or 11).
77*3a9fd824SRoger Pau Monné 	 */
78*3a9fd824SRoger Pau Monné 	uint16_t left_order, right_order;
79*3a9fd824SRoger Pau Monné 	/**
80*3a9fd824SRoger Pau Monné 	 * Shutdown detection:
81*3a9fd824SRoger Pau Monné 	 *  0: client (or server) has exited
82*3a9fd824SRoger Pau Monné 	 *  1: client (or server) is connected
83*3a9fd824SRoger Pau Monné 	 *  2: client has not yet connected
84*3a9fd824SRoger Pau Monné 	 */
85*3a9fd824SRoger Pau Monné 	uint8_t cli_live, srv_live;
86*3a9fd824SRoger Pau Monné 	/**
87*3a9fd824SRoger Pau Monné 	 * Notification bits:
88*3a9fd824SRoger Pau Monné 	 *  VCHAN_NOTIFY_WRITE: send notify when data is written
89*3a9fd824SRoger Pau Monné 	 *  VCHAN_NOTIFY_READ: send notify when data is read (consumed)
90*3a9fd824SRoger Pau Monné 	 * cli_notify is used for the client to inform the server of its action
91*3a9fd824SRoger Pau Monné 	 */
92*3a9fd824SRoger Pau Monné 	uint8_t cli_notify, srv_notify;
93*3a9fd824SRoger Pau Monné 	/**
94*3a9fd824SRoger Pau Monné 	 * Grant list: ordering is left, right. Must not extend into actual ring
95*3a9fd824SRoger Pau Monné 	 * or grow beyond the end of the initial shared page.
96*3a9fd824SRoger Pau Monné 	 * These should remain constant once the page is shared, to allow
97*3a9fd824SRoger Pau Monné 	 * for possible remapping by a client that restarts.
98*3a9fd824SRoger Pau Monné 	 */
99*3a9fd824SRoger Pau Monné 	uint32_t grants[0];
100*3a9fd824SRoger Pau Monné };
101*3a9fd824SRoger Pau Monné 
102