1 #define DPRINTK(fmt, args...) \
2 pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \
3 __func__, __LINE__, ##args)
5 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/ctype.h>
9 #include <linux/fcntl.h>
16 #include <linux/module.h>
19 #include <asm/pgtable.h>
20 #include <asm/xen/hypervisor.h>
22 #include <xen/events.h>
33 static int frontend_bus_id(
char bus_id[
XEN_BUS_ID_SIZE],
const char *nodename)
35 nodename =
strchr(nodename,
'/');
36 if (!nodename ||
strlen(nodename + 1) >= XEN_BUS_ID_SIZE) {
41 strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE);
42 if (!
strchr(bus_id,
'/')) {
46 *
strchr(bus_id,
'/') =
'-';
59 DPRINTK(
"Ignoring buggy device entry console/0");
74 static int xenbus_uevent_frontend(
struct device *_dev,
87 const char **vec,
unsigned int len)
92 static const struct dev_pm_ops xenbus_pm_ops = {
103 .get_bus_id = frontend_bus_id,
104 .probe = xenbus_probe_frontend,
105 .otherend_changed = backend_changed,
109 .uevent = xenbus_uevent_frontend,
115 .pm = &xenbus_pm_ops,
120 const char **vec,
unsigned int len)
131 .callback = frontend_changed,
134 static int read_backend_details(
struct xenbus_device *xendev)
139 static int is_device_connecting(
struct device *dev,
void *
data,
bool ignore_nonessential)
153 if (drv && (dev->
driver != drv))
156 if (ignore_nonessential) {
168 xendrv = to_xenbus_driver(dev->
driver);
173 static int essential_device_connecting(
struct device *dev,
void *data)
175 return is_device_connecting(dev, data,
true );
177 static int non_essential_device_connecting(
struct device *dev,
void *data)
179 return is_device_connecting(dev, data,
false);
182 static int exists_essential_connecting_device(
struct device_driver *drv)
185 essential_device_connecting);
187 static int exists_non_essential_connecting_device(
struct device_driver *drv)
190 non_essential_device_connecting);
193 static int print_device_status(
struct device *dev,
void *data)
199 if (drv && (dev->
driver != drv))
211 "to device: %s (local state %d, remote state %d)\n",
219 static int ready_to_wait_for_devices;
221 static bool wait_loop(
unsigned long start,
unsigned int max_delay,
222 unsigned int *seconds_waited)
224 if (
time_after(jiffies, start + (*seconds_waited+5)*
HZ)) {
225 if (!*seconds_waited)
227 "devices to initialise: ");
228 *seconds_waited += 5;
229 printk(
"%us...", max_delay - *seconds_waited);
230 if (*seconds_waited == max_delay)
256 unsigned int seconds_waited = 0;
258 if (!ready_to_wait_for_devices || !
xen_domain())
261 while (exists_non_essential_connecting_device(drv))
262 if (wait_loop(start, 30, &seconds_waited))
266 while (exists_essential_connecting_device(drv))
267 if (wait_loop(start, 270, &seconds_waited))
274 print_device_status);
288 wait_for_devices(drv);
295 static int backend_state;
297 static void xenbus_reset_backend_state_changed(
struct xenbus_watch *
w,
298 const char **
v,
unsigned int l)
306 static void xenbus_reset_wait_for_backend(
char *be,
int expected)
310 backend_state == expected, 5 *
HZ);
320 static void xenbus_reset_frontend(
char *fe,
char *be,
int be_state)
327 memset(&be_watch, 0,
sizeof(be_watch));
332 be_watch.callback = xenbus_reset_backend_state_changed;
355 kfree(be_watch.node);
358 static void xenbus_check_frontend(
char *
class,
char *dev)
360 int be_state, fe_state,
err;
361 char *backend, *frontend;
377 if (!backend || IS_ERR(backend))
381 xenbus_reset_frontend(frontend, backend, be_state);
391 static void xenbus_reset_state(
void)
393 char **devclass, **
dev;
394 int devclass_n, dev_n;
398 if (IS_ERR(devclass))
401 for (i = 0; i < devclass_n; i++) {
405 for (j = 0; j < dev_n; j++)
406 xenbus_check_frontend(devclass[i], dev[j]);
412 static int frontend_probe_and_watch(
struct notifier_block *notifier,
418 xenbus_reset_state();
427 static int __init xenbus_probe_frontend_init(
void)
448 static int __init boot_wait_for_devices(
void)
453 ready_to_wait_for_devices = 1;
454 wait_for_devices(
NULL);