1 /*
2  * pvcalls.h -- Xen PV Calls Protocol
3  *
4  * Refer to docs/misc/pvcalls.markdown for the specification
5  *
6  * The header is provided as a C reference for the specification. In
7  * case of conflict, the specification is authoritative.
8  *
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:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
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.
26  *
27  * Copyright (C) 2017 Stefano Stabellini <stefano@aporeto.com>
28  */
29 
30 #ifndef __XEN_PUBLIC_IO_PVCALLS_H__
31 #define __XEN_PUBLIC_IO_PVCALLS_H__
32 
33 #include "../grant_table.h"
34 #include "ring.h"
35 
36 /*
37  * See docs/misc/pvcalls.markdown in xen.git for the full specification:
38  * https://xenbits.xen.org/docs/unstable/misc/pvcalls.html
39  */
40 struct pvcalls_data_intf {
41     RING_IDX in_cons, in_prod, in_error;
42 
43     uint8_t pad1[52];
44 
45     RING_IDX out_cons, out_prod, out_error;
46 
47     uint8_t pad2[52];
48 
49     RING_IDX ring_order;
50     grant_ref_t ref[];
51 };
52 DEFINE_XEN_FLEX_RING(pvcalls);
53 
54 #define PVCALLS_SOCKET         0
55 #define PVCALLS_CONNECT        1
56 #define PVCALLS_RELEASE        2
57 #define PVCALLS_BIND           3
58 #define PVCALLS_LISTEN         4
59 #define PVCALLS_ACCEPT         5
60 #define PVCALLS_POLL           6
61 
62 struct xen_pvcalls_request {
63     uint32_t req_id; /* private to guest, echoed in response */
64     uint32_t cmd;    /* command to execute */
65     union {
66         struct xen_pvcalls_socket {
67             uint64_t id;
68             uint32_t domain;
69             uint32_t type;
70             uint32_t protocol;
71             uint8_t pad[4];
72         } socket;
73         struct xen_pvcalls_connect {
74             uint64_t id;
75             uint8_t addr[28];
76             uint32_t len;
77             uint32_t flags;
78             grant_ref_t ref;
79             uint32_t evtchn;
80             uint8_t pad[4];
81         } connect;
82         struct xen_pvcalls_release {
83             uint64_t id;
84             uint8_t reuse;
85             uint8_t pad[7];
86         } release;
87         struct xen_pvcalls_bind {
88             uint64_t id;
89             uint8_t addr[28];
90             uint32_t len;
91         } bind;
92         struct xen_pvcalls_listen {
93             uint64_t id;
94             uint32_t backlog;
95             uint8_t pad[4];
96         } listen;
97         struct xen_pvcalls_accept {
98             uint64_t id;
99             uint64_t id_new;
100             grant_ref_t ref;
101             uint32_t evtchn;
102         } accept;
103         struct xen_pvcalls_poll {
104             uint64_t id;
105         } poll;
106         /* dummy member to force sizeof(struct xen_pvcalls_request)
107          * to match across archs */
108         struct xen_pvcalls_dummy {
109             uint8_t dummy[56];
110         } dummy;
111     } u;
112 };
113 
114 struct xen_pvcalls_response {
115     uint32_t req_id;
116     uint32_t cmd;
117     int32_t ret;
118     uint32_t pad;
119     union {
120         struct _xen_pvcalls_socket {
121             uint64_t id;
122         } socket;
123         struct _xen_pvcalls_connect {
124             uint64_t id;
125         } connect;
126         struct _xen_pvcalls_release {
127             uint64_t id;
128         } release;
129         struct _xen_pvcalls_bind {
130             uint64_t id;
131         } bind;
132         struct _xen_pvcalls_listen {
133             uint64_t id;
134         } listen;
135         struct _xen_pvcalls_accept {
136             uint64_t id;
137         } accept;
138         struct _xen_pvcalls_poll {
139             uint64_t id;
140         } poll;
141         struct _xen_pvcalls_dummy {
142             uint8_t dummy[8];
143         } dummy;
144     } u;
145 };
146 
147 DEFINE_RING_TYPES(xen_pvcalls, struct xen_pvcalls_request,
148                   struct xen_pvcalls_response);
149 
150 #endif
151 
152 /*
153  * Local variables:
154  * mode: C
155  * c-file-style: "BSD"
156  * c-basic-offset: 4
157  * tab-width: 4
158  * indent-tabs-mode: nil
159  * End:
160  */
161