[MIPS] Always pass -msoft-float.
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / sparc / kernel / ebus.c
blob5c3529ceb5d60151704d1b8f92c381f485d32503
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/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>
18 #include <asm/page.h>
19 #include <asm/pbm.h>
20 #include <asm/ebus.h>
21 #include <asm/io.h>
22 #include <asm/oplib.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, 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(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(int node, struct linux_prom_registers *preg,
87 struct linux_ebus_child *dev)
89 int regs[PROMREG_MAX];
90 int irqs[PROMREG_MAX];
91 char lbuf[128];
92 int i, len;
94 dev->prom_node = node;
95 prom_getstring(node, "name", lbuf, sizeof(lbuf));
96 strcpy(dev->prom_name, lbuf);
98 len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs));
99 if (len == -1) len = 0;
100 dev->num_addrs = len / sizeof(regs[0]);
102 for (i = 0; i < dev->num_addrs; i++) {
103 if (regs[i] >= dev->parent->num_addrs) {
104 prom_printf("UGH: property for %s was %d, need < %d\n",
105 dev->prom_name, len, dev->parent->num_addrs);
106 panic(__FUNCTION__);
108 dev->resource[i].start = dev->parent->resource[regs[i]].start; /* XXX resource */
111 for (i = 0; i < PROMINTR_MAX; i++)
112 dev->irqs[i] = PCI_IRQ_NONE;
114 if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_name)) != 0) {
115 dev->num_irqs = 1;
116 } else if ((len = prom_getproperty(node, "interrupts",
117 (char *)&irqs, sizeof(irqs))) == -1 || len == 0) {
118 dev->num_irqs = 0;
119 dev->irqs[0] = 0;
120 if (dev->parent->num_irqs != 0) {
121 dev->num_irqs = 1;
122 dev->irqs[0] = dev->parent->irqs[0];
123 /* P3 */ /* printk("EBUS: dev %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
125 } else {
126 dev->num_irqs = len / sizeof(irqs[0]);
127 if (irqs[0] == 0 || irqs[0] >= 8) {
129 * XXX Zero is a valid pin number...
130 * This works as long as Ebus is not wired to INTA#.
132 printk("EBUS: %s got bad irq %d from PROM\n",
133 dev->prom_name, irqs[0]);
134 dev->num_irqs = 0;
135 dev->irqs[0] = 0;
136 } else {
137 dev->irqs[0] = pcic_pin_to_irq(irqs[0], dev->prom_name);
142 void __init fill_ebus_device(int node, struct linux_ebus_device *dev)
144 struct linux_prom_registers regs[PROMREG_MAX];
145 struct linux_ebus_child *child;
146 int irqs[PROMINTR_MAX];
147 char lbuf[128];
148 int i, n, len;
149 unsigned long baseaddr;
151 dev->prom_node = node;
152 prom_getstring(node, "name", lbuf, sizeof(lbuf));
153 strcpy(dev->prom_name, lbuf);
155 len = prom_getproperty(node, "reg", (void *)regs, sizeof(regs));
156 if (len % sizeof(struct linux_prom_registers)) {
157 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
158 dev->prom_name, len,
159 (int)sizeof(struct linux_prom_registers));
160 panic(__FUNCTION__);
162 dev->num_addrs = len / sizeof(struct linux_prom_registers);
164 for (i = 0; i < dev->num_addrs; i++) {
166 * XXX Collect JE-1 PROM
168 * Example - JS-E with 3.11:
169 * /ebus
170 * regs
171 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
172 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
173 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
174 * ranges
175 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
176 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
177 * /ebus/8042
178 * regs
179 * 0x00000001, 0x00300060, 0x00000008,
180 * 0x00000001, 0x00300060, 0x00000008,
182 n = regs[i].which_io;
183 if (n >= 4) {
184 /* XXX This is copied from old JE-1 by Gleb. */
185 n = (regs[i].which_io - 0x10) >> 2;
186 } else {
191 * XXX Now as we have regions, why don't we make an on-demand allocation...
193 dev->resource[i].start = 0;
194 if ((baseaddr = dev->bus->self->resource[n].start +
195 regs[i].phys_addr) != 0) {
196 /* dev->resource[i].name = dev->prom_name; */
197 if ((baseaddr = (unsigned long) ioremap(baseaddr,
198 regs[i].reg_size)) == 0) {
199 panic("ebus: unable to remap dev %s",
200 dev->prom_name);
203 dev->resource[i].start = baseaddr; /* XXX Unaligned */
206 for (i = 0; i < PROMINTR_MAX; i++)
207 dev->irqs[i] = PCI_IRQ_NONE;
209 if ((dev->irqs[0] = ebus_blacklist_irq(dev->prom_name)) != 0) {
210 dev->num_irqs = 1;
211 } else if ((len = prom_getproperty(node, "interrupts",
212 (char *)&irqs, sizeof(irqs))) == -1 || len == 0) {
213 dev->num_irqs = 0;
214 if ((dev->irqs[0] = dev->bus->self->irq) != 0) {
215 dev->num_irqs = 1;
216 /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
218 } else {
219 dev->num_irqs = 1; /* dev->num_irqs = len / sizeof(irqs[0]); */
220 if (irqs[0] == 0 || irqs[0] >= 8) {
221 /* See above for the parent. XXX */
222 printk("EBUS: %s got bad irq %d from PROM\n",
223 dev->prom_name, irqs[0]);
224 dev->num_irqs = 0;
225 dev->irqs[0] = 0;
226 } else {
227 dev->irqs[0] = pcic_pin_to_irq(irqs[0], dev->prom_name);
231 if ((node = prom_getchild(node))) {
232 dev->children = (struct linux_ebus_child *)
233 ebus_alloc(sizeof(struct linux_ebus_child));
235 child = dev->children;
236 child->next = NULL;
237 child->parent = dev;
238 child->bus = dev->bus;
239 fill_ebus_child(node, &regs[0], child);
241 while ((node = prom_getsibling(node)) != 0) {
242 child->next = (struct linux_ebus_child *)
243 ebus_alloc(sizeof(struct linux_ebus_child));
245 child = child->next;
246 child->next = NULL;
247 child->parent = dev;
248 child->bus = dev->bus;
249 fill_ebus_child(node, &regs[0], child);
254 void __init ebus_init(void)
256 struct linux_prom_pci_registers regs[PROMREG_MAX];
257 struct linux_pbm_info *pbm;
258 struct linux_ebus_device *dev;
259 struct linux_ebus *ebus;
260 struct ebus_system_entry *sp;
261 struct pci_dev *pdev;
262 struct pcidev_cookie *cookie;
263 char lbuf[128];
264 unsigned long addr, *base;
265 unsigned short pci_command;
266 int nd, len, ebusnd;
267 int reg, nreg;
268 int num_ebus = 0;
270 prom_getstring(prom_root_node, "name", lbuf, sizeof(lbuf));
271 for (sp = ebus_blacklist; sp->esname != NULL; sp++) {
272 if (strcmp(lbuf, sp->esname) == 0) {
273 ebus_blackp = sp->ipt;
274 break;
278 pdev = pci_get_device(PCI_VENDOR_ID_SUN, PCI_DEVICE_ID_SUN_EBUS, NULL);
279 if (!pdev) {
280 return;
282 cookie = pdev->sysdata;
283 ebusnd = cookie->prom_node;
285 ebus_chain = ebus = (struct linux_ebus *)
286 ebus_alloc(sizeof(struct linux_ebus));
287 ebus->next = NULL;
289 while (ebusnd) {
291 prom_getstring(ebusnd, "name", lbuf, sizeof(lbuf));
292 ebus->prom_node = ebusnd;
293 strcpy(ebus->prom_name, lbuf);
294 ebus->self = pdev;
295 ebus->parent = pbm = cookie->pbm;
297 /* Enable BUS Master. */
298 pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
299 pci_command |= PCI_COMMAND_MASTER;
300 pci_write_config_word(pdev, PCI_COMMAND, pci_command);
302 len = prom_getproperty(ebusnd, "reg", (void *)regs,
303 sizeof(regs));
304 if (len == 0 || len == -1) {
305 prom_printf("%s: can't find reg property\n",
306 __FUNCTION__);
307 prom_halt();
309 nreg = len / sizeof(struct linux_prom_pci_registers);
311 base = &ebus->self->resource[0].start;
312 for (reg = 0; reg < nreg; reg++) {
313 if (!(regs[reg].which_io & 0x03000000))
314 continue;
316 addr = regs[reg].phys_lo;
317 *base++ = addr;
320 nd = prom_getchild(ebusnd);
321 if (!nd)
322 goto next_ebus;
324 ebus->devices = (struct linux_ebus_device *)
325 ebus_alloc(sizeof(struct linux_ebus_device));
327 dev = ebus->devices;
328 dev->next = NULL;
329 dev->children = NULL;
330 dev->bus = ebus;
331 fill_ebus_device(nd, dev);
333 while ((nd = prom_getsibling(nd)) != 0) {
334 dev->next = (struct linux_ebus_device *)
335 ebus_alloc(sizeof(struct linux_ebus_device));
337 dev = dev->next;
338 dev->next = NULL;
339 dev->children = NULL;
340 dev->bus = ebus;
341 fill_ebus_device(nd, dev);
344 next_ebus:
345 pdev = pci_get_device(PCI_VENDOR_ID_SUN,
346 PCI_DEVICE_ID_SUN_EBUS, pdev);
347 if (!pdev)
348 break;
350 cookie = pdev->sysdata;
351 ebusnd = cookie->prom_node;
353 ebus->next = (struct linux_ebus *)
354 ebus_alloc(sizeof(struct linux_ebus));
355 ebus = ebus->next;
356 ebus->next = NULL;
357 ++num_ebus;
359 if (pdev)
360 pci_dev_put(pdev);