2 * IBM PowerPC iSeries Virtual I/O Infrastructure Support.
4 * Copyright (c) 2005 Stephen Rothwell, IBM Corp.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 #include <linux/types.h>
12 #include <linux/device.h>
13 #include <linux/init.h>
16 #include <asm/iommu.h>
18 #include <asm/abs_addr.h>
20 #include <asm/iseries/vio.h>
21 #include <asm/iseries/hv_types.h>
22 #include <asm/iseries/hv_lp_config.h>
23 #include <asm/iseries/hv_call_xm.h>
27 struct device *iSeries_vio_dev = &vio_bus_device.dev;
28 EXPORT_SYMBOL(iSeries_vio_dev);
30 static struct iommu_table veth_iommu_table;
31 static struct iommu_table vio_iommu_table;
33 static void __init iommu_vio_init(void)
35 iommu_table_getparms_iSeries(255, 0, 0xff, &veth_iommu_table);
36 veth_iommu_table.it_size /= 2;
37 vio_iommu_table = veth_iommu_table;
38 vio_iommu_table.it_offset += veth_iommu_table.it_size;
40 if (!iommu_init_table(&veth_iommu_table))
41 printk("Virtual Bus VETH TCE table failed.\n");
42 if (!iommu_init_table(&vio_iommu_table))
43 printk("Virtual Bus VIO TCE table failed.\n");
47 * vio_register_device_iseries: - Register a new iSeries vio device.
48 * @voidev: The device to register.
50 static struct vio_dev *__init vio_register_device_iseries(char *type,
53 struct vio_dev *viodev;
55 /* allocate a vio_dev for this device */
56 viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);
59 memset(viodev, 0, sizeof(struct vio_dev));
61 snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num);
63 viodev->name = viodev->dev.bus_id;
65 viodev->unit_address = unit_num;
66 viodev->iommu_table = &vio_iommu_table;
67 if (vio_register_device(viodev) == NULL) {
74 void __init probe_bus_iseries(void)
76 HvLpIndexMap vlan_map;
77 struct vio_dev *viodev;
80 /* there is only one of each of these */
81 vio_register_device_iseries("viocons", 0);
82 vio_register_device_iseries("vscsi", 0);
84 vlan_map = HvLpConfig_getVirtualLanIndexMap();
85 for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
86 if ((vlan_map & (0x8000 >> i)) == 0)
88 viodev = vio_register_device_iseries("vlan", i);
89 /* veth is special and has it own iommu_table */
90 viodev->iommu_table = &veth_iommu_table;
92 for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)
93 vio_register_device_iseries("viodasd", i);
94 for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)
95 vio_register_device_iseries("viocd", i);
96 for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)
97 vio_register_device_iseries("viotape", i);
101 * vio_match_device_iseries: - Tell if a iSeries VIO device matches a
104 static int vio_match_device_iseries(const struct vio_device_id *id,
105 const struct vio_dev *dev)
107 return strncmp(dev->type, id->type, strlen(id->type)) == 0;
110 static struct vio_bus_ops vio_bus_ops_iseries = {
111 .match = vio_match_device_iseries,
115 * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus
117 static int __init vio_bus_init_iseries(void)
121 err = vio_bus_init(&vio_bus_ops_iseries);
124 vio_bus_device.iommu_table = &vio_iommu_table;
125 iSeries_vio_dev = &vio_bus_device.dev;
131 __initcall(vio_bus_init_iseries);