]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
iommu/arm-smmu: Support DMA-API domains
authorRobin Murphy <robin.murphy@arm.com>
Tue, 26 Jan 2016 18:06:36 +0000 (18:06 +0000)
committerWill Deacon <will.deacon@arm.com>
Thu, 18 Feb 2016 15:02:43 +0000 (15:02 +0000)
With DMA mapping ops provided by the iommu-dma code, only a minimal
contribution from the IOMMU driver is needed to create a suitable
DMA-API domain for them to use. Implement this for the ARM SMMUs.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
drivers/iommu/arm-smmu-v3.c
drivers/iommu/arm-smmu.c

index 20875341c865e20512afe2c44b2422181dd0f521..f003b3ab646bc059a3ba5f316e3e058a96e8f748 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include <linux/delay.h>
+#include <linux/dma-iommu.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/iommu.h>
@@ -1396,7 +1397,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;
 
        /*
@@ -1408,6 +1409,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);
        return &smmu_domain->domain;
@@ -1436,6 +1443,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
        struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
        struct arm_smmu_device *smmu = smmu_domain->smmu;
 
+       iommu_put_dma_cookie(domain);
        free_io_pgtable_ops(smmu_domain->pgtbl_ops);
 
        /* Free the CD and ASID, if we allocated them */
index 1f9093d76d938d9229e58afc1fe797a066cb43ed..e8e7bcc4540c4093bde79214328bb2b7739a7be3 100644 (file)
@@ -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>
@@ -966,7 +967,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.
@@ -977,6 +978,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);
 
@@ -991,6 +998,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);
 }