Adds a debugfs file that can be read to view the contents of the EEH
address cache. This is pretty similar to the existing
eeh_addr_cache_print() function, but that function is intended to debug
issues inside of the kernel since it's #ifdef`ed out by default, and writes
into the kernel log.

Signed-off-by: Oliver O'Halloran <ooh...@gmail.com>
---
 arch/powerpc/include/asm/eeh.h  |  3 +++
 arch/powerpc/kernel/eeh.c       |  2 +-
 arch/powerpc/kernel/eeh_cache.c | 34 +++++++++++++++++++++++++++++----
 3 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h
index c003628441cc..fc21b6e78e91 100644
--- a/arch/powerpc/include/asm/eeh.h
+++ b/arch/powerpc/include/asm/eeh.h
@@ -460,6 +460,9 @@ static inline void eeh_readsl(const volatile void __iomem 
*addr, void * buf,
                eeh_check_failure(addr);
 }
 
+
+void eeh_cache_debugfs_init(void);
+
 #endif /* CONFIG_PPC64 */
 #endif /* __KERNEL__ */
 #endif /* _POWERPC_EEH_H */
diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
index f6e65375a8de..d1f0bdf41fac 100644
--- a/arch/powerpc/kernel/eeh.c
+++ b/arch/powerpc/kernel/eeh.c
@@ -1810,7 +1810,7 @@ static int __init eeh_init_proc(void)
                                           &eeh_enable_dbgfs_ops);
                debugfs_create_u32("eeh_max_freezes", 0600,
                                powerpc_debugfs_root, &eeh_max_freezes);
-#endif
+               eeh_cache_debugfs_init();
        }
 
        return 0;
diff --git a/arch/powerpc/kernel/eeh_cache.c b/arch/powerpc/kernel/eeh_cache.c
index b2c320e0fcef..dba421a577e7 100644
--- a/arch/powerpc/kernel/eeh_cache.c
+++ b/arch/powerpc/kernel/eeh_cache.c
@@ -26,6 +26,7 @@
 #include <linux/spinlock.h>
 #include <linux/atomic.h>
 #include <asm/pci-bridge.h>
+#include <asm/debugfs.h>
 #include <asm/ppc-pci.h>
 
 
@@ -298,9 +299,34 @@ void eeh_addr_cache_build(void)
                eeh_addr_cache_insert_dev(dev);
                eeh_sysfs_add_device(dev);
        }
+}
 
-#ifdef DEBUG
-       /* Verify tree built up above, echo back the list of addrs. */
-       eeh_addr_cache_print(&pci_io_addr_cache_root);
-#endif
+static int eeh_addr_cache_show(struct seq_file *s, void *v)
+{
+       struct rb_node *n = rb_first(&pci_io_addr_cache_root.rb_root);
+       struct pci_io_addr_range *piar;
+       int cnt = 0;
+
+       spin_lock(&pci_io_addr_cache_root.piar_lock);
+       while (n) {
+               piar = rb_entry(n, struct pci_io_addr_range, rb_node);
+
+               seq_printf(s, "%s addr range %3d [%pap-%pap]: %s\n",
+                      (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,
+                      &piar->addr_lo, &piar->addr_hi, pci_name(piar->pcidev));
+
+               n = rb_next(n);
+               cnt++;
+       }
+       spin_unlock(&pci_io_addr_cache_root.piar_lock);
+
+       return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(eeh_addr_cache);
+
+void eeh_cache_debugfs_init(void)
+{
+       debugfs_create_file_unsafe("eeh_address_cache", 0400,
+                       powerpc_debugfs_root, NULL,
+                       &eeh_addr_cache_fops);
 }
-- 
2.20.1

Reply via email to