@@ -666,23 +666,13 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
666
666
if (ret )
667
667
return ret ;
668
668
669
- switch (domain -> type ) {
670
- case IOMMU_DOMAIN_DMA :
671
- case IOMMU_DOMAIN_UNMANAGED :
672
- ret = apple_dart_domain_add_streams (dart_domain , cfg );
673
- if (ret )
674
- return ret ;
675
-
676
- for_each_stream_map (i , cfg , stream_map )
677
- apple_dart_setup_translation (dart_domain , stream_map );
678
- break ;
679
- case IOMMU_DOMAIN_BLOCKED :
680
- for_each_stream_map (i , cfg , stream_map )
681
- apple_dart_hw_disable_dma (stream_map );
682
- break ;
683
- }
669
+ ret = apple_dart_domain_add_streams (dart_domain , cfg );
670
+ if (ret )
671
+ return ret ;
684
672
685
- return ret ;
673
+ for_each_stream_map (i , cfg , stream_map )
674
+ apple_dart_setup_translation (dart_domain , stream_map );
675
+ return 0 ;
686
676
}
687
677
688
678
static int apple_dart_attach_dev_identity (struct iommu_domain * domain ,
@@ -709,6 +699,30 @@ static struct iommu_domain apple_dart_identity_domain = {
709
699
.ops = & apple_dart_identity_ops ,
710
700
};
711
701
702
+ static int apple_dart_attach_dev_blocked (struct iommu_domain * domain ,
703
+ struct device * dev )
704
+ {
705
+ struct apple_dart_master_cfg * cfg = dev_iommu_priv_get (dev );
706
+ struct apple_dart_stream_map * stream_map ;
707
+ int i ;
708
+
709
+ if (cfg -> stream_maps [0 ].dart -> force_bypass )
710
+ return - EINVAL ;
711
+
712
+ for_each_stream_map (i , cfg , stream_map )
713
+ apple_dart_hw_disable_dma (stream_map );
714
+ return 0 ;
715
+ }
716
+
717
+ static const struct iommu_domain_ops apple_dart_blocked_ops = {
718
+ .attach_dev = apple_dart_attach_dev_blocked ,
719
+ };
720
+
721
+ static struct iommu_domain apple_dart_blocked_domain = {
722
+ .type = IOMMU_DOMAIN_BLOCKED ,
723
+ .ops = & apple_dart_blocked_ops ,
724
+ };
725
+
712
726
static struct iommu_device * apple_dart_probe_device (struct device * dev )
713
727
{
714
728
struct apple_dart_master_cfg * cfg = dev_iommu_priv_get (dev );
@@ -738,8 +752,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
738
752
{
739
753
struct apple_dart_domain * dart_domain ;
740
754
741
- if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
742
- type != IOMMU_DOMAIN_BLOCKED )
755
+ if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED )
743
756
return NULL ;
744
757
745
758
dart_domain = kzalloc (sizeof (* dart_domain ), GFP_KERNEL );
@@ -748,10 +761,6 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
748
761
749
762
mutex_init (& dart_domain -> init_lock );
750
763
751
- /* no need to allocate pgtbl_ops or do any other finalization steps */
752
- if (type == IOMMU_DOMAIN_BLOCKED )
753
- dart_domain -> finalized = true;
754
-
755
764
return & dart_domain -> domain ;
756
765
}
757
766
@@ -965,6 +974,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
965
974
966
975
static const struct iommu_ops apple_dart_iommu_ops = {
967
976
.identity_domain = & apple_dart_identity_domain ,
977
+ .blocked_domain = & apple_dart_blocked_domain ,
968
978
.domain_alloc = apple_dart_domain_alloc ,
969
979
.probe_device = apple_dart_probe_device ,
970
980
.release_device = apple_dart_release_device ,
0 commit comments