xref: /titanic_50/usr/src/uts/common/xen/sys/xenbus_impl.h (revision ff3124eff995e6cd8ebd8c6543648e0670920034)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  *
29  * xenbus.h (renamed to xenbus_impl.h)
30  *
31  * Talks to Xen Store to figure out what devices we have.
32  *
33  * Copyright (C) 2005 Rusty Russell, IBM Corporation
34  *
35  * This file may be distributed separately from the Linux kernel, or
36  * incorporated into other software packages, subject to the following license:
37  *
38  * Permission is hereby granted, free of charge, to any person obtaining a copy
39  * of this source file (the "Software"), to deal in the Software without
40  * restriction, including without limitation the rights to use, copy, modify,
41  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
42  * and to permit persons to whom the Software is furnished to do so, subject to
43  * the following conditions:
44  *
45  * The above copyright notice and this permission notice shall be included in
46  * all copies or substantial portions of the Software.
47  *
48  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
51  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
53  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
54  * IN THE SOFTWARE.
55  */
56 
57 #ifndef _SYS_XENBUS_H
58 #define	_SYS_XENBUS_H
59 
60 #pragma ident	"%Z%%M%	%I%	%E% SMI"
61 
62 #include <sys/mutex.h>
63 #include <sys/list.h>
64 
65 #ifdef	__cplusplus
66 extern "C" {
67 #endif
68 
69 #define	XBT_NULL 0
70 
71 typedef uint32_t xenbus_transaction_t;
72 
73 /* Register callback to watch this node. */
74 struct xenbus_watch
75 {
76 	list_t list;
77 	const char *node;	/* path being watched */
78 	void (*callback)(struct xenbus_watch *,
79 			const char **vec,  unsigned int len);
80 	struct xenbus_device *dev;
81 };
82 
83 /*
84  * Call this function when xenstore is available, i.e. the daemon is
85  * connected to the xenbus device.
86  */
87 struct xenbus_notify {
88 	list_t list;
89 	void (*notify_func) (int);
90 };
91 
92 /* A xenbus device. */
93 struct xenbus_device {
94 	const char *devicetype;
95 	const char *nodename;
96 	const char *otherend;
97 	int otherend_id;
98 	int otherend_state;
99 	struct xenbus_watch otherend_watch;
100 	int has_error;
101 	int frontend;
102 	void (*otherend_changed)(struct xenbus_device *, XenbusState);
103 	void *data;
104 };
105 
106 
107 extern char **xenbus_directory(xenbus_transaction_t t, const char *dir,
108 	    const char *node, unsigned int *num);
109 extern int xenbus_read(xenbus_transaction_t t, const char *dir,
110 	    const char *node, void **rstr, unsigned int *len);
111 extern int xenbus_write(xenbus_transaction_t t, const char *dir,
112 	    const char *node, const char *string);
113 extern int xenbus_mkdir(xenbus_transaction_t t, const char *dir,
114 	    const char *node);
115 extern int xenbus_exists(xenbus_transaction_t t, const char *dir,
116 	    const char *node);
117 extern int xenbus_rm(xenbus_transaction_t t, const char *dir,
118 	    const char *node);
119 extern int xenbus_transaction_start(xenbus_transaction_t *t);
120 extern int xenbus_transaction_end(xenbus_transaction_t t, int abort);
121 
122 /* Single read and scanf: returns errno or num scanned if > 0. */
123 extern int xenbus_scanf(xenbus_transaction_t t, const char *dir,
124 	    const char *node, const char *fmt, ...);
125 
126 /* Single printf and write: returns errno or 0. */
127 extern int xenbus_printf(xenbus_transaction_t t, const char *dir,
128 	    const char *node, const char *fmt, ...);
129 
130 /*
131  * Generic read function: NULL-terminated triples of name,
132  * sprintf-style type string, and pointer. Returns 0 or errno.
133  */
134 extern int xenbus_gather(xenbus_transaction_t t, const char *dir, ...);
135 
136 extern int register_xenbus_watch(struct xenbus_watch *watch);
137 extern void unregister_xenbus_watch(struct xenbus_watch *watch);
138 extern void reregister_xenbus_watches(void);
139 
140 /* Called from xen core code. */
141 extern void xenbus_suspend(void);
142 extern void xenbus_resume(void);
143 
144 #define	XENBUS_EXIST_ERR(err) ((err) == ENOENT || (err) == ERANGE)
145 
146 /*
147  * Register a watch on the given path, using the given xenbus_watch structure
148  * for storage, and the given callback function as the callback.  Return 0 on
149  * success, or errno on error.  On success, the given path will be saved as
150  * watch->node, and remains the caller's to free.  On error, watch->node will
151  * be NULL, the device will switch to XenbusStateClosing, and the error will
152  * be saved in the store.
153  */
154 extern int xenbus_watch_path(struct xenbus_device *dev, const char *path,
155 			struct xenbus_watch *watch,
156 			void (*callback)(struct xenbus_watch *,
157 			const char **, unsigned int));
158 
159 
160 /*
161  * Register a watch on the given path/path2, using the given xenbus_watch
162  * structure for storage, and the given callback function as the callback.
163  * Return 0 on success, or errno on error.  On success, the watched path
164  * (path/path2) will be saved as watch->node, and becomes the caller's to
165  * kfree().  On error, watch->node will be NULL, so the caller has nothing to
166  * free, the device will switch to XenbusStateClosing, and the error will be
167  * saved in the store.
168  */
169 extern int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
170 			const char *path2, struct xenbus_watch *watch,
171 			void (*callback)(struct xenbus_watch *,
172 			const char **, unsigned int));
173 
174 
175 /*
176  * Advertise in the store a change of the given driver to the given new_state.
177  * Perform the change inside the given transaction xbt.  xbt may be NULL, in
178  * which case this is performed inside its own transaction.  Return 0 on
179  * success, or errno on error.  On error, the device will switch to
180  * XenbusStateClosing, and the error will be saved in the store.
181  */
182 extern int xenbus_switch_state(struct xenbus_device *dev,
183 			xenbus_transaction_t xbt,
184 			XenbusState new_state);
185 
186 
187 /*
188  * Grant access to the given ring_mfn to the peer of the given device.  Return
189  * 0 on success, or errno on error.  On error, the device will switch to
190  * XenbusStateClosing, and the error will be saved in the store.
191  */
192 extern int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
193 
194 
195 /*
196  * Allocate an event channel for the given xenbus_device, assigning the newly
197  * created local port to *port.  Return 0 on success, or errno on error.  On
198  * error, the device will switch to XenbusStateClosing, and the error will be
199  * saved in the store.
200  */
201 extern int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
202 
203 
204 /*
205  * Return the state of the driver rooted at the given store path, or
206  * XenbusStateClosed if no state can be read.
207  */
208 extern XenbusState xenbus_read_driver_state(const char *path);
209 
210 
211 /*
212  * Report the given negative errno into the store, along with the given
213  * formatted message.
214  */
215 extern void xenbus_dev_error(struct xenbus_device *dev, int err,
216 	const char *fmt, ...);
217 
218 
219 /*
220  * Equivalent to xenbus_dev_error(dev, err, fmt, args), followed by
221  * xenbus_switch_state(dev, NULL, XenbusStateClosing) to schedule an orderly
222  * closedown of this driver and its peer.
223  */
224 extern void xenbus_dev_fatal(struct xenbus_device *dev,
225 	int err, const char *fmt, ...);
226 
227 /* Clear any error. */
228 extern void xenbus_dev_ok(struct xenbus_device *dev);
229 
230 /*
231  * Set up watches on other end of split device.
232  */
233 extern int talk_to_otherend(struct xenbus_device *dev);
234 
235 #define	XENSTORE_DOWN	0	/* xenstore is down */
236 #define	XENSTORE_UP	1	/* xenstore is up */
237 
238 /*
239  * Register a notify callback function.
240  */
241 extern int xs_register_xenbus_callback(void (*callback)(int));
242 
243 /*
244  * Notify clients that xenstore is up
245  */
246 extern void xs_notify_xenstore_up(void);
247 
248 /*
249  * Notify clients that xenstore is down
250  */
251 extern void xs_notify_xenstore_down(void);
252 
253 struct xsd_sockmsg;
254 
255 extern int xenbus_dev_request_and_reply(struct xsd_sockmsg *, void **);
256 
257 #ifdef	__cplusplus
258 }
259 #endif
260 
261 #endif /* _SYS_XENBUS_H */
262