Commit 4575edd5 authored by Stephen Rothwell's avatar Stephen Rothwell Committed by Linus Torvalds

[PATCH] ppc64: vio infrastructure modifications

The intention here is to have no effect on pSeries except:

1) vio_register_device is renamed to vio_register_device_node to better
   reflect is purpose and to allow me to introduce
   vio_register_device_iseries.

2) I have introduced the name and type fields in struct vio_dev to make
   these two fields independent of subarchitecture.
Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f62ae120
...@@ -32,16 +32,19 @@ ...@@ -32,16 +32,19 @@
extern struct subsystem devices_subsys; /* needed for vio_find_name() */ extern struct subsystem devices_subsys; /* needed for vio_find_name() */
static struct iommu_table *vio_build_iommu_table(struct vio_dev *);
static const struct vio_device_id *vio_match_device( static const struct vio_device_id *vio_match_device(
const struct vio_device_id *, const struct vio_dev *); const struct vio_device_id *, const struct vio_dev *);
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
static struct iommu_table *vio_build_iommu_table(struct vio_dev *);
static int vio_num_address_cells; static int vio_num_address_cells;
#endif #endif
static struct vio_dev *vio_bus_device; /* fake "parent" device */ static struct vio_dev *vio_bus_device; /* fake "parent" device */
#ifdef CONFIG_PPC_ISERIES #ifdef CONFIG_PPC_ISERIES
static struct vio_dev *__init vio_register_device_iseries(char *type,
uint32_t unit_num);
static struct iommu_table veth_iommu_table; static struct iommu_table veth_iommu_table;
static struct iommu_table vio_iommu_table; static struct iommu_table vio_iommu_table;
...@@ -59,6 +62,9 @@ struct device *iSeries_vio_dev = &_vio_dev.dev; ...@@ -59,6 +62,9 @@ struct device *iSeries_vio_dev = &_vio_dev.dev;
EXPORT_SYMBOL(iSeries_veth_dev); EXPORT_SYMBOL(iSeries_veth_dev);
EXPORT_SYMBOL(iSeries_vio_dev); EXPORT_SYMBOL(iSeries_vio_dev);
#define device_is_compatible(a, b) 1
#endif #endif
/* convert from struct device to struct vio_dev and pass to driver. /* convert from struct device to struct vio_dev and pass to driver.
...@@ -143,14 +149,12 @@ static const struct vio_device_id * vio_match_device(const struct vio_device_id ...@@ -143,14 +149,12 @@ static const struct vio_device_id * vio_match_device(const struct vio_device_id
{ {
DBGENTER(); DBGENTER();
#ifdef CONFIG_PPC_PSERIES
while (ids->type) { while (ids->type) {
if ((strncmp(((struct device_node *)dev->dev.platform_data)->type, ids->type, strlen(ids->type)) == 0) && if ((strncmp(dev->type, ids->type, strlen(ids->type)) == 0) &&
device_is_compatible(dev->dev.platform_data, ids->compat)) device_is_compatible(dev->dev.platform_data, ids->compat))
return ids; return ids;
ids++; ids++;
} }
#endif
return NULL; return NULL;
} }
...@@ -196,14 +200,41 @@ void __init iommu_vio_init(void) ...@@ -196,14 +200,41 @@ void __init iommu_vio_init(void)
} }
#endif #endif
#ifdef CONFIG_PPC_PSERIES
static void probe_bus_pseries(void)
{
struct device_node *node_vroot, *of_node;
node_vroot = find_devices("vdevice");
if ((node_vroot == NULL) || (node_vroot->child == NULL))
/* this machine doesn't do virtual IO, and that's ok */
return;
vio_num_address_cells = prom_n_addr_cells(node_vroot->child);
/*
* Create struct vio_devices for each virtual device in 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);
vio_register_device_node(of_node);
}
}
#endif
#ifdef CONFIG_PPC_ISERIES
static void probe_bus_iseries(void)
{
}
#endif
/** /**
* vio_bus_init: - Initialize the virtual IO bus * vio_bus_init: - Initialize the virtual IO bus
*/ */
static int __init vio_bus_init(void) static int __init vio_bus_init(void)
{ {
#ifdef CONFIG_PPC_PSERIES
struct device_node *node_vroot, *of_node;
#endif
int err; int err;
err = bus_register(&vio_bus_type); err = bus_register(&vio_bus_type);
...@@ -229,25 +260,10 @@ static int __init vio_bus_init(void) ...@@ -229,25 +260,10 @@ static int __init vio_bus_init(void)
} }
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
node_vroot = find_devices("vdevice"); probe_bus_pseries();
if ((node_vroot == NULL) || (node_vroot->child == NULL)) { #endif
/* this machine doesn't do virtual IO, and that's ok */ #ifdef CONFIG_PPC_ISERIES
return 0; probe_bus_iseries();
}
vio_num_address_cells = prom_n_addr_cells(node_vroot->child);
/*
* Create struct vio_devices for each virtual device in 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);
vio_register_device(of_node);
}
#endif #endif
return 0; return 0;
...@@ -255,20 +271,19 @@ static int __init vio_bus_init(void) ...@@ -255,20 +271,19 @@ static int __init vio_bus_init(void)
__initcall(vio_bus_init); __initcall(vio_bus_init);
#ifdef CONFIG_PPC_PSERIES
/* vio_dev refcount hit 0 */ /* vio_dev refcount hit 0 */
static void __devinit vio_dev_release(struct device *dev) static void __devinit vio_dev_release(struct device *dev)
{ {
struct vio_dev *viodev = to_vio_dev(dev);
DBGENTER(); DBGENTER();
#ifdef CONFIG_PPC_PSERIES
/* XXX free TCE table */ /* XXX free TCE table */
of_node_put(viodev->dev.platform_data); of_node_put(dev->platform_data);
kfree(viodev); #endif
kfree(to_vio_dev(dev));
} }
#ifdef CONFIG_PPC_PSERIES
static ssize_t viodev_show_devspec(struct device *dev, char *buf) static ssize_t viodev_show_devspec(struct device *dev, char *buf)
{ {
struct device_node *of_node = dev->platform_data; struct device_node *of_node = dev->platform_data;
...@@ -276,17 +291,43 @@ static ssize_t viodev_show_devspec(struct device *dev, char *buf) ...@@ -276,17 +291,43 @@ static ssize_t viodev_show_devspec(struct device *dev, char *buf)
return sprintf(buf, "%s\n", of_node->full_name); return sprintf(buf, "%s\n", of_node->full_name);
} }
DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL); DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL);
#endif
static ssize_t viodev_show_name(struct device *dev, char *buf) static ssize_t viodev_show_name(struct device *dev, char *buf)
{ {
struct device_node *of_node = dev->platform_data; return sprintf(buf, "%s\n", to_vio_dev(dev)->name);
return sprintf(buf, "%s\n", of_node->name);
} }
DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL); DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL);
static struct vio_dev * __devinit vio_register_device_common(
struct vio_dev *viodev, char *name, char *type,
uint32_t unit_address, struct iommu_table *iommu_table)
{
DBGENTER();
viodev->name = name;
viodev->type = type;
viodev->unit_address = unit_address;
viodev->iommu_table = iommu_table;
/* init generic 'struct device' fields: */
viodev->dev.parent = &vio_bus_device->dev;
viodev->dev.bus = &vio_bus_type;
viodev->dev.release = vio_dev_release;
/* register with generic device framework */
if (device_register(&viodev->dev)) {
printk(KERN_ERR "%s: failed to register device %s\n",
__FUNCTION__, viodev->dev.bus_id);
return NULL;
}
device_create_file(&viodev->dev, &dev_attr_name);
return viodev;
}
#ifdef CONFIG_PPC_PSERIES
/** /**
* vio_register_device: - Register a new vio device. * vio_register_device_node: - Register a new vio device.
* @of_node: The OF node for this device. * @of_node: The OF node for this device.
* *
* Creates and initializes a vio_dev structure from the data in * Creates and initializes a vio_dev structure from the data in
...@@ -294,7 +335,7 @@ DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL); ...@@ -294,7 +335,7 @@ DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL);
* Returns a pointer to the created vio_dev or NULL if node has * Returns a pointer to the created vio_dev or NULL if node has
* NULL device_type or compatible fields. * NULL device_type or compatible fields.
*/ */
struct vio_dev * __devinit vio_register_device(struct device_node *of_node) struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node)
{ {
struct vio_dev *viodev; struct vio_dev *viodev;
unsigned int *unit_address; unsigned int *unit_address;
...@@ -325,8 +366,6 @@ struct vio_dev * __devinit vio_register_device(struct device_node *of_node) ...@@ -325,8 +366,6 @@ struct vio_dev * __devinit vio_register_device(struct device_node *of_node)
memset(viodev, 0, sizeof(struct vio_dev)); memset(viodev, 0, sizeof(struct vio_dev));
viodev->dev.platform_data = of_node_get(of_node); viodev->dev.platform_data = of_node_get(of_node);
viodev->unit_address = *unit_address;
viodev->iommu_table = vio_build_iommu_table(viodev);
viodev->irq = NO_IRQ; viodev->irq = NO_IRQ;
irq_p = (unsigned int *)get_property(of_node, "interrupts", 0); irq_p = (unsigned int *)get_property(of_node, "interrupts", 0);
...@@ -339,36 +378,60 @@ struct vio_dev * __devinit vio_register_device(struct device_node *of_node) ...@@ -339,36 +378,60 @@ struct vio_dev * __devinit vio_register_device(struct device_node *of_node)
viodev->irq = irq_offset_up(virq); viodev->irq = irq_offset_up(virq);
} }
/* init generic 'struct device' fields: */ snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address);
viodev->dev.parent = &vio_bus_device->dev;
viodev->dev.bus = &vio_bus_type;
snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", viodev->unit_address);
viodev->dev.release = vio_dev_release;
/* register with generic device framework */ /* register with generic device framework */
if (device_register(&viodev->dev)) { if (vio_register_device_common(viodev, of_node->name, of_node->type,
printk(KERN_ERR "%s: failed to register device %s\n", __FUNCTION__, *unit_address, vio_build_iommu_table(viodev))
viodev->dev.bus_id); == NULL) {
/* XXX free TCE table */ /* XXX free TCE table */
kfree(viodev); kfree(viodev);
return NULL; return NULL;
} }
device_create_file(&viodev->dev, &dev_attr_name);
device_create_file(&viodev->dev, &dev_attr_devspec); device_create_file(&viodev->dev, &dev_attr_devspec);
return viodev; return viodev;
} }
EXPORT_SYMBOL(vio_register_device); EXPORT_SYMBOL(vio_register_device_node);
#endif
#ifdef CONFIG_PPC_ISERIES
/**
* vio_register_device: - Register a new vio device.
* @voidev: The device to register.
*/
static struct vio_dev *__init vio_register_device_iseries(char *type,
uint32_t unit_num)
{
struct vio_dev *viodev;
DBGENTER();
/* allocate a vio_dev for this node */
viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);
if (!viodev)
return NULL;
memset(viodev, 0, sizeof(struct vio_dev));
snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num);
return vio_register_device_common(viodev, viodev->dev.bus_id, type,
unit_num, &vio_iommu_table);
}
#endif
void __devinit vio_unregister_device(struct vio_dev *viodev) void __devinit vio_unregister_device(struct vio_dev *viodev)
{ {
DBGENTER(); DBGENTER();
#ifdef CONFIG_PPC_PSERIES
device_remove_file(&viodev->dev, &dev_attr_devspec); device_remove_file(&viodev->dev, &dev_attr_devspec);
#endif
device_remove_file(&viodev->dev, &dev_attr_name); device_remove_file(&viodev->dev, &dev_attr_name);
device_unregister(&viodev->dev); device_unregister(&viodev->dev);
} }
EXPORT_SYMBOL(vio_unregister_device); EXPORT_SYMBOL(vio_unregister_device);
#ifdef CONFIG_PPC_PSERIES
/** /**
* vio_get_attribute: - get attribute for virtual device * vio_get_attribute: - get attribute for virtual device
* @vdev: The vio device to get property. * @vdev: The vio device to get property.
......
...@@ -87,7 +87,7 @@ int register_vio_slot(struct device_node *dn) ...@@ -87,7 +87,7 @@ int register_vio_slot(struct device_node *dn)
slot->dev_type = VIO_DEV; slot->dev_type = VIO_DEV;
slot->dev.vio_dev = vio_find_node(dn); slot->dev.vio_dev = vio_find_node(dn);
if (!slot->dev.vio_dev) if (!slot->dev.vio_dev)
slot->dev.vio_dev = vio_register_device(dn); slot->dev.vio_dev = vio_register_device_node(dn);
if (slot->dev.vio_dev) if (slot->dev.vio_dev)
slot->state = CONFIGURED; slot->state = CONFIGURED;
else else
...@@ -108,7 +108,7 @@ int rpaphp_enable_vio_slot(struct slot *slot) ...@@ -108,7 +108,7 @@ int rpaphp_enable_vio_slot(struct slot *slot)
{ {
int retval = 0; int retval = 0;
if ((slot->dev.vio_dev = vio_register_device(slot->dn))) { if ((slot->dev.vio_dev = vio_register_device_node(slot->dn))) {
info("%s: VIO adapter %s in slot[%s] has been configured\n", info("%s: VIO adapter %s in slot[%s] has been configured\n",
__FUNCTION__, slot->dn->name, slot->name); __FUNCTION__, slot->dn->name, slot->name);
slot->state = CONFIGURED; slot->state = CONFIGURED;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#ifndef _ASM_VIO_H #ifndef _ASM_VIO_H
#define _ASM_VIO_H #define _ASM_VIO_H
#include <linux/config.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -44,7 +45,10 @@ struct iommu_table; ...@@ -44,7 +45,10 @@ struct iommu_table;
int vio_register_driver(struct vio_driver *drv); int vio_register_driver(struct vio_driver *drv);
void vio_unregister_driver(struct vio_driver *drv); void vio_unregister_driver(struct vio_driver *drv);
struct vio_dev * __devinit vio_register_device(struct device_node *node_vdev); #ifdef CONFIG_PPC_PSERIES
struct vio_dev * __devinit vio_register_device_node(
struct device_node *node_vdev);
#endif
void __devinit vio_unregister_device(struct vio_dev *dev); void __devinit vio_unregister_device(struct vio_dev *dev);
struct vio_dev *vio_find_node(struct device_node *vnode); struct vio_dev *vio_find_node(struct device_node *vnode);
...@@ -108,6 +112,8 @@ static inline struct vio_driver *to_vio_driver(struct device_driver *drv) ...@@ -108,6 +112,8 @@ static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
*/ */
struct vio_dev { struct vio_dev {
struct iommu_table *iommu_table; /* vio_map_* uses this */ struct iommu_table *iommu_table; /* vio_map_* uses this */
char *name;
char *type;
uint32_t unit_address; uint32_t unit_address;
unsigned int irq; unsigned int irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment