All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1 2/5] drm/tegra: gr2d: Add IOMMU support
Date: Fri,  4 May 2018 02:47:20 +0300	[thread overview]
Message-ID: <20180503234723.4368-3-digetx@gmail.com> (raw)
In-Reply-To: <20180503234723.4368-1-digetx@gmail.com>

Attach GR2D to the display IOMMU group in order to provide GR2D access
to BO's IOVA.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/gpu/drm/tegra/gr2d.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tegra/gr2d.c b/drivers/gpu/drm/tegra/gr2d.c
index 9a8ea93016a9..8eb530a85dd0 100644
--- a/drivers/gpu/drm/tegra/gr2d.c
+++ b/drivers/gpu/drm/tegra/gr2d.c
@@ -7,12 +7,14 @@
  */
 
 #include <linux/clk.h>
+#include <linux/iommu.h>
 
 #include "drm.h"
 #include "gem.h"
 #include "gr2d.h"
 
 struct gr2d {
+	struct iommu_group *group;
 	struct tegra_drm_client client;
 	struct host1x_channel *channel;
 	struct clk *clk;
@@ -30,7 +32,9 @@ static int gr2d_init(struct host1x_client *client)
 	struct tegra_drm_client *drm = host1x_to_drm_client(client);
 	struct drm_device *dev = dev_get_drvdata(client->parent);
 	unsigned long flags = HOST1X_SYNCPT_HAS_BASE;
+	struct tegra_drm *tegra = dev->dev_private;
 	struct gr2d *gr2d = to_gr2d(drm);
+	int err;
 
 	gr2d->channel = host1x_channel_request(client->dev);
 	if (!gr2d->channel)
@@ -42,23 +46,46 @@ static int gr2d_init(struct host1x_client *client)
 		return -ENOMEM;
 	}
 
-	return tegra_drm_register_client(dev->dev_private, drm);
+	if (tegra->domain) {
+		gr2d->group = iommu_group_get(client->dev);
+
+		if (gr2d->group) {
+			err = iommu_attach_group(tegra->domain, gr2d->group);
+			if (err < 0) {
+				dev_err(client->dev,
+					"failed to attach to domain: %d\n",
+					err);
+				host1x_syncpt_free(client->syncpts[0]);
+				host1x_channel_put(gr2d->channel);
+				iommu_group_put(gr2d->group);
+				return err;
+			}
+		}
+	}
+
+	return tegra_drm_register_client(tegra, drm);
 }
 
 static int gr2d_exit(struct host1x_client *client)
 {
 	struct tegra_drm_client *drm = host1x_to_drm_client(client);
 	struct drm_device *dev = dev_get_drvdata(client->parent);
+	struct tegra_drm *tegra = dev->dev_private;
 	struct gr2d *gr2d = to_gr2d(drm);
 	int err;
 
-	err = tegra_drm_unregister_client(dev->dev_private, drm);
+	err = tegra_drm_unregister_client(tegra, drm);
 	if (err < 0)
 		return err;
 
 	host1x_syncpt_free(client->syncpts[0]);
 	host1x_channel_put(gr2d->channel);
 
+	if (gr2d->group) {
+		iommu_detach_group(tegra->domain, gr2d->group);
+		iommu_group_put(gr2d->group);
+	}
+
 	return 0;
 }
 
-- 
2.17.0

  parent reply	other threads:[~2018-05-03 23:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 23:47 [PATCH v1 0/5] Support IOMMU for 2d/3d on Tegra30/114 Dmitry Osipenko
2018-05-03 23:47 ` [PATCH v1 1/5] drm/tegra: dc: Balance IOMMU group refcounting Dmitry Osipenko
2018-05-04 10:45   ` Thierry Reding
2018-05-04 10:45     ` Thierry Reding
2018-05-04 11:28     ` Dmitry Osipenko
2018-05-04 12:19   ` Thierry Reding
2018-05-04 12:19     ` Thierry Reding
2018-05-03 23:47 ` Dmitry Osipenko [this message]
2018-05-04 10:54   ` [PATCH v1 2/5] drm/tegra: gr2d: Add IOMMU support Thierry Reding
2018-05-04 10:54     ` Thierry Reding
2018-05-04 11:31     ` Dmitry Osipenko
2018-05-04 12:20   ` Thierry Reding
2018-05-04 12:20     ` Thierry Reding
2018-05-03 23:47 ` [PATCH v1 3/5] drm/tegra: gr3d: " Dmitry Osipenko
2018-05-04 12:20   ` Thierry Reding
2018-05-04 12:20     ` Thierry Reding
2018-05-03 23:47 ` [PATCH v1 4/5] ARM: dts: tegra30: Add IOMMU nodes to Host1x and its clients Dmitry Osipenko
2018-05-04 15:22   ` Thierry Reding
2018-05-04 15:22     ` Thierry Reding
2018-05-03 23:47 ` [PATCH v1 5/5] ARM: dts: tegra114: " Dmitry Osipenko
2018-05-04 15:22   ` Thierry Reding
2018-05-04 10:56 ` [PATCH v1 0/5] Support IOMMU for 2d/3d on Tegra30/114 Thierry Reding
2018-05-04 10:56   ` Thierry Reding
2018-05-04 12:03   ` Dmitry Osipenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180503234723.4368-3-digetx@gmail.com \
    --to=digetx@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.