public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
From: robin.murphy@arm•com (Robin Murphy)
To: linux-arm-kernel@lists•infradead.org
Subject: [PATCH v6 2/3] arm64: Add IOMMU dma_ops
Date: Wed, 7 Oct 2015 17:36:24 +0100	[thread overview]
Message-ID: <56154A08.6060207@arm.com> (raw)
In-Reply-To: <CAAhSdy2tpAfH+i=1axDkmRqZixsbVhd-_9VGvpyQ=5e06v=Kpg@mail.gmail.com>

On 07/10/15 10:03, Anup Patel wrote:
[...]
>> +static bool do_iommu_attach(struct device *dev, const struct iommu_ops *ops,
>> +                          u64 dma_base, u64 size)
>> +{
>> +       struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
>> +
>> +       /*
>> +        * Best case: The device is either part of a group which was
>> +        * already attached to a domain in a previous call, or it's
>> +        * been put in a default DMA domain by the IOMMU core.
>> +        */
>> +       if (!domain) {
>> +               /*
>> +                * Urgh. The IOMMU core isn't going to do default domains
>> +                * for non-PCI devices anyway, until it has some means of
>> +                * abstracting the entirely implementation-specific
>> +                * sideband data/SoC topology/unicorn dust that may or
>> +                * may not differentiate upstream masters.
>> +                * So until then, HORRIBLE HACKS!
>> +                */
>> +               domain = ops->domain_alloc(IOMMU_DOMAIN_DMA);
>> +               if (!domain)
>> +                       goto out_no_domain;
>> +
>> +               domain->ops = ops;
>> +               domain->type = IOMMU_DOMAIN_DMA | __IOMMU_DOMAIN_FAKE_DEFAULT;
>
> We require iommu_get_dma_cookie(domain) here. If we dont
> allocate iommu cookie then iommu_dma_init_domain() will fail.

The iova cookie is tightly coupled with the domain, so it really only 
makes sense for the IOMMU driver to deal with it as part of its 
domain_alloc/domain_free callbacks.

Doing that here was one of the nastier 'compatibility' hacks which I've 
now taken out; trying to make things work without modifying existing 
IOMMU drivers was just too impractical. Drivers which want to play are 
now required to support the IOMMU_DOMAIN_DMA type appropriately, but 
it's still only a minimal change, as per the example diff for the ARM 
SMMU driver below (big pile of further patches necessary to make said 
driver compatible in other respects notwithstanding).

Robin.

--->8---
@@ -29,6 +29,7 @@
  #define pr_fmt(fmt) "arm-smmu: " fmt

  #include <linux/delay.h>
+#include <linux/dma-iommu.h>
  #include <linux/dma-mapping.h>
  #include <linux/err.h>
  #include <linux/interrupt.h>
@@ -973,7 +974,7 @@ static struct iommu_domain 
*arm_smmu_domain_alloc(unsigned type)
  {
  	struct arm_smmu_domain *smmu_domain;

-	if (type != IOMMU_DOMAIN_UNMANAGED)
+	if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA)
  		return NULL;
  	/*
  	 * Allocate the domain and initialise some of its data structures.
@@ -984,6 +985,12 @@ static struct iommu_domain 
*arm_smmu_domain_alloc(unsigned type)
  	if (!smmu_domain)
  		return NULL;

+	if (type == IOMMU_DOMAIN_DMA &&
+	    iommu_get_dma_cookie(&smmu_domain->domain)) {
+		kfree(smmu_domain);
+		return NULL;
+	}
+
  	mutex_init(&smmu_domain->init_mutex);
  	spin_lock_init(&smmu_domain->pgtbl_lock);

@@ -998,6 +1005,7 @@ static void arm_smmu_domain_free(struct 
iommu_domain *domain)
  	 * Free the domain resources. We assume that all devices have
  	 * already been detached.
  	 */
+	iommu_put_dma_cookie(domain);
  	arm_smmu_destroy_domain_context(domain);
  	kfree(smmu_domain);
  }

  reply	other threads:[~2015-10-07 16:36 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01 19:13 [PATCH v6 0/3] arm64: IOMMU-backed DMA mapping Robin Murphy
2015-10-01 19:13 ` [PATCH v6 1/3] iommu: Implement common IOMMU ops for " Robin Murphy
2015-10-26 13:44   ` Yong Wu
2015-10-26 16:55     ` Robin Murphy
2015-10-30  1:17       ` Daniel Kurtz
2015-10-30 14:09         ` Joerg Roedel
2015-10-30 14:27         ` Robin Murphy
2015-11-02 13:11           ` Daniel Kurtz
2015-11-02 13:43             ` Tomasz Figa
2015-11-03 17:41               ` Robin Murphy
2015-11-03 18:40                 ` Russell King - ARM Linux
2015-11-04  5:15                   ` Tomasz Figa
2015-11-04  9:10                     ` Russell King - ARM Linux
2015-11-04  5:12                 ` Tomasz Figa
2015-11-04  9:27                   ` Russell King - ARM Linux
2015-11-04  9:48                     ` Tomasz Figa
2015-11-04 10:50                       ` Russell King - ARM Linux
2015-11-09 13:11                   ` Robin Murphy
2015-11-17 12:02         ` Marek Szyprowski
2015-10-01 19:13 ` [PATCH v6 2/3] arm64: Add IOMMU dma_ops Robin Murphy
2015-10-06 11:00   ` Yong Wu
2015-10-07 16:07     ` Robin Murphy
2015-10-09  5:44       ` Yong Wu
2015-10-07  9:03   ` Anup Patel
2015-10-07 16:36     ` Robin Murphy [this message]
2015-10-07 17:40       ` Anup Patel
2015-10-14 11:47   ` Joerg Roedel
2015-10-14 13:35   ` Catalin Marinas
2015-10-14 16:34     ` Robin Murphy
2015-11-04  8:39   ` Yong Wu
2015-11-04 13:11     ` Robin Murphy
2015-11-04 17:35       ` Laura Abbott
2015-10-01 19:14 ` [PATCH v6 3/3] arm64: Hook up " Robin Murphy
2015-10-13 12:12 ` [PATCH v6 0/3] arm64: IOMMU-backed DMA mapping Robin Murphy
2015-10-14 11:50   ` joro at 8bytes.org
2015-10-14 18:19     ` Robin Murphy
2015-10-15 15:04 ` Joerg Roedel

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=56154A08.6060207@arm.com \
    --to=robin.murphy@arm$(echo .)com \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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