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