/**1* @file2* @section AUTHORS3*4* Copyright (C) 2010 Rafal Wojtczuk <[email protected]>5*6* Authors:7* Rafal Wojtczuk <[email protected]>8* Daniel De Graaf <[email protected]>9*10* @section LICENSE11*12* Permission is hereby granted, free of charge, to any person obtaining a copy13* of this software and associated documentation files (the "Software"), to14* deal in the Software without restriction, including without limitation the15* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or16* sell copies of the Software, and to permit persons to whom the Software is17* furnished to do so, subject to the following conditions:18*19* The above copyright notice and this permission notice shall be included in20* all copies or substantial portions of the Software.21*22* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR23* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,24* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE25* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER26* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING27* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER28* DEALINGS IN THE SOFTWARE.29*30* @section DESCRIPTION31*32* Originally borrowed from the Qubes OS Project, http://www.qubes-os.org,33* this code has been substantially rewritten to use the gntdev and gntalloc34* devices instead of raw MFNs and map_foreign_range.35*36* This is a library for inter-domain communication. A standard Xen ring37* buffer is used, with a datagram-based interface built on top. The grant38* reference and event channels are shared in XenStore under a user-specified39* path.40*41* The ring.h macros define an asymmetric interface to a shared data structure42* that assumes all rings reside in a single contiguous memory space. This is43* not suitable for vchan because the interface to the ring is symmetric except44* for the setup. Unlike the producer-consumer rings defined in ring.h, the45* size of the rings used in vchan are determined at execution time instead of46* compile time, so the macros in ring.h cannot be used to access the rings.47*/4849#include <stdint.h>50#include <sys/types.h>5152struct ring_shared {53uint32_t cons, prod;54};5556#define VCHAN_NOTIFY_WRITE 0x157#define VCHAN_NOTIFY_READ 0x25859/**60* vchan_interface: primary shared data structure61*/62struct vchan_interface {63/**64* Standard consumer/producer interface, one pair per buffer65* left is client write, server read66* right is client read, server write67*/68struct ring_shared left, right;69/**70* size of the rings, which determines their location71* 10 - at offset 1024 in ring's page72* 11 - at offset 2048 in ring's page73* 12+ - uses 2^(N-12) grants to describe the multi-page ring74* These should remain constant once the page is shared.75* Only one of the two orders can be 10 (or 11).76*/77uint16_t left_order, right_order;78/**79* Shutdown detection:80* 0: client (or server) has exited81* 1: client (or server) is connected82* 2: client has not yet connected83*/84uint8_t cli_live, srv_live;85/**86* Notification bits:87* VCHAN_NOTIFY_WRITE: send notify when data is written88* VCHAN_NOTIFY_READ: send notify when data is read (consumed)89* cli_notify is used for the client to inform the server of its action90*/91uint8_t cli_notify, srv_notify;92/**93* Grant list: ordering is left, right. Must not extend into actual ring94* or grow beyond the end of the initial shared page.95* These should remain constant once the page is shared, to allow96* for possible remapping by a client that restarts.97*/98uint32_t grants[0];99};100101102103