aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/vio.c
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2006-04-27 03:23:32 -0400
committerPaul Mackerras <paulus@samba.org>2006-04-29 04:02:02 -0400
commitc7f0e8cb5654a50986c6097b3c0cca972e406899 (patch)
treedc8a8e590c5cf97d8b7cae2f1e93bdbef178f89f /arch/powerpc/kernel/vio.c
parentdd721ffd95d5e1516380da0b254ef737582a258f (diff)
[PATCH] powerpc: merge the rest of the vio code
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel/vio.c')
-rw-r--r--arch/powerpc/kernel/vio.c198
1 files changed, 164 insertions, 34 deletions
diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 19529297a2dc..ac5c7bf907f5 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -13,25 +13,102 @@
13 * 2 of the License, or (at your option) any later version. 13 * 2 of the License, or (at your option) any later version.
14 */ 14 */
15 15
16#include <linux/types.h>
17#include <linux/device.h>
16#include <linux/init.h> 18#include <linux/init.h>
17#include <linux/console.h> 19#include <linux/console.h>
18#include <linux/module.h> 20#include <linux/module.h>
19#include <linux/mm.h> 21#include <linux/mm.h>
20#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/kobject.h>
24
21#include <asm/iommu.h> 25#include <asm/iommu.h>
22#include <asm/dma.h> 26#include <asm/dma.h>
23#include <asm/vio.h> 27#include <asm/vio.h>
24#include <asm/prom.h> 28#include <asm/prom.h>
25#include <asm/firmware.h> 29#include <asm/firmware.h>
26 30#include <asm/tce.h>
27struct vio_dev vio_bus_device = { /* fake "parent" device */ 31#include <asm/abs_addr.h>
32#include <asm/page.h>
33#include <asm/hvcall.h>
34#include <asm/iseries/vio.h>
35#include <asm/iseries/hv_types.h>
36#include <asm/iseries/hv_lp_config.h>
37#include <asm/iseries/hv_call_xm.h>
38#include <asm/iseries/iommu.h>
39
40extern struct subsystem devices_subsys; /* needed for vio_find_name() */
41
42static struct vio_dev vio_bus_device = { /* fake "parent" device */
28 .name = vio_bus_device.dev.bus_id, 43 .name = vio_bus_device.dev.bus_id,
29 .type = "", 44 .type = "",
30 .dev.bus_id = "vio", 45 .dev.bus_id = "vio",
31 .dev.bus = &vio_bus_type, 46 .dev.bus = &vio_bus_type,
32}; 47};
33 48
34static struct vio_bus_ops vio_bus_ops; 49#ifdef CONFIG_PPC_ISERIES
50struct device *iSeries_vio_dev = &vio_bus_device.dev;
51EXPORT_SYMBOL(iSeries_vio_dev);
52
53static struct iommu_table veth_iommu_table;
54static struct iommu_table vio_iommu_table;
55
56static void __init iommu_vio_init(void)
57{
58 iommu_table_getparms_iSeries(255, 0, 0xff, &veth_iommu_table);
59 veth_iommu_table.it_size /= 2;
60 vio_iommu_table = veth_iommu_table;
61 vio_iommu_table.it_offset += veth_iommu_table.it_size;
62
63 if (!iommu_init_table(&veth_iommu_table))
64 printk("Virtual Bus VETH TCE table failed.\n");
65 if (!iommu_init_table(&vio_iommu_table))
66 printk("Virtual Bus VIO TCE table failed.\n");
67}
68#endif
69
70static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
71{
72#ifdef CONFIG_PPC_ISERIES
73 if (firmware_has_feature(FW_FEATURE_ISERIES)) {
74 if (strcmp(dev->type, "vlan") == 0)
75 return &veth_iommu_table;
76 return &vio_iommu_table;
77 } else
78#endif
79 {
80 unsigned int *dma_window;
81 struct iommu_table *newTceTable;
82 unsigned long offset;
83 int dma_window_property_size;
84
85 dma_window = (unsigned int *)get_property(
86 dev->dev.platform_data, "ibm,my-dma-window",
87 &dma_window_property_size);
88 if (!dma_window)
89 return NULL;
90
91 newTceTable = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
92
93 /*
94 * There should be some code to extract the phys-encoded
95 * offset using prom_n_addr_cells(). However, according to
96 * a comment on earlier versions, it's always zero, so we
97 * don't bother
98 */
99 offset = dma_window[1] >> PAGE_SHIFT;
100
101 /* TCE table size - measured in tce entries */
102 newTceTable->it_size = dma_window[4] >> PAGE_SHIFT;
103 /* offset for VIO should always be 0 */
104 newTceTable->it_offset = offset;
105 newTceTable->it_busno = 0;
106 newTceTable->it_index = (unsigned long)dma_window[0];
107 newTceTable->it_type = TCE_VB;
108
109 return iommu_init_table(newTceTable);
110 }
111}
35 112
36/** 113/**
37 * vio_match_device: - Tell if a VIO device has a matching 114 * vio_match_device: - Tell if a VIO device has a matching
@@ -126,6 +203,16 @@ void vio_unregister_driver(struct vio_driver *viodrv)
126} 203}
127EXPORT_SYMBOL(vio_unregister_driver); 204EXPORT_SYMBOL(vio_unregister_driver);
128 205
206/* vio_dev refcount hit 0 */
207static void __devinit vio_dev_release(struct device *dev)
208{
209 if (dev->platform_data) {
210 /* XXX free TCE table */
211 of_node_put(dev->platform_data);
212 }
213 kfree(to_vio_dev(dev));
214}
215
129/** 216/**
130 * vio_register_device_node: - Register a new vio device. 217 * vio_register_device_node: - Register a new vio device.
131 * @of_node: The OF node for this device. 218 * @of_node: The OF node for this device.
@@ -185,10 +272,17 @@ struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node)
185 if (unit_address != NULL) 272 if (unit_address != NULL)
186 viodev->unit_address = *unit_address; 273 viodev->unit_address = *unit_address;
187 } 274 }
188 viodev->iommu_table = vio_bus_ops.build_iommu_table(viodev); 275 viodev->iommu_table = vio_build_iommu_table(viodev);
276
277 /* init generic 'struct device' fields: */
278 viodev->dev.parent = &vio_bus_device.dev;
279 viodev->dev.bus = &vio_bus_type;
280 viodev->dev.release = vio_dev_release;
189 281
190 /* register with generic device framework */ 282 /* register with generic device framework */
191 if (vio_register_device(viodev) == NULL) { 283 if (device_register(&viodev->dev)) {
284 printk(KERN_ERR "%s: failed to register device %s\n",
285 __FUNCTION__, viodev->dev.bus_id);
192 /* XXX free TCE table */ 286 /* XXX free TCE table */
193 kfree(viodev); 287 kfree(viodev);
194 return NULL; 288 return NULL;
@@ -201,12 +295,18 @@ EXPORT_SYMBOL(vio_register_device_node);
201/** 295/**
202 * vio_bus_init: - Initialize the virtual IO bus 296 * vio_bus_init: - Initialize the virtual IO bus
203 */ 297 */
204int __init vio_bus_init(struct vio_bus_ops *ops) 298static int __init vio_bus_init(void)
205{ 299{
206 int err; 300 int err;
207 struct device_node *node_vroot; 301 struct device_node *node_vroot;
208 302
209 vio_bus_ops = *ops; 303#ifdef CONFIG_PPC_ISERIES
304 if (firmware_has_feature(FW_FEATURE_ISERIES)) {
305 iommu_vio_init();
306 vio_bus_device.iommu_table = &vio_iommu_table;
307 iSeries_vio_dev = &vio_bus_device.dev;
308 }
309#endif
210 310
211 err = bus_register(&vio_bus_type); 311 err = bus_register(&vio_bus_type);
212 if (err) { 312 if (err) {
@@ -243,16 +343,7 @@ int __init vio_bus_init(struct vio_bus_ops *ops)
243 343
244 return 0; 344 return 0;
245} 345}
246 346__initcall(vio_bus_init);
247/* vio_dev refcount hit 0 */
248static void __devinit vio_dev_release(struct device *dev)
249{
250 if (dev->platform_data) {
251 /* XXX free TCE table */
252 of_node_put(dev->platform_data);
253 }
254 kfree(to_vio_dev(dev));
255}
256 347
257static ssize_t name_show(struct device *dev, 348static ssize_t name_show(struct device *dev,
258 struct device_attribute *attr, char *buf) 349 struct device_attribute *attr, char *buf)
@@ -274,23 +365,6 @@ static struct device_attribute vio_dev_attrs[] = {
274 __ATTR_NULL 365 __ATTR_NULL
275}; 366};
276 367
277struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev)
278{
279 /* init generic 'struct device' fields: */
280 viodev->dev.parent = &vio_bus_device.dev;
281 viodev->dev.bus = &vio_bus_type;
282 viodev->dev.release = vio_dev_release;
283
284 /* register with generic device framework */
285 if (device_register(&viodev->dev)) {
286 printk(KERN_ERR "%s: failed to register device %s\n",
287 __FUNCTION__, viodev->dev.bus_id);
288 return NULL;
289 }
290
291 return viodev;
292}
293
294void __devinit vio_unregister_device(struct vio_dev *viodev) 368void __devinit vio_unregister_device(struct vio_dev *viodev)
295{ 369{
296 device_unregister(&viodev->dev); 370 device_unregister(&viodev->dev);
@@ -412,3 +486,59 @@ const void *vio_get_attribute(struct vio_dev *vdev, char *which, int *length)
412 return get_property(vdev->dev.platform_data, which, length); 486 return get_property(vdev->dev.platform_data, which, length);
413} 487}
414EXPORT_SYMBOL(vio_get_attribute); 488EXPORT_SYMBOL(vio_get_attribute);
489
490#ifdef CONFIG_PPC_PSERIES
491/* vio_find_name() - internal because only vio.c knows how we formatted the
492 * kobject name
493 * XXX once vio_bus_type.devices is actually used as a kset in
494 * drivers/base/bus.c, this function should be removed in favor of
495 * "device_find(kobj_name, &vio_bus_type)"
496 */
497static struct vio_dev *vio_find_name(const char *kobj_name)
498{
499 struct kobject *found;
500
501 found = kset_find_obj(&devices_subsys.kset, kobj_name);
502 if (!found)
503 return NULL;
504
505 return to_vio_dev(container_of(found, struct device, kobj));
506}
507
508/**
509 * vio_find_node - find an already-registered vio_dev
510 * @vnode: device_node of the virtual device we're looking for
511 */
512struct vio_dev *vio_find_node(struct device_node *vnode)
513{
514 uint32_t *unit_address;
515 char kobj_name[BUS_ID_SIZE];
516
517 /* construct the kobject name from the device node */
518 unit_address = (uint32_t *)get_property(vnode, "reg", NULL);
519 if (!unit_address)
520 return NULL;
521 snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address);
522
523 return vio_find_name(kobj_name);
524}
525EXPORT_SYMBOL(vio_find_node);
526
527int vio_enable_interrupts(struct vio_dev *dev)
528{
529 int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE);
530 if (rc != H_SUCCESS)
531 printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc);
532 return rc;
533}
534EXPORT_SYMBOL(vio_enable_interrupts);
535
536int vio_disable_interrupts(struct vio_dev *dev)
537{
538 int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE);
539 if (rc != H_SUCCESS)
540 printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc);
541 return rc;
542}
543EXPORT_SYMBOL(vio_disable_interrupts);
544#endif /* CONFIG_PPC_PSERIES */