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.
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>
26 struct linux_ebus
*ebus_chain
= NULL
;
28 /* We are together with pcic.c under CONFIG_PCI. */
29 extern unsigned int pcic_pin_to_irq(unsigned int, char *name
);
33 * Here we list PROMs and systems that are known to supply crap as IRQ numbers.
35 struct ebus_device_irq
{
40 struct ebus_system_entry
{
42 struct ebus_device_irq
*ipt
;
45 static struct ebus_device_irq je1_1
[] = {
54 * Gleb's JE1 supplied reasonable pin numbers, but mine did not (OBP 2.32).
55 * Blacklist the sucker... Note that Gleb's system will work.
57 static struct ebus_system_entry ebus_blacklist
[] = {
58 { "SUNW,JavaEngine1", je1_1
},
62 static struct ebus_device_irq
*ebus_blackp
= NULL
;
66 static inline unsigned long ebus_alloc(size_t size
)
68 return (unsigned long)kmalloc(size
, GFP_ATOMIC
);
73 int __init
ebus_blacklist_irq(char *name
)
75 struct ebus_device_irq
*dp
;
77 if ((dp
= ebus_blackp
) != NULL
) {
78 for (; dp
->name
!= NULL
; dp
++) {
79 if (strcmp(name
, dp
->name
) == 0) {
80 return pcic_pin_to_irq(dp
->pin
, name
);
87 void __init
fill_ebus_child(struct device_node
*dp
,
88 struct linux_ebus_child
*dev
)
95 regs
= of_get_property(dp
, "reg", &len
);
98 dev
->num_addrs
= len
/ sizeof(regs
[0]);
100 for (i
= 0; i
< dev
->num_addrs
; i
++) {
101 if (regs
[i
] >= dev
->parent
->num_addrs
) {
102 prom_printf("UGH: property for %s was %d, need < %d\n",
103 dev
->prom_node
->name
, len
,
104 dev
->parent
->num_addrs
);
109 dev
->resource
[i
].start
=
110 dev
->parent
->resource
[regs
[i
]].start
;
113 for (i
= 0; i
< PROMINTR_MAX
; i
++)
114 dev
->irqs
[i
] = PCI_IRQ_NONE
;
116 if ((dev
->irqs
[0] = ebus_blacklist_irq(dev
->prom_node
->name
)) != 0) {
119 irqs
= of_get_property(dp
, "interrupts", &len
);
123 if (dev
->parent
->num_irqs
!= 0) {
125 dev
->irqs
[0] = dev
->parent
->irqs
[0];
128 dev
->num_irqs
= len
/ sizeof(irqs
[0]);
129 if (irqs
[0] == 0 || irqs
[0] >= 8) {
131 * XXX Zero is a valid pin number...
132 * This works as long as Ebus is not wired
135 printk("EBUS: %s got bad irq %d from PROM\n",
136 dev
->prom_node
->name
, irqs
[0]);
141 pcic_pin_to_irq(irqs
[0],
142 dev
->prom_node
->name
);
148 void __init
fill_ebus_device(struct device_node
*dp
, struct linux_ebus_device
*dev
)
150 struct linux_prom_registers
*regs
;
151 struct linux_ebus_child
*child
;
154 unsigned long baseaddr
;
158 regs
= of_get_property(dp
, "reg", &len
);
159 if (len
% sizeof(struct linux_prom_registers
)) {
160 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
161 dev
->prom_node
->name
, len
,
162 (int)sizeof(struct linux_prom_registers
));
165 dev
->num_addrs
= len
/ sizeof(struct linux_prom_registers
);
167 for (i
= 0; i
< dev
->num_addrs
; i
++) {
169 * XXX Collect JE-1 PROM
171 * Example - JS-E with 3.11:
174 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
175 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
176 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
178 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
179 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
182 * 0x00000001, 0x00300060, 0x00000008,
183 * 0x00000001, 0x00300060, 0x00000008,
185 n
= regs
[i
].which_io
;
187 /* XXX This is copied from old JE-1 by Gleb. */
188 n
= (regs
[i
].which_io
- 0x10) >> 2;
194 * XXX Now as we have regions, why don't we make an on-demand allocation...
196 dev
->resource
[i
].start
= 0;
197 if ((baseaddr
= dev
->bus
->self
->resource
[n
].start
+
198 regs
[i
].phys_addr
) != 0) {
199 /* dev->resource[i].name = dev->prom_name; */
200 if ((baseaddr
= (unsigned long) ioremap(baseaddr
,
201 regs
[i
].reg_size
)) == 0) {
202 panic("ebus: unable to remap dev %s",
203 dev
->prom_node
->name
);
206 dev
->resource
[i
].start
= baseaddr
; /* XXX Unaligned */
209 for (i
= 0; i
< PROMINTR_MAX
; i
++)
210 dev
->irqs
[i
] = PCI_IRQ_NONE
;
212 if ((dev
->irqs
[0] = ebus_blacklist_irq(dev
->prom_node
->name
)) != 0) {
215 irqs
= of_get_property(dp
, "interrupts", &len
);
218 if ((dev
->irqs
[0] = dev
->bus
->self
->irq
) != 0) {
220 /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
223 dev
->num_irqs
= 1; /* dev->num_irqs = len / sizeof(irqs[0]); */
224 if (irqs
[0] == 0 || irqs
[0] >= 8) {
225 /* See above for the parent. XXX */
226 printk("EBUS: %s got bad irq %d from PROM\n",
227 dev
->prom_node
->name
, irqs
[0]);
232 pcic_pin_to_irq(irqs
[0],
233 dev
->prom_node
->name
);
238 if ((dp
= dp
->child
) != NULL
) {
239 dev
->children
= (struct linux_ebus_child
*)
240 ebus_alloc(sizeof(struct linux_ebus_child
));
242 child
= dev
->children
;
245 child
->bus
= dev
->bus
;
246 fill_ebus_child(dp
, child
);
248 while ((dp
= dp
->sibling
) != NULL
) {
249 child
->next
= (struct linux_ebus_child
*)
250 ebus_alloc(sizeof(struct linux_ebus_child
));
255 child
->bus
= dev
->bus
;
256 fill_ebus_child(dp
, child
);
261 void __init
ebus_init(void)
263 struct linux_prom_pci_registers
*regs
;
264 struct linux_pbm_info
*pbm
;
265 struct linux_ebus_device
*dev
;
266 struct linux_ebus
*ebus
;
267 struct ebus_system_entry
*sp
;
268 struct pci_dev
*pdev
;
269 struct pcidev_cookie
*cookie
;
270 struct device_node
*dp
;
271 unsigned long addr
, *base
;
272 unsigned short pci_command
;
276 dp
= of_find_node_by_path("/");
277 for (sp
= ebus_blacklist
; sp
->esname
!= NULL
; sp
++) {
278 if (strcmp(dp
->name
, sp
->esname
) == 0) {
279 ebus_blackp
= sp
->ipt
;
284 pdev
= pci_get_device(PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_EBUS
, NULL
);
288 cookie
= pdev
->sysdata
;
289 dp
= cookie
->prom_node
;
291 ebus_chain
= ebus
= (struct linux_ebus
*)
292 ebus_alloc(sizeof(struct linux_ebus
));
296 struct device_node
*nd
;
298 ebus
->prom_node
= dp
;
300 ebus
->parent
= pbm
= cookie
->pbm
;
302 /* Enable BUS Master. */
303 pci_read_config_word(pdev
, PCI_COMMAND
, &pci_command
);
304 pci_command
|= PCI_COMMAND_MASTER
;
305 pci_write_config_word(pdev
, PCI_COMMAND
, pci_command
);
307 regs
= of_get_property(dp
, "reg", &len
);
309 prom_printf("%s: can't find reg property\n",
313 nreg
= len
/ sizeof(struct linux_prom_pci_registers
);
315 base
= &ebus
->self
->resource
[0].start
;
316 for (reg
= 0; reg
< nreg
; reg
++) {
317 if (!(regs
[reg
].which_io
& 0x03000000))
320 addr
= regs
[reg
].phys_lo
;
328 ebus
->devices
= (struct linux_ebus_device
*)
329 ebus_alloc(sizeof(struct linux_ebus_device
));
333 dev
->children
= NULL
;
335 fill_ebus_device(nd
, dev
);
337 while ((nd
= nd
->sibling
) != NULL
) {
338 dev
->next
= (struct linux_ebus_device
*)
339 ebus_alloc(sizeof(struct linux_ebus_device
));
343 dev
->children
= NULL
;
345 fill_ebus_device(nd
, dev
);
349 pdev
= pci_get_device(PCI_VENDOR_ID_SUN
,
350 PCI_DEVICE_ID_SUN_EBUS
, pdev
);
354 cookie
= pdev
->sysdata
;
355 dp
= cookie
->prom_node
;
357 ebus
->next
= (struct linux_ebus
*)
358 ebus_alloc(sizeof(struct linux_ebus
));