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>
25 struct linux_ebus
*ebus_chain
= 0;
27 /* We are together with pcic.c under CONFIG_PCI. */
28 extern unsigned int pcic_pin_to_irq(unsigned int, char *name
);
32 * Here we list PROMs and systems that are known to supply crap as IRQ numbers.
34 struct ebus_device_irq
{
39 struct ebus_system_entry
{
41 struct ebus_device_irq
*ipt
;
44 static struct ebus_device_irq je1_1
[] = {
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
},
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
);
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
];
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
);
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) {
116 } else if ((len
= prom_getproperty(node
, "interrupts",
117 (char *)&irqs
, sizeof(irqs
))) == -1 || len
== 0) {
120 if (dev
->parent
->num_irqs
!= 0) {
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]); */
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]);
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
];
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",
159 (int)sizeof(struct linux_prom_registers
));
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:
171 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
172 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
173 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
175 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
176 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
179 * 0x00000001, 0x00300060, 0x00000008,
180 * 0x00000001, 0x00300060, 0x00000008,
182 n
= regs
[i
].which_io
;
184 /* XXX This is copied from old JE-1 by Gleb. */
185 n
= (regs
[i
].which_io
- 0x10) >> 2;
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",
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) {
211 } else if ((len
= prom_getproperty(node
, "interrupts",
212 (char *)&irqs
, sizeof(irqs
))) == -1 || len
== 0) {
214 if ((dev
->irqs
[0] = dev
->bus
->self
->irq
) != 0) {
216 /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
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]);
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
;
238 child
->bus
= dev
->bus
;
239 fill_ebus_child(node
, ®s
[0], child
);
241 while ((node
= prom_getsibling(node
)) != 0) {
242 child
->next
= (struct linux_ebus_child
*)
243 ebus_alloc(sizeof(struct linux_ebus_child
));
248 child
->bus
= dev
->bus
;
249 fill_ebus_child(node
, ®s
[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
;
264 unsigned long addr
, *base
;
265 unsigned short pci_command
;
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
;
278 pdev
= pci_get_device(PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_EBUS
, 0);
282 cookie
= pdev
->sysdata
;
283 ebusnd
= cookie
->prom_node
;
285 ebus_chain
= ebus
= (struct linux_ebus
*)
286 ebus_alloc(sizeof(struct linux_ebus
));
291 prom_getstring(ebusnd
, "name", lbuf
, sizeof(lbuf
));
292 ebus
->prom_node
= ebusnd
;
293 strcpy(ebus
->prom_name
, lbuf
);
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
,
304 if (len
== 0 || len
== -1) {
305 prom_printf("%s: can't find reg property\n",
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))
316 addr
= regs
[reg
].phys_lo
;
320 nd
= prom_getchild(ebusnd
);
324 ebus
->devices
= (struct linux_ebus_device
*)
325 ebus_alloc(sizeof(struct linux_ebus_device
));
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
));
341 fill_ebus_device(nd
, dev
);
345 pdev
= pci_get_device(PCI_VENDOR_ID_SUN
,
346 PCI_DEVICE_ID_SUN_EBUS
, pdev
);
350 cookie
= pdev
->sysdata
;
351 ebusnd
= cookie
->prom_node
;
353 ebus
->next
= (struct linux_ebus
*)
354 ebus_alloc(sizeof(struct linux_ebus
));