blob: a80f8f1d2e5d9e1062562614dd87b6fe7e5614f7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IBM PowerPC Virtual I/O Infrastructure Support.
3 *
Stephen Rothwell19dbd0f2005-07-12 17:50:26 +10004 * Copyright (c) 2003-2005 IBM Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Dave Engebretsen engebret@us.ibm.com
6 * Santiago Leon santil@us.ibm.com
7 * Hollis Blanchard <hollisb@us.ibm.com>
Stephen Rothwell19dbd0f2005-07-12 17:50:26 +10008 * Stephen Rothwell
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100016#include <linux/types.h>
17#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/init.h>
19#include <linux/console.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/mm.h>
22#include <linux/dma-mapping.h>
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100023#include <linux/kobject.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/iommu.h>
26#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/vio.h>
Olaf Hering143dcec2005-11-08 21:34:36 -080028#include <asm/prom.h>
Stephen Rothwelle10fa772006-04-27 17:18:21 +100029#include <asm/firmware.h>
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100030#include <asm/tce.h>
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100040extern struct subsystem devices_subsys; /* needed for vio_find_name() */
41
42static struct vio_dev vio_bus_device = { /* fake "parent" device */
Stephen Rothwellac5b33c2005-06-21 17:15:54 -070043 .name = vio_bus_device.dev.bus_id,
44 .type = "",
Stephen Rothwellac5b33c2005-06-21 17:15:54 -070045 .dev.bus_id = "vio",
46 .dev.bus = &vio_bus_type,
47};
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100049#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
Anton Blanchardca1588e2006-06-10 20:58:08 +100063 if (!iommu_init_table(&veth_iommu_table, -1))
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100064 printk("Virtual Bus VETH TCE table failed.\n");
Anton Blanchardca1588e2006-06-10 20:58:08 +100065 if (!iommu_init_table(&vio_iommu_table, -1))
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100066 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)) {
Stephen Rothwell1dc461f2006-05-18 17:21:26 +100074 if (strcmp(dev->type, "network") == 0)
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100075 return &veth_iommu_table;
76 return &vio_iommu_table;
77 } else
78#endif
79 {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100080 const unsigned char *dma_window;
Jeremy Kerr4c76e0b2006-05-18 18:06:37 +100081 struct iommu_table *tbl;
82 unsigned long offset, size;
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100083
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +110084 dma_window = get_property(dev->dev.archdata.of_node,
85 "ibm,my-dma-window", NULL);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100086 if (!dma_window)
87 return NULL;
88
Jeremy Kerr4c76e0b2006-05-18 18:06:37 +100089 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100090
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +110091 of_parse_dma_window(dev->dev.archdata.of_node, dma_window,
92 &tbl->it_index, &offset, &size);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100093
94 /* TCE table size - measured in tce entries */
Linas Vepstas5d2efba2006-10-30 16:15:59 +110095 tbl->it_size = size >> IOMMU_PAGE_SHIFT;
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100096 /* offset for VIO should always be 0 */
Linas Vepstas5d2efba2006-10-30 16:15:59 +110097 tbl->it_offset = offset >> IOMMU_PAGE_SHIFT;
Jeremy Kerr4c76e0b2006-05-18 18:06:37 +100098 tbl->it_busno = 0;
99 tbl->it_type = TCE_VB;
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000100
Anton Blanchardca1588e2006-06-10 20:58:08 +1000101 return iommu_init_table(tbl, -1);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000102 }
103}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000105/**
106 * vio_match_device: - Tell if a VIO device has a matching
107 * VIO device id structure.
108 * @ids: array of VIO device id structures to search in
109 * @dev: the VIO device structure to match against
110 *
111 * Used by a driver to check whether a VIO device present in the
112 * system is in its list of supported devices. Returns the matching
113 * vio_device_id structure or NULL if there is no match.
114 */
115static const struct vio_device_id *vio_match_device(
116 const struct vio_device_id *ids, const struct vio_dev *dev)
117{
118 while (ids->type[0] != '\0') {
Stephen Rothwelldd721ff2006-04-27 17:21:46 +1000119 if ((strncmp(dev->type, ids->type, strlen(ids->type)) == 0) &&
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100120 device_is_compatible(dev->dev.archdata.of_node,
121 ids->compat))
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000122 return ids;
123 ids++;
124 }
125 return NULL;
126}
127
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000128/*
129 * Convert from struct device to struct vio_dev and pass to driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 * dev->driver has already been set by generic code because vio_bus_match
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000131 * succeeded.
132 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static int vio_bus_probe(struct device *dev)
134{
135 struct vio_dev *viodev = to_vio_dev(dev);
136 struct vio_driver *viodrv = to_vio_driver(dev->driver);
137 const struct vio_device_id *id;
138 int error = -ENODEV;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (!viodrv->probe)
141 return error;
142
143 id = vio_match_device(viodrv->id_table, viodev);
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000144 if (id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 error = viodrv->probe(viodev, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 return error;
148}
149
150/* convert from struct device to struct vio_dev and pass to driver. */
151static int vio_bus_remove(struct device *dev)
152{
153 struct vio_dev *viodev = to_vio_dev(dev);
154 struct vio_driver *viodrv = to_vio_driver(dev->driver);
155
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000156 if (viodrv->remove)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return viodrv->remove(viodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 /* driver can't remove */
160 return 1;
161}
162
Stephen Rothwell34060102005-10-24 17:40:23 +1000163/* convert from struct device to struct vio_dev and pass to driver. */
164static void vio_bus_shutdown(struct device *dev)
165{
166 struct vio_dev *viodev = to_vio_dev(dev);
167 struct vio_driver *viodrv = to_vio_driver(dev->driver);
168
Russell King2f53a802006-01-05 14:36:47 +0000169 if (dev->driver && viodrv->shutdown)
Stephen Rothwell34060102005-10-24 17:40:23 +1000170 viodrv->shutdown(viodev);
171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/**
174 * vio_register_driver: - Register a new vio driver
175 * @drv: The vio_driver structure to be registered.
176 */
177int vio_register_driver(struct vio_driver *viodrv)
178{
179 printk(KERN_DEBUG "%s: driver %s registering\n", __FUNCTION__,
Stephen Rothwell6fdf5392005-10-24 14:53:21 +1000180 viodrv->driver.name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182 /* fill in 'struct driver' fields */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 viodrv->driver.bus = &vio_bus_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 return driver_register(&viodrv->driver);
186}
187EXPORT_SYMBOL(vio_register_driver);
188
189/**
190 * vio_unregister_driver - Remove registration of vio driver.
191 * @driver: The vio_driver struct to be removed form registration
192 */
193void vio_unregister_driver(struct vio_driver *viodrv)
194{
195 driver_unregister(&viodrv->driver);
196}
197EXPORT_SYMBOL(vio_unregister_driver);
198
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000199/* vio_dev refcount hit 0 */
200static void __devinit vio_dev_release(struct device *dev)
201{
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100202 if (dev->archdata.of_node) {
203 /* XXX should free TCE table */
204 of_node_put(dev->archdata.of_node);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000205 }
206 kfree(to_vio_dev(dev));
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/**
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000210 * vio_register_device_node: - Register a new vio device.
211 * @of_node: The OF node for this device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 *
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000213 * Creates and initializes a vio_dev structure from the data in
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100214 * of_node and adds it to the list of virtual devices.
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000215 * Returns a pointer to the created vio_dev or NULL if node has
216 * NULL device_type or compatible fields.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 */
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000218struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000220 struct vio_dev *viodev;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000221 const unsigned int *unit_address;
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000222
223 /* we need the 'device_type' property, in order to match with drivers */
224 if (of_node->type == NULL) {
225 printk(KERN_WARNING "%s: node %s missing 'device_type'\n",
226 __FUNCTION__,
227 of_node->name ? of_node->name : "<unknown>");
228 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000230
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000231 unit_address = get_property(of_node, "reg", NULL);
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000232 if (unit_address == NULL) {
233 printk(KERN_WARNING "%s: node %s missing 'reg'\n",
234 __FUNCTION__,
235 of_node->name ? of_node->name : "<unknown>");
236 return NULL;
237 }
238
239 /* allocate a vio_dev for this node */
240 viodev = kzalloc(sizeof(struct vio_dev), GFP_KERNEL);
241 if (viodev == NULL)
242 return NULL;
243
Benjamin Herrenschmidt0ebfff12006-07-03 21:36:01 +1000244 viodev->irq = irq_of_parse_and_map(of_node, 0);
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000245
246 snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address);
247 viodev->name = of_node->name;
248 viodev->type = of_node->type;
249 viodev->unit_address = *unit_address;
250 if (firmware_has_feature(FW_FEATURE_ISERIES)) {
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000251 unit_address = get_property(of_node,
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000252 "linux,unit_address", NULL);
253 if (unit_address != NULL)
254 viodev->unit_address = *unit_address;
255 }
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100256 viodev->dev.archdata.of_node = of_node_get(of_node);
257 viodev->dev.archdata.dma_ops = &dma_iommu_ops;
258 viodev->dev.archdata.dma_data = vio_build_iommu_table(viodev);
259 viodev->dev.archdata.numa_node = of_node_to_nid(of_node);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000260
261 /* init generic 'struct device' fields: */
262 viodev->dev.parent = &vio_bus_device.dev;
263 viodev->dev.bus = &vio_bus_type;
264 viodev->dev.release = vio_dev_release;
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000265
266 /* register with generic device framework */
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000267 if (device_register(&viodev->dev)) {
268 printk(KERN_ERR "%s: failed to register device %s\n",
269 __FUNCTION__, viodev->dev.bus_id);
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000270 /* XXX free TCE table */
271 kfree(viodev);
272 return NULL;
273 }
274
275 return viodev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000277EXPORT_SYMBOL(vio_register_device_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279/**
280 * vio_bus_init: - Initialize the virtual IO bus
281 */
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000282static int __init vio_bus_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 int err;
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000285 struct device_node *node_vroot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000287#ifdef CONFIG_PPC_ISERIES
288 if (firmware_has_feature(FW_FEATURE_ISERIES)) {
289 iommu_vio_init();
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100290 vio_bus_device.dev.archdata.dma_ops = &dma_iommu_ops;
291 vio_bus_device.dev.archdata.dma_data = &vio_iommu_table;
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000292 iSeries_vio_dev = &vio_bus_device.dev;
293 }
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100294#endif /* CONFIG_PPC_ISERIES */
Stephen Rothwell63122362005-07-12 17:45:27 +1000295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 err = bus_register(&vio_bus_type);
297 if (err) {
298 printk(KERN_ERR "failed to register VIO bus\n");
299 return err;
300 }
301
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000302 /*
303 * The fake parent of all vio devices, just to give us
Stephen Rothwell3e494c82005-07-12 17:40:17 +1000304 * a nice directory
305 */
Stephen Rothwellac5b33c2005-06-21 17:15:54 -0700306 err = device_register(&vio_bus_device.dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (err) {
Stephen Rothwell3e494c82005-07-12 17:40:17 +1000308 printk(KERN_WARNING "%s: device_register returned %i\n",
309 __FUNCTION__, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return err;
311 }
312
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000313 node_vroot = find_devices("vdevice");
314 if (node_vroot) {
315 struct device_node *of_node;
316
317 /*
318 * Create struct vio_devices for each virtual device in
319 * the device tree. Drivers will associate with them later.
320 */
321 for (of_node = node_vroot->child; of_node != NULL;
322 of_node = of_node->sibling) {
323 printk(KERN_DEBUG "%s: processing %p\n",
324 __FUNCTION__, of_node);
325 vio_register_device_node(of_node);
326 }
327 }
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return 0;
330}
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000331__initcall(vio_bus_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000333static ssize_t name_show(struct device *dev,
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000334 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 return sprintf(buf, "%s\n", to_vio_dev(dev)->name);
337}
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000338
339static ssize_t devspec_show(struct device *dev,
340 struct device_attribute *attr, char *buf)
341{
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100342 struct device_node *of_node = dev->archdata.of_node;
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000343
344 return sprintf(buf, "%s\n", of_node ? of_node->full_name : "none");
345}
346
347static struct device_attribute vio_dev_attrs[] = {
348 __ATTR_RO(name),
349 __ATTR_RO(devspec),
350 __ATTR_NULL
351};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353void __devinit vio_unregister_device(struct vio_dev *viodev)
354{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 device_unregister(&viodev->dev);
356}
357EXPORT_SYMBOL(vio_unregister_device);
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359static int vio_bus_match(struct device *dev, struct device_driver *drv)
360{
361 const struct vio_dev *vio_dev = to_vio_dev(dev);
362 struct vio_driver *vio_drv = to_vio_driver(drv);
363 const struct vio_device_id *ids = vio_drv->id_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Stephen Rothwell5c0b4b82005-08-17 16:37:35 +1000365 return (ids != NULL) && (vio_match_device(ids, vio_dev) != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
Olaf Hering143dcec2005-11-08 21:34:36 -0800368static int vio_hotplug(struct device *dev, char **envp, int num_envp,
369 char *buffer, int buffer_size)
370{
371 const struct vio_dev *vio_dev = to_vio_dev(dev);
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100372 struct device_node *dn;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000373 const char *cp;
Olaf Hering143dcec2005-11-08 21:34:36 -0800374 int length;
375
376 if (!num_envp)
377 return -ENOMEM;
378
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100379 dn = dev->archdata.of_node;
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000380 if (!dn)
Olaf Hering143dcec2005-11-08 21:34:36 -0800381 return -ENODEV;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000382 cp = get_property(dn, "compatible", &length);
Olaf Hering143dcec2005-11-08 21:34:36 -0800383 if (!cp)
384 return -ENODEV;
385
386 envp[0] = buffer;
387 length = scnprintf(buffer, buffer_size, "MODALIAS=vio:T%sS%s",
388 vio_dev->type, cp);
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000389 if ((buffer_size - length) <= 0)
Olaf Hering143dcec2005-11-08 21:34:36 -0800390 return -ENOMEM;
391 envp[1] = NULL;
392 return 0;
393}
394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395struct bus_type vio_bus_type = {
396 .name = "vio",
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000397 .dev_attrs = vio_dev_attrs,
Kay Sievers312c0042005-11-16 09:00:00 +0100398 .uevent = vio_hotplug,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .match = vio_bus_match,
Russell King2f53a802006-01-05 14:36:47 +0000400 .probe = vio_bus_probe,
401 .remove = vio_bus_remove,
402 .shutdown = vio_bus_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403};
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000404
405/**
406 * vio_get_attribute: - get attribute for virtual device
407 * @vdev: The vio device to get property.
408 * @which: The property/attribute to be extracted.
409 * @length: Pointer to length of returned data size (unused if NULL).
410 *
411 * Calls prom.c's get_property() to return the value of the
412 * attribute specified by @which
413*/
414const void *vio_get_attribute(struct vio_dev *vdev, char *which, int *length)
415{
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +1100416 return get_property(vdev->dev.archdata.of_node, which, length);
Stephen Rothwelle10fa772006-04-27 17:18:21 +1000417}
418EXPORT_SYMBOL(vio_get_attribute);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000419
420#ifdef CONFIG_PPC_PSERIES
421/* vio_find_name() - internal because only vio.c knows how we formatted the
422 * kobject name
423 * XXX once vio_bus_type.devices is actually used as a kset in
424 * drivers/base/bus.c, this function should be removed in favor of
425 * "device_find(kobj_name, &vio_bus_type)"
426 */
427static struct vio_dev *vio_find_name(const char *kobj_name)
428{
429 struct kobject *found;
430
431 found = kset_find_obj(&devices_subsys.kset, kobj_name);
432 if (!found)
433 return NULL;
434
435 return to_vio_dev(container_of(found, struct device, kobj));
436}
437
438/**
439 * vio_find_node - find an already-registered vio_dev
440 * @vnode: device_node of the virtual device we're looking for
441 */
442struct vio_dev *vio_find_node(struct device_node *vnode)
443{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000444 const uint32_t *unit_address;
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000445 char kobj_name[BUS_ID_SIZE];
446
447 /* construct the kobject name from the device node */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000448 unit_address = get_property(vnode, "reg", NULL);
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +1000449 if (!unit_address)
450 return NULL;
451 snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address);
452
453 return vio_find_name(kobj_name);
454}
455EXPORT_SYMBOL(vio_find_node);
456
457int vio_enable_interrupts(struct vio_dev *dev)
458{
459 int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE);
460 if (rc != H_SUCCESS)
461 printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc);
462 return rc;
463}
464EXPORT_SYMBOL(vio_enable_interrupts);
465
466int vio_disable_interrupts(struct vio_dev *dev)
467{
468 int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE);
469 if (rc != H_SUCCESS)
470 printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc);
471 return rc;
472}
473EXPORT_SYMBOL(vio_disable_interrupts);
474#endif /* CONFIG_PPC_PSERIES */