1 #include <linux/kernel.h>
2 #include <linux/init.h>
4 #include <linux/slab.h>
7 #include <asm/of_device.h>
10 struct sparc_isa_bridge *isa_chain;
12 static void __init fatal_err(const char *reason)
14 prom_printf("ISA: fatal error, %s.\n", reason);
17 static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
20 printk(" (%s)", isa_dev->prom_node->name);
22 printk(" [%s", isa_dev->prom_node->name);
25 static struct linux_prom_registers * __init
26 isa_dev_get_resource(struct sparc_isa_device *isa_dev)
28 struct linux_prom_registers *pregs;
29 unsigned long base, len;
32 pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
34 /* Only the first one is interesting. */
35 len = pregs[0].reg_size;
36 base = (((unsigned long)pregs[0].which_io << 32) |
37 (unsigned long)pregs[0].phys_addr);
38 base += isa_dev->bus->parent->io_space.start;
40 isa_dev->resource.start = base;
41 isa_dev->resource.end = (base + len - 1UL);
42 isa_dev->resource.flags = IORESOURCE_IO;
43 isa_dev->resource.name = isa_dev->prom_node->name;
45 request_resource(&isa_dev->bus->parent->io_space,
51 static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
52 struct linux_prom_registers *pregs)
54 struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
56 if (!op || !op->num_irqs) {
57 isa_dev->irq = PCI_IRQ_NONE;
59 isa_dev->irq = op->irqs[0];
63 static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
65 struct device_node *dp = parent_isa_dev->prom_node->child;
72 struct linux_prom_registers *regs;
73 struct sparc_isa_device *isa_dev;
75 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
77 fatal_err("cannot allocate child isa_dev");
81 /* Link it in to parent. */
82 isa_dev->next = parent_isa_dev->child;
83 parent_isa_dev->child = isa_dev;
85 isa_dev->bus = parent_isa_dev->bus;
86 isa_dev->prom_node = dp;
88 regs = isa_dev_get_resource(isa_dev);
89 isa_dev_get_irq(isa_dev, regs);
91 report_dev(isa_dev, 1);
97 static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
99 struct device_node *dp = isa_br->prom_node->child;
102 struct linux_prom_registers *regs;
103 struct sparc_isa_device *isa_dev;
105 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
107 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
111 isa_dev->ofdev.node = dp;
112 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
113 isa_dev->ofdev.dev.bus = &isa_bus_type;
114 sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
116 /* Register with core */
117 if (of_device_register(&isa_dev->ofdev) != 0) {
118 printk(KERN_DEBUG "isa: device registration error for %s!\n",
119 dp->path_component_name);
125 isa_dev->next = NULL;
126 if (isa_br->devices == NULL) {
127 isa_br->devices = isa_dev;
129 struct sparc_isa_device *tmp = isa_br->devices;
137 isa_dev->bus = isa_br;
138 isa_dev->prom_node = dp;
140 regs = isa_dev_get_resource(isa_dev);
141 isa_dev_get_irq(isa_dev, regs);
143 report_dev(isa_dev, 0);
145 isa_fill_children(isa_dev);
154 void __init isa_init(void)
156 struct pci_dev *pdev;
157 unsigned short vendor, device;
160 vendor = PCI_VENDOR_ID_AL;
161 device = PCI_DEVICE_ID_AL_M1533;
164 while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
165 struct pcidev_cookie *pdev_cookie;
166 struct pci_pbm_info *pbm;
167 struct sparc_isa_bridge *isa_br;
168 struct device_node *dp;
170 pdev_cookie = pdev->sysdata;
172 printk("ISA: Warning, ISA bridge ignored due to "
173 "lack of OBP data.\n");
176 pbm = pdev_cookie->pbm;
177 dp = pdev_cookie->prom_node;
179 isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
181 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
185 isa_br->ofdev.node = dp;
186 isa_br->ofdev.dev.parent = &pdev->dev;
187 isa_br->ofdev.dev.bus = &isa_bus_type;
188 sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
190 /* Register with core */
191 if (of_device_register(&isa_br->ofdev) != 0) {
192 printk(KERN_DEBUG "isa: device registration error for %s!\n",
193 dp->path_component_name);
199 isa_br->next = isa_chain;
202 isa_br->parent = pbm;
204 isa_br->index = index++;
205 isa_br->prom_node = pdev_cookie->prom_node;
207 printk("isa%d:", isa_br->index);
209 isa_fill_devices(isa_br);