2 * IBM PowerPC pSeries Virtual I/O Infrastructure Support.
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>
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.
16 #include <linux/init.h>
17 #include <linux/module.h>
19 #include <linux/kobject.h>
20 #include <asm/iommu.h>
24 #include <asm/hvcall.h>
27 extern struct subsystem devices_subsys; /* needed for vio_find_name() */
30 * vio_match_device_pseries: - Tell if a pSeries VIO device matches a
33 static int vio_match_device_pseries(const struct vio_device_id *id,
34 const struct vio_dev *dev)
36 return (strncmp(dev->type, id->type, strlen(id->type)) == 0) &&
37 device_is_compatible(dev->dev.platform_data, id->compat);
41 * vio_build_iommu_table: - gets the dma information from OF and
42 * builds the TCE tree.
43 * @dev: the virtual device.
45 * Returns a pointer to the built tce tree, or NULL if it can't
48 static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
50 unsigned int *dma_window;
51 struct iommu_table *newTceTable;
53 int dma_window_property_size;
55 dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size);
60 newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
62 /* There should be some code to extract the phys-encoded offset
63 using prom_n_addr_cells(). However, according to a comment
64 on earlier versions, it's always zero, so we don't bother */
65 offset = dma_window[1] >> PAGE_SHIFT;
67 /* TCE table size - measured in tce entries */
68 newTceTable->it_size = dma_window[4] >> PAGE_SHIFT;
69 /* offset for VIO should always be 0 */
70 newTceTable->it_offset = offset;
71 newTceTable->it_busno = 0;
72 newTceTable->it_index = (unsigned long)dma_window[0];
73 newTceTable->it_type = TCE_VB;
75 return iommu_init_table(newTceTable);
78 static struct vio_bus_ops vio_bus_ops_pseries = {
79 .match = vio_match_device_pseries,
80 .build_iommu_table = vio_build_iommu_table,
84 * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus
86 static int __init vio_bus_init_pseries(void)
88 return vio_bus_init(&vio_bus_ops_pseries);
91 __initcall(vio_bus_init_pseries);
93 /* vio_find_name() - internal because only vio.c knows how we formatted the
95 * XXX once vio_bus_type.devices is actually used as a kset in
96 * drivers/base/bus.c, this function should be removed in favor of
97 * "device_find(kobj_name, &vio_bus_type)"
99 static struct vio_dev *vio_find_name(const char *kobj_name)
101 struct kobject *found;
103 found = kset_find_obj(&devices_subsys.kset, kobj_name);
107 return to_vio_dev(container_of(found, struct device, kobj));
111 * vio_find_node - find an already-registered vio_dev
112 * @vnode: device_node of the virtual device we're looking for
114 struct vio_dev *vio_find_node(struct device_node *vnode)
116 uint32_t *unit_address;
117 char kobj_name[BUS_ID_SIZE];
119 /* construct the kobject name from the device node */
120 unit_address = (uint32_t *)get_property(vnode, "reg", NULL);
123 snprintf(kobj_name, BUS_ID_SIZE, "%x", *unit_address);
125 return vio_find_name(kobj_name);
127 EXPORT_SYMBOL(vio_find_node);
129 int vio_enable_interrupts(struct vio_dev *dev)
131 int rc = h_vio_signal(dev->unit_address, VIO_IRQ_ENABLE);
133 printk(KERN_ERR "vio: Error 0x%x enabling interrupts\n", rc);
136 EXPORT_SYMBOL(vio_enable_interrupts);
138 int vio_disable_interrupts(struct vio_dev *dev)
140 int rc = h_vio_signal(dev->unit_address, VIO_IRQ_DISABLE);
142 printk(KERN_ERR "vio: Error 0x%x disabling interrupts\n", rc);
145 EXPORT_SYMBOL(vio_disable_interrupts);