blob: ad1c4f55420f8b2f456a4ba559a33336b3a55393 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/kernel.h>
2#include <linux/init.h>
3#include <linux/pci.h>
4#include <linux/slab.h>
5#include <asm/oplib.h>
David S. Miller2b1e5972006-06-29 15:07:37 -07006#include <asm/prom.h>
7#include <asm/of_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/isa.h>
9
10struct sparc_isa_bridge *isa_chain;
11
12static void __init fatal_err(const char *reason)
13{
14 prom_printf("ISA: fatal error, %s.\n", reason);
15}
16
17static void __init report_dev(struct sparc_isa_device *isa_dev, int child)
18{
19 if (child)
David S. Miller690c8fd2006-06-22 19:12:03 -070020 printk(" (%s)", isa_dev->prom_node->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 else
David S. Miller690c8fd2006-06-22 19:12:03 -070022 printk(" [%s", isa_dev->prom_node->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023}
24
David S. Miller690c8fd2006-06-22 19:12:03 -070025static struct linux_prom_registers * __init
26isa_dev_get_resource(struct sparc_isa_device *isa_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
David S. Miller690c8fd2006-06-22 19:12:03 -070028 struct linux_prom_registers *pregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 unsigned long base, len;
30 int prop_len;
31
David S. Miller690c8fd2006-06-22 19:12:03 -070032 pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
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;
39
40 isa_dev->resource.start = base;
41 isa_dev->resource.end = (base + len - 1UL);
42 isa_dev->resource.flags = IORESOURCE_IO;
David S. Miller690c8fd2006-06-22 19:12:03 -070043 isa_dev->resource.name = isa_dev->prom_node->name;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 request_resource(&isa_dev->bus->parent->io_space,
46 &isa_dev->resource);
David S. Miller690c8fd2006-06-22 19:12:03 -070047
48 return pregs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev,
52 struct linux_prom_registers *pregs)
53{
David S. Miller2b1e5972006-06-29 15:07:37 -070054 struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
David S. Miller2b1e5972006-06-29 15:07:37 -070056 if (!op || !op->num_irqs) {
57 isa_dev->irq = PCI_IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 } else {
David S. Miller2b1e5972006-06-29 15:07:37 -070059 isa_dev->irq = op->irqs[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
63static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
64{
David S. Miller690c8fd2006-06-22 19:12:03 -070065 struct device_node *dp = parent_isa_dev->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
David S. Miller690c8fd2006-06-22 19:12:03 -070067 if (!dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 return;
69
70 printk(" ->");
David S. Miller690c8fd2006-06-22 19:12:03 -070071 while (dp) {
72 struct linux_prom_registers *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 struct sparc_isa_device *isa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Yan Burman982c2062006-11-30 17:13:09 -080075 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 if (!isa_dev) {
77 fatal_err("cannot allocate child isa_dev");
78 prom_halt();
79 }
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* Link it in to parent. */
82 isa_dev->next = parent_isa_dev->child;
83 parent_isa_dev->child = isa_dev;
84
85 isa_dev->bus = parent_isa_dev->bus;
David S. Miller690c8fd2006-06-22 19:12:03 -070086 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
David S. Miller690c8fd2006-06-22 19:12:03 -070088 regs = isa_dev_get_resource(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 isa_dev_get_irq(isa_dev, regs);
90
91 report_dev(isa_dev, 1);
92
David S. Miller690c8fd2006-06-22 19:12:03 -070093 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95}
96
97static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
98{
David S. Miller690c8fd2006-06-22 19:12:03 -070099 struct device_node *dp = isa_br->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
David S. Miller690c8fd2006-06-22 19:12:03 -0700101 while (dp) {
102 struct linux_prom_registers *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 struct sparc_isa_device *isa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Yan Burman982c2062006-11-30 17:13:09 -0800105 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if (!isa_dev) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700107 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
108 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110
David S. Millera2bd4fd2006-06-23 01:44:10 -0700111 isa_dev->ofdev.node = dp;
112 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
113 isa_dev->ofdev.dev.bus = &isa_bus_type;
David S. Millerf5ef9d12006-10-27 01:03:31 -0700114 sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700115
116 /* Register with core */
117 if (of_device_register(&isa_dev->ofdev) != 0) {
118 printk(KERN_DEBUG "isa: device registration error for %s!\n",
David S. Millerf5ef9d12006-10-27 01:03:31 -0700119 dp->path_component_name);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700120 kfree(isa_dev);
121 goto next_sibling;
122 }
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* Link it in. */
125 isa_dev->next = NULL;
126 if (isa_br->devices == NULL) {
127 isa_br->devices = isa_dev;
128 } else {
129 struct sparc_isa_device *tmp = isa_br->devices;
130
131 while (tmp->next)
132 tmp = tmp->next;
133
134 tmp->next = isa_dev;
135 }
136
137 isa_dev->bus = isa_br;
David S. Miller690c8fd2006-06-22 19:12:03 -0700138 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
David S. Miller690c8fd2006-06-22 19:12:03 -0700140 regs = isa_dev_get_resource(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 isa_dev_get_irq(isa_dev, regs);
142
143 report_dev(isa_dev, 0);
144
145 isa_fill_children(isa_dev);
146
147 printk("]");
148
David S. Millera2bd4fd2006-06-23 01:44:10 -0700149 next_sibling:
David S. Miller690c8fd2006-06-22 19:12:03 -0700150 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152}
153
154void __init isa_init(void)
155{
156 struct pci_dev *pdev;
157 unsigned short vendor, device;
158 int index = 0;
159
160 vendor = PCI_VENDOR_ID_AL;
161 device = PCI_DEVICE_ID_AL_M1533;
162
163 pdev = NULL;
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;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700168 struct device_node *dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 pdev_cookie = pdev->sysdata;
171 if (!pdev_cookie) {
172 printk("ISA: Warning, ISA bridge ignored due to "
173 "lack of OBP data.\n");
174 continue;
175 }
176 pbm = pdev_cookie->pbm;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700177 dp = pdev_cookie->prom_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Yan Burman982c2062006-11-30 17:13:09 -0800179 isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (!isa_br) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700181 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
182 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
184
David S. Millera2bd4fd2006-06-23 01:44:10 -0700185 isa_br->ofdev.node = dp;
186 isa_br->ofdev.dev.parent = &pdev->dev;
187 isa_br->ofdev.dev.bus = &isa_bus_type;
David S. Millerf5ef9d12006-10-27 01:03:31 -0700188 sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700189
190 /* Register with core */
191 if (of_device_register(&isa_br->ofdev) != 0) {
192 printk(KERN_DEBUG "isa: device registration error for %s!\n",
David S. Millerf5ef9d12006-10-27 01:03:31 -0700193 dp->path_component_name);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700194 kfree(isa_br);
195 return;
196 }
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 /* Link it in. */
199 isa_br->next = isa_chain;
200 isa_chain = isa_br;
201
202 isa_br->parent = pbm;
203 isa_br->self = pdev;
204 isa_br->index = index++;
David S. Miller690c8fd2006-06-22 19:12:03 -0700205 isa_br->prom_node = pdev_cookie->prom_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 printk("isa%d:", isa_br->index);
208
209 isa_fill_devices(isa_br);
210
211 printk("\n");
212 }
213}