Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 1 | /* |
| 2 | * IBM PowerPC iSeries Virtual I/O Infrastructure Support. |
| 3 | * |
| 4 | * Copyright (c) 2005 Stephen Rothwell, IBM Corp. |
| 5 | * |
| 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. |
| 10 | */ |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/init.h> |
| 14 | |
| 15 | #include <asm/vio.h> |
| 16 | #include <asm/iommu.h> |
Olof Johansson | c707ffc | 2005-09-20 13:45:41 +1000 | [diff] [blame] | 17 | #include <asm/tce.h> |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 18 | #include <asm/abs_addr.h> |
| 19 | #include <asm/page.h> |
Kelly Daly | b420677 | 2005-11-02 15:13:57 +1100 | [diff] [blame] | 20 | #include <asm/iseries/vio.h> |
Kelly Daly | 1ec65d7 | 2005-11-02 13:46:07 +1100 | [diff] [blame] | 21 | #include <asm/iseries/hv_types.h> |
Kelly Daly | 15b1718 | 2005-11-02 11:55:28 +1100 | [diff] [blame] | 22 | #include <asm/iseries/hv_lp_config.h> |
Kelly Daly | 8021b8a | 2005-11-02 11:41:12 +1100 | [diff] [blame] | 23 | #include <asm/iseries/hv_call_xm.h> |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 24 | |
| 25 | struct device *iSeries_vio_dev = &vio_bus_device.dev; |
| 26 | EXPORT_SYMBOL(iSeries_vio_dev); |
| 27 | |
| 28 | static struct iommu_table veth_iommu_table; |
| 29 | static struct iommu_table vio_iommu_table; |
| 30 | |
Stephen Rothwell | 8c65b5c | 2005-07-12 17:42:49 +1000 | [diff] [blame] | 31 | static void __init iommu_vio_init(void) |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 32 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame^] | 33 | iommu_table_getparms_iSeries(255, 0, 0xff, &veth_iommu_table); |
| 34 | veth_iommu_table.it_size /= 2; |
| 35 | vio_iommu_table = veth_iommu_table; |
| 36 | vio_iommu_table.it_offset += veth_iommu_table.it_size; |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 37 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame^] | 38 | if (!iommu_init_table(&veth_iommu_table)) |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 39 | printk("Virtual Bus VETH TCE table failed.\n"); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame^] | 40 | if (!iommu_init_table(&vio_iommu_table)) |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 41 | printk("Virtual Bus VIO TCE table failed.\n"); |
| 42 | } |
| 43 | |
| 44 | /** |
Stephen Rothwell | b877b90 | 2005-08-17 16:40:12 +1000 | [diff] [blame] | 45 | * vio_register_device_iseries: - Register a new iSeries vio device. |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 46 | * @voidev: The device to register. |
| 47 | */ |
| 48 | static struct vio_dev *__init vio_register_device_iseries(char *type, |
| 49 | uint32_t unit_num) |
| 50 | { |
| 51 | struct vio_dev *viodev; |
| 52 | |
Stephen Rothwell | b877b90 | 2005-08-17 16:40:12 +1000 | [diff] [blame] | 53 | /* allocate a vio_dev for this device */ |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 54 | viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL); |
| 55 | if (!viodev) |
| 56 | return NULL; |
| 57 | memset(viodev, 0, sizeof(struct vio_dev)); |
| 58 | |
| 59 | snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num); |
| 60 | |
Stephen Rothwell | b877b90 | 2005-08-17 16:40:12 +1000 | [diff] [blame] | 61 | viodev->name = viodev->dev.bus_id; |
| 62 | viodev->type = type; |
| 63 | viodev->unit_address = unit_num; |
| 64 | viodev->iommu_table = &vio_iommu_table; |
| 65 | if (vio_register_device(viodev) == NULL) { |
| 66 | kfree(viodev); |
| 67 | return NULL; |
| 68 | } |
| 69 | return viodev; |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void __init probe_bus_iseries(void) |
| 73 | { |
| 74 | HvLpIndexMap vlan_map; |
| 75 | struct vio_dev *viodev; |
| 76 | int i; |
| 77 | |
| 78 | /* there is only one of each of these */ |
| 79 | vio_register_device_iseries("viocons", 0); |
| 80 | vio_register_device_iseries("vscsi", 0); |
| 81 | |
| 82 | vlan_map = HvLpConfig_getVirtualLanIndexMap(); |
| 83 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) { |
| 84 | if ((vlan_map & (0x8000 >> i)) == 0) |
| 85 | continue; |
| 86 | viodev = vio_register_device_iseries("vlan", i); |
| 87 | /* veth is special and has it own iommu_table */ |
| 88 | viodev->iommu_table = &veth_iommu_table; |
| 89 | } |
| 90 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++) |
| 91 | vio_register_device_iseries("viodasd", i); |
| 92 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++) |
| 93 | vio_register_device_iseries("viocd", i); |
| 94 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++) |
| 95 | vio_register_device_iseries("viotape", i); |
| 96 | } |
| 97 | |
| 98 | /** |
Stephen Rothwell | 6312236 | 2005-07-12 17:45:27 +1000 | [diff] [blame] | 99 | * vio_match_device_iseries: - Tell if a iSeries VIO device matches a |
| 100 | * vio_device_id |
| 101 | */ |
| 102 | static int vio_match_device_iseries(const struct vio_device_id *id, |
| 103 | const struct vio_dev *dev) |
| 104 | { |
| 105 | return strncmp(dev->type, id->type, strlen(id->type)) == 0; |
| 106 | } |
| 107 | |
Stephen Rothwell | 71d276d | 2005-08-17 16:41:44 +1000 | [diff] [blame] | 108 | static struct vio_bus_ops vio_bus_ops_iseries = { |
| 109 | .match = vio_match_device_iseries, |
| 110 | }; |
| 111 | |
Stephen Rothwell | 6312236 | 2005-07-12 17:45:27 +1000 | [diff] [blame] | 112 | /** |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 113 | * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus |
| 114 | */ |
| 115 | static int __init vio_bus_init_iseries(void) |
| 116 | { |
| 117 | int err; |
| 118 | |
Stephen Rothwell | 71d276d | 2005-08-17 16:41:44 +1000 | [diff] [blame] | 119 | err = vio_bus_init(&vio_bus_ops_iseries); |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 120 | if (err == 0) { |
Stephen Rothwell | 8c65b5c | 2005-07-12 17:42:49 +1000 | [diff] [blame] | 121 | iommu_vio_init(); |
Stephen Rothwell | 3e494c8 | 2005-07-12 17:40:17 +1000 | [diff] [blame] | 122 | vio_bus_device.iommu_table = &vio_iommu_table; |
| 123 | iSeries_vio_dev = &vio_bus_device.dev; |
| 124 | probe_bus_iseries(); |
| 125 | } |
| 126 | return err; |
| 127 | } |
| 128 | |
| 129 | __initcall(vio_bus_init_iseries); |