Skip to content

Commit 921b1f5

Browse files
rmurphy-armwildea01
authored andcommitted
arm64/dma-mapping: Remove default domain workaround
With the IOMMU core now taking care of default domains for groups regardless of bus type, we can gleefully rip out this stop-gap, as slight recompense for having to expand the other one. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 226d89c commit 921b1f5

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

arch/arm64/mm/dma-mapping.c

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -804,57 +804,24 @@ struct iommu_dma_notifier_data {
804804
static LIST_HEAD(iommu_dma_masters);
805805
static DEFINE_MUTEX(iommu_dma_notifier_lock);
806806

807-
/*
808-
* Temporarily "borrow" a domain feature flag to to tell if we had to resort
809-
* to creating our own domain here, in case we need to clean it up again.
810-
*/
811-
#define __IOMMU_DOMAIN_FAKE_DEFAULT (1U << 31)
812-
813807
static bool do_iommu_attach(struct device *dev, const struct iommu_ops *ops,
814808
u64 dma_base, u64 size)
815809
{
816810
struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
817811

818812
/*
819-
* Best case: The device is either part of a group which was
820-
* already attached to a domain in a previous call, or it's
821-
* been put in a default DMA domain by the IOMMU core.
813+
* If the IOMMU driver has the DMA domain support that we require,
814+
* then the IOMMU core will have already configured a group for this
815+
* device, and allocated the default domain for that group.
822816
*/
823-
if (!domain) {
824-
/*
825-
* Urgh. The IOMMU core isn't going to do default domains
826-
* for non-PCI devices anyway, until it has some means of
827-
* abstracting the entirely implementation-specific
828-
* sideband data/SoC topology/unicorn dust that may or
829-
* may not differentiate upstream masters.
830-
* So until then, HORRIBLE HACKS!
831-
*/
832-
domain = ops->domain_alloc(IOMMU_DOMAIN_DMA);
833-
if (!domain)
834-
goto out_no_domain;
835-
836-
domain->ops = ops;
837-
domain->type = IOMMU_DOMAIN_DMA | __IOMMU_DOMAIN_FAKE_DEFAULT;
838-
839-
if (iommu_attach_device(domain, dev))
840-
goto out_put_domain;
817+
if (!domain || iommu_dma_init_domain(domain, dma_base, size)) {
818+
pr_warn("Failed to set up IOMMU for device %s; retaining platform DMA ops\n",
819+
dev_name(dev));
820+
return false;
841821
}
842822

843-
if (iommu_dma_init_domain(domain, dma_base, size))
844-
goto out_detach;
845-
846823
dev->archdata.dma_ops = &iommu_dma_ops;
847824
return true;
848-
849-
out_detach:
850-
iommu_detach_device(domain, dev);
851-
out_put_domain:
852-
if (domain->type & __IOMMU_DOMAIN_FAKE_DEFAULT)
853-
iommu_domain_free(domain);
854-
out_no_domain:
855-
pr_warn("Failed to set up IOMMU for device %s; retaining platform DMA ops\n",
856-
dev_name(dev));
857-
return false;
858825
}
859826

860827
static void queue_iommu_attach(struct device *dev, const struct iommu_ops *ops,
@@ -971,11 +938,8 @@ void arch_teardown_dma_ops(struct device *dev)
971938
{
972939
struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
973940

974-
if (domain) {
941+
if (WARN_ON(domain))
975942
iommu_detach_device(domain, dev);
976-
if (domain->type & __IOMMU_DOMAIN_FAKE_DEFAULT)
977-
iommu_domain_free(domain);
978-
}
979943

980944
dev->archdata.dma_ops = NULL;
981945
}

0 commit comments

Comments
 (0)