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 pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #define dev_fmt pr_fmt
36 #define DPRINTK(fmt, args...) \
37 pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \
38 __func__, __LINE__, ##args)
40 #include <linux/kernel.h>
41 #include <linux/err.h>
42 #include <linux/string.h>
43 #include <linux/ctype.h>
44 #include <linux/fcntl.h>
46 #include <linux/proc_fs.h>
47 #include <linux/notifier.h>
48 #include <linux/kthread.h>
49 #include <linux/mutex.h>
51 #include <linux/slab.h>
52 #include <linux/module.h>
55 #include <asm/xen/hypervisor.h>
58 #include <xen/xenbus.h>
59 #include <xen/events.h>
60 #include <xen/xen-ops.h>
68 static int xs_init_irq;
70 EXPORT_SYMBOL_GPL(xen_store_evtchn);
72 struct xenstore_domain_interface *xen_store_interface;
73 EXPORT_SYMBOL_GPL(xen_store_interface);
75 enum xenstore_init xen_store_domain_type;
76 EXPORT_SYMBOL_GPL(xen_store_domain_type);
78 static unsigned long xen_store_gfn;
80 static BLOCKING_NOTIFIER_HEAD(xenstore_chain);
82 /* If something in array of ids matches this device, return it. */
83 static const struct xenbus_device_id *
84 match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev)
86 for (; *arr->devicetype != '\0'; arr++) {
87 if (!strcmp(arr->devicetype, dev->devicetype))
93 int xenbus_match(struct device *_dev, struct device_driver *_drv)
95 struct xenbus_driver *drv = to_xenbus_driver(_drv);
100 return match_device(drv->ids, to_xenbus_device(_dev)) != NULL;
102 EXPORT_SYMBOL_GPL(xenbus_match);
105 static void free_otherend_details(struct xenbus_device *dev)
107 kfree(dev->otherend);
108 dev->otherend = NULL;
112 static void free_otherend_watch(struct xenbus_device *dev)
114 if (dev->otherend_watch.node) {
115 unregister_xenbus_watch(&dev->otherend_watch);
116 kfree(dev->otherend_watch.node);
117 dev->otherend_watch.node = NULL;
122 static int talk_to_otherend(struct xenbus_device *dev)
124 struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver);
126 free_otherend_watch(dev);
127 free_otherend_details(dev);
129 return drv->read_otherend_details(dev);
134 static int watch_otherend(struct xenbus_device *dev)
136 struct xen_bus_type *bus =
137 container_of(dev->dev.bus, struct xen_bus_type, bus);
139 return xenbus_watch_pathfmt(dev, &dev->otherend_watch,
140 bus->otherend_will_handle,
141 bus->otherend_changed,
142 "%s/%s", dev->otherend, "state");
146 int xenbus_read_otherend_details(struct xenbus_device *xendev,
147 char *id_node, char *path_node)
149 int err = xenbus_gather(XBT_NIL, xendev->nodename,
150 id_node, "%i", &xendev->otherend_id,
151 path_node, NULL, &xendev->otherend,
154 xenbus_dev_fatal(xendev, err,
155 "reading other end details from %s",
159 if (strlen(xendev->otherend) == 0 ||
160 !xenbus_exists(XBT_NIL, xendev->otherend, "")) {
161 xenbus_dev_fatal(xendev, -ENOENT,
162 "unable to read other end from %s. "
163 "missing or inaccessible.",
165 free_otherend_details(xendev);
171 EXPORT_SYMBOL_GPL(xenbus_read_otherend_details);
173 void xenbus_otherend_changed(struct xenbus_watch *watch,
174 const char *path, const char *token,
175 int ignore_on_shutdown)
177 struct xenbus_device *dev =
178 container_of(watch, struct xenbus_device, otherend_watch);
179 struct xenbus_driver *drv = to_xenbus_driver(dev->dev.driver);
180 enum xenbus_state state;
182 /* Protect us against watches firing on old details when the otherend
183 details change, say immediately after a resume. */
184 if (!dev->otherend ||
185 strncmp(dev->otherend, path, strlen(dev->otherend))) {
186 dev_dbg(&dev->dev, "Ignoring watch at %s\n", path);
190 state = xenbus_read_driver_state(dev->otherend);
192 dev_dbg(&dev->dev, "state is %d, (%s), %s, %s\n",
193 state, xenbus_strstate(state), dev->otherend_watch.node, path);
196 * Ignore xenbus transitions during shutdown. This prevents us doing
197 * work that can fail e.g., when the rootfs is gone.
199 if (system_state > SYSTEM_RUNNING) {
200 if (ignore_on_shutdown && (state == XenbusStateClosing))
201 xenbus_frontend_closed(dev);
205 if (drv->otherend_changed)
206 drv->otherend_changed(dev, state);
208 EXPORT_SYMBOL_GPL(xenbus_otherend_changed);
210 #define XENBUS_SHOW_STAT(name) \
211 static ssize_t name##_show(struct device *_dev, \
212 struct device_attribute *attr, \
215 struct xenbus_device *dev = to_xenbus_device(_dev); \
217 return sprintf(buf, "%d\n", atomic_read(&dev->name)); \
219 static DEVICE_ATTR_RO(name)
221 XENBUS_SHOW_STAT(event_channels);
222 XENBUS_SHOW_STAT(events);
223 XENBUS_SHOW_STAT(spurious_events);
224 XENBUS_SHOW_STAT(jiffies_eoi_delayed);
226 static ssize_t spurious_threshold_show(struct device *_dev,
227 struct device_attribute *attr,
230 struct xenbus_device *dev = to_xenbus_device(_dev);
232 return sprintf(buf, "%d\n", dev->spurious_threshold);
235 static ssize_t spurious_threshold_store(struct device *_dev,
236 struct device_attribute *attr,
237 const char *buf, size_t count)
239 struct xenbus_device *dev = to_xenbus_device(_dev);
243 ret = kstrtouint(buf, 0, &val);
247 dev->spurious_threshold = val;
252 static DEVICE_ATTR_RW(spurious_threshold);
254 static struct attribute *xenbus_attrs[] = {
255 &dev_attr_event_channels.attr,
256 &dev_attr_events.attr,
257 &dev_attr_spurious_events.attr,
258 &dev_attr_jiffies_eoi_delayed.attr,
259 &dev_attr_spurious_threshold.attr,
263 static const struct attribute_group xenbus_group = {
265 .attrs = xenbus_attrs,
268 int xenbus_dev_probe(struct device *_dev)
270 struct xenbus_device *dev = to_xenbus_device(_dev);
271 struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
272 const struct xenbus_device_id *id;
275 DPRINTK("%s", dev->nodename);
282 id = match_device(drv->ids, dev);
288 err = talk_to_otherend(dev);
290 dev_warn(&dev->dev, "talk_to_otherend on %s failed.\n",
295 if (!try_module_get(drv->driver.owner)) {
296 dev_warn(&dev->dev, "failed to acquire module reference on '%s'\n",
302 down(&dev->reclaim_sem);
303 err = drv->probe(dev, id);
304 up(&dev->reclaim_sem);
308 err = watch_otherend(dev);
310 dev_warn(&dev->dev, "watch_otherend on %s failed.\n",
315 dev->spurious_threshold = 1;
316 if (sysfs_create_group(&dev->dev.kobj, &xenbus_group))
317 dev_warn(&dev->dev, "sysfs_create_group on %s failed.\n",
322 module_put(drv->driver.owner);
324 xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
327 EXPORT_SYMBOL_GPL(xenbus_dev_probe);
329 void xenbus_dev_remove(struct device *_dev)
331 struct xenbus_device *dev = to_xenbus_device(_dev);
332 struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
334 DPRINTK("%s", dev->nodename);
336 sysfs_remove_group(&dev->dev.kobj, &xenbus_group);
338 free_otherend_watch(dev);
341 down(&dev->reclaim_sem);
343 up(&dev->reclaim_sem);
346 module_put(drv->driver.owner);
348 free_otherend_details(dev);
351 * If the toolstack has forced the device state to closing then set
352 * the state to closed now to allow it to be cleaned up.
353 * Similarly, if the driver does not support re-bind, set the
356 if (!drv->allow_rebind ||
357 xenbus_read_driver_state(dev->nodename) == XenbusStateClosing)
358 xenbus_switch_state(dev, XenbusStateClosed);
360 EXPORT_SYMBOL_GPL(xenbus_dev_remove);
362 int xenbus_register_driver_common(struct xenbus_driver *drv,
363 struct xen_bus_type *bus,
364 struct module *owner, const char *mod_name)
366 drv->driver.name = drv->name ? drv->name : drv->ids[0].devicetype;
367 drv->driver.bus = &bus->bus;
368 drv->driver.owner = owner;
369 drv->driver.mod_name = mod_name;
371 return driver_register(&drv->driver);
373 EXPORT_SYMBOL_GPL(xenbus_register_driver_common);
375 void xenbus_unregister_driver(struct xenbus_driver *drv)
377 driver_unregister(&drv->driver);
379 EXPORT_SYMBOL_GPL(xenbus_unregister_driver);
381 struct xb_find_info {
382 struct xenbus_device *dev;
383 const char *nodename;
386 static int cmp_dev(struct device *dev, void *data)
388 struct xenbus_device *xendev = to_xenbus_device(dev);
389 struct xb_find_info *info = data;
391 if (!strcmp(xendev->nodename, info->nodename)) {
399 static struct xenbus_device *xenbus_device_find(const char *nodename,
400 struct bus_type *bus)
402 struct xb_find_info info = { .dev = NULL, .nodename = nodename };
404 bus_for_each_dev(bus, NULL, &info, cmp_dev);
408 static int cleanup_dev(struct device *dev, void *data)
410 struct xenbus_device *xendev = to_xenbus_device(dev);
411 struct xb_find_info *info = data;
412 int len = strlen(info->nodename);
414 DPRINTK("%s", info->nodename);
416 /* Match the info->nodename path, or any subdirectory of that path. */
417 if (strncmp(xendev->nodename, info->nodename, len))
420 /* If the node name is longer, ensure it really is a subdirectory. */
421 if ((strlen(xendev->nodename) > len) && (xendev->nodename[len] != '/'))
429 static void xenbus_cleanup_devices(const char *path, struct bus_type *bus)
431 struct xb_find_info info = { .nodename = path };
435 bus_for_each_dev(bus, NULL, &info, cleanup_dev);
437 device_unregister(&info.dev->dev);
438 put_device(&info.dev->dev);
443 static void xenbus_dev_release(struct device *dev)
446 kfree(to_xenbus_device(dev));
449 static ssize_t nodename_show(struct device *dev,
450 struct device_attribute *attr, char *buf)
452 return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename);
454 static DEVICE_ATTR_RO(nodename);
456 static ssize_t devtype_show(struct device *dev,
457 struct device_attribute *attr, char *buf)
459 return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype);
461 static DEVICE_ATTR_RO(devtype);
463 static ssize_t modalias_show(struct device *dev,
464 struct device_attribute *attr, char *buf)
466 return sprintf(buf, "%s:%s\n", dev->bus->name,
467 to_xenbus_device(dev)->devicetype);
469 static DEVICE_ATTR_RO(modalias);
471 static ssize_t state_show(struct device *dev,
472 struct device_attribute *attr, char *buf)
474 return sprintf(buf, "%s\n",
475 xenbus_strstate(to_xenbus_device(dev)->state));
477 static DEVICE_ATTR_RO(state);
479 static struct attribute *xenbus_dev_attrs[] = {
480 &dev_attr_nodename.attr,
481 &dev_attr_devtype.attr,
482 &dev_attr_modalias.attr,
483 &dev_attr_state.attr,
487 static const struct attribute_group xenbus_dev_group = {
488 .attrs = xenbus_dev_attrs,
491 const struct attribute_group *xenbus_dev_groups[] = {
495 EXPORT_SYMBOL_GPL(xenbus_dev_groups);
497 int xenbus_probe_node(struct xen_bus_type *bus,
499 const char *nodename)
501 char devname[XEN_BUS_ID_SIZE];
503 struct xenbus_device *xendev;
507 enum xenbus_state state = xenbus_read_driver_state(nodename);
509 if (state != XenbusStateInitialising) {
510 /* Device is not new, so ignore it. This can happen if a
511 device is going away after switching to Closed. */
515 stringlen = strlen(nodename) + 1 + strlen(type) + 1;
516 xendev = kzalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
520 xendev->state = XenbusStateInitialising;
522 /* Copy the strings into the extra space. */
524 tmpstring = (char *)(xendev + 1);
525 strcpy(tmpstring, nodename);
526 xendev->nodename = tmpstring;
528 tmpstring += strlen(tmpstring) + 1;
529 strcpy(tmpstring, type);
530 xendev->devicetype = tmpstring;
531 init_completion(&xendev->down);
533 xendev->dev.bus = &bus->bus;
534 xendev->dev.release = xenbus_dev_release;
536 err = bus->get_bus_id(devname, xendev->nodename);
540 dev_set_name(&xendev->dev, "%s", devname);
541 sema_init(&xendev->reclaim_sem, 1);
543 /* Register with generic device framework. */
544 err = device_register(&xendev->dev);
546 put_device(&xendev->dev);
556 EXPORT_SYMBOL_GPL(xenbus_probe_node);
558 static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type)
562 unsigned int dir_n = 0;
565 dir = xenbus_directory(XBT_NIL, bus->root, type, &dir_n);
569 for (i = 0; i < dir_n; i++) {
570 err = bus->probe(bus, type, dir[i]);
579 int xenbus_probe_devices(struct xen_bus_type *bus)
583 unsigned int i, dir_n;
585 dir = xenbus_directory(XBT_NIL, bus->root, "", &dir_n);
589 for (i = 0; i < dir_n; i++) {
590 err = xenbus_probe_device_type(bus, dir[i]);
598 EXPORT_SYMBOL_GPL(xenbus_probe_devices);
600 static unsigned int char_count(const char *str, char c)
602 unsigned int i, ret = 0;
604 for (i = 0; str[i]; i++)
610 static int strsep_len(const char *str, char c, unsigned int len)
614 for (i = 0; str[i]; i++)
620 return (len == 0) ? i : -ERANGE;
623 void xenbus_dev_changed(const char *node, struct xen_bus_type *bus)
626 struct xenbus_device *dev;
627 char type[XEN_BUS_ID_SIZE];
628 const char *p, *root;
630 if (char_count(node, '/') < 2)
633 exists = xenbus_exists(XBT_NIL, node, "");
635 xenbus_cleanup_devices(node, &bus->bus);
639 /* backend/<type>/... or device/<type>/... */
640 p = strchr(node, '/') + 1;
641 snprintf(type, XEN_BUS_ID_SIZE, "%.*s", (int)strcspn(p, "/"), p);
642 type[XEN_BUS_ID_SIZE-1] = '\0';
644 rootlen = strsep_len(node, '/', bus->levels);
647 root = kasprintf(GFP_KERNEL, "%.*s", rootlen, node);
651 dev = xenbus_device_find(root, &bus->bus);
653 xenbus_probe_node(bus, type, root);
655 put_device(&dev->dev);
659 EXPORT_SYMBOL_GPL(xenbus_dev_changed);
661 int xenbus_dev_suspend(struct device *dev)
664 struct xenbus_driver *drv;
665 struct xenbus_device *xdev
666 = container_of(dev, struct xenbus_device, dev);
668 DPRINTK("%s", xdev->nodename);
670 if (dev->driver == NULL)
672 drv = to_xenbus_driver(dev->driver);
674 err = drv->suspend(xdev);
676 dev_warn(dev, "suspend failed: %i\n", err);
679 EXPORT_SYMBOL_GPL(xenbus_dev_suspend);
681 int xenbus_dev_resume(struct device *dev)
684 struct xenbus_driver *drv;
685 struct xenbus_device *xdev
686 = container_of(dev, struct xenbus_device, dev);
688 DPRINTK("%s", xdev->nodename);
690 if (dev->driver == NULL)
692 drv = to_xenbus_driver(dev->driver);
693 err = talk_to_otherend(xdev);
695 dev_warn(dev, "resume (talk_to_otherend) failed: %i\n", err);
699 xdev->state = XenbusStateInitialising;
702 err = drv->resume(xdev);
704 dev_warn(dev, "resume failed: %i\n", err);
709 err = watch_otherend(xdev);
711 dev_warn(dev, "resume (watch_otherend) failed: %d\n", err);
717 EXPORT_SYMBOL_GPL(xenbus_dev_resume);
719 int xenbus_dev_cancel(struct device *dev)
725 EXPORT_SYMBOL_GPL(xenbus_dev_cancel);
727 /* A flag to determine if xenstored is 'ready' (i.e. has started) */
731 int register_xenstore_notifier(struct notifier_block *nb)
735 if (xenstored_ready > 0)
736 ret = nb->notifier_call(nb, 0, NULL);
738 blocking_notifier_chain_register(&xenstore_chain, nb);
742 EXPORT_SYMBOL_GPL(register_xenstore_notifier);
744 void unregister_xenstore_notifier(struct notifier_block *nb)
746 blocking_notifier_chain_unregister(&xenstore_chain, nb);
748 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier);
750 static void xenbus_probe(void)
754 if (!xen_store_interface) {
755 xen_store_interface = memremap(xen_store_gfn << XEN_PAGE_SHIFT,
756 XEN_PAGE_SIZE, MEMREMAP_WB);
758 * Now it is safe to free the IRQ used for xenstore late
759 * initialization. No need to unbind: it is about to be
760 * bound again from xb_init_comms. Note that calling
761 * unbind_from_irqhandler now would result in xen_evtchn_close()
762 * being called and the event channel not being enabled again
763 * afterwards, resulting in missed event notifications.
765 free_irq(xs_init_irq, &xb_waitq);
769 * In the HVM case, xenbus_init() deferred its call to
770 * xs_init() in case callbacks were not operational yet.
773 if (xen_store_domain_type == XS_HVM)
776 /* Notify others that xenstore is up */
777 blocking_notifier_call_chain(&xenstore_chain, 0, NULL);
781 * Returns true when XenStore init must be deferred in order to
782 * allow the PCI platform device to be initialised, before we
783 * can actually have event channel interrupts working.
785 static bool xs_hvm_defer_init_for_callback(void)
787 #ifdef CONFIG_XEN_PVHVM
788 return xen_store_domain_type == XS_HVM &&
789 !xen_have_vector_callback;
795 static int xenbus_probe_thread(void *unused)
800 * We actually just want to wait for *any* trigger of xb_waitq,
801 * and run xenbus_probe() the moment it occurs.
803 prepare_to_wait(&xb_waitq, &w, TASK_INTERRUPTIBLE);
805 finish_wait(&xb_waitq, &w);
812 static int __init xenbus_probe_initcall(void)
818 * Probe XenBus here in the XS_PV case, and also XS_HVM unless we
819 * need to wait for the platform PCI device to come up or
820 * xen_store_interface is not ready.
822 if (xen_store_domain_type == XS_PV ||
823 (xen_store_domain_type == XS_HVM &&
824 !xs_hvm_defer_init_for_callback() &&
825 xen_store_interface != NULL))
829 * For XS_LOCAL or when xen_store_interface is not ready, spawn a
830 * thread which will wait for xenstored or a xenstore-stubdom to be
831 * started, then probe. It will be triggered when communication
832 * starts happening, by waiting on xb_waitq.
834 if (xen_store_domain_type == XS_LOCAL || xen_store_interface == NULL) {
835 struct task_struct *probe_task;
837 probe_task = kthread_run(xenbus_probe_thread, NULL,
839 if (IS_ERR(probe_task))
840 return PTR_ERR(probe_task);
844 device_initcall(xenbus_probe_initcall);
846 int xen_set_callback_via(uint64_t via)
848 struct xen_hvm_param a;
851 a.domid = DOMID_SELF;
852 a.index = HVM_PARAM_CALLBACK_IRQ;
855 ret = HYPERVISOR_hvm_op(HVMOP_set_param, &a);
860 * If xenbus_probe_initcall() deferred the xenbus_probe()
861 * due to the callback not functioning yet, we can do it now.
863 if (!xenstored_ready && xs_hvm_defer_init_for_callback())
868 EXPORT_SYMBOL_GPL(xen_set_callback_via);
870 /* Set up event channel for xenstored which is run as a local process
871 * (this is normally used only in dom0)
873 static int __init xenstored_local_init(void)
876 unsigned long page = 0;
877 struct evtchn_alloc_unbound alloc_unbound;
879 /* Allocate Xenstore page */
880 page = get_zeroed_page(GFP_KERNEL);
884 xen_store_gfn = virt_to_gfn((void *)page);
886 /* Next allocate a local port which xenstored can bind to */
887 alloc_unbound.dom = DOMID_SELF;
888 alloc_unbound.remote_dom = DOMID_SELF;
890 err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
896 xen_store_evtchn = alloc_unbound.port;
906 static int xenbus_resume_cb(struct notifier_block *nb,
907 unsigned long action, void *data)
911 if (xen_hvm_domain()) {
914 err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
916 xen_store_evtchn = v;
918 pr_warn("Cannot update xenstore event channel: %d\n",
921 xen_store_evtchn = xen_start_info->store_evtchn;
926 static struct notifier_block xenbus_resume_nb = {
927 .notifier_call = xenbus_resume_cb,
930 static irqreturn_t xenbus_late_init(int irq, void *unused)
935 err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
936 if (err || !v || !~v)
938 xen_store_gfn = (unsigned long)v;
944 static int __init xenbus_init(void)
949 xen_store_domain_type = XS_UNKNOWN;
954 xenbus_ring_ops_init();
957 xen_store_domain_type = XS_PV;
958 if (xen_hvm_domain())
959 xen_store_domain_type = XS_HVM;
960 if (xen_hvm_domain() && xen_initial_domain())
961 xen_store_domain_type = XS_LOCAL;
962 if (xen_pv_domain() && !xen_start_info->store_evtchn)
963 xen_store_domain_type = XS_LOCAL;
964 if (xen_pv_domain() && xen_start_info->store_evtchn)
967 switch (xen_store_domain_type) {
969 err = xenstored_local_init();
972 xen_store_interface = gfn_to_virt(xen_store_gfn);
975 xen_store_evtchn = xen_start_info->store_evtchn;
976 xen_store_gfn = xen_start_info->store_mfn;
977 xen_store_interface = gfn_to_virt(xen_store_gfn);
980 err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
983 xen_store_evtchn = (int)v;
984 err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
988 * Uninitialized hvm_params are zero and return no error.
989 * Although it is theoretically possible to have
990 * HVM_PARAM_STORE_PFN set to zero on purpose, in reality it is
991 * not zero when valid. If zero, it means that Xenstore hasn't
992 * been properly initialized. Instead of attempting to map a
993 * wrong guest physical address return error.
995 * Also recognize all bits set as an invalid/uninitialized value.
1004 /* Avoid truncation on 32-bit. */
1005 #if BITS_PER_LONG == 32
1006 if (v > ULONG_MAX) {
1007 pr_err("%s: cannot handle HVM_PARAM_STORE_PFN=%llx > ULONG_MAX\n",
1013 xen_store_gfn = (unsigned long)v;
1014 xen_store_interface =
1015 memremap(xen_store_gfn << XEN_PAGE_SHIFT,
1016 XEN_PAGE_SIZE, MEMREMAP_WB);
1017 if (xen_store_interface->connection != XENSTORE_CONNECTED)
1021 err = bind_evtchn_to_irqhandler(xen_store_evtchn,
1023 0, "xenstore_late_init",
1026 pr_err("xenstore_late_init couldn't bind irq err=%d\n",
1035 pr_warn("Xenstore state unknown\n");
1040 * HVM domains may not have a functional callback yet. In that
1041 * case let xs_init() be called from xenbus_probe(), which will
1042 * get invoked at an appropriate time.
1044 if (xen_store_domain_type != XS_HVM) {
1047 pr_warn("Error initializing xenstore comms: %i\n", err);
1052 if ((xen_store_domain_type != XS_LOCAL) &&
1053 (xen_store_domain_type != XS_UNKNOWN))
1054 xen_resume_notifier_register(&xenbus_resume_nb);
1056 #ifdef CONFIG_XEN_COMPAT_XENFS
1058 * Create xenfs mountpoint in /proc for compatibility with
1059 * utilities that expect to find "xenbus" under "/proc/xen".
1061 proc_create_mount_point("xen");
1066 xen_store_domain_type = XS_UNKNOWN;
1070 postcore_initcall(xenbus_init);
1072 MODULE_LICENSE("GPL");