diff options
Diffstat (limited to 'arch/powerpc/platforms/pseries/vio.c')
-rw-r--r-- | arch/powerpc/platforms/pseries/vio.c | 147 |
1 files changed, 9 insertions, 138 deletions
diff --git a/arch/powerpc/platforms/pseries/vio.c b/arch/powerpc/platforms/pseries/vio.c index 8e53e04ada8b..b3925aefdac6 100644 --- a/arch/powerpc/platforms/pseries/vio.c +++ b/arch/powerpc/platforms/pseries/vio.c | |||
@@ -26,26 +26,6 @@ | |||
26 | 26 | ||
27 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ | 27 | extern struct subsystem devices_subsys; /* needed for vio_find_name() */ |
28 | 28 | ||
29 | static void probe_bus_pseries(void) | ||
30 | { | ||
31 | struct device_node *node_vroot, *of_node; | ||
32 | |||
33 | node_vroot = find_devices("vdevice"); | ||
34 | if ((node_vroot == NULL) || (node_vroot->child == NULL)) | ||
35 | /* this machine doesn't do virtual IO, and that's ok */ | ||
36 | return; | ||
37 | |||
38 | /* | ||
39 | * Create struct vio_devices for each virtual device in the device tree. | ||
40 | * Drivers will associate with them later. | ||
41 | */ | ||
42 | for (of_node = node_vroot->child; of_node != NULL; | ||
43 | of_node = of_node->sibling) { | ||
44 | printk(KERN_DEBUG "%s: processing %p\n", __FUNCTION__, of_node); | ||
45 | vio_register_device_node(of_node); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | /** | 29 | /** |
50 | * vio_match_device_pseries: - Tell if a pSeries VIO device matches a | 30 | * vio_match_device_pseries: - Tell if a pSeries VIO device matches a |
51 | * vio_device_id | 31 | * vio_device_id |
@@ -57,47 +37,6 @@ static int vio_match_device_pseries(const struct vio_device_id *id, | |||
57 | device_is_compatible(dev->dev.platform_data, id->compat); | 37 | device_is_compatible(dev->dev.platform_data, id->compat); |
58 | } | 38 | } |
59 | 39 | ||
60 | static void vio_release_device_pseries(struct device *dev) | ||
61 | { | ||
62 | /* XXX free TCE table */ | ||
63 | of_node_put(dev->platform_data); | ||
64 | } | ||
65 | |||
66 | static ssize_t viodev_show_devspec(struct device *dev, | ||
67 | struct device_attribute *attr, char *buf) | ||
68 | { | ||
69 | struct device_node *of_node = dev->platform_data; | ||
70 | |||
71 | return sprintf(buf, "%s\n", of_node->full_name); | ||
72 | } | ||
73 | DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL); | ||
74 | |||
75 | static void vio_unregister_device_pseries(struct vio_dev *viodev) | ||
76 | { | ||
77 | device_remove_file(&viodev->dev, &dev_attr_devspec); | ||
78 | } | ||
79 | |||
80 | static struct vio_bus_ops vio_bus_ops_pseries = { | ||
81 | .match = vio_match_device_pseries, | ||
82 | .unregister_device = vio_unregister_device_pseries, | ||
83 | .release_device = vio_release_device_pseries, | ||
84 | }; | ||
85 | |||
86 | /** | ||
87 | * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus | ||
88 | */ | ||
89 | static int __init vio_bus_init_pseries(void) | ||
90 | { | ||
91 | int err; | ||
92 | |||
93 | err = vio_bus_init(&vio_bus_ops_pseries); | ||
94 | if (err == 0) | ||
95 | probe_bus_pseries(); | ||
96 | return err; | ||
97 | } | ||
98 | |||
99 | __initcall(vio_bus_init_pseries); | ||
100 | |||
101 | /** | 40 | /** |
102 | * vio_build_iommu_table: - gets the dma information from OF and | 41 | * vio_build_iommu_table: - gets the dma information from OF and |
103 | * builds the TCE tree. | 42 | * builds the TCE tree. |
@@ -136,88 +75,20 @@ static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev) | |||
136 | return iommu_init_table(newTceTable); | 75 | return iommu_init_table(newTceTable); |
137 | } | 76 | } |
138 | 77 | ||
78 | static struct vio_bus_ops vio_bus_ops_pseries = { | ||
79 | .match = vio_match_device_pseries, | ||
80 | .build_iommu_table = vio_build_iommu_table, | ||
81 | }; | ||
82 | |||
139 | /** | 83 | /** |
140 | * vio_register_device_node: - Register a new vio device. | 84 | * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus |
141 | * @of_node: The OF node for this device. | ||
142 | * | ||
143 | * Creates and initializes a vio_dev structure from the data in | ||
144 | * of_node (dev.platform_data) and adds it to the list of virtual devices. | ||
145 | * Returns a pointer to the created vio_dev or NULL if node has | ||
146 | * NULL device_type or compatible fields. | ||
147 | */ | 85 | */ |
148 | struct vio_dev * __devinit vio_register_device_node(struct device_node *of_node) | 86 | static int __init vio_bus_init_pseries(void) |
149 | { | 87 | { |
150 | struct vio_dev *viodev; | 88 | return vio_bus_init(&vio_bus_ops_pseries); |
151 | unsigned int *unit_address; | ||
152 | unsigned int *irq_p; | ||
153 | |||
154 | /* we need the 'device_type' property, in order to match with drivers */ | ||
155 | if ((NULL == of_node->type)) { | ||
156 | printk(KERN_WARNING | ||
157 | "%s: node %s missing 'device_type'\n", __FUNCTION__, | ||
158 | of_node->name ? of_node->name : "<unknown>"); | ||
159 | return NULL; | ||
160 | } | ||
161 | |||
162 | unit_address = (unsigned int *)get_property(of_node, "reg", NULL); | ||
163 | if (!unit_address) { | ||
164 | printk(KERN_WARNING "%s: node %s missing 'reg'\n", __FUNCTION__, | ||
165 | of_node->name ? of_node->name : "<unknown>"); | ||
166 | return NULL; | ||
167 | } | ||
168 | |||
169 | /* allocate a vio_dev for this node */ | ||
170 | viodev = kmalloc(sizeof(struct vio_dev), GFP_KERNEL); | ||
171 | if (!viodev) { | ||
172 | return NULL; | ||
173 | } | ||
174 | memset(viodev, 0, sizeof(struct vio_dev)); | ||
175 | |||
176 | viodev->dev.platform_data = of_node_get(of_node); | ||
177 | |||
178 | viodev->irq = NO_IRQ; | ||
179 | irq_p = (unsigned int *)get_property(of_node, "interrupts", NULL); | ||
180 | if (irq_p) { | ||
181 | int virq = virt_irq_create_mapping(*irq_p); | ||
182 | if (virq == NO_IRQ) { | ||
183 | printk(KERN_ERR "Unable to allocate interrupt " | ||
184 | "number for %s\n", of_node->full_name); | ||
185 | } else | ||
186 | viodev->irq = irq_offset_up(virq); | ||
187 | } | ||
188 | |||
189 | snprintf(viodev->dev.bus_id, BUS_ID_SIZE, "%x", *unit_address); | ||
190 | viodev->name = of_node->name; | ||
191 | viodev->type = of_node->type; | ||
192 | viodev->unit_address = *unit_address; | ||
193 | viodev->iommu_table = vio_build_iommu_table(viodev); | ||
194 | |||
195 | /* register with generic device framework */ | ||
196 | if (vio_register_device(viodev) == NULL) { | ||
197 | /* XXX free TCE table */ | ||
198 | kfree(viodev); | ||
199 | return NULL; | ||
200 | } | ||
201 | device_create_file(&viodev->dev, &dev_attr_devspec); | ||
202 | |||
203 | return viodev; | ||
204 | } | 89 | } |
205 | EXPORT_SYMBOL(vio_register_device_node); | ||
206 | 90 | ||
207 | /** | 91 | __initcall(vio_bus_init_pseries); |
208 | * vio_get_attribute: - get attribute for virtual device | ||
209 | * @vdev: The vio device to get property. | ||
210 | * @which: The property/attribute to be extracted. | ||
211 | * @length: Pointer to length of returned data size (unused if NULL). | ||
212 | * | ||
213 | * Calls prom.c's get_property() to return the value of the | ||
214 | * attribute specified by the preprocessor constant @which | ||
215 | */ | ||
216 | const void * vio_get_attribute(struct vio_dev *vdev, void* which, int* length) | ||
217 | { | ||
218 | return get_property(vdev->dev.platform_data, (char*)which, length); | ||
219 | } | ||
220 | EXPORT_SYMBOL(vio_get_attribute); | ||
221 | 92 | ||
222 | /* vio_find_name() - internal because only vio.c knows how we formatted the | 93 | /* vio_find_name() - internal because only vio.c knows how we formatted the |
223 | * kobject name | 94 | * kobject name |