Merge branches 'stable/drivers-3.2', 'stable/drivers.bugfixes-3.2' and 'stable/pci...
[firefly-linux-kernel-4.4.55.git] / drivers / xen / xenbus / xenbus_probe.c
index 739769551e33b98e983b2a76369051b9e2915557..cef9b0bf63d527f8a10b3cdc5d5016f281b80e59 100644 (file)
@@ -378,26 +378,32 @@ static void xenbus_dev_release(struct device *dev)
                kfree(to_xenbus_device(dev));
 }
 
-static ssize_t xendev_show_nodename(struct device *dev,
-                                   struct device_attribute *attr, char *buf)
+static ssize_t nodename_show(struct device *dev,
+                            struct device_attribute *attr, char *buf)
 {
        return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename);
 }
-static DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL);
 
-static ssize_t xendev_show_devtype(struct device *dev,
-                                  struct device_attribute *attr, char *buf)
+static ssize_t devtype_show(struct device *dev,
+                           struct device_attribute *attr, char *buf)
 {
        return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype);
 }
-static DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL);
 
-static ssize_t xendev_show_modalias(struct device *dev,
-                                   struct device_attribute *attr, char *buf)
+static ssize_t modalias_show(struct device *dev,
+                            struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf, "xen:%s\n", to_xenbus_device(dev)->devicetype);
+       return sprintf(buf, "%s:%s\n", dev->bus->name,
+                      to_xenbus_device(dev)->devicetype);
 }
-static DEVICE_ATTR(modalias, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_modalias, NULL);
+
+struct device_attribute xenbus_dev_attrs[] = {
+       __ATTR_RO(nodename),
+       __ATTR_RO(devtype),
+       __ATTR_RO(modalias),
+       __ATTR_NULL
+};
+EXPORT_SYMBOL_GPL(xenbus_dev_attrs);
 
 int xenbus_probe_node(struct xen_bus_type *bus,
                      const char *type,
@@ -449,25 +455,7 @@ int xenbus_probe_node(struct xen_bus_type *bus,
        if (err)
                goto fail;
 
-       err = device_create_file(&xendev->dev, &dev_attr_nodename);
-       if (err)
-               goto fail_unregister;
-
-       err = device_create_file(&xendev->dev, &dev_attr_devtype);
-       if (err)
-               goto fail_remove_nodename;
-
-       err = device_create_file(&xendev->dev, &dev_attr_modalias);
-       if (err)
-               goto fail_remove_devtype;
-
        return 0;
-fail_remove_devtype:
-       device_remove_file(&xendev->dev, &dev_attr_devtype);
-fail_remove_nodename:
-       device_remove_file(&xendev->dev, &dev_attr_nodename);
-fail_unregister:
-       device_unregister(&xendev->dev);
 fail:
        kfree(xendev);
        return err;
@@ -696,64 +684,74 @@ static int __init xenbus_probe_initcall(void)
 
 device_initcall(xenbus_probe_initcall);
 
-static int __init xenbus_init(void)
+/* Set up event channel for xenstored which is run as a local process
+ * (this is normally used only in dom0)
+ */
+static int __init xenstored_local_init(void)
 {
        int err = 0;
        unsigned long page = 0;
+       struct evtchn_alloc_unbound alloc_unbound;
 
-       DPRINTK("");
+       /* Allocate Xenstore page */
+       page = get_zeroed_page(GFP_KERNEL);
+       if (!page)
+               goto out_err;
 
-       err = -ENODEV;
-       if (!xen_domain())
-               return err;
+       xen_store_mfn = xen_start_info->store_mfn =
+               pfn_to_mfn(virt_to_phys((void *)page) >>
+                          PAGE_SHIFT);
 
-       /*
-        * Domain0 doesn't have a store_evtchn or store_mfn yet.
-        */
-       if (xen_initial_domain()) {
-               struct evtchn_alloc_unbound alloc_unbound;
+       /* Next allocate a local port which xenstored can bind to */
+       alloc_unbound.dom        = DOMID_SELF;
+       alloc_unbound.remote_dom = DOMID_SELF;
 
-               /* Allocate Xenstore page */
-               page = get_zeroed_page(GFP_KERNEL);
-               if (!page)
-                       goto out_error;
+       err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
+                                         &alloc_unbound);
+       if (err == -ENOSYS)
+               goto out_err;
 
-               xen_store_mfn = xen_start_info->store_mfn =
-                       pfn_to_mfn(virt_to_phys((void *)page) >>
-                                  PAGE_SHIFT);
+       BUG_ON(err);
+       xen_store_evtchn = xen_start_info->store_evtchn =
+               alloc_unbound.port;
 
-               /* Next allocate a local port which xenstored can bind to */
-               alloc_unbound.dom        = DOMID_SELF;
-               alloc_unbound.remote_dom = 0;
+       return 0;
 
-               err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound,
-                                                 &alloc_unbound);
-               if (err == -ENOSYS)
-                       goto out_error;
+ out_err:
+       if (page != 0)
+               free_page(page);
+       return err;
+}
 
-               BUG_ON(err);
-               xen_store_evtchn = xen_start_info->store_evtchn =
-                       alloc_unbound.port;
+static int __init xenbus_init(void)
+{
+       int err = 0;
 
-               xen_store_interface = mfn_to_virt(xen_store_mfn);
+       if (!xen_domain())
+               return -ENODEV;
+
+       if (xen_hvm_domain()) {
+               uint64_t v = 0;
+               err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
+               if (err)
+                       goto out_error;
+               xen_store_evtchn = (int)v;
+               err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
+               if (err)
+                       goto out_error;
+               xen_store_mfn = (unsigned long)v;
+               xen_store_interface = ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE);
        } else {
-               if (xen_hvm_domain()) {
-                       uint64_t v = 0;
-                       err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
-                       if (err)
-                               goto out_error;
-                       xen_store_evtchn = (int)v;
-                       err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
+               xen_store_evtchn = xen_start_info->store_evtchn;
+               xen_store_mfn = xen_start_info->store_mfn;
+               if (xen_store_evtchn)
+                       xenstored_ready = 1;
+               else {
+                       err = xenstored_local_init();
                        if (err)
                                goto out_error;
-                       xen_store_mfn = (unsigned long)v;
-                       xen_store_interface = ioremap(xen_store_mfn << PAGE_SHIFT, PAGE_SIZE);
-               } else {
-                       xen_store_evtchn = xen_start_info->store_evtchn;
-                       xen_store_mfn = xen_start_info->store_mfn;
-                       xen_store_interface = mfn_to_virt(xen_store_mfn);
-                       xenstored_ready = 1;
                }
+               xen_store_interface = mfn_to_virt(xen_store_mfn);
        }
 
        /* Initialize the interface to xenstore. */
@@ -772,12 +770,7 @@ static int __init xenbus_init(void)
        proc_mkdir("xen", NULL);
 #endif
 
-       return 0;
-
-  out_error:
-       if (page != 0)
-               free_page(page);
-
+ out_error:
        return err;
 }