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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 * xenbus.h (renamed to xenbus_impl.h)
31 * Talks to Xen Store to figure out what devices we have.
33 * Copyright (C) 2005 Rusty Russell, IBM Corporation
35 * This file may be distributed separately from the Linux kernel, or
36 * incorporated into other software packages, subject to the following license:
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:
45 * The above copyright notice and this permission notice shall be included in
46 * all copies or substantial portions of the Software.
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
60 #include <sys/mutex.h>
69 typedef uint32_t xenbus_transaction_t
;
71 /* Register callback to watch this node. */
73 typedef void (*xenbus_watch_cb_t
)(struct xenbus_watch
*,
74 const char **vec
, unsigned int len
);
77 const char *node
; /* path being watched */
78 xenbus_watch_cb_t callback
;
79 struct xenbus_device
*dev
;
83 * Call this function when xenstore is available, i.e. the daemon is
84 * connected to the xenbus device.
86 struct xenbus_notify
{
88 void (*notify_func
) (int);
91 /* A xenbus device. */
92 struct xenbus_device
{
93 const char *devicetype
;
98 struct xenbus_watch otherend_watch
;
101 void (*otherend_changed
)(struct xenbus_device
*, XenbusState
);
105 typedef void (*xvdi_xb_watch_cb_t
)(dev_info_t
*dip
, const char *path
,
108 typedef struct xd_xb_watches
{
109 list_node_t xxw_list
;
111 struct xenbus_watch xxw_watch
;
112 struct xendev_ppd
*xxw_xppd
;
113 xvdi_xb_watch_cb_t xxw_cb
;
117 extern char **xenbus_directory(xenbus_transaction_t t
, const char *dir
,
118 const char *node
, unsigned int *num
);
119 extern int xenbus_read(xenbus_transaction_t t
, const char *dir
,
120 const char *node
, void **rstr
, unsigned int *len
);
121 extern int xenbus_read_str(const char *dir
, const char *node
, char **rstr
);
122 extern int xenbus_write(xenbus_transaction_t t
, const char *dir
,
123 const char *node
, const char *string
);
124 extern int xenbus_mkdir(xenbus_transaction_t t
, const char *dir
,
126 extern boolean_t
xenbus_exists(const char *dir
, const char *node
);
127 extern boolean_t
xenbus_exists_dir(const char *dir
, const char *node
);
128 extern int xenbus_rm(xenbus_transaction_t t
, const char *dir
,
130 extern int xenbus_transaction_start(xenbus_transaction_t
*t
);
131 extern int xenbus_transaction_end(xenbus_transaction_t t
, int abort
);
133 /* Single read and scanf: returns errno or num scanned if > 0. */
134 extern int xenbus_scanf(xenbus_transaction_t t
, const char *dir
,
135 const char *node
, const char *fmt
, ...);
137 /* Single printf and write: returns errno or 0. */
138 extern int xenbus_printf(xenbus_transaction_t t
, const char *dir
,
139 const char *node
, const char *fmt
, ...);
142 * Generic read function: NULL-terminated triples of name,
143 * sprintf-style type string, and pointer. Returns 0 or errno.
145 extern int xenbus_gather(xenbus_transaction_t t
, const char *dir
, ...);
147 extern int register_xenbus_watch(struct xenbus_watch
*watch
);
148 extern void unregister_xenbus_watch(struct xenbus_watch
*watch
);
149 extern void reregister_xenbus_watches(void);
151 /* Called from xen core code. */
152 extern void xenbus_suspend(void);
153 extern void xenbus_resume(void);
155 #define XENBUS_EXIST_ERR(err) ((err) == ENOENT || (err) == ERANGE)
158 * Register a watch on the given path, using the given xenbus_watch structure
159 * for storage, and the given callback function as the callback. Return 0 on
160 * success, or errno on error. On success, the given path will be saved as
161 * watch->node, and remains the caller's to free. On error, watch->node will
162 * be NULL, the device will switch to XenbusStateClosing, and the error will
163 * be saved in the store.
165 extern int xenbus_watch_path(struct xenbus_device
*dev
, const char *path
,
166 struct xenbus_watch
*watch
,
167 void (*callback
)(struct xenbus_watch
*,
168 const char **, unsigned int));
172 * Register a watch on the given path/path2, using the given xenbus_watch
173 * structure for storage, and the given callback function as the callback.
174 * Return 0 on success, or errno on error. On success, the watched path
175 * (path/path2) will be saved as watch->node, and becomes the caller's to
176 * kfree(). On error, watch->node will be NULL, so the caller has nothing to
177 * free, the device will switch to XenbusStateClosing, and the error will be
178 * saved in the store.
180 extern int xenbus_watch_path2(struct xenbus_device
*dev
, const char *path
,
181 const char *path2
, struct xenbus_watch
*watch
,
182 void (*callback
)(struct xenbus_watch
*,
183 const char **, unsigned int));
187 * Advertise in the store a change of the given driver to the given new_state.
188 * Perform the change inside the given transaction xbt. xbt may be NULL, in
189 * which case this is performed inside its own transaction. Return 0 on
190 * success, or errno on error. On error, the device will switch to
191 * XenbusStateClosing, and the error will be saved in the store.
193 extern int xenbus_switch_state(struct xenbus_device
*dev
,
194 xenbus_transaction_t xbt
,
195 XenbusState new_state
);
199 * Grant access to the given ring_mfn to the peer of the given device. Return
200 * 0 on success, or errno on error. On error, the device will switch to
201 * XenbusStateClosing, and the error will be saved in the store.
203 extern int xenbus_grant_ring(struct xenbus_device
*dev
, unsigned long ring_mfn
);
207 * Allocate an event channel for the given xenbus_device, assigning the newly
208 * created local port to *port. Return 0 on success, or errno on error. On
209 * error, the device will switch to XenbusStateClosing, and the error will be
210 * saved in the store.
212 extern int xenbus_alloc_evtchn(struct xenbus_device
*dev
, int *port
);
216 * Return the state of the driver rooted at the given store path, or
217 * XenbusStateClosed if no state can be read.
219 extern XenbusState
xenbus_read_driver_state(const char *path
);
223 * Report the given negative errno into the store, along with the given
226 extern void xenbus_dev_error(struct xenbus_device
*dev
, int err
,
227 const char *fmt
, ...);
231 * Equivalent to xenbus_dev_error(dev, err, fmt, args), followed by
232 * xenbus_switch_state(dev, NULL, XenbusStateClosing) to schedule an orderly
233 * closedown of this driver and its peer.
235 extern void xenbus_dev_fatal(struct xenbus_device
*dev
,
236 int err
, const char *fmt
, ...);
238 /* Clear any error. */
239 extern void xenbus_dev_ok(struct xenbus_device
*dev
);
242 * Set up watches on other end of split device.
244 extern int talk_to_otherend(struct xenbus_device
*dev
);
246 #define XENSTORE_DOWN 0 /* xenstore is down */
247 #define XENSTORE_UP 1 /* xenstore is up */
250 * Register a notify callback function.
252 extern int xs_register_xenbus_callback(void (*callback
)(int));
255 * Notify clients that xenstore is up
257 extern void xs_notify_xenstore_up(void);
260 * Notify clients that xenstore is down
262 extern void xs_notify_xenstore_down(void);
266 extern int xenbus_dev_request_and_reply(struct xsd_sockmsg
*, void **);
272 #endif /* _SYS_XENBUS_H */