Skip to content

Commit ce2785a

Browse files
digetxjoergroedel
authored andcommitted
iommu/tegra: gart: Integrate with Memory Controller driver
The device-tree binding has been changed. There is no separate GART device anymore, it is squashed into the Memory Controller. Integrate GART module with the MC in a way it is done for the SMMU on Tegra30+. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 45594c6 commit ce2785a

File tree

4 files changed

+87
-53
lines changed

4 files changed

+87
-53
lines changed

drivers/iommu/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ config ROCKCHIP_IOMMU
282282
config TEGRA_IOMMU_GART
283283
bool "Tegra GART IOMMU Support"
284284
depends on ARCH_TEGRA_2x_SOC
285+
depends on TEGRA_MC
285286
select IOMMU_API
286287
help
287288
Enables support for remapping discontiguous physical memory

drivers/iommu/tegra-gart.c

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
2020
*/
2121

22-
#include <linux/init.h>
2322
#include <linux/io.h>
2423
#include <linux/iommu.h>
2524
#include <linux/list.h>
2625
#include <linux/moduleparam.h>
27-
#include <linux/of_device.h>
26+
#include <linux/platform_device.h>
2827
#include <linux/slab.h>
2928
#include <linux/spinlock.h>
3029
#include <linux/vmalloc.h>
3130

31+
#include <soc/tegra/mc.h>
32+
3233
/* bitmap of the page sizes currently supported */
3334
#define GART_IOMMU_PGSIZES (SZ_4K)
3435

@@ -397,9 +398,8 @@ static const struct iommu_ops gart_iommu_ops = {
397398
.iotlb_sync = gart_iommu_sync,
398399
};
399400

400-
static int tegra_gart_suspend(struct device *dev)
401+
int tegra_gart_suspend(struct gart_device *gart)
401402
{
402-
struct gart_device *gart = dev_get_drvdata(dev);
403403
unsigned long iova;
404404
u32 *data = gart->savedata;
405405
unsigned long flags;
@@ -411,9 +411,8 @@ static int tegra_gart_suspend(struct device *dev)
411411
return 0;
412412
}
413413

414-
static int tegra_gart_resume(struct device *dev)
414+
int tegra_gart_resume(struct gart_device *gart)
415415
{
416-
struct gart_device *gart = dev_get_drvdata(dev);
417416
unsigned long flags;
418417

419418
spin_lock_irqsave(&gart->pte_lock, flags);
@@ -422,41 +421,33 @@ static int tegra_gart_resume(struct device *dev)
422421
return 0;
423422
}
424423

425-
static int tegra_gart_probe(struct platform_device *pdev)
424+
struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc)
426425
{
427426
struct gart_device *gart;
428-
struct resource *res, *res_remap;
427+
struct resource *res_remap;
429428
void __iomem *gart_regs;
430-
struct device *dev = &pdev->dev;
431429
int ret;
432430

433431
BUILD_BUG_ON(PAGE_SHIFT != GART_PAGE_SHIFT);
434432

435433
/* the GART memory aperture is required */
436-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
437-
res_remap = platform_get_resource(pdev, IORESOURCE_MEM, 1);
438-
if (!res || !res_remap) {
434+
res_remap = platform_get_resource(to_platform_device(dev),
435+
IORESOURCE_MEM, 1);
436+
if (!res_remap) {
439437
dev_err(dev, "GART memory aperture expected\n");
440-
return -ENXIO;
438+
return ERR_PTR(-ENXIO);
441439
}
442440

443441
gart = devm_kzalloc(dev, sizeof(*gart), GFP_KERNEL);
444442
if (!gart) {
445443
dev_err(dev, "failed to allocate gart_device\n");
446-
return -ENOMEM;
447-
}
448-
449-
gart_regs = devm_ioremap(dev, res->start, resource_size(res));
450-
if (!gart_regs) {
451-
dev_err(dev, "failed to remap GART registers\n");
452-
return -ENXIO;
444+
return ERR_PTR(-ENOMEM);
453445
}
454446

455-
ret = iommu_device_sysfs_add(&gart->iommu, &pdev->dev, NULL,
456-
dev_name(&pdev->dev));
447+
ret = iommu_device_sysfs_add(&gart->iommu, dev, NULL, "gart");
457448
if (ret) {
458449
dev_err(dev, "Failed to register IOMMU in sysfs\n");
459-
return ret;
450+
return ERR_PTR(ret);
460451
}
461452

462453
iommu_device_set_ops(&gart->iommu, &gart_iommu_ops);
@@ -468,7 +459,8 @@ static int tegra_gart_probe(struct platform_device *pdev)
468459
goto remove_sysfs;
469460
}
470461

471-
gart->dev = &pdev->dev;
462+
gart->dev = dev;
463+
gart_regs = mc->regs + GART_REG_BASE;
472464
spin_lock_init(&gart->pte_lock);
473465
spin_lock_init(&gart->client_lock);
474466
INIT_LIST_HEAD(&gart->client);
@@ -483,46 +475,19 @@ static int tegra_gart_probe(struct platform_device *pdev)
483475
goto unregister_iommu;
484476
}
485477

486-
platform_set_drvdata(pdev, gart);
487478
do_gart_setup(gart, NULL);
488479

489480
gart_handle = gart;
490481

491-
return 0;
482+
return gart;
492483

493484
unregister_iommu:
494485
iommu_device_unregister(&gart->iommu);
495486
remove_sysfs:
496487
iommu_device_sysfs_remove(&gart->iommu);
497488

498-
return ret;
499-
}
500-
501-
static const struct dev_pm_ops tegra_gart_pm_ops = {
502-
.suspend = tegra_gart_suspend,
503-
.resume = tegra_gart_resume,
504-
};
505-
506-
static const struct of_device_id tegra_gart_of_match[] = {
507-
{ .compatible = "nvidia,tegra20-gart", },
508-
{ },
509-
};
510-
511-
static struct platform_driver tegra_gart_driver = {
512-
.probe = tegra_gart_probe,
513-
.driver = {
514-
.name = "tegra-gart",
515-
.pm = &tegra_gart_pm_ops,
516-
.of_match_table = tegra_gart_of_match,
517-
.suppress_bind_attrs = true,
518-
},
519-
};
520-
521-
static int __init tegra_gart_init(void)
522-
{
523-
return platform_driver_register(&tegra_gart_driver);
489+
return ERR_PTR(ret);
524490
}
525-
subsys_initcall(tegra_gart_init);
526491

527492
module_param(gart_debug, bool, 0644);
528493
MODULE_PARM_DESC(gart_debug, "Enable GART debugging");

drivers/memory/tegra/mc.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,56 @@ static int tegra_mc_probe(struct platform_device *pdev)
702702
PTR_ERR(mc->smmu));
703703
}
704704

705+
if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && !mc->soc->smmu) {
706+
mc->gart = tegra_gart_probe(&pdev->dev, mc);
707+
if (IS_ERR(mc->gart)) {
708+
dev_err(&pdev->dev, "failed to probe GART: %ld\n",
709+
PTR_ERR(mc->gart));
710+
mc->gart = NULL;
711+
}
712+
}
713+
714+
return 0;
715+
}
716+
717+
static int tegra_mc_suspend(struct device *dev)
718+
{
719+
struct tegra_mc *mc = dev_get_drvdata(dev);
720+
int err;
721+
722+
if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) {
723+
err = tegra_gart_suspend(mc->gart);
724+
if (err)
725+
return err;
726+
}
727+
705728
return 0;
706729
}
707730

731+
static int tegra_mc_resume(struct device *dev)
732+
{
733+
struct tegra_mc *mc = dev_get_drvdata(dev);
734+
int err;
735+
736+
if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) {
737+
err = tegra_gart_resume(mc->gart);
738+
if (err)
739+
return err;
740+
}
741+
742+
return 0;
743+
}
744+
745+
static const struct dev_pm_ops tegra_mc_pm_ops = {
746+
.suspend = tegra_mc_suspend,
747+
.resume = tegra_mc_resume,
748+
};
749+
708750
static struct platform_driver tegra_mc_driver = {
709751
.driver = {
710752
.name = "tegra-mc",
711753
.of_match_table = tegra_mc_of_match,
754+
.pm = &tegra_mc_pm_ops,
712755
.suppress_bind_attrs = true,
713756
},
714757
.prevent_deferred_probe = true,

include/soc/tegra/mc.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef __SOC_TEGRA_MC_H__
1010
#define __SOC_TEGRA_MC_H__
1111

12+
#include <linux/err.h>
1213
#include <linux/reset-controller.h>
1314
#include <linux/types.h>
1415

@@ -77,6 +78,7 @@ struct tegra_smmu_soc {
7778

7879
struct tegra_mc;
7980
struct tegra_smmu;
81+
struct gart_device;
8082

8183
#ifdef CONFIG_TEGRA_IOMMU_SMMU
8284
struct tegra_smmu *tegra_smmu_probe(struct device *dev,
@@ -96,6 +98,28 @@ static inline void tegra_smmu_remove(struct tegra_smmu *smmu)
9698
}
9799
#endif
98100

101+
#ifdef CONFIG_TEGRA_IOMMU_GART
102+
struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc);
103+
int tegra_gart_suspend(struct gart_device *gart);
104+
int tegra_gart_resume(struct gart_device *gart);
105+
#else
106+
static inline struct gart_device *
107+
tegra_gart_probe(struct device *dev, struct tegra_mc *mc)
108+
{
109+
return ERR_PTR(-ENODEV);
110+
}
111+
112+
static inline int tegra_gart_suspend(struct gart_device *gart)
113+
{
114+
return -ENODEV;
115+
}
116+
117+
static inline int tegra_gart_resume(struct gart_device *gart)
118+
{
119+
return -ENODEV;
120+
}
121+
#endif
122+
99123
struct tegra_mc_reset {
100124
const char *name;
101125
unsigned long id;
@@ -144,6 +168,7 @@ struct tegra_mc_soc {
144168
struct tegra_mc {
145169
struct device *dev;
146170
struct tegra_smmu *smmu;
171+
struct gart_device *gart;
147172
void __iomem *regs;
148173
struct clk *clk;
149174
int irq;

0 commit comments

Comments
 (0)