Skip to contentSkip to conversation

iommu/tegra-smmu: Add debugfs support

PATCH In review Thierry Reding 2 participants 9 messages Mar 27, 2015 – Apr 14, 2015 5 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 iommu/tegra-smmu: Add debugfs support

From: Thierry Reding <[email protected]>

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.

---
 drivers/iommu/tegra-smmu.c | 109 +++++++++++++++++++++++++++++++++++++++++++++
 include/soc/tegra/mc.h     |   5 +++
 2 files changed, 114 insertions(+)
drivers/iommu/tegra-smmu.c +109 -0
index 6e134c7c227f..fff45b3d3e57 100644
@@ -6,6 +6,7 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/debugfs.h>
 #include <linux/err.h>
 #include <linux/iommu.h>
 #include <linux/kernel.h>
@@ -28,6 +29,8 @@ struct tegra_smmu {
 	struct mutex lock;
 
 	struct list_head list;
+
+	struct dentry *debugfs;
 };
 
 struct tegra_smmu_as {
@@ -662,6 +665,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)
@@ -728,5 +828,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);
+}
include/soc/tegra/mc.h +5 -0
index 63deb8d9f82a..09a3dabf2ea7 100644
@@ -71,6 +71,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,
@@ -78,6 +79,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 {
Signature · 1 line
2.3.2

A message that is not in the archive (sent off-list or not yet received): 1427450847-17719-1-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/4 iommu/tegra: Setup aperture

From: Thierry Reding <[email protected]>

Each address space in the Tegra SMMU provides 4 GiB worth of addresses.

---
 drivers/iommu/tegra-smmu.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iommu/tegra-smmu.c +5 -0
index fff45b3d3e57..7b36760ae087 100644
@@ -269,6 +269,11 @@ static int tegra_smmu_domain_init(struct iommu_domain *domain)
 
 	domain->priv = as;
 
+	/* setup aperture */
+	domain->geometry.aperture_start = 0;
+	domain->geometry.aperture_end = 0xffffffff;
+	domain->geometry.force_aperture = true;
+
 	return 0;
 }
 
Signature · 1 line
2.3.2

A message that is not in the archive (sent off-list or not yet received): 1427450847-17719-2-git-send-email-thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

Re: [PATCH 2/4] iommu/tegra: Setup aperture

Quoted 15 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Each address space in the Tegra SMMU provides 4 GiB worth of addresses.

---
 drivers/iommu/tegra-smmu.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/iommu/tegra-smmu.c +0 -0
index fff45b3d3e57..7b36760ae087 100644

drivers/iommu/tegra-smmu.c static int tegra_smmu_domain_init(struct iommu_domain *domain) · line 278

Quoted 10 lines
drivers/iommu/tegra-smmu.c +5 -0
@@ -269,6 +269,11 @@ static int tegra_smmu_domain_init(struct iommu_domain *domain)
 
 	domain->priv = as;
 
+	/* setup aperture */
+	domain->geometry.aperture_start = 0;
+	domain->geometry.aperture_end = 0xffffffff;
+	domain->geometry.force_aperture = true;
+
 	return 0;
 }

I also just realized that this hunk conflicts with the IOMMU domain alloc/free series that you sent out yesterday. Were you planning on merging that series for 4.1? If so I can regenerate these patches on top of your series.

Thierry

A message that is not in the archive (sent off-list or not yet received): 20150327101935.GB17976-AwZRO8vwLAwmlAP/[email protected]

#6 lore raw

Re: [PATCH 2/4] iommu/tegra: Setup aperture

Quoted 4 lines · Thierry Reding

I also just realized that this hunk conflicts with the IOMMU domain alloc/free series that you sent out yesterday. Were you planning on merging that series for 4.1? If so I can regenerate these patches on top of your series.

Yes, I just merged the series. But please just base these patches on plain v4.0-rc6, so I can put them into a seperate branch. I'll try to solve the conflict then by myself.

Joerg

#7 lore raw

PATCH 3/4 iommu/tegra: gart: Set aperture at domain initialization time

In reply to a message not in the archive

From: Thierry Reding <[email protected]>

The aperture of the domain should always be available, otherwise drivers need to attach first before they can use the aperture geometry.

---
 drivers/iommu/tegra-gart.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/iommu/tegra-gart.c +14 -11
index c48da057dbb1..5f3b68c26b83 100644
@@ -156,20 +156,10 @@ static inline bool gart_iova_range_valid(struct gart_device *gart,
 static int gart_iommu_attach_dev(struct iommu_domain *domain,
 				 struct device *dev)
 {
-	struct gart_device *gart;
+	struct gart_device *gart = domain->priv;
 	struct gart_client *client, *c;
 	int err = 0;
 
-	gart = gart_handle;
-	if (!gart)
-		return -EINVAL;
-	domain->priv = gart;
-
-	domain->geometry.aperture_start = gart->iovmm_base;
-	domain->geometry.aperture_end   = gart->iovmm_base +
-					gart->page_count * GART_PAGE_SIZE - 1;
-	domain->geometry.force_aperture = true;
-
 	client = devm_kzalloc(gart->dev, sizeof(*c), GFP_KERNEL);
 	if (!client)
 		return -ENOMEM;
@@ -218,6 +208,19 @@ out:
 
 static int gart_iommu_domain_init(struct iommu_domain *domain)
 {
+	struct gart_device *gart;
+
+	gart = gart_handle;
+	if (!gart)
+		return -EINVAL;
+
+	domain->priv = gart;
+
+	domain->geometry.aperture_start = gart->iovmm_base;
+	domain->geometry.aperture_end = gart->iovmm_base +
+					gart->page_count * GART_PAGE_SIZE - 1;
+	domain->geometry.force_aperture = true;
+
 	return 0;
 }
 
Signature · 1 line
2.3.2
#8 lore raw

PATCH 4/4 iommu/tegra: smmu: Compute PFN mask at runtime

In reply to a message not in the archive

From: Thierry Reding <[email protected]>

The SMMU on Tegra30 and Tegra114 supports addressing up to 4 GiB of physical memory. On Tegra124 the addressable physical memory was extended to 16 GiB. The page frame number stored in PTEs therefore requires 20 or 22 bits, depending on SoC generation.

In order to cope with this, compute the proper value at runtime.

---
 drivers/iommu/tegra-smmu.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/iommu/tegra-smmu.c +10 -5
index 7b36760ae087..f0496e34ada3 100644
@@ -6,6 +6,7 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/bitops.h>
 #include <linux/debugfs.h>
 #include <linux/err.h>
 #include <linux/iommu.h>
@@ -25,6 +26,8 @@ struct tegra_smmu {
 	struct tegra_mc *mc;
 	const struct tegra_smmu_soc *soc;
 
+	unsigned long pfn_mask;
+
 	unsigned long *asids;
 	struct mutex lock;
 
@@ -108,8 +111,6 @@ static inline u32 smmu_readl(struct tegra_smmu *smmu, unsigned long offset)
 #define SMMU_PDE_SHIFT 22
 #define SMMU_PTE_SHIFT 12
 
-#define SMMU_PFN_MASK 0x000fffff
-
 #define SMMU_PD_READABLE	(1 << 31)
 #define SMMU_PD_WRITABLE	(1 << 30)
 #define SMMU_PD_NONSECURE	(1 << 29)
@@ -489,7 +490,7 @@ static u32 *as_get_pte(struct tegra_smmu_as *as, dma_addr_t iova,
 		smmu_flush_tlb_section(smmu, as->id, iova);
 		smmu_flush(smmu);
 	} else {
-		page = pfn_to_page(pd[pde] & SMMU_PFN_MASK);
+		page = pfn_to_page(pd[pde] & smmu->pfn_mask);
 		pt = page_address(page);
 	}
 
@@ -511,7 +512,7 @@ static void as_put_pte(struct tegra_smmu_as *as, dma_addr_t iova)
 	u32 *pd = page_address(as->pd), *pt;
 	struct page *page;
 
-	page = pfn_to_page(pd[pde] & SMMU_PFN_MASK);
+	page = pfn_to_page(pd[pde] & as->smmu->pfn_mask);
 	pt = page_address(page);
 
 	/*
@@ -586,7 +587,7 @@ static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,
 	u32 *pte;
 
 	pte = as_get_pte(as, iova, &page);
-	pfn = *pte & SMMU_PFN_MASK;
+	pfn = *pte & as->smmu->pfn_mask;
 
 	return PFN_PHYS(pfn);
 }
@@ -807,6 +808,10 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
 	smmu->dev = dev;
 	smmu->mc = mc;
 
+	smmu->pfn_mask = BIT_MASK(mc->soc->num_address_bits - PAGE_SHIFT) - 1;
+	dev_dbg(dev, "address bits: %u, PFN mask: %#lx\n",
+		mc->soc->num_address_bits, smmu->pfn_mask);
+
 	value = SMMU_PTC_CONFIG_ENABLE | SMMU_PTC_CONFIG_INDEX_MAP(0x3f);
 
 	if (soc->supports_request_limit)
Signature · 1 line
2.3.2
#9 lore raw
In reply to a message not in the archive
Quoted 6 lines · Thierry Reding

From: Thierry Reding <[email protected]>

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.

Quoted 6 lines
---
 drivers/iommu/tegra-smmu.c | 109 +++++++++++++++++++++++++++++++++++++++++++++
 include/soc/tegra/mc.h     |   5 +++
 2 files changed, 114 insertions(+)

Hi Joerg,

I forgot to mention that this patch depends on another patch that I plan to take through the Tegra tree. That patch adds the group names that are used by the debugfs support introduced here.

There are a couple of ways to solve this: omit this patch for v4.1 and merge it for v4.2, at which point the dependency will have been merged. That's obviously the simplest one and given that this is debugfs support it isn't very critical, just nice to have.

Another possibility would be for you to ack this patch so that I can take it into the same branch as the dependency. The remainder of this series doesn't depend on either of the two patches, so they should be fine for you to take into your tree.

Yet another alternative would be for me to provide a stable branch that can be merged into the Tegra and IOMMU trees, but quite frankly I don't think it's worth jumping through hoops like that for this particular patch. I'd prefer either the first or second alternative, whichever suits you best.

Thanks,
Thierry

A message that is not in the archive (sent off-list or not yet received): 20150327101539.GA17976-AwZRO8vwLAwmlAP/[email protected]

Acked-by
#11 lore raw

Hi Thierry,

Quoted 4 lines · Thierry Reding

Another possibility would be for you to ack this patch so that I can take it into the same branch as the dependency. The remainder of this series doesn't depend on either of the two patches, so they should be fine for you to take into your tree.

This solution sounds like the best one. You have my

on the first patch. I merged patches 2-4 into the arm/tegra branch. As you noticed there were conflict merging the branch into next. Please have a look into my solution for that when I pushed it out later today and let me know if it looks good and still works.

Joerg

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 8 lines · Joerg Roedel

Hi Thierry,

Quoted 4 lines · Thierry Reding

Another possibility would be for you to ack this patch so that I can take it into the same branch as the dependency. The remainder of this series doesn't depend on either of the two patches, so they should be fine for you to take into your tree.

Quoted 5 lines

This solution sounds like the best one. You have my

on the first patch.

Thanks.

Quoted 4 lines

I merged patches 2-4 into the arm/tegra branch. As
you noticed there were conflict merging the branch into next. Please have a look into my solution for that when I pushed it out later today and let me know if it looks good and still works.

Yes, the resolution looks correct and I've been running linux-next without issues for a couple of days now.

Thanks,
Thierry