2828#include <linux/of_platform.h>
2929#include <linux/pci.h>
3030#include <linux/platform_device.h>
31+ #include <linux/pm_runtime.h>
3132#include <linux/slab.h>
3233#include <linux/swab.h>
3334#include <linux/types.h>
@@ -506,7 +507,9 @@ static void apple_dart_domain_flush_tlb(struct apple_dart_domain *domain)
506507 for (j = 0 ; j < BITS_TO_LONGS (stream_map .dart -> num_streams ); j ++ )
507508 stream_map .sidmap [j ] = atomic_long_read (& domain_stream_map -> sidmap [j ]);
508509
510+ WARN_ON (pm_runtime_get_sync (stream_map .dart -> dev ) < 0 );
509511 stream_map .dart -> hw -> invalidate_tlb (& stream_map );
512+ pm_runtime_put (stream_map .dart -> dev );
510513 }
511514}
512515
@@ -680,17 +683,24 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
680683 struct apple_dart_master_cfg * cfg = dev_iommu_priv_get (dev );
681684 struct apple_dart_domain * dart_domain = to_dart_domain (domain );
682685
686+ for_each_stream_map (i , cfg , stream_map )
687+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
688+
683689 ret = apple_dart_finalize_domain (dart_domain , cfg );
684690 if (ret )
685- return ret ;
691+ goto err ;
686692
687693 ret = apple_dart_domain_add_streams (dart_domain , cfg );
688694 if (ret )
689- return ret ;
695+ goto err ;
690696
691697 for_each_stream_map (i , cfg , stream_map )
692698 apple_dart_setup_translation (dart_domain , stream_map );
693- return 0 ;
699+
700+ err :
701+ for_each_stream_map (i , cfg , stream_map )
702+ pm_runtime_put (stream_map -> dart -> dev );
703+ return ret ;
694704}
695705
696706static int apple_dart_attach_dev_identity (struct iommu_domain * domain ,
@@ -704,8 +714,14 @@ static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
704714 if (!cfg -> supports_bypass )
705715 return - EINVAL ;
706716
717+ for_each_stream_map (i , cfg , stream_map )
718+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
719+
707720 for_each_stream_map (i , cfg , stream_map )
708721 apple_dart_hw_enable_bypass (stream_map );
722+
723+ for_each_stream_map (i , cfg , stream_map )
724+ pm_runtime_put (stream_map -> dart -> dev );
709725 return 0 ;
710726}
711727
@@ -726,8 +742,14 @@ static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
726742 struct apple_dart_stream_map * stream_map ;
727743 int i ;
728744
745+ for_each_stream_map (i , cfg , stream_map )
746+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
747+
729748 for_each_stream_map (i , cfg , stream_map )
730749 apple_dart_hw_disable_dma (stream_map );
750+
751+ for_each_stream_map (i , cfg , stream_map )
752+ pm_runtime_put (stream_map -> dart -> dev );
731753 return 0 ;
732754}
733755
@@ -1151,6 +1173,14 @@ static int apple_dart_probe(struct platform_device *pdev)
11511173 if (ret )
11521174 return ret ;
11531175
1176+ pm_runtime_get_noresume (dev );
1177+ pm_runtime_set_active (dev );
1178+ pm_runtime_irq_safe (dev );
1179+
1180+ ret = devm_pm_runtime_enable (dev );
1181+ if (ret )
1182+ goto err_clk_disable ;
1183+
11541184 dart_params [0 ] = readl (dart -> regs + DART_PARAMS1 );
11551185 dart_params [1 ] = readl (dart -> regs + DART_PARAMS2 );
11561186 dart -> pgsize = 1 << FIELD_GET (DART_PARAMS1_PAGE_SHIFT , dart_params [0 ]);
@@ -1201,6 +1231,8 @@ static int apple_dart_probe(struct platform_device *pdev)
12011231 if (ret )
12021232 goto err_sysfs_remove ;
12031233
1234+ pm_runtime_put (dev );
1235+
12041236 dev_info (
12051237 & pdev -> dev ,
12061238 "DART [pagesize %x, %d streams, bypass support: %d, bypass forced: %d, AS %d -> %d] initialized\n" ,
@@ -1213,6 +1245,7 @@ static int apple_dart_probe(struct platform_device *pdev)
12131245err_free_irq :
12141246 free_irq (dart -> irq , dart );
12151247err_clk_disable :
1248+ pm_runtime_put (dev );
12161249 clk_bulk_disable_unprepare (dart -> num_clks , dart -> clks );
12171250
12181251 return ret ;
@@ -1372,7 +1405,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev)
13721405 return 0 ;
13731406}
13741407
1375- static DEFINE_SIMPLE_DEV_PM_OPS (apple_dart_pm_ops , apple_dart_suspend , apple_dart_resume ) ;
1408+ static DEFINE_RUNTIME_DEV_PM_OPS (apple_dart_pm_ops , apple_dart_suspend , apple_dart_resume , NULL ) ;
13761409
13771410static const struct of_device_id apple_dart_of_match [] = {
13781411 { .compatible = "apple,t8103-dart" , .data = & apple_dart_hw_t8103 },
@@ -1388,7 +1421,7 @@ static struct platform_driver apple_dart_driver = {
13881421 .name = "apple-dart" ,
13891422 .of_match_table = apple_dart_of_match ,
13901423 .suppress_bind_attrs = true,
1391- .pm = pm_sleep_ptr (& apple_dart_pm_ops ),
1424+ .pm = pm_ptr (& apple_dart_pm_ops ),
13921425 },
13931426 .probe = apple_dart_probe ,
13941427 .remove = apple_dart_remove ,
0 commit comments