diff options
-rw-r--r-- | arch/ppc64/kernel/Makefile | 1 | ||||
-rw-r--r-- | arch/ppc64/kernel/iSeries_vio.c | 2 | ||||
-rw-r--r-- | arch/ppc64/kernel/pSeries_vio.c | 266 | ||||
-rw-r--r-- | arch/ppc64/kernel/vio.c | 290 | ||||
-rw-r--r-- | include/asm-ppc64/vio.h | 4 |
5 files changed, 284 insertions, 279 deletions
diff --git a/arch/ppc64/kernel/Makefile b/arch/ppc64/kernel/Makefile index a22c94f6b2db..cbf87dcac92a 100644 --- a/arch/ppc64/kernel/Makefile +++ b/arch/ppc64/kernel/Makefile | |||
@@ -51,6 +51,7 @@ obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o | |||
51 | obj-$(CONFIG_BOOTX_TEXT) += btext.o | 51 | obj-$(CONFIG_BOOTX_TEXT) += btext.o |
52 | obj-$(CONFIG_HVCS) += hvcserver.o | 52 | obj-$(CONFIG_HVCS) += hvcserver.o |
53 | 53 | ||
54 | vio-obj-$(CONFIG_PPC_PSERIES) += pSeries_vio.o | ||
54 | vio-obj-$(CONFIG_PPC_ISERIES) += iSeries_vio.o | 55 | vio-obj-$(CONFIG_PPC_ISERIES) += iSeries_vio.o |
55 | obj-$(CONFIG_IBMVIO) += vio.o $(vio-obj-y) | 56 | obj-$(CONFIG_IBMVIO) += vio.o $(vio-obj-y) |
56 | obj-$(CONFIG_XICS) += xics.o | 57 | obj-$(CONFIG_XICS) += xics.o |
diff --git a/arch/ppc64/kernel/iSeries_vio.c b/arch/ppc64/kernel/iSeries_vio.c index 2656b1ca834d..b4268cc4ba48 100644 --- a/arch/ppc64/kernel/iSeries_vio.c +++ b/arch/ppc64/kernel/iSeries_vio.c | |||
@@ -131,7 +131,7 @@ static int __init vio_bus_init_iseries(void) | |||
131 | { | 131 | { |
132 | int err; | 132 | int err; |
133 | 133 | ||
134 | err = vio_bus_init(vio_match_device_iseries); | 134 | err = vio_bus_init(vio_match_device_iseries, NULL, NULL); |
135 | if (err == 0) { | 135 | if (err == 0) { |
136 | iommu_vio_init(); | 136 | iommu_vio_init(); |
137 | vio_bus_device.iommu_table = &vio_iommu_table; | 137 | vio_bus_device.iommu_table = &vio_iommu_table; |
diff --git a/arch/ppc64/kernel/pSeries_vio.c b/arch/ppc64/kernel/pSeries_vio.c new file mode 100644 index 000000000000..338f9e1bdc09 --- /dev/null +++ b/arch/ppc64/kernel/pSeries_vio.c | |||
@@ -0,0 +1,266 @@ | |||
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/vio.h> | ||
23 | #include <asm/hvcall.h> | ||
24 | |||
25 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ | ||
26 | |||
27 | static void probe_bus_pseries(void) | ||
28 | { | ||
29 | struct device_node *node_vroot, *of_node; | ||
30 | |||
31 | node_vroot = find_devices("vdevice"); | ||
32 | if ((node_vroot == NULL) || (node_vroot->child == NULL)) | ||
33 | /* this machine doesn't do virtual IO, and that's ok */ | ||
34 | return; | ||
35 | |||
36 | /* | ||
37 | * Create struct vio_devices for each virtual device in the device tree. | ||
38 | * Drivers will associate with them later. | ||
39 | */ | ||
40 | for (of_node = node_vroot->child; of_node != NULL; | ||
41 | of_node = of_node->sibling) { | ||
42 | printk(KERN_DEBUG "%s: processing %p\n", __FUNCTION__, of_node); | ||
43 | vio_register_device_node(of_node); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * vio_match_device_pseries: - Tell if a pSeries VIO device matches a | ||
49 | * vio_device_id | ||
50 | */ | ||
51 | static int vio_match_device_pseries(const struct vio_device_id *id, | ||
52 | const struct vio_dev *dev) | ||
53 | { | ||
54 | return (strncmp(dev->type, id->type, strlen(id->type)) == 0) && | ||
55 | device_is_compatible(dev->dev.platform_data, id->compat); | ||
56 | } | ||
57 | |||
58 | static void vio_release_device_pseries(struct device *dev) | ||
59 | { | ||
60 | /* XXX free TCE table */ | ||
61 | of_node_put(dev->platform_data); | ||
62 | } | ||
63 | |||
64 | static ssize_t viodev_show_devspec(struct device *dev, | ||
65 | struct device_attribute *attr, char *buf) | ||
66 | { | ||
67 | struct device_node *of_node = dev->platform_data; | ||
68 | |||
69 | return sprintf(buf, "%s\n", of_node->full_name); | ||
70 | } | ||
71 | DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL); | ||
72 | |||
73 | static void vio_unregister_device_pseries(struct vio_dev *viodev) | ||
74 | { | ||
75 | device_remove_file(&viodev->dev, &dev_attr_devspec); | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus | ||
80 | */ | ||
81 | static int __init vio_bus_init_pseries(void) | ||
82 | { | ||
83 | int err; | ||
84 | |||
85 | err = vio_bus_init(vio_match_device_pseries, | ||
86 | vio_unregister_device_pseries, | ||
87 | vio_release_device_pseries); | ||
88 | if (err == 0) | ||
89 | probe_bus_pseries(); | ||
90 | return err; | ||
91 | } | ||
92 | |||
93 | __initcall(vio_bus_init_pseries); | ||
94 | |||
95 | /** | ||
96 | * vio_build_iommu_table: - gets the dma information from OF and | ||
97 | * builds the TCE tree. | ||
98 | * @dev: the virtual device. | ||
99 | * | ||
100 | * Returns a pointer to the built tce tree, or NULL if it can't | ||
101 | * find property. | ||
102 | */ | ||
103 | static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev) | ||
104 | { | ||
105 | unsigned int *dma_window; | ||
106 | struct iommu_table *newTceTable; | ||
107 | unsigned long offset; | ||
108 | int dma_window_property_size; | ||
109 | |||
110 | dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size); | ||
111 | if(!dma_window) { | ||
112 | return NULL; | ||
113 | } | ||
114 | |||
115 | newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL); | ||
116 | |||
117 | /* There should be some code to extract the phys-encoded offset | ||
118 | using prom_n_addr_cells(). However, according to a comment | ||
119 | on earlier versions, it's always zero, so we don't bother */ | ||
120 | offset = dma_window[1] >> PAGE_SHIFT; | ||
121 | |||
122 | /* TCE table size - measured in tce entries */ | ||
123 | newTceTable->it_size = dma_window[4] >> PAGE_SHIFT; | ||
124 | /* offset for VIO should always be 0 */ | ||
125 | newTceTable->it_offset = offset; | ||
126 | newTceTable->it_busno = 0; | ||
127 | newTceTable->it_index = (unsigned long)dma_window[0]; | ||
128 | newTceTable->it_type = TCE_VB; | ||
129 | |||
130 | return iommu_init_table(newTceTable); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * vio_register_device_node: - Register a new vio device. | ||
135 | * @of_node: The OF node for this device. | ||
136 | * | ||
137 | * Creates and initializes a vio_dev structure from the data in | ||
138 | * of_node (dev.platform_data) and adds it to the list of virtual devices. | ||
139 | * Returns a pointer to the created vio_dev or NULL if node has | ||
140 | * NULL device_type or compatible fields. | ||
141 | */ | ||
142 | struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node) | ||
143 | { | ||
144 | struct vio_dev *viodev; | ||
145 | unsigned int *unit_address; | ||
146 | unsigned int *irq_p; | ||
147 | |||
148 | /* we need the 'device_type' property, in order to match with drivers */ | ||
149 | if ((NULL == of_node->type)) { | ||
150 | printk(KERN_WARNING | ||
151 | "%s: node %s missing 'device_type'\n", __FUNCTION__, | ||
152 | of_node->name ? of_node->name : "<unknown>"); | ||
153 | return NULL; | ||
154 | } | ||
155 | |||
156 | unit_address = (unsigned int *)get_property(of_node, "reg", NULL); | ||
157 | if (!unit_address) { | ||
158 | printk(KERN_WARNING "%s: node %s missing 'reg'\n", __FUNCTION__, | ||
159 | of_node->name ? of_node->name : "<unknown>"); | ||
160 | return NULL; | ||
161 | } | ||
162 | |||
163 | /* allocate a vio_dev for this node */ | ||
164 | viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL); | ||
165 | if (!viodev) { | ||
166 | return NULL; | ||
167 | } | ||
168 | memset(viodev, 0, sizeof(struct vio_dev)); | ||
169 | |||
170 | viodev->dev.platform_data = of_node_get(of_node); | ||
171 | |||
172 | viodev->irq = NO_IRQ; | ||
173 | irq_p = (unsigned int *)get_property(of_node, "interrupts", NULL); | ||
174 | if (irq_p) { | ||
175 | int virq = virt_irq_create_mapping(*irq_p); | ||
176 | if (virq == NO_IRQ) { | ||
177 | printk(KERN_ERR "Unable to allocate interrupt " | ||
178 | "number for %s\n", of_node->full_name); | ||
179 | } else | ||
180 | viodev->irq = irq_offset_up(virq); | ||
181 | } | ||
182 | |||
183 | snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address); | ||
184 | |||
185 | /* register with generic device framework */ | ||
186 | if (vio_register_device_common(viodev, of_node->name, of_node->type, | ||
187 | *unit_address, vio_build_iommu_table(viodev)) | ||
188 | == NULL) { | ||
189 | /* XXX free TCE table */ | ||
190 | kfree(viodev); | ||
191 | return NULL; | ||
192 | } | ||
193 | device_create_file(&viodev->dev, &dev_attr_devspec); | ||
194 | |||
195 | return viodev; | ||
196 | } | ||
197 | EXPORT_SYMBOL(vio_register_device_node); | ||
198 | |||
199 | /** | ||
200 | * vio_get_attribute: - get attribute for virtual device | ||
201 | * @vdev: The vio device to get property. | ||
202 | * @which: The property/attribute to be extracted. | ||
203 | * @length: Pointer to length of returned data size (unused if NULL). | ||
204 | * | ||
205 | * Calls prom.c's get_property() to return the value of the | ||
206 | * attribute specified by the preprocessor constant @which | ||
207 | */ | ||
208 | const void * vio_get_attribute(struct vio_dev *vdev, void* which, int* length) | ||
209 | { | ||
210 | return get_property(vdev->dev.platform_data, (char*)which, length); | ||
211 | } | ||
212 | EXPORT_SYMBOL(vio_get_attribute); | ||
213 | |||
214 | /* vio_find_name() - internal because only vio.c knows how we formatted the | ||
215 | * kobject name | ||
216 | * XXX once vio_bus_type.devices is actually used as a kset in | ||
217 | * drivers/base/bus.c, this function should be removed in favor of | ||
218 | * "device_find(kobj_name, &vio_bus_type)" | ||
219 | */ | ||
220 | static struct vio_dev *vio_find_name(const char *kobj_name) | ||
221 | { | ||
222 | struct kobject *found; | ||
223 | |||
224 | found = kset_find_obj(&devices_subsys.kset, kobj_name); | ||
225 | if (!found) | ||
226 | return NULL; | ||
227 | |||
228 | return to_vio_dev(container_of(found, struct device, kobj)); | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * vio_find_node - find an already-registered vio_dev | ||
233 | * @vnode: device_node of the virtual device we're looking for | ||
234 | */ | ||
235 | struct vio_dev *vio_find_node(struct device_node *vnode) | ||
236 | { | ||
237 | uint32_t *unit_address; | ||
238 | char kobj_name[BUS_ID_SIZE]; | ||
239 | |||
240 | /* construct the kobject name from the device node */ | ||
241 | unit_address = (uint32_t *)get_property(vnode, "reg", NULL); | ||
242 | if (!unit_address) | ||
243 | return NULL; | ||
244 | snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address); | ||
245 | |||
246 | return vio_find_name(kobj_name); | ||
247 | } | ||
248 | EXPORT_SYMBOL(vio_find_node); | ||
249 | |||
250 | int vio_enable_interrupts(struct vio_dev *dev) | ||
251 | { | ||
252 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE); | ||
253 | if (rc != H_Success) | ||
254 | printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc); | ||
255 | return rc; | ||
256 | } | ||
257 | EXPORT_SYMBOL(vio_enable_interrupts); | ||
258 | |||
259 | int vio_disable_interrupts(struct vio_dev *dev) | ||
260 | { | ||
261 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE); | ||
262 | if (rc != H_Success) | ||
263 | printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc); | ||
264 | return rc; | ||
265 | } | ||
266 | EXPORT_SYMBOL(vio_disable_interrupts); | ||
diff --git a/arch/ppc64/kernel/vio.c b/arch/ppc64/kernel/vio.c index 8a243cad0f8b..3b790bafcaad 100644 --- a/arch/ppc64/kernel/vio.c +++ b/arch/ppc64/kernel/vio.c | |||
@@ -1,10 +1,11 @@ | |||
1 | /* | 1 | /* |
2 | * IBM PowerPC Virtual I/O Infrastructure Support. | 2 | * IBM PowerPC Virtual I/O Infrastructure Support. |
3 | * | 3 | * |
4 | * Copyright (c) 2003 IBM Corp. | 4 | * Copyright (c) 2003-2005 IBM Corp. |
5 | * Dave Engebretsen engebret@us.ibm.com | 5 | * Dave Engebretsen engebret@us.ibm.com |
6 | * Santiago Leon santil@us.ibm.com | 6 | * Santiago Leon santil@us.ibm.com |
7 | * Hollis Blanchard <hollisb@us.ibm.com> | 7 | * Hollis Blanchard <hollisb@us.ibm.com> |
8 | * Stephen Rothwell | ||
8 | * | 9 | * |
9 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
10 | * modify it under the terms of the GNU General Public License | 11 | * modify it under the terms of the GNU General Public License |
@@ -14,29 +15,16 @@ | |||
14 | 15 | ||
15 | #include <linux/init.h> | 16 | #include <linux/init.h> |
16 | #include <linux/console.h> | 17 | #include <linux/console.h> |
17 | #include <linux/version.h> | ||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/kobject.h> | ||
20 | #include <linux/mm.h> | 19 | #include <linux/mm.h> |
21 | #include <linux/dma-mapping.h> | 20 | #include <linux/dma-mapping.h> |
22 | #include <asm/rtas.h> | ||
23 | #include <asm/iommu.h> | 21 | #include <asm/iommu.h> |
24 | #include <asm/dma.h> | 22 | #include <asm/dma.h> |
25 | #include <asm/ppcdebug.h> | ||
26 | #include <asm/vio.h> | 23 | #include <asm/vio.h> |
27 | #include <asm/hvcall.h> | ||
28 | |||
29 | #define DBGENTER() pr_debug("%s entered\n", __FUNCTION__) | ||
30 | |||
31 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ | ||
32 | 24 | ||
33 | static const struct vio_device_id *vio_match_device( | 25 | static const struct vio_device_id *vio_match_device( |
34 | const struct vio_device_id *, const struct vio_dev *); | 26 | const struct vio_device_id *, const struct vio_dev *); |
35 | 27 | ||
36 | #ifdef CONFIG_PPC_PSERIES | ||
37 | static struct iommu_table *vio_build_iommu_table(struct vio_dev *); | ||
38 | static int vio_num_address_cells; | ||
39 | #endif | ||
40 | struct vio_dev vio_bus_device = { /* fake "parent" device */ | 28 | struct vio_dev vio_bus_device = { /* fake "parent" device */ |
41 | .name = vio_bus_device.dev.bus_id, | 29 | .name = vio_bus_device.dev.bus_id, |
42 | .type = "", | 30 | .type = "", |
@@ -46,6 +34,8 @@ struct vio_dev vio_bus_device = { /* fake "parent" device */ | |||
46 | 34 | ||
47 | static int (*is_match)(const struct vio_device_id *id, | 35 | static int (*is_match)(const struct vio_device_id *id, |
48 | const struct vio_dev *dev); | 36 | const struct vio_dev *dev); |
37 | static void (*unregister_device_callback)(struct vio_dev *dev); | ||
38 | static void (*release_device_callback)(struct device *dev); | ||
49 | 39 | ||
50 | /* convert from struct device to struct vio_dev and pass to driver. | 40 | /* convert from struct device to struct vio_dev and pass to driver. |
51 | * dev->driver has already been set by generic code because vio_bus_match | 41 | * dev->driver has already been set by generic code because vio_bus_match |
@@ -57,8 +47,6 @@ static int vio_bus_probe(struct device *dev) | |||
57 | const struct vio_device_id *id; | 47 | const struct vio_device_id *id; |
58 | int error = -ENODEV; | 48 | int error = -ENODEV; |
59 | 49 | ||
60 | DBGENTER(); | ||
61 | |||
62 | if (!viodrv->probe) | 50 | if (!viodrv->probe) |
63 | return error; | 51 | return error; |
64 | 52 | ||
@@ -76,8 +64,6 @@ static int vio_bus_remove(struct device *dev) | |||
76 | struct vio_dev *viodev = to_vio_dev(dev); | 64 | struct vio_dev *viodev = to_vio_dev(dev); |
77 | struct vio_driver *viodrv = to_vio_driver(dev->driver); | 65 | struct vio_driver *viodrv = to_vio_driver(dev->driver); |
78 | 66 | ||
79 | DBGENTER(); | ||
80 | |||
81 | if (viodrv->remove) { | 67 | if (viodrv->remove) { |
82 | return viodrv->remove(viodev); | 68 | return viodrv->remove(viodev); |
83 | } | 69 | } |
@@ -127,8 +113,6 @@ EXPORT_SYMBOL(vio_unregister_driver); | |||
127 | static const struct vio_device_id * vio_match_device(const struct vio_device_id *ids, | 113 | static const struct vio_device_id * vio_match_device(const struct vio_device_id *ids, |
128 | const struct vio_dev *dev) | 114 | const struct vio_dev *dev) |
129 | { | 115 | { |
130 | DBGENTER(); | ||
131 | |||
132 | while (ids->type) { | 116 | while (ids->type) { |
133 | if (is_match(ids, dev)) | 117 | if (is_match(ids, dev)) |
134 | return ids; | 118 | return ids; |
@@ -137,39 +121,19 @@ static const struct vio_device_id * vio_match_device(const struct vio_device_id | |||
137 | return NULL; | 121 | return NULL; |
138 | } | 122 | } |
139 | 123 | ||
140 | #ifdef CONFIG_PPC_PSERIES | ||
141 | static void probe_bus_pseries(void) | ||
142 | { | ||
143 | struct device_node *node_vroot, *of_node; | ||
144 | |||
145 | node_vroot = find_devices("vdevice"); | ||
146 | if ((node_vroot == NULL) || (node_vroot->child == NULL)) | ||
147 | /* this machine doesn't do virtual IO, and that's ok */ | ||
148 | return; | ||
149 | |||
150 | vio_num_address_cells = prom_n_addr_cells(node_vroot->child); | ||
151 | |||
152 | /* | ||
153 | * Create struct vio_devices for each virtual device in the device tree. | ||
154 | * Drivers will associate with them later. | ||
155 | */ | ||
156 | for (of_node = node_vroot->child; of_node != NULL; | ||
157 | of_node = of_node->sibling) { | ||
158 | printk(KERN_DEBUG "%s: processing %p\n", __FUNCTION__, of_node); | ||
159 | vio_register_device_node(of_node); | ||
160 | } | ||
161 | } | ||
162 | #endif | ||
163 | |||
164 | /** | 124 | /** |
165 | * vio_bus_init: - Initialize the virtual IO bus | 125 | * vio_bus_init: - Initialize the virtual IO bus |
166 | */ | 126 | */ |
167 | int __init vio_bus_init(int (*match_func)(const struct vio_device_id *id, | 127 | int __init vio_bus_init(int (*match_func)(const struct vio_device_id *id, |
168 | const struct vio_dev *dev)) | 128 | const struct vio_dev *dev), |
129 | void (*unregister_dev)(struct vio_dev *), | ||
130 | void (*release_dev)(struct device *)) | ||
169 | { | 131 | { |
170 | int err; | 132 | int err; |
171 | 133 | ||
172 | is_match = match_func; | 134 | is_match = match_func; |
135 | unregister_device_callback = unregister_dev; | ||
136 | release_device_callback = release_dev; | ||
173 | 137 | ||
174 | err = bus_register(&vio_bus_type); | 138 | err = bus_register(&vio_bus_type); |
175 | if (err) { | 139 | if (err) { |
@@ -190,56 +154,14 @@ int __init vio_bus_init(int (*match_func)(const struct vio_device_id *id, | |||
190 | return 0; | 154 | return 0; |
191 | } | 155 | } |
192 | 156 | ||
193 | #ifdef CONFIG_PPC_PSERIES | ||
194 | /** | ||
195 | * vio_match_device_pseries: - Tell if a pSeries VIO device matches a | ||
196 | * vio_device_id | ||
197 | */ | ||
198 | static int vio_match_device_pseries(const struct vio_device_id *id, | ||
199 | const struct vio_dev *dev) | ||
200 | { | ||
201 | return (strncmp(dev->type, id->type, strlen(id->type)) == 0) && | ||
202 | device_is_compatible(dev->dev.platform_data, id->compat); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus | ||
207 | */ | ||
208 | static int __init vio_bus_init_pseries(void) | ||
209 | { | ||
210 | int err; | ||
211 | |||
212 | err = vio_bus_init(vio_match_device_pseries); | ||
213 | if (err == 0) | ||
214 | probe_bus_pseries(); | ||
215 | return err; | ||
216 | } | ||
217 | |||
218 | __initcall(vio_bus_init_pseries); | ||
219 | #endif | ||
220 | |||
221 | /* vio_dev refcount hit 0 */ | 157 | /* vio_dev refcount hit 0 */ |
222 | static void __devinit vio_dev_release(struct device *dev) | 158 | static void __devinit vio_dev_release(struct device *dev) |
223 | { | 159 | { |
224 | DBGENTER(); | 160 | if (release_device_callback) |
225 | 161 | release_device_callback(dev); | |
226 | #ifdef CONFIG_PPC_PSERIES | ||
227 | /* XXX free TCE table */ | ||
228 | of_node_put(dev->platform_data); | ||
229 | #endif | ||
230 | kfree(to_vio_dev(dev)); | 162 | kfree(to_vio_dev(dev)); |
231 | } | 163 | } |
232 | 164 | ||
233 | #ifdef CONFIG_PPC_PSERIES | ||
234 | static ssize_t viodev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) | ||
235 | { | ||
236 | struct device_node *of_node = dev->platform_data; | ||
237 | |||
238 | return sprintf(buf, "%s\n", of_node->full_name); | ||
239 | } | ||
240 | DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL); | ||
241 | #endif | ||
242 | |||
243 | static ssize_t viodev_show_name(struct device *dev, struct device_attribute *attr, char *buf) | 165 | static ssize_t viodev_show_name(struct device *dev, struct device_attribute *attr, char *buf) |
244 | { | 166 | { |
245 | return sprintf(buf, "%s\n", to_vio_dev(dev)->name); | 167 | return sprintf(buf, "%s\n", to_vio_dev(dev)->name); |
@@ -250,8 +172,6 @@ struct vio_dev * __devinit vio_register_device_common( | |||
250 | struct vio_dev *viodev, char *name, char *type, | 172 | struct vio_dev *viodev, char *name, char *type, |
251 | uint32_t unit_address, struct iommu_table *iommu_table) | 173 | uint32_t unit_address, struct iommu_table *iommu_table) |
252 | { | 174 | { |
253 | DBGENTER(); | ||
254 | |||
255 | viodev->name = name; | 175 | viodev->name = name; |
256 | viodev->type = type; | 176 | viodev->type = type; |
257 | viodev->unit_address = unit_address; | 177 | viodev->unit_address = unit_address; |
@@ -272,197 +192,15 @@ struct vio_dev * __devinit vio_register_device_common( | |||
272 | return viodev; | 192 | return viodev; |
273 | } | 193 | } |
274 | 194 | ||
275 | #ifdef CONFIG_PPC_PSERIES | ||
276 | /** | ||
277 | * vio_register_device_node: - Register a new vio device. | ||
278 | * @of_node: The OF node for this device. | ||
279 | * | ||
280 | * Creates and initializes a vio_dev structure from the data in | ||
281 | * of_node (dev.platform_data) and adds it to the list of virtual devices. | ||
282 | * Returns a pointer to the created vio_dev or NULL if node has | ||
283 | * NULL device_type or compatible fields. | ||
284 | */ | ||
285 | struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node) | ||
286 | { | ||
287 | struct vio_dev *viodev; | ||
288 | unsigned int *unit_address; | ||
289 | unsigned int *irq_p; | ||
290 | |||
291 | DBGENTER(); | ||
292 | |||
293 | /* we need the 'device_type' property, in order to match with drivers */ | ||
294 | if ((NULL == of_node->type)) { | ||
295 | printk(KERN_WARNING | ||
296 | "%s: node %s missing 'device_type'\n", __FUNCTION__, | ||
297 | of_node->name ? of_node->name : "<unknown>"); | ||
298 | return NULL; | ||
299 | } | ||
300 | |||
301 | unit_address = (unsigned int *)get_property(of_node, "reg", NULL); | ||
302 | if (!unit_address) { | ||
303 | printk(KERN_WARNING "%s: node %s missing 'reg'\n", __FUNCTION__, | ||
304 | of_node->name ? of_node->name : "<unknown>"); | ||
305 | return NULL; | ||
306 | } | ||
307 | |||
308 | /* allocate a vio_dev for this node */ | ||
309 | viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL); | ||
310 | if (!viodev) { | ||
311 | return NULL; | ||
312 | } | ||
313 | memset(viodev, 0, sizeof(struct vio_dev)); | ||
314 | |||
315 | viodev->dev.platform_data = of_node_get(of_node); | ||
316 | |||
317 | viodev->irq = NO_IRQ; | ||
318 | irq_p = (unsigned int *)get_property(of_node, "interrupts", NULL); | ||
319 | if (irq_p) { | ||
320 | int virq = virt_irq_create_mapping(*irq_p); | ||
321 | if (virq == NO_IRQ) { | ||
322 | printk(KERN_ERR "Unable to allocate interrupt " | ||
323 | "number for %s\n", of_node->full_name); | ||
324 | } else | ||
325 | viodev->irq = irq_offset_up(virq); | ||
326 | } | ||
327 | |||
328 | snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address); | ||
329 | |||
330 | /* register with generic device framework */ | ||
331 | if (vio_register_device_common(viodev, of_node->name, of_node->type, | ||
332 | *unit_address, vio_build_iommu_table(viodev)) | ||
333 | == NULL) { | ||
334 | /* XXX free TCE table */ | ||
335 | kfree(viodev); | ||
336 | return NULL; | ||
337 | } | ||
338 | device_create_file(&viodev->dev, &dev_attr_devspec); | ||
339 | |||
340 | return viodev; | ||
341 | } | ||
342 | EXPORT_SYMBOL(vio_register_device_node); | ||
343 | #endif | ||
344 | |||
345 | void __devinit vio_unregister_device(struct vio_dev *viodev) | 195 | void __devinit vio_unregister_device(struct vio_dev *viodev) |
346 | { | 196 | { |
347 | DBGENTER(); | 197 | if (unregister_device_callback) |
348 | #ifdef CONFIG_PPC_PSERIES | 198 | unregister_device_callback(viodev); |
349 | device_remove_file(&viodev->dev, &dev_attr_devspec); | ||
350 | #endif | ||
351 | device_remove_file(&viodev->dev, &dev_attr_name); | 199 | device_remove_file(&viodev->dev, &dev_attr_name); |
352 | device_unregister(&viodev->dev); | 200 | device_unregister(&viodev->dev); |
353 | } | 201 | } |
354 | EXPORT_SYMBOL(vio_unregister_device); | 202 | EXPORT_SYMBOL(vio_unregister_device); |
355 | 203 | ||
356 | #ifdef CONFIG_PPC_PSERIES | ||
357 | /** | ||
358 | * vio_get_attribute: - get attribute for virtual device | ||
359 | * @vdev: The vio device to get property. | ||
360 | * @which: The property/attribute to be extracted. | ||
361 | * @length: Pointer to length of returned data size (unused if NULL). | ||
362 | * | ||
363 | * Calls prom.c's get_property() to return the value of the | ||
364 | * attribute specified by the preprocessor constant @which | ||
365 | */ | ||
366 | const void * vio_get_attribute(struct vio_dev *vdev, void* which, int* length) | ||
367 | { | ||
368 | return get_property(vdev->dev.platform_data, (char*)which, length); | ||
369 | } | ||
370 | EXPORT_SYMBOL(vio_get_attribute); | ||
371 | |||
372 | /* vio_find_name() - internal because only vio.c knows how we formatted the | ||
373 | * kobject name | ||
374 | * XXX once vio_bus_type.devices is actually used as a kset in | ||
375 | * drivers/base/bus.c, this function should be removed in favor of | ||
376 | * "device_find(kobj_name, &vio_bus_type)" | ||
377 | */ | ||
378 | static struct vio_dev *vio_find_name(const char *kobj_name) | ||
379 | { | ||
380 | struct kobject *found; | ||
381 | |||
382 | found = kset_find_obj(&devices_subsys.kset, kobj_name); | ||
383 | if (!found) | ||
384 | return NULL; | ||
385 | |||
386 | return to_vio_dev(container_of(found, struct device, kobj)); | ||
387 | } | ||
388 | |||
389 | /** | ||
390 | * vio_find_node - find an already-registered vio_dev | ||
391 | * @vnode: device_node of the virtual device we're looking for | ||
392 | */ | ||
393 | struct vio_dev *vio_find_node(struct device_node *vnode) | ||
394 | { | ||
395 | uint32_t *unit_address; | ||
396 | char kobj_name[BUS_ID_SIZE]; | ||
397 | |||
398 | /* construct the kobject name from the device node */ | ||
399 | unit_address = (uint32_t *)get_property(vnode, "reg", NULL); | ||
400 | if (!unit_address) | ||
401 | return NULL; | ||
402 | snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address); | ||
403 | |||
404 | return vio_find_name(kobj_name); | ||
405 | } | ||
406 | EXPORT_SYMBOL(vio_find_node); | ||
407 | |||
408 | /** | ||
409 | * vio_build_iommu_table: - gets the dma information from OF and builds the TCE tree. | ||
410 | * @dev: the virtual device. | ||
411 | * | ||
412 | * Returns a pointer to the built tce tree, or NULL if it can't | ||
413 | * find property. | ||
414 | */ | ||
415 | static struct iommu_table * vio_build_iommu_table(struct vio_dev *dev) | ||
416 | { | ||
417 | unsigned int *dma_window; | ||
418 | struct iommu_table *newTceTable; | ||
419 | unsigned long offset; | ||
420 | int dma_window_property_size; | ||
421 | |||
422 | dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size); | ||
423 | if(!dma_window) { | ||
424 | return NULL; | ||
425 | } | ||
426 | |||
427 | newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL); | ||
428 | |||
429 | /* There should be some code to extract the phys-encoded offset | ||
430 | using prom_n_addr_cells(). However, according to a comment | ||
431 | on earlier versions, it's always zero, so we don't bother */ | ||
432 | offset = dma_window[1] >> PAGE_SHIFT; | ||
433 | |||
434 | /* TCE table size - measured in tce entries */ | ||
435 | newTceTable->it_size = dma_window[4] >> PAGE_SHIFT; | ||
436 | /* offset for VIO should always be 0 */ | ||
437 | newTceTable->it_offset = offset; | ||
438 | newTceTable->it_busno = 0; | ||
439 | newTceTable->it_index = (unsigned long)dma_window[0]; | ||
440 | newTceTable->it_type = TCE_VB; | ||
441 | |||
442 | return iommu_init_table(newTceTable); | ||
443 | } | ||
444 | |||
445 | int vio_enable_interrupts(struct vio_dev *dev) | ||
446 | { | ||
447 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE); | ||
448 | if (rc != H_Success) { | ||
449 | printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc); | ||
450 | } | ||
451 | return rc; | ||
452 | } | ||
453 | EXPORT_SYMBOL(vio_enable_interrupts); | ||
454 | |||
455 | int vio_disable_interrupts(struct vio_dev *dev) | ||
456 | { | ||
457 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE); | ||
458 | if (rc != H_Success) { | ||
459 | printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc); | ||
460 | } | ||
461 | return rc; | ||
462 | } | ||
463 | EXPORT_SYMBOL(vio_disable_interrupts); | ||
464 | #endif | ||
465 | |||
466 | static dma_addr_t vio_map_single(struct device *dev, void *vaddr, | 204 | static dma_addr_t vio_map_single(struct device *dev, void *vaddr, |
467 | size_t size, enum dma_data_direction direction) | 205 | size_t size, enum dma_data_direction direction) |
468 | { | 206 | { |
@@ -526,8 +264,6 @@ static int vio_bus_match(struct device *dev, struct device_driver *drv) | |||
526 | const struct vio_device_id *ids = vio_drv->id_table; | 264 | const struct vio_device_id *ids = vio_drv->id_table; |
527 | const struct vio_device_id *found_id; | 265 | const struct vio_device_id *found_id; |
528 | 266 | ||
529 | DBGENTER(); | ||
530 | |||
531 | if (!ids) | 267 | if (!ids) |
532 | return 0; | 268 | return 0; |
533 | 269 | ||
diff --git a/include/asm-ppc64/vio.h b/include/asm-ppc64/vio.h index 70644a232210..a82e87c1c5fa 100644 --- a/include/asm-ppc64/vio.h +++ b/include/asm-ppc64/vio.h | |||
@@ -106,6 +106,8 @@ static inline struct vio_dev *to_vio_dev(struct device *dev) | |||
106 | } | 106 | } |
107 | 107 | ||
108 | extern int vio_bus_init(int (*is_match)(const struct vio_device_id *id, | 108 | extern int vio_bus_init(int (*is_match)(const struct vio_device_id *id, |
109 | const struct vio_dev *dev)); | 109 | const struct vio_dev *dev), |
110 | void (*)(struct vio_dev *), | ||
111 | void (*)(struct device *)); | ||
110 | 112 | ||
111 | #endif /* _ASM_VIO_H */ | 113 | #endif /* _ASM_VIO_H */ |