Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 1 | /* |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 2 | * PCI address cache; allows the lookup of PCI devices based on I/O address |
| 3 | * |
Linas Vepstas | 3c8c90a | 2007-05-24 03:28:01 +1000 | [diff] [blame] | 4 | * Copyright IBM Corporation 2004 |
| 5 | * Copyright Linas Vepstas <linas@austin.ibm.com> 2004 |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/rbtree.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 26 | #include <linux/spinlock.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 27 | #include <linux/atomic.h> |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 28 | #include <asm/pci-bridge.h> |
Oliver O'Halloran | 5ca85ae | 2019-02-15 11:48:13 +1100 | [diff] [blame^] | 29 | #include <asm/debugfs.h> |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 30 | #include <asm/ppc-pci.h> |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 31 | |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * The pci address cache subsystem. This subsystem places |
| 35 | * PCI device address resources into a red-black tree, sorted |
| 36 | * according to the address range, so that given only an i/o |
| 37 | * address, the corresponding PCI device can be **quickly** |
| 38 | * found. It is safe to perform an address lookup in an interrupt |
| 39 | * context; this ability is an important feature. |
| 40 | * |
| 41 | * Currently, the only customer of this code is the EEH subsystem; |
| 42 | * thus, this code has been somewhat tailored to suit EEH better. |
| 43 | * In particular, the cache does *not* hold the addresses of devices |
| 44 | * for which EEH is not enabled. |
| 45 | * |
| 46 | * (Implementation Note: The RB tree seems to be better/faster |
| 47 | * than any hash algo I could think of for this problem, even |
| 48 | * with the penalty of slow pointer chases for d-cache misses). |
| 49 | */ |
Gavin Shan | 29f8bf1 | 2012-02-27 20:04:02 +0000 | [diff] [blame] | 50 | struct pci_io_addr_range { |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 51 | struct rb_node rb_node; |
Wei Yang | 3721352 | 2015-04-27 09:25:09 +0800 | [diff] [blame] | 52 | resource_size_t addr_lo; |
| 53 | resource_size_t addr_hi; |
Gavin Shan | f8f7d63 | 2012-09-07 22:44:22 +0000 | [diff] [blame] | 54 | struct eeh_dev *edev; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 55 | struct pci_dev *pcidev; |
Wei Yang | 3721352 | 2015-04-27 09:25:09 +0800 | [diff] [blame] | 56 | unsigned long flags; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 57 | }; |
| 58 | |
Gavin Shan | 29f8bf1 | 2012-02-27 20:04:02 +0000 | [diff] [blame] | 59 | static struct pci_io_addr_cache { |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 60 | struct rb_root rb_root; |
| 61 | spinlock_t piar_lock; |
| 62 | } pci_io_addr_cache_root; |
| 63 | |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 64 | static inline struct eeh_dev *__eeh_addr_cache_get_device(unsigned long addr) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 65 | { |
| 66 | struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node; |
| 67 | |
| 68 | while (n) { |
| 69 | struct pci_io_addr_range *piar; |
| 70 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
| 71 | |
Gavin Shan | 0ba1788 | 2013-07-24 10:24:51 +0800 | [diff] [blame] | 72 | if (addr < piar->addr_lo) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 73 | n = n->rb_left; |
Gavin Shan | 0ba1788 | 2013-07-24 10:24:51 +0800 | [diff] [blame] | 74 | else if (addr > piar->addr_hi) |
| 75 | n = n->rb_right; |
| 76 | else |
| 77 | return piar->edev; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | return NULL; |
| 81 | } |
| 82 | |
| 83 | /** |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 84 | * eeh_addr_cache_get_dev - Get device, given only address |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 85 | * @addr: mmio (PIO) phys address or i/o port number |
| 86 | * |
| 87 | * Given an mmio phys address, or a port number, find a pci device |
Sam Bobroff | 63457b1 | 2018-03-19 13:46:40 +1100 | [diff] [blame] | 88 | * that implements this address. I/O port numbers are assumed to be offset |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 89 | * from zero (that is, they do *not* have pci_io_addr added in). |
| 90 | * It is safe to call this function within an interrupt. |
| 91 | */ |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 92 | struct eeh_dev *eeh_addr_cache_get_dev(unsigned long addr) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 93 | { |
Gavin Shan | f8f7d63 | 2012-09-07 22:44:22 +0000 | [diff] [blame] | 94 | struct eeh_dev *edev; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 95 | unsigned long flags; |
| 96 | |
| 97 | spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags); |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 98 | edev = __eeh_addr_cache_get_device(addr); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 99 | spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags); |
Gavin Shan | f8f7d63 | 2012-09-07 22:44:22 +0000 | [diff] [blame] | 100 | return edev; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | #ifdef DEBUG |
| 104 | /* |
| 105 | * Handy-dandy debug print routine, does nothing more |
| 106 | * than print out the contents of our addr cache. |
| 107 | */ |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 108 | static void eeh_addr_cache_print(struct pci_io_addr_cache *cache) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 109 | { |
| 110 | struct rb_node *n; |
| 111 | int cnt = 0; |
| 112 | |
| 113 | n = rb_first(&cache->rb_root); |
| 114 | while (n) { |
| 115 | struct pci_io_addr_range *piar; |
| 116 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
Andrew Donnellan | 91dc068 | 2016-06-24 15:54:22 +1000 | [diff] [blame] | 117 | pr_debug("PCI: %s addr range %d [%pap-%pap]: %s\n", |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 118 | (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt, |
Andrew Donnellan | 91dc068 | 2016-06-24 15:54:22 +1000 | [diff] [blame] | 119 | &piar->addr_lo, &piar->addr_hi, pci_name(piar->pcidev)); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 120 | cnt++; |
| 121 | n = rb_next(n); |
| 122 | } |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | /* Insert address range into the rb tree. */ |
| 127 | static struct pci_io_addr_range * |
Wei Yang | 3721352 | 2015-04-27 09:25:09 +0800 | [diff] [blame] | 128 | eeh_addr_cache_insert(struct pci_dev *dev, resource_size_t alo, |
| 129 | resource_size_t ahi, unsigned long flags) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 130 | { |
| 131 | struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node; |
| 132 | struct rb_node *parent = NULL; |
| 133 | struct pci_io_addr_range *piar; |
| 134 | |
| 135 | /* Walk tree, find a place to insert into tree */ |
| 136 | while (*p) { |
| 137 | parent = *p; |
| 138 | piar = rb_entry(parent, struct pci_io_addr_range, rb_node); |
| 139 | if (ahi < piar->addr_lo) { |
| 140 | p = &parent->rb_left; |
| 141 | } else if (alo > piar->addr_hi) { |
| 142 | p = &parent->rb_right; |
| 143 | } else { |
| 144 | if (dev != piar->pcidev || |
| 145 | alo != piar->addr_lo || ahi != piar->addr_hi) { |
Gavin Shan | 0dae274 | 2014-07-17 14:41:41 +1000 | [diff] [blame] | 146 | pr_warn("PIAR: overlapping address range\n"); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 147 | } |
| 148 | return piar; |
| 149 | } |
| 150 | } |
Gavin Shan | 7e4bbaf | 2012-09-07 22:44:03 +0000 | [diff] [blame] | 151 | piar = kzalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 152 | if (!piar) |
| 153 | return NULL; |
| 154 | |
| 155 | piar->addr_lo = alo; |
| 156 | piar->addr_hi = ahi; |
Gavin Shan | f8f7d63 | 2012-09-07 22:44:22 +0000 | [diff] [blame] | 157 | piar->edev = pci_dev_to_eeh_dev(dev); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 158 | piar->pcidev = dev; |
| 159 | piar->flags = flags; |
| 160 | |
Andrew Donnellan | 91dc068 | 2016-06-24 15:54:22 +1000 | [diff] [blame] | 161 | pr_debug("PIAR: insert range=[%pap:%pap] dev=%s\n", |
| 162 | &alo, &ahi, pci_name(dev)); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 163 | |
| 164 | rb_link_node(&piar->rb_node, parent, p); |
| 165 | rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root); |
| 166 | |
| 167 | return piar; |
| 168 | } |
| 169 | |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 170 | static void __eeh_addr_cache_insert_dev(struct pci_dev *dev) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 171 | { |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 172 | struct pci_dn *pdn; |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 173 | struct eeh_dev *edev; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 174 | int i; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 175 | |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 176 | pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn); |
| 177 | if (!pdn) { |
Gavin Shan | 0dae274 | 2014-07-17 14:41:41 +1000 | [diff] [blame] | 178 | pr_warn("PCI: no pci dn found for dev=%s\n", |
| 179 | pci_name(dev)); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 180 | return; |
| 181 | } |
| 182 | |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 183 | edev = pdn_to_eeh_dev(pdn); |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 184 | if (!edev) { |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 185 | pr_warn("PCI: no EEH dev found for %s\n", |
| 186 | pci_name(dev)); |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 190 | /* Skip any devices for which EEH is not enabled. */ |
Gavin Shan | 05b1721 | 2014-07-17 14:41:38 +1000 | [diff] [blame] | 191 | if (!edev->pe) { |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 192 | dev_dbg(&dev->dev, "EEH: Skip building address cache\n"); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 193 | return; |
| 194 | } |
| 195 | |
Wei Yang | 51c0e87 | 2016-03-04 10:53:06 +1100 | [diff] [blame] | 196 | /* |
| 197 | * Walk resources on this device, poke the first 7 (6 normal BAR and 1 |
| 198 | * ROM BAR) into the tree. |
| 199 | */ |
| 200 | for (i = 0; i <= PCI_ROM_RESOURCE; i++) { |
Wei Yang | 3721352 | 2015-04-27 09:25:09 +0800 | [diff] [blame] | 201 | resource_size_t start = pci_resource_start(dev,i); |
| 202 | resource_size_t end = pci_resource_end(dev,i); |
| 203 | unsigned long flags = pci_resource_flags(dev,i); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 204 | |
| 205 | /* We are interested only bus addresses, not dma or other stuff */ |
| 206 | if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM))) |
| 207 | continue; |
| 208 | if (start == 0 || ~start == 0 || end == 0 || ~end == 0) |
| 209 | continue; |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 210 | eeh_addr_cache_insert(dev, start, end, flags); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 211 | } |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /** |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 215 | * eeh_addr_cache_insert_dev - Add a device to the address cache |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 216 | * @dev: PCI device whose I/O addresses we are interested in. |
| 217 | * |
| 218 | * In order to support the fast lookup of devices based on addresses, |
| 219 | * we maintain a cache of devices that can be quickly searched. |
| 220 | * This routine adds a device to that cache. |
| 221 | */ |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 222 | void eeh_addr_cache_insert_dev(struct pci_dev *dev) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 223 | { |
| 224 | unsigned long flags; |
| 225 | |
| 226 | spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags); |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 227 | __eeh_addr_cache_insert_dev(dev); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 228 | spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags); |
| 229 | } |
| 230 | |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 231 | static inline void __eeh_addr_cache_rmv_dev(struct pci_dev *dev) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 232 | { |
| 233 | struct rb_node *n; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 234 | |
| 235 | restart: |
| 236 | n = rb_first(&pci_io_addr_cache_root.rb_root); |
| 237 | while (n) { |
| 238 | struct pci_io_addr_range *piar; |
| 239 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
| 240 | |
| 241 | if (piar->pcidev == dev) { |
Oliver O'Halloran | e67fbbe | 2019-02-15 11:48:12 +1100 | [diff] [blame] | 242 | pr_debug("PIAR: remove range=[%pap:%pap] dev=%s\n", |
| 243 | &piar->addr_lo, &piar->addr_hi, pci_name(dev)); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 244 | rb_erase(n, &pci_io_addr_cache_root.rb_root); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 245 | kfree(piar); |
| 246 | goto restart; |
| 247 | } |
| 248 | n = rb_next(n); |
| 249 | } |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 253 | * eeh_addr_cache_rmv_dev - remove pci device from addr cache |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 254 | * @dev: device to remove |
| 255 | * |
| 256 | * Remove a device from the addr-cache tree. |
| 257 | * This is potentially expensive, since it will walk |
| 258 | * the tree multiple times (once per resource). |
| 259 | * But so what; device removal doesn't need to be that fast. |
| 260 | */ |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 261 | void eeh_addr_cache_rmv_dev(struct pci_dev *dev) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 262 | { |
| 263 | unsigned long flags; |
| 264 | |
| 265 | spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags); |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 266 | __eeh_addr_cache_rmv_dev(dev); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 267 | spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags); |
| 268 | } |
| 269 | |
| 270 | /** |
Gavin Shan | 3ab96a0 | 2012-09-07 22:44:23 +0000 | [diff] [blame] | 271 | * eeh_addr_cache_build - Build a cache of I/O addresses |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 272 | * |
| 273 | * Build a cache of pci i/o addresses. This cache will be used to |
| 274 | * find the pci device that corresponds to a given address. |
| 275 | * This routine scans all pci busses to build the cache. |
| 276 | * Must be run late in boot process, after the pci controllers |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 277 | * have been scanned for devices (after all device resources are known). |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 278 | */ |
Gavin Shan | eeb6361 | 2013-06-27 13:46:47 +0800 | [diff] [blame] | 279 | void eeh_addr_cache_build(void) |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 280 | { |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 281 | struct pci_dn *pdn; |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 282 | struct eeh_dev *edev; |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 283 | struct pci_dev *dev = NULL; |
| 284 | |
| 285 | spin_lock_init(&pci_io_addr_cache_root.piar_lock); |
| 286 | |
Kulikov Vasiliy | 6901c6c | 2010-07-03 06:03:48 +0000 | [diff] [blame] | 287 | for_each_pci_dev(dev) { |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 288 | pdn = pci_get_pdn_by_devfn(dev->bus, dev->devfn); |
| 289 | if (!pdn) |
Nathan Lynch | ccba051 | 2006-06-20 18:01:58 +1000 | [diff] [blame] | 290 | continue; |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 291 | |
Gavin Shan | c6406d8 | 2015-03-17 16:15:08 +1100 | [diff] [blame] | 292 | edev = pdn_to_eeh_dev(pdn); |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 293 | if (!edev) |
| 294 | continue; |
| 295 | |
Gavin Shan | d50a7d4 | 2012-02-27 20:04:06 +0000 | [diff] [blame] | 296 | dev->dev.archdata.edev = edev; |
| 297 | edev->pdev = dev; |
Linas Vepstas | e1d04c9 | 2007-05-24 03:16:46 +1000 | [diff] [blame] | 298 | |
Thadeu Lima de Souza Cascardo | 1abd601 | 2013-06-27 18:00:10 -0300 | [diff] [blame] | 299 | eeh_addr_cache_insert_dev(dev); |
Linas Vepstas | e1d04c9 | 2007-05-24 03:16:46 +1000 | [diff] [blame] | 300 | eeh_sysfs_add_device(dev); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 301 | } |
Oliver O'Halloran | 5ca85ae | 2019-02-15 11:48:13 +1100 | [diff] [blame^] | 302 | } |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 303 | |
Oliver O'Halloran | 5ca85ae | 2019-02-15 11:48:13 +1100 | [diff] [blame^] | 304 | static int eeh_addr_cache_show(struct seq_file *s, void *v) |
| 305 | { |
| 306 | struct pci_io_addr_range *piar; |
| 307 | struct rb_node *n; |
| 308 | |
| 309 | spin_lock(&pci_io_addr_cache_root.piar_lock); |
| 310 | for (n = rb_first(&pci_io_addr_cache_root.rb_root); n; n = rb_next(n)) { |
| 311 | piar = rb_entry(n, struct pci_io_addr_range, rb_node); |
| 312 | |
| 313 | seq_printf(s, "%s addr range [%pap-%pap]: %s\n", |
| 314 | (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", |
| 315 | &piar->addr_lo, &piar->addr_hi, pci_name(piar->pcidev)); |
| 316 | } |
| 317 | spin_unlock(&pci_io_addr_cache_root.piar_lock); |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | DEFINE_SHOW_ATTRIBUTE(eeh_addr_cache); |
| 322 | |
| 323 | void eeh_cache_debugfs_init(void) |
| 324 | { |
| 325 | debugfs_create_file_unsafe("eeh_address_cache", 0400, |
| 326 | powerpc_debugfs_root, NULL, |
| 327 | &eeh_addr_cache_fops); |
Linas Vepstas | 5d5a093 | 2005-11-03 18:53:07 -0600 | [diff] [blame] | 328 | } |