diff options
Diffstat (limited to 'arch/ppc64/kernel/vio.c')
-rw-r--r-- | arch/ppc64/kernel/vio.c | 444 |
1 files changed, 35 insertions, 409 deletions
diff --git a/arch/ppc64/kernel/vio.c b/arch/ppc64/kernel/vio.c index 0c0ba71ac0e8..c90e1dd875ce 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,61 +15,30 @@ | |||
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 | #include <asm/iSeries/vio.h> | ||
29 | #include <asm/iSeries/HvTypes.h> | ||
30 | #include <asm/iSeries/HvCallXm.h> | ||
31 | #include <asm/iSeries/HvLpConfig.h> | ||
32 | |||
33 | #define DBGENTER() pr_debug("%s entered\n", __FUNCTION__) | ||
34 | |||
35 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ | ||
36 | 24 | ||
37 | static const struct vio_device_id *vio_match_device( | 25 | static const struct vio_device_id *vio_match_device( |
38 | const struct vio_device_id *, const struct vio_dev *); | 26 | const struct vio_device_id *, const struct vio_dev *); |
39 | 27 | ||
40 | #ifdef CONFIG_PPC_PSERIES | 28 | struct vio_dev vio_bus_device = { /* fake "parent" device */ |
41 | static struct iommu_table *vio_build_iommu_table(struct vio_dev *); | ||
42 | static int vio_num_address_cells; | ||
43 | #endif | ||
44 | #ifdef CONFIG_PPC_ISERIES | ||
45 | static struct iommu_table veth_iommu_table; | ||
46 | static struct iommu_table vio_iommu_table; | ||
47 | #endif | ||
48 | static struct vio_dev vio_bus_device = { /* fake "parent" device */ | ||
49 | .name = vio_bus_device.dev.bus_id, | 29 | .name = vio_bus_device.dev.bus_id, |
50 | .type = "", | 30 | .type = "", |
51 | #ifdef CONFIG_PPC_ISERIES | ||
52 | .iommu_table = &vio_iommu_table, | ||
53 | #endif | ||
54 | .dev.bus_id = "vio", | 31 | .dev.bus_id = "vio", |
55 | .dev.bus = &vio_bus_type, | 32 | .dev.bus = &vio_bus_type, |
56 | }; | 33 | }; |
57 | 34 | ||
58 | #ifdef CONFIG_PPC_ISERIES | 35 | static struct vio_bus_ops vio_bus_ops; |
59 | static struct vio_dev *__init vio_register_device_iseries(char *type, | ||
60 | uint32_t unit_num); | ||
61 | |||
62 | struct device *iSeries_vio_dev = &vio_bus_device.dev; | ||
63 | EXPORT_SYMBOL(iSeries_vio_dev); | ||
64 | |||
65 | #define device_is_compatible(a, b) 1 | ||
66 | 36 | ||
67 | #endif | 37 | /* |
68 | 38 | * Convert from struct device to struct vio_dev and pass to driver. | |
69 | /* convert from struct device to struct vio_dev and pass to driver. | ||
70 | * dev->driver has already been set by generic code because vio_bus_match | 39 | * dev->driver has already been set by generic code because vio_bus_match |
71 | * succeeded. */ | 40 | * succeeded. |
41 | */ | ||
72 | static int vio_bus_probe(struct device *dev) | 42 | static int vio_bus_probe(struct device *dev) |
73 | { | 43 | { |
74 | struct vio_dev *viodev = to_vio_dev(dev); | 44 | struct vio_dev *viodev = to_vio_dev(dev); |
@@ -76,15 +46,12 @@ static int vio_bus_probe(struct device *dev) | |||
76 | const struct vio_device_id *id; | 46 | const struct vio_device_id *id; |
77 | int error = -ENODEV; | 47 | int error = -ENODEV; |
78 | 48 | ||
79 | DBGENTER(); | ||
80 | |||
81 | if (!viodrv->probe) | 49 | if (!viodrv->probe) |
82 | return error; | 50 | return error; |
83 | 51 | ||
84 | id = vio_match_device(viodrv->id_table, viodev); | 52 | id = vio_match_device(viodrv->id_table, viodev); |
85 | if (id) { | 53 | if (id) |
86 | error = viodrv->probe(viodev, id); | 54 | error = viodrv->probe(viodev, id); |
87 | } | ||
88 | 55 | ||
89 | return error; | 56 | return error; |
90 | } | 57 | } |
@@ -95,11 +62,8 @@ static int vio_bus_remove(struct device *dev) | |||
95 | struct vio_dev *viodev = to_vio_dev(dev); | 62 | struct vio_dev *viodev = to_vio_dev(dev); |
96 | struct vio_driver *viodrv = to_vio_driver(dev->driver); | 63 | struct vio_driver *viodrv = to_vio_driver(dev->driver); |
97 | 64 | ||
98 | DBGENTER(); | 65 | if (viodrv->remove) |
99 | |||
100 | if (viodrv->remove) { | ||
101 | return viodrv->remove(viodev); | 66 | return viodrv->remove(viodev); |
102 | } | ||
103 | 67 | ||
104 | /* driver can't remove */ | 68 | /* driver can't remove */ |
105 | return 1; | 69 | return 1; |
@@ -135,193 +99,72 @@ void vio_unregister_driver(struct vio_driver *viodrv) | |||
135 | EXPORT_SYMBOL(vio_unregister_driver); | 99 | EXPORT_SYMBOL(vio_unregister_driver); |
136 | 100 | ||
137 | /** | 101 | /** |
138 | * vio_match_device: - Tell if a VIO device has a matching VIO device id structure. | 102 | * vio_match_device: - Tell if a VIO device has a matching |
139 | * @ids: array of VIO device id structures to search in | 103 | * VIO device id structure. |
140 | * @dev: the VIO device structure to match against | 104 | * @ids: array of VIO device id structures to search in |
105 | * @dev: the VIO device structure to match against | ||
141 | * | 106 | * |
142 | * Used by a driver to check whether a VIO device present in the | 107 | * Used by a driver to check whether a VIO device present in the |
143 | * system is in its list of supported devices. Returns the matching | 108 | * system is in its list of supported devices. Returns the matching |
144 | * vio_device_id structure or NULL if there is no match. | 109 | * vio_device_id structure or NULL if there is no match. |
145 | */ | 110 | */ |
146 | static const struct vio_device_id * vio_match_device(const struct vio_device_id *ids, | 111 | static const struct vio_device_id *vio_match_device( |
147 | const struct vio_dev *dev) | 112 | const struct vio_device_id *ids, const struct vio_dev *dev) |
148 | { | 113 | { |
149 | DBGENTER(); | 114 | while (ids->type[0] != '\0') { |
150 | 115 | if (vio_bus_ops.match(ids, dev)) | |
151 | while (ids->type) { | ||
152 | if ((strncmp(dev->type, ids->type, strlen(ids->type)) == 0) && | ||
153 | device_is_compatible(dev->dev.platform_data, ids->compat)) | ||
154 | return ids; | 116 | return ids; |
155 | ids++; | 117 | ids++; |
156 | } | 118 | } |
157 | return NULL; | 119 | return NULL; |
158 | } | 120 | } |
159 | 121 | ||
160 | #ifdef CONFIG_PPC_ISERIES | ||
161 | void __init iommu_vio_init(void) | ||
162 | { | ||
163 | struct iommu_table *t; | ||
164 | struct iommu_table_cb cb; | ||
165 | unsigned long cbp; | ||
166 | unsigned long itc_entries; | ||
167 | |||
168 | cb.itc_busno = 255; /* Bus 255 is the virtual bus */ | ||
169 | cb.itc_virtbus = 0xff; /* Ask for virtual bus */ | ||
170 | |||
171 | cbp = virt_to_abs(&cb); | ||
172 | HvCallXm_getTceTableParms(cbp); | ||
173 | |||
174 | itc_entries = cb.itc_size * PAGE_SIZE / sizeof(union tce_entry); | ||
175 | veth_iommu_table.it_size = itc_entries / 2; | ||
176 | veth_iommu_table.it_busno = cb.itc_busno; | ||
177 | veth_iommu_table.it_offset = cb.itc_offset; | ||
178 | veth_iommu_table.it_index = cb.itc_index; | ||
179 | veth_iommu_table.it_type = TCE_VB; | ||
180 | veth_iommu_table.it_blocksize = 1; | ||
181 | |||
182 | t = iommu_init_table(&veth_iommu_table); | ||
183 | |||
184 | if (!t) | ||
185 | printk("Virtual Bus VETH TCE table failed.\n"); | ||
186 | |||
187 | vio_iommu_table.it_size = itc_entries - veth_iommu_table.it_size; | ||
188 | vio_iommu_table.it_busno = cb.itc_busno; | ||
189 | vio_iommu_table.it_offset = cb.itc_offset + | ||
190 | veth_iommu_table.it_size; | ||
191 | vio_iommu_table.it_index = cb.itc_index; | ||
192 | vio_iommu_table.it_type = TCE_VB; | ||
193 | vio_iommu_table.it_blocksize = 1; | ||
194 | |||
195 | t = iommu_init_table(&vio_iommu_table); | ||
196 | |||
197 | if (!t) | ||
198 | printk("Virtual Bus VIO TCE table failed.\n"); | ||
199 | } | ||
200 | #endif | ||
201 | |||
202 | #ifdef CONFIG_PPC_PSERIES | ||
203 | static void probe_bus_pseries(void) | ||
204 | { | ||
205 | struct device_node *node_vroot, *of_node; | ||
206 | |||
207 | node_vroot = find_devices("vdevice"); | ||
208 | if ((node_vroot == NULL) || (node_vroot->child == NULL)) | ||
209 | /* this machine doesn't do virtual IO, and that's ok */ | ||
210 | return; | ||
211 | |||
212 | vio_num_address_cells = prom_n_addr_cells(node_vroot->child); | ||
213 | |||
214 | /* | ||
215 | * Create struct vio_devices for each virtual device in the device tree. | ||
216 | * Drivers will associate with them later. | ||
217 | */ | ||
218 | for (of_node = node_vroot->child; of_node != NULL; | ||
219 | of_node = of_node->sibling) { | ||
220 | printk(KERN_DEBUG "%s: processing %p\n", __FUNCTION__, of_node); | ||
221 | vio_register_device_node(of_node); | ||
222 | } | ||
223 | } | ||
224 | #endif | ||
225 | |||
226 | #ifdef CONFIG_PPC_ISERIES | ||
227 | static void probe_bus_iseries(void) | ||
228 | { | ||
229 | HvLpIndexMap vlan_map = HvLpConfig_getVirtualLanIndexMap(); | ||
230 | struct vio_dev *viodev; | ||
231 | int i; | ||
232 | |||
233 | /* there is only one of each of these */ | ||
234 | vio_register_device_iseries("viocons", 0); | ||
235 | vio_register_device_iseries("vscsi", 0); | ||
236 | |||
237 | vlan_map = HvLpConfig_getVirtualLanIndexMap(); | ||
238 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) { | ||
239 | if ((vlan_map & (0x8000 >> i)) == 0) | ||
240 | continue; | ||
241 | viodev = vio_register_device_iseries("vlan", i); | ||
242 | /* veth is special and has it own iommu_table */ | ||
243 | viodev->iommu_table = &veth_iommu_table; | ||
244 | } | ||
245 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++) | ||
246 | vio_register_device_iseries("viodasd", i); | ||
247 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++) | ||
248 | vio_register_device_iseries("viocd", i); | ||
249 | for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++) | ||
250 | vio_register_device_iseries("viotape", i); | ||
251 | } | ||
252 | #endif | ||
253 | |||
254 | /** | 122 | /** |
255 | * vio_bus_init: - Initialize the virtual IO bus | 123 | * vio_bus_init: - Initialize the virtual IO bus |
256 | */ | 124 | */ |
257 | static int __init vio_bus_init(void) | 125 | int __init vio_bus_init(struct vio_bus_ops *ops) |
258 | { | 126 | { |
259 | int err; | 127 | int err; |
260 | 128 | ||
129 | vio_bus_ops = *ops; | ||
130 | |||
261 | err = bus_register(&vio_bus_type); | 131 | err = bus_register(&vio_bus_type); |
262 | if (err) { | 132 | if (err) { |
263 | printk(KERN_ERR "failed to register VIO bus\n"); | 133 | printk(KERN_ERR "failed to register VIO bus\n"); |
264 | return err; | 134 | return err; |
265 | } | 135 | } |
266 | 136 | ||
267 | /* the fake parent of all vio devices, just to give us a nice directory */ | 137 | /* |
138 | * The fake parent of all vio devices, just to give us | ||
139 | * a nice directory | ||
140 | */ | ||
268 | err = device_register(&vio_bus_device.dev); | 141 | err = device_register(&vio_bus_device.dev); |
269 | if (err) { | 142 | if (err) { |
270 | printk(KERN_WARNING "%s: device_register returned %i\n", __FUNCTION__, | 143 | printk(KERN_WARNING "%s: device_register returned %i\n", |
271 | err); | 144 | __FUNCTION__, err); |
272 | return err; | 145 | return err; |
273 | } | 146 | } |
274 | 147 | ||
275 | #ifdef CONFIG_PPC_PSERIES | ||
276 | probe_bus_pseries(); | ||
277 | #endif | ||
278 | #ifdef CONFIG_PPC_ISERIES | ||
279 | probe_bus_iseries(); | ||
280 | #endif | ||
281 | |||
282 | return 0; | 148 | return 0; |
283 | } | 149 | } |
284 | 150 | ||
285 | __initcall(vio_bus_init); | ||
286 | |||
287 | /* vio_dev refcount hit 0 */ | 151 | /* vio_dev refcount hit 0 */ |
288 | static void __devinit vio_dev_release(struct device *dev) | 152 | static void __devinit vio_dev_release(struct device *dev) |
289 | { | 153 | { |
290 | DBGENTER(); | 154 | if (vio_bus_ops.release_device) |
291 | 155 | vio_bus_ops.release_device(dev); | |
292 | #ifdef CONFIG_PPC_PSERIES | ||
293 | /* XXX free TCE table */ | ||
294 | of_node_put(dev->platform_data); | ||
295 | #endif | ||
296 | kfree(to_vio_dev(dev)); | 156 | kfree(to_vio_dev(dev)); |
297 | } | 157 | } |
298 | 158 | ||
299 | #ifdef CONFIG_PPC_PSERIES | 159 | static ssize_t viodev_show_name(struct device *dev, |
300 | static ssize_t viodev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) | 160 | struct device_attribute *attr, char *buf) |
301 | { | ||
302 | struct device_node *of_node = dev->platform_data; | ||
303 | |||
304 | return sprintf(buf, "%s\n", of_node->full_name); | ||
305 | } | ||
306 | DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL); | ||
307 | #endif | ||
308 | |||
309 | static ssize_t viodev_show_name(struct device *dev, struct device_attribute *attr, char *buf) | ||
310 | { | 161 | { |
311 | return sprintf(buf, "%s\n", to_vio_dev(dev)->name); | 162 | return sprintf(buf, "%s\n", to_vio_dev(dev)->name); |
312 | } | 163 | } |
313 | DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL); | 164 | DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL); |
314 | 165 | ||
315 | static struct vio_dev * __devinit vio_register_device_common( | 166 | struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev) |
316 | struct vio_dev *viodev, char *name, char *type, | ||
317 | uint32_t unit_address, struct iommu_table *iommu_table) | ||
318 | { | 167 | { |
319 | DBGENTER(); | ||
320 | |||
321 | viodev->name = name; | ||
322 | viodev->type = type; | ||
323 | viodev->unit_address = unit_address; | ||
324 | viodev->iommu_table = iommu_table; | ||
325 | /* init generic 'struct device' fields: */ | 168 | /* init generic 'struct device' fields: */ |
326 | viodev->dev.parent = &vio_bus_device.dev; | 169 | viodev->dev.parent = &vio_bus_device.dev; |
327 | viodev->dev.bus = &vio_bus_type; | 170 | viodev->dev.bus = &vio_bus_type; |
@@ -338,222 +181,15 @@ static struct vio_dev * __devinit vio_register_device_common( | |||
338 | return viodev; | 181 | return viodev; |
339 | } | 182 | } |
340 | 183 | ||
341 | #ifdef CONFIG_PPC_PSERIES | ||
342 | /** | ||
343 | * vio_register_device_node: - Register a new vio device. | ||
344 | * @of_node: The OF node for this device. | ||
345 | * | ||
346 | * Creates and initializes a vio_dev structure from the data in | ||
347 | * of_node (dev.platform_data) and adds it to the list of virtual devices. | ||
348 | * Returns a pointer to the created vio_dev or NULL if node has | ||
349 | * NULL device_type or compatible fields. | ||
350 | */ | ||
351 | struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node) | ||
352 | { | ||
353 | struct vio_dev *viodev; | ||
354 | unsigned int *unit_address; | ||
355 | unsigned int *irq_p; | ||
356 | |||
357 | DBGENTER(); | ||
358 | |||
359 | /* we need the 'device_type' property, in order to match with drivers */ | ||
360 | if ((NULL == of_node->type)) { | ||
361 | printk(KERN_WARNING | ||
362 | "%s: node %s missing 'device_type'\n", __FUNCTION__, | ||
363 | of_node->name ? of_node->name : "<unknown>"); | ||
364 | return NULL; | ||
365 | } | ||
366 | |||
367 | unit_address = (unsigned int *)get_property(of_node, "reg", NULL); | ||
368 | if (!unit_address) { | ||
369 | printk(KERN_WARNING "%s: node %s missing 'reg'\n", __FUNCTION__, | ||
370 | of_node->name ? of_node->name : "<unknown>"); | ||
371 | return NULL; | ||
372 | } | ||
373 | |||
374 | /* allocate a vio_dev for this node */ | ||
375 | viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL); | ||
376 | if (!viodev) { | ||
377 | return NULL; | ||
378 | } | ||
379 | memset(viodev, 0, sizeof(struct vio_dev)); | ||
380 | |||
381 | viodev->dev.platform_data = of_node_get(of_node); | ||
382 | |||
383 | viodev->irq = NO_IRQ; | ||
384 | irq_p = (unsigned int *)get_property(of_node, "interrupts", NULL); | ||
385 | if (irq_p) { | ||
386 | int virq = virt_irq_create_mapping(*irq_p); | ||
387 | if (virq == NO_IRQ) { | ||
388 | printk(KERN_ERR "Unable to allocate interrupt " | ||
389 | "number for %s\n", of_node->full_name); | ||
390 | } else | ||
391 | viodev->irq = irq_offset_up(virq); | ||
392 | } | ||
393 | |||
394 | snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address); | ||
395 | |||
396 | /* register with generic device framework */ | ||
397 | if (vio_register_device_common(viodev, of_node->name, of_node->type, | ||
398 | *unit_address, vio_build_iommu_table(viodev)) | ||
399 | == NULL) { | ||
400 | /* XXX free TCE table */ | ||
401 | kfree(viodev); | ||
402 | return NULL; | ||
403 | } | ||
404 | device_create_file(&viodev->dev, &dev_attr_devspec); | ||
405 | |||
406 | return viodev; | ||
407 | } | ||
408 | EXPORT_SYMBOL(vio_register_device_node); | ||
409 | #endif | ||
410 | |||
411 | #ifdef CONFIG_PPC_ISERIES | ||
412 | /** | ||
413 | * vio_register_device: - Register a new vio device. | ||
414 | * @voidev: The device to register. | ||
415 | */ | ||
416 | static struct vio_dev *__init vio_register_device_iseries(char *type, | ||
417 | uint32_t unit_num) | ||
418 | { | ||
419 | struct vio_dev *viodev; | ||
420 | |||
421 | DBGENTER(); | ||
422 | |||
423 | /* allocate a vio_dev for this node */ | ||
424 | viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL); | ||
425 | if (!viodev) | ||
426 | return NULL; | ||
427 | memset(viodev, 0, sizeof(struct vio_dev)); | ||
428 | |||
429 | snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%s%d", type, unit_num); | ||
430 | |||
431 | return vio_register_device_common(viodev, viodev->dev.bus_id, type, | ||
432 | unit_num, &vio_iommu_table); | ||
433 | } | ||
434 | #endif | ||
435 | |||
436 | void __devinit vio_unregister_device(struct vio_dev *viodev) | 184 | void __devinit vio_unregister_device(struct vio_dev *viodev) |
437 | { | 185 | { |
438 | DBGENTER(); | 186 | if (vio_bus_ops.unregister_device) |
439 | #ifdef CONFIG_PPC_PSERIES | 187 | vio_bus_ops.unregister_device(viodev); |
440 | device_remove_file(&viodev->dev, &dev_attr_devspec); | ||
441 | #endif | ||
442 | device_remove_file(&viodev->dev, &dev_attr_name); | 188 | device_remove_file(&viodev->dev, &dev_attr_name); |
443 | device_unregister(&viodev->dev); | 189 | device_unregister(&viodev->dev); |
444 | } | 190 | } |
445 | EXPORT_SYMBOL(vio_unregister_device); | 191 | EXPORT_SYMBOL(vio_unregister_device); |
446 | 192 | ||
447 | #ifdef CONFIG_PPC_PSERIES | ||
448 | /** | ||
449 | * vio_get_attribute: - get attribute for virtual device | ||
450 | * @vdev: The vio device to get property. | ||
451 | * @which: The property/attribute to be extracted. | ||
452 | * @length: Pointer to length of returned data size (unused if NULL). | ||
453 | * | ||
454 | * Calls prom.c's get_property() to return the value of the | ||
455 | * attribute specified by the preprocessor constant @which | ||
456 | */ | ||
457 | const void * vio_get_attribute(struct vio_dev *vdev, void* which, int* length) | ||
458 | { | ||
459 | return get_property(vdev->dev.platform_data, (char*)which, length); | ||
460 | } | ||
461 | EXPORT_SYMBOL(vio_get_attribute); | ||
462 | |||
463 | /* vio_find_name() - internal because only vio.c knows how we formatted the | ||
464 | * kobject name | ||
465 | * XXX once vio_bus_type.devices is actually used as a kset in | ||
466 | * drivers/base/bus.c, this function should be removed in favor of | ||
467 | * "device_find(kobj_name, &vio_bus_type)" | ||
468 | */ | ||
469 | static struct vio_dev *vio_find_name(const char *kobj_name) | ||
470 | { | ||
471 | struct kobject *found; | ||
472 | |||
473 | found = kset_find_obj(&devices_subsys.kset, kobj_name); | ||
474 | if (!found) | ||
475 | return NULL; | ||
476 | |||
477 | return to_vio_dev(container_of(found, struct device, kobj)); | ||
478 | } | ||
479 | |||
480 | /** | ||
481 | * vio_find_node - find an already-registered vio_dev | ||
482 | * @vnode: device_node of the virtual device we're looking for | ||
483 | */ | ||
484 | struct vio_dev *vio_find_node(struct device_node *vnode) | ||
485 | { | ||
486 | uint32_t *unit_address; | ||
487 | char kobj_name[BUS_ID_SIZE]; | ||
488 | |||
489 | /* construct the kobject name from the device node */ | ||
490 | unit_address = (uint32_t *)get_property(vnode, "reg", NULL); | ||
491 | if (!unit_address) | ||
492 | return NULL; | ||
493 | snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address); | ||
494 | |||
495 | return vio_find_name(kobj_name); | ||
496 | } | ||
497 | EXPORT_SYMBOL(vio_find_node); | ||
498 | |||
499 | /** | ||
500 | * vio_build_iommu_table: - gets the dma information from OF and builds the TCE tree. | ||
501 | * @dev: the virtual device. | ||
502 | * | ||
503 | * Returns a pointer to the built tce tree, or NULL if it can't | ||
504 | * find property. | ||
505 | */ | ||
506 | static struct iommu_table * vio_build_iommu_table(struct vio_dev *dev) | ||
507 | { | ||
508 | unsigned int *dma_window; | ||
509 | struct iommu_table *newTceTable; | ||
510 | unsigned long offset; | ||
511 | int dma_window_property_size; | ||
512 | |||
513 | dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size); | ||
514 | if(!dma_window) { | ||
515 | return NULL; | ||
516 | } | ||
517 | |||
518 | newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL); | ||
519 | |||
520 | /* There should be some code to extract the phys-encoded offset | ||
521 | using prom_n_addr_cells(). However, according to a comment | ||
522 | on earlier versions, it's always zero, so we don't bother */ | ||
523 | offset = dma_window[1] >> PAGE_SHIFT; | ||
524 | |||
525 | /* TCE table size - measured in tce entries */ | ||
526 | newTceTable->it_size = dma_window[4] >> PAGE_SHIFT; | ||
527 | /* offset for VIO should always be 0 */ | ||
528 | newTceTable->it_offset = offset; | ||
529 | newTceTable->it_busno = 0; | ||
530 | newTceTable->it_index = (unsigned long)dma_window[0]; | ||
531 | newTceTable->it_type = TCE_VB; | ||
532 | |||
533 | return iommu_init_table(newTceTable); | ||
534 | } | ||
535 | |||
536 | int vio_enable_interrupts(struct vio_dev *dev) | ||
537 | { | ||
538 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE); | ||
539 | if (rc != H_Success) { | ||
540 | printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc); | ||
541 | } | ||
542 | return rc; | ||
543 | } | ||
544 | EXPORT_SYMBOL(vio_enable_interrupts); | ||
545 | |||
546 | int vio_disable_interrupts(struct vio_dev *dev) | ||
547 | { | ||
548 | int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE); | ||
549 | if (rc != H_Success) { | ||
550 | printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc); | ||
551 | } | ||
552 | return rc; | ||
553 | } | ||
554 | EXPORT_SYMBOL(vio_disable_interrupts); | ||
555 | #endif | ||
556 | |||
557 | static dma_addr_t vio_map_single(struct device *dev, void *vaddr, | 193 | static dma_addr_t vio_map_single(struct device *dev, void *vaddr, |
558 | size_t size, enum dma_data_direction direction) | 194 | size_t size, enum dma_data_direction direction) |
559 | { | 195 | { |
@@ -615,18 +251,8 @@ static int vio_bus_match(struct device *dev, struct device_driver *drv) | |||
615 | const struct vio_dev *vio_dev = to_vio_dev(dev); | 251 | const struct vio_dev *vio_dev = to_vio_dev(dev); |
616 | struct vio_driver *vio_drv = to_vio_driver(drv); | 252 | struct vio_driver *vio_drv = to_vio_driver(drv); |
617 | const struct vio_device_id *ids = vio_drv->id_table; | 253 | const struct vio_device_id *ids = vio_drv->id_table; |
618 | const struct vio_device_id *found_id; | ||
619 | |||
620 | DBGENTER(); | ||
621 | 254 | ||
622 | if (!ids) | 255 | return (ids != NULL) && (vio_match_device(ids, vio_dev) != NULL); |
623 | return 0; | ||
624 | |||
625 | found_id = vio_match_device(ids, vio_dev); | ||
626 | if (found_id) | ||
627 | return 1; | ||
628 | |||
629 | return 0; | ||
630 | } | 256 | } |
631 | 257 | ||
632 | struct bus_type vio_bus_type = { | 258 | struct bus_type vio_bus_type = { |