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