OSDN Git Service

iommu: Create iommu debugfs directory from IOMMU code
authorMitchel Humpherys <mitchelh@codeaurora.org>
Thu, 16 Jul 2015 01:27:36 +0000 (18:27 -0700)
committerDavid Keitel <dkeitel@codeaurora.org>
Tue, 22 Mar 2016 18:13:39 +0000 (11:13 -0700)
Currently we're creating an "iommu" debugfs directory from the
iommu-debug code.  Other IOMMU modules might want to make use of this
same directory, so create it from the IOMMU framework code itself.

Change-Id: I679fdfc34ba5fcbd927dc5981438c6fabcfa3639
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
drivers/iommu/iommu-debug.c
drivers/iommu/iommu.c
include/linux/iommu.h

index 72d4a89..f775544 100644 (file)
@@ -22,8 +22,6 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 
-static struct dentry *debugfs_top_dir;
-
 #ifdef CONFIG_IOMMU_DEBUG_TRACKING
 
 static DEFINE_MUTEX(iommu_debug_attachments_lock);
@@ -200,7 +198,7 @@ static int iommu_debug_init_tracking(void)
 
        mutex_lock(&iommu_debug_attachments_lock);
        debugfs_attachments_dir = debugfs_create_dir("attachments",
-                                                    debugfs_top_dir);
+                                                    iommu_debugfs_top);
        if (!debugfs_attachments_dir) {
                pr_err("Couldn't create iommu/attachments debugfs directory\n");
                ret = -ENODEV;
@@ -215,8 +213,14 @@ out_unlock:
        mutex_unlock(&iommu_debug_attachments_lock);
        return ret;
 }
+
+static void iommu_debug_destroy_tracking(void)
+{
+       debugfs_remove_recursive(debugfs_attachments_dir);
+}
 #else
 static inline int iommu_debug_init_tracking(void) { return 0; }
+static inline void iommu_debug_destroy_tracking(void) { }
 #endif
 
 #ifdef CONFIG_IOMMU_TESTS
@@ -809,7 +813,7 @@ err:
 static int iommu_debug_init_tests(void)
 {
        debugfs_tests_dir = debugfs_create_dir("tests",
-                                              debugfs_top_dir);
+                                              iommu_debugfs_top);
        if (!debugfs_tests_dir) {
                pr_err("Couldn't create iommu/tests debugfs directory\n");
                return -ENODEV;
@@ -818,33 +822,31 @@ static int iommu_debug_init_tests(void)
        return bus_for_each_dev(&platform_bus_type, NULL, NULL,
                                snarf_iommu_devices);
 }
+
+static void iommu_debug_destroy_tests(void)
+{
+       debugfs_remove_recursive(debugfs_tests_dir);
+}
 #else
 static inline int iommu_debug_init_tests(void) { return 0; }
+static inline void iommu_debug_destroy_tests(void) { }
 #endif
 
 static int iommu_debug_init(void)
 {
-       debugfs_top_dir = debugfs_create_dir("iommu", NULL);
-       if (!debugfs_top_dir) {
-               pr_err("Couldn't create iommu debugfs directory\n");
-               return -ENODEV;
-       }
-
        if (iommu_debug_init_tracking())
-               goto err;
+               return -ENODEV;
 
        if (iommu_debug_init_tests())
-               goto err;
+               return -ENODEV;
 
        return 0;
-err:
-       debugfs_remove_recursive(debugfs_top_dir);
-       return -ENODEV;
 }
 
 static void iommu_debug_exit(void)
 {
-       debugfs_remove_recursive(debugfs_top_dir);
+       iommu_debug_destroy_tracking();
+       iommu_debug_destroy_tests();
 }
 
 module_init(iommu_debug_init);
index 9959b48..7137b96 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/err.h>
 #include <linux/pci.h>
 #include <linux/bitops.h>
+#include <linux/debugfs.h>
 #include <trace/events/iommu.h>
 
 #include "iommu-debug.h"
@@ -1227,6 +1228,8 @@ void iommu_domain_window_disable(struct iommu_domain *domain, u32 wnd_nr)
 }
 EXPORT_SYMBOL_GPL(iommu_domain_window_disable);
 
+struct dentry *iommu_debugfs_top;
+
 static int __init iommu_init(void)
 {
        iommu_group_kset = kset_create_and_add("iommu_groups",
@@ -1236,6 +1239,12 @@ static int __init iommu_init(void)
 
        BUG_ON(!iommu_group_kset);
 
+       iommu_debugfs_top = debugfs_create_dir("iommu", NULL);
+       if (!iommu_debugfs_top) {
+               pr_err("Couldn't create iommu debugfs directory\n");
+               return -ENODEV;
+       }
+
        return 0;
 }
 arch_initcall(iommu_init);
index a0edc7c..4c7d919 100644 (file)
@@ -101,6 +101,8 @@ enum iommu_attr {
        DOMAIN_ATTR_MAX,
 };
 
+extern struct dentry *iommu_debugfs_top;
+
 #ifdef CONFIG_IOMMU_API
 
 /**