aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sbus
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2006-06-23 18:55:45 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-06-24 02:15:50 -0400
commit576c352e89e57cfa6c9f493e549d10d86f60a0cf (patch)
tree4f393f05beef86284a037b106bfb353ff0d72c8a /drivers/sbus
parentfd5314311634245172d40ccb418d89dac91d6ad6 (diff)
[SBUS]: Rewrite and plug into of_device framework.
I severely apologize, I was still learning how to program in C when I wrote this stuff 10 years ago... Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/sbus')
-rw-r--r--drivers/sbus/sbus.c449
1 files changed, 139 insertions, 310 deletions
diff --git a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
index 6e9b2608202b..387a6aa8c020 100644
--- a/drivers/sbus/sbus.c
+++ b/drivers/sbus/sbus.c
@@ -13,32 +13,29 @@
13#include <asm/sbus.h> 13#include <asm/sbus.h>
14#include <asm/dma.h> 14#include <asm/dma.h>
15#include <asm/oplib.h> 15#include <asm/oplib.h>
16#include <asm/prom.h>
17#include <asm/of_device.h>
16#include <asm/bpp.h> 18#include <asm/bpp.h>
17#include <asm/irq.h> 19#include <asm/irq.h>
18 20
19struct sbus_bus *sbus_root; 21struct sbus_bus *sbus_root;
20 22
21#ifdef CONFIG_PCI 23static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
22extern int pcic_present(void);
23#endif
24
25static void __init fill_sbus_device(int prom_node, struct sbus_dev *sdev)
26{ 24{
27 unsigned long address, base; 25 unsigned long base;
26 void *pval;
28 int len; 27 int len;
29 28
30 sdev->prom_node = prom_node; 29 sdev->prom_node = dp->node;
31 prom_getstring(prom_node, "name", 30 strcpy(sdev->prom_name, dp->name);
32 sdev->prom_name, sizeof(sdev->prom_name)); 31
33 address = prom_getint(prom_node, "address"); 32 pval = of_get_property(dp, "reg", &len);
34 len = prom_getproperty(prom_node, "reg",
35 (char *) sdev->reg_addrs,
36 sizeof(sdev->reg_addrs));
37 sdev->num_registers = 0; 33 sdev->num_registers = 0;
38 if (len != -1) { 34 if (pval) {
35 memcpy(sdev->reg_addrs, pval, len);
36
39 sdev->num_registers = 37 sdev->num_registers =
40 len / sizeof(struct linux_prom_registers); 38 len / sizeof(struct linux_prom_registers);
41 sdev->ranges_applied = 0;
42 39
43 base = (unsigned long) sdev->reg_addrs[0].phys_addr; 40 base = (unsigned long) sdev->reg_addrs[0].phys_addr;
44 41
@@ -49,97 +46,43 @@ static void __init fill_sbus_device(int prom_node, struct sbus_dev *sdev)
49 sdev->slot = sdev->reg_addrs[0].which_io; 46 sdev->slot = sdev->reg_addrs[0].which_io;
50 } 47 }
51 48
52 len = prom_getproperty(prom_node, "ranges", 49 pval = of_get_property(dp, "ranges", &len);
53 (char *)sdev->device_ranges,
54 sizeof(sdev->device_ranges));
55 sdev->num_device_ranges = 0; 50 sdev->num_device_ranges = 0;
56 if (len != -1) 51 if (pval) {
52 memcpy(sdev->device_ranges, pval, len);
57 sdev->num_device_ranges = 53 sdev->num_device_ranges =
58 len / sizeof(struct linux_prom_ranges); 54 len / sizeof(struct linux_prom_ranges);
55 }
59 56
60 sbus_fill_device_irq(sdev); 57 sbus_fill_device_irq(sdev);
61}
62 58
63/* This routine gets called from whoever needs the sbus first, to scan 59 sdev->ofdev.node = dp;
64 * the SBus device tree. Currently it just prints out the devices 60 if (sdev->parent)
65 * found on the bus and builds trees of SBUS structs and attached 61 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
66 * devices. 62 else
67 */ 63 sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
68 64 sdev->ofdev.dev.bus = &sbus_bus_type;
69extern void iommu_init(int iommu_node, struct sbus_bus *sbus); 65 strcpy(sdev->ofdev.dev.bus_id, dp->path_component_name);
70extern void iounit_init(int sbi_node, int iounit_node, struct sbus_bus *sbus); 66
71void sun4_init(void); 67 if (of_device_register(&sdev->ofdev) != 0)
72#ifdef CONFIG_SUN_AUXIO 68 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
73extern void auxio_probe(void); 69 sdev->ofdev.dev.bus_id);
74#endif
75
76static void __init sbus_do_child_siblings(int start_node,
77 struct sbus_dev *child,
78 struct sbus_dev *parent,
79 struct sbus_bus *sbus)
80{
81 struct sbus_dev *this_dev = child;
82 int this_node = start_node;
83
84 /* Child already filled in, just need to traverse siblings. */
85 child->child = NULL;
86 child->parent = parent;
87 while((this_node = prom_getsibling(this_node)) != 0) {
88 this_dev->next = kmalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
89 this_dev = this_dev->next;
90 this_dev->next = NULL;
91 this_dev->parent = parent;
92
93 this_dev->bus = sbus;
94 fill_sbus_device(this_node, this_dev);
95
96 if(prom_getchild(this_node)) {
97 this_dev->child = kmalloc(sizeof(struct sbus_dev),
98 GFP_ATOMIC);
99 this_dev->child->bus = sbus;
100 this_dev->child->next = NULL;
101 fill_sbus_device(prom_getchild(this_node), this_dev->child);
102 sbus_do_child_siblings(prom_getchild(this_node),
103 this_dev->child, this_dev, sbus);
104 } else {
105 this_dev->child = NULL;
106 }
107 }
108} 70}
109 71
110/* 72static void __init sbus_bus_ranges_init(struct device_node *dp, struct sbus_bus *sbus)
111 * XXX This functions appears to be a distorted version of
112 * prom_sbus_ranges_init(), with all sun4d stuff cut away.
113 * Ask DaveM what is going on here, how is sun4d supposed to work... XXX
114 */
115/* added back sun4d patch from Thomas Bogendoerfer - should be OK (crn) */
116
117static void __init sbus_bus_ranges_init(int parent_node, struct sbus_bus *sbus)
118{ 73{
74 void *pval;
119 int len; 75 int len;
120 76
121 len = prom_getproperty(sbus->prom_node, "ranges", 77 pval = of_get_property(dp, "ranges", &len);
122 (char *) sbus->sbus_ranges, 78 sbus->num_sbus_ranges = 0;
123 sizeof(sbus->sbus_ranges)); 79 if (pval) {
124 if (len == -1 || len == 0) { 80 memcpy(sbus->sbus_ranges, pval, len);
125 sbus->num_sbus_ranges = 0; 81 sbus->num_sbus_ranges =
126 return; 82 len / sizeof(struct linux_prom_ranges);
127 } 83
128 sbus->num_sbus_ranges = len / sizeof(struct linux_prom_ranges); 84 sbus_arch_bus_ranges_init(dp->parent, sbus);
129#ifdef CONFIG_SPARC32
130 if (sparc_cpu_model == sun4d) {
131 struct linux_prom_ranges iounit_ranges[PROMREG_MAX];
132 int num_iounit_ranges;
133
134 len = prom_getproperty(parent_node, "ranges",
135 (char *) iounit_ranges,
136 sizeof (iounit_ranges));
137 if (len != -1) {
138 num_iounit_ranges = (len/sizeof(struct linux_prom_ranges));
139 prom_adjust_ranges (sbus->sbus_ranges, sbus->num_sbus_ranges, iounit_ranges, num_iounit_ranges);
140 }
141 } 85 }
142#endif
143} 86}
144 87
145static void __init __apply_ranges_to_regs(struct linux_prom_ranges *ranges, 88static void __init __apply_ranges_to_regs(struct linux_prom_ranges *ranges,
@@ -217,241 +160,127 @@ static void __init sbus_fixup_all_regs(struct sbus_dev *first_sdev)
217 } 160 }
218} 161}
219 162
220extern void register_proc_sparc_ioport(void); 163/* We preserve the "probe order" of these bus and device lists to give
221extern void firetruck_init(void); 164 * the same ordering as the old code.
165 */
166static void __init sbus_insert(struct sbus_bus *sbus, struct sbus_bus **root)
167{
168 while (*root)
169 root = &(*root)->next;
170 *root = sbus;
171 sbus->next = NULL;
172}
222 173
223#ifdef CONFIG_SUN4 174static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root)
224extern void sun4_dvma_init(void); 175{
225#endif 176 while (*root)
177 root = &(*root)->next;
178 *root = sdev;
179 sdev->next = NULL;
180}
226 181
227static int __init sbus_init(void) 182static void __init walk_children(struct device_node *dp, struct sbus_dev *parent, struct sbus_bus *sbus)
228{ 183{
229 int nd, this_sbus, sbus_devs, topnd, iommund; 184 dp = dp->child;
230 unsigned int sbus_clock; 185 while (dp) {
231 struct sbus_bus *sbus; 186 struct sbus_dev *sdev;
232 struct sbus_dev *this_dev;
233 int num_sbus = 0; /* How many did we find? */
234 187
235#ifdef CONFIG_SPARC32 188 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
236 register_proc_sparc_ioport(); 189 if (sdev) {
237#endif 190 sdev_insert(sdev, &parent->child);
238 191
239#ifdef CONFIG_SUN4 192 sdev->bus = sbus;
240 sun4_dvma_init(); 193 sdev->parent = parent;
241 return 0; 194
242#endif 195 fill_sbus_device(dp, sdev);
243 196
244 topnd = prom_getchild(prom_root_node); 197 walk_children(dp, sdev, sbus);
245
246 /* Finding the first sbus is a special case... */
247 iommund = 0;
248 if(sparc_cpu_model == sun4u) {
249 nd = prom_searchsiblings(topnd, "sbus");
250 if(nd == 0) {
251#ifdef CONFIG_PCI
252 if (!pcic_present()) {
253 prom_printf("Neither SBUS nor PCI found.\n");
254 prom_halt();
255 } else {
256#ifdef CONFIG_SPARC64
257 firetruck_init();
258#endif
259 }
260 return 0;
261#else
262 prom_printf("YEEE, UltraSparc sbus not found\n");
263 prom_halt();
264#endif
265 }
266 } else if(sparc_cpu_model == sun4d) {
267 if((iommund = prom_searchsiblings(topnd, "io-unit")) == 0 ||
268 (nd = prom_getchild(iommund)) == 0 ||
269 (nd = prom_searchsiblings(nd, "sbi")) == 0) {
270 panic("sbi not found");
271 }
272 } else if((nd = prom_searchsiblings(topnd, "sbus")) == 0) {
273 if((iommund = prom_searchsiblings(topnd, "iommu")) == 0 ||
274 (nd = prom_getchild(iommund)) == 0 ||
275 (nd = prom_searchsiblings(nd, "sbus")) == 0) {
276#ifdef CONFIG_PCI
277 if (!pcic_present()) {
278 prom_printf("Neither SBUS nor PCI found.\n");
279 prom_halt();
280 }
281 return 0;
282#else
283 /* No reason to run further - the data access trap will occur. */
284 panic("sbus not found");
285#endif
286 } 198 }
199 dp = dp->sibling;
287 } 200 }
201}
288 202
289 /* Ok, we've found the first one, allocate first SBus struct 203static void __init build_one_sbus(struct device_node *dp, int num_sbus)
290 * and place in chain. 204{
291 */ 205 struct sbus_bus *sbus;
292 sbus = sbus_root = kmalloc(sizeof(struct sbus_bus), GFP_ATOMIC); 206 unsigned int sbus_clock;
293 sbus->next = NULL; 207 struct device_node *dev_dp;
294 sbus->prom_node = nd;
295 this_sbus = nd;
296 208
297 if(iommund && sparc_cpu_model != sun4u && sparc_cpu_model != sun4d) 209 sbus = kzalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
298 iommu_init(iommund, sbus); 210 if (!sbus)
211 return;
299 212
300 /* Loop until we find no more SBUS's */ 213 sbus_insert(sbus, &sbus_root);
301 while(this_sbus) { 214 sbus->prom_node = dp->node;
302#ifdef CONFIG_SPARC64
303 /* IOMMU hides inside SBUS/SYSIO prom node on Ultra. */
304 if(sparc_cpu_model == sun4u) {
305 extern void sbus_iommu_init(int prom_node, struct sbus_bus *sbus);
306 215
307 sbus_iommu_init(this_sbus, sbus); 216 sbus_setup_iommu(sbus, dp);
308 }
309#endif /* CONFIG_SPARC64 */
310
311#ifdef CONFIG_SPARC32
312 if (sparc_cpu_model == sun4d)
313 iounit_init(this_sbus, iommund, sbus);
314#endif /* CONFIG_SPARC32 */
315 printk("sbus%d: ", num_sbus);
316 sbus_clock = prom_getint(this_sbus, "clock-frequency");
317 if(sbus_clock == -1)
318 sbus_clock = (25*1000*1000);
319 printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
320 (int) (((sbus_clock/1000)%1000 != 0) ?
321 (((sbus_clock/1000)%1000) + 1000) : 0));
322
323 prom_getstring(this_sbus, "name",
324 sbus->prom_name, sizeof(sbus->prom_name));
325 sbus->clock_freq = sbus_clock;
326#ifdef CONFIG_SPARC32
327 if (sparc_cpu_model == sun4d) {
328 sbus->devid = prom_getint(iommund, "device-id");
329 sbus->board = prom_getint(iommund, "board#");
330 }
331#endif
332
333 sbus_bus_ranges_init(iommund, sbus);
334
335 sbus_devs = prom_getchild(this_sbus);
336 if (!sbus_devs) {
337 sbus->devices = NULL;
338 goto next_bus;
339 }
340 217
341 sbus->devices = kmalloc(sizeof(struct sbus_dev), GFP_ATOMIC); 218 printk("sbus%d: ", num_sbus);
342
343 this_dev = sbus->devices;
344 this_dev->next = NULL;
345
346 this_dev->bus = sbus;
347 this_dev->parent = NULL;
348 fill_sbus_device(sbus_devs, this_dev);
349
350 /* Should we traverse for children? */
351 if(prom_getchild(sbus_devs)) {
352 /* Allocate device node */
353 this_dev->child = kmalloc(sizeof(struct sbus_dev),
354 GFP_ATOMIC);
355 /* Fill it */
356 this_dev->child->bus = sbus;
357 this_dev->child->next = NULL;
358 fill_sbus_device(prom_getchild(sbus_devs),
359 this_dev->child);
360 sbus_do_child_siblings(prom_getchild(sbus_devs),
361 this_dev->child,
362 this_dev,
363 sbus);
364 } else {
365 this_dev->child = NULL;
366 }
367 219
368 while((sbus_devs = prom_getsibling(sbus_devs)) != 0) { 220 sbus_clock = of_getintprop_default(dp, "clock-frequency",
369 /* Allocate device node */ 221 (25*1000*1000));
370 this_dev->next = kmalloc(sizeof(struct sbus_dev), 222 sbus->clock_freq = sbus_clock;
371 GFP_ATOMIC); 223
372 this_dev = this_dev->next; 224 printk("Clock %d.%d MHz\n", (int) ((sbus_clock/1000)/1000),
373 this_dev->next = NULL; 225 (int) (((sbus_clock/1000)%1000 != 0) ?
374 226 (((sbus_clock/1000)%1000) + 1000) : 0));
375 /* Fill it */ 227
376 this_dev->bus = sbus; 228 strcpy(sbus->prom_name, dp->name);
377 this_dev->parent = NULL; 229
378 fill_sbus_device(sbus_devs, this_dev); 230 sbus_setup_arch_props(sbus, dp);
379 231
380 /* Is there a child node hanging off of us? */ 232 sbus_bus_ranges_init(dp, sbus);
381 if(prom_getchild(sbus_devs)) { 233
382 /* Get new device struct */ 234 sbus->ofdev.node = dp;
383 this_dev->child = kmalloc(sizeof(struct sbus_dev), 235 sbus->ofdev.dev.parent = NULL;
384 GFP_ATOMIC); 236 sbus->ofdev.dev.bus = &sbus_bus_type;
385 /* Fill it */ 237 strcpy(sbus->ofdev.dev.bus_id, dp->path_component_name);
386 this_dev->child->bus = sbus; 238
387 this_dev->child->next = NULL; 239 if (of_device_register(&sbus->ofdev) != 0)
388 fill_sbus_device(prom_getchild(sbus_devs), 240 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
389 this_dev->child); 241 sbus->ofdev.dev.bus_id);
390 sbus_do_child_siblings(prom_getchild(sbus_devs), 242
391 this_dev->child, 243 dev_dp = dp->child;
392 this_dev, 244 while (dev_dp) {
393 sbus); 245 struct sbus_dev *sdev;
394 } else { 246
395 this_dev->child = NULL; 247 sdev = kzalloc(sizeof(struct sbus_dev), GFP_ATOMIC);
396 } 248 if (sdev) {
249 sdev_insert(sdev, &sbus->devices);
250
251 sdev->bus = sbus;
252 sdev->parent = NULL;
253 fill_sbus_device(dev_dp, sdev);
254
255 walk_children(dev_dp, sdev, sbus);
397 } 256 }
257 dev_dp = dev_dp->sibling;
258 }
259
260 sbus_fixup_all_regs(sbus->devices);
261
262 dvma_init(sbus);
263}
264
265static int __init sbus_init(void)
266{
267 struct device_node *dp;
268 const char *sbus_name = "sbus";
269 int num_sbus = 0;
398 270
399 /* Walk all devices and apply parent ranges. */ 271 if (sbus_arch_preinit())
400 sbus_fixup_all_regs(sbus->devices); 272 return 0;
401 273
402 dvma_init(sbus); 274 if (sparc_cpu_model == sun4d)
403 next_bus: 275 sbus_name = "sbi";
276
277 for_each_node_by_name(dp, sbus_name) {
278 build_one_sbus(dp, num_sbus);
404 num_sbus++; 279 num_sbus++;
405 if(sparc_cpu_model == sun4u) {
406 this_sbus = prom_getsibling(this_sbus);
407 if(!this_sbus)
408 break;
409 this_sbus = prom_searchsiblings(this_sbus, "sbus");
410 } else if(sparc_cpu_model == sun4d) {
411 iommund = prom_getsibling(iommund);
412 if(!iommund)
413 break;
414 iommund = prom_searchsiblings(iommund, "io-unit");
415 if(!iommund)
416 break;
417 this_sbus = prom_searchsiblings(prom_getchild(iommund), "sbi");
418 } else {
419 this_sbus = prom_getsibling(this_sbus);
420 if(!this_sbus)
421 break;
422 this_sbus = prom_searchsiblings(this_sbus, "sbus");
423 }
424 if(this_sbus) {
425 sbus->next = kmalloc(sizeof(struct sbus_bus), GFP_ATOMIC);
426 sbus = sbus->next;
427 sbus->next = NULL;
428 sbus->prom_node = this_sbus;
429 } else {
430 break;
431 }
432 } /* while(this_sbus) */
433 280
434 if (sparc_cpu_model == sun4d) {
435 extern void sun4d_init_sbi_irq(void);
436 sun4d_init_sbi_irq();
437 }
438
439#ifdef CONFIG_SPARC64
440 if (sparc_cpu_model == sun4u) {
441 firetruck_init();
442 } 281 }
443#endif 282
444#ifdef CONFIG_SUN_AUXIO 283 sbus_arch_postinit();
445 if (sparc_cpu_model == sun4u)
446 auxio_probe ();
447#endif
448#ifdef CONFIG_SPARC64
449 if (sparc_cpu_model == sun4u) {
450 extern void clock_probe(void);
451
452 clock_probe();
453 }
454#endif
455 284
456 return 0; 285 return 0;
457} 286}