22 #include <linux/list.h>
23 #include <linux/pci.h>
24 #include <linux/rbtree.h>
25 #include <linux/slab.h>
28 #include <asm/pci-bridge.h>
58 static struct pci_io_addr_cache {
61 } pci_io_addr_cache_root;
63 static inline struct eeh_dev *__eeh_addr_cache_get_device(
unsigned long addr)
65 struct rb_node *
n = pci_io_addr_cache_root.rb_root.rb_node;
102 edev = __eeh_addr_cache_get_device(addr);
103 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
112 static void eeh_addr_cache_print(
struct pci_io_addr_cache *
cache)
121 pr_debug(
"PCI: %s addr range %d [%lx-%lx]: %s\n",
132 eeh_addr_cache_insert(
struct pci_dev *
dev,
unsigned long alo,
133 unsigned long ahi,
unsigned int flags)
135 struct rb_node **
p = &pci_io_addr_cache_root.rb_root.rb_node;
145 }
else if (alo > piar->
addr_hi) {
148 if (dev != piar->
pcidev ||
150 pr_warning(
"PIAR: overlapping address range\n");
162 piar->
edev = pci_dev_to_eeh_dev(dev);
167 pr_debug(
"PIAR: insert range=[%lx:%lx] dev=%s\n",
168 alo, ahi, pci_name(dev));
171 rb_link_node(&piar->
rb_node, parent, p);
177 static void __eeh_addr_cache_insert_dev(
struct pci_dev *dev)
180 struct eeh_dev *edev;
183 dn = pci_device_to_OF_node(dev);
185 pr_warning(
"PCI: no pci dn found for dev=%s\n", pci_name(dev));
189 edev = of_node_to_eeh_dev(dn);
191 pr_warning(
"PCI: no EEH dev found for dn=%s\n",
199 pr_info(
"PCI: skip building address cache for=%s - %s\n",
214 if (start == 0 || ~start == 0 || end == 0 || ~end == 0)
216 eeh_addr_cache_insert(dev, start, end, flags);
237 __eeh_addr_cache_insert_dev(dev);
238 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
241 static inline void __eeh_addr_cache_rmv_dev(
struct pci_dev *dev)
246 n =
rb_first(&pci_io_addr_cache_root.rb_root);
251 if (piar->
pcidev == dev) {
252 rb_erase(n, &pci_io_addr_cache_root.rb_root);
275 __eeh_addr_cache_rmv_dev(dev);
276 spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);
291 struct eeh_dev *edev;
299 dn = pci_device_to_OF_node(dev);
303 edev = of_node_to_eeh_dev(dn);
308 dev->
dev.archdata.edev = edev;
316 eeh_addr_cache_print(&pci_io_addr_cache_root);