@@ -237,6 +237,7 @@ static const struct sysmmu_fault_info sysmmu_v5_faults[] = {
237
237
struct exynos_iommu_owner {
238
238
struct list_head controllers ; /* list of sysmmu_drvdata.owner_node */
239
239
struct iommu_domain * domain ; /* domain this device is attached */
240
+ struct mutex rpm_lock ; /* for runtime pm of all sysmmus */
240
241
};
241
242
242
243
/*
@@ -632,40 +633,46 @@ static int __init exynos_sysmmu_probe(struct platform_device *pdev)
632
633
return 0 ;
633
634
}
634
635
635
- #ifdef CONFIG_PM_SLEEP
636
- static int exynos_sysmmu_suspend (struct device * dev )
636
+ static int __maybe_unused exynos_sysmmu_suspend (struct device * dev )
637
637
{
638
638
struct sysmmu_drvdata * data = dev_get_drvdata (dev );
639
639
struct device * master = data -> master ;
640
640
641
641
if (master ) {
642
- pm_runtime_put (dev );
642
+ struct exynos_iommu_owner * owner = master -> archdata .iommu ;
643
+
644
+ mutex_lock (& owner -> rpm_lock );
643
645
if (data -> domain ) {
644
646
dev_dbg (data -> sysmmu , "saving state\n" );
645
647
__sysmmu_disable (data );
646
648
}
649
+ mutex_unlock (& owner -> rpm_lock );
647
650
}
648
651
return 0 ;
649
652
}
650
653
651
- static int exynos_sysmmu_resume (struct device * dev )
654
+ static int __maybe_unused exynos_sysmmu_resume (struct device * dev )
652
655
{
653
656
struct sysmmu_drvdata * data = dev_get_drvdata (dev );
654
657
struct device * master = data -> master ;
655
658
656
659
if (master ) {
657
- pm_runtime_get_sync (dev );
660
+ struct exynos_iommu_owner * owner = master -> archdata .iommu ;
661
+
662
+ mutex_lock (& owner -> rpm_lock );
658
663
if (data -> domain ) {
659
664
dev_dbg (data -> sysmmu , "restoring state\n" );
660
665
__sysmmu_enable (data );
661
666
}
667
+ mutex_unlock (& owner -> rpm_lock );
662
668
}
663
669
return 0 ;
664
670
}
665
- #endif
666
671
667
672
static const struct dev_pm_ops sysmmu_pm_ops = {
668
- SET_LATE_SYSTEM_SLEEP_PM_OPS (exynos_sysmmu_suspend , exynos_sysmmu_resume )
673
+ SET_RUNTIME_PM_OPS (exynos_sysmmu_suspend , exynos_sysmmu_resume , NULL )
674
+ SET_LATE_SYSTEM_SLEEP_PM_OPS (pm_runtime_force_suspend ,
675
+ pm_runtime_force_resume )
669
676
};
670
677
671
678
static const struct of_device_id sysmmu_of_match [] __initconst = {
@@ -813,7 +820,15 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
813
820
return ;
814
821
815
822
list_for_each_entry (data , & owner -> controllers , owner_node ) {
816
- __sysmmu_disable (data );
823
+ pm_runtime_put_sync (data -> sysmmu );
824
+ }
825
+
826
+ mutex_lock (& owner -> rpm_lock );
827
+
828
+ list_for_each_entry (data , & owner -> controllers , owner_node ) {
829
+ pm_runtime_get_noresume (data -> sysmmu );
830
+ if (pm_runtime_active (data -> sysmmu ))
831
+ __sysmmu_disable (data );
817
832
pm_runtime_put (data -> sysmmu );
818
833
}
819
834
@@ -828,6 +843,7 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain,
828
843
owner -> domain = NULL ;
829
844
spin_unlock_irqrestore (& domain -> lock , flags );
830
845
846
+ mutex_unlock (& owner -> rpm_lock );
831
847
832
848
dev_dbg (dev , "%s: Detached IOMMU with pgtable %pa\n" , __func__ ,
833
849
& pagetable );
@@ -848,6 +864,8 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
848
864
if (owner -> domain )
849
865
exynos_iommu_detach_device (owner -> domain , dev );
850
866
867
+ mutex_lock (& owner -> rpm_lock );
868
+
851
869
spin_lock_irqsave (& domain -> lock , flags );
852
870
list_for_each_entry (data , & owner -> controllers , owner_node ) {
853
871
spin_lock (& data -> lock );
@@ -859,9 +877,17 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain,
859
877
owner -> domain = iommu_domain ;
860
878
spin_unlock_irqrestore (& domain -> lock , flags );
861
879
880
+ list_for_each_entry (data , & owner -> controllers , owner_node ) {
881
+ pm_runtime_get_noresume (data -> sysmmu );
882
+ if (pm_runtime_active (data -> sysmmu ))
883
+ __sysmmu_enable (data );
884
+ pm_runtime_put (data -> sysmmu );
885
+ }
886
+
887
+ mutex_unlock (& owner -> rpm_lock );
888
+
862
889
list_for_each_entry (data , & owner -> controllers , owner_node ) {
863
890
pm_runtime_get_sync (data -> sysmmu );
864
- __sysmmu_enable (data );
865
891
}
866
892
867
893
dev_dbg (dev , "%s: Attached IOMMU with pgtable %pa\n" , __func__ ,
@@ -1239,6 +1265,7 @@ static int exynos_iommu_of_xlate(struct device *dev,
1239
1265
return - ENOMEM ;
1240
1266
1241
1267
INIT_LIST_HEAD (& owner -> controllers );
1268
+ mutex_init (& owner -> rpm_lock );
1242
1269
dev -> archdata .iommu = owner ;
1243
1270
}
1244
1271
0 commit comments