blob: a2af5ed784c99bd12def0527f8dccecbbc120725 [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. Millerf4060c02006-12-28 21:43:51 -080025static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
David S. Millerdeb66c42007-02-28 18:01:38 -080027 struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
David S. Millerdeb66c42007-02-28 18:01:38 -080029 memcpy(&isa_dev->resource, &op->resource[0], sizeof(struct resource));
Linus Torvalds1da177e2005-04-16 15:20:36 -070030}
31
David S. Millerf4060c02006-12-28 21:43:51 -080032static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
David S. Miller2b1e5972006-06-29 15:07:37 -070034 struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
David S. Miller2b1e5972006-06-29 15:07:37 -070036 if (!op || !op->num_irqs) {
37 isa_dev->irq = PCI_IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 } else {
David S. Miller2b1e5972006-06-29 15:07:37 -070039 isa_dev->irq = op->irqs[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
43static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
44{
David S. Miller690c8fd2006-06-22 19:12:03 -070045 struct device_node *dp = parent_isa_dev->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
David S. Miller690c8fd2006-06-22 19:12:03 -070047 if (!dp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return;
49
50 printk(" ->");
David S. Miller690c8fd2006-06-22 19:12:03 -070051 while (dp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct sparc_isa_device *isa_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Yan Burman982c2062006-11-30 17:13:09 -080054 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 if (!isa_dev) {
56 fatal_err("cannot allocate child isa_dev");
57 prom_halt();
58 }
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 /* Link it in to parent. */
61 isa_dev->next = parent_isa_dev->child;
62 parent_isa_dev->child = isa_dev;
63
64 isa_dev->bus = parent_isa_dev->bus;
David S. Miller690c8fd2006-06-22 19:12:03 -070065 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
David S. Millerf4060c02006-12-28 21:43:51 -080067 isa_dev_get_resource(isa_dev);
68 isa_dev_get_irq(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 report_dev(isa_dev, 1);
71
David S. Miller690c8fd2006-06-22 19:12:03 -070072 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 }
74}
75
76static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
77{
David S. Miller690c8fd2006-06-22 19:12:03 -070078 struct device_node *dp = isa_br->prom_node->child;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
David S. Miller690c8fd2006-06-22 19:12:03 -070080 while (dp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 struct sparc_isa_device *isa_dev;
David S. Miller3d6e4702007-07-18 22:03:25 -070082 struct dev_archdata *sd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Yan Burman982c2062006-11-30 17:13:09 -080084 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 if (!isa_dev) {
David S. Millera2bd4fd2006-06-23 01:44:10 -070086 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
87 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
David S. Miller3d6e4702007-07-18 22:03:25 -070090 sd = &isa_dev->ofdev.dev.archdata;
91 sd->prom_node = dp;
92 sd->op = &isa_dev->ofdev;
David S. Millerad7ad572007-07-27 22:39:14 -070093 sd->iommu = isa_br->ofdev.dev.parent->archdata.iommu;
94 sd->stc = isa_br->ofdev.dev.parent->archdata.stc;
David S. Millerc1b1a5f2008-03-19 04:52:48 -070095 sd->numa_node = isa_br->ofdev.dev.parent->archdata.numa_node;
David S. Miller3d6e4702007-07-18 22:03:25 -070096
David S. Millera2bd4fd2006-06-23 01:44:10 -070097 isa_dev->ofdev.node = dp;
98 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
99 isa_dev->ofdev.dev.bus = &isa_bus_type;
David S. Millerf5ef9d12006-10-27 01:03:31 -0700100 sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700101
102 /* Register with core */
103 if (of_device_register(&isa_dev->ofdev) != 0) {
104 printk(KERN_DEBUG "isa: device registration error for %s!\n",
David S. Millerf5ef9d12006-10-27 01:03:31 -0700105 dp->path_component_name);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700106 kfree(isa_dev);
107 goto next_sibling;
108 }
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* Link it in. */
111 isa_dev->next = NULL;
112 if (isa_br->devices == NULL) {
113 isa_br->devices = isa_dev;
114 } else {
115 struct sparc_isa_device *tmp = isa_br->devices;
116
117 while (tmp->next)
118 tmp = tmp->next;
119
120 tmp->next = isa_dev;
121 }
122
123 isa_dev->bus = isa_br;
David S. Miller690c8fd2006-06-22 19:12:03 -0700124 isa_dev->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
David S. Millerf4060c02006-12-28 21:43:51 -0800126 isa_dev_get_resource(isa_dev);
127 isa_dev_get_irq(isa_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 report_dev(isa_dev, 0);
130
131 isa_fill_children(isa_dev);
132
133 printk("]");
134
David S. Millera2bd4fd2006-06-23 01:44:10 -0700135 next_sibling:
David S. Miller690c8fd2006-06-22 19:12:03 -0700136 dp = dp->sibling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138}
139
140void __init isa_init(void)
141{
142 struct pci_dev *pdev;
143 unsigned short vendor, device;
144 int index = 0;
145
146 vendor = PCI_VENDOR_ID_AL;
147 device = PCI_DEVICE_ID_AL_M1533;
148
149 pdev = NULL;
150 while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 struct sparc_isa_bridge *isa_br;
David S. Millera2bd4fd2006-06-23 01:44:10 -0700152 struct device_node *dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
David S. Millerdeb66c42007-02-28 18:01:38 -0800154 dp = pci_device_to_OF_node(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Yan Burman982c2062006-11-30 17:13:09 -0800156 isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 if (!isa_br) {
David S. Millera2bd4fd2006-06-23 01:44:10 -0700158 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
Julia Lawall55c45a32007-11-19 22:50:01 -0800159 pci_dev_put(pdev);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700160 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
David S. Millera2bd4fd2006-06-23 01:44:10 -0700163 isa_br->ofdev.node = dp;
164 isa_br->ofdev.dev.parent = &pdev->dev;
165 isa_br->ofdev.dev.bus = &isa_bus_type;
David S. Millerf5ef9d12006-10-27 01:03:31 -0700166 sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700167
168 /* Register with core */
169 if (of_device_register(&isa_br->ofdev) != 0) {
170 printk(KERN_DEBUG "isa: device registration error for %s!\n",
David S. Millerf5ef9d12006-10-27 01:03:31 -0700171 dp->path_component_name);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700172 kfree(isa_br);
Julia Lawall55c45a32007-11-19 22:50:01 -0800173 pci_dev_put(pdev);
David S. Millera2bd4fd2006-06-23 01:44:10 -0700174 return;
175 }
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* Link it in. */
178 isa_br->next = isa_chain;
179 isa_chain = isa_br;
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 isa_br->self = pdev;
182 isa_br->index = index++;
David S. Millerdeb66c42007-02-28 18:01:38 -0800183 isa_br->prom_node = dp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 printk("isa%d:", isa_br->index);
186
187 isa_fill_devices(isa_br);
188
189 printk("\n");
190 }
191}