Back to home page

OSCL-LXR

 
 

    


0001 /******************************************************************************
0002  * xenbus.h
0003  *
0004  * Talks to Xen Store to figure out what devices we have.
0005  *
0006  * Copyright (C) 2005 Rusty Russell, IBM Corporation
0007  * Copyright (C) 2005 XenSource Ltd.
0008  *
0009  * This program is free software; you can redistribute it and/or
0010  * modify it under the terms of the GNU General Public License version 2
0011  * as published by the Free Software Foundation; or, when distributed
0012  * separately from the Linux kernel or incorporated into other
0013  * software packages, subject to the following license:
0014  *
0015  * Permission is hereby granted, free of charge, to any person obtaining a copy
0016  * of this source file (the "Software"), to deal in the Software without
0017  * restriction, including without limitation the rights to use, copy, modify,
0018  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
0019  * and to permit persons to whom the Software is furnished to do so, subject to
0020  * the following conditions:
0021  *
0022  * The above copyright notice and this permission notice shall be included in
0023  * all copies or substantial portions of the Software.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0026  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0027  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0028  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0029  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0030  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0031  * IN THE SOFTWARE.
0032  */
0033 
0034 #ifndef _XEN_XENBUS_H
0035 #define _XEN_XENBUS_H
0036 
0037 #include <linux/device.h>
0038 #include <linux/notifier.h>
0039 #include <linux/mutex.h>
0040 #include <linux/export.h>
0041 #include <linux/fs.h>
0042 #include <linux/completion.h>
0043 #include <linux/init.h>
0044 #include <linux/slab.h>
0045 #include <linux/semaphore.h>
0046 #include <xen/interface/xen.h>
0047 #include <xen/interface/grant_table.h>
0048 #include <xen/interface/io/xenbus.h>
0049 #include <xen/interface/io/xs_wire.h>
0050 #include <xen/interface/event_channel.h>
0051 
0052 #define XENBUS_MAX_RING_GRANT_ORDER 4
0053 #define XENBUS_MAX_RING_GRANTS      (1U << XENBUS_MAX_RING_GRANT_ORDER)
0054 
0055 /* Register callback to watch this node. */
0056 struct xenbus_watch
0057 {
0058     struct list_head list;
0059 
0060     /* Path being watched. */
0061     const char *node;
0062 
0063     unsigned int nr_pending;
0064 
0065     /*
0066      * Called just before enqueing new event while a spinlock is held.
0067      * The event will be discarded if this callback returns false.
0068      */
0069     bool (*will_handle)(struct xenbus_watch *,
0070                   const char *path, const char *token);
0071 
0072     /* Callback (executed in a process context with no locks held). */
0073     void (*callback)(struct xenbus_watch *,
0074              const char *path, const char *token);
0075 };
0076 
0077 
0078 /* A xenbus device. */
0079 struct xenbus_device {
0080     const char *devicetype;
0081     const char *nodename;
0082     const char *otherend;
0083     int otherend_id;
0084     struct xenbus_watch otherend_watch;
0085     struct device dev;
0086     enum xenbus_state state;
0087     struct completion down;
0088     struct work_struct work;
0089     struct semaphore reclaim_sem;
0090 
0091     /* Event channel based statistics and settings. */
0092     atomic_t event_channels;
0093     atomic_t events;
0094     atomic_t spurious_events;
0095     atomic_t jiffies_eoi_delayed;
0096     unsigned int spurious_threshold;
0097 };
0098 
0099 static inline struct xenbus_device *to_xenbus_device(struct device *dev)
0100 {
0101     return container_of(dev, struct xenbus_device, dev);
0102 }
0103 
0104 struct xenbus_device_id
0105 {
0106     /* .../device/<device_type>/<identifier> */
0107     char devicetype[32];    /* General class of device. */
0108 };
0109 
0110 /* A xenbus driver. */
0111 struct xenbus_driver {
0112     const char *name;       /* defaults to ids[0].devicetype */
0113     const struct xenbus_device_id *ids;
0114     bool allow_rebind; /* avoid setting xenstore closed during remove */
0115     bool not_essential;     /* is not mandatory for boot progress */
0116     int (*probe)(struct xenbus_device *dev,
0117              const struct xenbus_device_id *id);
0118     void (*otherend_changed)(struct xenbus_device *dev,
0119                  enum xenbus_state backend_state);
0120     int (*remove)(struct xenbus_device *dev);
0121     int (*suspend)(struct xenbus_device *dev);
0122     int (*resume)(struct xenbus_device *dev);
0123     int (*uevent)(struct xenbus_device *, struct kobj_uevent_env *);
0124     struct device_driver driver;
0125     int (*read_otherend_details)(struct xenbus_device *dev);
0126     int (*is_ready)(struct xenbus_device *dev);
0127     void (*reclaim_memory)(struct xenbus_device *dev);
0128 };
0129 
0130 static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
0131 {
0132     return container_of(drv, struct xenbus_driver, driver);
0133 }
0134 
0135 int __must_check __xenbus_register_frontend(struct xenbus_driver *drv,
0136                         struct module *owner,
0137                         const char *mod_name);
0138 int __must_check __xenbus_register_backend(struct xenbus_driver *drv,
0139                        struct module *owner,
0140                        const char *mod_name);
0141 
0142 #define xenbus_register_frontend(drv) \
0143     __xenbus_register_frontend(drv, THIS_MODULE, KBUILD_MODNAME)
0144 #define xenbus_register_backend(drv) \
0145     __xenbus_register_backend(drv, THIS_MODULE, KBUILD_MODNAME)
0146 
0147 void xenbus_unregister_driver(struct xenbus_driver *drv);
0148 
0149 struct xenbus_transaction
0150 {
0151     u32 id;
0152 };
0153 
0154 /* Nil transaction ID. */
0155 #define XBT_NIL ((struct xenbus_transaction) { 0 })
0156 
0157 char **xenbus_directory(struct xenbus_transaction t,
0158             const char *dir, const char *node, unsigned int *num);
0159 void *xenbus_read(struct xenbus_transaction t,
0160           const char *dir, const char *node, unsigned int *len);
0161 int xenbus_write(struct xenbus_transaction t,
0162          const char *dir, const char *node, const char *string);
0163 int xenbus_mkdir(struct xenbus_transaction t,
0164          const char *dir, const char *node);
0165 int xenbus_exists(struct xenbus_transaction t,
0166           const char *dir, const char *node);
0167 int xenbus_rm(struct xenbus_transaction t, const char *dir, const char *node);
0168 int xenbus_transaction_start(struct xenbus_transaction *t);
0169 int xenbus_transaction_end(struct xenbus_transaction t, int abort);
0170 
0171 /* Single read and scanf: returns -errno or num scanned if > 0. */
0172 __scanf(4, 5)
0173 int xenbus_scanf(struct xenbus_transaction t,
0174          const char *dir, const char *node, const char *fmt, ...);
0175 
0176 /* Read an (optional) unsigned value. */
0177 unsigned int xenbus_read_unsigned(const char *dir, const char *node,
0178                   unsigned int default_val);
0179 
0180 /* Single printf and write: returns -errno or 0. */
0181 __printf(4, 5)
0182 int xenbus_printf(struct xenbus_transaction t,
0183           const char *dir, const char *node, const char *fmt, ...);
0184 
0185 /* Generic read function: NULL-terminated triples of name,
0186  * sprintf-style type string, and pointer. Returns 0 or errno.*/
0187 int xenbus_gather(struct xenbus_transaction t, const char *dir, ...);
0188 
0189 /* notifer routines for when the xenstore comes up */
0190 extern int xenstored_ready;
0191 int register_xenstore_notifier(struct notifier_block *nb);
0192 void unregister_xenstore_notifier(struct notifier_block *nb);
0193 
0194 int register_xenbus_watch(struct xenbus_watch *watch);
0195 void unregister_xenbus_watch(struct xenbus_watch *watch);
0196 void xs_suspend(void);
0197 void xs_resume(void);
0198 void xs_suspend_cancel(void);
0199 
0200 struct work_struct;
0201 
0202 #define XENBUS_IS_ERR_READ(str) ({          \
0203     if (!IS_ERR(str) && strlen(str) == 0) {     \
0204         kfree(str);             \
0205         str = ERR_PTR(-ERANGE);         \
0206     }                       \
0207     IS_ERR(str);                    \
0208 })
0209 
0210 #define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
0211 
0212 int xenbus_watch_path(struct xenbus_device *dev, const char *path,
0213               struct xenbus_watch *watch,
0214               bool (*will_handle)(struct xenbus_watch *,
0215                       const char *, const char *),
0216               void (*callback)(struct xenbus_watch *,
0217                        const char *, const char *));
0218 __printf(5, 6)
0219 int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
0220              bool (*will_handle)(struct xenbus_watch *,
0221                          const char *, const char *),
0222              void (*callback)(struct xenbus_watch *,
0223                       const char *, const char *),
0224              const char *pathfmt, ...);
0225 
0226 int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
0227 int xenbus_setup_ring(struct xenbus_device *dev, gfp_t gfp, void **vaddr,
0228               unsigned int nr_pages, grant_ref_t *grefs);
0229 void xenbus_teardown_ring(void **vaddr, unsigned int nr_pages,
0230               grant_ref_t *grefs);
0231 int xenbus_map_ring_valloc(struct xenbus_device *dev, grant_ref_t *gnt_refs,
0232                unsigned int nr_grefs, void **vaddr);
0233 
0234 int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
0235 
0236 int xenbus_alloc_evtchn(struct xenbus_device *dev, evtchn_port_t *port);
0237 int xenbus_free_evtchn(struct xenbus_device *dev, evtchn_port_t port);
0238 
0239 enum xenbus_state xenbus_read_driver_state(const char *path);
0240 
0241 __printf(3, 4)
0242 void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
0243 __printf(3, 4)
0244 void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...);
0245 
0246 const char *xenbus_strstate(enum xenbus_state state);
0247 int xenbus_dev_is_online(struct xenbus_device *dev);
0248 int xenbus_frontend_closed(struct xenbus_device *dev);
0249 
0250 extern const struct file_operations xen_xenbus_fops;
0251 extern struct xenstore_domain_interface *xen_store_interface;
0252 extern int xen_store_evtchn;
0253 
0254 #endif /* _XEN_XENBUS_H */