]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/include/xen/xenbus.h
add -n option to suppress clearing the build tree and add -DNO_CLEAN
[FreeBSD/FreeBSD.git] / sys / i386 / include / xen / xenbus.h
1 /******************************************************************************
2  * xenbus.h
3  *
4  * Talks to Xen Store to figure out what devices we have.
5  *
6  * Copyright (C) 2005 Rusty Russell, IBM Corporation
7  * Copyright (C) 2005 XenSource Ltd.
8  * 
9  * This file may be distributed separately from the Linux kernel, or
10  * incorporated into other software packages, subject to the following license:
11  * 
12  * Permission is hereby granted, free of charge, to any person obtaining a copy
13  * of this source file (the "Software"), to deal in the Software without
14  * restriction, including without limitation the rights to use, copy, modify,
15  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
16  * and to permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  * 
19  * The above copyright notice and this permission notice shall be included in
20  * all copies or substantial portions of the Software.
21  * 
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28  * IN THE SOFTWARE.
29  *
30  * $FreeBSD$
31  */
32
33 #ifndef _ASM_XEN_XENBUS_H
34 #define _ASM_XEN_XENBUS_H
35
36 #include <sys/queue.h>
37 #include <sys/bus.h>
38 #include <sys/eventhandler.h>
39 #include <xen/interface/io/xenbus.h>
40 #include <xen/interface/io/xs_wire.h>
41
42 LIST_HEAD(xendev_list_head, xenbus_device); 
43
44 /* Register callback to watch this node. */
45 struct xenbus_watch
46 {
47         LIST_ENTRY(xenbus_watch) list;
48
49         /* Path being watched. */
50         char *node;
51
52         /* Callback (executed in a process context with no locks held). */
53         void (*callback)(struct xenbus_watch *,
54                          const char **vec, unsigned int len);
55 };
56
57
58 /* A xenbus device. */
59 struct xenbus_device {
60                 struct xenbus_watch otherend_watch; /* must be first */
61                 const char *devicetype;
62                 const char *nodename;
63                 const char *otherend;
64                 int otherend_id;
65                 struct xendev_list_head *bus;
66                 struct xenbus_driver *driver;
67                 int has_error;
68                 enum xenbus_state state;
69                 void *dev_driver_data;
70                 LIST_ENTRY(xenbus_device) list;
71 };
72
73 static inline struct xenbus_device *to_xenbus_device(device_t dev)
74 {       
75                 return device_get_softc(dev);
76 }
77
78 struct xenbus_device_id
79 {
80         /* .../device/<device_type>/<identifier> */
81         char devicetype[32];    /* General class of device. */
82 };
83
84 /* A xenbus driver. */
85 struct xenbus_driver {
86                 char *name;
87                 struct module *owner;
88                 const struct xenbus_device_id *ids;
89                 int (*probe)(struct xenbus_device *dev,
90                                          const struct xenbus_device_id *id);
91                 void (*otherend_changed)(struct xenbus_device *dev,
92                                                                  XenbusState backend_state);
93                 int (*remove)(struct xenbus_device *dev);
94                 int (*suspend)(struct xenbus_device *dev);
95                 int (*resume)(struct xenbus_device *dev);
96                 int (*hotplug)(struct xenbus_device *, char **, int, char *, int);
97 #if 0
98                 struct device_driver driver;
99 #endif
100                 driver_t driver;
101                 int (*read_otherend_details)(struct xenbus_device *dev);
102                 int (*watch_otherend)(struct xenbus_device *dev);
103                 int (*cleanup_device)(struct xenbus_device *dev);
104                 int (*is_ready)(struct xenbus_device *dev);
105                 LIST_ENTRY(xenbus_driver) list;
106 };
107
108 static inline struct xenbus_driver *to_xenbus_driver(driver_t *drv)
109 {
110 #if 0
111         return container_of(drv, struct xenbus_driver, driver);
112 #endif
113         return NULL;
114 }
115 typedef int (*xenstore_event_handler_t)(void *);
116
117 int xenbus_register_frontend(struct xenbus_driver *drv);
118 int xenbus_register_backend(struct xenbus_driver *drv);
119 void xenbus_unregister_driver(struct xenbus_driver *drv);
120
121 int xenbus_remove_device(struct xenbus_device *dev);
122
123 struct xenbus_transaction
124 {
125                 uint32_t id;
126 };
127
128 #define XBT_NIL ((struct xenbus_transaction) { 0 })
129
130 char **xenbus_directory(struct xenbus_transaction t,
131                         const char *dir, const char *node, unsigned int *num);
132 void *xenbus_read(struct xenbus_transaction t,
133                   const char *dir, const char *node, unsigned int *len);
134 int xenbus_write(struct xenbus_transaction t,
135                  const char *dir, const char *node, const char *string);
136 int xenbus_mkdir(struct xenbus_transaction t,
137                  const char *dir, const char *node);
138 int xenbus_exists(struct xenbus_transaction t,
139                   const char *dir, const char *node);
140 int xenbus_rm(struct xenbus_transaction t, const char *dir, const char *node);
141 int xenbus_transaction_start(struct xenbus_transaction *t);
142 int xenbus_transaction_end(struct xenbus_transaction t, int abort);
143
144 /* Single read and scanf: returns -errno or num scanned if > 0. */
145 int xenbus_scanf(struct xenbus_transaction t,
146                  const char *dir, const char *node, const char *fmt, ...)
147         __attribute__((format(scanf, 4, 5)));
148
149 /* Single printf and write: returns -errno or 0. */
150 int xenbus_printf(struct xenbus_transaction t,
151                   const char *dir, const char *node, const char *fmt, ...)
152         __attribute__((format(printf, 4, 5)));
153
154 /* Generic read function: NULL-terminated triples of name,
155  * sprintf-style type string, and pointer. Returns 0 or errno.*/
156 int xenbus_gather(struct xenbus_transaction t, const char *dir, ...);
157
158 /* notifer routines for when the xenstore comes up */
159 int register_xenstore_notifier(xenstore_event_handler_t func, void *arg, int priority);
160 #if 0
161 void unregister_xenstore_notifier();
162 #endif
163 int register_xenbus_watch(struct xenbus_watch *watch);
164 void unregister_xenbus_watch(struct xenbus_watch *watch);
165 void xs_suspend(void);
166 void xs_resume(void);
167
168 /* Used by xenbus_dev to borrow kernel's store connection. */
169 void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg);
170
171 /* Called from xen core code. */
172 void xenbus_suspend(void);
173 void xenbus_resume(void);
174
175 #define XENBUS_IS_ERR_READ(str) ({                      \
176         if (!IS_ERR(str) && strlen(str) == 0) {         \
177                 free(str, M_DEVBUF);                            \
178                 str = ERR_PTR(-ERANGE);                 \
179         }                                               \
180         IS_ERR(str);                                    \
181 })
182
183 #define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
184
185
186 /**
187  * Register a watch on the given path, using the given xenbus_watch structure
188  * for storage, and the given callback function as the callback.  Return 0 on
189  * success, or -errno on error.  On success, the given path will be saved as
190  * watch->node, and remains the caller's to free.  On error, watch->node will
191  * be NULL, the device will switch to XenbusStateClosing, and the error will
192  * be saved in the store.
193  */
194 int xenbus_watch_path(struct xenbus_device *dev, char *path,
195                       struct xenbus_watch *watch, 
196                       void (*callback)(struct xenbus_watch *,
197                                        const char **, unsigned int));
198
199
200 /**
201  * Register a watch on the given path/path2, using the given xenbus_watch
202  * structure for storage, and the given callback function as the callback.
203  * Return 0 on success, or -errno on error.  On success, the watched path
204  * (path/path2) will be saved as watch->node, and becomes the caller's to
205  * kfree().  On error, watch->node will be NULL, so the caller has nothing to
206  * free, the device will switch to XenbusStateClosing, and the error will be
207  * saved in the store.
208  */
209 int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
210                        const char *path2, struct xenbus_watch *watch, 
211                        void (*callback)(struct xenbus_watch *,
212                                         const char **, unsigned int));
213
214
215 /**
216  * Advertise in the store a change of the given driver to the given new_state.
217  * which case this is performed inside its own transaction.  Return 0 on
218  * success, or -errno on error.  On error, the device will switch to
219  * XenbusStateClosing, and the error will be saved in the store.
220  */
221 int xenbus_switch_state(struct xenbus_device *dev,
222                         XenbusState new_state);
223
224
225 /**
226  * Grant access to the given ring_mfn to the peer of the given device.  Return
227  * 0 on success, or -errno on error.  On error, the device will switch to
228  * XenbusStateClosing, and the error will be saved in the store.
229  */
230 int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
231
232
233 /**
234  * Allocate an event channel for the given xenbus_device, assigning the newly
235  * created local port to *port.  Return 0 on success, or -errno on error.  On
236  * error, the device will switch to XenbusStateClosing, and the error will be
237  * saved in the store.
238  */
239 int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
240
241
242 /**
243  * Free an existing event channel. Returns 0 on success or -errno on error.
244  */
245 int xenbus_free_evtchn(struct xenbus_device *dev, int port);
246
247
248 /**
249  * Return the state of the driver rooted at the given store path, or
250  * XenbusStateClosed if no state can be read.
251  */
252 XenbusState xenbus_read_driver_state(const char *path);
253
254
255 /***
256  * Report the given negative errno into the store, along with the given
257  * formatted message.
258  */
259 void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,
260                       ...);
261
262
263 /***
264  * Equivalent to xenbus_dev_error(dev, err, fmt, args), followed by
265  * xenbus_switch_state(dev, NULL, XenbusStateClosing) to schedule an orderly
266  * closedown of this driver and its peer.
267  */
268 void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt,
269                       ...);
270
271 int xenbus_dev_init(void);
272
273 const char *xenbus_strstate(enum xenbus_state state);
274 int xenbus_dev_is_online(struct xenbus_device *dev);
275 int xenbus_frontend_closed(struct xenbus_device *dev);
276
277 #endif /* _ASM_XEN_XENBUS_H */
278
279 /*
280  * Local variables:
281  *  c-file-style: "bsd"
282  *  indent-tabs-mode: t
283  *  c-indent-level: 4
284  *  c-basic-offset: 8
285  *  tab-width: 4
286  * End:
287  */