0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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
0056 struct xenbus_watch
0057 {
0058 struct list_head list;
0059
0060
0061 const char *node;
0062
0063 unsigned int nr_pending;
0064
0065
0066
0067
0068
0069 bool (*will_handle)(struct xenbus_watch *,
0070 const char *path, const char *token);
0071
0072
0073 void (*callback)(struct xenbus_watch *,
0074 const char *path, const char *token);
0075 };
0076
0077
0078
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
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
0107 char devicetype[32];
0108 };
0109
0110
0111 struct xenbus_driver {
0112 const char *name;
0113 const struct xenbus_device_id *ids;
0114 bool allow_rebind;
0115 bool not_essential;
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
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
0172 __scanf(4, 5)
0173 int xenbus_scanf(struct xenbus_transaction t,
0174 const char *dir, const char *node, const char *fmt, ...);
0175
0176
0177 unsigned int xenbus_read_unsigned(const char *dir, const char *node,
0178 unsigned int default_val);
0179
0180
0181 __printf(4, 5)
0182 int xenbus_printf(struct xenbus_transaction t,
0183 const char *dir, const char *node, const char *fmt, ...);
0184
0185
0186
0187 int xenbus_gather(struct xenbus_transaction t, const char *dir, ...);
0188
0189
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