1 /******************************************************************************
2 * Talks to Xen Store to figure out what devices we have.
4 * Copyright (C) 2005 Rusty Russell, IBM Corporation
5 * Copyright (C) 2005 Mike Wray, Hewlett-Packard
6 * Copyright (C) 2005, 2006 XenSource Ltd
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation; or, when distributed
11 * separately from the Linux kernel or incorporated into other
12 * software packages, subject to the following license:
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this source file (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use, copy, modify,
17 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18 * and to permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 #define DPRINTK(fmt, args...) \
34 pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \
35 __func__, __LINE__, ##args)
37 #include <linux/kernel.h>
38 #include <linux/err.h>
39 #include <linux/string.h>
40 #include <linux/ctype.h>
41 #include <linux/fcntl.h>
43 #include <linux/proc_fs.h>
44 #include <linux/notifier.h>
45 #include <linux/kthread.h>
46 #include <linux/mutex.h>
48 #include <linux/slab.h>
51 #include <asm/pgtable.h>
52 #include <asm/xen/hypervisor.h>
55 #include <xen/xenbus.h>
56 #include <xen/events.h>
59 #include <xen/platform_pci.h>
62 #include "xenbus_comms.h"
63 #include "xenbus_probe.h"
67 EXPORT_SYMBOL_GPL(xen_store_evtchn);
69 struct xenstore_domain_interface *xen_store_interface;
70 EXPORT_SYMBOL_GPL(xen_store_interface);
72 static unsigned long xen_store_mfn;
74 static BLOCKING_NOTIFIER_HEAD(xenstore_chain);
76 static void wait_for_devices(struct xenbus_driver *xendrv);
78 static int xenbus_probe_frontend(const char *type, const char *name);
80 static void xenbus_dev_shutdown(struct device *_dev);
82 static int xenbus_dev_suspend(struct device *dev, pm_message_t state);
83 static int xenbus_dev_resume(struct device *dev);
85 /* If something in array of ids matches this device, return it. */
86 static const struct xenbus_device_id *
87 match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev)
89 for (; *arr->devicetype != '\0'; arr++) {
90 if (!strcmp(arr->devicetype, dev->devicetype))
96 int xenbus_match(struct device *_dev, struct device_driver *_drv)
98 struct xenbus_driver *drv = to_xenbus_driver(_drv);
103 return match_device(drv->ids, to_xenbus_device(_dev)) != NULL;
106 static int xenbus_uevent(struct device *_dev, struct kobj_uevent_env *env)
108 struct xenbus_device *dev = to_xenbus_device(_dev);
110 if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype))
116 /* device/<type>/<id> => <type>-<id> */
117 static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename)
119 nodename = strchr(nodename, '/');
120 if (!nodename || strlen(nodename + 1) >= XEN_BUS_ID_SIZE) {
121 printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename);
125 strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE);
126 if (!strchr(bus_id, '/')) {
127 printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id);
130 *strchr(bus_id, '/') = '-';
135 static void free_otherend_details(struct xenbus_device *dev)
137 kfree(dev->otherend);
138 dev->otherend = NULL;
142 static void free_otherend_watch(struct xenbus_device *dev)
144 if (dev->otherend_watch.node) {
145 unregister_xenbus_watch(&dev->otherend_watch);
146 kfree(dev->otherend_watch.node);
147 dev->otherend_watch.node = NULL;
152 int read_otherend_details(struct xenbus_device *xendev,
153 char *id_node, char *path_node)
155 int err = xenbus_gather(XBT_NIL, xendev->nodename,
156 id_node, "%i", &xendev->otherend_id,
157 path_node, NULL, &xendev->otherend,
160 xenbus_dev_fatal(xendev, err,
161 "reading other end details from %s",
165 if (strlen(xendev->otherend) == 0 ||
166 !xenbus_exists(XBT_NIL, xendev->otherend, "")) {
167 xenbus_dev_fatal(xendev, -ENOENT,
168 "unable to read other end from %s. "
169 "missing or inaccessible.",
171 free_otherend_details(xendev);
179 static int read_backend_details(struct xenbus_device *xendev)
181 return read_otherend_details(xendev, "backend-id", "backend");
184 static struct device_attribute xenbus_dev_attrs[] = {
188 /* Bus type for frontend drivers. */
189 static struct xen_bus_type xenbus_frontend = {
191 .levels = 2, /* device/type/<id> */
192 .get_bus_id = frontend_bus_id,
193 .probe = xenbus_probe_frontend,
196 .match = xenbus_match,
197 .uevent = xenbus_uevent,
198 .probe = xenbus_dev_probe,
199 .remove = xenbus_dev_remove,
200 .shutdown = xenbus_dev_shutdown,
201 .dev_attrs = xenbus_dev_attrs,
203 .suspend = xenbus_dev_suspend,
204 .resume = xenbus_dev_resume,
208 static void otherend_changed(struct xenbus_watch *watch,
209 const char **vec, unsigned int len)
211 struct xenbus_device *dev =
212 container_of(watch, struct xenbus_device, otherend_watch);
213 struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver);
214 enum xenbus_state state;
216 /* Protect us against watches firing on old details when the otherend
217 details change, say immediately after a resume. */
218 if (!dev->otherend ||
219 strncmp(dev->otherend, vec[XS_WATCH_PATH],
220 strlen(dev->otherend))) {
221 dev_dbg(&dev->dev, "Ignoring watch at %s\n",
226 state = xenbus_read_driver_state(dev->otherend);
228 dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n",
229 state, xenbus_strstate(state), dev->otherend_watch.node,
233 * Ignore xenbus transitions during shutdown. This prevents us doing
234 * work that can fail e.g., when the rootfs is gone.
236 if (system_state > SYSTEM_RUNNING) {
237 struct xen_bus_type *bus = bus;
238 bus = container_of(dev->dev.bus, struct xen_bus_type, bus);
239 /* If we're frontend, drive the state machine to Closed. */
240 /* This should cause the backend to release our resources. */
241 if ((bus == &xenbus_frontend) && (state == XenbusStateClosing))
242 xenbus_frontend_closed(dev);
246 if (drv->otherend_changed)
247 drv->otherend_changed(dev, state);
251 static int talk_to_otherend(struct xenbus_device *dev)
253 struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver);
255 free_otherend_watch(dev);
256 free_otherend_details(dev);
258 return drv->read_otherend_details(dev);
262 static int watch_otherend(struct xenbus_device *dev)
264 return xenbus_watch_pathfmt(dev, &dev->otherend_watch, otherend_changed,
265 "%s/%s", dev->otherend, "state");
269 int xenbus_dev_probe(struct device *_dev)
271 struct xenbus_device *dev = to_xenbus_device(_dev);
272 struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
273 const struct xenbus_device_id *id;
276 DPRINTK("%s", dev->nodename);
283 id = match_device(drv->ids, dev);
289 err = talk_to_otherend(dev);
291 dev_warn(&dev->dev, "talk_to_otherend on %s failed.\n",
296 err = drv->probe(dev, id);
300 err = watch_otherend(dev);
302 dev_warn(&dev->dev, "watch_otherend on %s failed.\n",
309 xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
310 xenbus_switch_state(dev, XenbusStateClosed);
314 int xenbus_dev_remove(struct device *_dev)
316 struct xenbus_device *dev = to_xenbus_device(_dev);
317 struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
319 DPRINTK("%s", dev->nodename);
321 free_otherend_watch(dev);
322 free_otherend_details(dev);
327 xenbus_switch_state(dev, XenbusStateClosed);
331 static void xenbus_dev_shutdown(struct device *_dev)
333 struct xenbus_device *dev = to_xenbus_device(_dev);
334 unsigned long timeout = 5*HZ;
336 DPRINTK("%s", dev->nodename);
338 get_device(&dev->dev);
339 if (dev->state != XenbusStateConnected) {
340 printk(KERN_INFO "%s: %s: %s != Connected, skipping\n", __func__,
341 dev->nodename, xenbus_strstate(dev->state));
344 xenbus_switch_state(dev, XenbusStateClosing);
345 timeout = wait_for_completion_timeout(&dev->down, timeout);
347 printk(KERN_INFO "%s: %s timeout closing device\n",
348 __func__, dev->nodename);
350 put_device(&dev->dev);
353 int xenbus_register_driver_common(struct xenbus_driver *drv,
354 struct xen_bus_type *bus,
355 struct module *owner,
356 const char *mod_name)
358 drv->driver.name = drv->name;
359 drv->driver.bus = &bus->bus;
360 drv->driver.owner = owner;
361 drv->driver.mod_name = mod_name;
363 return driver_register(&drv->driver);
366 int __xenbus_register_frontend(struct xenbus_driver *drv,
367 struct module *owner, const char *mod_name)
371 drv->read_otherend_details = read_backend_details;
373 ret = xenbus_register_driver_common(drv, &xenbus_frontend,
378 /* If this driver is loaded as a module wait for devices to attach. */
379 wait_for_devices(drv);
383 EXPORT_SYMBOL_GPL(__xenbus_register_frontend);
385 void xenbus_unregister_driver(struct xenbus_driver *drv)
387 driver_unregister(&drv->driver);
389 EXPORT_SYMBOL_GPL(xenbus_unregister_driver);
393 struct xenbus_device *dev;
394 const char *nodename;
397 static int cmp_dev(struct device *dev, void *data)
399 struct xenbus_device *xendev = to_xenbus_device(dev);
400 struct xb_find_info *info = data;
402 if (!strcmp(xendev->nodename, info->nodename)) {
410 struct xenbus_device *xenbus_device_find(const char *nodename,
411 struct bus_type *bus)
413 struct xb_find_info info = { .dev = NULL, .nodename = nodename };
415 bus_for_each_dev(bus, NULL, &info, cmp_dev);
419 static int cleanup_dev(struct device *dev, void *data)
421 struct xenbus_device *xendev = to_xenbus_device(dev);
422 struct xb_find_info *info = data;
423 int len = strlen(info->nodename);
425 DPRINTK("%s", info->nodename);
427 /* Match the info->nodename path, or any subdirectory of that path. */
428 if (strncmp(xendev->nodename, info->nodename, len))
431 /* If the node name is longer, ensure it really is a subdirectory. */
432 if ((strlen(xendev->nodename) > len) && (xendev->nodename[len] != '/'))
440 static void xenbus_cleanup_devices(const char *path, struct bus_type *bus)
442 struct xb_find_info info = { .nodename = path };
446 bus_for_each_dev(bus, NULL, &info, cleanup_dev);
448 device_unregister(&info.dev->dev);
449 put_device(&info.dev->dev);
454 static void xenbus_dev_release(struct device *dev)
457 kfree(to_xenbus_device(dev));
460 static ssize_t xendev_show_nodename(struct device *dev,
461 struct device_attribute *attr, char *buf)
463 return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename);
465 static DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL);
467 static ssize_t xendev_show_devtype(struct device *dev,
468 struct device_attribute *attr, char *buf)
470 return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype);
472 static DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL);
474 static ssize_t xendev_show_modalias(struct device *dev,
475 struct device_attribute *attr, char *buf)
477 return sprintf(buf, "xen:%s\n", to_xenbus_device(dev)->devicetype);
479 static DEVICE_ATTR(modalias, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_modalias, NULL);
481 int xenbus_probe_node(struct xen_bus_type *bus,
483 const char *nodename)
485 char devname[XEN_BUS_ID_SIZE];
487 struct xenbus_device *xendev;
491 enum xenbus_state state = xenbus_read_driver_state(nodename);
493 if (state != XenbusStateInitialising) {
494 /* Device is not new, so ignore it. This can happen if a
495 device is going away after switching to Closed. */
499 stringlen = strlen(nodename) + 1 + strlen(type) + 1;
500 xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
504 xendev->state = XenbusStateInitialising;
506 /* Copy the strings into the extra space. */
508 tmpstring = (char *)(xendev + 1);
509 strcpy(tmpstring, nodename);
510 xendev->nodename = tmpstring;
512 tmpstring += strlen(tmpstring) + 1;
513 strcpy(tmpstring, type);
514 xendev->devicetype = tmpstring;
515 init_completion(&xendev->down);
517 xendev->dev.bus = &bus->bus;
518 xendev->dev.release = xenbus_dev_release;
520 err = bus->get_bus_id(devname, xendev->nodename);
524 dev_set_name(&xendev->dev, devname);
526 /* Register with generic device framework. */
527 err = device_register(&xendev->dev);
531 err = device_create_file(&xendev->dev, &dev_attr_nodename);
533 goto fail_unregister;
535 err = device_create_file(&xendev->dev, &dev_attr_devtype);
537 goto fail_remove_nodename;
539 err = device_create_file(&xendev->dev, &dev_attr_modalias);
541 goto fail_remove_devtype;
545 device_remove_file(&xendev->dev, &dev_attr_devtype);
546 fail_remove_nodename:
547 device_remove_file(&xendev->dev, &dev_attr_nodename);
549 device_unregister(&xendev->dev);
555 /* device/<typename>/<name> */
556 static int xenbus_probe_frontend(const char *type, const char *name)
561 nodename = kasprintf(GFP_KERNEL, "%s/%s/%s",
562 xenbus_frontend.root, type, name);
566 DPRINTK("%s", nodename);
568 err = xenbus_probe_node(&xenbus_frontend, type, nodename);
573 static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type)
577 unsigned int dir_n = 0;
580 dir = xenbus_directory(XBT_NIL, bus->root, type, &dir_n);
584 for (i = 0; i < dir_n; i++) {
585 err = bus->probe(type, dir[i]);
593 int xenbus_probe_devices(struct xen_bus_type *bus)
597 unsigned int i, dir_n;
599 dir = xenbus_directory(XBT_NIL, bus->root, "", &dir_n);
603 for (i = 0; i < dir_n; i++) {
604 err = xenbus_probe_device_type(bus, dir[i]);
612 static unsigned int char_count(const char *str, char c)
614 unsigned int i, ret = 0;
616 for (i = 0; str[i]; i++)
622 static int strsep_len(const char *str, char c, unsigned int len)
626 for (i = 0; str[i]; i++)
632 return (len == 0) ? i : -ERANGE;
635 void xenbus_dev_changed(const char *node, struct xen_bus_type *bus)
638 struct xenbus_device *dev;
639 char type[XEN_BUS_ID_SIZE];
640 const char *p, *root;
642 if (char_count(node, '/') < 2)
645 exists = xenbus_exists(XBT_NIL, node, "");
647 xenbus_cleanup_devices(node, &bus->bus);
651 /* backend/<type>/... or device/<type>/... */
652 p = strchr(node, '/') + 1;
653 snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p);
654 type[XEN_BUS_ID_SIZE-1] = '\0';
656 rootlen = strsep_len(node, '/', bus->levels);
659 root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node);
663 dev = xenbus_device_find(root, &bus->bus);
665 xenbus_probe_node(bus, type, root);
667 put_device(&dev->dev);
671 EXPORT_SYMBOL_GPL(xenbus_dev_changed);
673 static void frontend_changed(struct xenbus_watch *watch,
674 const char **vec, unsigned int len)
678 xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend);
681 /* We watch for devices appearing and vanishing. */
682 static struct xenbus_watch fe_watch = {
684 .callback = frontend_changed,
687 static int xenbus_dev_suspend(struct device *dev, pm_message_t state)
690 struct xenbus_driver *drv;
691 struct xenbus_device *xdev;
695 if (dev->driver == NULL)
697 drv = to_xenbus_driver(dev->driver);
698 xdev = container_of(dev, struct xenbus_device, dev);
700 err = drv->suspend(xdev, state);
703 "xenbus: suspend %s failed: %i\n", dev_name(dev), err);
707 static int xenbus_dev_resume(struct device *dev)
710 struct xenbus_driver *drv;
711 struct xenbus_device *xdev;
715 if (dev->driver == NULL)
718 drv = to_xenbus_driver(dev->driver);
719 xdev = container_of(dev, struct xenbus_device, dev);
721 err = talk_to_otherend(xdev);
724 "xenbus: resume (talk_to_otherend) %s failed: %i\n",
729 xdev->state = XenbusStateInitialising;
732 err = drv->resume(xdev);
735 "xenbus: resume %s failed: %i\n",
741 err = watch_otherend(xdev);
744 "xenbus_probe: resume (watch_otherend) %s failed: "
745 "%d.\n", dev_name(dev), err);
752 /* A flag to determine if xenstored is 'ready' (i.e. has started) */
753 int xenstored_ready = 0;
756 int register_xenstore_notifier(struct notifier_block *nb)
760 if (xenstored_ready > 0)
761 ret = nb->notifier_call(nb, 0, NULL);
763 blocking_notifier_chain_register(&xenstore_chain, nb);
767 EXPORT_SYMBOL_GPL(register_xenstore_notifier);
769 void unregister_xenstore_notifier(struct notifier_block *nb)
771 blocking_notifier_chain_unregister(&xenstore_chain, nb);
773 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier);
775 void xenbus_probe(struct work_struct *unused)
779 /* Enumerate devices in xenstore and watch for changes. */
780 xenbus_probe_devices(&xenbus_frontend);
781 register_xenbus_watch(&fe_watch);
782 xenbus_backend_probe_and_watch();
784 /* Notify others that xenstore is up */
785 blocking_notifier_call_chain(&xenstore_chain, 0, NULL);
787 EXPORT_SYMBOL_GPL(xenbus_probe);
789 static int __init xenbus_probe_initcall(void)
794 if (xen_initial_domain() || xen_hvm_domain())
801 device_initcall(xenbus_probe_initcall);
803 static int __init xenbus_init(void)
806 unsigned long page = 0;
814 /* Register ourselves with the kernel bus subsystem */
815 err = bus_register(&xenbus_frontend.bus);
819 err = xenbus_backend_bus_register();
821 goto out_unreg_front;
824 * Domain0 doesn't have a store_evtchn or store_mfn yet.
826 if (xen_initial_domain()) {
827 struct evtchn_alloc_unbound alloc_unbound;
829 /* Allocate Xenstore page */
830 page = get_zeroed_page(GFP_KERNEL);
834 xen_store_mfn = xen_start_info->store_mfn =
835 pfn_to_mfn(virt_to_phys((void *)page) >>
838 /* Next allocate a local port which xenstored can bind to */
839 alloc_unbound.dom = DOMID_SELF;
840 alloc_unbound.remote_dom = 0;
842 err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
848 xen_store_evtchn = xen_start_info->store_evtchn =
851 xen_store_interface = mfn_to_virt(xen_store_mfn);
853 if (xen_hvm_domain()) {
855 err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
858 xen_store_evtchn = (int)v;
859 err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
862 xen_store_mfn = (unsigned long)v;
863 xen_store_interface = ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE);
865 xen_store_evtchn = xen_start_info->store_evtchn;
866 xen_store_mfn = xen_start_info->store_mfn;
867 xen_store_interface = mfn_to_virt(xen_store_mfn);
872 /* Initialize the interface to xenstore. */
876 "XENBUS: Error initializing xenstore comms: %i\n", err);
880 #ifdef CONFIG_XEN_COMPAT_XENFS
882 * Create xenfs mountpoint in /proc for compatibility with
883 * utilities that expect to find "xenbus" under "/proc/xen".
885 proc_mkdir("xen", NULL);
891 xenbus_backend_bus_unregister();
894 bus_unregister(&xenbus_frontend.bus);
902 postcore_initcall(xenbus_init);
904 MODULE_LICENSE("GPL");
906 static int is_device_connecting(struct device *dev, void *data)
908 struct xenbus_device *xendev = to_xenbus_device(dev);
909 struct device_driver *drv = data;
910 struct xenbus_driver *xendrv;
913 * A device with no driver will never connect. We care only about
914 * devices which should currently be in the process of connecting.
919 /* Is this search limited to a particular driver? */
920 if (drv && (dev->driver != drv))
923 xendrv = to_xenbus_driver(dev->driver);
924 return (xendev->state < XenbusStateConnected ||
925 (xendev->state == XenbusStateConnected &&
926 xendrv->is_ready && !xendrv->is_ready(xendev)));
929 static int exists_connecting_device(struct device_driver *drv)
931 return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
932 is_device_connecting);
935 static int print_device_status(struct device *dev, void *data)
937 struct xenbus_device *xendev = to_xenbus_device(dev);
938 struct device_driver *drv = data;
940 /* Is this operation limited to a particular driver? */
941 if (drv && (dev->driver != drv))
945 /* Information only: is this too noisy? */
946 printk(KERN_INFO "XENBUS: Device with no driver: %s\n",
948 } else if (xendev->state < XenbusStateConnected) {
949 enum xenbus_state rstate = XenbusStateUnknown;
950 if (xendev->otherend)
951 rstate = xenbus_read_driver_state(xendev->otherend);
952 printk(KERN_WARNING "XENBUS: Timeout connecting "
953 "to device: %s (local state %d, remote state %d)\n",
954 xendev->nodename, xendev->state, rstate);
960 /* We only wait for device setup after most initcalls have run. */
961 static int ready_to_wait_for_devices;
964 * On a 5-minute timeout, wait for all devices currently configured. We need
965 * to do this to guarantee that the filesystems and / or network devices
966 * needed for boot are available, before we can allow the boot to proceed.
968 * This needs to be on a late_initcall, to happen after the frontend device
969 * drivers have been initialised, but before the root fs is mounted.
971 * A possible improvement here would be to have the tools add a per-device
972 * flag to the store entry, indicating whether it is needed at boot time.
973 * This would allow people who knew what they were doing to accelerate their
974 * boot slightly, but of course needs tools or manual intervention to set up
975 * those flags correctly.
977 static void wait_for_devices(struct xenbus_driver *xendrv)
979 unsigned long start = jiffies;
980 struct device_driver *drv = xendrv ? &xendrv->driver : NULL;
981 unsigned int seconds_waited = 0;
983 if (!ready_to_wait_for_devices || !xen_domain())
986 while (exists_connecting_device(drv)) {
987 if (time_after(jiffies, start + (seconds_waited+5)*HZ)) {
989 printk(KERN_WARNING "XENBUS: Waiting for "
990 "devices to initialise: ");
992 printk("%us...", 300 - seconds_waited);
993 if (seconds_waited == 300)
997 schedule_timeout_interruptible(HZ/10);
1003 bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,
1004 print_device_status);
1008 static int __init boot_wait_for_devices(void)
1010 if (xen_hvm_domain() && !xen_platform_pci_unplug)
1013 ready_to_wait_for_devices = 1;
1014 wait_for_devices(NULL);
1018 late_initcall(boot_wait_for_devices);