blob: ad36ab0639f0496df1f1c1cbbe155c2b26d421f1 [file] [log] [blame]
Stephen Rothwell3e494c82005-07-12 17:40:17 +10001/*
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 Johanssonc707ffc2005-09-20 13:45:41 +100017#include <asm/tce.h>
Stephen Rothwell3e494c82005-07-12 17:40:17 +100018#include <asm/abs_addr.h>
19#include <asm/page.h>
Kelly Dalyb4206772005-11-02 15:13:57 +110020#include <asm/iseries/vio.h>
Kelly Daly1ec65d72005-11-02 13:46:07 +110021#include <asm/iseries/hv_types.h>
Kelly Daly15b17182005-11-02 11:55:28 +110022#include <asm/iseries/hv_lp_config.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110023#include <asm/iseries/hv_call_xm.h>
Stephen Rothwell3e494c82005-07-12 17:40:17 +100024
Stephen Rothwell9bd7ea62006-01-12 13:58:19 +110025#include "iommu.h"
26
Stephen Rothwell3e494c82005-07-12 17:40:17 +100027struct device *iSeries_vio_dev = &vio_bus_device.dev;
28EXPORT_SYMBOL(iSeries_vio_dev);
29
30static struct iommu_table veth_iommu_table;
31static struct iommu_table vio_iommu_table;
32
Stephen Rothwell8c65b5c2005-07-12 17:42:49 +100033static void __init iommu_vio_init(void)
Stephen Rothwell3e494c82005-07-12 17:40:17 +100034{
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110035 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;
Stephen Rothwell3e494c82005-07-12 17:40:17 +100039
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110040 if (!iommu_init_table(&veth_iommu_table))
Stephen Rothwell3e494c82005-07-12 17:40:17 +100041 printk("Virtual Bus VETH TCE table failed.\n");
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110042 if (!iommu_init_table(&vio_iommu_table))
Stephen Rothwell3e494c82005-07-12 17:40:17 +100043 printk("Virtual Bus VIO TCE table failed.\n");
44}
45
46/**
Stephen Rothwellb877b902005-08-17 16:40:12 +100047 * vio_register_device_iseries: - Register a new iSeries vio device.
Stephen Rothwell3e494c82005-07-12 17:40:17 +100048 * @voidev: The device to register.
49 */
50static struct vio_dev *__init vio_register_device_iseries(char *type,
51 uint32_t unit_num)
52{
53 struct vio_dev *viodev;
54
Stephen Rothwellb877b902005-08-17 16:40:12 +100055 /* allocate a vio_dev for this device */
Stephen Rothwell3e494c82005-07-12 17:40:17 +100056 viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);
57 if (!viodev)
58 return NULL;
59 memset(viodev, 0, sizeof(struct vio_dev));
60
61 snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num);
62
Stephen Rothwellb877b902005-08-17 16:40:12 +100063 viodev->name = viodev->dev.bus_id;
64 viodev->type = type;
65 viodev->unit_address = unit_num;
66 viodev->iommu_table = &vio_iommu_table;
67 if (vio_register_device(viodev) == NULL) {
68 kfree(viodev);
69 return NULL;
70 }
71 return viodev;
Stephen Rothwell3e494c82005-07-12 17:40:17 +100072}
73
74void __init probe_bus_iseries(void)
75{
76 HvLpIndexMap vlan_map;
77 struct vio_dev *viodev;
78 int i;
79
80 /* there is only one of each of these */
81 vio_register_device_iseries("viocons", 0);
82 vio_register_device_iseries("vscsi", 0);
83
84 vlan_map = HvLpConfig_getVirtualLanIndexMap();
85 for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {
86 if ((vlan_map & (0x8000 >> i)) == 0)
87 continue;
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;
91 }
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);
98}
99
100/**
Stephen Rothwell63122362005-07-12 17:45:27 +1000101 * vio_match_device_iseries: - Tell if a iSeries VIO device matches a
102 * vio_device_id
103 */
104static int vio_match_device_iseries(const struct vio_device_id *id,
105 const struct vio_dev *dev)
106{
107 return strncmp(dev->type, id->type, strlen(id->type)) == 0;
108}
109
Stephen Rothwell71d276d2005-08-17 16:41:44 +1000110static struct vio_bus_ops vio_bus_ops_iseries = {
111 .match = vio_match_device_iseries,
112};
113
Stephen Rothwell63122362005-07-12 17:45:27 +1000114/**
Stephen Rothwell3e494c82005-07-12 17:40:17 +1000115 * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus
116 */
117static int __init vio_bus_init_iseries(void)
118{
119 int err;
120
Stephen Rothwell71d276d2005-08-17 16:41:44 +1000121 err = vio_bus_init(&vio_bus_ops_iseries);
Stephen Rothwell3e494c82005-07-12 17:40:17 +1000122 if (err == 0) {
Stephen Rothwell8c65b5c2005-07-12 17:42:49 +1000123 iommu_vio_init();
Stephen Rothwell3e494c82005-07-12 17:40:17 +1000124 vio_bus_device.iommu_table = &vio_iommu_table;
125 iSeries_vio_dev = &vio_bus_device.dev;
126 probe_bus_iseries();
127 }
128 return err;
129}
130
131__initcall(vio_bus_init_iseries);