ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/xenbus.h @ 8534:da7873110bbb

Tiny bootstrap cleanup.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jan 09 19:46:46 2006 +0100 (2006-01-09)
parents 42474df9b248
children 991ccc24bf2e
line source
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 */
31 #ifndef _ASM_XEN_XENBUS_H
32 #define _ASM_XEN_XENBUS_H
34 #include <linux/device.h>
35 #include <linux/notifier.h>
36 #include <asm/semaphore.h>
37 #include <asm-xen/xen-public/io/xenbus.h>
38 #include <asm-xen/xen-public/io/xs_wire.h>
40 /* Register callback to watch this node. */
41 struct xenbus_watch
42 {
43 struct list_head list;
45 /* Path being watched. */
46 const char *node;
48 /* Callback (executed in a process context with no locks held). */
49 void (*callback)(struct xenbus_watch *,
50 const char **vec, unsigned int len);
51 };
54 /* A xenbus device. */
55 struct xenbus_device {
56 const char *devicetype;
57 const char *nodename;
58 const char *otherend;
59 int otherend_id;
60 struct xenbus_watch otherend_watch;
61 struct device dev;
62 int has_error;
63 void *data;
64 };
66 static inline struct xenbus_device *to_xenbus_device(struct device *dev)
67 {
68 return container_of(dev, struct xenbus_device, dev);
69 }
71 struct xenbus_device_id
72 {
73 /* .../device/<device_type>/<identifier> */
74 char devicetype[32]; /* General class of device. */
75 };
77 /* A xenbus driver. */
78 struct xenbus_driver {
79 char *name;
80 struct module *owner;
81 const struct xenbus_device_id *ids;
82 int (*probe)(struct xenbus_device *dev,
83 const struct xenbus_device_id *id);
84 void (*otherend_changed)(struct xenbus_device *dev,
85 XenbusState backend_state);
86 int (*remove)(struct xenbus_device *dev);
87 int (*suspend)(struct xenbus_device *dev);
88 int (*resume)(struct xenbus_device *dev);
89 int (*hotplug)(struct xenbus_device *, char **, int, char *, int);
90 struct device_driver driver;
91 int (*read_otherend_details)(struct xenbus_device *dev);
92 };
94 static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
95 {
96 return container_of(drv, struct xenbus_driver, driver);
97 }
99 int xenbus_register_frontend(struct xenbus_driver *drv);
100 int xenbus_register_backend(struct xenbus_driver *drv);
101 void xenbus_unregister_driver(struct xenbus_driver *drv);
103 struct xenbus_transaction;
105 char **xenbus_directory(struct xenbus_transaction *t,
106 const char *dir, const char *node, unsigned int *num);
107 void *xenbus_read(struct xenbus_transaction *t,
108 const char *dir, const char *node, unsigned int *len);
109 int xenbus_write(struct xenbus_transaction *t,
110 const char *dir, const char *node, const char *string);
111 int xenbus_mkdir(struct xenbus_transaction *t,
112 const char *dir, const char *node);
113 int xenbus_exists(struct xenbus_transaction *t,
114 const char *dir, const char *node);
115 int xenbus_rm(struct xenbus_transaction *t, const char *dir, const char *node);
116 struct xenbus_transaction *xenbus_transaction_start(void);
117 int xenbus_transaction_end(struct xenbus_transaction *t, int abort);
119 /* Single read and scanf: returns -errno or num scanned if > 0. */
120 int xenbus_scanf(struct xenbus_transaction *t,
121 const char *dir, const char *node, const char *fmt, ...)
122 __attribute__((format(scanf, 4, 5)));
124 /* Single printf and write: returns -errno or 0. */
125 int xenbus_printf(struct xenbus_transaction *t,
126 const char *dir, const char *node, const char *fmt, ...)
127 __attribute__((format(printf, 4, 5)));
129 /* Generic read function: NULL-terminated triples of name,
130 * sprintf-style type string, and pointer. Returns 0 or errno.*/
131 int xenbus_gather(struct xenbus_transaction *t, const char *dir, ...);
133 /* notifer routines for when the xenstore comes up */
134 int register_xenstore_notifier(struct notifier_block *nb);
135 void unregister_xenstore_notifier(struct notifier_block *nb);
137 int register_xenbus_watch(struct xenbus_watch *watch);
138 void unregister_xenbus_watch(struct xenbus_watch *watch);
139 void xs_suspend(void);
140 void xs_resume(void);
142 /* Used by xenbus_dev to borrow kernel's store connection. */
143 void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg);
145 /* Called from xen core code. */
146 void xenbus_suspend(void);
147 void xenbus_resume(void);
149 #define XENBUS_IS_ERR_READ(str) ({ \
150 if (!IS_ERR(str) && strlen(str) == 0) { \
151 kfree(str); \
152 str = ERR_PTR(-ERANGE); \
153 } \
154 IS_ERR(str); \
155 })
157 #define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
160 /**
161 * Register a watch on the given path, using the given xenbus_watch structure
162 * for storage, and the given callback function as the callback. Return 0 on
163 * success, or -errno on error. On success, the given path will be saved as
164 * watch->node, and remains the caller's to free. On error, watch->node will
165 * be NULL, the device will switch to XenbusStateClosing, and the error will
166 * be saved in the store.
167 */
168 int xenbus_watch_path(struct xenbus_device *dev, const char *path,
169 struct xenbus_watch *watch,
170 void (*callback)(struct xenbus_watch *,
171 const char **, unsigned int));
174 /**
175 * Register a watch on the given path/path2, using the given xenbus_watch
176 * structure for storage, and the given callback function as the callback.
177 * Return 0 on success, or -errno on error. On success, the watched path
178 * (path/path2) will be saved as watch->node, and becomes the caller's to
179 * kfree(). On error, watch->node will be NULL, so the caller has nothing to
180 * free, the device will switch to XenbusStateClosing, and the error will be
181 * saved in the store.
182 */
183 int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
184 const char *path2, struct xenbus_watch *watch,
185 void (*callback)(struct xenbus_watch *,
186 const char **, unsigned int));
189 /**
190 * Advertise in the store a change of the given driver to the given new_state.
191 * Perform the change inside the given transaction xbt. xbt may be NULL, in
192 * which case this is performed inside its own transaction. Return 0 on
193 * success, or -errno on error. On error, the device will switch to
194 * XenbusStateClosing, and the error will be saved in the store.
195 */
196 int xenbus_switch_state(struct xenbus_device *dev,
197 struct xenbus_transaction *xbt,
198 XenbusState new_state);
201 /**
202 * Grant access to the given ring_mfn to the peer of the given device. Return
203 * 0 on success, or -errno on error. On error, the device will switch to
204 * XenbusStateClosing, and the error will be saved in the store.
205 */
206 int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
209 /**
210 * Allocate an event channel for the given xenbus_device, assigning the newly
211 * created local port to *port. Return 0 on success, or -errno on error. On
212 * error, the device will switch to XenbusStateClosing, and the error will be
213 * saved in the store.
214 */
215 int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
218 /**
219 * Return the state of the driver rooted at the given store path, or
220 * XenbusStateClosed if no state can be read.
221 */
222 XenbusState xenbus_read_driver_state(const char *path);
225 /***
226 * Report the given negative errno into the store, along with the given
227 * formatted message.
228 */
229 void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,
230 ...);
233 /***
234 * Equivalent to xenbus_dev_error(dev, err, fmt, args), followed by
235 * xenbus_switch_state(dev, NULL, XenbusStateClosing) to schedule an orderly
236 * closedown of this driver and its peer.
237 */
238 void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt,
239 ...);
242 #endif /* _ASM_XEN_XENBUS_H */
244 /*
245 * Local variables:
246 * c-file-style: "linux"
247 * indent-tabs-mode: t
248 * c-indent-level: 8
249 * c-basic-offset: 8
250 * tab-width: 8
251 * End:
252 */