From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>,
Alex Williamson <alex.williamson@redhat.com>,
Robin Murphy <robin.murphy@arm.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Christoph Hellwig <hch@infradead.org>,
Kevin Tian <kevin.tian@intel.com>,
Ashok Raj <ashok.raj@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Will Deacon <will@kernel.org>,
Dan Williams <dan.j.williams@intel.com>,
rafael@kernel.org, Diana Craciun <diana.craciun@oss.nxp.com>,
Cornelia Huck <cohuck@redhat.com>,
Eric Auger <eric.auger@redhat.com>, Liu Yi L <yi.l.liu@intel.com>,
Jacob jun Pan <jacob.jun.pan@intel.com>,
Chaitanya Kulkarni <kch@nvidia.com>,
Stuart Yoder <stuyoder@gmail.com>,
Laurentiu Tudor <laurentiu.tudor@nxp.com>,
Thierry Reding <thierry.reding@gmail.com>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Jonathan Hunter <jonathanh@nvidia.com>,
Li Yang <leoyang.li@nxp.com>, Dmitry Osipenko <digetx@gmail.com>,
iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH v1 4/8] drm/tegra: Use iommu_attach/detatch_device()
Date: Thu, 6 Jan 2022 10:20:49 +0800 [thread overview]
Message-ID: <20220106022053.2406748-5-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20220106022053.2406748-1-baolu.lu@linux.intel.com>
From: Jason Gunthorpe <jgg@nvidia.com>
Tegra joins many platform devices onto the same iommu_domain and builds
sort-of a DMA API on top of it.
Given that iommu_attach/detatch_device() has supported this usage model,
each device that wants to use the special domain could set the
no_kernel_api_dma field of the driver structure and call
iommu_attach/detach_device() directly which will use dma owner framework
to lock out other usages of the group and refcount the domain attachment.
When the last device calls detatch the domain will be disconnected.
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/gpu/drm/tegra/dc.c | 1 +
drivers/gpu/drm/tegra/drm.c | 47 ++++++++++++------------------------
drivers/gpu/drm/tegra/gr2d.c | 1 +
drivers/gpu/drm/tegra/gr3d.c | 1 +
drivers/gpu/drm/tegra/vic.c | 1 +
5 files changed, 20 insertions(+), 31 deletions(-)
diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index a29d64f87563..0da50b39ce00 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -3111,4 +3111,5 @@ struct platform_driver tegra_dc_driver = {
},
.probe = tegra_dc_probe,
.remove = tegra_dc_remove,
+ .no_kernel_api_dma = true,
};
diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index 8d37d6b00562..d6c57a40b772 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -928,12 +928,15 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
return 0;
}
+/*
+ * Clients which use this function must set suppress_auto_claim_dma_owner in
+ * their platform_driver's device_driver struct.
+ */
int host1x_client_iommu_attach(struct host1x_client *client)
{
struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev);
struct drm_device *drm = dev_get_drvdata(client->host);
struct tegra_drm *tegra = drm->dev_private;
- struct iommu_group *group = NULL;
int err;
/*
@@ -941,48 +944,30 @@ int host1x_client_iommu_attach(struct host1x_client *client)
* not the shared IOMMU domain, don't try to attach it to a different
* domain. This allows using the IOMMU-backed DMA API.
*/
- if (domain && domain != tegra->domain)
- return 0;
-
- if (tegra->domain) {
- group = iommu_group_get(client->dev);
- if (!group)
- return -ENODEV;
-
- if (domain != tegra->domain) {
- err = iommu_attach_group(tegra->domain, group);
- if (err < 0) {
- iommu_group_put(group);
- return err;
- }
- }
-
- tegra->use_explicit_iommu = true;
- }
+ client->group = NULL;
+ if (!client->dev->iommu_group || (domain && domain != tegra->domain))
+ return iommu_device_use_dma_api(client->dev);
- client->group = group;
+ err = iommu_attach_device(tegra->domain, client->dev);
+ if (err)
+ return err;
+ tegra->use_explicit_iommu = true;
+ client->group = client->dev->iommu_group;
return 0;
}
void host1x_client_iommu_detach(struct host1x_client *client)
{
+ struct iommu_domain *domain = iommu_get_domain_for_dev(client->dev);
struct drm_device *drm = dev_get_drvdata(client->host);
struct tegra_drm *tegra = drm->dev_private;
- struct iommu_domain *domain;
if (client->group) {
- /*
- * Devices that are part of the same group may no longer be
- * attached to a domain at this point because their group may
- * have been detached by an earlier client.
- */
- domain = iommu_get_domain_for_dev(client->dev);
- if (domain)
- iommu_detach_group(tegra->domain, client->group);
-
- iommu_group_put(client->group);
+ iommu_detach_device(tegra->domain, client->dev);
client->group = NULL;
+ } else {
+ iommu_device_unuse_dma_api(client->dev);
}
}
diff --git a/drivers/gpu/drm/tegra/gr2d.c b/drivers/gpu/drm/tegra/gr2d.c
index de288cba3905..6fd502c1cdbf 100644
--- a/drivers/gpu/drm/tegra/gr2d.c
+++ b/drivers/gpu/drm/tegra/gr2d.c
@@ -271,4 +271,5 @@ struct platform_driver tegra_gr2d_driver = {
},
.probe = gr2d_probe,
.remove = gr2d_remove,
+ .no_kernel_api_dma = true,
};
diff --git a/drivers/gpu/drm/tegra/gr3d.c b/drivers/gpu/drm/tegra/gr3d.c
index 24442ade0da3..d47794b6394f 100644
--- a/drivers/gpu/drm/tegra/gr3d.c
+++ b/drivers/gpu/drm/tegra/gr3d.c
@@ -400,4 +400,5 @@ struct platform_driver tegra_gr3d_driver = {
},
.probe = gr3d_probe,
.remove = gr3d_remove,
+ .no_kernel_api_dma = true,
};
diff --git a/drivers/gpu/drm/tegra/vic.c b/drivers/gpu/drm/tegra/vic.c
index c02010ff2b7f..167de5509c3b 100644
--- a/drivers/gpu/drm/tegra/vic.c
+++ b/drivers/gpu/drm/tegra/vic.c
@@ -527,6 +527,7 @@ struct platform_driver tegra_vic_driver = {
},
.probe = vic_probe,
.remove = vic_remove,
+ .no_kernel_api_dma = true,
};
#if IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC)
--
2.25.1
next prev parent reply other threads:[~2022-01-06 2:22 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 2:20 [PATCH v1 0/8] Scrap iommu_attach/detach_group() interfaces Lu Baolu
2022-01-06 2:20 ` [PATCH v1 1/8] iommu: Add iommu_group_replace_domain() Lu Baolu
2022-01-06 17:06 ` Jason Gunthorpe
2022-01-07 0:26 ` Lu Baolu
2022-02-14 12:09 ` Robin Murphy
2022-02-14 12:45 ` Jason Gunthorpe
2022-02-14 14:10 ` Robin Murphy
2022-02-14 14:56 ` Jason Gunthorpe
2022-02-14 16:38 ` Robin Murphy
2022-02-14 17:25 ` Jason Gunthorpe
2022-01-06 2:20 ` [PATCH v1 2/8] vfio/type1: Use iommu_group_replace_domain() Lu Baolu
2022-01-06 2:20 ` [PATCH v1 3/8] iommu: Extend iommu_at[de]tach_device() for multi-device groups Lu Baolu
2022-01-06 17:22 ` Jason Gunthorpe
2022-01-07 1:14 ` Lu Baolu
2022-01-07 1:19 ` Jason Gunthorpe
2022-02-14 11:39 ` Joerg Roedel
2022-02-14 13:03 ` Jason Gunthorpe
2022-02-14 14:39 ` Joerg Roedel
2022-02-14 15:18 ` Robin Murphy
2022-02-14 15:46 ` Jason Gunthorpe
2022-02-15 8:58 ` Joerg Roedel
2022-02-15 13:47 ` Jason Gunthorpe
2022-02-16 6:28 ` Lu Baolu
2022-02-16 13:54 ` Jason Gunthorpe
2022-01-06 2:20 ` Lu Baolu [this message]
2022-01-06 2:20 ` [PATCH v1 5/8] iommu/amd: Use iommu_attach/detach_device() Lu Baolu
2022-01-06 14:33 ` Jason Gunthorpe
2022-01-07 0:23 ` Lu Baolu
2022-02-14 11:27 ` Joerg Roedel
2022-02-14 13:15 ` Jason Gunthorpe
2022-02-14 13:40 ` Joerg Roedel
2022-02-14 14:02 ` Jason Gunthorpe
2022-02-14 14:23 ` Joerg Roedel
2022-02-14 15:00 ` Jason Gunthorpe
2022-02-15 9:11 ` Joerg Roedel
2022-02-15 13:02 ` Robin Murphy
2022-02-15 14:37 ` Jason Gunthorpe
2022-01-06 2:20 ` [PATCH v1 6/8] gpu/host1x: " Lu Baolu
2022-01-06 15:35 ` Jason Gunthorpe
2022-01-07 0:35 ` Lu Baolu
2022-01-07 0:48 ` Jason Gunthorpe
2022-01-07 1:19 ` Lu Baolu
2022-01-06 2:20 ` [PATCH v1 7/8] media: staging: media: tegra-vde: " Lu Baolu
2022-01-06 2:20 ` [PATCH v1 8/8] iommu: Remove iommu_attach/detach_group() Lu Baolu
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=20220106022053.2406748-5-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=airlied@linux.ie \
--cc=alex.williamson@redhat.com \
--cc=ashok.raj@intel.com \
--cc=bhelgaas@google.com \
--cc=cohuck@redhat.com \
--cc=dan.j.williams@intel.com \
--cc=daniel@ffwll.ch \
--cc=diana.craciun@oss.nxp.com \
--cc=digetx@gmail.com \
--cc=eric.auger@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=jgg@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=joro@8bytes.org \
--cc=kch@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=laurentiu.tudor@nxp.com \
--cc=leoyang.li@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=stuyoder@gmail.com \
--cc=thierry.reding@gmail.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).