1 /* $Id: ebus.c,v 1.18.2.2 2002/01/05 01:12:31 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.
10 #include <linux/config.h>
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/string.h>
17 #include <asm/system.h>
22 #include <asm/oplib.h>
25 struct linux_ebus *ebus_chain = 0;
27 #ifdef CONFIG_SUN_AUXIO
28 extern void auxio_probe(void);
30 extern void rs_init(void);
32 /* We are together with pcic.c under CONFIG_PCI. */
33 extern unsigned int pcic_pin_to_irq(unsigned int, char *name);
37 * Here we list PROMs and systems that are known to supply crap as IRQ numbers.
39 struct ebus_device_irq {
44 struct ebus_system_entry {
46 struct ebus_device_irq *ipt;
49 static struct ebus_device_irq je1_1[] = {
58 * Gleb's JE1 supplied reasonable pin numbers, but mine did not (OBP 2.32).
59 * Blacklist the sucker... Note that Gleb's system will work.
61 static struct ebus_system_entry ebus_blacklist[] = {
62 { "SUNW,JavaEngine1", je1_1 },
66 static struct ebus_device_irq *ebus_blackp = NULL;
70 static inline unsigned long ebus_alloc(size_t size)
72 return (unsigned long)kmalloc(size, GFP_ATOMIC);
77 int __init ebus_blacklist_irq(char *name)
79 struct ebus_device_irq *dp;
81 if ((dp = ebus_blackp) != NULL) {
82 for (; dp->name != NULL; dp++) {
83 if (strcmp(name, dp->name) == 0) {
84 return pcic_pin_to_irq(dp->pin, name);
91 void __init fill_ebus_child(int node, struct linux_prom_registers *preg,
92 struct linux_ebus_child *dev)
94 int regs[PROMREG_MAX];
95 int irqs[PROMREG_MAX];
99 dev->prom_node = node;
100 prom_getstring(node, "name", lbuf, sizeof(lbuf));
101 strcpy(dev->prom_name, lbuf);
103 len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs));
104 if (len == -1) len = 0;
105 dev->num_addrs = len / sizeof(regs[0]);
107 for (i = 0; i < dev->num_addrs; i++) {
108 if (regs[i] >= dev->parent->num_addrs) {
109 prom_printf("UGH: property for %s was %d, need < %d\n",
110 dev->prom_name, len, dev->parent->num_addrs);
113 dev->resource[i].start = dev->parent->resource[regs[i]].start; /* XXX resource */
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_name)) != 0) {
121 } else if ((len = prom_getproperty(node, "interrupts",
122 (char *)&irqs, sizeof(irqs))) == -1 || len == 0) {
125 if (dev->parent->num_irqs != 0) {
127 dev->irqs[0] = dev->parent->irqs[0];
128 /* P3 */ /* printk("EBUS: dev %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
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 to INTA#.
137 printk("EBUS: %s got bad irq %d from PROM\n",
138 dev->prom_name, irqs[0]);
142 dev->irqs[0] = pcic_pin_to_irq(irqs[0], dev->prom_name);
147 void __init fill_ebus_device(int node, struct linux_ebus_device *dev)
149 struct linux_prom_registers regs[PROMREG_MAX];
150 struct linux_ebus_child *child;
151 int irqs[PROMINTR_MAX];
154 unsigned long baseaddr;
156 dev->prom_node = node;
157 prom_getstring(node, "name", lbuf, sizeof(lbuf));
158 strcpy(dev->prom_name, lbuf);
160 len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs));
161 if (len % sizeof(struct linux_prom_registers)) {
162 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
164 (int)sizeof(struct linux_prom_registers));
167 dev->num_addrs = len / sizeof(struct linux_prom_registers);
169 for (i = 0; i < dev->num_addrs; i++) {
171 * XXX Collect JE-1 PROM
173 * Example - JS-E with 3.11:
176 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
177 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
178 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
180 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
181 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
184 * 0x00000001, 0x00300060, 0x00000008,
185 * 0x00000001, 0x00300060, 0x00000008,
187 n = regs[i].which_io;
189 /* XXX This is copied from old JE-1 by Gleb. */
190 n = (regs[i].which_io - 0x10) >> 2;
196 * XXX Now as we have regions, why don't we make an on-demand allocation...
198 dev->resource[i].start = 0;
199 if ((baseaddr = dev->bus->self->resource[n].start +
200 regs[i].phys_addr) != 0) {
201 /* dev->resource[i].name = dev->prom_name; */
202 if ((baseaddr = (unsigned long) ioremap(baseaddr,
203 regs[i].reg_size)) == 0) {
204 panic("ebus: unable to remap dev %s",
208 dev->resource[i].start = baseaddr; /* XXX Unaligned */
211 for (i = 0; i < PROMINTR_MAX; i++)
212 dev->irqs[i] = PCI_IRQ_NONE;
214 if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_name)) != 0) {
216 } else if ((len = prom_getproperty(node, "interrupts",
217 (char *)&irqs, sizeof(irqs))) == -1 || len == 0) {
219 if ((dev->irqs[0] = dev->bus->self->irq) != 0) {
221 /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
224 dev->num_irqs = 1; /* dev->num_irqs = len / sizeof(irqs[0]); */
225 if (irqs[0] == 0 || irqs[0] >= 8) {
226 /* See above for the parent. XXX */
227 printk("EBUS: %s got bad irq %d from PROM\n",
228 dev->prom_name, irqs[0]);
232 dev->irqs[0] = pcic_pin_to_irq(irqs[0], dev->prom_name);
236 if ((node = prom_getchild(node))) {
237 dev->children = (struct linux_ebus_child *)
238 ebus_alloc(sizeof(struct linux_ebus_child));
240 child = dev->children;
243 child->bus = dev->bus;
244 fill_ebus_child(node, ®s[0], child);
246 while ((node = prom_getsibling(node))) {
247 child->next = (struct linux_ebus_child *)
248 ebus_alloc(sizeof(struct linux_ebus_child));
253 child->bus = dev->bus;
254 fill_ebus_child(node, ®s[0], child);
259 void __init ebus_init(void)
261 struct linux_prom_pci_registers regs[PROMREG_MAX];
262 struct linux_pbm_info *pbm;
263 struct linux_ebus_device *dev;
264 struct linux_ebus *ebus;
265 struct ebus_system_entry *sp;
266 struct pci_dev *pdev;
267 struct pcidev_cookie *cookie;
269 unsigned long addr, *base;
270 unsigned short pci_command;
278 prom_getstring(prom_root_node, "name", lbuf, sizeof(lbuf));
279 for (sp = ebus_blacklist; sp->esname != NULL; sp++) {
280 if (strcmp(lbuf, sp->esname) == 0) {
281 ebus_blackp = sp->ipt;
286 pdev = pci_find_device(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_EBUS, 0);
290 cookie = pdev->sysdata;
291 ebusnd = cookie->prom_node;
293 ebus_chain = ebus = (struct linux_ebus *)
294 ebus_alloc(sizeof(struct linux_ebus));
299 prom_getstring(ebusnd, "name", lbuf, sizeof(lbuf));
300 ebus->prom_node = ebusnd;
301 strcpy(ebus->prom_name, lbuf);
303 ebus->parent = pbm = cookie->pbm;
305 /* Enable BUS Master. */
306 pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
307 pci_command |= PCI_COMMAND_MASTER;
308 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
310 len = prom_getproperty(ebusnd, "reg", (void *)regs,
312 if (len == 0 || len == -1) {
313 prom_printf("%s: can't find reg property\n",
317 nreg = len / sizeof(struct linux_prom_pci_registers);
319 base = &ebus->self->resource[0].start;
320 for (reg = 0; reg < nreg; reg++) {
321 if (!(regs[reg].which_io & 0x03000000))
324 addr = regs[reg].phys_lo;
328 nd = prom_getchild(ebusnd);
332 ebus->devices = (struct linux_ebus_device *)
333 ebus_alloc(sizeof(struct linux_ebus_device));
339 fill_ebus_device(nd, dev);
341 while ((nd = prom_getsibling(nd))) {
342 dev->next = (struct linux_ebus_device *)
343 ebus_alloc(sizeof(struct linux_ebus_device));
349 fill_ebus_device(nd, dev);
353 pdev = pci_find_device(PCI_VENDOR_ID_SUN,
354 PCI_DEVICE_ID_SUN_EBUS, pdev);
358 cookie = pdev->sysdata;
359 ebusnd = cookie->prom_node;
361 ebus->next = (struct linux_ebus *)
362 ebus_alloc(sizeof(struct linux_ebus));
369 #ifdef CONFIG_SUN_AUXIO