]> git.karo-electronics.de Git - linux-beck.git/blob - arch/powerpc/platforms/pseries/vio.c
d2891661d87b11647ee5b99f91f2bee4f29e6703
[linux-beck.git] / arch / powerpc / platforms / pseries / vio.c
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);