Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
2b1e5978 DM |
6 | #include <asm/prom.h> |
7 | #include <asm/of_device.h> | |
1da177e4 LT |
8 | #include <asm/isa.h> |
9 | ||
10 | struct sparc_isa_bridge *isa_chain; | |
11 | ||
12 | static void __init fatal_err(const char *reason) | |
13 | { | |
14 | prom_printf("ISA: fatal error, %s.\n", reason); | |
15 | } | |
16 | ||
17 | static void __init report_dev(struct sparc_isa_device *isa_dev, int child) | |
18 | { | |
19 | if (child) | |
690c8fd3 | 20 | printk(" (%s)", isa_dev->prom_node->name); |
1da177e4 | 21 | else |
690c8fd3 | 22 | printk(" [%s", isa_dev->prom_node->name); |
1da177e4 LT |
23 | } |
24 | ||
690c8fd3 DM |
25 | static struct linux_prom_registers * __init |
26 | isa_dev_get_resource(struct sparc_isa_device *isa_dev) | |
1da177e4 | 27 | { |
690c8fd3 | 28 | struct linux_prom_registers *pregs; |
1da177e4 LT |
29 | unsigned long base, len; |
30 | int prop_len; | |
31 | ||
690c8fd3 | 32 | pregs = of_get_property(isa_dev->prom_node, "reg", &prop_len); |
1da177e4 LT |
33 | |
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; | |
690c8fd3 | 43 | isa_dev->resource.name = isa_dev->prom_node->name; |
1da177e4 LT |
44 | |
45 | request_resource(&isa_dev->bus->parent->io_space, | |
46 | &isa_dev->resource); | |
690c8fd3 DM |
47 | |
48 | return pregs; | |
1da177e4 LT |
49 | } |
50 | ||
1da177e4 LT |
51 | static void __init isa_dev_get_irq(struct sparc_isa_device *isa_dev, |
52 | struct linux_prom_registers *pregs) | |
53 | { | |
2b1e5978 | 54 | struct of_device *op = of_find_device_by_node(isa_dev->prom_node); |
1da177e4 | 55 | |
2b1e5978 DM |
56 | if (!op || !op->num_irqs) { |
57 | isa_dev->irq = PCI_IRQ_NONE; | |
1da177e4 | 58 | } else { |
2b1e5978 | 59 | isa_dev->irq = op->irqs[0]; |
1da177e4 | 60 | } |
1da177e4 LT |
61 | } |
62 | ||
63 | static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev) | |
64 | { | |
690c8fd3 | 65 | struct device_node *dp = parent_isa_dev->prom_node->child; |
1da177e4 | 66 | |
690c8fd3 | 67 | if (!dp) |
1da177e4 LT |
68 | return; |
69 | ||
70 | printk(" ->"); | |
690c8fd3 DM |
71 | while (dp) { |
72 | struct linux_prom_registers *regs; | |
1da177e4 | 73 | struct sparc_isa_device *isa_dev; |
1da177e4 | 74 | |
982c2064 | 75 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
1da177e4 LT |
76 | if (!isa_dev) { |
77 | fatal_err("cannot allocate child isa_dev"); | |
78 | prom_halt(); | |
79 | } | |
80 | ||
1da177e4 LT |
81 | /* 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; | |
690c8fd3 | 86 | isa_dev->prom_node = dp; |
1da177e4 | 87 | |
690c8fd3 | 88 | regs = isa_dev_get_resource(isa_dev); |
1da177e4 LT |
89 | isa_dev_get_irq(isa_dev, regs); |
90 | ||
91 | report_dev(isa_dev, 1); | |
92 | ||
690c8fd3 | 93 | dp = dp->sibling; |
1da177e4 LT |
94 | } |
95 | } | |
96 | ||
97 | static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br) | |
98 | { | |
690c8fd3 | 99 | struct device_node *dp = isa_br->prom_node->child; |
1da177e4 | 100 | |
690c8fd3 DM |
101 | while (dp) { |
102 | struct linux_prom_registers *regs; | |
1da177e4 | 103 | struct sparc_isa_device *isa_dev; |
1da177e4 | 104 | |
982c2064 | 105 | isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL); |
1da177e4 | 106 | if (!isa_dev) { |
a2bd4fd1 DM |
107 | printk(KERN_DEBUG "ISA: cannot allocate isa_dev"); |
108 | return; | |
1da177e4 LT |
109 | } |
110 | ||
a2bd4fd1 DM |
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; | |
f5ef9d11 | 114 | sprintf(isa_dev->ofdev.dev.bus_id, "isa[%08x]", dp->node); |
a2bd4fd1 DM |
115 | |
116 | /* Register with core */ | |
117 | if (of_device_register(&isa_dev->ofdev) != 0) { | |
118 | printk(KERN_DEBUG "isa: device registration error for %s!\n", | |
f5ef9d11 | 119 | dp->path_component_name); |
a2bd4fd1 DM |
120 | kfree(isa_dev); |
121 | goto next_sibling; | |
122 | } | |
123 | ||
1da177e4 LT |
124 | /* 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; | |
690c8fd3 | 138 | isa_dev->prom_node = dp; |
1da177e4 | 139 | |
690c8fd3 | 140 | regs = isa_dev_get_resource(isa_dev); |
1da177e4 LT |
141 | 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 | ||
a2bd4fd1 | 149 | next_sibling: |
690c8fd3 | 150 | dp = dp->sibling; |
1da177e4 LT |
151 | } |
152 | } | |
153 | ||
154 | void __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; | |
a2bd4fd1 | 168 | struct device_node *dp; |
1da177e4 LT |
169 | |
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; | |
a2bd4fd1 | 177 | dp = pdev_cookie->prom_node; |
1da177e4 | 178 | |
982c2064 | 179 | isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL); |
1da177e4 | 180 | if (!isa_br) { |
a2bd4fd1 DM |
181 | printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge"); |
182 | return; | |
1da177e4 LT |
183 | } |
184 | ||
a2bd4fd1 DM |
185 | isa_br->ofdev.node = dp; |
186 | isa_br->ofdev.dev.parent = &pdev->dev; | |
187 | isa_br->ofdev.dev.bus = &isa_bus_type; | |
f5ef9d11 | 188 | sprintf(isa_br->ofdev.dev.bus_id, "isa%d", index); |
a2bd4fd1 DM |
189 | |
190 | /* Register with core */ | |
191 | if (of_device_register(&isa_br->ofdev) != 0) { | |
192 | printk(KERN_DEBUG "isa: device registration error for %s!\n", | |
f5ef9d11 | 193 | dp->path_component_name); |
a2bd4fd1 DM |
194 | kfree(isa_br); |
195 | return; | |
196 | } | |
197 | ||
1da177e4 LT |
198 | /* 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++; | |
690c8fd3 DM |
205 | isa_br->prom_node = pdev_cookie->prom_node; |
206 | ||
1da177e4 LT |
207 | printk("isa%d:", isa_br->index); |
208 | ||
209 | isa_fill_devices(isa_br); | |
210 | ||
211 | printk("\n"); | |
212 | } | |
213 | } |