lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 27 May 2013 19:19:28 +0530
From:	Mayuresh Kulkarni <mkulkarni@...dia.com>
To:	<tbergstrom@...dia.com>, <amerilainen@...dia.com>,
	<thierry.reding@...onic-design.de>, <airlied@...hat.com>,
	<dri-devel@...ts.freedesktop.org>, <linux-tegra@...r.kernel.org>
CC:	<linux-kernel@...r.kernel.org>,
	Mayuresh Kulkarni <mkulkarni@...dia.com>
Subject: [PATCH] drm/tegra: add support for runtime pm

- as of now host1x and gr2d module's clocks are enabled
in their driver's .probe and never disabled
- this commit adds support for runtime pm in host1x and
gr2d drivers
- during boot-up clocks are enabled in .probe and disabled
on its exit
- when new work is submitted, clocks are enabled in submit
and disabled when submit completes
- parent->child relation between host1x and gr2d ensures
that host1x clock is also enabled before enabling gr2d clock
and it is turned off after gr2d clock is turned off

Signed-off-by: Mayuresh Kulkarni <mkulkarni@...dia.com>
---
 drivers/gpu/host1x/channel.c  |  5 ++++
 drivers/gpu/host1x/dev.c      | 58 ++++++++++++++++++++++++++++++++++++++----
 drivers/gpu/host1x/drm/gr2d.c | 59 ++++++++++++++++++++++++++++++++++++++-----
 drivers/gpu/host1x/intr.c     |  9 +++++--
 4 files changed, 118 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/host1x/channel.c b/drivers/gpu/host1x/channel.c
index 83ea51b..b71caec 100644
--- a/drivers/gpu/host1x/channel.c
+++ b/drivers/gpu/host1x/channel.c
@@ -18,6 +18,7 @@
 
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/pm_runtime.h>
 
 #include "channel.h"
 #include "dev.h"
@@ -41,6 +42,10 @@ int host1x_job_submit(struct host1x_job *job)
 {
 	struct host1x *host = dev_get_drvdata(job->channel->dev->parent);
 
+	/* enable clocks
+	 * they will be disabled in action_submit_complete */
+	pm_runtime_get_sync(job->channel->dev);
+
 	return host1x_hw_channel_submit(host, job);
 }
 
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
index 28e28a2..93d9d72 100644
--- a/drivers/gpu/host1x/dev.c
+++ b/drivers/gpu/host1x/dev.c
@@ -23,6 +23,7 @@
 #include <linux/of_device.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/pm_runtime.h>
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/host1x.h>
@@ -143,11 +144,11 @@ static int host1x_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = clk_prepare_enable(host->clk);
-	if (err < 0) {
-		dev_err(&pdev->dev, "failed to enable clock\n");
-		return err;
-	}
+	/* enable runtime pm */
+	pm_runtime_enable(&pdev->dev);
+
+	/* enable clocks */
+	pm_runtime_get_sync(&pdev->dev);
 
 	err = host1x_syncpt_init(host);
 	if (err) {
@@ -165,6 +166,9 @@ static int host1x_probe(struct platform_device *pdev)
 
 	host1x_drm_alloc(pdev);
 
+	/* disable clocks */
+	pm_runtime_put(&pdev->dev);
+
 	return 0;
 
 fail_deinit_syncpt:
@@ -183,6 +187,47 @@ static int __exit host1x_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_RUNTIME
+static int host1x_runtime_suspend(struct device *dev)
+{
+	struct host1x *host;
+
+	host = dev_get_drvdata(dev);
+	if (IS_ERR_OR_NULL(host))
+		return -EINVAL;
+
+	clk_disable_unprepare(host->clk);
+
+	return 0;
+}
+
+static int host1x_runtime_resume(struct device *dev)
+{
+	int err = 0;
+	struct host1x *host;
+
+	host = dev_get_drvdata(dev);
+	if (IS_ERR_OR_NULL(host))
+		return -EINVAL;
+
+	err = clk_prepare_enable(host->clk);
+	if (err < 0)
+		dev_err(dev, "failed to enable clock\n");
+
+	return err;
+}
+#endif /* CONFIG_PM_RUNTIME */
+
+#ifdef CONFIG_PM
+static const struct dev_pm_ops host1x_pm_ops = {
+#ifdef CONFIG_PM_RUNTIME
+	.runtime_suspend = host1x_runtime_suspend,
+	.runtime_resume = host1x_runtime_resume,
+#endif
+};
+
+#endif /* CONFIG_PM */
+
 static struct platform_driver tegra_host1x_driver = {
 	.probe = host1x_probe,
 	.remove = __exit_p(host1x_remove),
@@ -190,6 +235,9 @@ static struct platform_driver tegra_host1x_driver = {
 		.owner = THIS_MODULE,
 		.name = "tegra-host1x",
 		.of_match_table = host1x_of_match,
+#ifdef CONFIG_PM
+		.pm = &host1x_pm_ops,
+#endif
 	},
 };
 
diff --git a/drivers/gpu/host1x/drm/gr2d.c b/drivers/gpu/host1x/drm/gr2d.c
index 6a45ae0..172a654 100644
--- a/drivers/gpu/host1x/drm/gr2d.c
+++ b/drivers/gpu/host1x/drm/gr2d.c
@@ -22,6 +22,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/clk.h>
+#include <linux/pm_runtime.h>
 
 #include "channel.h"
 #include "drm.h"
@@ -271,11 +272,13 @@ static int gr2d_probe(struct platform_device *pdev)
 		return PTR_ERR(gr2d->clk);
 	}
 
-	err = clk_prepare_enable(gr2d->clk);
-	if (err) {
-		dev_err(dev, "cannot turn on clock\n");
-		return err;
-	}
+	platform_set_drvdata(pdev, gr2d);
+
+	/* enable runtime pm */
+	pm_runtime_enable(&pdev->dev);
+
+	/* enable clocks */
+	pm_runtime_get_sync(&pdev->dev);
 
 	gr2d->channel = host1x_channel_request(dev);
 	if (!gr2d->channel)
@@ -301,7 +304,8 @@ static int gr2d_probe(struct platform_device *pdev)
 
 	gr2d_init_addr_reg_map(dev, gr2d);
 
-	platform_set_drvdata(pdev, gr2d);
+	/* disable clocks */
+	pm_runtime_put(&pdev->dev);
 
 	return 0;
 }
@@ -328,6 +332,46 @@ static int __exit gr2d_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_RUNTIME
+static int gr2d_runtime_suspend(struct device *dev)
+{
+	struct gr2d *gr2d;
+
+	gr2d = dev_get_drvdata(dev);
+	if (IS_ERR_OR_NULL(gr2d))
+		return -EINVAL;
+
+	clk_disable_unprepare(gr2d->clk);
+
+	return 0;
+}
+
+static int gr2d_runtime_resume(struct device *dev)
+{
+	int err = 0;
+	struct gr2d *gr2d;
+
+	gr2d = dev_get_drvdata(dev);
+	if (IS_ERR_OR_NULL(gr2d))
+		return -EINVAL;
+
+	err = clk_prepare_enable(gr2d->clk);
+	if (err < 0)
+		dev_err(dev, "failed to enable clock\n");
+
+	return err;
+}
+#endif /* CONFIG_PM_RUNTIME */
+
+#ifdef CONFIG_PM
+static const struct dev_pm_ops gr2d_pm_ops = {
+#ifdef CONFIG_PM_RUNTIME
+	.runtime_suspend = gr2d_runtime_suspend,
+	.runtime_resume = gr2d_runtime_resume,
+#endif
+};
+#endif /* CONFIG_PM */
+
 struct platform_driver tegra_gr2d_driver = {
 	.probe = gr2d_probe,
 	.remove = __exit_p(gr2d_remove),
@@ -335,5 +379,8 @@ struct platform_driver tegra_gr2d_driver = {
 		.owner = THIS_MODULE,
 		.name = "gr2d",
 		.of_match_table = gr2d_match,
+#ifdef CONFIG_PM
+		.pm = &gr2d_pm_ops,
+#endif
 	}
 };
diff --git a/drivers/gpu/host1x/intr.c b/drivers/gpu/host1x/intr.c
index 2491bf8..c23fb64 100644
--- a/drivers/gpu/host1x/intr.c
+++ b/drivers/gpu/host1x/intr.c
@@ -20,6 +20,7 @@
 #include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/irq.h>
+#include <linux/pm_runtime.h>
 
 #include <trace/events/host1x.h>
 #include "channel.h"
@@ -109,14 +110,18 @@ static void reset_threshold_interrupt(struct host1x *host,
 
 static void action_submit_complete(struct host1x_waitlist *waiter)
 {
+	int completed = waiter->count;
 	struct host1x_channel *channel = waiter->data;
 
+	/* disable clocks for all the submits that got completed in this lot */
+	while (completed--)
+		pm_runtime_put(channel->dev);
+
 	host1x_cdma_update(&channel->cdma);
 
-	/*  Add nr_completed to trace */
+	/* Add nr_completed to trace */
 	trace_host1x_channel_submit_complete(dev_name(channel->dev),
 					     waiter->count, waiter->thresh);
-
 }
 
 static void action_wakeup(struct host1x_waitlist *waiter)
-- 
1.8.1.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists