This source file includes following definitions.
- __eeh_addr_cache_get_device
- eeh_addr_cache_get_dev
- eeh_addr_cache_print
- eeh_addr_cache_insert
- __eeh_addr_cache_insert_dev
- eeh_addr_cache_insert_dev
- __eeh_addr_cache_rmv_dev
- eeh_addr_cache_rmv_dev
- eeh_addr_cache_init
- eeh_addr_cache_show
- eeh_cache_debugfs_init
1
2
3
4
5
6
7
8
9 #include <linux/list.h>
10 #include <linux/pci.h>
11 #include <linux/rbtree.h>
12 #include <linux/slab.h>
13 #include <linux/spinlock.h>
14 #include <linux/atomic.h>
15 #include <asm/pci-bridge.h>
16 #include <asm/debugfs.h>
17 #include <asm/ppc-pci.h>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 struct pci_io_addr_range {
41 struct rb_node rb_node;
42 resource_size_t addr_lo;
43 resource_size_t addr_hi;
44 struct eeh_dev *edev;
45 struct pci_dev *pcidev;
46 unsigned long flags;
47 };
48
49 static struct pci_io_addr_cache {
50 struct rb_root rb_root;
51 spinlock_t piar_lock;
52 } pci_io_addr_cache_root;
53
54 static inline struct eeh_dev *__eeh_addr_cache_get_device(unsigned long addr)
55 {
56 struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;
57
58 while (n) {
59 struct pci_io_addr_range *piar;
60 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
61
62 if (addr < piar->addr_lo)
63 n = n->rb_left;
64 else if (addr > piar->addr_hi)
65 n = n->rb_right;
66 else
67 return piar->edev;
68 }
69
70 return NULL;
71 }
72
73
74
75
76
77
78
79
80
81
82 struct eeh_dev *eeh_addr_cache_get_dev(unsigned long addr)
83 {
84 struct eeh_dev *edev;
85 unsigned long flags;
86
87 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
88 edev = __eeh_addr_cache_get_device(addr);
89 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
90 return edev;
91 }
92
93 #ifdef DEBUG
94
95
96
97
98 static void eeh_addr_cache_print(struct pci_io_addr_cache *cache)
99 {
100 struct rb_node *n;
101 int cnt = 0;
102
103 n = rb_first(&cache->rb_root);
104 while (n) {
105 struct pci_io_addr_range *piar;
106 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
107 pr_info("PCI: %s addr range %d [%pap-%pap]: %s\n",
108 (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
109 &piar->addr_lo, &piar->addr_hi, pci_name(piar->pcidev));
110 cnt++;
111 n = rb_next(n);
112 }
113 }
114 #endif
115
116
117 static struct pci_io_addr_range *
118 eeh_addr_cache_insert(struct pci_dev *dev, resource_size_t alo,
119 resource_size_t ahi, unsigned long flags)
120 {
121 struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;
122 struct rb_node *parent = NULL;
123 struct pci_io_addr_range *piar;
124
125
126 while (*p) {
127 parent = *p;
128 piar = rb_entry(parent, struct pci_io_addr_range, rb_node);
129 if (ahi < piar->addr_lo) {
130 p = &parent->rb_left;
131 } else if (alo > piar->addr_hi) {
132 p = &parent->rb_right;
133 } else {
134 if (dev != piar->pcidev ||
135 alo != piar->addr_lo || ahi != piar->addr_hi) {
136 pr_warn("PIAR: overlapping address range\n");
137 }
138 return piar;
139 }
140 }
141 piar = kzalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);
142 if (!piar)
143 return NULL;
144
145 piar->addr_lo = alo;
146 piar->addr_hi = ahi;
147 piar->edev = pci_dev_to_eeh_dev(dev);
148 piar->pcidev = dev;
149 piar->flags = flags;
150
151 eeh_edev_dbg(piar->edev, "PIAR: insert range=[%pap:%pap]\n",
152 &alo, &ahi);
153
154 rb_link_node(&piar->rb_node, parent, p);
155 rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);
156
157 return piar;
158 }
159
160 static void __eeh_addr_cache_insert_dev(struct pci_dev *dev)
161 {
162 struct pci_dn *pdn;
163 struct eeh_dev *edev;
164 int i;
165
166 pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn);
167 if (!pdn) {
168 pr_warn("PCI: no pci dn found for dev=%s\n",
169 pci_name(dev));
170 return;
171 }
172
173 edev = pdn_to_eeh_dev(pdn);
174 if (!edev) {
175 pr_warn("PCI: no EEH dev found for %s\n",
176 pci_name(dev));
177 return;
178 }
179
180
181 if (!edev->pe) {
182 dev_dbg(&dev->dev, "EEH: Skip building address cache\n");
183 return;
184 }
185
186
187
188
189
190 for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
191 resource_size_t start = pci_resource_start(dev,i);
192 resource_size_t end = pci_resource_end(dev,i);
193 unsigned long flags = pci_resource_flags(dev,i);
194
195
196 if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))
197 continue;
198 if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
199 continue;
200 eeh_addr_cache_insert(dev, start, end, flags);
201 }
202 }
203
204
205
206
207
208
209
210
211
212 void eeh_addr_cache_insert_dev(struct pci_dev *dev)
213 {
214 unsigned long flags;
215
216 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
217 __eeh_addr_cache_insert_dev(dev);
218 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
219 }
220
221 static inline void __eeh_addr_cache_rmv_dev(struct pci_dev *dev)
222 {
223 struct rb_node *n;
224
225 restart:
226 n = rb_first(&pci_io_addr_cache_root.rb_root);
227 while (n) {
228 struct pci_io_addr_range *piar;
229 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
230
231 if (piar->pcidev == dev) {
232 eeh_edev_dbg(piar->edev, "PIAR: remove range=[%pap:%pap]\n",
233 &piar->addr_lo, &piar->addr_hi);
234 rb_erase(n, &pci_io_addr_cache_root.rb_root);
235 kfree(piar);
236 goto restart;
237 }
238 n = rb_next(n);
239 }
240 }
241
242
243
244
245
246
247
248
249
250
251 void eeh_addr_cache_rmv_dev(struct pci_dev *dev)
252 {
253 unsigned long flags;
254
255 spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);
256 __eeh_addr_cache_rmv_dev(dev);
257 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
258 }
259
260
261
262
263
264
265
266 void eeh_addr_cache_init(void)
267 {
268 spin_lock_init(&pci_io_addr_cache_root.piar_lock);
269 }
270
271 static int eeh_addr_cache_show(struct seq_file *s, void *v)
272 {
273 struct pci_io_addr_range *piar;
274 struct rb_node *n;
275
276 spin_lock(&pci_io_addr_cache_root.piar_lock);
277 for (n = rb_first(&pci_io_addr_cache_root.rb_root); n; n = rb_next(n)) {
278 piar = rb_entry(n, struct pci_io_addr_range, rb_node);
279
280 seq_printf(s, "%s addr range [%pap-%pap]: %s\n",
281 (piar->flags & IORESOURCE_IO) ? "i/o" : "mem",
282 &piar->addr_lo, &piar->addr_hi, pci_name(piar->pcidev));
283 }
284 spin_unlock(&pci_io_addr_cache_root.piar_lock);
285
286 return 0;
287 }
288 DEFINE_SHOW_ATTRIBUTE(eeh_addr_cache);
289
290 void eeh_cache_debugfs_init(void)
291 {
292 debugfs_create_file_unsafe("eeh_address_cache", 0400,
293 powerpc_debugfs_root, NULL,
294 &eeh_addr_cache_fops);
295 }