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>
@@ -497,7 +498,9 @@ static void apple_dart_domain_flush_tlb(struct apple_dart_domain *domain)
497498 for (j = 0 ; j < BITS_TO_LONGS (stream_map .dart -> num_streams ); j ++ )
498499 stream_map .sidmap [j ] = atomic_long_read (& domain_stream_map -> sidmap [j ]);
499500
501+ WARN_ON (pm_runtime_get_sync (stream_map .dart -> dev ) < 0 );
500502 stream_map .dart -> hw -> invalidate_tlb (& stream_map );
503+ pm_runtime_put (stream_map .dart -> dev );
501504 }
502505}
503506
@@ -669,17 +672,24 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
669672 struct apple_dart_master_cfg * cfg = dev_iommu_priv_get (dev );
670673 struct apple_dart_domain * dart_domain = to_dart_domain (domain );
671674
675+ for_each_stream_map (i , cfg , stream_map )
676+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
677+
672678 ret = apple_dart_finalize_domain (dart_domain , cfg );
673679 if (ret )
674- return ret ;
680+ goto err ;
675681
676682 ret = apple_dart_domain_add_streams (dart_domain , cfg );
677683 if (ret )
678- return ret ;
684+ goto err ;
679685
680686 for_each_stream_map (i , cfg , stream_map )
681687 apple_dart_setup_translation (dart_domain , stream_map );
682- return 0 ;
688+
689+ err :
690+ for_each_stream_map (i , cfg , stream_map )
691+ pm_runtime_put (stream_map -> dart -> dev );
692+ return ret ;
683693}
684694
685695static int apple_dart_attach_dev_identity (struct iommu_domain * domain ,
@@ -692,8 +702,14 @@ static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
692702 if (!cfg -> supports_bypass )
693703 return - EINVAL ;
694704
705+ for_each_stream_map (i , cfg , stream_map )
706+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
707+
695708 for_each_stream_map (i , cfg , stream_map )
696709 apple_dart_hw_enable_bypass (stream_map );
710+
711+ for_each_stream_map (i , cfg , stream_map )
712+ pm_runtime_put (stream_map -> dart -> dev );
697713 return 0 ;
698714}
699715
@@ -713,8 +729,14 @@ static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
713729 struct apple_dart_stream_map * stream_map ;
714730 int i ;
715731
732+ for_each_stream_map (i , cfg , stream_map )
733+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
734+
716735 for_each_stream_map (i , cfg , stream_map )
717736 apple_dart_hw_disable_dma (stream_map );
737+
738+ for_each_stream_map (i , cfg , stream_map )
739+ pm_runtime_put (stream_map -> dart -> dev );
718740 return 0 ;
719741}
720742
@@ -1134,6 +1156,14 @@ static int apple_dart_probe(struct platform_device *pdev)
11341156 if (ret )
11351157 return ret ;
11361158
1159+ pm_runtime_get_noresume (dev );
1160+ pm_runtime_set_active (dev );
1161+ pm_runtime_irq_safe (dev );
1162+
1163+ ret = devm_pm_runtime_enable (dev );
1164+ if (ret )
1165+ goto err_clk_disable ;
1166+
11371167 dart_params [0 ] = readl (dart -> regs + DART_PARAMS1 );
11381168 dart_params [1 ] = readl (dart -> regs + DART_PARAMS2 );
11391169 dart -> pgsize = 1 << FIELD_GET (DART_PARAMS1_PAGE_SHIFT , dart_params [0 ]);
@@ -1183,6 +1213,8 @@ static int apple_dart_probe(struct platform_device *pdev)
11831213 if (ret )
11841214 goto err_sysfs_remove ;
11851215
1216+ pm_runtime_put (dev );
1217+
11861218 dev_info (
11871219 & pdev -> dev ,
11881220 "DART [pagesize %x, %d streams, bypass support: %d, bypass forced: %d] initialized\n" ,
@@ -1195,6 +1227,7 @@ static int apple_dart_probe(struct platform_device *pdev)
11951227err_free_irq :
11961228 free_irq (dart -> irq , dart );
11971229err_clk_disable :
1230+ pm_runtime_put (dev );
11981231 clk_bulk_disable_unprepare (dart -> num_clks , dart -> clks );
11991232
12001233 return ret ;
@@ -1353,7 +1386,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev)
13531386 return 0 ;
13541387}
13551388
1356- static DEFINE_SIMPLE_DEV_PM_OPS (apple_dart_pm_ops , apple_dart_suspend , apple_dart_resume ) ;
1389+ static DEFINE_RUNTIME_DEV_PM_OPS (apple_dart_pm_ops , apple_dart_suspend , apple_dart_resume , NULL ) ;
13571390
13581391static const struct of_device_id apple_dart_of_match [] = {
13591392 { .compatible = "apple,t8103-dart" , .data = & apple_dart_hw_t8103 },
@@ -1369,7 +1402,7 @@ static struct platform_driver apple_dart_driver = {
13691402 .name = "apple-dart" ,
13701403 .of_match_table = apple_dart_of_match ,
13711404 .suppress_bind_attrs = true,
1372- .pm = pm_sleep_ptr (& apple_dart_pm_ops ),
1405+ .pm = pm_ptr (& apple_dart_pm_ops ),
13731406 },
13741407 .probe = apple_dart_probe ,
13751408 .remove = apple_dart_remove ,
0 commit comments