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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 48 | #include <linux/slab.h> |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 49 | |
| 50 | #include <asm/page.h> |
| 51 | #include <asm/pgtable.h> |
| 52 | #include <asm/xen/hypervisor.h> |
Jeremy Fitzhardinge | 1ccbf53 | 2009-10-06 15:11:14 -0700 | [diff] [blame] | 53 | |
| 54 | #include <xen/xen.h> |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 55 | #include <xen/xenbus.h> |
| 56 | #include <xen/events.h> |
| 57 | #include <xen/page.h> |
| 58 | |
Sheng Yang | bee6ab53 | 2010-05-14 12:39:33 +0100 | [diff] [blame] | 59 | #include <xen/hvm.h> |
| 60 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 61 | #include "xenbus_comms.h" |
| 62 | #include "xenbus_probe.h" |
| 63 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 64 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 65 | int xen_store_evtchn; |
Jeremy Fitzhardinge | 8e3e999 | 2009-03-21 23:51:26 -0700 | [diff] [blame] | 66 | EXPORT_SYMBOL_GPL(xen_store_evtchn); |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 67 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 68 | struct xenstore_domain_interface *xen_store_interface; |
Jeremy Fitzhardinge | 8e3e999 | 2009-03-21 23:51:26 -0700 | [diff] [blame] | 69 | EXPORT_SYMBOL_GPL(xen_store_interface); |
| 70 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 71 | static unsigned long xen_store_mfn; |
| 72 | |
| 73 | static BLOCKING_NOTIFIER_HEAD(xenstore_chain); |
| 74 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 75 | /* If something in array of ids matches this device, return it. */ |
| 76 | static const struct xenbus_device_id * |
| 77 | match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) |
| 78 | { |
| 79 | for (; *arr->devicetype != '\0'; arr++) { |
| 80 | if (!strcmp(arr->devicetype, dev->devicetype)) |
| 81 | return arr; |
| 82 | } |
| 83 | return NULL; |
| 84 | } |
| 85 | |
| 86 | int xenbus_match(struct device *_dev, struct device_driver *_drv) |
| 87 | { |
| 88 | struct xenbus_driver *drv = to_xenbus_driver(_drv); |
| 89 | |
| 90 | if (!drv->ids) |
| 91 | return 0; |
| 92 | |
| 93 | return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; |
| 94 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 95 | EXPORT_SYMBOL_GPL(xenbus_match); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 96 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 97 | |
| 98 | int xenbus_uevent(struct device *_dev, struct kobj_uevent_env *env) |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 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 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 107 | EXPORT_SYMBOL_GPL(xenbus_uevent); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 108 | |
| 109 | static void free_otherend_details(struct xenbus_device *dev) |
| 110 | { |
| 111 | kfree(dev->otherend); |
| 112 | dev->otherend = NULL; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static void free_otherend_watch(struct xenbus_device *dev) |
| 117 | { |
| 118 | if (dev->otherend_watch.node) { |
| 119 | unregister_xenbus_watch(&dev->otherend_watch); |
| 120 | kfree(dev->otherend_watch.node); |
| 121 | dev->otherend_watch.node = NULL; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 126 | static int talk_to_otherend(struct xenbus_device *dev) |
| 127 | { |
| 128 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); |
| 129 | |
| 130 | free_otherend_watch(dev); |
| 131 | free_otherend_details(dev); |
| 132 | |
| 133 | return drv->read_otherend_details(dev); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | static int watch_otherend(struct xenbus_device *dev) |
| 139 | { |
| 140 | struct xen_bus_type *bus = container_of(dev->dev.bus, struct xen_bus_type, bus); |
| 141 | |
| 142 | return xenbus_watch_pathfmt(dev, &dev->otherend_watch, bus->otherend_changed, |
| 143 | "%s/%s", dev->otherend, "state"); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | int xenbus_read_otherend_details(struct xenbus_device *xendev, |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 148 | char *id_node, char *path_node) |
| 149 | { |
| 150 | int err = xenbus_gather(XBT_NIL, xendev->nodename, |
| 151 | id_node, "%i", &xendev->otherend_id, |
| 152 | path_node, NULL, &xendev->otherend, |
| 153 | NULL); |
| 154 | if (err) { |
| 155 | xenbus_dev_fatal(xendev, err, |
| 156 | "reading other end details from %s", |
| 157 | xendev->nodename); |
| 158 | return err; |
| 159 | } |
| 160 | if (strlen(xendev->otherend) == 0 || |
| 161 | !xenbus_exists(XBT_NIL, xendev->otherend, "")) { |
| 162 | xenbus_dev_fatal(xendev, -ENOENT, |
| 163 | "unable to read other end from %s. " |
| 164 | "missing or inaccessible.", |
| 165 | xendev->nodename); |
| 166 | free_otherend_details(xendev); |
| 167 | return -ENOENT; |
| 168 | } |
| 169 | |
| 170 | return 0; |
| 171 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 172 | EXPORT_SYMBOL_GPL(xenbus_read_otherend_details); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 173 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 174 | void xenbus_otherend_changed(struct xenbus_watch *watch, |
| 175 | const char **vec, unsigned int len, |
| 176 | int ignore_on_shutdown) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 177 | { |
| 178 | struct xenbus_device *dev = |
| 179 | container_of(watch, struct xenbus_device, otherend_watch); |
| 180 | struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver); |
| 181 | enum xenbus_state state; |
| 182 | |
| 183 | /* Protect us against watches firing on old details when the otherend |
| 184 | details change, say immediately after a resume. */ |
| 185 | if (!dev->otherend || |
| 186 | strncmp(dev->otherend, vec[XS_WATCH_PATH], |
| 187 | strlen(dev->otherend))) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 188 | dev_dbg(&dev->dev, "Ignoring watch at %s\n", |
| 189 | vec[XS_WATCH_PATH]); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
| 193 | state = xenbus_read_driver_state(dev->otherend); |
| 194 | |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 195 | dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n", |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 196 | state, xenbus_strstate(state), dev->otherend_watch.node, |
| 197 | vec[XS_WATCH_PATH]); |
| 198 | |
| 199 | /* |
| 200 | * Ignore xenbus transitions during shutdown. This prevents us doing |
| 201 | * work that can fail e.g., when the rootfs is gone. |
| 202 | */ |
| 203 | if (system_state > SYSTEM_RUNNING) { |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 204 | if (ignore_on_shutdown && (state == XenbusStateClosing)) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 205 | xenbus_frontend_closed(dev); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | if (drv->otherend_changed) |
| 210 | drv->otherend_changed(dev, state); |
| 211 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 212 | EXPORT_SYMBOL_GPL(xenbus_otherend_changed); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 213 | |
| 214 | int xenbus_dev_probe(struct device *_dev) |
| 215 | { |
| 216 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 217 | struct xenbus_driver *drv = to_xenbus_driver(_dev->driver); |
| 218 | const struct xenbus_device_id *id; |
| 219 | int err; |
| 220 | |
| 221 | DPRINTK("%s", dev->nodename); |
| 222 | |
| 223 | if (!drv->probe) { |
| 224 | err = -ENODEV; |
| 225 | goto fail; |
| 226 | } |
| 227 | |
| 228 | id = match_device(drv->ids, dev); |
| 229 | if (!id) { |
| 230 | err = -ENODEV; |
| 231 | goto fail; |
| 232 | } |
| 233 | |
| 234 | err = talk_to_otherend(dev); |
| 235 | if (err) { |
| 236 | dev_warn(&dev->dev, "talk_to_otherend on %s failed.\n", |
| 237 | dev->nodename); |
| 238 | return err; |
| 239 | } |
| 240 | |
| 241 | err = drv->probe(dev, id); |
| 242 | if (err) |
| 243 | goto fail; |
| 244 | |
| 245 | err = watch_otherend(dev); |
| 246 | if (err) { |
| 247 | dev_warn(&dev->dev, "watch_otherend on %s failed.\n", |
| 248 | dev->nodename); |
| 249 | return err; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | fail: |
| 254 | xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); |
| 255 | xenbus_switch_state(dev, XenbusStateClosed); |
| 256 | return -ENODEV; |
| 257 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 258 | EXPORT_SYMBOL_GPL(xenbus_dev_probe); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 259 | |
| 260 | int xenbus_dev_remove(struct device *_dev) |
| 261 | { |
| 262 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 263 | struct xenbus_driver *drv = to_xenbus_driver(_dev->driver); |
| 264 | |
| 265 | DPRINTK("%s", dev->nodename); |
| 266 | |
| 267 | free_otherend_watch(dev); |
| 268 | free_otherend_details(dev); |
| 269 | |
| 270 | if (drv->remove) |
| 271 | drv->remove(dev); |
| 272 | |
| 273 | xenbus_switch_state(dev, XenbusStateClosed); |
| 274 | return 0; |
| 275 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 276 | EXPORT_SYMBOL_GPL(xenbus_dev_remove); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 277 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 278 | void xenbus_dev_shutdown(struct device *_dev) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 279 | { |
| 280 | struct xenbus_device *dev = to_xenbus_device(_dev); |
| 281 | unsigned long timeout = 5*HZ; |
| 282 | |
| 283 | DPRINTK("%s", dev->nodename); |
| 284 | |
| 285 | get_device(&dev->dev); |
| 286 | if (dev->state != XenbusStateConnected) { |
| 287 | printk(KERN_INFO "%s: %s: %s != Connected, skipping\n", __func__, |
| 288 | dev->nodename, xenbus_strstate(dev->state)); |
| 289 | goto out; |
| 290 | } |
| 291 | xenbus_switch_state(dev, XenbusStateClosing); |
| 292 | timeout = wait_for_completion_timeout(&dev->down, timeout); |
| 293 | if (!timeout) |
| 294 | printk(KERN_INFO "%s: %s timeout closing device\n", |
| 295 | __func__, dev->nodename); |
| 296 | out: |
| 297 | put_device(&dev->dev); |
| 298 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 299 | EXPORT_SYMBOL_GPL(xenbus_dev_shutdown); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 300 | |
| 301 | int xenbus_register_driver_common(struct xenbus_driver *drv, |
| 302 | struct xen_bus_type *bus, |
| 303 | struct module *owner, |
| 304 | const char *mod_name) |
| 305 | { |
| 306 | drv->driver.name = drv->name; |
| 307 | drv->driver.bus = &bus->bus; |
| 308 | drv->driver.owner = owner; |
| 309 | drv->driver.mod_name = mod_name; |
| 310 | |
| 311 | return driver_register(&drv->driver); |
| 312 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 313 | EXPORT_SYMBOL_GPL(xenbus_register_driver_common); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 314 | |
| 315 | void xenbus_unregister_driver(struct xenbus_driver *drv) |
| 316 | { |
| 317 | driver_unregister(&drv->driver); |
| 318 | } |
| 319 | EXPORT_SYMBOL_GPL(xenbus_unregister_driver); |
| 320 | |
| 321 | struct xb_find_info |
| 322 | { |
| 323 | struct xenbus_device *dev; |
| 324 | const char *nodename; |
| 325 | }; |
| 326 | |
| 327 | static int cmp_dev(struct device *dev, void *data) |
| 328 | { |
| 329 | struct xenbus_device *xendev = to_xenbus_device(dev); |
| 330 | struct xb_find_info *info = data; |
| 331 | |
| 332 | if (!strcmp(xendev->nodename, info->nodename)) { |
| 333 | info->dev = xendev; |
| 334 | get_device(dev); |
| 335 | return 1; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | struct xenbus_device *xenbus_device_find(const char *nodename, |
| 341 | struct bus_type *bus) |
| 342 | { |
| 343 | struct xb_find_info info = { .dev = NULL, .nodename = nodename }; |
| 344 | |
| 345 | bus_for_each_dev(bus, NULL, &info, cmp_dev); |
| 346 | return info.dev; |
| 347 | } |
| 348 | |
| 349 | static int cleanup_dev(struct device *dev, void *data) |
| 350 | { |
| 351 | struct xenbus_device *xendev = to_xenbus_device(dev); |
| 352 | struct xb_find_info *info = data; |
| 353 | int len = strlen(info->nodename); |
| 354 | |
| 355 | DPRINTK("%s", info->nodename); |
| 356 | |
| 357 | /* Match the info->nodename path, or any subdirectory of that path. */ |
| 358 | if (strncmp(xendev->nodename, info->nodename, len)) |
| 359 | return 0; |
| 360 | |
| 361 | /* If the node name is longer, ensure it really is a subdirectory. */ |
| 362 | if ((strlen(xendev->nodename) > len) && (xendev->nodename[len] != '/')) |
| 363 | return 0; |
| 364 | |
| 365 | info->dev = xendev; |
| 366 | get_device(dev); |
| 367 | return 1; |
| 368 | } |
| 369 | |
| 370 | static void xenbus_cleanup_devices(const char *path, struct bus_type *bus) |
| 371 | { |
| 372 | struct xb_find_info info = { .nodename = path }; |
| 373 | |
| 374 | do { |
| 375 | info.dev = NULL; |
| 376 | bus_for_each_dev(bus, NULL, &info, cleanup_dev); |
| 377 | if (info.dev) { |
| 378 | device_unregister(&info.dev->dev); |
| 379 | put_device(&info.dev->dev); |
| 380 | } |
| 381 | } while (info.dev); |
| 382 | } |
| 383 | |
| 384 | static void xenbus_dev_release(struct device *dev) |
| 385 | { |
| 386 | if (dev) |
| 387 | kfree(to_xenbus_device(dev)); |
| 388 | } |
| 389 | |
| 390 | static ssize_t xendev_show_nodename(struct device *dev, |
| 391 | struct device_attribute *attr, char *buf) |
| 392 | { |
| 393 | return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename); |
| 394 | } |
Jeremy Fitzhardinge | db05fed | 2009-11-24 16:41:47 -0800 | [diff] [blame] | 395 | 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] | 396 | |
| 397 | static ssize_t xendev_show_devtype(struct device *dev, |
| 398 | struct device_attribute *attr, char *buf) |
| 399 | { |
| 400 | return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype); |
| 401 | } |
Jeremy Fitzhardinge | db05fed | 2009-11-24 16:41:47 -0800 | [diff] [blame] | 402 | 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] | 403 | |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 404 | static ssize_t xendev_show_modalias(struct device *dev, |
| 405 | struct device_attribute *attr, char *buf) |
| 406 | { |
| 407 | return sprintf(buf, "xen:%s\n", to_xenbus_device(dev)->devicetype); |
| 408 | } |
Jeremy Fitzhardinge | db05fed | 2009-11-24 16:41:47 -0800 | [diff] [blame] | 409 | 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] | 410 | |
| 411 | int xenbus_probe_node(struct xen_bus_type *bus, |
| 412 | const char *type, |
| 413 | const char *nodename) |
| 414 | { |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 415 | char devname[XEN_BUS_ID_SIZE]; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 416 | int err; |
| 417 | struct xenbus_device *xendev; |
| 418 | size_t stringlen; |
| 419 | char *tmpstring; |
| 420 | |
| 421 | enum xenbus_state state = xenbus_read_driver_state(nodename); |
| 422 | |
| 423 | if (state != XenbusStateInitialising) { |
| 424 | /* Device is not new, so ignore it. This can happen if a |
| 425 | device is going away after switching to Closed. */ |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | stringlen = strlen(nodename) + 1 + strlen(type) + 1; |
| 430 | xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL); |
| 431 | if (!xendev) |
| 432 | return -ENOMEM; |
| 433 | |
| 434 | xendev->state = XenbusStateInitialising; |
| 435 | |
| 436 | /* Copy the strings into the extra space. */ |
| 437 | |
| 438 | tmpstring = (char *)(xendev + 1); |
| 439 | strcpy(tmpstring, nodename); |
| 440 | xendev->nodename = tmpstring; |
| 441 | |
| 442 | tmpstring += strlen(tmpstring) + 1; |
| 443 | strcpy(tmpstring, type); |
| 444 | xendev->devicetype = tmpstring; |
| 445 | init_completion(&xendev->down); |
| 446 | |
| 447 | xendev->dev.bus = &bus->bus; |
| 448 | xendev->dev.release = xenbus_dev_release; |
| 449 | |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 450 | err = bus->get_bus_id(devname, xendev->nodename); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 451 | if (err) |
| 452 | goto fail; |
| 453 | |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 454 | dev_set_name(&xendev->dev, devname); |
| 455 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 456 | /* Register with generic device framework. */ |
| 457 | err = device_register(&xendev->dev); |
| 458 | if (err) |
| 459 | goto fail; |
| 460 | |
| 461 | err = device_create_file(&xendev->dev, &dev_attr_nodename); |
| 462 | if (err) |
| 463 | goto fail_unregister; |
| 464 | |
| 465 | err = device_create_file(&xendev->dev, &dev_attr_devtype); |
| 466 | if (err) |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 467 | goto fail_remove_nodename; |
| 468 | |
| 469 | err = device_create_file(&xendev->dev, &dev_attr_modalias); |
| 470 | if (err) |
| 471 | goto fail_remove_devtype; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 472 | |
| 473 | return 0; |
Mark McLoughlin | d2f0c52 | 2008-04-02 10:54:05 -0700 | [diff] [blame] | 474 | fail_remove_devtype: |
| 475 | device_remove_file(&xendev->dev, &dev_attr_devtype); |
| 476 | fail_remove_nodename: |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 477 | device_remove_file(&xendev->dev, &dev_attr_nodename); |
| 478 | fail_unregister: |
| 479 | device_unregister(&xendev->dev); |
| 480 | fail: |
| 481 | kfree(xendev); |
| 482 | return err; |
| 483 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 484 | EXPORT_SYMBOL_GPL(xenbus_probe_node); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 485 | |
| 486 | static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) |
| 487 | { |
| 488 | int err = 0; |
| 489 | char **dir; |
| 490 | unsigned int dir_n = 0; |
| 491 | int i; |
| 492 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 493 | printk(KERN_CRIT "%s type %s\n", __func__, type); |
| 494 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 495 | dir = xenbus_directory(XBT_NIL, bus->root, type, &dir_n); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 496 | if (IS_ERR(dir)) { |
| 497 | printk(KERN_CRIT "%s failed xenbus_directory\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 498 | return PTR_ERR(dir); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 499 | } |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 500 | |
| 501 | for (i = 0; i < dir_n; i++) { |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 502 | printk(KERN_CRIT "%s %d/%d %s\n", __func__, i+1,dir_n, dir[i]); |
| 503 | err = bus->probe(bus, type, dir[i]); |
| 504 | if (err) { |
| 505 | printk(KERN_CRIT "%s failed\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 506 | break; |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 507 | } |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 508 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 509 | printk("%s done\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 510 | kfree(dir); |
| 511 | return err; |
| 512 | } |
| 513 | |
| 514 | int xenbus_probe_devices(struct xen_bus_type *bus) |
| 515 | { |
| 516 | int err = 0; |
| 517 | char **dir; |
| 518 | unsigned int i, dir_n; |
| 519 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 520 | printk(KERN_CRIT "%s %s\n", __func__, bus->root); |
| 521 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 522 | dir = xenbus_directory(XBT_NIL, bus->root, "", &dir_n); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 523 | if (IS_ERR(dir)) { |
| 524 | printk(KERN_CRIT "%s failed xenbus_directory\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 525 | return PTR_ERR(dir); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 526 | } |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 527 | |
| 528 | for (i = 0; i < dir_n; i++) { |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 529 | printk(KERN_CRIT "%s %d/%d %s\n", __func__, i+1,dir_n, dir[i]); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 530 | err = xenbus_probe_device_type(bus, dir[i]); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 531 | if (err) { |
| 532 | printk(KERN_CRIT "%s failed\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 533 | break; |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 534 | } |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 535 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 536 | printk("%s done\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 537 | kfree(dir); |
| 538 | return err; |
| 539 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 540 | EXPORT_SYMBOL_GPL(xenbus_probe_devices); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 541 | |
| 542 | static unsigned int char_count(const char *str, char c) |
| 543 | { |
| 544 | unsigned int i, ret = 0; |
| 545 | |
| 546 | for (i = 0; str[i]; i++) |
| 547 | if (str[i] == c) |
| 548 | ret++; |
| 549 | return ret; |
| 550 | } |
| 551 | |
| 552 | static int strsep_len(const char *str, char c, unsigned int len) |
| 553 | { |
| 554 | unsigned int i; |
| 555 | |
| 556 | for (i = 0; str[i]; i++) |
| 557 | if (str[i] == c) { |
| 558 | if (len == 0) |
| 559 | return i; |
| 560 | len--; |
| 561 | } |
| 562 | return (len == 0) ? i : -ERANGE; |
| 563 | } |
| 564 | |
| 565 | void xenbus_dev_changed(const char *node, struct xen_bus_type *bus) |
| 566 | { |
| 567 | int exists, rootlen; |
| 568 | struct xenbus_device *dev; |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 569 | char type[XEN_BUS_ID_SIZE]; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 570 | const char *p, *root; |
| 571 | |
| 572 | if (char_count(node, '/') < 2) |
| 573 | return; |
| 574 | |
| 575 | exists = xenbus_exists(XBT_NIL, node, ""); |
| 576 | if (!exists) { |
| 577 | xenbus_cleanup_devices(node, &bus->bus); |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | /* backend/<type>/... or device/<type>/... */ |
| 582 | p = strchr(node, '/') + 1; |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 583 | snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p); |
| 584 | type[XEN_BUS_ID_SIZE-1] = '\0'; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 585 | |
| 586 | rootlen = strsep_len(node, '/', bus->levels); |
| 587 | if (rootlen < 0) |
| 588 | return; |
| 589 | root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node); |
| 590 | if (!root) |
| 591 | return; |
| 592 | |
| 593 | dev = xenbus_device_find(root, &bus->bus); |
| 594 | if (!dev) |
| 595 | xenbus_probe_node(bus, type, root); |
| 596 | else |
| 597 | put_device(&dev->dev); |
| 598 | |
| 599 | kfree(root); |
| 600 | } |
Jeremy Fitzhardinge | c6a960c | 2009-02-09 12:05:53 -0800 | [diff] [blame] | 601 | EXPORT_SYMBOL_GPL(xenbus_dev_changed); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 602 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 603 | int xenbus_dev_suspend(struct device *dev, pm_message_t state) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 604 | { |
| 605 | int err = 0; |
| 606 | struct xenbus_driver *drv; |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 607 | struct xenbus_device *xdev = container_of(dev, struct xenbus_device, dev); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 608 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 609 | DPRINTK("%s", xdev->nodename); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 610 | |
| 611 | if (dev->driver == NULL) |
| 612 | return 0; |
| 613 | drv = to_xenbus_driver(dev->driver); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 614 | if (drv->suspend) |
Ian Campbell | de5b31b | 2009-02-09 12:05:50 -0800 | [diff] [blame] | 615 | err = drv->suspend(xdev, state); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 616 | if (err) |
| 617 | printk(KERN_WARNING |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 618 | "xenbus: suspend %s failed: %i\n", dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 619 | return 0; |
| 620 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 621 | EXPORT_SYMBOL_GPL(xenbus_dev_suspend); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 622 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 623 | int xenbus_dev_resume(struct device *dev) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 624 | { |
| 625 | int err; |
| 626 | struct xenbus_driver *drv; |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 627 | struct xenbus_device *xdev = container_of(dev, struct xenbus_device, dev); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 628 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 629 | DPRINTK("%s", xdev->nodename); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 630 | |
| 631 | if (dev->driver == NULL) |
| 632 | return 0; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 633 | drv = to_xenbus_driver(dev->driver); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 634 | err = talk_to_otherend(xdev); |
| 635 | if (err) { |
| 636 | printk(KERN_WARNING |
| 637 | "xenbus: resume (talk_to_otherend) %s failed: %i\n", |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 638 | dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 639 | return err; |
| 640 | } |
| 641 | |
| 642 | xdev->state = XenbusStateInitialising; |
| 643 | |
| 644 | if (drv->resume) { |
| 645 | err = drv->resume(xdev); |
| 646 | if (err) { |
| 647 | printk(KERN_WARNING |
| 648 | "xenbus: resume %s failed: %i\n", |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 649 | dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 650 | return err; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | err = watch_otherend(xdev); |
| 655 | if (err) { |
| 656 | printk(KERN_WARNING |
| 657 | "xenbus_probe: resume (watch_otherend) %s failed: " |
Kay Sievers | 2a678cc | 2009-01-06 10:44:34 -0800 | [diff] [blame] | 658 | "%d.\n", dev_name(dev), err); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 659 | return err; |
| 660 | } |
| 661 | |
| 662 | return 0; |
| 663 | } |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 664 | EXPORT_SYMBOL_GPL(xenbus_dev_resume); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 665 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 666 | /* A flag to determine if xenstored is 'ready' (i.e. has started) */ |
| 667 | int xenstored_ready = 0; |
| 668 | |
| 669 | |
| 670 | int register_xenstore_notifier(struct notifier_block *nb) |
| 671 | { |
| 672 | int ret = 0; |
| 673 | |
Stefano Stabellini | a947f0f | 2010-10-04 16:10:06 +0100 | [diff] [blame] | 674 | if (xenstored_ready > 0) |
| 675 | ret = nb->notifier_call(nb, 0, NULL); |
| 676 | else |
| 677 | blocking_notifier_chain_register(&xenstore_chain, nb); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 678 | |
| 679 | return ret; |
| 680 | } |
| 681 | EXPORT_SYMBOL_GPL(register_xenstore_notifier); |
| 682 | |
| 683 | void unregister_xenstore_notifier(struct notifier_block *nb) |
| 684 | { |
| 685 | blocking_notifier_chain_unregister(&xenstore_chain, nb); |
| 686 | } |
| 687 | EXPORT_SYMBOL_GPL(unregister_xenstore_notifier); |
| 688 | |
| 689 | void xenbus_probe(struct work_struct *unused) |
| 690 | { |
Stefano Stabellini | a947f0f | 2010-10-04 16:10:06 +0100 | [diff] [blame] | 691 | xenstored_ready = 1; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 692 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 693 | /* Notify others that xenstore is up */ |
| 694 | blocking_notifier_call_chain(&xenstore_chain, 0, NULL); |
| 695 | } |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 696 | EXPORT_SYMBOL_GPL(xenbus_probe); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 697 | |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 698 | static int __init xenbus_probe_initcall(void) |
| 699 | { |
| 700 | if (!xen_domain()) |
| 701 | return -ENODEV; |
| 702 | |
| 703 | if (xen_initial_domain() || xen_hvm_domain()) |
| 704 | return 0; |
| 705 | |
| 706 | xenbus_probe(NULL); |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | device_initcall(xenbus_probe_initcall); |
| 711 | |
| 712 | static int __init xenbus_init(void) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 713 | { |
| 714 | int err = 0; |
Juan Quintela | b37a56d | 2010-09-02 14:53:56 +0100 | [diff] [blame] | 715 | unsigned long page = 0; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 716 | |
| 717 | DPRINTK(""); |
| 718 | |
| 719 | err = -ENODEV; |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 720 | if (!xen_domain()) |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 721 | goto out_error; |
| 722 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 723 | /* |
| 724 | * Domain0 doesn't have a store_evtchn or store_mfn yet. |
| 725 | */ |
Jeremy Fitzhardinge | 6e83358 | 2008-08-19 13:16:17 -0700 | [diff] [blame] | 726 | if (xen_initial_domain()) { |
Juan Quintela | b37a56d | 2010-09-02 14:53:56 +0100 | [diff] [blame] | 727 | struct evtchn_alloc_unbound alloc_unbound; |
| 728 | |
| 729 | /* Allocate Xenstore page */ |
| 730 | page = get_zeroed_page(GFP_KERNEL); |
| 731 | if (!page) |
| 732 | goto out_error; |
| 733 | |
| 734 | xen_store_mfn = xen_start_info->store_mfn = |
| 735 | pfn_to_mfn(virt_to_phys((void *)page) >> |
| 736 | PAGE_SHIFT); |
| 737 | |
| 738 | /* Next allocate a local port which xenstored can bind to */ |
| 739 | alloc_unbound.dom = DOMID_SELF; |
| 740 | alloc_unbound.remote_dom = 0; |
| 741 | |
| 742 | err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, |
| 743 | &alloc_unbound); |
| 744 | if (err == -ENOSYS) |
| 745 | goto out_error; |
| 746 | |
| 747 | BUG_ON(err); |
| 748 | xen_store_evtchn = xen_start_info->store_evtchn = |
| 749 | alloc_unbound.port; |
| 750 | |
| 751 | xen_store_interface = mfn_to_virt(xen_store_mfn); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 752 | } else { |
Sheng Yang | bee6ab53 | 2010-05-14 12:39:33 +0100 | [diff] [blame] | 753 | if (xen_hvm_domain()) { |
| 754 | uint64_t v = 0; |
| 755 | err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v); |
| 756 | if (err) |
| 757 | goto out_error; |
| 758 | xen_store_evtchn = (int)v; |
| 759 | err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v); |
| 760 | if (err) |
| 761 | goto out_error; |
| 762 | xen_store_mfn = (unsigned long)v; |
| 763 | xen_store_interface = ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE); |
| 764 | } else { |
| 765 | xen_store_evtchn = xen_start_info->store_evtchn; |
| 766 | xen_store_mfn = xen_start_info->store_mfn; |
| 767 | xen_store_interface = mfn_to_virt(xen_store_mfn); |
Stefano Stabellini | a947f0f | 2010-10-04 16:10:06 +0100 | [diff] [blame] | 768 | xenstored_ready = 1; |
Sheng Yang | bee6ab53 | 2010-05-14 12:39:33 +0100 | [diff] [blame] | 769 | } |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 770 | } |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 771 | |
| 772 | /* Initialize the interface to xenstore. */ |
| 773 | err = xs_init(); |
| 774 | if (err) { |
| 775 | printk(KERN_WARNING |
| 776 | "XENBUS: Error initializing xenstore comms: %i\n", err); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 777 | goto out_error; |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Alex Zeffertt | 1107ba8 | 2009-01-07 18:07:11 -0800 | [diff] [blame] | 780 | #ifdef CONFIG_XEN_COMPAT_XENFS |
| 781 | /* |
| 782 | * Create xenfs mountpoint in /proc for compatibility with |
| 783 | * utilities that expect to find "xenbus" under "/proc/xen". |
| 784 | */ |
| 785 | proc_mkdir("xen", NULL); |
| 786 | #endif |
| 787 | |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 788 | printk(KERN_CRIT "%s ok\n", __func__); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 789 | return 0; |
| 790 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 791 | out_error: |
Juan Quintela | b37a56d | 2010-09-02 14:53:56 +0100 | [diff] [blame] | 792 | if (page != 0) |
| 793 | free_page(page); |
Ian Campbell | 2de06cc | 2009-02-09 12:05:51 -0800 | [diff] [blame^] | 794 | |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 795 | return err; |
| 796 | } |
| 797 | |
Stefano Stabellini | 183d03c | 2010-05-17 17:08:21 +0100 | [diff] [blame] | 798 | postcore_initcall(xenbus_init); |
Jeremy Fitzhardinge | 4bac07c | 2007-07-17 18:37:06 -0700 | [diff] [blame] | 799 | |
| 800 | MODULE_LICENSE("GPL"); |