blob: 0f3aec72ef5fc3161530997853502f4d985e5052 [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
75 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
76 if (!isa_dev) {
77 fatal_err("cannot allocate child isa_dev");
78 prom_halt();
79 }
80
81 memset(isa_dev, 0, sizeof(*isa_dev));
82
83 /* Link it in to parent. */
84 isa_dev->next = parent_isa_dev->child;
85 parent_isa_dev->child = isa_dev;
86
87 isa_dev->bus = parent_isa_dev->bus;
David S. Miller690c8fd2006-06-22 19:12:03 -070088 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
David S. Miller690c8fd2006-06-22 19:12:03 -070090 regs = isa_dev_get_resource(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 isa_dev_get_irq(isa_dev, regs);
92
93 report_dev(isa_dev, 1);
94
David S. Miller690c8fd2006-06-22 19:12:03 -070095 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
97}
98
99static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
100{
David S. Miller690c8fd2006-06-22 19:12:03 -0700101 struct device_node *dp = isa_br->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
David S. Miller690c8fd2006-06-22 19:12:03 -0700103 while (dp) {
104 struct linux_prom_registers *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 struct sparc_isa_device *isa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL);
108 if (!isa_dev) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700109 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
110 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
112
113 memset(isa_dev, 0, sizeof(*isa_dev));
114
David S. Millera2bd4fd2006-06-23 01:44:10 -0700115 isa_dev->ofdev.node = dp;
116 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
117 isa_dev->ofdev.dev.bus = &isa_bus_type;
118 strcpy(isa_dev->ofdev.dev.bus_id, dp->path_component_name);
119
120 /* Register with core */
121 if (of_device_register(&isa_dev->ofdev) != 0) {
122 printk(KERN_DEBUG "isa: device registration error for %s!\n",
123 isa_dev->ofdev.dev.bus_id);
124 kfree(isa_dev);
125 goto next_sibling;
126 }
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* Link it in. */
129 isa_dev->next = NULL;
130 if (isa_br->devices == NULL) {
131 isa_br->devices = isa_dev;
132 } else {
133 struct sparc_isa_device *tmp = isa_br->devices;
134
135 while (tmp->next)
136 tmp = tmp->next;
137
138 tmp->next = isa_dev;
139 }
140
141 isa_dev->bus = isa_br;
David S. Miller690c8fd2006-06-22 19:12:03 -0700142 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
David S. Miller690c8fd2006-06-22 19:12:03 -0700144 regs = isa_dev_get_resource(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 isa_dev_get_irq(isa_dev, regs);
146
147 report_dev(isa_dev, 0);
148
149 isa_fill_children(isa_dev);
150
151 printk("]");
152
David S. Millera2bd4fd2006-06-23 01:44:10 -0700153 next_sibling:
David S. Miller690c8fd2006-06-22 19:12:03 -0700154 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 }
156}
157
158void __init isa_init(void)
159{
160 struct pci_dev *pdev;
161 unsigned short vendor, device;
162 int index = 0;
163
164 vendor = PCI_VENDOR_ID_AL;
165 device = PCI_DEVICE_ID_AL_M1533;
166
167 pdev = NULL;
168 while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
169 struct pcidev_cookie *pdev_cookie;
170 struct pci_pbm_info *pbm;
171 struct sparc_isa_bridge *isa_br;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700172 struct device_node *dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 pdev_cookie = pdev->sysdata;
175 if (!pdev_cookie) {
176 printk("ISA: Warning, ISA bridge ignored due to "
177 "lack of OBP data.\n");
178 continue;
179 }
180 pbm = pdev_cookie->pbm;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700181 dp = pdev_cookie->prom_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL);
184 if (!isa_br) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700185 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
186 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 memset(isa_br, 0, sizeof(*isa_br));
190
David S. Millera2bd4fd2006-06-23 01:44:10 -0700191 isa_br->ofdev.node = dp;
192 isa_br->ofdev.dev.parent = &pdev->dev;
193 isa_br->ofdev.dev.bus = &isa_bus_type;
194 strcpy(isa_br->ofdev.dev.bus_id, dp->path_component_name);
195
196 /* Register with core */
197 if (of_device_register(&isa_br->ofdev) != 0) {
198 printk(KERN_DEBUG "isa: device registration error for %s!\n",
199 isa_br->ofdev.dev.bus_id);
200 kfree(isa_br);
201 return;
202 }
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 /* Link it in. */
205 isa_br->next = isa_chain;
206 isa_chain = isa_br;
207
208 isa_br->parent = pbm;
209 isa_br->self = pdev;
210 isa_br->index = index++;
David S. Miller690c8fd2006-06-22 19:12:03 -0700211 isa_br->prom_node = pdev_cookie->prom_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 printk("isa%d:", isa_br->index);
214
215 isa_fill_devices(isa_br);
216
217 printk("\n");
218 }
219}