1 /* $Id: ebus.c,v 1.4 1999/08/31 06:54:19 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/malloc.h>
15 #include <linux/string.h>
17 #include <asm/system.h>
22 #include <asm/oplib.h>
26 #undef DEBUG_FILL_EBUS_DEV
29 #define dprintk prom_printf
31 #define dprintk printk
34 struct linux_ebus
*ebus_chain
= 0;
36 #ifdef CONFIG_SUN_OPENPROMIO
37 extern int openprom_init(void);
39 #ifdef CONFIG_SPARCAUDIO
40 extern int sparcaudio_init(void);
42 #ifdef CONFIG_SUN_AUXIO
43 extern void auxio_probe(void);
45 #ifdef CONFIG_OBP_FLASH
46 extern int flash_init(void);
49 extern int envctrl_init(void);
52 /* We are together with pcic.c under CONFIG_PCI. */
53 extern unsigned int pcic_pin_to_irq(unsigned int, char *name
);
55 static inline unsigned long ebus_alloc(size_t size
)
57 return (unsigned long)kmalloc(size
, GFP_ATOMIC
);
60 void __init
fill_ebus_child(int node
, struct linux_prom_registers
*preg
,
61 struct linux_ebus_child
*dev
)
63 int regs
[PROMREG_MAX
];
64 int irqs
[PROMREG_MAX
];
68 dev
->prom_node
= node
;
69 prom_getstring(node
, "name", lbuf
, sizeof(lbuf
));
70 strcpy(dev
->prom_name
, lbuf
);
72 len
= prom_getproperty(node
, "reg", (void *)regs
, sizeof(regs
));
73 if (len
== -1) len
= 0;
74 dev
->num_addrs
= len
/ sizeof(regs
[0]);
76 for (i
= 0; i
< dev
->num_addrs
; i
++) {
77 if (regs
[i
] >= dev
->parent
->num_addrs
) {
78 prom_printf("UGH: property for %s was %d, need < %d\n",
79 dev
->prom_name
, len
, dev
->parent
->num_addrs
);
82 dev
->base_address
[i
] = dev
->parent
->base_address
[regs
[i
]];
86 * Houston, we have a problem...
87 * Sometimes PROM supplies absolutely meaningless properties.
88 * Still, we take what it gives since we have nothing better.
89 * Children of ebus may be wired on any input pin of PCIC.
91 len
= prom_getproperty(node
, "interrupts", (char *)&irqs
, sizeof(irqs
));
92 if ((len
== -1) || (len
== 0)) {
95 if (dev
->parent
->num_irqs
!= 0) {
97 dev
->irqs
[0] = dev
->parent
->irqs
[0];
98 /* P3 remove */ printk("EBUS: dev %s irq %d from parent\n", dev
->prom_name
, dev
->irqs
[0]);
101 dev
->num_irqs
= len
/ sizeof(irqs
[0]);
102 if (irqs
[0] == 0 || irqs
[0] >= 8) {
104 * XXX Zero is a valid pin number...
105 * This works as long as Ebus is not wired to INTA#.
107 printk("EBUS: %s got bad irq %d from PROM\n",
108 dev
->prom_name
, irqs
[0]);
112 dev
->irqs
[0] = pcic_pin_to_irq(irqs
[0], dev
->prom_name
);
113 /* P3 remove */ printk("EBUS: dev %s irq %d from PROM\n", dev
->prom_name
, dev
->irqs
[0]);
117 #ifdef DEBUG_FILL_EBUS_DEV
118 dprintk("child '%s': address%s\n", dev
->prom_name
,
119 dev
->num_addrs
> 1 ? "es" : "");
120 for (i
= 0; i
< dev
->num_addrs
; i
++)
121 dprintk(" %016lx\n", dev
->base_address
[i
]);
123 dprintk(" IRQ%s", dev
->num_irqs
> 1 ? "s" : "");
124 for (i
= 0; i
< dev
->num_irqs
; i
++)
125 dprintk(" %08x", dev
->irqs
[i
]);
131 void __init
fill_ebus_device(int node
, struct linux_ebus_device
*dev
)
133 struct linux_prom_registers regs
[PROMREG_MAX
];
134 struct linux_ebus_child
*child
;
135 int irqs
[PROMINTR_MAX
];
139 dev
->prom_node
= node
;
140 prom_getstring(node
, "name", lbuf
, sizeof(lbuf
));
141 strcpy(dev
->prom_name
, lbuf
);
143 len
= prom_getproperty(node
, "reg", (void *)regs
, sizeof(regs
));
144 if (len
% sizeof(struct linux_prom_registers
)) {
145 prom_printf("UGH: proplen for %s was %d, need multiple of %d\n",
147 (int)sizeof(struct linux_prom_registers
));
150 dev
->num_addrs
= len
/ sizeof(struct linux_prom_registers
);
152 for (i
= 0; i
< dev
->num_addrs
; i
++) {
154 * XXX Collect JE-1 PROM
156 * Example - JS-E with 3.11:
159 * 0x00000000, 0x0, 0x00000000, 0x0, 0x00000000,
160 * 0x82000010, 0x0, 0xf0000000, 0x0, 0x01000000,
161 * 0x82000014, 0x0, 0x38800000, 0x0, 0x00800000,
163 * 0x00, 0x00000000, 0x02000010, 0x0, 0x0, 0x01000000,
164 * 0x01, 0x01000000, 0x02000014, 0x0, 0x0, 0x00800000,
167 * 0x00000001, 0x00300060, 0x00000008,
168 * 0x00000001, 0x00300060, 0x00000008,
170 n
= regs
[i
].which_io
;
172 /* XXX This is copied from old JE-1 by Gleb. */
173 n
= (regs
[i
].which_io
- 0x10) >> 2;
178 dev
->base_address
[i
] = dev
->bus
->self
->base_address
[n
];
179 dev
->base_address
[i
] += regs
[i
].phys_addr
;
181 if (dev
->base_address
[i
]) {
182 dev
->base_address
[i
] =
183 (unsigned long)sparc_alloc_io (dev
->base_address
[i
], 0,
185 dev
->prom_name
, 0, 0);
188 * This release_region() screwes those who do sparc_alloc_io().
189 * Change drivers which do check_region(). See drivers/block/floppy.c.
191 /* Some drivers call 'check_region', so we release it */
192 release_region(dev
->base_address
[i
] & PAGE_MASK
, PAGE_SIZE
);
195 if (dev
->base_address
[i
] == 0 ) {
196 panic("ebus: unable sparc_alloc_io for dev %s",
202 len
= prom_getproperty(node
, "interrupts", (char *)&irqs
, sizeof(irqs
));
203 if ((len
== -1) || (len
== 0)) {
205 if ((dev
->irqs
[0] = dev
->bus
->self
->irq
) != 0) {
207 /* P3 remove */ printk("EBUS: child %s irq %d from parent\n", dev
->prom_name
, dev
->irqs
[0]);
210 dev
->num_irqs
= 1; /* dev->num_irqs = len / sizeof(irqs[0]); */
211 if (irqs
[0] == 0 || irqs
[0] >= 8) {
212 /* See above for the parent. XXX */
213 printk("EBUS: %s got bad irq %d from PROM\n",
214 dev
->prom_name
, irqs
[0]);
218 dev
->irqs
[0] = pcic_pin_to_irq(irqs
[0], dev
->prom_name
);
219 /* P3 remove */ printk("EBUS: child %s irq %d from PROM\n", dev
->prom_name
, dev
->irqs
[0]);
223 #ifdef DEBUG_FILL_EBUS_DEV
224 dprintk("'%s': address%s\n", dev
->prom_name
,
225 dev
->num_addrs
> 1 ? "es" : "");
226 for (i
= 0; i
< dev
->num_addrs
; i
++)
227 dprintk(" %016lx\n", dev
->base_address
[i
]);
229 dprintk(" IRQ%s", dev
->num_irqs
> 1 ? "s" : "");
230 for (i
= 0; i
< dev
->num_irqs
; i
++)
231 dprintk(" %08x", dev
->irqs
[i
]);
235 if ((node
= prom_getchild(node
))) {
236 dev
->children
= (struct linux_ebus_child
*)
237 ebus_alloc(sizeof(struct linux_ebus_child
));
239 child
= dev
->children
;
242 child
->bus
= dev
->bus
;
243 fill_ebus_child(node
, ®s
[0], child
);
245 while ((node
= prom_getsibling(node
))) {
246 child
->next
= (struct linux_ebus_child
*)
247 ebus_alloc(sizeof(struct linux_ebus_child
));
252 child
->bus
= dev
->bus
;
253 fill_ebus_child(node
, ®s
[0], child
);
258 void __init
ebus_init(void)
260 struct linux_prom_pci_registers regs
[PROMREG_MAX
];
261 struct linux_pbm_info
*pbm
;
262 struct linux_ebus_device
*dev
;
263 struct linux_ebus
*ebus
;
264 struct pci_dev
*pdev
;
265 struct pcidev_cookie
*cookie
;
267 unsigned long addr
, *base
;
268 unsigned short pci_command
;
276 pdev
= pci_find_device(PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_EBUS
, 0);
279 dprintk("ebus: No EBus's found.\n");
283 cookie
= pdev
->sysdata
;
284 ebusnd
= cookie
->prom_node
;
286 ebus_chain
= ebus
= (struct linux_ebus
*)
287 ebus_alloc(sizeof(struct linux_ebus
));
292 dprintk("ebus%d:", num_ebus
);
295 prom_getstring(ebusnd
, "name", lbuf
, sizeof(lbuf
));
296 ebus
->prom_node
= ebusnd
;
297 strcpy(ebus
->prom_name
, lbuf
);
299 ebus
->parent
= pbm
= cookie
->pbm
;
301 /* Enable BUS Master. */
302 pci_read_config_word(pdev
, PCI_COMMAND
, &pci_command
);
303 pci_command
|= PCI_COMMAND_MASTER
;
304 pci_write_config_word(pdev
, PCI_COMMAND
, pci_command
);
306 len
= prom_getproperty(ebusnd
, "reg", (void *)regs
,
308 if (len
== 0 || len
== -1) {
309 prom_printf("%s: can't find reg property\n",
313 nreg
= len
/ sizeof(struct linux_prom_pci_registers
);
315 base
= &ebus
->self
->base_address
[0];
316 for (reg
= 0; reg
< nreg
; reg
++) {
317 if (!(regs
[reg
].which_io
& 0x03000000))
320 addr
= regs
[reg
].phys_lo
;
323 dprintk(" %lx[%x]", addr
, regs
[reg
].size_lo
);
330 nd
= prom_getchild(ebusnd
);
334 ebus
->devices
= (struct linux_ebus_device
*)
335 ebus_alloc(sizeof(struct linux_ebus_device
));
341 fill_ebus_device(nd
, dev
);
343 while ((nd
= prom_getsibling(nd
))) {
344 dev
->next
= (struct linux_ebus_device
*)
345 ebus_alloc(sizeof(struct linux_ebus_device
));
351 fill_ebus_device(nd
, dev
);
355 pdev
= pci_find_device(PCI_VENDOR_ID_SUN
,
356 PCI_DEVICE_ID_SUN_EBUS
, pdev
);
360 cookie
= pdev
->sysdata
;
361 ebusnd
= cookie
->prom_node
;
363 ebus
->next
= (struct linux_ebus
*)
364 ebus_alloc(sizeof(struct linux_ebus
));
370 #ifdef CONFIG_SUN_OPENPROMIO
374 #ifdef CONFIG_SPARCAUDIO
377 #ifdef CONFIG_SUN_BPP
380 #ifdef CONFIG_SUN_AUXIO
383 #ifdef CONFIG_ENVCTRL
386 #ifdef CONFIG_OBP_FLASH