Linux 2.6.21
[linux/fpc-iii.git] / arch / sparc64 / kernel / isa.c
blob98721a8f8619122b56852f7f8e99c1200a9cfada
1 #include <linux/kernel.h>
2 #include <linux/init.h>
3 #include <linux/pci.h>
4 #include <linux/slab.h>
5 #include <asm/oplib.h>
6 #include <asm/prom.h>
7 #include <asm/of_device.h>
8 #include <asm/isa.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)
19 if (child)
20 printk(" (%s)", isa_dev->prom_node->name);
21 else
22 printk(" [%s", isa_dev->prom_node->name);
25 static void __init isa_dev_get_resource(struct sparc_isa_device *isa_dev)
27 struct linux_prom_registers *pregs;
28 unsigned long base, len;
29 int prop_len;
31 pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len);
32 if (!pregs)
33 return;
35 /* Only the first one is interesting. */
36 len = pregs[0].reg_size;
37 base = (((unsigned long)pregs[0].which_io << 32) |
38 (unsigned long)pregs[0].phys_addr);
39 base += isa_dev->bus->parent->io_space.start;
41 isa_dev->resource.start = base;
42 isa_dev->resource.end = (base + len - 1UL);
43 isa_dev->resource.flags = IORESOURCE_IO;
44 isa_dev->resource.name = isa_dev->prom_node->name;
46 request_resource(&isa_dev->bus->parent->io_space,
47 &isa_dev->resource);
50 static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev)
52 struct of_device *op = of_find_device_by_node(isa_dev->prom_node);
54 if (!op || !op->num_irqs) {
55 isa_dev->irq = PCI_IRQ_NONE;
56 } else {
57 isa_dev->irq = op->irqs[0];
61 static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
63 struct device_node *dp = parent_isa_dev->prom_node->child;
65 if (!dp)
66 return;
68 printk(" ->");
69 while (dp) {
70 struct sparc_isa_device *isa_dev;
72 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
73 if (!isa_dev) {
74 fatal_err("cannot allocate child isa_dev");
75 prom_halt();
78 /* Link it in to parent. */
79 isa_dev->next = parent_isa_dev->child;
80 parent_isa_dev->child = isa_dev;
82 isa_dev->bus = parent_isa_dev->bus;
83 isa_dev->prom_node = dp;
85 isa_dev_get_resource(isa_dev);
86 isa_dev_get_irq(isa_dev);
88 report_dev(isa_dev, 1);
90 dp = dp->sibling;
94 static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
96 struct device_node *dp = isa_br->prom_node->child;
98 while (dp) {
99 struct sparc_isa_device *isa_dev;
101 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
102 if (!isa_dev) {
103 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
104 return;
107 isa_dev->ofdev.node = dp;
108 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
109 isa_dev->ofdev.dev.bus = &isa_bus_type;
110 sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node);
112 /* Register with core */
113 if (of_device_register(&isa_dev->ofdev) != 0) {
114 printk(KERN_DEBUG "isa: device registration error for %s!\n",
115 dp->path_component_name);
116 kfree(isa_dev);
117 goto next_sibling;
120 /* Link it in. */
121 isa_dev->next = NULL;
122 if (isa_br->devices == NULL) {
123 isa_br->devices = isa_dev;
124 } else {
125 struct sparc_isa_device *tmp = isa_br->devices;
127 while (tmp->next)
128 tmp = tmp->next;
130 tmp->next = isa_dev;
133 isa_dev->bus = isa_br;
134 isa_dev->prom_node = dp;
136 isa_dev_get_resource(isa_dev);
137 isa_dev_get_irq(isa_dev);
139 report_dev(isa_dev, 0);
141 isa_fill_children(isa_dev);
143 printk("]");
145 next_sibling:
146 dp = dp->sibling;
150 void __init isa_init(void)
152 struct pci_dev *pdev;
153 unsigned short vendor, device;
154 int index = 0;
156 vendor = PCI_VENDOR_ID_AL;
157 device = PCI_DEVICE_ID_AL_M1533;
159 pdev = NULL;
160 while ((pdev = pci_get_device(vendor, device, pdev)) != NULL) {
161 struct pcidev_cookie *pdev_cookie;
162 struct pci_pbm_info *pbm;
163 struct sparc_isa_bridge *isa_br;
164 struct device_node *dp;
166 pdev_cookie = pdev->sysdata;
167 if (!pdev_cookie) {
168 printk("ISA: Warning, ISA bridge ignored due to "
169 "lack of OBP data.\n");
170 continue;
172 pbm = pdev_cookie->pbm;
173 dp = pdev_cookie->prom_node;
175 isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
176 if (!isa_br) {
177 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
178 return;
181 isa_br->ofdev.node = dp;
182 isa_br->ofdev.dev.parent = &pdev->dev;
183 isa_br->ofdev.dev.bus = &isa_bus_type;
184 sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index);
186 /* Register with core */
187 if (of_device_register(&isa_br->ofdev) != 0) {
188 printk(KERN_DEBUG "isa: device registration error for %s!\n",
189 dp->path_component_name);
190 kfree(isa_br);
191 return;
194 /* Link it in. */
195 isa_br->next = isa_chain;
196 isa_chain = isa_br;
198 isa_br->parent = pbm;
199 isa_br->self = pdev;
200 isa_br->index = index++;
201 isa_br->prom_node = pdev_cookie->prom_node;
203 printk("isa%d:", isa_br->index);
205 isa_fill_devices(isa_br);
207 printk("\n");