Skip to content

Commit e8284ec

Browse files
committed
iommu: apple-dart: Enable runtime PM
Signed-off-by: Hector Martin <[email protected]>
1 parent 7edfa96 commit e8284ec

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

drivers/iommu/apple-dart.c

Lines changed: 24 additions & 4 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>
@@ -491,7 +492,9 @@ static void apple_dart_domain_flush_tlb(struct apple_dart_domain *domain)
491492
for (j = 0; j < BITS_TO_LONGS(stream_map.dart->num_streams); j++)
492493
stream_map.sidmap[j] = atomic_long_read(&domain_stream_map->sidmap[j]);
493494

495+
WARN_ON(pm_runtime_get_sync(stream_map.dart->dev) < 0);
494496
stream_map.dart->hw->invalidate_tlb(&stream_map);
497+
pm_runtime_put(stream_map.dart->dev);
495498
}
496499
}
497500

@@ -733,16 +736,19 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
733736
if (dart0->locked && domain->type != IOMMU_DOMAIN_DMA)
734737
return -EINVAL;
735738

739+
for_each_stream_map(i, cfg, stream_map)
740+
WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0);
741+
736742
ret = apple_dart_finalize_domain(domain, dev, cfg);
737743
if (ret)
738-
return ret;
744+
goto err;
739745

740746
switch (domain->type) {
741747
case IOMMU_DOMAIN_DMA:
742748
case IOMMU_DOMAIN_UNMANAGED:
743749
ret = apple_dart_domain_add_streams(dart_domain, cfg);
744750
if (ret)
745-
return ret;
751+
goto err;
746752

747753
for_each_stream_map(i, cfg, stream_map)
748754
apple_dart_setup_translation(dart_domain, stream_map);
@@ -757,6 +763,9 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
757763
break;
758764
}
759765

766+
err:
767+
for_each_stream_map(i, cfg, stream_map)
768+
pm_runtime_put(stream_map->dart->dev);
760769
return ret;
761770
}
762771

@@ -1169,6 +1178,14 @@ static int apple_dart_probe(struct platform_device *pdev)
11691178
if (ret)
11701179
return ret;
11711180

1181+
pm_runtime_get_noresume(dev);
1182+
pm_runtime_set_active(dev);
1183+
pm_runtime_irq_safe(dev);
1184+
1185+
ret = devm_pm_runtime_enable(dev);
1186+
if (ret)
1187+
goto err_clk_disable;
1188+
11721189
dart_params[0] = readl(dart->regs + DART_PARAMS1);
11731190
dart_params[1] = readl(dart->regs + DART_PARAMS2);
11741191
dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]);
@@ -1223,6 +1240,8 @@ static int apple_dart_probe(struct platform_device *pdev)
12231240
if (ret)
12241241
goto err_sysfs_remove;
12251242

1243+
pm_runtime_put(dev);
1244+
12261245
dev_info(
12271246
&pdev->dev,
12281247
"DART [pagesize %x, %d streams, bypass support: %d, bypass forced: %d, locked: %d] initialized\n",
@@ -1234,6 +1253,7 @@ static int apple_dart_probe(struct platform_device *pdev)
12341253
err_free_irq:
12351254
free_irq(dart->irq, dart);
12361255
err_clk_disable:
1256+
pm_runtime_put(dev);
12371257
clk_bulk_disable_unprepare(dart->num_clks, dart->clks);
12381258

12391259
return ret;
@@ -1373,7 +1393,7 @@ static __maybe_unused int apple_dart_resume(struct device *dev)
13731393
return 0;
13741394
}
13751395

1376-
DEFINE_SIMPLE_DEV_PM_OPS(apple_dart_pm_ops, apple_dart_suspend, apple_dart_resume);
1396+
DEFINE_RUNTIME_DEV_PM_OPS(apple_dart_pm_ops, apple_dart_suspend, apple_dart_resume, NULL);
13771397

13781398
static const struct of_device_id apple_dart_of_match[] = {
13791399
{ .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 },
@@ -1388,7 +1408,7 @@ static struct platform_driver apple_dart_driver = {
13881408
.name = "apple-dart",
13891409
.of_match_table = apple_dart_of_match,
13901410
.suppress_bind_attrs = true,
1391-
.pm = pm_sleep_ptr(&apple_dart_pm_ops),
1411+
.pm = pm_ptr(&apple_dart_pm_ops),
13921412
},
13931413
.probe = apple_dart_probe,
13941414
.remove = apple_dart_remove,

0 commit comments

Comments
 (0)