@@ -10,6 +10,7 @@
#include <linux/iommu.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <drm/drm_aperture.h>
#include <drm/drm_atomic.h>
@@ -116,6 +117,7 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
static void tegra_drm_context_free(struct tegra_drm_context *context)
{
context->client->ops->close_channel(context);
+ pm_runtime_put(context->client->base.dev);
kfree(context);
}
@@ -427,13 +429,20 @@ static int tegra_client_open(struct tegra_drm_file *fpriv,
{
int err;
+ err = pm_runtime_resume_and_get(client->base.dev);
+ if (err)
+ return err;
+
err = client->ops->open_channel(client, context);
- if (err < 0)
+ if (err < 0) {
+ pm_runtime_put(client->base.dev);
return err;
+ }
err = idr_alloc(&fpriv->legacy_contexts, context, 1, 0, GFP_KERNEL);
if (err < 0) {
client->ops->close_channel(context);
+ pm_runtime_put(client->base.dev);
return err;
}
@@ -127,17 +127,10 @@ static int gr2d_open_channel(struct tegra_drm_client *client,
struct tegra_drm_context *context)
{
struct gr2d *gr2d = to_gr2d(client);
- int err;
-
- err = pm_runtime_resume_and_get(client->base.dev);
- if (err)
- return err;
context->channel = host1x_channel_get(gr2d->channel);
- if (!context->channel) {
- pm_runtime_put(client->base.dev);
+ if (!context->channel)
return -ENOMEM;
- }
return 0;
}
@@ -145,7 +138,6 @@ static int gr2d_open_channel(struct tegra_drm_client *client,
static void gr2d_close_channel(struct tegra_drm_context *context)
{
host1x_channel_put(context->channel);
- pm_runtime_put(context->client->base.dev);
}
static int gr2d_is_addr_reg(struct device *dev, u32 class, u32 offset)
@@ -136,17 +136,10 @@ static int gr3d_open_channel(struct tegra_drm_client *client,
struct tegra_drm_context *context)
{
struct gr3d *gr3d = to_gr3d(client);
- int err;
-
- err = pm_runtime_resume_and_get(client->base.dev);
- if (err)
- return err;
context->channel = host1x_channel_get(gr3d->channel);
- if (!context->channel) {
- pm_runtime_put(client->base.dev);
+ if (!context->channel)
return -ENOMEM;
- }
return 0;
}
@@ -154,7 +147,6 @@ static int gr3d_open_channel(struct tegra_drm_client *client,
static void gr3d_close_channel(struct tegra_drm_context *context)
{
host1x_channel_put(context->channel);
- pm_runtime_put(context->client->base.dev);
}
static int gr3d_is_addr_reg(struct device *dev, u32 class, u32 offset)
@@ -291,29 +291,17 @@ static int nvdec_open_channel(struct tegra_drm_client *client,
struct tegra_drm_context *context)
{
struct nvdec *nvdec = to_nvdec(client);
- int err;
-
- err = pm_runtime_get_sync(nvdec->dev);
- if (err < 0) {
- pm_runtime_put(nvdec->dev);
- return err;
- }
context->channel = host1x_channel_get(nvdec->channel);
- if (!context->channel) {
- pm_runtime_put(nvdec->dev);
+ if (!context->channel)
return -ENOMEM;
- }
return 0;
}
static void nvdec_close_channel(struct tegra_drm_context *context)
{
- struct nvdec *nvdec = to_nvdec(context->client);
-
host1x_channel_put(context->channel);
- pm_runtime_put(nvdec->dev);
}
static const struct tegra_drm_client_ops nvdec_ops = {
@@ -344,27 +344,17 @@ static int vic_open_channel(struct tegra_drm_client *client,
struct tegra_drm_context *context)
{
struct vic *vic = to_vic(client);
- int err;
-
- err = pm_runtime_resume_and_get(vic->dev);
- if (err < 0)
- return err;
context->channel = host1x_channel_get(vic->channel);
- if (!context->channel) {
- pm_runtime_put(vic->dev);
+ if (!context->channel)
return -ENOMEM;
- }
return 0;
}
static void vic_close_channel(struct tegra_drm_context *context)
{
- struct vic *vic = to_vic(context->client);
-
host1x_channel_put(context->channel);
- pm_runtime_put(vic->dev);
}
static const struct tegra_drm_client_ops vic_ops = {
Move runtime PM management of older UAPI code paths into the common place. This removes boilerplate code from client drivers. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> --- drivers/gpu/drm/tegra/drm.c | 11 ++++++++++- drivers/gpu/drm/tegra/gr2d.c | 10 +--------- drivers/gpu/drm/tegra/gr3d.c | 10 +--------- drivers/gpu/drm/tegra/nvdec.c | 14 +------------- drivers/gpu/drm/tegra/vic.c | 12 +----------- 5 files changed, 14 insertions(+), 43 deletions(-)