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