Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[sfrench/cifs-2.6.git] / arch / powerpc / kernel / vio.c
index 2968ffeafdb68c06f6d1d7ff96dfa8e4bab4578d..19a5656001c080f8da3f3f5a9050c03a80fb1746 100644 (file)
@@ -37,7 +37,9 @@
 #include <asm/iseries/hv_call_xm.h>
 #include <asm/iseries/iommu.h>
 
-extern struct subsystem devices_subsys; /* needed for vio_find_name() */
+extern struct kset devices_subsys; /* needed for vio_find_name() */
+
+static struct bus_type vio_bus_type;
 
 static struct vio_dev vio_bus_device  = { /* fake "parent" device */
        .name = vio_bus_device.dev.bus_id,
@@ -46,60 +48,33 @@ static struct vio_dev vio_bus_device  = { /* fake "parent" device */
        .dev.bus = &vio_bus_type,
 };
 
-#ifdef CONFIG_PPC_ISERIES
-struct device *iSeries_vio_dev = &vio_bus_device.dev;
-EXPORT_SYMBOL(iSeries_vio_dev);
+static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
+{
+       const unsigned char *dma_window;
+       struct iommu_table *tbl;
+       unsigned long offset, size;
 
-static struct iommu_table veth_iommu_table;
-static struct iommu_table vio_iommu_table;
+       if (firmware_has_feature(FW_FEATURE_ISERIES))
+               return vio_build_iommu_table_iseries(dev);
 
-static void __init iommu_vio_init(void)
-{
-       iommu_table_getparms_iSeries(255, 0, 0xff, &veth_iommu_table);
-       veth_iommu_table.it_size /= 2;
-       vio_iommu_table = veth_iommu_table;
-       vio_iommu_table.it_offset += veth_iommu_table.it_size;
-
-       if (!iommu_init_table(&veth_iommu_table, -1))
-               printk("Virtual Bus VETH TCE table failed.\n");
-       if (!iommu_init_table(&vio_iommu_table, -1))
-               printk("Virtual Bus VIO TCE table failed.\n");
-}
-#endif
+       dma_window = of_get_property(dev->dev.archdata.of_node,
+                                 "ibm,my-dma-window", NULL);
+       if (!dma_window)
+               return NULL;
 
-static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
-{
-#ifdef CONFIG_PPC_ISERIES
-       if (firmware_has_feature(FW_FEATURE_ISERIES)) {
-               if (strcmp(dev->type, "network") == 0)
-                       return &veth_iommu_table;
-               return &vio_iommu_table;
-       } else
-#endif
-       {
-               const unsigned char *dma_window;
-               struct iommu_table *tbl;
-               unsigned long offset, size;
-
-               dma_window = get_property(dev->dev.archdata.of_node,
-                                         "ibm,my-dma-window", NULL);
-               if (!dma_window)
-                       return NULL;
-
-               tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
-
-               of_parse_dma_window(dev->dev.archdata.of_node, dma_window,
-                                   &tbl->it_index, &offset, &size);
-
-               /* TCE table size - measured in tce entries */
-               tbl->it_size = size >> IOMMU_PAGE_SHIFT;
-               /* offset for VIO should always be 0 */
-               tbl->it_offset = offset >> IOMMU_PAGE_SHIFT;
-               tbl->it_busno = 0;
-               tbl->it_type = TCE_VB;
-
-               return iommu_init_table(tbl, -1);
-       }
+       tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
+
+       of_parse_dma_window(dev->dev.archdata.of_node, dma_window,
+                           &tbl->it_index, &offset, &size);
+
+       /* TCE table size - measured in tce entries */
+       tbl->it_size = size >> IOMMU_PAGE_SHIFT;
+       /* offset for VIO should always be 0 */
+       tbl->it_offset = offset >> IOMMU_PAGE_SHIFT;
+       tbl->it_busno = 0;
+       tbl->it_type = TCE_VB;
+
+       return iommu_init_table(tbl, -1);
 }
 
 /**
@@ -117,7 +92,7 @@ static const struct vio_device_id *vio_match_device(
 {
        while (ids->type[0] != '\0') {
                if ((strncmp(dev->type, ids->type, strlen(ids->type)) == 0) &&
-                   device_is_compatible(dev->dev.archdata.of_node,
+                   of_device_is_compatible(dev->dev.archdata.of_node,
                                         ids->compat))
                        return ids;
                ids++;
@@ -160,16 +135,6 @@ static int vio_bus_remove(struct device *dev)
        return 1;
 }
 
-/* convert from struct device to struct vio_dev and pass to driver. */
-static void vio_bus_shutdown(struct device *dev)
-{
-       struct vio_dev *viodev = to_vio_dev(dev);
-       struct vio_driver *viodrv = to_vio_driver(dev->driver);
-
-       if (dev->driver && viodrv->shutdown)
-               viodrv->shutdown(viodev);
-}
-
 /**
  * vio_register_driver: - Register a new vio driver
  * @drv:       The vio_driver structure to be registered.
@@ -226,7 +191,7 @@ struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node)
                return NULL;
        }
 
-       unit_address = get_property(of_node, "reg", NULL);
+       unit_address = of_get_property(of_node, "reg", NULL);
        if (unit_address == NULL) {
                printk(KERN_WARNING "%s: node %s missing 'reg'\n",
                                __FUNCTION__,
@@ -246,7 +211,7 @@ struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node)
        viodev->type = of_node->type;
        viodev->unit_address = *unit_address;
        if (firmware_has_feature(FW_FEATURE_ISERIES)) {
-               unit_address = get_property(of_node,
+               unit_address = of_get_property(of_node,
                                "linux,unit_address", NULL);
                if (unit_address != NULL)
                        viodev->unit_address = *unit_address;
@@ -282,15 +247,6 @@ static int __init vio_bus_init(void)
        int err;
        struct device_node *node_vroot;
 
-#ifdef CONFIG_PPC_ISERIES
-       if (firmware_has_feature(FW_FEATURE_ISERIES)) {
-               iommu_vio_init();
-               vio_bus_device.dev.archdata.dma_ops = &dma_iommu_ops;
-               vio_bus_device.dev.archdata.dma_data = &vio_iommu_table;
-               iSeries_vio_dev = &vio_bus_device.dev;
-       }
-#endif /* CONFIG_PPC_ISERIES */
-
        err = bus_register(&vio_bus_type);
        if (err) {
                printk(KERN_ERR "failed to register VIO bus\n");
@@ -308,7 +264,7 @@ static int __init vio_bus_init(void)
                return err;
        }
 
-       node_vroot = find_devices("vdevice");
+       node_vroot = of_find_node_by_name(NULL, "vdevice");
        if (node_vroot) {
                struct device_node *of_node;
 
@@ -317,11 +273,9 @@ static int __init vio_bus_init(void)
                 * the device tree. Drivers will associate with them later.
                 */
                for (of_node = node_vroot->child; of_node != NULL;
-                               of_node = of_node->sibling) {
-                       printk(KERN_DEBUG "%s: processing %p\n",
-                                       __FUNCTION__, of_node);
+                               of_node = of_node->sibling)
                        vio_register_device_node(of_node);
-               }
+               of_node_put(node_vroot);
        }
 
        return 0;
@@ -363,41 +317,30 @@ static int vio_bus_match(struct device *dev, struct device_driver *drv)
        return (ids != NULL) && (vio_match_device(ids, vio_dev) != NULL);
 }
 
-static int vio_hotplug(struct device *dev, char **envp, int num_envp,
-                       char *buffer, int buffer_size)
+static int vio_hotplug(struct device *dev, struct kobj_uevent_env *env)
 {
        const struct vio_dev *vio_dev = to_vio_dev(dev);
        struct device_node *dn;
        const char *cp;
-       int length;
-
-       if (!num_envp)
-               return -ENOMEM;
 
        dn = dev->archdata.of_node;
        if (!dn)
                return -ENODEV;
-       cp = get_property(dn, "compatible", &length);
+       cp = of_get_property(dn, "compatible", NULL);
        if (!cp)
                return -ENODEV;
 
-       envp[0] = buffer;
-       length = scnprintf(buffer, buffer_size, "MODALIAS=vio:T%sS%s",
-                               vio_dev->type, cp);
-       if ((buffer_size - length) <= 0)
-               return -ENOMEM;
-       envp[1] = NULL;
+       add_uevent_var(env, "MODALIAS=vio:T%sS%s", vio_dev->type, cp);
        return 0;
 }
 
-struct bus_type vio_bus_type = {
+static struct bus_type vio_bus_type = {
        .name = "vio",
        .dev_attrs = vio_dev_attrs,
        .uevent = vio_hotplug,
        .match = vio_bus_match,
        .probe = vio_bus_probe,
        .remove = vio_bus_remove,
-       .shutdown = vio_bus_shutdown,
 };
 
 /**
@@ -406,12 +349,12 @@ struct bus_type vio_bus_type = {
  * @which:     The property/attribute to be extracted.
  * @length:    Pointer to length of returned data size (unused if NULL).
  *
- * Calls prom.c's get_property() to return the value of the
+ * Calls prom.c's of_get_property() to return the value of the
  * attribute specified by @which
 */
 const void *vio_get_attribute(struct vio_dev *vdev, char *which, int *length)
 {
-       return get_property(vdev->dev.archdata.of_node, which, length);
+       return of_get_property(vdev->dev.archdata.of_node, which, length);
 }
 EXPORT_SYMBOL(vio_get_attribute);
 
@@ -426,7 +369,7 @@ static struct vio_dev *vio_find_name(const char *kobj_name)
 {
        struct kobject *found;
 
-       found = kset_find_obj(&devices_subsys.kset, kobj_name);
+       found = kset_find_obj(&devices_subsys, kobj_name);
        if (!found)
                return NULL;
 
@@ -443,7 +386,7 @@ struct vio_dev *vio_find_node(struct device_node *vnode)
        char kobj_name[BUS_ID_SIZE];
 
        /* construct the kobject name from the device node */
-       unit_address = get_property(vnode, "reg", NULL);
+       unit_address = of_get_property(vnode, "reg", NULL);
        if (!unit_address)
                return NULL;
        snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address);