drm/tegra: Refactor IOMMU attach/detach
Attaching to and detaching from an IOMMU uses the same code sequence in every driver, so factor it out into separate helpers. Reviewed-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Thierry Reding <treding@nvidia.com>
This commit is contained in:
@@ -32,7 +32,6 @@ 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;
|
||||
|
||||
@@ -47,22 +46,14 @@ static int gr2d_init(struct host1x_client *client)
|
||||
goto put;
|
||||
}
|
||||
|
||||
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);
|
||||
iommu_group_put(gr2d->group);
|
||||
goto free;
|
||||
}
|
||||
}
|
||||
gr2d->group = host1x_client_iommu_attach(client, false);
|
||||
if (IS_ERR(gr2d->group)) {
|
||||
err = PTR_ERR(gr2d->group);
|
||||
dev_err(client->dev, "failed to attach to domain: %d\n", err);
|
||||
goto free;
|
||||
}
|
||||
|
||||
err = tegra_drm_register_client(tegra, drm);
|
||||
err = tegra_drm_register_client(dev->dev_private, drm);
|
||||
if (err < 0) {
|
||||
dev_err(client->dev, "failed to register client: %d\n", err);
|
||||
goto detach;
|
||||
@@ -71,10 +62,7 @@ static int gr2d_init(struct host1x_client *client)
|
||||
return 0;
|
||||
|
||||
detach:
|
||||
if (gr2d->group) {
|
||||
iommu_detach_group(tegra->domain, gr2d->group);
|
||||
iommu_group_put(gr2d->group);
|
||||
}
|
||||
host1x_client_iommu_detach(client, gr2d->group);
|
||||
free:
|
||||
host1x_syncpt_free(client->syncpts[0]);
|
||||
put:
|
||||
@@ -94,14 +82,10 @@ static int gr2d_exit(struct host1x_client *client)
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
host1x_client_iommu_detach(client, gr2d->group);
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user