gpu: host1x: Add runtime pm support
v4 cover gpu: host1x: Add runtime pm support
This series adds runtime pm support for host1x, gr2d and dc. It retains the current behaviour if CONFIG_PM_RUNTIME is not enabled.
The gr2d clock is enabled when a new job is submitted and disabled when the work is done. Due to parent->child relations between host1x->gr2d, this scheme enables and disables host1x clock.
For dc, the clocks are enabled in .probe and disabled in .remove via runtime pm instead of direct clock APIs.
Mayuresh is unfortunately not available to continue with the series and hence I will continue working on the patches.
Changes in v4:
- Fixed initialisation clean up in host1x and gr2d drivers
- Runtime pm support removal follows now the same convention as other Tegra drivers
- Code shuffling to prevent unnecessary function prototypes
- Removed unnecessary NULL pointer checks.
- Rebased on top of 3.12-rc4
Changes in v3:
- Rebased patches on top of 3.12-rc2
- Removed unnecessary #ifdefs
- Added descriptions to commit messages
- If runtime pm is disabled, the code calls suspend/resume functions for enabling/disabling the clocks instead of repeating the functions
Arto Merilainen (1):
drm/tegra: Fix gr2d initialisation clean up
Mayuresh Kulkarni (4):
gpu: host1x: shuffle job APIs
drm/tegra: Add runtime pm support for gr2d
drm/tegra: Add runtime pm support for dc
gpu: host1x: Add runtime pm support for host1x
drivers/gpu/host1x/cdma.c | 2 ++ drivers/gpu/host1x/channel.c | 8 ----- drivers/gpu/host1x/channel.h | 1 - drivers/gpu/host1x/dev.c | 56 +++++++++++++++++++++++++++++----- drivers/gpu/host1x/drm/dc.c | 59 ++++++++++++++++++++++++++++++----- drivers/gpu/host1x/drm/gr2d.c | 71 ++++++++++++++++++++++++++++++++++++------- drivers/gpu/host1x/job.c | 13 ++++++++ drivers/gpu/host1x/job.h | 3 ++ 8 files changed, 177 insertions(+), 36 deletions(-)
Signature · 1 line
1.8.1.5
PATCH v4 1/5 drm/tegra: Fix gr2d initialisation clean up
gr2d initialisation clean up had missing steps (i.e. host1x channel was not released if we could not register gr2d as a host1x client) that could have lead to weird issues. This patch reworks the initialisation sequence to do clean up correctly.
--- drivers/gpu/host1x/drm/gr2d.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/gpu/host1x/drm/gr2d.c +16 -5
@@ -282,13 +282,15 @@ static int gr2d_probe(struct platform_device *pdev) } gr2d->channel =host1x_channel_request (dev); -if (!gr2d->channel) -return -ENOMEM ; +if (!gr2d->channel) { + err = -ENOMEM ; + goto err_channel_request; + } *syncpts =host1x_syncpt_request (dev, false);if (!(*syncpts)) { -host1x_channel_free (gr2d->channel); -return -ENOMEM ; + err = -ENOMEM ; + goto err_syncpt_request; } gr2d->client.ops = &gr2d_client_ops;
@@ -300,7 +302,7 @@ static int gr2d_probe(struct platform_device *pdev) err =host1x_register_client (host1x, &gr2d->client);if (err <0 ) {dev_err (dev,"failed to register host1x client: %d\n" , err); -return err; + goto err_register_client; }gr2d_init_addr_reg_map (dev, gr2d);
@@ -308,6 +310,15 @@ static int gr2d_probe(struct platform_device *pdev)platform_set_drvdata (pdev, gr2d);return 0 ; + +err_register_client: +host1x_syncpt_free (*gr2d->client.syncpts); +err_syncpt_request: +host1x_channel_free (gr2d->channel); +err_channel_request: +clk_disable_unprepare (gr2d->clk); + +return err; } static int __exit gr2d_remove(struct platform_device *pdev)
Signature · 1 line
1.8.1.5
PATCH v4 2/5 gpu: host1x: shuffle job APIs
In reply to Arto MerilainenFrom: Mayuresh Kulkarni <[email protected]>
This patch moves function host1x_job_submit() to job.c file where all other host1x_job_* functions are placed. This patch also introduces function host1x_job_complete().
--- drivers/gpu/host1x/cdma.c | 2 ++ drivers/gpu/host1x/channel.c | 8 -------- drivers/gpu/host1x/channel.h | 1 - drivers/gpu/host1x/job.c | 12 ++++++++++++ drivers/gpu/host1x/job.h | 3 +++ 5 files changed, 17 insertions(+), 9 deletions(-)
drivers/gpu/host1x/cdma.c +2 -0
@@ -252,6 +252,8 @@ static void update_cdma_locked(struct host1x_cdma *cdma) signal = true; } +host1x_job_complete (job); +list_del (&job->list);host1x_job_put (job); }
drivers/gpu/host1x/channel.c +0 -8
@@ -21,7 +21,6 @@#include "channel.h" #include "dev.h" -#include "job.h" /* Constructor for the host1x device list */ int host1x_channel_list_init (struct host1x *host)
@@ -37,13 +36,6 @@ int host1x_channel_list_init(struct host1x *host)return 0 ; } -int host1x_job_submit (struct host1x_job *job) -{ -struct host1x *host =dev_get_drvdata (job->channel->dev->parent); - -return host1x_hw_channel_submit (host, job); -} -struct host1x_channel *host1x_channel_get (struct host1x_channel *channel) {int err =0 ;
drivers/gpu/host1x/channel.h +0 -1
@@ -44,7 +44,6 @@ struct host1x_channel *host1x_channel_request(struct device *dev);void host1x_channel_free (struct host1x_channel *channel);struct host1x_channel *host1x_channel_get (struct host1x_channel *channel);void host1x_channel_put (struct host1x_channel *channel); -int host1x_job_submit (struct host1x_job *job);#define host1x_for_each_channel (host, channel) \ list_for_each_entry(channel, &host->chlist.list, list)
drivers/gpu/host1x/job.c +12 -0
@@ -585,3 +585,15 @@ void host1x_job_dump(struct device *dev, struct host1x_job *job)dev_dbg (dev," NUM_SLOTS %d\n" , job->num_slots);dev_dbg (dev," NUM_HANDLES %d\n" , job->num_unpins); } + +int host1x_job_submit (struct host1x_job *job) +{ +struct host1x *host =dev_get_drvdata (job->channel->dev->parent); + +return host1x_hw_channel_submit (host, job); +} + +int host1x_job_complete (struct host1x_job *job) +{ +return 0 ; +}
drivers/gpu/host1x/job.h +3 -0
@@ -159,4 +159,7 @@ void host1x_job_unpin(struct host1x_job *job);*/ void host1x_job_dump (struct device *dev,struct host1x_job *job); +int host1x_job_submit (struct host1x_job *job); +int host1x_job_complete (struct host1x_job *job); +#endif
Signature · 1 line
1.8.1.5
PATCH v4 3/5 drm/tegra: Add runtime pm support for gr2d
In reply to Arto MerilainenFrom: Mayuresh Kulkarni <[email protected]>
This far we have enabled gr2d clock on device probe and disabled it on device deinitialisation. This patch adds runtime pm support for the hardware unit allowing dynamic power management. If pm runtime is not enabled, gr2d clock is enabled in device probe and disabled in remove.
--- drivers/gpu/host1x/drm/gr2d.c | 52 +++++++++++++++++++++++++++++++++++++------ drivers/gpu/host1x/job.c | 5 +++-- 2 files changed, 48 insertions(+), 9 deletions(-)
drivers/gpu/host1x/drm/gr2d.c +45 -7
@@ -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"
@@ -46,6 +47,27 @@ static inline struct gr2d *to_gr2d(struct host1x_client *client)static int gr2d_is_addr_reg (struct device *dev,u32 class,u32 reg); +static int gr2d_runtime_suspend (struct device *dev) +{ +struct gr2d *gr2d =dev_get_drvdata (dev); + +clk_disable_unprepare (gr2d->clk); + +return 0 ; +} + +static int gr2d_runtime_resume (struct device *dev) +{ +int err =0 ; +struct gr2d *gr2d =dev_get_drvdata (dev); + + err =clk_prepare_enable (gr2d->clk); +if (err <0 ) +dev_err (dev,"failed to enable clock\n" ); + +return err; +} +static int gr2d_client_init (struct host1x_client *client,struct drm_device *drm) {
@@ -275,12 +297,18 @@ 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; +/* pm runtime accesses the clock through driver data */ +platform_set_drvdata (pdev, gr2d); + +pm_runtime_enable (&pdev->dev); +if (!pm_runtime_enabled (&pdev->dev)) { + err =gr2d_runtime_resume (&pdev->dev); +if (err <0 ) +return err; } +pm_runtime_get_sync (&pdev->dev); + gr2d->channel =host1x_channel_request (dev);if (!gr2d->channel) { err = -ENOMEM ;
@@ -307,7 +335,7 @@ static int gr2d_probe(struct platform_device *pdev)gr2d_init_addr_reg_map (dev, gr2d); -platform_set_drvdata (pdev, gr2d); +pm_runtime_put (&pdev->dev);return 0 ;
@@ -316,7 +344,9 @@ err_register_client: err_syncpt_request:host1x_channel_free (gr2d->channel); err_channel_request: -clk_disable_unprepare (gr2d->clk); +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +gr2d_runtime_suspend (&pdev->dev);return err; }
@@ -338,11 +368,18 @@ static int __exit gr2d_remove(struct platform_device *pdev)host1x_syncpt_free (gr2d->client.syncpts[i]);host1x_channel_free (gr2d->channel); -clk_disable_unprepare (gr2d->clk); + +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +gr2d_runtime_suspend (&pdev->dev);return 0 ; } +static const struct dev_pm_ops gr2d_pm_ops = { +SET_RUNTIME_PM_OPS (gr2d_runtime_suspend, gr2d_runtime_resume,NULL ) +}; +struct platform_driver tegra_gr2d_driver = { .probe = gr2d_probe, .remove =__exit_p (gr2d_remove),
@@ -350,5 +387,6 @@ struct platform_driver tegra_gr2d_driver = { .owner = THIS_MODULE, .name = "gr2d", .of_match_table = gr2d_match, + .pm = &gr2d_pm_ops, } };
drivers/gpu/host1x/job.c +3 -2
@@ -23,6 +23,7 @@#include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include <linux/pm_runtime.h> #include <trace/events/host1x.h> #include "channel.h"
@@ -589,11 +590,11 @@ void host1x_job_dump(struct device *dev, struct host1x_job *job)int host1x_job_submit (struct host1x_job *job) {struct host1x *host =dev_get_drvdata (job->channel->dev->parent); - +pm_runtime_get_sync (job->channel->dev);return host1x_hw_channel_submit (host, job); }int host1x_job_complete (struct host1x_job *job) { -return 0 ; +return pm_runtime_put (job->channel->dev); }
Signature · 1 line
1.8.1.5
PATCH v4 4/5 drm/tegra: Add runtime pm support for dc
In reply to Arto MerilainenFrom: Mayuresh Kulkarni <[email protected]>
This patch adds initial runtime pm support for Tegra display controller. As of now, the dc clock is enabled in device probe via runtime pm and disabled in device remove. In case pm runtime is not configured, we simply enable the clock in device probe (..and disable it in remove).
--- drivers/gpu/host1x/drm/dc.c | 59 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 8 deletions(-)
drivers/gpu/host1x/drm/dc.c +51 -8
@@ -13,6 +13,7 @@#include <linux/of.h> #include <linux/platform_device.h> #include <linux/clk/tegra.h> +#include <linux/pm_runtime.h> #include "host1x_client.h" #include "dc.h"
@@ -24,6 +25,27 @@ struct tegra_plane {unsigned int index; }; +static int tegra_dc_runtime_suspend (struct device *dev) +{ +struct tegra_dc *dc =dev_get_drvdata (dev); + +clk_disable_unprepare (dc->clk); + +return 0 ; +} + +static int tegra_dc_runtime_resume (struct device *dev) +{ +int err =0 ; +struct tegra_dc *dc =dev_get_drvdata (dev); + + err =clk_prepare_enable (dc->clk); +if (err <0 ) +dev_err (dev,"failed to enable clock\n" ); + +return err; +} +static inline struct tegra_plane *to_tegra_plane (struct drm_plane *plane) { return container_of(plane, struct tegra_plane, base);
@@ -1128,9 +1150,7 @@ static int tegra_dc_probe(struct platform_device *pdev)return PTR_ERR (dc->clk); } - err =clk_prepare_enable (dc->clk); -if (err <0 ) -return err; +platform_set_drvdata (pdev, dc); regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); dc->regs =devm_ioremap_resource (&pdev->dev, regs);
@@ -1147,22 +1167,37 @@ static int tegra_dc_probe(struct platform_device *pdev) dc->client.ops = &dc_client_ops; dc->client.dev = &pdev->dev; +pm_runtime_enable (&pdev->dev); +if (!pm_runtime_enabled (&pdev->dev)) { + err =tegra_dc_runtime_resume (&pdev->dev); +if (err <0 ) +return err; + } + +pm_runtime_get_sync (&pdev->dev); + err =tegra_dc_rgb_probe (dc);if (err <0 && err != -ENODEV ) {dev_err (&pdev->dev,"failed to probe RGB output: %d\n" , err); -return err; + goto err_dc_rgb_probe; } err =host1x_register_client (host1x, &dc->client);if (err <0 ) {dev_err (&pdev->dev,"failed to register host1x client: %d\n" , err); -return err; + goto err_register_client; } -platform_set_drvdata (pdev, dc); -return 0 ; + +err_register_client: +err_dc_rgb_probe: +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +tegra_dc_runtime_suspend (&pdev->dev); + +return err; }static int tegra_dc_remove (struct platform_device *pdev)
@@ -1178,11 +1213,18 @@ static int tegra_dc_remove(struct platform_device *pdev)return err; } -clk_disable_unprepare (dc->clk); +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +tegra_dc_runtime_suspend (&pdev->dev);return 0 ; } +static const struct dev_pm_ops tegra_dc_pm_ops = { +SET_RUNTIME_PM_OPS (tegra_dc_runtime_suspend, + tegra_dc_runtime_resume,NULL ) +}; +static struct of_device_id tegra_dc_of_match[] = { { .compatible ="nvidia,tegra30-dc" , }, { .compatible ="nvidia,tegra20-dc" , },
@@ -1194,6 +1236,7 @@ struct platform_driver tegra_dc_driver = { .name = "tegra-dc", .owner = THIS_MODULE, .of_match_table = tegra_dc_of_match, + .pm = &tegra_dc_pm_ops, }, .probe = tegra_dc_probe, .remove = tegra_dc_remove,
Signature · 1 line
1.8.1.5
PATCH v4 5/5 gpu: host1x: Add runtime pm support for host1x
In reply to Arto MerilainenFrom: Mayuresh Kulkarni <[email protected]>
This patch adds runtime pm support for host1x hardware unit. This allows host1x clock to be turned off when it is idle. If pm runtime is not configured, we enable host1x clock in device probe and disable it in remove.
--- drivers/gpu/host1x/dev.c | 56 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-)
drivers/gpu/host1x/dev.c +48 -8
@@ -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>
@@ -34,6 +35,27 @@#include "hw/host1x01.h" #include "host1x_client.h" +static int host1x_runtime_suspend (struct device *dev) +{ +struct host1x *host =dev_get_drvdata (dev); + +clk_disable_unprepare (host->clk); + +return 0 ; +} + +static int host1x_runtime_resume (struct device *dev) +{ +int err =0 ; +struct host1x *host =dev_get_drvdata (dev); + + err =clk_prepare_enable (host->clk); +if (err <0 ) +dev_err (dev,"failed to enable clock\n" ); + +return err; +} +void host1x_set_drm_data (struct device *dev,void *data) {struct host1x *host1x =dev_get_drvdata (dev);
@@ -143,32 +165,42 @@ 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; +pm_runtime_enable (&pdev->dev); +if (!pm_runtime_enabled (&pdev->dev)) { + err =host1x_runtime_resume (&pdev->dev); +if (err <0 ) +return err; } +pm_runtime_get_sync (&pdev->dev); + err =host1x_syncpt_init (host);if (err) {dev_err (&pdev->dev,"failed to initialize syncpts\n" ); -return err; + goto err_syncpt_init; } err =host1x_intr_init (host, syncpt_irq);if (err) {dev_err (&pdev->dev,"failed to initialize interrupts\n" ); - goto fail_deinit_syncpt; + goto err_intr_init; }host1x_debug_init (host);host1x_drm_alloc (pdev); +pm_runtime_put (&pdev->dev); +return 0 ; -fail_deinit_syncpt: +err_intr_init:host1x_syncpt_deinit (host); +err_syncpt_init: +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +pm_runtime_disable (&pdev->dev); +return err; }
@@ -178,11 +210,18 @@ static int __exit host1x_remove(struct platform_device *pdev)host1x_intr_deinit (host);host1x_syncpt_deinit (host); -clk_disable_unprepare (host->clk); + +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +host1x_runtime_suspend (&pdev->dev);return 0 ; } +static const struct dev_pm_ops host1x_pm_ops = { +SET_RUNTIME_PM_OPS (host1x_runtime_suspend, host1x_runtime_resume,NULL ) +}; +static struct platform_driver tegra_host1x_driver = { .probe = host1x_probe, .remove =__exit_p (host1x_remove),
@@ -190,6 +229,7 @@ static struct platform_driver tegra_host1x_driver = { .owner = THIS_MODULE, .name = "tegra-host1x", .of_match_table = host1x_of_match, + .pm = &host1x_pm_ops, }, };
Signature · 1 line
1.8.1.5
Quoted 7 lines · Arto Merilainen
This series adds runtime pm support for host1x, gr2d and dc. It retains the current behaviour if
CONFIG_PM_RUNTIMEis not enabled.The gr2d clock is enabled when a new job is submitted and disabled when the work is done. Due to
parent->childrelations betweenhost1x->gr2d, this scheme enables and disables host1x clock.
Quoted 5 lines
For dc, the clocks are enabled in .probe and disabled in .remove via runtime pm instead of direct clock APIs.
Mayuresh is unfortunately not available to continue with the series and hence I will continue working on the patches.
The series, briefly,
Quoted 7 lines · Arto Merilainen
This series adds runtime pm support for host1x, gr2d and dc. It retains the current behaviour if
CONFIG_PM_RUNTIMEis not enabled.The gr2d clock is enabled when a new job is submitted and disabled when the work is done. Due to
parent->childrelations betweenhost1x->gr2d, this scheme enables and disables host1x clock.
Quoted 5 lines
For dc, the clocks are enabled in .probe and disabled in .remove via runtime pm instead of direct clock APIs.
Mayuresh is unfortunately not available to continue with the series and hence I will continue working on the patches.
The series,
Terje