diff options
author | David S. Miller <davem@davemloft.net> | 2006-06-23 18:55:45 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-06-24 02:15:50 -0400 |
commit | 576c352e89e57cfa6c9f493e549d10d86f60a0cf (patch) | |
tree | 4f393f05beef86284a037b106bfb353ff0d72c8a | |
parent | fd5314311634245172d40ccb418d89dac91d6ad6 (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>
-rw-r--r-- | arch/sparc/kernel/ioport.c | 85 | ||||
-rw-r--r-- | arch/sparc64/kernel/sbus.c | 31 | ||||
-rw-r--r-- | drivers/sbus/sbus.c | 449 | ||||
-rw-r--r-- | include/asm-sparc/sbus.h | 27 | ||||
-rw-r--r-- | include/asm-sparc64/sbus.h | 28 |
5 files changed, 293 insertions, 327 deletions
diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c index 00cf41182912..ae4c667c906f 100644 --- a/arch/sparc/kernel/ioport.c +++ b/arch/sparc/kernel/ioport.c | |||
@@ -39,6 +39,8 @@ | |||
39 | #include <asm/io.h> | 39 | #include <asm/io.h> |
40 | #include <asm/vaddrs.h> | 40 | #include <asm/vaddrs.h> |
41 | #include <asm/oplib.h> | 41 | #include <asm/oplib.h> |
42 | #include <asm/prom.h> | ||
43 | #include <asm/sbus.h> | ||
42 | #include <asm/page.h> | 44 | #include <asm/page.h> |
43 | #include <asm/pgalloc.h> | 45 | #include <asm/pgalloc.h> |
44 | #include <asm/dma.h> | 46 | #include <asm/dma.h> |
@@ -458,6 +460,89 @@ void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev, struct scatterlist *sg, | |||
458 | { | 460 | { |
459 | printk("sbus_dma_sync_sg_for_device: not implemented yet\n"); | 461 | printk("sbus_dma_sync_sg_for_device: not implemented yet\n"); |
460 | } | 462 | } |
463 | |||
464 | /* Support code for sbus_init(). */ | ||
465 | /* | ||
466 | * XXX This functions appears to be a distorted version of | ||
467 | * prom_sbus_ranges_init(), with all sun4d stuff cut away. | ||
468 | * Ask DaveM what is going on here, how is sun4d supposed to work... XXX | ||
469 | */ | ||
470 | /* added back sun4d patch from Thomas Bogendoerfer - should be OK (crn) */ | ||
471 | void __init sbus_arch_bus_ranges_init(struct device_node *pn, struct sbus_bus *sbus) | ||
472 | { | ||
473 | int parent_node = pn->node; | ||
474 | |||
475 | if (sparc_cpu_model == sun4d) { | ||
476 | struct linux_prom_ranges iounit_ranges[PROMREG_MAX]; | ||
477 | int num_iounit_ranges, len; | ||
478 | |||
479 | len = prom_getproperty(parent_node, "ranges", | ||
480 | (char *) iounit_ranges, | ||
481 | sizeof (iounit_ranges)); | ||
482 | if (len != -1) { | ||
483 | num_iounit_ranges = | ||
484 | (len / sizeof(struct linux_prom_ranges)); | ||
485 | prom_adjust_ranges(sbus->sbus_ranges, | ||
486 | sbus->num_sbus_ranges, | ||
487 | iounit_ranges, num_iounit_ranges); | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | |||
492 | void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp) | ||
493 | { | ||
494 | struct device_node *parent = dp->parent; | ||
495 | |||
496 | if (sparc_cpu_model != sun4d && | ||
497 | parent != NULL && | ||
498 | !strcmp(parent->name, "iommu")) { | ||
499 | extern void iommu_init(int iommu_node, struct sbus_bus *sbus); | ||
500 | |||
501 | iommu_init(parent->node, sbus); | ||
502 | } | ||
503 | |||
504 | if (sparc_cpu_model == sun4d) { | ||
505 | extern void iounit_init(int sbi_node, int iounit_node, | ||
506 | struct sbus_bus *sbus); | ||
507 | |||
508 | iounit_init(dp->node, parent->node, sbus); | ||
509 | } | ||
510 | } | ||
511 | |||
512 | void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp) | ||
513 | { | ||
514 | if (sparc_cpu_model == sun4d) { | ||
515 | struct device_node *parent = dp->parent; | ||
516 | |||
517 | sbus->devid = of_getintprop_default(parent, "device-id", 0); | ||
518 | sbus->board = of_getintprop_default(parent, "board#", 0); | ||
519 | } | ||
520 | } | ||
521 | |||
522 | int __init sbus_arch_preinit(void) | ||
523 | { | ||
524 | extern void register_proc_sparc_ioport(void); | ||
525 | |||
526 | register_proc_sparc_ioport(); | ||
527 | |||
528 | #ifdef CONFIG_SUN4 | ||
529 | { | ||
530 | extern void sun4_dvma_init(void); | ||
531 | sun4_dvma_init(); | ||
532 | } | ||
533 | return 1; | ||
534 | #else | ||
535 | return 0; | ||
536 | #endif | ||
537 | } | ||
538 | |||
539 | void __init sbus_arch_postinit(void) | ||
540 | { | ||
541 | if (sparc_cpu_model == sun4d) { | ||
542 | extern void sun4d_init_sbi_irq(void); | ||
543 | sun4d_init_sbi_irq(); | ||
544 | } | ||
545 | } | ||
461 | #endif /* CONFIG_SBUS */ | 546 | #endif /* CONFIG_SBUS */ |
462 | 547 | ||
463 | #ifdef CONFIG_PCI | 548 | #ifdef CONFIG_PCI |
diff --git a/arch/sparc64/kernel/sbus.c b/arch/sparc64/kernel/sbus.c index a72bba398809..d3da23cdc264 100644 --- a/arch/sparc64/kernel/sbus.c +++ b/arch/sparc64/kernel/sbus.c | |||
@@ -1099,7 +1099,7 @@ static void __init sysio_register_error_handlers(struct sbus_bus *sbus) | |||
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | /* Boot time initialization. */ | 1101 | /* Boot time initialization. */ |
1102 | void __init sbus_iommu_init(int __node, struct sbus_bus *sbus) | 1102 | static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus) |
1103 | { | 1103 | { |
1104 | struct linux_prom64_registers *pr; | 1104 | struct linux_prom64_registers *pr; |
1105 | struct device_node *dp; | 1105 | struct device_node *dp; |
@@ -1247,3 +1247,32 @@ void sbus_fill_device_irq(struct sbus_dev *sdev) | |||
1247 | sdev->irqs[0] = sbus_build_irq(sdev->bus, pri); | 1247 | sdev->irqs[0] = sbus_build_irq(sdev->bus, pri); |
1248 | } | 1248 | } |
1249 | } | 1249 | } |
1250 | |||
1251 | void __init sbus_arch_bus_ranges_init(struct device_node *pn, struct sbus_bus *sbus) | ||
1252 | { | ||
1253 | } | ||
1254 | |||
1255 | void __init sbus_setup_iommu(struct sbus_bus *sbus, struct device_node *dp) | ||
1256 | { | ||
1257 | sbus_iommu_init(dp->node, sbus); | ||
1258 | } | ||
1259 | |||
1260 | void __init sbus_setup_arch_props(struct sbus_bus *sbus, struct device_node *dp) | ||
1261 | { | ||
1262 | } | ||
1263 | |||
1264 | int __init sbus_arch_preinit(void) | ||
1265 | { | ||
1266 | return 0; | ||
1267 | } | ||
1268 | |||
1269 | void __init sbus_arch_postinit(void) | ||
1270 | { | ||
1271 | extern void firetruck_init(void); | ||
1272 | extern void auxio_probe(void); | ||
1273 | extern void clock_probe(void); | ||
1274 | |||
1275 | firetruck_init(); | ||
1276 | auxio_probe(); | ||
1277 | clock_probe(); | ||
1278 | } | ||
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 | ||
19 | struct sbus_bus *sbus_root; | 21 | struct sbus_bus *sbus_root; |
20 | 22 | ||
21 | #ifdef CONFIG_PCI | 23 | static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev) |
22 | extern int pcic_present(void); | ||
23 | #endif | ||
24 | |||
25 | static 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; | |
69 | extern void iommu_init(int iommu_node, struct sbus_bus *sbus); | 65 | strcpy(sdev->ofdev.dev.bus_id, dp->path_component_name); |
70 | extern void iounit_init(int sbi_node, int iounit_node, struct sbus_bus *sbus); | 66 | |
71 | void 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", |
73 | extern void auxio_probe(void); | 69 | sdev->ofdev.dev.bus_id); |
74 | #endif | ||
75 | |||
76 | static 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 | /* | 72 | static 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 | |||
117 | static 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 | ||
145 | static void __init __apply_ranges_to_regs(struct linux_prom_ranges *ranges, | 88 | static 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 | ||
220 | extern void register_proc_sparc_ioport(void); | 163 | /* We preserve the "probe order" of these bus and device lists to give |
221 | extern void firetruck_init(void); | 164 | * the same ordering as the old code. |
165 | */ | ||
166 | static 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 | 174 | static void __init sdev_insert(struct sbus_dev *sdev, struct sbus_dev **root) |
224 | extern 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 | ||
227 | static int __init sbus_init(void) | 182 | static 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 | 203 | static 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 | |||
265 | static 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 | } |
diff --git a/include/asm-sparc/sbus.h b/include/asm-sparc/sbus.h index 76654fa23091..d036e4419d79 100644 --- a/include/asm-sparc/sbus.h +++ b/include/asm-sparc/sbus.h | |||
@@ -11,7 +11,8 @@ | |||
11 | #include <linux/ioport.h> | 11 | #include <linux/ioport.h> |
12 | 12 | ||
13 | #include <asm/oplib.h> | 13 | #include <asm/oplib.h> |
14 | /* #include <asm/iommu.h> */ /* Unused since we use opaque iommu (|io-unit) */ | 14 | #include <asm/prom.h> |
15 | #include <asm/of_device.h> | ||
15 | #include <asm/scatterlist.h> | 16 | #include <asm/scatterlist.h> |
16 | 17 | ||
17 | /* We scan which devices are on the SBus using the PROM node device | 18 | /* We scan which devices are on the SBus using the PROM node device |
@@ -42,18 +43,19 @@ struct sbus_bus; | |||
42 | 43 | ||
43 | /* Linux SBUS device tables */ | 44 | /* Linux SBUS device tables */ |
44 | struct sbus_dev { | 45 | struct sbus_dev { |
45 | struct sbus_bus *bus; /* Back ptr to sbus */ | 46 | struct of_device ofdev; |
46 | struct sbus_dev *next; /* next device on this SBus or null */ | 47 | struct sbus_bus *bus; |
47 | struct sbus_dev *child; /* For ledma and espdma on sun4m */ | 48 | struct sbus_dev *next; |
48 | struct sbus_dev *parent; /* Parent device if not toplevel */ | 49 | struct sbus_dev *child; |
49 | int prom_node; /* PROM device tree node for this device */ | 50 | struct sbus_dev *parent; |
50 | char prom_name[64]; /* PROM device name */ | 51 | int prom_node; |
52 | char prom_name[64]; | ||
51 | int slot; | 53 | int slot; |
52 | 54 | ||
53 | struct resource resource[PROMREG_MAX]; | 55 | struct resource resource[PROMREG_MAX]; |
54 | 56 | ||
55 | struct linux_prom_registers reg_addrs[PROMREG_MAX]; | 57 | struct linux_prom_registers reg_addrs[PROMREG_MAX]; |
56 | int num_registers, ranges_applied; | 58 | int num_registers; |
57 | 59 | ||
58 | struct linux_prom_ranges device_ranges[PROMREG_MAX]; | 60 | struct linux_prom_ranges device_ranges[PROMREG_MAX]; |
59 | int num_device_ranges; | 61 | int num_device_ranges; |
@@ -61,9 +63,11 @@ struct sbus_dev { | |||
61 | unsigned int irqs[4]; | 63 | unsigned int irqs[4]; |
62 | int num_irqs; | 64 | int num_irqs; |
63 | }; | 65 | }; |
66 | #define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev) | ||
64 | 67 | ||
65 | /* This struct describes the SBus(s) found on this machine. */ | 68 | /* This struct describes the SBus(s) found on this machine. */ |
66 | struct sbus_bus { | 69 | struct sbus_bus { |
70 | struct of_device ofdev; | ||
67 | void *iommu; /* Opaque IOMMU cookie */ | 71 | void *iommu; /* Opaque IOMMU cookie */ |
68 | struct sbus_dev *devices; /* Link to devices on this SBus */ | 72 | struct sbus_dev *devices; /* Link to devices on this SBus */ |
69 | struct sbus_bus *next; /* next SBus, if more than one SBus */ | 73 | struct sbus_bus *next; /* next SBus, if more than one SBus */ |
@@ -77,6 +81,7 @@ struct sbus_bus { | |||
77 | int devid; | 81 | int devid; |
78 | int board; | 82 | int board; |
79 | }; | 83 | }; |
84 | #define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev) | ||
80 | 85 | ||
81 | extern struct sbus_bus *sbus_root; | 86 | extern struct sbus_bus *sbus_root; |
82 | 87 | ||
@@ -140,4 +145,10 @@ extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, | |||
140 | BTFIXUPDEF_CALL(unsigned int, sbint_to_irq, struct sbus_dev *sdev, unsigned int) | 145 | BTFIXUPDEF_CALL(unsigned int, sbint_to_irq, struct sbus_dev *sdev, unsigned int) |
141 | #define sbint_to_irq(sdev, sbint) BTFIXUP_CALL(sbint_to_irq)(sdev, sbint) | 146 | #define sbint_to_irq(sdev, sbint) BTFIXUP_CALL(sbint_to_irq)(sdev, sbint) |
142 | 147 | ||
148 | extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *); | ||
149 | extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *); | ||
150 | extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *); | ||
151 | extern int sbus_arch_preinit(void); | ||
152 | extern void sbus_arch_postinit(void); | ||
153 | |||
143 | #endif /* !(_SPARC_SBUS_H) */ | 154 | #endif /* !(_SPARC_SBUS_H) */ |
diff --git a/include/asm-sparc64/sbus.h b/include/asm-sparc64/sbus.h index ca2054da2430..56ee985e4605 100644 --- a/include/asm-sparc64/sbus.h +++ b/include/asm-sparc64/sbus.h | |||
@@ -11,6 +11,8 @@ | |||
11 | #include <linux/ioport.h> | 11 | #include <linux/ioport.h> |
12 | 12 | ||
13 | #include <asm/oplib.h> | 13 | #include <asm/oplib.h> |
14 | #include <asm/prom.h> | ||
15 | #include <asm/of_device.h> | ||
14 | #include <asm/iommu.h> | 16 | #include <asm/iommu.h> |
15 | #include <asm/scatterlist.h> | 17 | #include <asm/scatterlist.h> |
16 | 18 | ||
@@ -42,18 +44,19 @@ struct sbus_bus; | |||
42 | 44 | ||
43 | /* Linux SBUS device tables */ | 45 | /* Linux SBUS device tables */ |
44 | struct sbus_dev { | 46 | struct sbus_dev { |
45 | struct sbus_bus *bus; /* Our toplevel parent SBUS */ | 47 | struct of_device ofdev; |
46 | struct sbus_dev *next; /* Chain of siblings */ | 48 | struct sbus_bus *bus; |
47 | struct sbus_dev *child; /* Chain of children */ | 49 | struct sbus_dev *next; |
48 | struct sbus_dev *parent;/* Parent device if not toplevel*/ | 50 | struct sbus_dev *child; |
49 | int prom_node; /* OBP node of this device */ | 51 | struct sbus_dev *parent; |
50 | char prom_name[64]; /* OBP device name property */ | 52 | int prom_node; |
51 | int slot; /* SBUS slot number */ | 53 | char prom_name[64]; |
54 | int slot; | ||
52 | 55 | ||
53 | struct resource resource[PROMREG_MAX]; | 56 | struct resource resource[PROMREG_MAX]; |
54 | 57 | ||
55 | struct linux_prom_registers reg_addrs[PROMREG_MAX]; | 58 | struct linux_prom_registers reg_addrs[PROMREG_MAX]; |
56 | int num_registers, ranges_applied; | 59 | int num_registers; |
57 | 60 | ||
58 | struct linux_prom_ranges device_ranges[PROMREG_MAX]; | 61 | struct linux_prom_ranges device_ranges[PROMREG_MAX]; |
59 | int num_device_ranges; | 62 | int num_device_ranges; |
@@ -61,9 +64,11 @@ struct sbus_dev { | |||
61 | unsigned int irqs[4]; | 64 | unsigned int irqs[4]; |
62 | int num_irqs; | 65 | int num_irqs; |
63 | }; | 66 | }; |
67 | #define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev) | ||
64 | 68 | ||
65 | /* This struct describes the SBus(s) found on this machine. */ | 69 | /* This struct describes the SBus(s) found on this machine. */ |
66 | struct sbus_bus { | 70 | struct sbus_bus { |
71 | struct of_device ofdev; | ||
67 | void *iommu; /* Opaque IOMMU cookie */ | 72 | void *iommu; /* Opaque IOMMU cookie */ |
68 | struct sbus_dev *devices; /* Tree of SBUS devices */ | 73 | struct sbus_dev *devices; /* Tree of SBUS devices */ |
69 | struct sbus_bus *next; /* Next SBUS in system */ | 74 | struct sbus_bus *next; /* Next SBUS in system */ |
@@ -77,6 +82,7 @@ struct sbus_bus { | |||
77 | int portid; | 82 | int portid; |
78 | void *starfire_cookie; | 83 | void *starfire_cookie; |
79 | }; | 84 | }; |
85 | #define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev) | ||
80 | 86 | ||
81 | extern struct sbus_bus *sbus_root; | 87 | extern struct sbus_bus *sbus_root; |
82 | 88 | ||
@@ -120,4 +126,10 @@ extern void sbus_dma_sync_sg_for_cpu(struct sbus_dev *, struct scatterlist *, in | |||
120 | #define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu | 126 | #define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu |
121 | extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, int, int); | 127 | extern void sbus_dma_sync_sg_for_device(struct sbus_dev *, struct scatterlist *, int, int); |
122 | 128 | ||
129 | extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *); | ||
130 | extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *); | ||
131 | extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *); | ||
132 | extern int sbus_arch_preinit(void); | ||
133 | extern void sbus_arch_postinit(void); | ||
134 | |||
123 | #endif /* !(_SPARC64_SBUS_H) */ | 135 | #endif /* !(_SPARC64_SBUS_H) */ |