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(xen_store_evtchn
);
69 struct xenstore_domain_interface
*xen_store_interface
;
70 static unsigned long xen_store_mfn
;
72 static BLOCKING_NOTIFIER_HEAD(xenstore_chain
);
74 static void wait_for_devices(struct xenbus_driver
*xendrv
);
76 static int xenbus_probe_frontend(const char *type
, const char *name
);
78 static void xenbus_dev_shutdown(struct device
*_dev
);
80 static int xenbus_dev_suspend(struct device
*dev
, pm_message_t state
);
81 static int xenbus_dev_resume(struct device
*dev
);
83 /* If something in array of ids matches this device, return it. */
84 static const struct xenbus_device_id
*
85 match_device(const struct xenbus_device_id
*arr
, struct xenbus_device
*dev
)
87 for (; *arr
->devicetype
!= '\0'; arr
++) {
88 if (!strcmp(arr
->devicetype
, dev
->devicetype
))
94 int xenbus_match(struct device
*_dev
, struct device_driver
*_drv
)
96 struct xenbus_driver
*drv
= to_xenbus_driver(_drv
);
101 return match_device(drv
->ids
, to_xenbus_device(_dev
)) != NULL
;
104 static int xenbus_uevent(struct device
*_dev
, struct kobj_uevent_env
*env
)
106 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
108 if (add_uevent_var(env
, "MODALIAS=xen:%s", dev
->devicetype
))
114 /* device/<type>/<id> => <type>-<id> */
115 static int frontend_bus_id(char bus_id
[XEN_BUS_ID_SIZE
], const char *nodename
)
117 nodename
= strchr(nodename
, '/');
118 if (!nodename
|| strlen(nodename
+ 1) >= XEN_BUS_ID_SIZE
) {
119 printk(KERN_WARNING
"XENBUS: bad frontend %s\n", nodename
);
123 strlcpy(bus_id
, nodename
+ 1, XEN_BUS_ID_SIZE
);
124 if (!strchr(bus_id
, '/')) {
125 printk(KERN_WARNING
"XENBUS: bus_id %s no slash\n", bus_id
);
128 *strchr(bus_id
, '/') = '-';
133 static void free_otherend_details(struct xenbus_device
*dev
)
135 kfree(dev
->otherend
);
136 dev
->otherend
= NULL
;
140 static void free_otherend_watch(struct xenbus_device
*dev
)
142 if (dev
->otherend_watch
.node
) {
143 unregister_xenbus_watch(&dev
->otherend_watch
);
144 kfree(dev
->otherend_watch
.node
);
145 dev
->otherend_watch
.node
= NULL
;
150 int read_otherend_details(struct xenbus_device
*xendev
,
151 char *id_node
, char *path_node
)
153 int err
= xenbus_gather(XBT_NIL
, xendev
->nodename
,
154 id_node
, "%i", &xendev
->otherend_id
,
155 path_node
, NULL
, &xendev
->otherend
,
158 xenbus_dev_fatal(xendev
, err
,
159 "reading other end details from %s",
163 if (strlen(xendev
->otherend
) == 0 ||
164 !xenbus_exists(XBT_NIL
, xendev
->otherend
, "")) {
165 xenbus_dev_fatal(xendev
, -ENOENT
,
166 "unable to read other end from %s. "
167 "missing or inaccessible.",
169 free_otherend_details(xendev
);
177 static int read_backend_details(struct xenbus_device
*xendev
)
179 return read_otherend_details(xendev
, "backend-id", "backend");
182 static struct device_attribute xenbus_dev_attrs
[] = {
186 /* Bus type for frontend drivers. */
187 static struct xen_bus_type xenbus_frontend
= {
189 .levels
= 2, /* device/type/<id> */
190 .get_bus_id
= frontend_bus_id
,
191 .probe
= xenbus_probe_frontend
,
194 .match
= xenbus_match
,
195 .uevent
= xenbus_uevent
,
196 .probe
= xenbus_dev_probe
,
197 .remove
= xenbus_dev_remove
,
198 .shutdown
= xenbus_dev_shutdown
,
199 .dev_attrs
= xenbus_dev_attrs
,
201 .suspend
= xenbus_dev_suspend
,
202 .resume
= xenbus_dev_resume
,
206 static void otherend_changed(struct xenbus_watch
*watch
,
207 const char **vec
, unsigned int len
)
209 struct xenbus_device
*dev
=
210 container_of(watch
, struct xenbus_device
, otherend_watch
);
211 struct xenbus_driver
*drv
= to_xenbus_driver(dev
->dev
.driver
);
212 enum xenbus_state state
;
214 /* Protect us against watches firing on old details when the otherend
215 details change, say immediately after a resume. */
216 if (!dev
->otherend
||
217 strncmp(dev
->otherend
, vec
[XS_WATCH_PATH
],
218 strlen(dev
->otherend
))) {
219 dev_dbg(&dev
->dev
, "Ignoring watch at %s\n",
224 state
= xenbus_read_driver_state(dev
->otherend
);
226 dev_dbg(&dev
->dev
, "state is %d, (%s), %s, %s\n",
227 state
, xenbus_strstate(state
), dev
->otherend_watch
.node
,
231 * Ignore xenbus transitions during shutdown. This prevents us doing
232 * work that can fail e.g., when the rootfs is gone.
234 if (system_state
> SYSTEM_RUNNING
) {
235 struct xen_bus_type
*bus
= bus
;
236 bus
= container_of(dev
->dev
.bus
, struct xen_bus_type
, bus
);
237 /* If we're frontend, drive the state machine to Closed. */
238 /* This should cause the backend to release our resources. */
239 if ((bus
== &xenbus_frontend
) && (state
== XenbusStateClosing
))
240 xenbus_frontend_closed(dev
);
244 if (drv
->otherend_changed
)
245 drv
->otherend_changed(dev
, state
);
249 static int talk_to_otherend(struct xenbus_device
*dev
)
251 struct xenbus_driver
*drv
= to_xenbus_driver(dev
->dev
.driver
);
253 free_otherend_watch(dev
);
254 free_otherend_details(dev
);
256 return drv
->read_otherend_details(dev
);
260 static int watch_otherend(struct xenbus_device
*dev
)
262 return xenbus_watch_pathfmt(dev
, &dev
->otherend_watch
, otherend_changed
,
263 "%s/%s", dev
->otherend
, "state");
267 int xenbus_dev_probe(struct device
*_dev
)
269 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
270 struct xenbus_driver
*drv
= to_xenbus_driver(_dev
->driver
);
271 const struct xenbus_device_id
*id
;
274 DPRINTK("%s", dev
->nodename
);
281 id
= match_device(drv
->ids
, dev
);
287 err
= talk_to_otherend(dev
);
289 dev_warn(&dev
->dev
, "talk_to_otherend on %s failed.\n",
294 err
= drv
->probe(dev
, id
);
298 err
= watch_otherend(dev
);
300 dev_warn(&dev
->dev
, "watch_otherend on %s failed.\n",
307 xenbus_dev_error(dev
, err
, "xenbus_dev_probe on %s", dev
->nodename
);
308 xenbus_switch_state(dev
, XenbusStateClosed
);
312 int xenbus_dev_remove(struct device
*_dev
)
314 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
315 struct xenbus_driver
*drv
= to_xenbus_driver(_dev
->driver
);
317 DPRINTK("%s", dev
->nodename
);
319 free_otherend_watch(dev
);
320 free_otherend_details(dev
);
325 xenbus_switch_state(dev
, XenbusStateClosed
);
329 static void xenbus_dev_shutdown(struct device
*_dev
)
331 struct xenbus_device
*dev
= to_xenbus_device(_dev
);
332 unsigned long timeout
= 5*HZ
;
334 DPRINTK("%s", dev
->nodename
);
336 get_device(&dev
->dev
);
337 if (dev
->state
!= XenbusStateConnected
) {
338 printk(KERN_INFO
"%s: %s: %s != Connected, skipping\n", __func__
,
339 dev
->nodename
, xenbus_strstate(dev
->state
));
342 xenbus_switch_state(dev
, XenbusStateClosing
);
343 timeout
= wait_for_completion_timeout(&dev
->down
, timeout
);
345 printk(KERN_INFO
"%s: %s timeout closing device\n",
346 __func__
, dev
->nodename
);
348 put_device(&dev
->dev
);
351 int xenbus_register_driver_common(struct xenbus_driver
*drv
,
352 struct xen_bus_type
*bus
,
353 struct module
*owner
,
354 const char *mod_name
)
356 drv
->driver
.name
= drv
->name
;
357 drv
->driver
.bus
= &bus
->bus
;
358 drv
->driver
.owner
= owner
;
359 drv
->driver
.mod_name
= mod_name
;
361 return driver_register(&drv
->driver
);
364 int __xenbus_register_frontend(struct xenbus_driver
*drv
,
365 struct module
*owner
, const char *mod_name
)
369 drv
->read_otherend_details
= read_backend_details
;
371 ret
= xenbus_register_driver_common(drv
, &xenbus_frontend
,
376 /* If this driver is loaded as a module wait for devices to attach. */
377 wait_for_devices(drv
);
381 EXPORT_SYMBOL_GPL(__xenbus_register_frontend
);
383 void xenbus_unregister_driver(struct xenbus_driver
*drv
)
385 driver_unregister(&drv
->driver
);
387 EXPORT_SYMBOL_GPL(xenbus_unregister_driver
);
391 struct xenbus_device
*dev
;
392 const char *nodename
;
395 static int cmp_dev(struct device
*dev
, void *data
)
397 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
398 struct xb_find_info
*info
= data
;
400 if (!strcmp(xendev
->nodename
, info
->nodename
)) {
408 struct xenbus_device
*xenbus_device_find(const char *nodename
,
409 struct bus_type
*bus
)
411 struct xb_find_info info
= { .dev
= NULL
, .nodename
= nodename
};
413 bus_for_each_dev(bus
, NULL
, &info
, cmp_dev
);
417 static int cleanup_dev(struct device
*dev
, void *data
)
419 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
420 struct xb_find_info
*info
= data
;
421 int len
= strlen(info
->nodename
);
423 DPRINTK("%s", info
->nodename
);
425 /* Match the info->nodename path, or any subdirectory of that path. */
426 if (strncmp(xendev
->nodename
, info
->nodename
, len
))
429 /* If the node name is longer, ensure it really is a subdirectory. */
430 if ((strlen(xendev
->nodename
) > len
) && (xendev
->nodename
[len
] != '/'))
438 static void xenbus_cleanup_devices(const char *path
, struct bus_type
*bus
)
440 struct xb_find_info info
= { .nodename
= path
};
444 bus_for_each_dev(bus
, NULL
, &info
, cleanup_dev
);
446 device_unregister(&info
.dev
->dev
);
447 put_device(&info
.dev
->dev
);
452 static void xenbus_dev_release(struct device
*dev
)
455 kfree(to_xenbus_device(dev
));
458 static ssize_t
xendev_show_nodename(struct device
*dev
,
459 struct device_attribute
*attr
, char *buf
)
461 return sprintf(buf
, "%s\n", to_xenbus_device(dev
)->nodename
);
463 static DEVICE_ATTR(nodename
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_nodename
, NULL
);
465 static ssize_t
xendev_show_devtype(struct device
*dev
,
466 struct device_attribute
*attr
, char *buf
)
468 return sprintf(buf
, "%s\n", to_xenbus_device(dev
)->devicetype
);
470 static DEVICE_ATTR(devtype
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_devtype
, NULL
);
472 static ssize_t
xendev_show_modalias(struct device
*dev
,
473 struct device_attribute
*attr
, char *buf
)
475 return sprintf(buf
, "xen:%s\n", to_xenbus_device(dev
)->devicetype
);
477 static DEVICE_ATTR(modalias
, S_IRUSR
| S_IRGRP
| S_IROTH
, xendev_show_modalias
, NULL
);
479 int xenbus_probe_node(struct xen_bus_type
*bus
,
481 const char *nodename
)
483 char devname
[XEN_BUS_ID_SIZE
];
485 struct xenbus_device
*xendev
;
489 enum xenbus_state state
= xenbus_read_driver_state(nodename
);
491 if (state
!= XenbusStateInitialising
) {
492 /* Device is not new, so ignore it. This can happen if a
493 device is going away after switching to Closed. */
497 stringlen
= strlen(nodename
) + 1 + strlen(type
) + 1;
498 xendev
= kzalloc(sizeof(*xendev
) + stringlen
, GFP_KERNEL
);
502 xendev
->state
= XenbusStateInitialising
;
504 /* Copy the strings into the extra space. */
506 tmpstring
= (char *)(xendev
+ 1);
507 strcpy(tmpstring
, nodename
);
508 xendev
->nodename
= tmpstring
;
510 tmpstring
+= strlen(tmpstring
) + 1;
511 strcpy(tmpstring
, type
);
512 xendev
->devicetype
= tmpstring
;
513 init_completion(&xendev
->down
);
515 xendev
->dev
.bus
= &bus
->bus
;
516 xendev
->dev
.release
= xenbus_dev_release
;
518 err
= bus
->get_bus_id(devname
, xendev
->nodename
);
522 dev_set_name(&xendev
->dev
, devname
);
524 /* Register with generic device framework. */
525 err
= device_register(&xendev
->dev
);
529 err
= device_create_file(&xendev
->dev
, &dev_attr_nodename
);
531 goto fail_unregister
;
533 err
= device_create_file(&xendev
->dev
, &dev_attr_devtype
);
535 goto fail_remove_nodename
;
537 err
= device_create_file(&xendev
->dev
, &dev_attr_modalias
);
539 goto fail_remove_devtype
;
543 device_remove_file(&xendev
->dev
, &dev_attr_devtype
);
544 fail_remove_nodename
:
545 device_remove_file(&xendev
->dev
, &dev_attr_nodename
);
547 device_unregister(&xendev
->dev
);
553 /* device/<typename>/<name> */
554 static int xenbus_probe_frontend(const char *type
, const char *name
)
559 nodename
= kasprintf(GFP_KERNEL
, "%s/%s/%s",
560 xenbus_frontend
.root
, type
, name
);
564 DPRINTK("%s", nodename
);
566 err
= xenbus_probe_node(&xenbus_frontend
, type
, nodename
);
571 static int xenbus_probe_device_type(struct xen_bus_type
*bus
, const char *type
)
575 unsigned int dir_n
= 0;
578 dir
= xenbus_directory(XBT_NIL
, bus
->root
, type
, &dir_n
);
582 for (i
= 0; i
< dir_n
; i
++) {
583 err
= bus
->probe(type
, dir
[i
]);
591 int xenbus_probe_devices(struct xen_bus_type
*bus
)
595 unsigned int i
, dir_n
;
597 dir
= xenbus_directory(XBT_NIL
, bus
->root
, "", &dir_n
);
601 for (i
= 0; i
< dir_n
; i
++) {
602 err
= xenbus_probe_device_type(bus
, dir
[i
]);
610 static unsigned int char_count(const char *str
, char c
)
612 unsigned int i
, ret
= 0;
614 for (i
= 0; str
[i
]; i
++)
620 static int strsep_len(const char *str
, char c
, unsigned int len
)
624 for (i
= 0; str
[i
]; i
++)
630 return (len
== 0) ? i
: -ERANGE
;
633 void xenbus_dev_changed(const char *node
, struct xen_bus_type
*bus
)
636 struct xenbus_device
*dev
;
637 char type
[XEN_BUS_ID_SIZE
];
638 const char *p
, *root
;
640 if (char_count(node
, '/') < 2)
643 exists
= xenbus_exists(XBT_NIL
, node
, "");
645 xenbus_cleanup_devices(node
, &bus
->bus
);
649 /* backend/<type>/... or device/<type>/... */
650 p
= strchr(node
, '/') + 1;
651 snprintf(type
, XEN_BUS_ID_SIZE
, "%.*s", (int)strcspn(p
, "/"), p
);
652 type
[XEN_BUS_ID_SIZE
-1] = '\0';
654 rootlen
= strsep_len(node
, '/', bus
->levels
);
657 root
= kasprintf(GFP_KERNEL
, "%.*s", rootlen
, node
);
661 dev
= xenbus_device_find(root
, &bus
->bus
);
663 xenbus_probe_node(bus
, type
, root
);
665 put_device(&dev
->dev
);
669 EXPORT_SYMBOL_GPL(xenbus_dev_changed
);
671 static void frontend_changed(struct xenbus_watch
*watch
,
672 const char **vec
, unsigned int len
)
676 xenbus_dev_changed(vec
[XS_WATCH_PATH
], &xenbus_frontend
);
679 /* We watch for devices appearing and vanishing. */
680 static struct xenbus_watch fe_watch
= {
682 .callback
= frontend_changed
,
685 static int xenbus_dev_suspend(struct device
*dev
, pm_message_t state
)
688 struct xenbus_driver
*drv
;
689 struct xenbus_device
*xdev
;
693 if (dev
->driver
== NULL
)
695 drv
= to_xenbus_driver(dev
->driver
);
696 xdev
= container_of(dev
, struct xenbus_device
, dev
);
698 err
= drv
->suspend(xdev
, state
);
701 "xenbus: suspend %s failed: %i\n", dev_name(dev
), err
);
705 static int xenbus_dev_resume(struct device
*dev
)
708 struct xenbus_driver
*drv
;
709 struct xenbus_device
*xdev
;
713 if (dev
->driver
== NULL
)
716 drv
= to_xenbus_driver(dev
->driver
);
717 xdev
= container_of(dev
, struct xenbus_device
, dev
);
719 err
= talk_to_otherend(xdev
);
722 "xenbus: resume (talk_to_otherend) %s failed: %i\n",
727 xdev
->state
= XenbusStateInitialising
;
730 err
= drv
->resume(xdev
);
733 "xenbus: resume %s failed: %i\n",
739 err
= watch_otherend(xdev
);
742 "xenbus_probe: resume (watch_otherend) %s failed: "
743 "%d.\n", dev_name(dev
), err
);
750 /* A flag to determine if xenstored is 'ready' (i.e. has started) */
751 int xenstored_ready
= 0;
754 int register_xenstore_notifier(struct notifier_block
*nb
)
758 if (xenstored_ready
> 0)
759 ret
= nb
->notifier_call(nb
, 0, NULL
);
761 blocking_notifier_chain_register(&xenstore_chain
, nb
);
765 EXPORT_SYMBOL_GPL(register_xenstore_notifier
);
767 void unregister_xenstore_notifier(struct notifier_block
*nb
)
769 blocking_notifier_chain_unregister(&xenstore_chain
, nb
);
771 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier
);
773 void xenbus_probe(struct work_struct
*unused
)
777 /* Enumerate devices in xenstore and watch for changes. */
778 xenbus_probe_devices(&xenbus_frontend
);
779 register_xenbus_watch(&fe_watch
);
780 xenbus_backend_probe_and_watch();
782 /* Notify others that xenstore is up */
783 blocking_notifier_call_chain(&xenstore_chain
, 0, NULL
);
785 EXPORT_SYMBOL_GPL(xenbus_probe
);
787 static int __init
xenbus_probe_initcall(void)
792 if (xen_initial_domain() || xen_hvm_domain())
799 device_initcall(xenbus_probe_initcall
);
801 static int __init
xenbus_init(void)
811 /* Register ourselves with the kernel bus subsystem */
812 err
= bus_register(&xenbus_frontend
.bus
);
816 err
= xenbus_backend_bus_register();
818 goto out_unreg_front
;
821 * Domain0 doesn't have a store_evtchn or store_mfn yet.
823 if (xen_initial_domain()) {
824 /* dom0 not yet supported */
826 if (xen_hvm_domain()) {
828 err
= hvm_get_parameter(HVM_PARAM_STORE_EVTCHN
, &v
);
831 xen_store_evtchn
= (int)v
;
832 err
= hvm_get_parameter(HVM_PARAM_STORE_PFN
, &v
);
835 xen_store_mfn
= (unsigned long)v
;
836 xen_store_interface
= ioremap(xen_store_mfn
<< PAGE_SHIFT
, PAGE_SIZE
);
838 xen_store_evtchn
= xen_start_info
->store_evtchn
;
839 xen_store_mfn
= xen_start_info
->store_mfn
;
840 xen_store_interface
= mfn_to_virt(xen_store_mfn
);
845 /* Initialize the interface to xenstore. */
849 "XENBUS: Error initializing xenstore comms: %i\n", err
);
853 #ifdef CONFIG_XEN_COMPAT_XENFS
855 * Create xenfs mountpoint in /proc for compatibility with
856 * utilities that expect to find "xenbus" under "/proc/xen".
858 proc_mkdir("xen", NULL
);
864 xenbus_backend_bus_unregister();
867 bus_unregister(&xenbus_frontend
.bus
);
873 postcore_initcall(xenbus_init
);
875 MODULE_LICENSE("GPL");
877 static int is_device_connecting(struct device
*dev
, void *data
)
879 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
880 struct device_driver
*drv
= data
;
881 struct xenbus_driver
*xendrv
;
884 * A device with no driver will never connect. We care only about
885 * devices which should currently be in the process of connecting.
890 /* Is this search limited to a particular driver? */
891 if (drv
&& (dev
->driver
!= drv
))
894 xendrv
= to_xenbus_driver(dev
->driver
);
895 return (xendev
->state
< XenbusStateConnected
||
896 (xendev
->state
== XenbusStateConnected
&&
897 xendrv
->is_ready
&& !xendrv
->is_ready(xendev
)));
900 static int exists_connecting_device(struct device_driver
*drv
)
902 return bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, drv
,
903 is_device_connecting
);
906 static int print_device_status(struct device
*dev
, void *data
)
908 struct xenbus_device
*xendev
= to_xenbus_device(dev
);
909 struct device_driver
*drv
= data
;
911 /* Is this operation limited to a particular driver? */
912 if (drv
&& (dev
->driver
!= drv
))
916 /* Information only: is this too noisy? */
917 printk(KERN_INFO
"XENBUS: Device with no driver: %s\n",
919 } else if (xendev
->state
< XenbusStateConnected
) {
920 enum xenbus_state rstate
= XenbusStateUnknown
;
921 if (xendev
->otherend
)
922 rstate
= xenbus_read_driver_state(xendev
->otherend
);
923 printk(KERN_WARNING
"XENBUS: Timeout connecting "
924 "to device: %s (local state %d, remote state %d)\n",
925 xendev
->nodename
, xendev
->state
, rstate
);
931 /* We only wait for device setup after most initcalls have run. */
932 static int ready_to_wait_for_devices
;
935 * On a 5-minute timeout, wait for all devices currently configured. We need
936 * to do this to guarantee that the filesystems and / or network devices
937 * needed for boot are available, before we can allow the boot to proceed.
939 * This needs to be on a late_initcall, to happen after the frontend device
940 * drivers have been initialised, but before the root fs is mounted.
942 * A possible improvement here would be to have the tools add a per-device
943 * flag to the store entry, indicating whether it is needed at boot time.
944 * This would allow people who knew what they were doing to accelerate their
945 * boot slightly, but of course needs tools or manual intervention to set up
946 * those flags correctly.
948 static void wait_for_devices(struct xenbus_driver
*xendrv
)
950 unsigned long start
= jiffies
;
951 struct device_driver
*drv
= xendrv
? &xendrv
->driver
: NULL
;
952 unsigned int seconds_waited
= 0;
954 if (!ready_to_wait_for_devices
|| !xen_domain())
957 while (exists_connecting_device(drv
)) {
958 if (time_after(jiffies
, start
+ (seconds_waited
+5)*HZ
)) {
960 printk(KERN_WARNING
"XENBUS: Waiting for "
961 "devices to initialise: ");
963 printk("%us...", 300 - seconds_waited
);
964 if (seconds_waited
== 300)
968 schedule_timeout_interruptible(HZ
/10);
974 bus_for_each_dev(&xenbus_frontend
.bus
, NULL
, drv
,
975 print_device_status
);
979 static int __init
boot_wait_for_devices(void)
981 if (xen_hvm_domain() && !xen_platform_pci_unplug
)
984 ready_to_wait_for_devices
= 1;
985 wait_for_devices(NULL
);
989 late_initcall(boot_wait_for_devices
);