diff options
-rw-r--r-- | arch/powerpc/kernel/vio.c | 198 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/iommu.c | 3 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/pci.c | 2 | ||||
-rw-r--r-- | arch/powerpc/platforms/iseries/vio.c | 67 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/platforms/pseries/vio.c | 133 | ||||
-rw-r--r-- | include/asm-powerpc/iseries/iommu.h (renamed from arch/powerpc/platforms/iseries/iommu.h) | 6 | ||||
-rw-r--r-- | include/asm-powerpc/vio.h | 8 |
9 files changed, 169 insertions, 250 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> | |
27 | struct 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 | |||
40 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ | ||
41 | |||
42 | static 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 | ||
34 | static struct vio_bus_ops vio_bus_ops; | 49 | #ifdef CONFIG_PPC_ISERIES |
50 | struct device *iSeries_vio_dev = &vio_bus_device.dev; | ||
51 | EXPORT_SYMBOL(iSeries_vio_dev); | ||
52 | |||
53 | static struct iommu_table veth_iommu_table; | ||
54 | static struct iommu_table vio_iommu_table; | ||
55 | |||
56 | static 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 | |||
70 | static 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 | } |
127 | EXPORT_SYMBOL(vio_unregister_driver); | 204 | EXPORT_SYMBOL(vio_unregister_driver); |
128 | 205 | ||
206 | /* vio_dev refcount hit 0 */ | ||
207 | static 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 | */ |
204 | int __init vio_bus_init(struct vio_bus_ops *ops) | 298 | static 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 */ | ||
248 | static 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 | ||
257 | static ssize_t name_show(struct device *dev, | 348 | static 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 | ||
277 | struct 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 | |||
294 | void __devinit vio_unregister_device(struct vio_dev *viodev) | 368 | void __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 | } |
414 | EXPORT_SYMBOL(vio_get_attribute); | 488 | EXPORT_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 | */ | ||
497 | static 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 | */ | ||
512 | struct 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 | } | ||
525 | EXPORT_SYMBOL(vio_find_node); | ||
526 | |||
527 | int 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 | } | ||
534 | EXPORT_SYMBOL(vio_enable_interrupts); | ||
535 | |||
536 | int 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 | } | ||
543 | EXPORT_SYMBOL(vio_disable_interrupts); | ||
544 | #endif /* CONFIG_PPC_PSERIES */ | ||
diff --git a/arch/powerpc/platforms/iseries/Makefile b/arch/powerpc/platforms/iseries/Makefile index ce8c0b943fa0..7e67a20c18ab 100644 --- a/arch/powerpc/platforms/iseries/Makefile +++ b/arch/powerpc/platforms/iseries/Makefile | |||
@@ -3,7 +3,6 @@ EXTRA_CFLAGS += -mno-minimal-toc | |||
3 | obj-y += hvlog.o hvlpconfig.o lpardata.o setup.o mf.o lpevents.o \ | 3 | obj-y += hvlog.o hvlpconfig.o lpardata.o setup.o mf.o lpevents.o \ |
4 | hvcall.o proc.o htab.o iommu.o misc.o irq.o | 4 | hvcall.o proc.o htab.o iommu.o misc.o irq.o |
5 | obj-$(CONFIG_PCI) += pci.o vpdinfo.o | 5 | obj-$(CONFIG_PCI) += pci.o vpdinfo.o |
6 | obj-$(CONFIG_IBMVIO) += vio.o | ||
7 | obj-$(CONFIG_SMP) += smp.o | 6 | obj-$(CONFIG_SMP) += smp.o |
8 | obj-$(CONFIG_VIOPATH) += viopath.o | 7 | obj-$(CONFIG_VIOPATH) += viopath.o |
9 | obj-$(CONFIG_MODULES) += ksyms.o | 8 | obj-$(CONFIG_MODULES) += ksyms.o |
diff --git a/arch/powerpc/platforms/iseries/iommu.c b/arch/powerpc/platforms/iseries/iommu.c index bea0b703f409..a8d96314c982 100644 --- a/arch/powerpc/platforms/iseries/iommu.c +++ b/arch/powerpc/platforms/iseries/iommu.c | |||
@@ -33,8 +33,7 @@ | |||
33 | #include <asm/abs_addr.h> | 33 | #include <asm/abs_addr.h> |
34 | #include <asm/pci-bridge.h> | 34 | #include <asm/pci-bridge.h> |
35 | #include <asm/iseries/hv_call_xm.h> | 35 | #include <asm/iseries/hv_call_xm.h> |
36 | 36 | #include <asm/iseries/iommu.h> | |
37 | #include "iommu.h" | ||
38 | 37 | ||
39 | extern struct list_head iSeries_Global_Device_List; | 38 | extern struct list_head iSeries_Global_Device_List; |
40 | 39 | ||
diff --git a/arch/powerpc/platforms/iseries/pci.c b/arch/powerpc/platforms/iseries/pci.c index 5a61c6fdb33a..428ffb5cf044 100644 --- a/arch/powerpc/platforms/iseries/pci.c +++ b/arch/powerpc/platforms/iseries/pci.c | |||
@@ -37,13 +37,13 @@ | |||
37 | 37 | ||
38 | #include <asm/iseries/hv_call_xm.h> | 38 | #include <asm/iseries/hv_call_xm.h> |
39 | #include <asm/iseries/mf.h> | 39 | #include <asm/iseries/mf.h> |
40 | #include <asm/iseries/iommu.h> | ||
40 | 41 | ||
41 | #include <asm/ppc-pci.h> | 42 | #include <asm/ppc-pci.h> |
42 | 43 | ||
43 | #include "irq.h" | 44 | #include "irq.h" |
44 | #include "pci.h" | 45 | #include "pci.h" |
45 | #include "call_pci.h" | 46 | #include "call_pci.h" |
46 | #include "iommu.h" | ||
47 | 47 | ||
48 | /* | 48 | /* |
49 | * Forward declares of prototypes. | 49 | * Forward declares of prototypes. |
diff --git a/arch/powerpc/platforms/iseries/vio.c b/arch/powerpc/platforms/iseries/vio.c deleted file mode 100644 index bdd2b7d97d15..000000000000 --- a/arch/powerpc/platforms/iseries/vio.c +++ /dev/null | |||
@@ -1,67 +0,0 @@ | |||
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> | ||
17 | #include <asm/tce.h> | ||
18 | #include <asm/abs_addr.h> | ||
19 | #include <asm/page.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> | ||
24 | |||
25 | #include "iommu.h" | ||
26 | |||
27 | struct device *iSeries_vio_dev = &vio_bus_device.dev; | ||
28 | EXPORT_SYMBOL(iSeries_vio_dev); | ||
29 | |||
30 | static struct iommu_table veth_iommu_table; | ||
31 | static struct iommu_table vio_iommu_table; | ||
32 | |||
33 | static void __init iommu_vio_init(void) | ||
34 | { | ||
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; | ||
39 | |||
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"); | ||
44 | } | ||
45 | |||
46 | static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev) | ||
47 | { | ||
48 | if (strcmp(dev->type, "vlan") == 0) | ||
49 | return &veth_iommu_table; | ||
50 | return &vio_iommu_table; | ||
51 | } | ||
52 | |||
53 | static struct vio_bus_ops vio_bus_ops_iseries = { | ||
54 | .build_iommu_table = vio_build_iommu_table, | ||
55 | }; | ||
56 | |||
57 | /** | ||
58 | * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus | ||
59 | */ | ||
60 | static int __init vio_bus_init_iseries(void) | ||
61 | { | ||
62 | iommu_vio_init(); | ||
63 | vio_bus_device.iommu_table = &vio_iommu_table; | ||
64 | iSeries_vio_dev = &vio_bus_device.dev; | ||
65 | return vio_bus_init(&vio_bus_ops_iseries); | ||
66 | } | ||
67 | __initcall(vio_bus_init_iseries); | ||
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile index 930898635c9f..b46ce3b9bb3c 100644 --- a/arch/powerpc/platforms/pseries/Makefile +++ b/arch/powerpc/platforms/pseries/Makefile | |||
@@ -2,7 +2,6 @@ obj-y := pci.o lpar.o hvCall.o nvram.o reconfig.o \ | |||
2 | setup.o iommu.o ras.o rtasd.o pci_dlpar.o \ | 2 | setup.o iommu.o ras.o rtasd.o pci_dlpar.o \ |
3 | firmware.o | 3 | firmware.o |
4 | obj-$(CONFIG_SMP) += smp.o | 4 | obj-$(CONFIG_SMP) += smp.o |
5 | obj-$(CONFIG_IBMVIO) += vio.o | ||
6 | obj-$(CONFIG_XICS) += xics.o | 5 | obj-$(CONFIG_XICS) += xics.o |
7 | obj-$(CONFIG_SCANLOG) += scanlog.o | 6 | obj-$(CONFIG_SCANLOG) += scanlog.o |
8 | obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o | 7 | obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o |
diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c deleted file mode 100644 index d2891661d87b..000000000000 --- a/arch/powerpc/platforms/pseries/vio.c +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /* | ||
2 | * IBM PowerPC pSeries Virtual I/O Infrastructure Support. | ||
3 | * | ||
4 | * Copyright (c) 2003-2005 IBM Corp. | ||
5 | * Dave Engebretsen engebret@us.ibm.com | ||
6 | * Santiago Leon santil@us.ibm.com | ||
7 | * Hollis Blanchard <hollisb@us.ibm.com> | ||
8 | * Stephen Rothwell | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version | ||
13 | * 2 of the License, or (at your option) any later version. | ||
14 | */ | ||
15 | |||
16 | #include <linux/init.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/mm.h> | ||
19 | #include <linux/kobject.h> | ||
20 | #include <asm/iommu.h> | ||
21 | #include <asm/dma.h> | ||
22 | #include <asm/prom.h> | ||
23 | #include <asm/vio.h> | ||
24 | #include <asm/hvcall.h> | ||
25 | #include <asm/tce.h> | ||
26 | |||
27 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ | ||
28 | |||
29 | /** | ||
30 | * vio_build_iommu_table: - gets the dma information from OF and | ||
31 | * builds the TCE tree. | ||
32 | * @dev: the virtual device. | ||
33 | * | ||
34 | * Returns a pointer to the built tce tree, or NULL if it can't | ||
35 | * find property. | ||
36 | */ | ||
37 | static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev) | ||
38 | { | ||
39 | unsigned int *dma_window; | ||
40 | struct iommu_table *newTceTable; | ||
41 | unsigned long offset; | ||
42 | int dma_window_property_size; | ||
43 | |||
44 | dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size); | ||
45 | if(!dma_window) { | ||
46 | return NULL; | ||
47 | } | ||
48 | |||
49 | newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL); | ||
50 | |||
51 | /* There should be some code to extract the phys-encoded offset | ||
52 | using prom_n_addr_cells(). However, according to a comment | ||
53 | on earlier versions, it's always zero, so we don't bother */ | ||
54 | offset = dma_window[1] >> PAGE_SHIFT; | ||
55 | |||
56 | /* TCE table size - measured in tce entries */ | ||
57 | newTceTable->it_size = dma_window[4] >> PAGE_SHIFT; | ||
58 | /* offset for VIO should always be 0 */ | ||
59 | newTceTable->it_offset = offset; | ||
60 | newTceTable->it_busno = 0; | ||
61 | newTceTable->it_index = (unsigned long)dma_window[0]; | ||
62 | newTceTable->it_type = TCE_VB; | ||
63 | |||
64 | return iommu_init_table(newTceTable); | ||
65 | } | ||
66 | |||
67 | static struct vio_bus_ops vio_bus_ops_pseries = { | ||
68 | .build_iommu_table = vio_build_iommu_table, | ||
69 | }; | ||
70 | |||
71 | /** | ||
72 | * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus | ||
73 | */ | ||
74 | static int __init vio_bus_init_pseries(void) | ||
75 | { | ||
76 | return vio_bus_init(&vio_bus_ops_pseries); | ||
77 | } | ||
78 | |||
79 | __initcall(vio_bus_init_pseries); | ||
80 | |||
81 | /* vio_find_name() - internal because only vio.c knows how we formatted the | ||
82 | * kobject name | ||
83 | * XXX once vio_bus_type.devices is actually used as a kset in | ||
84 | * drivers/base/bus.c, this function should be removed in favor of | ||
85 | * "device_find(kobj_name, &vio_bus_type)" | ||
86 | */ | ||
87 | static struct vio_dev *vio_find_name(const char *kobj_name) | ||
88 | { | ||
89 | struct kobject *found; | ||
90 | |||
91 | found = kset_find_obj(&devices_subsys.kset, kobj_name); | ||
92 | if (!found) | ||
93 | return NULL; | ||
94 | |||
95 | return to_vio_dev(container_of(found, struct device, kobj)); | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | * vio_find_node - find an already-registered vio_dev | ||
100 | * @vnode: device_node of the virtual device we're looking for | ||
101 | */ | ||
102 | struct vio_dev *vio_find_node(struct device_node *vnode) | ||
103 | { | ||
104 | uint32_t *unit_address; | ||
105 | char kobj_name[BUS_ID_SIZE]; | ||
106 | |||
107 | /* construct the kobject name from the device node */ | ||
108 | unit_address = (uint32_t *)get_property(vnode, "reg", NULL); | ||
109 | if (!unit_address) | ||
110 | return NULL; | ||
111 | snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address); | ||
112 | |||
113 | return vio_find_name(kobj_name); | ||
114 | } | ||
115 | EXPORT_SYMBOL(vio_find_node); | ||
116 | |||
117 | int vio_enable_interrupts(struct vio_dev *dev) | ||
118 | { | ||
119 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE); | ||
120 | if (rc != H_SUCCESS) | ||
121 | printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc); | ||
122 | return rc; | ||
123 | } | ||
124 | EXPORT_SYMBOL(vio_enable_interrupts); | ||
125 | |||
126 | int vio_disable_interrupts(struct vio_dev *dev) | ||
127 | { | ||
128 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE); | ||
129 | if (rc != H_SUCCESS) | ||
130 | printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc); | ||
131 | return rc; | ||
132 | } | ||
133 | EXPORT_SYMBOL(vio_disable_interrupts); | ||
diff --git a/arch/powerpc/platforms/iseries/iommu.h b/include/asm-powerpc/iseries/iommu.h index cb5658fbe657..0edbfe10cb37 100644 --- a/arch/powerpc/platforms/iseries/iommu.h +++ b/include/asm-powerpc/iseries/iommu.h | |||
@@ -1,5 +1,5 @@ | |||
1 | #ifndef _PLATFORMS_ISERIES_IOMMU_H | 1 | #ifndef _ASM_POWERPC_ISERIES_IOMMU_H |
2 | #define _PLATFORMS_ISERIES_IOMMU_H | 2 | #define _ASM_POWERPC_ISERIES_IOMMU_H |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * Copyright (C) 2005 Stephen Rothwell, IBM Corporation | 5 | * Copyright (C) 2005 Stephen Rothwell, IBM Corporation |
@@ -32,4 +32,4 @@ extern void iommu_table_getparms_iSeries(unsigned long busno, | |||
32 | unsigned char slotno, unsigned char virtbus, | 32 | unsigned char slotno, unsigned char virtbus, |
33 | struct iommu_table *tbl); | 33 | struct iommu_table *tbl); |
34 | 34 | ||
35 | #endif /* _PLATFORMS_ISERIES_IOMMU_H */ | 35 | #endif /* _ASM_POWERPC_ISERIES_IOMMU_H */ |
diff --git a/include/asm-powerpc/vio.h b/include/asm-powerpc/vio.h index 9c09a8ffa128..10da7f3af938 100644 --- a/include/asm-powerpc/vio.h +++ b/include/asm-powerpc/vio.h | |||
@@ -64,22 +64,14 @@ struct vio_driver { | |||
64 | struct device_driver driver; | 64 | struct device_driver driver; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | struct vio_bus_ops { | ||
68 | struct iommu_table *(*build_iommu_table)(struct vio_dev *dev); | ||
69 | }; | ||
70 | |||
71 | extern struct dma_mapping_ops vio_dma_ops; | 67 | extern struct dma_mapping_ops vio_dma_ops; |
72 | extern struct bus_type vio_bus_type; | 68 | extern struct bus_type vio_bus_type; |
73 | extern struct vio_dev vio_bus_device; | ||
74 | 69 | ||
75 | extern int vio_register_driver(struct vio_driver *drv); | 70 | extern int vio_register_driver(struct vio_driver *drv); |
76 | extern void vio_unregister_driver(struct vio_driver *drv); | 71 | extern void vio_unregister_driver(struct vio_driver *drv); |
77 | 72 | ||
78 | extern struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev); | ||
79 | extern void __devinit vio_unregister_device(struct vio_dev *dev); | 73 | extern void __devinit vio_unregister_device(struct vio_dev *dev); |
80 | 74 | ||
81 | extern int vio_bus_init(struct vio_bus_ops *); | ||
82 | |||
83 | struct device_node; | 75 | struct device_node; |
84 | 76 | ||
85 | extern struct vio_dev * __devinit vio_register_device_node( | 77 | extern struct vio_dev * __devinit vio_register_device_node( |