#include <asm/vio.h>
#include <asm/hvcall.h>
#include <asm/iSeries/vio.h>
+#include <asm/iSeries/HvTypes.h>
#include <asm/iSeries/HvCallXm.h>
+#include <asm/iSeries/HvLpConfig.h>
#define DBGENTER() pr_debug("%s entered\n", __FUNCTION__)
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(
const struct vio_device_id *, const struct vio_dev *);
#ifdef CONFIG_PPC_PSERIES
+static struct iommu_table *vio_build_iommu_table(struct vio_dev *);
static int vio_num_address_cells;
#endif
static struct vio_dev *vio_bus_device; /* fake "parent" device */
#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 vio_iommu_table;
-static struct vio_dev _veth_dev = {
- .iommu_table = &veth_iommu_table,
- .dev.bus = &vio_bus_type
-};
static struct vio_dev _vio_dev = {
.iommu_table = &vio_iommu_table,
.dev.bus = &vio_bus_type
};
-
-struct vio_dev *iSeries_veth_dev = &_veth_dev;
struct device *iSeries_vio_dev = &_vio_dev.dev;
-
-EXPORT_SYMBOL(iSeries_veth_dev);
EXPORT_SYMBOL(iSeries_vio_dev);
+
+#define device_is_compatible(a, b) 1
+
#endif
/* convert from struct device to struct vio_dev and pass to driver.
{
DBGENTER();
-#ifdef CONFIG_PPC_PSERIES
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))
return ids;
ids++;
}
-#endif
return NULL;
}
struct iommu_table *t;
struct iommu_table_cb cb;
unsigned long cbp;
+ unsigned long itc_entries;
cb.itc_busno = 255; /* Bus 255 is the virtual bus */
cb.itc_virtbus = 0xff; /* Ask for virtual bus */
cbp = virt_to_abs(&cb);
HvCallXm_getTceTableParms(cbp);
- veth_iommu_table.it_size = cb.itc_size / 2;
+ itc_entries = cb.itc_size * PAGE_SIZE / sizeof(union tce_entry);
+ veth_iommu_table.it_size = itc_entries / 2;
veth_iommu_table.it_busno = cb.itc_busno;
veth_iommu_table.it_offset = cb.itc_offset;
veth_iommu_table.it_index = cb.itc_index;
veth_iommu_table.it_type = TCE_VB;
- veth_iommu_table.it_entrysize = sizeof(union tce_entry);
veth_iommu_table.it_blocksize = 1;
t = iommu_init_table(&veth_iommu_table);
if (!t)
printk("Virtual Bus VETH TCE table failed.\n");
- vio_iommu_table.it_size = cb.itc_size - veth_iommu_table.it_size;
+ vio_iommu_table.it_size = itc_entries - veth_iommu_table.it_size;
vio_iommu_table.it_busno = cb.itc_busno;
vio_iommu_table.it_offset = cb.itc_offset +
- veth_iommu_table.it_size * (PAGE_SIZE/sizeof(union tce_entry));
+ veth_iommu_table.it_size;
vio_iommu_table.it_index = cb.itc_index;
vio_iommu_table.it_type = TCE_VB;
- vio_iommu_table.it_entrysize = sizeof(union tce_entry);
vio_iommu_table.it_blocksize = 1;
t = iommu_init_table(&vio_iommu_table);
}
#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)
+{
+ HvLpIndexMap vlan_map = HvLpConfig_getVirtualLanIndexMap();
+ struct vio_dev *viodev;
+ int i;
+
+ /* there is only one of each of these */
+ vio_register_device_iseries("viocons", 0);
+ vio_register_device_iseries("vscsi", 0);
+
+ vlan_map = HvLpConfig_getVirtualLanIndexMap();
+ for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
+ if ((vlan_map & (0x8000 >> i)) == 0)
+ continue;
+ viodev = vio_register_device_iseries("vlan", i);
+ /* veth is special and has it own iommu_table */
+ viodev->iommu_table = &veth_iommu_table;
+ }
+ for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
+ vio_register_device_iseries("viodasd", i);
+ for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
+ vio_register_device_iseries("viocd", i);
+ for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
+ vio_register_device_iseries("viotape", i);
+}
+#endif
+
/**
* vio_bus_init: - Initialize the virtual IO bus
*/
static int __init vio_bus_init(void)
{
-#ifdef CONFIG_PPC_PSERIES
- struct device_node *node_vroot, *of_node;
-#endif
int err;
err = bus_register(&vio_bus_type);
}
#ifdef CONFIG_PPC_PSERIES
- 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 0;
- }
-
- 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);
- }
+ probe_bus_pseries();
+#endif
+#ifdef CONFIG_PPC_ISERIES
+ probe_bus_iseries();
#endif
return 0;
__initcall(vio_bus_init);
-
-#ifdef CONFIG_PPC_PSERIES
/* vio_dev refcount hit 0 */
static void __devinit vio_dev_release(struct device *dev)
{
- struct vio_dev *viodev = to_vio_dev(dev);
-
DBGENTER();
+#ifdef CONFIG_PPC_PSERIES
/* XXX free TCE table */
- of_node_put(viodev->dev.platform_data);
- kfree(viodev);
+ of_node_put(dev->platform_data);
+#endif
+ kfree(to_vio_dev(dev));
}
+#ifdef CONFIG_PPC_PSERIES
static ssize_t viodev_show_devspec(struct device *dev, char *buf)
{
struct device_node *of_node = dev->platform_data;
return sprintf(buf, "%s\n", of_node->full_name);
}
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)
{
- struct device_node *of_node = dev->platform_data;
-
- return sprintf(buf, "%s\n", of_node->name);
+ return sprintf(buf, "%s\n", to_vio_dev(dev)->name);
}
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.
*
* Creates and initializes a vio_dev structure from the data in
* Returns a pointer to the created vio_dev or NULL if node has
* 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;
unsigned int *unit_address;
memset(viodev, 0, sizeof(struct vio_dev));
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;
- irq_p = (unsigned int *)get_property(of_node, "interrupts", 0);
+ irq_p = (unsigned int *)get_property(of_node, "interrupts", NULL);
if (irq_p) {
int virq = virt_irq_create_mapping(*irq_p);
if (virq == NO_IRQ) {
viodev->irq = irq_offset_up(virq);
}
- /* init generic 'struct device' fields: */
- 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;
+ snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address);
/* 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);
+ if (vio_register_device_common(viodev, of_node->name, of_node->type,
+ *unit_address, vio_build_iommu_table(viodev))
+ == NULL) {
/* XXX free TCE table */
kfree(viodev);
return NULL;
}
- device_create_file(&viodev->dev, &dev_attr_name);
device_create_file(&viodev->dev, &dev_attr_devspec);
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)
{
DBGENTER();
+#ifdef CONFIG_PPC_PSERIES
device_remove_file(&viodev->dev, &dev_attr_devspec);
+#endif
device_remove_file(&viodev->dev, &dev_attr_name);
device_unregister(&viodev->dev);
}
EXPORT_SYMBOL(vio_unregister_device);
+#ifdef CONFIG_PPC_PSERIES
/**
* vio_get_attribute: - get attribute for virtual device
* @vdev: The vio device to get property.
unsigned int *dma_window;
struct iommu_table *newTceTable;
unsigned long offset;
- unsigned long size;
int dma_window_property_size;
dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size);
newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
- /* RPA docs say that #address-cells is always 1 for virtual
- devices, but some older boxes' OF returns 2. This should
- be removed by GA, unless there is legacy OFs that still
- have 2 for #address-cells */
- size = ((dma_window[1+vio_num_address_cells] >> PAGE_SHIFT) << 3)
- >> PAGE_SHIFT;
-
- /* This is just an ugly kludge. Remove as soon as the OF for all
- machines actually follow the spec and encodes the offset field
- as phys-encode (that is, #address-cells wide)*/
- if (dma_window_property_size == 12) {
- size = ((dma_window[1] >> PAGE_SHIFT) << 3) >> PAGE_SHIFT;
- } else if (dma_window_property_size == 20) {
- size = ((dma_window[4] >> PAGE_SHIFT) << 3) >> PAGE_SHIFT;
- } else {
- printk(KERN_WARNING "vio_build_iommu_table: Invalid size of ibm,my-dma-window=%i, using 0x80 for size\n", dma_window_property_size);
- size = 0x80;
- }
-
/* There should be some code to extract the phys-encoded offset
using prom_n_addr_cells(). However, according to a comment
on earlier versions, it's always zero, so we don't bother */
offset = dma_window[1] >> PAGE_SHIFT;
- /* TCE table size - measured in units of pages of tce table */
- newTceTable->it_size = size;
+ /* TCE table size - measured in tce entries */
+ newTceTable->it_size = dma_window[4] >> PAGE_SHIFT;
/* offset for VIO should always be 0 */
newTceTable->it_offset = offset;
newTceTable->it_busno = 0;
newTceTable->it_index = (unsigned long)dma_window[0];
newTceTable->it_type = TCE_VB;
- newTceTable->it_entrysize = sizeof(union tce_entry);
return iommu_init_table(newTceTable);
}