1251767Sgibbs/**
2251767Sgibbs * @file
3251767Sgibbs * @section AUTHORS
4251767Sgibbs *
5251767Sgibbs * Copyright (C) 2010  Rafal Wojtczuk  <rafal@invisiblethingslab.com>
6251767Sgibbs *
7251767Sgibbs *  Authors:
8251767Sgibbs *       Rafal Wojtczuk  <rafal@invisiblethingslab.com>
9251767Sgibbs *       Daniel De Graaf <dgdegra@tycho.nsa.gov>
10251767Sgibbs *
11251767Sgibbs * @section LICENSE
12251767Sgibbs *
13251767Sgibbs *  This library is free software; you can redistribute it and/or
14251767Sgibbs *  modify it under the terms of the GNU Lesser General Public
15251767Sgibbs *  License as published by the Free Software Foundation; either
16251767Sgibbs *  version 2.1 of the License, or (at your option) any later version.
17251767Sgibbs *
18251767Sgibbs *  This library is distributed in the hope that it will be useful,
19251767Sgibbs *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20251767Sgibbs *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21251767Sgibbs *  Lesser General Public License for more details.
22251767Sgibbs *
23251767Sgibbs *  You should have received a copy of the GNU Lesser General Public
24251767Sgibbs *  License along with this library; if not, write to the Free Software
25251767Sgibbs *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
26251767Sgibbs *
27251767Sgibbs * @section DESCRIPTION
28251767Sgibbs *
29251767Sgibbs *  Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,
30251767Sgibbs *  this code has been substantially rewritten to use the gntdev and gntalloc
31251767Sgibbs *  devices instead of raw MFNs and map_foreign_range.
32251767Sgibbs *
33251767Sgibbs *  This is a library for inter-domain communication.  A standard Xen ring
34251767Sgibbs *  buffer is used, with a datagram-based interface built on top.  The grant
35251767Sgibbs *  reference and event channels are shared in XenStore under a user-specified
36251767Sgibbs *  path.
37251767Sgibbs *
38251767Sgibbs *  The ring.h macros define an asymmetric interface to a shared data structure
39251767Sgibbs *  that assumes all rings reside in a single contiguous memory space. This is
40251767Sgibbs *  not suitable for vchan because the interface to the ring is symmetric except
41251767Sgibbs *  for the setup. Unlike the producer-consumer rings defined in ring.h, the
42251767Sgibbs *  size of the rings used in vchan are determined at execution time instead of
43251767Sgibbs *  compile time, so the macros in ring.h cannot be used to access the rings.
44251767Sgibbs */
45251767Sgibbs
46251767Sgibbs#include <stdint.h>
47251767Sgibbs#include <sys/types.h>
48251767Sgibbs
49251767Sgibbsstruct ring_shared {
50251767Sgibbs	uint32_t cons, prod;
51251767Sgibbs};
52251767Sgibbs
53251767Sgibbs#define VCHAN_NOTIFY_WRITE 0x1
54251767Sgibbs#define VCHAN_NOTIFY_READ 0x2
55251767Sgibbs
56251767Sgibbs/**
57251767Sgibbs * vchan_interface: primary shared data structure
58251767Sgibbs */
59251767Sgibbsstruct vchan_interface {
60251767Sgibbs	/**
61251767Sgibbs	 * Standard consumer/producer interface, one pair per buffer
62251767Sgibbs	 * left is client write, server read
63251767Sgibbs	 * right is client read, server write
64251767Sgibbs	 */
65251767Sgibbs	struct ring_shared left, right;
66251767Sgibbs	/**
67251767Sgibbs	 * size of the rings, which determines their location
68251767Sgibbs	 * 10   - at offset 1024 in ring's page
69251767Sgibbs	 * 11   - at offset 2048 in ring's page
70251767Sgibbs	 * 12+  - uses 2^(N-12) grants to describe the multi-page ring
71251767Sgibbs	 * These should remain constant once the page is shared.
72251767Sgibbs	 * Only one of the two orders can be 10 (or 11).
73251767Sgibbs	 */
74251767Sgibbs	uint16_t left_order, right_order;
75251767Sgibbs	/**
76251767Sgibbs	 * Shutdown detection:
77251767Sgibbs	 *  0: client (or server) has exited
78251767Sgibbs	 *  1: client (or server) is connected
79251767Sgibbs	 *  2: client has not yet connected
80251767Sgibbs	 */
81251767Sgibbs	uint8_t cli_live, srv_live;
82251767Sgibbs	/**
83251767Sgibbs	 * Notification bits:
84251767Sgibbs	 *  VCHAN_NOTIFY_WRITE: send notify when data is written
85251767Sgibbs	 *  VCHAN_NOTIFY_READ: send notify when data is read (consumed)
86251767Sgibbs	 * cli_notify is used for the client to inform the server of its action
87251767Sgibbs	 */
88251767Sgibbs	uint8_t cli_notify, srv_notify;
89251767Sgibbs	/**
90251767Sgibbs	 * Grant list: ordering is left, right. Must not extend into actual ring
91251767Sgibbs	 * or grow beyond the end of the initial shared page.
92251767Sgibbs	 * These should remain constant once the page is shared, to allow
93251767Sgibbs	 * for possible remapping by a client that restarts.
94251767Sgibbs	 */
95251767Sgibbs	uint32_t grants[0];
96251767Sgibbs};
97251767Sgibbs
98