iommu/tegra-smmu: Add debugfs support
authorThierry Reding <treding@nvidia.com>
Fri, 23 Jan 2015 08:49:25 +0000 (09:49 +0100)
committerThierry Reding <treding@nvidia.com>
Mon, 4 May 2015 10:54:23 +0000 (12:54 +0200)
Provide clients and swgroups files in debugfs. These files show for
which clients IOMMU translation is enabled and which ASID is associated
with each SWGROUP.

Cc: Hiroshi Doyu <hdoyu@nvidia.com>
Acked-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/iommu/tegra-smmu.c
include/soc/tegra/mc.h

index c845d99ecf6b8c50757998f08c86224c70064acb..c1f2e521dc52cdb383b528c27d07f0786e4ffc43 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/debugfs.h>
 #include <linux/err.h>
 #include <linux/iommu.h>
 #include <linux/kernel.h>
@@ -31,6 +32,8 @@ struct tegra_smmu {
        struct mutex lock;
 
        struct list_head list;
+
+       struct dentry *debugfs;
 };
 
 struct tegra_smmu_as {
@@ -673,6 +676,103 @@ static void tegra_smmu_ahb_enable(void)
        }
 }
 
+static int tegra_smmu_swgroups_show(struct seq_file *s, void *data)
+{
+       struct tegra_smmu *smmu = s->private;
+       unsigned int i;
+       u32 value;
+
+       seq_printf(s, "swgroup    enabled  ASID\n");
+       seq_printf(s, "------------------------\n");
+
+       for (i = 0; i < smmu->soc->num_swgroups; i++) {
+               const struct tegra_smmu_swgroup *group = &smmu->soc->swgroups[i];
+               const char *status;
+               unsigned int asid;
+
+               value = smmu_readl(smmu, group->reg);
+
+               if (value & SMMU_ASID_ENABLE)
+                       status = "yes";
+               else
+                       status = "no";
+
+               asid = value & SMMU_ASID_MASK;
+
+               seq_printf(s, "%-9s  %-7s  %#04x\n", group->name, status,
+                          asid);
+       }
+
+       return 0;
+}
+
+static int tegra_smmu_swgroups_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, tegra_smmu_swgroups_show, inode->i_private);
+}
+
+static const struct file_operations tegra_smmu_swgroups_fops = {
+       .open = tegra_smmu_swgroups_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+};
+
+static int tegra_smmu_clients_show(struct seq_file *s, void *data)
+{
+       struct tegra_smmu *smmu = s->private;
+       unsigned int i;
+       u32 value;
+
+       seq_printf(s, "client       enabled\n");
+       seq_printf(s, "--------------------\n");
+
+       for (i = 0; i < smmu->soc->num_clients; i++) {
+               const struct tegra_mc_client *client = &smmu->soc->clients[i];
+               const char *status;
+
+               value = smmu_readl(smmu, client->smmu.reg);
+
+               if (value & BIT(client->smmu.bit))
+                       status = "yes";
+               else
+                       status = "no";
+
+               seq_printf(s, "%-12s %s\n", client->name, status);
+       }
+
+       return 0;
+}
+
+static int tegra_smmu_clients_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, tegra_smmu_clients_show, inode->i_private);
+}
+
+static const struct file_operations tegra_smmu_clients_fops = {
+       .open = tegra_smmu_clients_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+};
+
+static void tegra_smmu_debugfs_init(struct tegra_smmu *smmu)
+{
+       smmu->debugfs = debugfs_create_dir("smmu", NULL);
+       if (!smmu->debugfs)
+               return;
+
+       debugfs_create_file("swgroups", S_IRUGO, smmu->debugfs, smmu,
+                           &tegra_smmu_swgroups_fops);
+       debugfs_create_file("clients", S_IRUGO, smmu->debugfs, smmu,
+                           &tegra_smmu_clients_fops);
+}
+
+static void tegra_smmu_debugfs_exit(struct tegra_smmu *smmu)
+{
+       debugfs_remove_recursive(smmu->debugfs);
+}
+
 struct tegra_smmu *tegra_smmu_probe(struct device *dev,
                                    const struct tegra_smmu_soc *soc,
                                    struct tegra_mc *mc)
@@ -743,5 +843,14 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
        if (err < 0)
                return ERR_PTR(err);
 
+       if (IS_ENABLED(CONFIG_DEBUG_FS))
+               tegra_smmu_debugfs_init(smmu);
+
        return smmu;
 }
+
+void tegra_smmu_remove(struct tegra_smmu *smmu)
+{
+       if (IS_ENABLED(CONFIG_DEBUG_FS))
+               tegra_smmu_debugfs_exit(smmu);
+}
index b2548811e1d55b8796ca9117cad51d0bdd0b43dd..e5ba518aaece545ad37fb0990c029c50342b3879 100644 (file)
@@ -72,6 +72,7 @@ struct tegra_smmu;
 struct tegra_smmu *tegra_smmu_probe(struct device *dev,
                                    const struct tegra_smmu_soc *soc,
                                    struct tegra_mc *mc);
+void tegra_smmu_remove(struct tegra_smmu *smmu);
 #else
 static inline struct tegra_smmu *
 tegra_smmu_probe(struct device *dev, const struct tegra_smmu_soc *soc,
@@ -79,6 +80,10 @@ tegra_smmu_probe(struct device *dev, const struct tegra_smmu_soc *soc,
 {
        return NULL;
 }
+
+static inline void tegra_smmu_remove(struct tegra_smmu *smmu)
+{
+}
 #endif
 
 struct tegra_mc_soc {