Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / sparc / kernel / ebus.c
blobe8fa575b28f079671fdeab4b10e5bb87800006fc
1 /* $Id: ebus.c,v 1.20 2002/01/05 01:13:43 davem Exp $
2 * ebus.c: PCI to EBus bridge device.
4 * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
6 * Adopted for sparc by V. Roganov and G. Raiko.
7 * Fixes for different platforms by Pete Zaitcev.
8 */
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/string.h>
16 #include <asm/system.h>
17 #include <asm/page.h>
18 #include <asm/pbm.h>
19 #include <asm/ebus.h>
20 #include <asm/io.h>
21 #include <asm/oplib.h>
22 #include <asm/prom.h>
23 #include <asm/bpp.h>
25 struct linux_ebus *ebus_chain = NULL;
27 /* We are together with pcic.c under CONFIG_PCI. */
28 extern unsigned int pcic_pin_to_irq(unsigned int, const char *name);
31 * IRQ Blacklist
32 * Here we list PROMs and systems that are known to supply crap as IRQ numbers.
34 struct ebus_device_irq {
35 char *name;
36 unsigned int pin;
39 struct ebus_system_entry {
40 char *esname;
41 struct ebus_device_irq *ipt;
44 static struct ebus_device_irq je1_1[] = {
45 { "8042", 3 },
46 { "SUNW,CS4231", 0 },
47 { "parallel", 0 },
48 { "se", 2 },
49 { NULL, 0 }
53 * Gleb's JE1 supplied reasonable pin numbers, but mine did not (OBP 2.32).
54 * Blacklist the sucker... Note that Gleb's system will work.
56 static struct ebus_system_entry ebus_blacklist[] = {
57 { "SUNW,JavaEngine1", je1_1 },
58 { NULL, NULL }
61 static struct ebus_device_irq *ebus_blackp = NULL;
65 static inline unsigned long ebus_alloc(size_t size)
67 return (unsigned long)kmalloc(size, GFP_ATOMIC);
72 int __init ebus_blacklist_irq(const char *name)
74 struct ebus_device_irq *dp;
76 if ((dp = ebus_blackp) != NULL) {
77 for (; dp->name != NULL; dp++) {
78 if (strcmp(name, dp->name) == 0) {
79 return pcic_pin_to_irq(dp->pin, name);
83 return 0;
86 void __init fill_ebus_child(struct device_node *dp,
87 struct linux_ebus_child *dev)
89 const int *regs;
90 const int *irqs;
91 int i, len;
93 dev->prom_node = dp;
94 regs = of_get_property(dp, "reg", &len);
95 if (!regs)
96 len = 0;
97 dev->num_addrs = len / sizeof(regs[0]);
99 for (i = 0; i < dev->num_addrs; i++) {
100 if (regs[i] >= dev->parent->num_addrs) {
101 prom_printf("UGH: property for %s was %d, need < %d\n",
102 dev->prom_node->name, len,
103 dev->parent->num_addrs);
104 <<<<<<< HEAD:arch/sparc/kernel/ebus.c
105 panic(__FUNCTION__);
106 =======
107 panic(__func__);
108 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc/kernel/ebus.c
111 /* XXX resource */
112 dev->resource[i].start =
113 dev->parent->resource[regs[i]].start;
116 for (i = 0; i < PROMINTR_MAX; i++)
117 dev->irqs[i] = PCI_IRQ_NONE;
119 if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_node->name)) != 0) {
120 dev->num_irqs = 1;
121 } else {
122 irqs = of_get_property(dp, "interrupts", &len);
123 if (!irqs) {
124 dev->num_irqs = 0;
125 dev->irqs[0] = 0;
126 if (dev->parent->num_irqs != 0) {
127 dev->num_irqs = 1;
128 dev->irqs[0] = dev->parent->irqs[0];
130 } else {
131 dev->num_irqs = len / sizeof(irqs[0]);
132 if (irqs[0] == 0 || irqs[0] >= 8) {
134 * XXX Zero is a valid pin number...
135 * This works as long as Ebus is not wired
136 * to INTA#.
138 printk("EBUS: %s got bad irq %d from PROM\n",
139 dev->prom_node->name, irqs[0]);
140 dev->num_irqs = 0;
141 dev->irqs[0] = 0;
142 } else {
143 dev->irqs[0] =
144 pcic_pin_to_irq(irqs[0],
145 dev->prom_node->name);
151 void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_device *dev)
153 const struct linux_prom_registers *regs;
154 struct linux_ebus_child *child;
155 struct dev_archdata *sd;
156 const int *irqs;
157 int i, n, len;
158 unsigned long baseaddr;
160 dev->prom_node = dp;
162 regs = of_get_property(dp, "reg", &len);
163 if (!regs)
164 len = 0;
165 if (len % sizeof(struct linux_prom_registers)) {
166 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
167 dev->prom_node->name, len,
168 (int)sizeof(struct linux_prom_registers));
169 <<<<<<< HEAD:arch/sparc/kernel/ebus.c
170 panic(__FUNCTION__);
171 =======
172 panic(__func__);
173 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc/kernel/ebus.c
175 dev->num_addrs = len / sizeof(struct linux_prom_registers);
177 for (i = 0; i < dev->num_addrs; i++) {
179 * XXX Collect JE-1 PROM
181 * Example - JS-E with 3.11:
182 * /ebus
183 * regs
184 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
185 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
186 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
187 * ranges
188 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
189 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
190 * /ebus/8042
191 * regs
192 * 0x00000001, 0x00300060, 0x00000008,
193 * 0x00000001, 0x00300060, 0x00000008,
195 n = regs[i].which_io;
196 if (n >= 4) {
197 /* XXX This is copied from old JE-1 by Gleb. */
198 n = (regs[i].which_io - 0x10) >> 2;
199 } else {
204 * XXX Now as we have regions, why don't we make an on-demand allocation...
206 dev->resource[i].start = 0;
207 if ((baseaddr = dev->bus->self->resource[n].start +
208 regs[i].phys_addr) != 0) {
209 /* dev->resource[i].name = dev->prom_name; */
210 if ((baseaddr = (unsigned long) ioremap(baseaddr,
211 regs[i].reg_size)) == 0) {
212 panic("ebus: unable to remap dev %s",
213 dev->prom_node->name);
216 dev->resource[i].start = baseaddr; /* XXX Unaligned */
219 for (i = 0; i < PROMINTR_MAX; i++)
220 dev->irqs[i] = PCI_IRQ_NONE;
222 if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_node->name)) != 0) {
223 dev->num_irqs = 1;
224 } else {
225 irqs = of_get_property(dp, "interrupts", &len);
226 if (!irqs) {
227 dev->num_irqs = 0;
228 if ((dev->irqs[0] = dev->bus->self->irq) != 0) {
229 dev->num_irqs = 1;
230 /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
232 } else {
233 dev->num_irqs = 1; /* dev->num_irqs = len / sizeof(irqs[0]); */
234 if (irqs[0] == 0 || irqs[0] >= 8) {
235 /* See above for the parent. XXX */
236 printk("EBUS: %s got bad irq %d from PROM\n",
237 dev->prom_node->name, irqs[0]);
238 dev->num_irqs = 0;
239 dev->irqs[0] = 0;
240 } else {
241 dev->irqs[0] =
242 pcic_pin_to_irq(irqs[0],
243 dev->prom_node->name);
248 sd = &dev->ofdev.dev.archdata;
249 sd->prom_node = dp;
250 sd->op = &dev->ofdev;
251 sd->iommu = dev->bus->ofdev.dev.parent->archdata.iommu;
253 dev->ofdev.node = dp;
254 dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
255 dev->ofdev.dev.bus = &ebus_bus_type;
256 sprintf(dev->ofdev.dev.bus_id, "ebus[%08x]", dp->node);
258 /* Register with core */
259 if (of_device_register(&dev->ofdev) != 0)
260 printk(KERN_DEBUG "ebus: device registration error for %s!\n",
261 dp->path_component_name);
263 if ((dp = dp->child) != NULL) {
264 dev->children = (struct linux_ebus_child *)
265 ebus_alloc(sizeof(struct linux_ebus_child));
267 child = dev->children;
268 child->next = NULL;
269 child->parent = dev;
270 child->bus = dev->bus;
271 fill_ebus_child(dp, child);
273 while ((dp = dp->sibling) != NULL) {
274 child->next = (struct linux_ebus_child *)
275 ebus_alloc(sizeof(struct linux_ebus_child));
277 child = child->next;
278 child->next = NULL;
279 child->parent = dev;
280 child->bus = dev->bus;
281 fill_ebus_child(dp, child);
286 void __init ebus_init(void)
288 const struct linux_prom_pci_registers *regs;
289 struct linux_pbm_info *pbm;
290 struct linux_ebus_device *dev;
291 struct linux_ebus *ebus;
292 struct ebus_system_entry *sp;
293 struct pci_dev *pdev;
294 struct pcidev_cookie *cookie;
295 struct device_node *dp;
296 struct resource *p;
297 unsigned short pci_command;
298 int len, reg, nreg;
299 int num_ebus = 0;
301 dp = of_find_node_by_path("/");
302 for (sp = ebus_blacklist; sp->esname != NULL; sp++) {
303 if (strcmp(dp->name, sp->esname) == 0) {
304 ebus_blackp = sp->ipt;
305 break;
309 pdev = pci_get_device(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_EBUS, NULL);
310 if (!pdev)
311 return;
313 cookie = pdev->sysdata;
314 dp = cookie->prom_node;
316 ebus_chain = ebus = (struct linux_ebus *)
317 ebus_alloc(sizeof(struct linux_ebus));
318 ebus->next = NULL;
320 while (dp) {
321 struct device_node *nd;
323 ebus->prom_node = dp;
324 ebus->self = pdev;
325 ebus->parent = pbm = cookie->pbm;
327 /* Enable BUS Master. */
328 pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
329 pci_command |= PCI_COMMAND_MASTER;
330 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
332 regs = of_get_property(dp, "reg", &len);
333 if (!regs) {
334 prom_printf("%s: can't find reg property\n",
335 <<<<<<< HEAD:arch/sparc/kernel/ebus.c
336 __FUNCTION__);
337 =======
338 __func__);
339 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc/kernel/ebus.c
340 prom_halt();
342 nreg = len / sizeof(struct linux_prom_pci_registers);
344 p = &ebus->self->resource[0];
345 for (reg = 0; reg < nreg; reg++) {
346 if (!(regs[reg].which_io & 0x03000000))
347 continue;
349 (p++)->start = regs[reg].phys_lo;
352 ebus->ofdev.node = dp;
353 ebus->ofdev.dev.parent = &pdev->dev;
354 ebus->ofdev.dev.bus = &ebus_bus_type;
355 sprintf(ebus->ofdev.dev.bus_id, "ebus%d", num_ebus);
357 /* Register with core */
358 if (of_device_register(&ebus->ofdev) != 0)
359 printk(KERN_DEBUG "ebus: device registration error for %s!\n",
360 dp->path_component_name);
363 nd = dp->child;
364 if (!nd)
365 goto next_ebus;
367 ebus->devices = (struct linux_ebus_device *)
368 ebus_alloc(sizeof(struct linux_ebus_device));
370 dev = ebus->devices;
371 dev->next = NULL;
372 dev->children = NULL;
373 dev->bus = ebus;
374 fill_ebus_device(nd, dev);
376 while ((nd = nd->sibling) != NULL) {
377 dev->next = (struct linux_ebus_device *)
378 ebus_alloc(sizeof(struct linux_ebus_device));
380 dev = dev->next;
381 dev->next = NULL;
382 dev->children = NULL;
383 dev->bus = ebus;
384 fill_ebus_device(nd, dev);
387 next_ebus:
388 pdev = pci_get_device(PCI_VENDOR_ID_SUN,
389 PCI_DEVICE_ID_SUN_EBUS, pdev);
390 if (!pdev)
391 break;
393 cookie = pdev->sysdata;
394 dp = cookie->prom_node;
396 ebus->next = (struct linux_ebus *)
397 ebus_alloc(sizeof(struct linux_ebus));
398 ebus = ebus->next;
399 ebus->next = NULL;
400 ++num_ebus;
402 if (pdev)
403 pci_dev_put(pdev);