Skip to content

Commit 55c84fe

Browse files
marcanjannau
authored andcommitted
iommu: apple-dart: Enable runtime PM
Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 6f910e4 commit 55c84fe

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

drivers/iommu/apple-dart.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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>
@@ -569,10 +570,13 @@ static void apple_dart_domain_flush_tlb(struct apple_dart_domain *domain)
569570
for (j = 0; j < BITS_TO_LONGS(stream_map.dart->num_streams); j++)
570571
stream_map.sidmap[j] = atomic_long_read(&domain_stream_map->sidmap[j]);
571572

573+
WARN_ON(pm_runtime_get_sync(stream_map.dart->dev) < 0);
574+
572575
if (stream_map.dart->locked)
573576
apple_dart_hw_sync_locked(pgtbl_cfg, &stream_map);
574577

575578
stream_map.dart->hw->invalidate_tlb(&stream_map);
579+
pm_runtime_put(stream_map.dart->dev);
576580
}
577581
}
578582

@@ -778,13 +782,16 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
778782
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
779783
struct apple_dart_domain *dart_domain = to_dart_domain(domain);
780784

785+
for_each_stream_map(i, cfg, stream_map)
786+
WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0);
787+
781788
ret = apple_dart_finalize_domain(dart_domain, cfg);
782789
if (ret)
783-
return ret;
790+
goto err;
784791

785792
ret = apple_dart_domain_add_streams(dart_domain, cfg);
786793
if (ret)
787-
return ret;
794+
goto err;
788795

789796
for_each_stream_map(i, cfg, stream_map) {
790797
if (!stream_map->dart->locked)
@@ -794,7 +801,10 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain,
794801
stream_map);
795802
}
796803

797-
return 0;
804+
err:
805+
for_each_stream_map(i, cfg, stream_map)
806+
pm_runtime_put(stream_map->dart->dev);
807+
return ret;
798808
}
799809

800810
static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
@@ -807,8 +817,14 @@ static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
807817
if (!cfg->supports_bypass)
808818
return -EINVAL;
809819

820+
for_each_stream_map(i, cfg, stream_map)
821+
WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0);
822+
810823
for_each_stream_map(i, cfg, stream_map)
811824
apple_dart_hw_enable_bypass(stream_map);
825+
826+
for_each_stream_map(i, cfg, stream_map)
827+
pm_runtime_put(stream_map->dart->dev);
812828
return 0;
813829
}
814830

@@ -828,8 +844,14 @@ static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
828844
struct apple_dart_stream_map *stream_map;
829845
int i;
830846

847+
for_each_stream_map(i, cfg, stream_map)
848+
WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0);
849+
831850
for_each_stream_map(i, cfg, stream_map)
832851
apple_dart_hw_disable_dma(stream_map);
852+
853+
for_each_stream_map(i, cfg, stream_map)
854+
pm_runtime_put(stream_map->dart->dev);
833855
return 0;
834856
}
835857

@@ -1282,6 +1304,14 @@ static int apple_dart_probe(struct platform_device *pdev)
12821304
if (ret)
12831305
return ret;
12841306

1307+
pm_runtime_get_noresume(dev);
1308+
pm_runtime_set_active(dev);
1309+
pm_runtime_irq_safe(dev);
1310+
1311+
ret = devm_pm_runtime_enable(dev);
1312+
if (ret)
1313+
goto err_clk_disable;
1314+
12851315
dart_params[0] = readl(dart->regs + DART_PARAMS1);
12861316
dart_params[1] = readl(dart->regs + DART_PARAMS2);
12871317
dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]);
@@ -1339,6 +1369,8 @@ static int apple_dart_probe(struct platform_device *pdev)
13391369
if (ret)
13401370
goto err_sysfs_remove;
13411371

1372+
pm_runtime_put(dev);
1373+
13421374
dev_info(
13431375
&pdev->dev,
13441376
"DART [pagesize %x, %d streams, bypass support: %d, bypass forced: %d, locked: %d] initialized\n",
@@ -1351,6 +1383,7 @@ static int apple_dart_probe(struct platform_device *pdev)
13511383
err_free_irq:
13521384
free_irq(dart->irq, dart);
13531385
err_clk_disable:
1386+
pm_runtime_put(dev);
13541387
clk_bulk_disable_unprepare(dart->num_clks, dart->clks);
13551388

13561389
return ret;
@@ -1519,7 +1552,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev)
15191552
return 0;
15201553
}
15211554

1522-
static DEFINE_SIMPLE_DEV_PM_OPS(apple_dart_pm_ops, apple_dart_suspend, apple_dart_resume);
1555+
static DEFINE_RUNTIME_DEV_PM_OPS(apple_dart_pm_ops, apple_dart_suspend, apple_dart_resume, NULL);
15231556

15241557
static const struct of_device_id apple_dart_of_match[] = {
15251558
{ .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 },
@@ -1535,7 +1568,7 @@ static struct platform_driver apple_dart_driver = {
15351568
.name = "apple-dart",
15361569
.of_match_table = apple_dart_of_match,
15371570
.suppress_bind_attrs = true,
1538-
.pm = pm_sleep_ptr(&apple_dart_pm_ops),
1571+
.pm = pm_ptr(&apple_dart_pm_ops),
15391572
},
15401573
.probe = apple_dart_probe,
15411574
.remove = apple_dart_remove,

0 commit comments

Comments
 (0)