1 #include <linux/kernel.h>
2 #include <linux/init.h>
4 #include <linux/slab.h>
8 struct sparc_isa_bridge *isa_chain;
10 static void __init fatal_err(const char *reason)
12 prom_printf("ISA: fatal error, %s.\n", reason);
15 static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
18 printk(" (%s)", isa_dev->prom_node->name);
20 printk(" [%s", isa_dev->prom_node->name);
23 static struct linux_prom_registers * __init
24 isa_dev_get_resource(struct sparc_isa_device *isa_dev)
26 struct linux_prom_registers *pregs;
27 unsigned long base, len;
30 pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
32 /* Only the first one is interesting. */
33 len = pregs[0].reg_size;
34 base = (((unsigned long)pregs[0].which_io << 32) |
35 (unsigned long)pregs[0].phys_addr);
36 base += isa_dev->bus->parent->io_space.start;
38 isa_dev->resource.start = base;
39 isa_dev->resource.end = (base + len - 1UL);
40 isa_dev->resource.flags = IORESOURCE_IO;
41 isa_dev->resource.name = isa_dev->prom_node->name;
43 request_resource(&isa_dev->bus->parent->io_space,
49 /* I can't believe they didn't put a real INO in the isa device
50 * interrupts property. The whole point of the OBP properties
51 * is to shield the kernel from IRQ routing details.
53 * The P1275 standard for ISA devices seems to also have been
56 * On later systems, an interrupt-map and interrupt-map-mask scheme
57 * akin to EBUS is used.
62 } grover_irq_table[] = {
63 { 1, 0x00 }, /* dma, unknown ino at this point */
64 { 2, 0x27 }, /* floppy */
65 { 3, 0x22 }, /* parallel */
66 { 4, 0x2b }, /* serial */
67 { 5, 0x25 }, /* acpi power management */
69 { 0, 0x00 } /* end of table */
72 static int __init isa_dev_get_irq_using_imap(struct sparc_isa_device *isa_dev,
73 struct sparc_isa_bridge *isa_br,
75 struct linux_prom_registers *reg)
77 struct linux_prom_ebus_intmap *imap;
78 struct linux_prom_ebus_intmap *imask;
79 unsigned int hi, lo, irq;
82 imap = of_get_property(isa_br->prom_node, "interrupt-map", &len);
85 n_imap = len / sizeof(imap[0]);
87 imask = of_get_property(isa_br->prom_node, "interrupt-map-mask", NULL);
91 hi = reg->which_io & imask->phys_hi;
92 lo = reg->phys_addr & imask->phys_lo;
93 irq = *interrupt & imask->interrupt;
94 for (i = 0; i < n_imap; i++) {
95 if ((imap[i].phys_hi == hi) &&
96 (imap[i].phys_lo == lo) &&
97 (imap[i].interrupt == irq)) {
98 *interrupt = imap[i].cinterrupt;
105 static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
106 struct linux_prom_registers *pregs)
110 irq_prop = of_getintprop_default(isa_dev->prom_node,
115 struct pci_controller_info *pcic;
116 struct pci_pbm_info *pbm;
119 if (of_find_property(isa_dev->bus->prom_node,
120 "interrupt-map", NULL)) {
121 if (!isa_dev_get_irq_using_imap(isa_dev,
128 for (i = 0; grover_irq_table[i].obp_irq != 0; i++) {
129 if (grover_irq_table[i].obp_irq == irq_prop) {
130 int ino = grover_irq_table[i].pci_ino;
142 pbm = isa_dev->bus->parent;
144 isa_dev->irq = pcic->irq_build(pbm, NULL, irq_prop);
149 isa_dev->irq = PCI_IRQ_NONE;
152 static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
154 struct device_node *dp = parent_isa_dev->prom_node->child;
161 struct linux_prom_registers *regs;
162 struct sparc_isa_device *isa_dev;
164 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
166 fatal_err("cannot allocate child isa_dev");
170 memset(isa_dev, 0, sizeof(*isa_dev));
172 /* Link it in to parent. */
173 isa_dev->next = parent_isa_dev->child;
174 parent_isa_dev->child = isa_dev;
176 isa_dev->bus = parent_isa_dev->bus;
177 isa_dev->prom_node = dp;
179 regs = isa_dev_get_resource(isa_dev);
180 isa_dev_get_irq(isa_dev, regs);
182 report_dev(isa_dev, 1);
188 static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
190 struct device_node *dp = isa_br->prom_node->child;
193 struct linux_prom_registers *regs;
194 struct sparc_isa_device *isa_dev;
196 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
198 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
202 memset(isa_dev, 0, sizeof(*isa_dev));
204 isa_dev->ofdev.node = dp;
205 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
206 isa_dev->ofdev.dev.bus = &isa_bus_type;
207 strcpy(isa_dev->ofdev.dev.bus_id, dp->path_component_name);
209 /* Register with core */
210 if (of_device_register(&isa_dev->ofdev) != 0) {
211 printk(KERN_DEBUG "isa: device registration error for %s!\n",
212 isa_dev->ofdev.dev.bus_id);
218 isa_dev->next = NULL;
219 if (isa_br->devices == NULL) {
220 isa_br->devices = isa_dev;
222 struct sparc_isa_device *tmp = isa_br->devices;
230 isa_dev->bus = isa_br;
231 isa_dev->prom_node = dp;
233 regs = isa_dev_get_resource(isa_dev);
234 isa_dev_get_irq(isa_dev, regs);
236 report_dev(isa_dev, 0);
238 isa_fill_children(isa_dev);
247 void __init isa_init(void)
249 struct pci_dev *pdev;
250 unsigned short vendor, device;
253 vendor = PCI_VENDOR_ID_AL;
254 device = PCI_DEVICE_ID_AL_M1533;
257 while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
258 struct pcidev_cookie *pdev_cookie;
259 struct pci_pbm_info *pbm;
260 struct sparc_isa_bridge *isa_br;
261 struct device_node *dp;
263 pdev_cookie = pdev->sysdata;
265 printk("ISA: Warning, ISA bridge ignored due to "
266 "lack of OBP data.\n");
269 pbm = pdev_cookie->pbm;
270 dp = pdev_cookie->prom_node;
272 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
274 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
278 memset(isa_br, 0, sizeof(*isa_br));
280 isa_br->ofdev.node = dp;
281 isa_br->ofdev.dev.parent = &pdev->dev;
282 isa_br->ofdev.dev.bus = &isa_bus_type;
283 strcpy(isa_br->ofdev.dev.bus_id, dp->path_component_name);
285 /* Register with core */
286 if (of_device_register(&isa_br->ofdev) != 0) {
287 printk(KERN_DEBUG "isa: device registration error for %s!\n",
288 isa_br->ofdev.dev.bus_id);
294 isa_br->next = isa_chain;
297 isa_br->parent = pbm;
299 isa_br->index = index++;
300 isa_br->prom_node = pdev_cookie->prom_node;
302 printk("isa%d:", isa_br->index);
304 isa_fill_devices(isa_br);