Home | History | Annotate | Line # | Download | only in include
xenbus.h revision 1.1
      1 /* $NetBSD: xenbus.h,v 1.1 2006/03/06 20:29:52 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 	const char *node;
     60 
     61 	/* Callback (executed in a process context with no locks held). */
     62 	void (*callback)(struct xenbus_watch *,
     63 			 const char **vec, unsigned int len);
     64 };
     65 
     66 
     67 /* A xenbus device. */
     68 struct xenbus_device {
     69 	const char xbusd_path[80];
     70 	char *xbusd_otherend;
     71 	int xbusd_otherend_id;
     72 	struct xenbus_watch xbusd_otherend_watch;
     73 	int xbusd_has_error;
     74 	void *xbusd_data;
     75 };
     76 
     77 struct xenbus_device_id
     78 {
     79 	/* .../device/<device_type>/<identifier> */
     80 	char devicetype[32]; 	/* General class of device. */
     81 };
     82 
     83 /* A xenbus driver. */
     84 struct xenbus_driver {
     85 	char *name;
     86 	struct module *owner;
     87 	const struct xenbus_device_id *ids;
     88 	int (*probe)(struct xenbus_device *dev,
     89 		     const struct xenbus_device_id *id);
     90 	void (*otherend_changed)(struct xenbus_device *dev,
     91 				 XenbusState backend_state);
     92 	int (*remove)(struct xenbus_device *dev);
     93 	int (*suspend)(struct xenbus_device *dev);
     94 	int (*resume)(struct xenbus_device *dev);
     95 	int (*hotplug)(struct xenbus_device *, char **, int, char *, int);
     96 	int (*read_otherend_details)(struct xenbus_device *dev);
     97 };
     98 
     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);
    102 
    103 struct xenbus_transaction;
    104 
    105 int xenbus_directory(struct xenbus_transaction *t,
    106 			const char *dir, const char *node, unsigned int *num,
    107 			char ***);
    108 int xenbus_read(struct xenbus_transaction *t,
    109 		  const char *dir, const char *node, unsigned int *len,
    110 		  char **);
    111 int xenbus_write(struct xenbus_transaction *t,
    112 		 const char *dir, const char *node, const char *string);
    113 int xenbus_mkdir(struct xenbus_transaction *t,
    114 		 const char *dir, const char *node);
    115 int xenbus_exists(struct xenbus_transaction *t,
    116 		  const char *dir, const char *node);
    117 int xenbus_rm(struct xenbus_transaction *t, const char *dir, const char *node);
    118 struct xenbus_transaction *xenbus_transaction_start(void);
    119 int xenbus_transaction_end(struct xenbus_transaction *t, int abort);
    120 
    121 /* Single read and scanf: returns -errno or num scanned if > 0. */
    122 int xenbus_scanf(struct xenbus_transaction *t,
    123 		 const char *dir, const char *node, const char *fmt, ...)
    124 	__attribute__((format(scanf, 4, 5)));
    125 
    126 /* Single printf and write: returns -errno or 0. */
    127 int xenbus_printf(struct xenbus_transaction *t,
    128 		  const char *dir, const char *node, const char *fmt, ...)
    129 	__attribute__((format(printf, 4, 5)));
    130 
    131 /* Generic read function: NULL-terminated triples of name,
    132  * sprintf-style type string, and pointer. Returns 0 or errno.*/
    133 int xenbus_gather(struct xenbus_transaction *t, const char *dir, ...);
    134 
    135 /* notifer routines for when the xenstore comes up */
    136 // XXX int register_xenstore_notifier(struct notifier_block *nb);
    137 // XXX void unregister_xenstore_notifier(struct notifier_block *nb);
    138 
    139 int register_xenbus_watch(struct xenbus_watch *watch);
    140 void unregister_xenbus_watch(struct xenbus_watch *watch);
    141 void xs_suspend(void);
    142 void xs_resume(void);
    143 
    144 /* Used by xenbus_dev to borrow kernel's store connection. */
    145 int xenbus_dev_request_and_reply(struct xsd_sockmsg *msg, void **);
    146 
    147 /* Called from xen core code. */
    148 void xenbus_suspend(void);
    149 void xenbus_resume(void);
    150 
    151 void xenbus_probe(void *);
    152 
    153 #define XENBUS_IS_ERR_READ(str) ({			\
    154 	if (!IS_ERR(str) && strlen(str) == 0) {		\
    155 		kfree(str);				\
    156 		str = ERR_PTR(-ERANGE);			\
    157 	}						\
    158 	IS_ERR(str);					\
    159 })
    160 
    161 #define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
    162 
    163 
    164 /**
    165  * Register a watch on the given path, using the given xenbus_watch structure
    166  * for storage, and the given callback function as the callback.  Return 0 on
    167  * success, or -errno on error.  On success, the given path will be saved as
    168  * watch->node, and remains the caller's to free.  On error, watch->node will
    169  * be NULL, the device will switch to XenbusStateClosing, and the error will
    170  * be saved in the store.
    171  */
    172 int xenbus_watch_path(struct xenbus_device *dev, char *path,
    173 		      struct xenbus_watch *watch,
    174 		      void (*callback)(struct xenbus_watch *,
    175 				       const char **, unsigned int));
    176 
    177 
    178 /**
    179  * Register a watch on the given path/path2, using the given xenbus_watch
    180  * structure for storage, and the given callback function as the callback.
    181  * Return 0 on success, or -errno on error.  On success, the watched path
    182  * (path/path2) will be saved as watch->node, and becomes the caller's to
    183  * kfree().  On error, watch->node will be NULL, so the caller has nothing to
    184  * free, the device will switch to XenbusStateClosing, and the error will be
    185  * saved in the store.
    186  */
    187 int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
    188 		       const char *path2, struct xenbus_watch *watch,
    189 		       void (*callback)(struct xenbus_watch *,
    190 					const char **, unsigned int));
    191 
    192 
    193 /**
    194  * Advertise in the store a change of the given driver to the given new_state.
    195  * Perform the change inside the given transaction xbt.  xbt may be NULL, in
    196  * which case this is performed inside its own transaction.  Return 0 on
    197  * success, or -errno on error.  On error, the device will switch to
    198  * XenbusStateClosing, and the error will be saved in the store.
    199  */
    200 int xenbus_switch_state(struct xenbus_device *dev,
    201 			struct xenbus_transaction *xbt,
    202 			XenbusState new_state);
    203 
    204 
    205 /**
    206  * Grant access to the given ring_mfn to the peer of the given device.  Return
    207  * 0 on success, or -errno on error.  On error, the device will switch to
    208  * XenbusStateClosing, and the error will be saved in the store.
    209  */
    210 int xenbus_grant_ring(struct xenbus_device *, paddr_t, grant_ref_t *);
    211 
    212 
    213 /**
    214  * Allocate an event channel for the given xenbus_device, assigning the newly
    215  * created local port to *port.  Return 0 on success, or -errno on error.  On
    216  * error, the device will switch to XenbusStateClosing, and the error will be
    217  * saved in the store.
    218  */
    219 int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
    220 
    221 
    222 /**
    223  * Return the state of the driver rooted at the given store path, or
    224  * XenbusStateClosed if no state can be read.
    225  */
    226 XenbusState xenbus_read_driver_state(const char *path);
    227 
    228 
    229 /***
    230  * Report the given negative errno into the store, along with the given
    231  * formatted message.
    232  */
    233 void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt,
    234 		      ...);
    235 
    236 
    237 /***
    238  * Equivalent to xenbus_dev_error(dev, err, fmt, args), followed by
    239  * xenbus_switch_state(dev, NULL, XenbusStateClosing) to schedule an orderly
    240  * closedown of this driver and its peer.
    241  */
    242 void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt,
    243 		      ...);
    244 
    245 
    246 #endif /* _ASM_XEN_XENBUS_H */
    247 
    248 /*
    249  * Local variables:
    250  *  c-file-style: "linux"
    251  *  indent-tabs-mode: t
    252  *  c-indent-level: 8
    253  *  c-basic-offset: 8
    254  *  tab-width: 8
    255  * End:
    256  */
    257