Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * Talks to Xen Store to figure out what devices we have. |
| 3 | * |
| 4 | * Copyright (C) 2005 Rusty Russell, IBM Corporation |
| 5 | * Copyright (C) 2005 Mike Wray, Hewlett-Packard |
| 6 | * Copyright (C) 2005, 2006 XenSource Ltd |
| 7 | * |
| 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: |
| 13 | * |
| 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: |
| 20 | * |
| 21 | * The above copyright notice and this permission notice shall be included in |
| 22 | * all copies or substantial portions of the Software. |
| 23 | * |
| 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 |
| 30 | * IN THE SOFTWARE. |
| 31 | */ |
| 32 | |
| 33 | #define DPRINTK(fmt, args...) \ |
| 34 | pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \ |
| 35 | __func__, __LINE__, ##args) |
| 36 | |
| 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> |
| 42 | #include <linux/mm.h> |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 43 | #include <linux/proc_fs.h> |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 44 | #include <linux/notifier.h> |
| 45 | #include <linux/kthread.h> |
| 46 | #include <linux/mutex.h> |
| 47 | #include <linux/io.h> |
| 48 | |
| 49 | #include <asm/page.h> |
| 50 | #include <asm/pgtable.h> |
| 51 | #include <asm/xen/hypervisor.h> |
| 52 | #include <xen/xenbus.h> |
| 53 | #include <xen/events.h> |
| 54 | #include <xen/page.h> |
| 55 | |
| 56 | #include "xenbus_comms.h" |
| 57 | #include "xenbus_probe.h" |
| 58 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 59 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 60 | int xen_store_evtchn; |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 61 | EXPORT_SYMBOL(xen_store_evtchn); |
| 62 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 63 | struct xenstore_domain_interface *xen_store_interface; |
| 64 | static unsigned long xen_store_mfn; |
| 65 | |
| 66 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); |
| 67 | |
| 68 | static void wait_for_devices(struct xenbus_driver *xendrv); |
| 69 | |
| 70 | static int xenbus_probe_frontend(const char *type, const char *name); |
| 71 | |
| 72 | static void xenbus_dev_shutdown(struct device *_dev); |
| 73 | |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 74 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state); |
| 75 | static int xenbus_dev_resume(struct device *dev); |
| 76 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 77 | /* If something in array of ids matches this device, return it. */ |
| 78 | static const struct xenbus_device_id * |
| 79 | match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) |
| 80 | { |
| 81 | for (; *arr->devicetype != '\0'; arr++) { |
| 82 | if (!strcmp(arr->devicetype, dev->devicetype)) |
| 83 | return arr; |
| 84 | } |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | int xenbus_match(struct device *_dev, struct device_driver *_drv) |
| 89 | { |
| 90 | struct xenbus_driver *drv = to_xenbus_driver(_drv); |
| 91 | |
| 92 | if (!drv->ids) |
| 93 | return 0; |
| 94 | |
| 95 | return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; |
| 96 | } |
| 97 | |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 98 | static int xenbus_uevent(struct device *_dev, struct kobj_uevent_env *env) |
| 99 | { |
| 100 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 101 | |
| 102 | if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype)) |
| 103 | return -ENOMEM; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 108 | /* device/<type>/<id> => <type>-<id> */ |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 109 | static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 110 | { |
| 111 | nodename = strchr(nodename, '/'); |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 112 | if (!nodename || strlen(nodename + 1) >= XEN_BUS_ID_SIZE) { |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 113 | printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 117 | strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 118 | if (!strchr(bus_id, '/')) { |
| 119 | printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id); |
| 120 | return -EINVAL; |
| 121 | } |
| 122 | *strchr(bus_id, '/') = '-'; |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | static void free_otherend_details(struct xenbus_device *dev) |
| 128 | { |
| 129 | kfree(dev->otherend); |
| 130 | dev->otherend = NULL; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | static void free_otherend_watch(struct xenbus_device *dev) |
| 135 | { |
| 136 | if (dev->otherend_watch.node) { |
| 137 | unregister_xenbus_watch(&dev->otherend_watch); |
| 138 | kfree(dev->otherend_watch.node); |
| 139 | dev->otherend_watch.node = NULL; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
| 144 | int read_otherend_details(struct xenbus_device *xendev, |
| 145 | char *id_node, char *path_node) |
| 146 | { |
| 147 | int err = xenbus_gather(XBT_NIL, xendev->nodename, |
| 148 | id_node, "%i", &xendev->otherend_id, |
| 149 | path_node, NULL, &xendev->otherend, |
| 150 | NULL); |
| 151 | if (err) { |
| 152 | xenbus_dev_fatal(xendev, err, |
| 153 | "reading other end details from %s", |
| 154 | xendev->nodename); |
| 155 | return err; |
| 156 | } |
| 157 | if (strlen(xendev->otherend) == 0 || |
| 158 | !xenbus_exists(XBT_NIL, xendev->otherend, "")) { |
| 159 | xenbus_dev_fatal(xendev, -ENOENT, |
| 160 | "unable to read other end from %s. " |
| 161 | "missing or inaccessible.", |
| 162 | xendev->nodename); |
| 163 | free_otherend_details(xendev); |
| 164 | return -ENOENT; |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | static int read_backend_details(struct xenbus_device *xendev) |
| 172 | { |
| 173 | return read_otherend_details(xendev, "backend-id", "backend"); |
| 174 | } |
| 175 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 176 | static struct device_attribute xenbus_dev_attrs[] = { |
| 177 | __ATTR_NULL |
| 178 | }; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 179 | |
| 180 | /* Bus type for frontend drivers. */ |
| 181 | static struct xen_bus_type xenbus_frontend = { |
| 182 | .root = "device", |
| 183 | .levels = 2, /* device/type/<id> */ |
| 184 | .get_bus_id = frontend_bus_id, |
| 185 | .probe = xenbus_probe_frontend, |
| 186 | .bus = { |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 187 | .name = "xen", |
| 188 | .match = xenbus_match, |
| 189 | .uevent = xenbus_uevent, |
| 190 | .probe = xenbus_dev_probe, |
| 191 | .remove = xenbus_dev_remove, |
| 192 | .shutdown = xenbus_dev_shutdown, |
| 193 | .dev_attrs = xenbus_dev_attrs, |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 194 | |
| 195 | .suspend = xenbus_dev_suspend, |
| 196 | .resume = xenbus_dev_resume, |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 197 | }, |
| 198 | }; |
| 199 | |
| 200 | static void otherend_changed(struct xenbus_watch *watch, |
| 201 | const char **vec, unsigned int len) |
| 202 | { |
| 203 | struct xenbus_device *dev = |
| 204 | container_of(watch, struct xenbus_device, otherend_watch); |
| 205 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); |
| 206 | enum xenbus_state state; |
| 207 | |
| 208 | /* Protect us against watches firing on old details when the otherend |
| 209 | details change, say immediately after a resume. */ |
| 210 | if (!dev->otherend || |
| 211 | strncmp(dev->otherend, vec[XS_WATCH_PATH], |
| 212 | strlen(dev->otherend))) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 213 | dev_dbg(&dev->dev, "Ignoring watch at %s\n", |
| 214 | vec[XS_WATCH_PATH]); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | |
| 218 | state = xenbus_read_driver_state(dev->otherend); |
| 219 | |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 220 | dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n", |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 221 | state, xenbus_strstate(state), dev->otherend_watch.node, |
| 222 | vec[XS_WATCH_PATH]); |
| 223 | |
| 224 | /* |
| 225 | * Ignore xenbus transitions during shutdown. This prevents us doing |
| 226 | * work that can fail e.g., when the rootfs is gone. |
| 227 | */ |
| 228 | if (system_state > SYSTEM_RUNNING) { |
| 229 | struct xen_bus_type *bus = bus; |
| 230 | bus = container_of(dev->dev.bus, struct xen_bus_type, bus); |
| 231 | /* If we're frontend, drive the state machine to Closed. */ |
| 232 | /* This should cause the backend to release our resources. */ |
| 233 | if ((bus == &xenbus_frontend) && (state == XenbusStateClosing)) |
| 234 | xenbus_frontend_closed(dev); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (drv->otherend_changed) |
| 239 | drv->otherend_changed(dev, state); |
| 240 | } |
| 241 | |
| 242 | |
| 243 | static int talk_to_otherend(struct xenbus_device *dev) |
| 244 | { |
| 245 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); |
| 246 | |
| 247 | free_otherend_watch(dev); |
| 248 | free_otherend_details(dev); |
| 249 | |
| 250 | return drv->read_otherend_details(dev); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | static int watch_otherend(struct xenbus_device *dev) |
| 255 | { |
| 256 | return xenbus_watch_pathfmt(dev, &dev->otherend_watch, otherend_changed, |
| 257 | "%s/%s", dev->otherend, "state"); |
| 258 | } |
| 259 | |
| 260 | |
| 261 | int xenbus_dev_probe(struct device *_dev) |
| 262 | { |
| 263 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 264 | struct xenbus_driver *drv = to_xenbus_driver(_dev->driver); |
| 265 | const struct xenbus_device_id *id; |
| 266 | int err; |
| 267 | |
| 268 | DPRINTK("%s", dev->nodename); |
| 269 | |
| 270 | if (!drv->probe) { |
| 271 | err = -ENODEV; |
| 272 | goto fail; |
| 273 | } |
| 274 | |
| 275 | id = match_device(drv->ids, dev); |
| 276 | if (!id) { |
| 277 | err = -ENODEV; |
| 278 | goto fail; |
| 279 | } |
| 280 | |
| 281 | err = talk_to_otherend(dev); |
| 282 | if (err) { |
| 283 | dev_warn(&dev->dev, "talk_to_otherend on %s failed.\n", |
| 284 | dev->nodename); |
| 285 | return err; |
| 286 | } |
| 287 | |
| 288 | err = drv->probe(dev, id); |
| 289 | if (err) |
| 290 | goto fail; |
| 291 | |
| 292 | err = watch_otherend(dev); |
| 293 | if (err) { |
| 294 | dev_warn(&dev->dev, "watch_otherend on %s failed.\n", |
| 295 | dev->nodename); |
| 296 | return err; |
| 297 | } |
| 298 | |
| 299 | return 0; |
| 300 | fail: |
| 301 | xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); |
| 302 | xenbus_switch_state(dev, XenbusStateClosed); |
| 303 | return -ENODEV; |
| 304 | } |
| 305 | |
| 306 | int xenbus_dev_remove(struct device *_dev) |
| 307 | { |
| 308 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 309 | struct xenbus_driver *drv = to_xenbus_driver(_dev->driver); |
| 310 | |
| 311 | DPRINTK("%s", dev->nodename); |
| 312 | |
| 313 | free_otherend_watch(dev); |
| 314 | free_otherend_details(dev); |
| 315 | |
| 316 | if (drv->remove) |
| 317 | drv->remove(dev); |
| 318 | |
| 319 | xenbus_switch_state(dev, XenbusStateClosed); |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static void xenbus_dev_shutdown(struct device *_dev) |
| 324 | { |
| 325 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 326 | unsigned long timeout = 5*HZ; |
| 327 | |
| 328 | DPRINTK("%s", dev->nodename); |
| 329 | |
| 330 | get_device(&dev->dev); |
| 331 | if (dev->state != XenbusStateConnected) { |
| 332 | printk(KERN_INFO "%s: %s: %s != Connected, skipping\n", __func__, |
| 333 | dev->nodename, xenbus_strstate(dev->state)); |
| 334 | goto out; |
| 335 | } |
| 336 | xenbus_switch_state(dev, XenbusStateClosing); |
| 337 | timeout = wait_for_completion_timeout(&dev->down, timeout); |
| 338 | if (!timeout) |
| 339 | printk(KERN_INFO "%s: %s timeout closing device\n", |
| 340 | __func__, dev->nodename); |
| 341 | out: |
| 342 | put_device(&dev->dev); |
| 343 | } |
| 344 | |
| 345 | int xenbus_register_driver_common(struct xenbus_driver *drv, |
| 346 | struct xen_bus_type *bus, |
| 347 | struct module *owner, |
| 348 | const char *mod_name) |
| 349 | { |
| 350 | drv->driver.name = drv->name; |
| 351 | drv->driver.bus = &bus->bus; |
| 352 | drv->driver.owner = owner; |
| 353 | drv->driver.mod_name = mod_name; |
| 354 | |
| 355 | return driver_register(&drv->driver); |
| 356 | } |
| 357 | |
| 358 | int __xenbus_register_frontend(struct xenbus_driver *drv, |
| 359 | struct module *owner, const char *mod_name) |
| 360 | { |
| 361 | int ret; |
| 362 | |
| 363 | drv->read_otherend_details = read_backend_details; |
| 364 | |
| 365 | ret = xenbus_register_driver_common(drv, &xenbus_frontend, |
| 366 | owner, mod_name); |
| 367 | if (ret) |
| 368 | return ret; |
| 369 | |
| 370 | /* If this driver is loaded as a module wait for devices to attach. */ |
| 371 | wait_for_devices(drv); |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | EXPORT_SYMBOL_GPL(__xenbus_register_frontend); |
| 376 | |
| 377 | void xenbus_unregister_driver(struct xenbus_driver *drv) |
| 378 | { |
| 379 | driver_unregister(&drv->driver); |
| 380 | } |
| 381 | EXPORT_SYMBOL_GPL(xenbus_unregister_driver); |
| 382 | |
| 383 | struct xb_find_info |
| 384 | { |
| 385 | struct xenbus_device *dev; |
| 386 | const char *nodename; |
| 387 | }; |
| 388 | |
| 389 | static int cmp_dev(struct device *dev, void *data) |
| 390 | { |
| 391 | struct xenbus_device *xendev = to_xenbus_device(dev); |
| 392 | struct xb_find_info *info = data; |
| 393 | |
| 394 | if (!strcmp(xendev->nodename, info->nodename)) { |
| 395 | info->dev = xendev; |
| 396 | get_device(dev); |
| 397 | return 1; |
| 398 | } |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | struct xenbus_device *xenbus_device_find(const char *nodename, |
| 403 | struct bus_type *bus) |
| 404 | { |
| 405 | struct xb_find_info info = { .dev = NULL, .nodename = nodename }; |
| 406 | |
| 407 | bus_for_each_dev(bus, NULL, &info, cmp_dev); |
| 408 | return info.dev; |
| 409 | } |
| 410 | |
| 411 | static int cleanup_dev(struct device *dev, void *data) |
| 412 | { |
| 413 | struct xenbus_device *xendev = to_xenbus_device(dev); |
| 414 | struct xb_find_info *info = data; |
| 415 | int len = strlen(info->nodename); |
| 416 | |
| 417 | DPRINTK("%s", info->nodename); |
| 418 | |
| 419 | /* Match the info->nodename path, or any subdirectory of that path. */ |
| 420 | if (strncmp(xendev->nodename, info->nodename, len)) |
| 421 | return 0; |
| 422 | |
| 423 | /* If the node name is longer, ensure it really is a subdirectory. */ |
| 424 | if ((strlen(xendev->nodename) > len) && (xendev->nodename[len] != '/')) |
| 425 | return 0; |
| 426 | |
| 427 | info->dev = xendev; |
| 428 | get_device(dev); |
| 429 | return 1; |
| 430 | } |
| 431 | |
| 432 | static void xenbus_cleanup_devices(const char *path, struct bus_type *bus) |
| 433 | { |
| 434 | struct xb_find_info info = { .nodename = path }; |
| 435 | |
| 436 | do { |
| 437 | info.dev = NULL; |
| 438 | bus_for_each_dev(bus, NULL, &info, cleanup_dev); |
| 439 | if (info.dev) { |
| 440 | device_unregister(&info.dev->dev); |
| 441 | put_device(&info.dev->dev); |
| 442 | } |
| 443 | } while (info.dev); |
| 444 | } |
| 445 | |
| 446 | static void xenbus_dev_release(struct device *dev) |
| 447 | { |
| 448 | if (dev) |
| 449 | kfree(to_xenbus_device(dev)); |
| 450 | } |
| 451 | |
| 452 | static ssize_t xendev_show_nodename(struct device *dev, |
| 453 | struct device_attribute *attr, char *buf) |
| 454 | { |
| 455 | return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename); |
| 456 | } |
Jeremy Fitzhardinge | db05fed | 2009-11-24 16:41:47 -0800 | [diff] [blame] | 457 | static DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 458 | |
| 459 | static ssize_t xendev_show_devtype(struct device *dev, |
| 460 | struct device_attribute *attr, char *buf) |
| 461 | { |
| 462 | return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype); |
| 463 | } |
Jeremy Fitzhardinge | db05fed | 2009-11-24 16:41:47 -0800 | [diff] [blame] | 464 | static DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 465 | |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 466 | static ssize_t xendev_show_modalias(struct device *dev, |
| 467 | struct device_attribute *attr, char *buf) |
| 468 | { |
| 469 | return sprintf(buf, "xen:%s\n", to_xenbus_device(dev)->devicetype); |
| 470 | } |
Jeremy Fitzhardinge | db05fed | 2009-11-24 16:41:47 -0800 | [diff] [blame] | 471 | static DEVICE_ATTR(modalias, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_modalias, NULL); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 472 | |
| 473 | int xenbus_probe_node(struct xen_bus_type *bus, |
| 474 | const char *type, |
| 475 | const char *nodename) |
| 476 | { |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 477 | char devname[XEN_BUS_ID_SIZE]; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 478 | int err; |
| 479 | struct xenbus_device *xendev; |
| 480 | size_t stringlen; |
| 481 | char *tmpstring; |
| 482 | |
| 483 | enum xenbus_state state = xenbus_read_driver_state(nodename); |
| 484 | |
| 485 | if (state != XenbusStateInitialising) { |
| 486 | /* Device is not new, so ignore it. This can happen if a |
| 487 | device is going away after switching to Closed. */ |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | stringlen = strlen(nodename) + 1 + strlen(type) + 1; |
| 492 | xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL); |
| 493 | if (!xendev) |
| 494 | return -ENOMEM; |
| 495 | |
| 496 | xendev->state = XenbusStateInitialising; |
| 497 | |
| 498 | /* Copy the strings into the extra space. */ |
| 499 | |
| 500 | tmpstring = (char *)(xendev + 1); |
| 501 | strcpy(tmpstring, nodename); |
| 502 | xendev->nodename = tmpstring; |
| 503 | |
| 504 | tmpstring += strlen(tmpstring) + 1; |
| 505 | strcpy(tmpstring, type); |
| 506 | xendev->devicetype = tmpstring; |
| 507 | init_completion(&xendev->down); |
| 508 | |
| 509 | xendev->dev.bus = &bus->bus; |
| 510 | xendev->dev.release = xenbus_dev_release; |
| 511 | |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 512 | err = bus->get_bus_id(devname, xendev->nodename); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 513 | if (err) |
| 514 | goto fail; |
| 515 | |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 516 | dev_set_name(&xendev->dev, devname); |
| 517 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 518 | /* Register with generic device framework. */ |
| 519 | err = device_register(&xendev->dev); |
| 520 | if (err) |
| 521 | goto fail; |
| 522 | |
| 523 | err = device_create_file(&xendev->dev, &dev_attr_nodename); |
| 524 | if (err) |
| 525 | goto fail_unregister; |
| 526 | |
| 527 | err = device_create_file(&xendev->dev, &dev_attr_devtype); |
| 528 | if (err) |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 529 | goto fail_remove_nodename; |
| 530 | |
| 531 | err = device_create_file(&xendev->dev, &dev_attr_modalias); |
| 532 | if (err) |
| 533 | goto fail_remove_devtype; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 534 | |
| 535 | return 0; |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 536 | fail_remove_devtype: |
| 537 | device_remove_file(&xendev->dev, &dev_attr_devtype); |
| 538 | fail_remove_nodename: |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 539 | device_remove_file(&xendev->dev, &dev_attr_nodename); |
| 540 | fail_unregister: |
| 541 | device_unregister(&xendev->dev); |
| 542 | fail: |
| 543 | kfree(xendev); |
| 544 | return err; |
| 545 | } |
| 546 | |
| 547 | /* device/<typename>/<name> */ |
| 548 | static int xenbus_probe_frontend(const char *type, const char *name) |
| 549 | { |
| 550 | char *nodename; |
| 551 | int err; |
| 552 | |
| 553 | nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", |
| 554 | xenbus_frontend.root, type, name); |
| 555 | if (!nodename) |
| 556 | return -ENOMEM; |
| 557 | |
| 558 | DPRINTK("%s", nodename); |
| 559 | |
| 560 | err = xenbus_probe_node(&xenbus_frontend, type, nodename); |
| 561 | kfree(nodename); |
| 562 | return err; |
| 563 | } |
| 564 | |
| 565 | static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) |
| 566 | { |
| 567 | int err = 0; |
| 568 | char **dir; |
| 569 | unsigned int dir_n = 0; |
| 570 | int i; |
| 571 | |
| 572 | dir = xenbus_directory(XBT_NIL, bus->root, type, &dir_n); |
| 573 | if (IS_ERR(dir)) |
| 574 | return PTR_ERR(dir); |
| 575 | |
| 576 | for (i = 0; i < dir_n; i++) { |
| 577 | err = bus->probe(type, dir[i]); |
| 578 | if (err) |
| 579 | break; |
| 580 | } |
| 581 | kfree(dir); |
| 582 | return err; |
| 583 | } |
| 584 | |
| 585 | int xenbus_probe_devices(struct xen_bus_type *bus) |
| 586 | { |
| 587 | int err = 0; |
| 588 | char **dir; |
| 589 | unsigned int i, dir_n; |
| 590 | |
| 591 | dir = xenbus_directory(XBT_NIL, bus->root, "", &dir_n); |
| 592 | if (IS_ERR(dir)) |
| 593 | return PTR_ERR(dir); |
| 594 | |
| 595 | for (i = 0; i < dir_n; i++) { |
| 596 | err = xenbus_probe_device_type(bus, dir[i]); |
| 597 | if (err) |
| 598 | break; |
| 599 | } |
| 600 | kfree(dir); |
| 601 | return err; |
| 602 | } |
| 603 | |
| 604 | static unsigned int char_count(const char *str, char c) |
| 605 | { |
| 606 | unsigned int i, ret = 0; |
| 607 | |
| 608 | for (i = 0; str[i]; i++) |
| 609 | if (str[i] == c) |
| 610 | ret++; |
| 611 | return ret; |
| 612 | } |
| 613 | |
| 614 | static int strsep_len(const char *str, char c, unsigned int len) |
| 615 | { |
| 616 | unsigned int i; |
| 617 | |
| 618 | for (i = 0; str[i]; i++) |
| 619 | if (str[i] == c) { |
| 620 | if (len == 0) |
| 621 | return i; |
| 622 | len--; |
| 623 | } |
| 624 | return (len == 0) ? i : -ERANGE; |
| 625 | } |
| 626 | |
| 627 | void xenbus_dev_changed(const char *node, struct xen_bus_type *bus) |
| 628 | { |
| 629 | int exists, rootlen; |
| 630 | struct xenbus_device *dev; |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 631 | char type[XEN_BUS_ID_SIZE]; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 632 | const char *p, *root; |
| 633 | |
| 634 | if (char_count(node, '/') < 2) |
| 635 | return; |
| 636 | |
| 637 | exists = xenbus_exists(XBT_NIL, node, ""); |
| 638 | if (!exists) { |
| 639 | xenbus_cleanup_devices(node, &bus->bus); |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | /* backend/<type>/... or device/<type>/... */ |
| 644 | p = strchr(node, '/') + 1; |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 645 | snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p); |
| 646 | type[XEN_BUS_ID_SIZE-1] = '\0'; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 647 | |
| 648 | rootlen = strsep_len(node, '/', bus->levels); |
| 649 | if (rootlen < 0) |
| 650 | return; |
| 651 | root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node); |
| 652 | if (!root) |
| 653 | return; |
| 654 | |
| 655 | dev = xenbus_device_find(root, &bus->bus); |
| 656 | if (!dev) |
| 657 | xenbus_probe_node(bus, type, root); |
| 658 | else |
| 659 | put_device(&dev->dev); |
| 660 | |
| 661 | kfree(root); |
| 662 | } |
Jeremy Fitzhardinge | c6a960c | 2009-02-09 12:05:53 -0800 | [diff] [blame] | 663 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 664 | |
| 665 | static void frontend_changed(struct xenbus_watch *watch, |
| 666 | const char **vec, unsigned int len) |
| 667 | { |
| 668 | DPRINTK(""); |
| 669 | |
| 670 | xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend); |
| 671 | } |
| 672 | |
| 673 | /* We watch for devices appearing and vanishing. */ |
| 674 | static struct xenbus_watch fe_watch = { |
| 675 | .node = "device", |
| 676 | .callback = frontend_changed, |
| 677 | }; |
| 678 | |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 679 | static int xenbus_dev_suspend(struct device *dev, pm_message_t state) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 680 | { |
| 681 | int err = 0; |
| 682 | struct xenbus_driver *drv; |
| 683 | struct xenbus_device *xdev; |
| 684 | |
| 685 | DPRINTK(""); |
| 686 | |
| 687 | if (dev->driver == NULL) |
| 688 | return 0; |
| 689 | drv = to_xenbus_driver(dev->driver); |
| 690 | xdev = container_of(dev, struct xenbus_device, dev); |
| 691 | if (drv->suspend) |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 692 | err = drv->suspend(xdev, state); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 693 | if (err) |
| 694 | printk(KERN_WARNING |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 695 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 696 | return 0; |
| 697 | } |
| 698 | |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 699 | static int xenbus_dev_resume(struct device *dev) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 700 | { |
| 701 | int err; |
| 702 | struct xenbus_driver *drv; |
| 703 | struct xenbus_device *xdev; |
| 704 | |
| 705 | DPRINTK(""); |
| 706 | |
| 707 | if (dev->driver == NULL) |
| 708 | return 0; |
| 709 | |
| 710 | drv = to_xenbus_driver(dev->driver); |
| 711 | xdev = container_of(dev, struct xenbus_device, dev); |
| 712 | |
| 713 | err = talk_to_otherend(xdev); |
| 714 | if (err) { |
| 715 | printk(KERN_WARNING |
| 716 | "xenbus: resume (talk_to_otherend) %s failed: %i\n", |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 717 | dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 718 | return err; |
| 719 | } |
| 720 | |
| 721 | xdev->state = XenbusStateInitialising; |
| 722 | |
| 723 | if (drv->resume) { |
| 724 | err = drv->resume(xdev); |
| 725 | if (err) { |
| 726 | printk(KERN_WARNING |
| 727 | "xenbus: resume %s failed: %i\n", |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 728 | dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 729 | return err; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | err = watch_otherend(xdev); |
| 734 | if (err) { |
| 735 | printk(KERN_WARNING |
| 736 | "xenbus_probe: resume (watch_otherend) %s failed: " |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 737 | "%d.\n", dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 738 | return err; |
| 739 | } |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 744 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ |
| 745 | int xenstored_ready = 0; |
| 746 | |
| 747 | |
| 748 | int register_xenstore_notifier(struct notifier_block *nb) |
| 749 | { |
| 750 | int ret = 0; |
| 751 | |
| 752 | if (xenstored_ready > 0) |
| 753 | ret = nb->notifier_call(nb, 0, NULL); |
| 754 | else |
| 755 | blocking_notifier_chain_register(&xenstore_chain, nb); |
| 756 | |
| 757 | return ret; |
| 758 | } |
| 759 | EXPORT_SYMBOL_GPL(register_xenstore_notifier); |
| 760 | |
| 761 | void unregister_xenstore_notifier(struct notifier_block *nb) |
| 762 | { |
| 763 | blocking_notifier_chain_unregister(&xenstore_chain, nb); |
| 764 | } |
| 765 | EXPORT_SYMBOL_GPL(unregister_xenstore_notifier); |
| 766 | |
| 767 | void xenbus_probe(struct work_struct *unused) |
| 768 | { |
| 769 | BUG_ON((xenstored_ready <= 0)); |
| 770 | |
| 771 | /* Enumerate devices in xenstore and watch for changes. */ |
| 772 | xenbus_probe_devices(&xenbus_frontend); |
| 773 | register_xenbus_watch(&fe_watch); |
| 774 | xenbus_backend_probe_and_watch(); |
| 775 | |
| 776 | /* Notify others that xenstore is up */ |
| 777 | blocking_notifier_call_chain(&xenstore_chain, 0, NULL); |
| 778 | } |
| 779 | |
| 780 | static int __init xenbus_probe_init(void) |
| 781 | { |
| 782 | int err = 0; |
| 783 | |
| 784 | DPRINTK(""); |
| 785 | |
| 786 | err = -ENODEV; |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 787 | if (!xen_domain()) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 788 | goto out_error; |
| 789 | |
| 790 | /* Register ourselves with the kernel bus subsystem */ |
| 791 | err = bus_register(&xenbus_frontend.bus); |
| 792 | if (err) |
| 793 | goto out_error; |
| 794 | |
| 795 | err = xenbus_backend_bus_register(); |
| 796 | if (err) |
| 797 | goto out_unreg_front; |
| 798 | |
| 799 | /* |
| 800 | * Domain0 doesn't have a store_evtchn or store_mfn yet. |
| 801 | */ |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 802 | if (xen_initial_domain()) { |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 803 | /* dom0 not yet supported */ |
| 804 | } else { |
| 805 | xenstored_ready = 1; |
| 806 | xen_store_evtchn = xen_start_info->store_evtchn; |
| 807 | xen_store_mfn = xen_start_info->store_mfn; |
| 808 | } |
| 809 | xen_store_interface = mfn_to_virt(xen_store_mfn); |
| 810 | |
| 811 | /* Initialize the interface to xenstore. */ |
| 812 | err = xs_init(); |
| 813 | if (err) { |
| 814 | printk(KERN_WARNING |
| 815 | "XENBUS: Error initializing xenstore comms: %i\n", err); |
| 816 | goto out_unreg_back; |
| 817 | } |
| 818 | |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 819 | if (!xen_initial_domain()) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 820 | xenbus_probe(NULL); |
| 821 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 822 | #ifdef CONFIG_XEN_COMPAT_XENFS |
| 823 | /* |
| 824 | * Create xenfs mountpoint in /proc for compatibility with |
| 825 | * utilities that expect to find "xenbus" under "/proc/xen". |
| 826 | */ |
| 827 | proc_mkdir("xen", NULL); |
| 828 | #endif |
| 829 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 830 | return 0; |
| 831 | |
| 832 | out_unreg_back: |
| 833 | xenbus_backend_bus_unregister(); |
| 834 | |
| 835 | out_unreg_front: |
| 836 | bus_unregister(&xenbus_frontend.bus); |
| 837 | |
| 838 | out_error: |
| 839 | return err; |
| 840 | } |
| 841 | |
| 842 | postcore_initcall(xenbus_probe_init); |
| 843 | |
| 844 | MODULE_LICENSE("GPL"); |
| 845 | |
Paolo Bonzini | c6e1971 | 2009-07-08 12:27:37 +0200 | [diff] [blame] | 846 | static int is_device_connecting(struct device *dev, void *data) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 847 | { |
| 848 | struct xenbus_device *xendev = to_xenbus_device(dev); |
| 849 | struct device_driver *drv = data; |
Christian Limpach | 1d78d70 | 2008-04-02 10:54:04 -0700 | [diff] [blame] | 850 | struct xenbus_driver *xendrv; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * A device with no driver will never connect. We care only about |
| 854 | * devices which should currently be in the process of connecting. |
| 855 | */ |
| 856 | if (!dev->driver) |
| 857 | return 0; |
| 858 | |
| 859 | /* Is this search limited to a particular driver? */ |
| 860 | if (drv && (dev->driver != drv)) |
| 861 | return 0; |
| 862 | |
Christian Limpach | 1d78d70 | 2008-04-02 10:54:04 -0700 | [diff] [blame] | 863 | xendrv = to_xenbus_driver(dev->driver); |
Paolo Bonzini | c6e1971 | 2009-07-08 12:27:37 +0200 | [diff] [blame] | 864 | return (xendev->state < XenbusStateConnected || |
| 865 | (xendev->state == XenbusStateConnected && |
| 866 | xendrv->is_ready && !xendrv->is_ready(xendev))); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Paolo Bonzini | c6e1971 | 2009-07-08 12:27:37 +0200 | [diff] [blame] | 869 | static int exists_connecting_device(struct device_driver *drv) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 870 | { |
| 871 | return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, |
Paolo Bonzini | c6e1971 | 2009-07-08 12:27:37 +0200 | [diff] [blame] | 872 | is_device_connecting); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static int print_device_status(struct device *dev, void *data) |
| 876 | { |
| 877 | struct xenbus_device *xendev = to_xenbus_device(dev); |
| 878 | struct device_driver *drv = data; |
| 879 | |
| 880 | /* Is this operation limited to a particular driver? */ |
| 881 | if (drv && (dev->driver != drv)) |
| 882 | return 0; |
| 883 | |
| 884 | if (!dev->driver) { |
| 885 | /* Information only: is this too noisy? */ |
| 886 | printk(KERN_INFO "XENBUS: Device with no driver: %s\n", |
| 887 | xendev->nodename); |
Paolo Bonzini | f8dc330 | 2009-07-08 12:27:38 +0200 | [diff] [blame] | 888 | } else if (xendev->state < XenbusStateConnected) { |
| 889 | enum xenbus_state rstate = XenbusStateUnknown; |
| 890 | if (xendev->otherend) |
| 891 | rstate = xenbus_read_driver_state(xendev->otherend); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 892 | printk(KERN_WARNING "XENBUS: Timeout connecting " |
Paolo Bonzini | f8dc330 | 2009-07-08 12:27:38 +0200 | [diff] [blame] | 893 | "to device: %s (local state %d, remote state %d)\n", |
| 894 | xendev->nodename, xendev->state, rstate); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | /* We only wait for device setup after most initcalls have run. */ |
| 901 | static int ready_to_wait_for_devices; |
| 902 | |
| 903 | /* |
Paolo Bonzini | ae78880 | 2009-07-08 12:27:39 +0200 | [diff] [blame^] | 904 | * On a 5-minute timeout, wait for all devices currently configured. We need |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 905 | * to do this to guarantee that the filesystems and / or network devices |
| 906 | * needed for boot are available, before we can allow the boot to proceed. |
| 907 | * |
| 908 | * This needs to be on a late_initcall, to happen after the frontend device |
| 909 | * drivers have been initialised, but before the root fs is mounted. |
| 910 | * |
| 911 | * A possible improvement here would be to have the tools add a per-device |
| 912 | * flag to the store entry, indicating whether it is needed at boot time. |
| 913 | * This would allow people who knew what they were doing to accelerate their |
| 914 | * boot slightly, but of course needs tools or manual intervention to set up |
| 915 | * those flags correctly. |
| 916 | */ |
| 917 | static void wait_for_devices(struct xenbus_driver *xendrv) |
| 918 | { |
Paolo Bonzini | ae78880 | 2009-07-08 12:27:39 +0200 | [diff] [blame^] | 919 | unsigned long start = jiffies; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 920 | struct device_driver *drv = xendrv ? &xendrv->driver : NULL; |
Paolo Bonzini | ae78880 | 2009-07-08 12:27:39 +0200 | [diff] [blame^] | 921 | unsigned int seconds_waited = 0; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 922 | |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 923 | if (!ready_to_wait_for_devices || !xen_domain()) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 924 | return; |
| 925 | |
Paolo Bonzini | c6e1971 | 2009-07-08 12:27:37 +0200 | [diff] [blame] | 926 | while (exists_connecting_device(drv)) { |
Paolo Bonzini | ae78880 | 2009-07-08 12:27:39 +0200 | [diff] [blame^] | 927 | if (time_after(jiffies, start + (seconds_waited+5)*HZ)) { |
| 928 | if (!seconds_waited) |
| 929 | printk(KERN_WARNING "XENBUS: Waiting for " |
| 930 | "devices to initialise: "); |
| 931 | seconds_waited += 5; |
| 932 | printk("%us...", 300 - seconds_waited); |
| 933 | if (seconds_waited == 300) |
| 934 | break; |
| 935 | } |
| 936 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 937 | schedule_timeout_interruptible(HZ/10); |
| 938 | } |
| 939 | |
Paolo Bonzini | ae78880 | 2009-07-08 12:27:39 +0200 | [diff] [blame^] | 940 | if (seconds_waited) |
| 941 | printk("\n"); |
| 942 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 943 | bus_for_each_dev(&xenbus_frontend.bus, NULL, drv, |
| 944 | print_device_status); |
| 945 | } |
| 946 | |
| 947 | #ifndef MODULE |
| 948 | static int __init boot_wait_for_devices(void) |
| 949 | { |
| 950 | ready_to_wait_for_devices = 1; |
| 951 | wait_for_devices(NULL); |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | late_initcall(boot_wait_for_devices); |
| 956 | #endif |