1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#define DEBUG
17
18#include <linux/kernel.h>
19#include <linux/pci.h>
20#include <linux/string.h>
21#include <linux/export.h>
22#include <linux/init.h>
23#include <linux/mm.h>
24#include <linux/notifier.h>
25
26#include <asm/processor.h>
27#include <asm/io.h>
28#include <asm/prom.h>
29#include <asm/pci-bridge.h>
30#include <asm/machdep.h>
31#include <asm/ppc-pci.h>
32
33unsigned long isa_io_base;
34EXPORT_SYMBOL(isa_io_base);
35
36
37static struct device_node *isa_bridge_devnode;
38struct pci_dev *isa_bridge_pcidev;
39EXPORT_SYMBOL_GPL(isa_bridge_pcidev);
40
41#define ISA_SPACE_MASK 0x1
42#define ISA_SPACE_IO 0x1
43
44static void pci_process_ISA_OF_ranges(struct device_node *isa_node,
45 unsigned long phb_io_base_phys)
46{
47
48 struct pci_address {
49 u32 a_hi;
50 u32 a_mid;
51 u32 a_lo;
52 };
53
54 struct isa_address {
55 u32 a_hi;
56 u32 a_lo;
57 };
58
59 struct isa_range {
60 struct isa_address isa_addr;
61 struct pci_address pci_addr;
62 unsigned int size;
63 };
64
65 const struct isa_range *range;
66 unsigned long pci_addr;
67 unsigned int isa_addr;
68 unsigned int size;
69 int rlen = 0;
70
71 range = of_get_property(isa_node, "ranges", &rlen);
72 if (range == NULL || (rlen < sizeof(struct isa_range)))
73 goto inval_range;
74
75
76
77
78
79
80
81
82
83 if ((range->isa_addr.a_hi & ISA_SPACE_MASK) != ISA_SPACE_IO) {
84 range++;
85 rlen -= sizeof(struct isa_range);
86 if (rlen < sizeof(struct isa_range))
87 goto inval_range;
88 }
89 if ((range->isa_addr.a_hi & ISA_SPACE_MASK) != ISA_SPACE_IO)
90 goto inval_range;
91
92 isa_addr = range->isa_addr.a_lo;
93 pci_addr = (unsigned long) range->pci_addr.a_mid << 32 |
94 range->pci_addr.a_lo;
95
96
97
98
99
100 if ((pci_addr != 0) || (isa_addr != 0)) {
101 printk(KERN_ERR "unexpected isa to pci mapping: %s\n",
102 __func__);
103 return;
104 }
105
106
107 size = PAGE_ALIGN(range->size);
108 if (size > 0x10000)
109 size = 0x10000;
110
111 __ioremap_at(phb_io_base_phys, (void *)ISA_IO_BASE,
112 size, _PAGE_NO_CACHE|_PAGE_GUARDED);
113 return;
114
115inval_range:
116 printk(KERN_ERR "no ISA IO ranges or unexpected isa range, "
117 "mapping 64k\n");
118 __ioremap_at(phb_io_base_phys, (void *)ISA_IO_BASE,
119 0x10000, _PAGE_NO_CACHE|_PAGE_GUARDED);
120}
121
122
123
124
125
126
127
128
129void __init isa_bridge_find_early(struct pci_controller *hose)
130{
131 struct device_node *np, *parent = NULL, *tmp;
132
133
134 if (isa_bridge_devnode != NULL)
135 return;
136
137
138
139
140
141
142 for_each_node_by_type(np, "isa") {
143
144 for (parent = of_get_parent(np); parent;) {
145 if (parent == hose->dn) {
146 of_node_put(parent);
147 break;
148 }
149 tmp = parent;
150 parent = of_get_parent(parent);
151 of_node_put(tmp);
152 }
153 if (parent != NULL)
154 break;
155 }
156 if (np == NULL)
157 return;
158 isa_bridge_devnode = np;
159
160
161 pci_process_ISA_OF_ranges(np, hose->io_base_phys);
162
163
164 isa_io_base = ISA_IO_BASE;
165
166 pr_debug("ISA bridge (early) is %s\n", np->full_name);
167}
168
169
170
171
172
173static void isa_bridge_find_late(struct pci_dev *pdev,
174 struct device_node *devnode)
175{
176 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
177
178
179 isa_bridge_devnode = of_node_get(devnode);
180 isa_bridge_pcidev = pdev;
181
182
183 pci_process_ISA_OF_ranges(devnode, hose->io_base_phys);
184
185
186 isa_io_base = ISA_IO_BASE;
187
188 pr_debug("ISA bridge (late) is %s on %s\n",
189 devnode->full_name, pci_name(pdev));
190}
191
192
193
194
195static void isa_bridge_remove(void)
196{
197 pr_debug("ISA bridge removed !\n");
198
199
200
201
202
203
204 isa_io_base = ISA_IO_BASE;
205
206
207 of_node_put(isa_bridge_devnode);
208 isa_bridge_devnode = NULL;
209 isa_bridge_pcidev = NULL;
210
211
212 __iounmap_at((void *)ISA_IO_BASE, 0x10000);
213}
214
215
216
217
218static int isa_bridge_notify(struct notifier_block *nb, unsigned long action,
219 void *data)
220{
221 struct device *dev = data;
222 struct pci_dev *pdev = to_pci_dev(dev);
223 struct device_node *devnode = pci_device_to_OF_node(pdev);
224
225 switch(action) {
226 case BUS_NOTIFY_ADD_DEVICE:
227
228 if (isa_bridge_devnode && isa_bridge_devnode == devnode &&
229 !isa_bridge_pcidev) {
230 pr_debug("ISA bridge PCI attached: %s\n",
231 pci_name(pdev));
232 isa_bridge_pcidev = pdev;
233 }
234
235
236
237
238 if (!isa_bridge_devnode && devnode && devnode->type &&
239 !strcmp(devnode->type, "isa"))
240 isa_bridge_find_late(pdev, devnode);
241
242 return 0;
243 case BUS_NOTIFY_DEL_DEVICE:
244
245 if (pdev == isa_bridge_pcidev ||
246 (devnode && devnode == isa_bridge_devnode))
247 isa_bridge_remove();
248 return 0;
249 }
250 return 0;
251}
252
253static struct notifier_block isa_bridge_notifier = {
254 .notifier_call = isa_bridge_notify
255};
256
257
258
259
260
261static int __init isa_bridge_init(void)
262{
263 bus_register_notifier(&pci_bus_type, &isa_bridge_notifier);
264 return 0;
265}
266arch_initcall(isa_bridge_init);
267