xref: /openbmc/qemu/include/hw/xen/interface/io/xs_wire.h (revision ed75658a)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Details of the "wire" protocol between Xen Store Daemon and client
4  * library or guest kernel.
5  *
6  * Copyright (C) 2005 Rusty Russell IBM Corporation
7  */
8 
9 #ifndef _XS_WIRE_H
10 #define _XS_WIRE_H
11 
12 enum xsd_sockmsg_type
13 {
14     XS_CONTROL,
15 #define XS_DEBUG XS_CONTROL
16     XS_DIRECTORY,
17     XS_READ,
18     XS_GET_PERMS,
19     XS_WATCH,
20     XS_UNWATCH,
21     XS_TRANSACTION_START,
22     XS_TRANSACTION_END,
23     XS_INTRODUCE,
24     XS_RELEASE,
25     XS_GET_DOMAIN_PATH,
26     XS_WRITE,
27     XS_MKDIR,
28     XS_RM,
29     XS_SET_PERMS,
30     XS_WATCH_EVENT,
31     XS_ERROR,
32     XS_IS_DOMAIN_INTRODUCED,
33     XS_RESUME,
34     XS_SET_TARGET,
35     /* XS_RESTRICT has been removed */
36     XS_RESET_WATCHES = XS_SET_TARGET + 2,
37     XS_DIRECTORY_PART,
38 
39     XS_TYPE_COUNT,      /* Number of valid types. */
40 
41     XS_INVALID = 0xffff /* Guaranteed to remain an invalid type */
42 };
43 
44 #define XS_WRITE_NONE "NONE"
45 #define XS_WRITE_CREATE "CREATE"
46 #define XS_WRITE_CREATE_EXCL "CREATE|EXCL"
47 
48 /* We hand errors as strings, for portability. */
49 struct xsd_errors
50 {
51     int errnum;
52     const char *errstring;
53 };
54 #ifdef EINVAL
55 #define XSD_ERROR(x) { x, #x }
56 /* LINTED: static unused */
57 static const struct xsd_errors xsd_errors[]
58 #if defined(__GNUC__)
59 __attribute__((unused))
60 #endif
61     = {
62     /* /!\ New errors should be added at the end of the array. */
63     XSD_ERROR(EINVAL),
64     XSD_ERROR(EACCES),
65     XSD_ERROR(EEXIST),
66     XSD_ERROR(EISDIR),
67     XSD_ERROR(ENOENT),
68     XSD_ERROR(ENOMEM),
69     XSD_ERROR(ENOSPC),
70     XSD_ERROR(EIO),
71     XSD_ERROR(ENOTEMPTY),
72     XSD_ERROR(ENOSYS),
73     XSD_ERROR(EROFS),
74     XSD_ERROR(EBUSY),
75     XSD_ERROR(EAGAIN),
76     XSD_ERROR(EISCONN),
77     XSD_ERROR(E2BIG),
78     XSD_ERROR(EPERM),
79 };
80 #endif
81 
82 struct xsd_sockmsg
83 {
84     uint32_t type;  /* XS_??? */
85     uint32_t req_id;/* Request identifier, echoed in daemon's response.  */
86     uint32_t tx_id; /* Transaction id (0 if not related to a transaction). */
87     uint32_t len;   /* Length of data following this. */
88 
89     /* Generally followed by nul-terminated string(s). */
90 };
91 
92 enum xs_watch_type
93 {
94     XS_WATCH_PATH = 0,
95     XS_WATCH_TOKEN
96 };
97 
98 /*
99  * `incontents 150 xenstore_struct XenStore wire protocol.
100  *
101  * Inter-domain shared memory communications. */
102 #define XENSTORE_RING_SIZE 1024
103 typedef uint32_t XENSTORE_RING_IDX;
104 #define MASK_XENSTORE_IDX(idx) ((idx) & (XENSTORE_RING_SIZE-1))
105 struct xenstore_domain_interface {
106     char req[XENSTORE_RING_SIZE]; /* Requests to xenstore daemon. */
107     char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */
108     XENSTORE_RING_IDX req_cons, req_prod;
109     XENSTORE_RING_IDX rsp_cons, rsp_prod;
110     uint32_t server_features; /* Bitmap of features supported by the server */
111     uint32_t connection;
112     uint32_t error;
113 };
114 
115 /* Violating this is very bad.  See docs/misc/xenstore.txt. */
116 #define XENSTORE_PAYLOAD_MAX 4096
117 
118 /* Violating these just gets you an error back */
119 #define XENSTORE_ABS_PATH_MAX 3072
120 #define XENSTORE_REL_PATH_MAX 2048
121 
122 /* The ability to reconnect a ring */
123 #define XENSTORE_SERVER_FEATURE_RECONNECTION 1
124 /* The presence of the "error" field in the ring page */
125 #define XENSTORE_SERVER_FEATURE_ERROR        2
126 
127 /* Valid values for the connection field */
128 #define XENSTORE_CONNECTED 0 /* the steady-state */
129 #define XENSTORE_RECONNECT 1 /* reconnect in progress */
130 
131 /* Valid values for the error field */
132 #define XENSTORE_ERROR_NONE    0 /* No error */
133 #define XENSTORE_ERROR_COMM    1 /* Communication problem */
134 #define XENSTORE_ERROR_RINGIDX 2 /* Invalid ring index */
135 #define XENSTORE_ERROR_PROTO   3 /* Protocol violation (payload too long) */
136 
137 #endif /* _XS_WIRE_H */
138 
139 /*
140  * Local variables:
141  * mode: C
142  * c-file-style: "BSD"
143  * c-basic-offset: 4
144  * tab-width: 4
145  * indent-tabs-mode: nil
146  * End:
147  */
148