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/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>
21 #include <asm/oplib.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
);
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 static 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
);
86 static void __init
fill_ebus_child(struct device_node
*dp
,
87 struct linux_ebus_child
*dev
)
94 regs
= of_get_property(dp
, "reg", &len
);
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
);
108 dev
->resource
[i
].start
=
109 dev
->parent
->resource
[regs
[i
]].start
;
112 for (i
= 0; i
< PROMINTR_MAX
; i
++)
113 dev
->irqs
[i
] = PCI_IRQ_NONE
;
115 if ((dev
->irqs
[0] = ebus_blacklist_irq(dev
->prom_node
->name
)) != 0) {
118 irqs
= of_get_property(dp
, "interrupts", &len
);
122 if (dev
->parent
->num_irqs
!= 0) {
124 dev
->irqs
[0] = dev
->parent
->irqs
[0];
127 dev
->num_irqs
= len
/ sizeof(irqs
[0]);
128 if (irqs
[0] == 0 || irqs
[0] >= 8) {
130 * XXX Zero is a valid pin number...
131 * This works as long as Ebus is not wired
134 printk("EBUS: %s got bad irq %d from PROM\n",
135 dev
->prom_node
->name
, irqs
[0]);
140 pcic_pin_to_irq(irqs
[0],
141 dev
->prom_node
->name
);
147 static void __init
fill_ebus_device(struct device_node
*dp
,
148 struct linux_ebus_device
*dev
)
150 const struct linux_prom_registers
*regs
;
151 struct linux_ebus_child
*child
;
152 struct dev_archdata
*sd
;
155 unsigned long baseaddr
;
159 regs
= of_get_property(dp
, "reg", &len
);
162 if (len
% sizeof(struct linux_prom_registers
)) {
163 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
164 dev
->prom_node
->name
, len
,
165 (int)sizeof(struct linux_prom_registers
));
168 dev
->num_addrs
= len
/ sizeof(struct linux_prom_registers
);
170 for (i
= 0; i
< dev
->num_addrs
; i
++) {
172 * XXX Collect JE-1 PROM
174 * Example - JS-E with 3.11:
177 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
178 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
179 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
181 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
182 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
185 * 0x00000001, 0x00300060, 0x00000008,
186 * 0x00000001, 0x00300060, 0x00000008,
188 n
= regs
[i
].which_io
;
190 /* XXX This is copied from old JE-1 by Gleb. */
191 n
= (regs
[i
].which_io
- 0x10) >> 2;
197 * XXX Now as we have regions, why don't we make an on-demand allocation...
199 dev
->resource
[i
].start
= 0;
200 if ((baseaddr
= dev
->bus
->self
->resource
[n
].start
+
201 regs
[i
].phys_addr
) != 0) {
202 /* dev->resource[i].name = dev->prom_name; */
203 if ((baseaddr
= (unsigned long) ioremap(baseaddr
,
204 regs
[i
].reg_size
)) == 0) {
205 panic("ebus: unable to remap dev %s",
206 dev
->prom_node
->name
);
209 dev
->resource
[i
].start
= baseaddr
; /* XXX Unaligned */
212 for (i
= 0; i
< PROMINTR_MAX
; i
++)
213 dev
->irqs
[i
] = PCI_IRQ_NONE
;
215 if ((dev
->irqs
[0] = ebus_blacklist_irq(dev
->prom_node
->name
)) != 0) {
218 irqs
= of_get_property(dp
, "interrupts", &len
);
221 if ((dev
->irqs
[0] = dev
->bus
->self
->irq
) != 0) {
223 /* P3 */ /* printk("EBUS: child %s irq %d from parent\n", dev->prom_name, dev->irqs[0]); */
226 dev
->num_irqs
= 1; /* dev->num_irqs = len / sizeof(irqs[0]); */
227 if (irqs
[0] == 0 || irqs
[0] >= 8) {
228 /* See above for the parent. XXX */
229 printk("EBUS: %s got bad irq %d from PROM\n",
230 dev
->prom_node
->name
, irqs
[0]);
235 pcic_pin_to_irq(irqs
[0],
236 dev
->prom_node
->name
);
241 sd
= &dev
->ofdev
.dev
.archdata
;
243 sd
->op
= &dev
->ofdev
;
244 sd
->iommu
= dev
->bus
->ofdev
.dev
.parent
->archdata
.iommu
;
246 dev
->ofdev
.node
= dp
;
247 dev
->ofdev
.dev
.parent
= &dev
->bus
->ofdev
.dev
;
248 dev
->ofdev
.dev
.bus
= &ebus_bus_type
;
249 sprintf(dev
->ofdev
.dev
.bus_id
, "ebus[%08x]", dp
->node
);
251 /* Register with core */
252 if (of_device_register(&dev
->ofdev
) != 0)
253 printk(KERN_DEBUG
"ebus: device registration error for %s!\n",
254 dp
->path_component_name
);
256 if ((dp
= dp
->child
) != NULL
) {
257 dev
->children
= (struct linux_ebus_child
*)
258 ebus_alloc(sizeof(struct linux_ebus_child
));
260 child
= dev
->children
;
263 child
->bus
= dev
->bus
;
264 fill_ebus_child(dp
, child
);
266 while ((dp
= dp
->sibling
) != NULL
) {
267 child
->next
= (struct linux_ebus_child
*)
268 ebus_alloc(sizeof(struct linux_ebus_child
));
273 child
->bus
= dev
->bus
;
274 fill_ebus_child(dp
, child
);
279 void __init
ebus_init(void)
281 const struct linux_prom_pci_registers
*regs
;
282 struct linux_pbm_info
*pbm
;
283 struct linux_ebus_device
*dev
;
284 struct linux_ebus
*ebus
;
285 struct ebus_system_entry
*sp
;
286 struct pci_dev
*pdev
;
287 struct pcidev_cookie
*cookie
;
288 struct device_node
*dp
;
290 unsigned short pci_command
;
294 dp
= of_find_node_by_path("/");
295 for (sp
= ebus_blacklist
; sp
->esname
!= NULL
; sp
++) {
296 if (strcmp(dp
->name
, sp
->esname
) == 0) {
297 ebus_blackp
= sp
->ipt
;
302 pdev
= pci_get_device(PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_EBUS
, NULL
);
306 cookie
= pdev
->sysdata
;
307 dp
= cookie
->prom_node
;
309 ebus_chain
= ebus
= (struct linux_ebus
*)
310 ebus_alloc(sizeof(struct linux_ebus
));
314 struct device_node
*nd
;
316 ebus
->prom_node
= dp
;
318 ebus
->parent
= pbm
= cookie
->pbm
;
320 /* Enable BUS Master. */
321 pci_read_config_word(pdev
, PCI_COMMAND
, &pci_command
);
322 pci_command
|= PCI_COMMAND_MASTER
;
323 pci_write_config_word(pdev
, PCI_COMMAND
, pci_command
);
325 regs
= of_get_property(dp
, "reg", &len
);
327 prom_printf("%s: can't find reg property\n",
331 nreg
= len
/ sizeof(struct linux_prom_pci_registers
);
333 p
= &ebus
->self
->resource
[0];
334 for (reg
= 0; reg
< nreg
; reg
++) {
335 if (!(regs
[reg
].which_io
& 0x03000000))
338 (p
++)->start
= regs
[reg
].phys_lo
;
341 ebus
->ofdev
.node
= dp
;
342 ebus
->ofdev
.dev
.parent
= &pdev
->dev
;
343 ebus
->ofdev
.dev
.bus
= &ebus_bus_type
;
344 sprintf(ebus
->ofdev
.dev
.bus_id
, "ebus%d", num_ebus
);
346 /* Register with core */
347 if (of_device_register(&ebus
->ofdev
) != 0)
348 printk(KERN_DEBUG
"ebus: device registration error for %s!\n",
349 dp
->path_component_name
);
356 ebus
->devices
= (struct linux_ebus_device
*)
357 ebus_alloc(sizeof(struct linux_ebus_device
));
361 dev
->children
= NULL
;
363 fill_ebus_device(nd
, dev
);
365 while ((nd
= nd
->sibling
) != NULL
) {
366 dev
->next
= (struct linux_ebus_device
*)
367 ebus_alloc(sizeof(struct linux_ebus_device
));
371 dev
->children
= NULL
;
373 fill_ebus_device(nd
, dev
);
377 pdev
= pci_get_device(PCI_VENDOR_ID_SUN
,
378 PCI_DEVICE_ID_SUN_EBUS
, pdev
);
382 cookie
= pdev
->sysdata
;
383 dp
= cookie
->prom_node
;
385 ebus
->next
= (struct linux_ebus
*)
386 ebus_alloc(sizeof(struct linux_ebus
));