Blame view

include/xen/xenbus.h 7.72 KB
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  /******************************************************************************
   * xenbus.h
   *
   * Talks to Xen Store to figure out what devices we have.
   *
   * Copyright (C) 2005 Rusty Russell, IBM Corporation
   * Copyright (C) 2005 XenSource Ltd.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License version 2
   * as published by the Free Software Foundation; or, when distributed
   * separately from the Linux kernel or incorporated into other
   * software packages, subject to the following license:
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this source file (the "Software"), to deal in the Software without
   * restriction, including without limitation the rights to use, copy, modify,
   * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   * and to permit persons to whom the Software is furnished to do so, subject to
   * the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   * IN THE SOFTWARE.
   */
  
  #ifndef _XEN_XENBUS_H
  #define _XEN_XENBUS_H
  
  #include <linux/device.h>
  #include <linux/notifier.h>
  #include <linux/mutex.h>
63c9744b9   Paul Gortmaker   xen: Add export.h...
40
  #include <linux/export.h>
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
41
42
  #include <linux/completion.h>
  #include <linux/init.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
43
  #include <linux/slab.h>
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  #include <xen/interface/xen.h>
  #include <xen/interface/grant_table.h>
  #include <xen/interface/io/xenbus.h>
  #include <xen/interface/io/xs_wire.h>
  
  /* Register callback to watch this node. */
  struct xenbus_watch
  {
  	struct list_head list;
  
  	/* Path being watched. */
  	const char *node;
  
  	/* Callback (executed in a process context with no locks held). */
  	void (*callback)(struct xenbus_watch *,
  			 const char **vec, unsigned int len);
  };
  
  
  /* A xenbus device. */
  struct xenbus_device {
  	const char *devicetype;
  	const char *nodename;
  	const char *otherend;
  	int otherend_id;
  	struct xenbus_watch otherend_watch;
  	struct device dev;
  	enum xenbus_state state;
  	struct completion down;
  };
  
  static inline struct xenbus_device *to_xenbus_device(struct device *dev)
  {
  	return container_of(dev, struct xenbus_device, dev);
  }
  
  struct xenbus_device_id
  {
  	/* .../device/<device_type>/<identifier> */
  	char devicetype[32]; 	/* General class of device. */
  };
  
  /* A xenbus driver. */
  struct xenbus_driver {
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
88
89
90
91
92
93
  	const struct xenbus_device_id *ids;
  	int (*probe)(struct xenbus_device *dev,
  		     const struct xenbus_device_id *id);
  	void (*otherend_changed)(struct xenbus_device *dev,
  				 enum xenbus_state backend_state);
  	int (*remove)(struct xenbus_device *dev);
c7853aea5   Kazuhiro SUZUKI   xen: xenbus PM ev...
94
  	int (*suspend)(struct xenbus_device *dev);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
95
  	int (*resume)(struct xenbus_device *dev);
df660251e   Ian Campbell   xen: add backend ...
96
  	int (*uevent)(struct xenbus_device *, struct kobj_uevent_env *);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
97
98
  	struct device_driver driver;
  	int (*read_otherend_details)(struct xenbus_device *dev);
1d78d7055   Christian Limpach   xen blkfront: Del...
99
  	int (*is_ready)(struct xenbus_device *dev);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
100
  };
73db144b5   Jan Beulich   Xen: consolidate ...
101
102
103
104
105
  #define DEFINE_XENBUS_DRIVER(var, drvname, methods...)		\
  struct xenbus_driver var ## _driver = {				\
  	.driver.name = drvname + 0 ?: var ## _ids->devicetype,	\
  	.driver.owner = THIS_MODULE,				\
  	.ids = var ## _ids, ## methods				\
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
106
  }
73db144b5   Jan Beulich   Xen: consolidate ...
107
  static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
108
  {
73db144b5   Jan Beulich   Xen: consolidate ...
109
  	return container_of(drv, struct xenbus_driver, driver);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
110
  }
73db144b5   Jan Beulich   Xen: consolidate ...
111
112
  int __must_check xenbus_register_frontend(struct xenbus_driver *);
  int __must_check xenbus_register_backend(struct xenbus_driver *);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
113
114
115
116
117
118
119
120
121
122
  
  void xenbus_unregister_driver(struct xenbus_driver *drv);
  
  struct xenbus_transaction
  {
  	u32 id;
  };
  
  /* Nil transaction ID. */
  #define XBT_NIL ((struct xenbus_transaction) { 0 })
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  char **xenbus_directory(struct xenbus_transaction t,
  			const char *dir, const char *node, unsigned int *num);
  void *xenbus_read(struct xenbus_transaction t,
  		  const char *dir, const char *node, unsigned int *len);
  int xenbus_write(struct xenbus_transaction t,
  		 const char *dir, const char *node, const char *string);
  int xenbus_mkdir(struct xenbus_transaction t,
  		 const char *dir, const char *node);
  int xenbus_exists(struct xenbus_transaction t,
  		  const char *dir, const char *node);
  int xenbus_rm(struct xenbus_transaction t, const char *dir, const char *node);
  int xenbus_transaction_start(struct xenbus_transaction *t);
  int xenbus_transaction_end(struct xenbus_transaction t, int abort);
  
  /* Single read and scanf: returns -errno or num scanned if > 0. */
  int xenbus_scanf(struct xenbus_transaction t,
  		 const char *dir, const char *node, const char *fmt, ...)
  	__attribute__((format(scanf, 4, 5)));
  
  /* Single printf and write: returns -errno or 0. */
b9075fa96   Joe Perches   treewide: use __p...
143
  __printf(4, 5)
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
144
  int xenbus_printf(struct xenbus_transaction t,
b9075fa96   Joe Perches   treewide: use __p...
145
  		  const char *dir, const char *node, const char *fmt, ...);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  
  /* Generic read function: NULL-terminated triples of name,
   * sprintf-style type string, and pointer. Returns 0 or errno.*/
  int xenbus_gather(struct xenbus_transaction t, const char *dir, ...);
  
  /* notifer routines for when the xenstore comes up */
  extern int xenstored_ready;
  int register_xenstore_notifier(struct notifier_block *nb);
  void unregister_xenstore_notifier(struct notifier_block *nb);
  
  int register_xenbus_watch(struct xenbus_watch *watch);
  void unregister_xenbus_watch(struct xenbus_watch *watch);
  void xs_suspend(void);
  void xs_resume(void);
  void xs_suspend_cancel(void);
  
  /* Used by xenbus_dev to borrow kernel's store connection. */
  void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg);
  
  struct work_struct;
  
  /* Prepare for domain suspend: then resume or cancel the suspend. */
  void xenbus_suspend(void);
  void xenbus_resume(void);
  void xenbus_probe(struct work_struct *);
  void xenbus_suspend_cancel(void);
  
  #define XENBUS_IS_ERR_READ(str) ({			\
  	if (!IS_ERR(str) && strlen(str) == 0) {		\
  		kfree(str);				\
  		str = ERR_PTR(-ERANGE);			\
  	}						\
  	IS_ERR(str);					\
  })
  
  #define XENBUS_EXIST_ERR(err) ((err) == -ENOENT || (err) == -ERANGE)
  
  int xenbus_watch_path(struct xenbus_device *dev, const char *path,
  		      struct xenbus_watch *watch,
  		      void (*callback)(struct xenbus_watch *,
  				       const char **, unsigned int));
b9075fa96   Joe Perches   treewide: use __p...
187
  __printf(4, 5)
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
188
189
190
  int xenbus_watch_pathfmt(struct xenbus_device *dev, struct xenbus_watch *watch,
  			 void (*callback)(struct xenbus_watch *,
  					  const char **, unsigned int),
b9075fa96   Joe Perches   treewide: use __p...
191
  			 const char *pathfmt, ...);
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
  
  int xenbus_switch_state(struct xenbus_device *dev, enum xenbus_state new_state);
  int xenbus_grant_ring(struct xenbus_device *dev, unsigned long ring_mfn);
  int xenbus_map_ring_valloc(struct xenbus_device *dev,
  			   int gnt_ref, void **vaddr);
  int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
  			   grant_handle_t *handle, void *vaddr);
  
  int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
  int xenbus_unmap_ring(struct xenbus_device *dev,
  		      grant_handle_t handle, void *vaddr);
  
  int xenbus_alloc_evtchn(struct xenbus_device *dev, int *port);
  int xenbus_bind_evtchn(struct xenbus_device *dev, int remote_port, int *port);
  int xenbus_free_evtchn(struct xenbus_device *dev, int port);
  
  enum xenbus_state xenbus_read_driver_state(const char *path);
b9075fa96   Joe Perches   treewide: use __p...
209
  __printf(3, 4)
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
210
  void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...);
b9075fa96   Joe Perches   treewide: use __p...
211
  __printf(3, 4)
4bac07c99   Jeremy Fitzhardinge   xen: add the Xenb...
212
213
214
215
216
217
218
  void xenbus_dev_fatal(struct xenbus_device *dev, int err, const char *fmt, ...);
  
  const char *xenbus_strstate(enum xenbus_state state);
  int xenbus_dev_is_online(struct xenbus_device *dev);
  int xenbus_frontend_closed(struct xenbus_device *dev);
  
  #endif /* _XEN_XENBUS_H */