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
@@ -679,17 +682,24 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
679682 struct apple_dart_master_cfg * cfg = dev_iommu_priv_get (dev );
680683 struct apple_dart_domain * dart_domain = to_dart_domain (domain );
681684
685+ for_each_stream_map (i , cfg , stream_map )
686+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
687+
682688 ret = apple_dart_finalize_domain (dart_domain , cfg );
683689 if (ret )
684- return ret ;
690+ goto err ;
685691
686692 ret = apple_dart_domain_add_streams (dart_domain , cfg );
687693 if (ret )
688- return ret ;
694+ goto err ;
689695
690696 for_each_stream_map (i , cfg , stream_map )
691697 apple_dart_setup_translation (dart_domain , stream_map );
692- return 0 ;
698+
699+ err :
700+ for_each_stream_map (i , cfg , stream_map )
701+ pm_runtime_put (stream_map -> dart -> dev );
702+ return ret ;
693703}
694704
695705static int apple_dart_attach_dev_identity (struct iommu_domain * domain ,
@@ -702,8 +712,14 @@ static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
702712 if (!cfg -> supports_bypass )
703713 return - EINVAL ;
704714
715+ for_each_stream_map (i , cfg , stream_map )
716+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
717+
705718 for_each_stream_map (i , cfg , stream_map )
706719 apple_dart_hw_enable_bypass (stream_map );
720+
721+ for_each_stream_map (i , cfg , stream_map )
722+ pm_runtime_put (stream_map -> dart -> dev );
707723 return 0 ;
708724}
709725
@@ -723,8 +739,14 @@ static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
723739 struct apple_dart_stream_map * stream_map ;
724740 int i ;
725741
742+ for_each_stream_map (i , cfg , stream_map )
743+ WARN_ON (pm_runtime_get_sync (stream_map -> dart -> dev ) < 0 );
744+
726745 for_each_stream_map (i , cfg , stream_map )
727746 apple_dart_hw_disable_dma (stream_map );
747+
748+ for_each_stream_map (i , cfg , stream_map )
749+ pm_runtime_put (stream_map -> dart -> dev );
728750 return 0 ;
729751}
730752
@@ -1146,6 +1168,14 @@ static int apple_dart_probe(struct platform_device *pdev)
11461168 if (ret )
11471169 return ret ;
11481170
1171+ pm_runtime_get_noresume (dev );
1172+ pm_runtime_set_active (dev );
1173+ pm_runtime_irq_safe (dev );
1174+
1175+ ret = devm_pm_runtime_enable (dev );
1176+ if (ret )
1177+ goto err_clk_disable ;
1178+
11491179 dart_params [0 ] = readl (dart -> regs + DART_PARAMS1 );
11501180 dart_params [1 ] = readl (dart -> regs + DART_PARAMS2 );
11511181 dart -> pgsize = 1 << FIELD_GET (DART_PARAMS1_PAGE_SHIFT , dart_params [0 ]);
@@ -1196,6 +1226,8 @@ static int apple_dart_probe(struct platform_device *pdev)
11961226 if (ret )
11971227 goto err_sysfs_remove ;
11981228
1229+ pm_runtime_put (dev );
1230+
11991231 dev_info (
12001232 & pdev -> dev ,
12011233 "DART [pagesize %x, %d streams, bypass support: %d, bypass forced: %d, AS %d -> %d] initialized\n" ,
@@ -1208,6 +1240,7 @@ static int apple_dart_probe(struct platform_device *pdev)
12081240err_free_irq :
12091241 free_irq (dart -> irq , dart );
12101242err_clk_disable :
1243+ pm_runtime_put (dev );
12111244 clk_bulk_disable_unprepare (dart -> num_clks , dart -> clks );
12121245
12131246 return ret ;
@@ -1367,7 +1400,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev)
13671400 return 0 ;
13681401}
13691402
1370- static DEFINE_SIMPLE_DEV_PM_OPS (apple_dart_pm_ops , apple_dart_suspend , apple_dart_resume ) ;
1403+ static DEFINE_RUNTIME_DEV_PM_OPS (apple_dart_pm_ops , apple_dart_suspend , apple_dart_resume , NULL ) ;
13711404
13721405static const struct of_device_id apple_dart_of_match [] = {
13731406 { .compatible = "apple,t8103-dart" , .data = & apple_dart_hw_t8103 },
@@ -1383,7 +1416,7 @@ static struct platform_driver apple_dart_driver = {
13831416 .name = "apple-dart" ,
13841417 .of_match_table = apple_dart_of_match ,
13851418 .suppress_bind_attrs = true,
1386- .pm = pm_sleep_ptr (& apple_dart_pm_ops ),
1419+ .pm = pm_ptr (& apple_dart_pm_ops ),
13871420 },
13881421 .probe = apple_dart_probe ,
13891422 .remove = apple_dart_remove ,
0 commit comments