iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Herrmann <andreas.herrmann@calxeda.com>
To: Will Deacon <will.deacon@arm.com>
Cc: Andreas Herrmann <andreas.herrmann@calxeda.com>,
	iommu@lists.linux-foundation.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 5/7] iommu/arm-smmu: Add function that isolates all masters for all SMMUs
Date: Tue, 24 Sep 2013 17:06:59 +0200	[thread overview]
Message-ID: <1380035221-11576-6-git-send-email-andreas.herrmann@calxeda.com> (raw)
In-Reply-To: <1380035221-11576-1-git-send-email-andreas.herrmann@calxeda.com>

Each device is put into its own protection domain (if possible).
For configuration with one or just a view masters per SMMU that
is easy to achieve.

In case of many devices per SMMU (e.g. MMU-500 with it's distributed
translation support) isolation of each device might not be possible --
depending on number of available SMR groups and/or context banks.

Derive dma_base and size from (coherent_)dma_mask of device

Signed-off-by: Andreas Herrmann <andreas.herrmann@calxeda.com>
---
 drivers/iommu/arm-smmu.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 0dfd255..3eb2259 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -46,6 +46,7 @@
 #include <linux/amba/bus.h>
 
 #include <asm/pgalloc.h>
+#include <asm/dma-iommu.h>
 
 /* Maximum number of stream IDs assigned to a single device */
 #define MAX_MASTER_STREAMIDS		8
@@ -1768,6 +1769,64 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 	return 0;
 }
 
+extern struct platform_device *of_find_device_by_node(struct device_node *np);
+
+static int arm_smmu_isolate_devices(void)
+{
+	struct dma_iommu_mapping *mapping;
+	struct arm_smmu_device *smmu;
+	struct rb_node *rbn;
+	struct arm_smmu_master *master;
+	struct platform_device *pdev;
+	struct device *dev;
+	void __iomem *gr0_base;
+	u32 cr0;
+	int ret = 0;
+	size_t size;
+
+	list_for_each_entry(smmu, &arm_smmu_devices, list) {
+		rbn = rb_first(&smmu->masters);
+		while (rbn) {
+			master = container_of(rbn, struct arm_smmu_master, node);
+			pdev = of_find_device_by_node(master->of_node);
+			if (!pdev)
+				break;
+			dev = &pdev->dev;
+
+			size = (size_t) dev->coherent_dma_mask;
+			size = size ? : (unsigned long) dev->dma_mask;
+			if (!size) {
+				dev_warn(dev, "(coherent_)dma_mask not set\n");
+				continue;
+			}
+
+			mapping = arm_iommu_create_mapping(&platform_bus_type,
+							0, size, 0);
+			if (IS_ERR(mapping)) {
+				ret = PTR_ERR(mapping);
+				dev_info(dev, "arm_iommu_create_mapping failed\n");
+				goto out;
+			}
+
+			ret = arm_iommu_attach_device(dev, mapping);
+			if (ret < 0) {
+				dev_info(dev, "arm_iommu_attach_device failed\n");
+				arm_iommu_release_mapping(mapping);
+			}
+			rbn = rb_next(rbn);
+		}
+
+		gr0_base = ARM_SMMU_GR0(smmu);
+		cr0 = readl_relaxed(gr0_base + ARM_SMMU_GR0_sCR0);
+		cr0 |= sCR0_USFCFG;
+		writel(cr0, gr0_base + ARM_SMMU_GR0_sCR0);
+	}
+
+out:
+	return ret;
+}
+
+
 static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 {
 	struct resource *res;
-- 
1.7.9.5

  parent reply	other threads:[~2013-09-24 15:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 15:06 [PATCH 0/7]: iommu/arm-smmu: Misc fixes/adaptions Andreas Herrmann
2013-09-24 15:06 ` [PATCH 1/7] iommu/arm-smmu: Switch to arch_initcall for driver registration Andreas Herrmann
2013-09-24 15:14   ` Andreas Herrmann
2013-09-24 15:19     ` Will Deacon
2013-09-24 15:06 ` [PATCH 2/7] iommu/arm-smmu: Calculate SMMU_CB_BASE from smmu register values Andreas Herrmann
2013-09-24 15:34   ` Will Deacon
     [not found]     ` <20130924153457.GC20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-24 18:07       ` Andreas Herrmann
2013-09-25 16:43         ` Will Deacon
2013-09-24 15:06 ` [PATCH 3/7] ARM: dma-mapping: Always pass proper prot flags to iommu_map() Andreas Herrmann
     [not found]   ` <1380035221-11576-4-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:36     ` Will Deacon
     [not found]       ` <20130924153625.GD20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-24 17:40         ` Andreas Herrmann
2013-09-24 15:06 ` [PATCH 4/7] iommu/arm-smmu: Check for num_context_irqs > 0 to avoid divide by zero exception Andreas Herrmann
     [not found]   ` <1380035221-11576-5-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:40     ` Will Deacon
     [not found]       ` <20130924154048.GE20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-25 10:50         ` Andreas Herrmann
2013-09-24 15:06 ` Andreas Herrmann [this message]
2013-09-24 15:07 ` [PATCH 6/7] iommu/arm-smmu: Add module parameter arm-smmu=off|force_isolation Andreas Herrmann
     [not found]   ` <1380035221-11576-7-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:42     ` Will Deacon
     [not found]       ` <20130924154218.GF20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-25 14:56         ` Andreas Herrmann
2013-09-25 15:57         ` Joerg Roedel
2013-09-24 15:07 ` [PATCH 7/7] iommu/arm-smmu: Clear global and context bank fault status and syndrome registers Andreas Herrmann
     [not found]   ` <1380035221-11576-8-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:42     ` Will Deacon
     [not found]       ` <20130924154252.GG20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-24 18:32         ` Andreas Herrmann
2013-09-25 16:49           ` Will Deacon
     [not found]             ` <20130925164917.GG14502-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-25 18:20               ` Andreas Herrmann
2013-09-24 15:31 ` [PATCH 0/7]: iommu/arm-smmu: Misc fixes/adaptions Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1380035221-11576-6-git-send-email-andreas.herrmann@calxeda.com \
    --to=andreas.herrmann@calxeda.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).