@@ -804,57 +804,24 @@ struct iommu_dma_notifier_data {
804
804
static LIST_HEAD (iommu_dma_masters );
805
805
static DEFINE_MUTEX (iommu_dma_notifier_lock );
806
806
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
-
813
807
static bool do_iommu_attach (struct device * dev , const struct iommu_ops * ops ,
814
808
u64 dma_base , u64 size )
815
809
{
816
810
struct iommu_domain * domain = iommu_get_domain_for_dev (dev );
817
811
818
812
/*
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 .
822
816
*/
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;
841
821
}
842
822
843
- if (iommu_dma_init_domain (domain , dma_base , size ))
844
- goto out_detach ;
845
-
846
823
dev -> archdata .dma_ops = & iommu_dma_ops ;
847
824
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;
858
825
}
859
826
860
827
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)
971
938
{
972
939
struct iommu_domain * domain = iommu_get_domain_for_dev (dev );
973
940
974
- if (domain ) {
941
+ if (WARN_ON ( domain ))
975
942
iommu_detach_device (domain , dev );
976
- if (domain -> type & __IOMMU_DOMAIN_FAKE_DEFAULT )
977
- iommu_domain_free (domain );
978
- }
979
943
980
944
dev -> archdata .dma_ops = NULL ;
981
945
}
0 commit comments