Commit aacdf198 authored by Thierry Reding's avatar Thierry Reding

drm/tegra: Move IOMMU group into host1x client

Handling of the IOMMU group attachment is common to all clients, so move
the group into the client to simplify code.
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
parent 7baa943e
...@@ -2014,9 +2014,8 @@ static int tegra_dc_init(struct host1x_client *client) ...@@ -2014,9 +2014,8 @@ static int tegra_dc_init(struct host1x_client *client)
if (!dc->syncpt) if (!dc->syncpt)
dev_warn(dc->dev, "failed to allocate syncpoint\n"); dev_warn(dc->dev, "failed to allocate syncpoint\n");
dc->group = host1x_client_iommu_attach(client, true); err = host1x_client_iommu_attach(client, true);
if (IS_ERR(dc->group)) { if (err < 0) {
err = PTR_ERR(dc->group);
dev_err(client->dev, "failed to attach to domain: %d\n", err); dev_err(client->dev, "failed to attach to domain: %d\n", err);
return err; return err;
} }
...@@ -2089,7 +2088,7 @@ static int tegra_dc_init(struct host1x_client *client) ...@@ -2089,7 +2088,7 @@ static int tegra_dc_init(struct host1x_client *client)
if (!IS_ERR(primary)) if (!IS_ERR(primary))
drm_plane_cleanup(primary); drm_plane_cleanup(primary);
host1x_client_iommu_detach(client, dc->group); host1x_client_iommu_detach(client);
host1x_syncpt_free(dc->syncpt); host1x_syncpt_free(dc->syncpt);
return err; return err;
...@@ -2114,7 +2113,7 @@ static int tegra_dc_exit(struct host1x_client *client) ...@@ -2114,7 +2113,7 @@ static int tegra_dc_exit(struct host1x_client *client)
return err; return err;
} }
host1x_client_iommu_detach(client, dc->group); host1x_client_iommu_detach(client);
host1x_syncpt_free(dc->syncpt); host1x_syncpt_free(dc->syncpt);
return 0; return 0;
......
...@@ -90,8 +90,6 @@ struct tegra_dc { ...@@ -90,8 +90,6 @@ struct tegra_dc {
struct drm_info_list *debugfs_files; struct drm_info_list *debugfs_files;
const struct tegra_dc_soc_info *soc; const struct tegra_dc_soc_info *soc;
struct iommu_group *group;
}; };
static inline struct tegra_dc * static inline struct tegra_dc *
......
...@@ -1068,8 +1068,7 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra, ...@@ -1068,8 +1068,7 @@ int tegra_drm_unregister_client(struct tegra_drm *tegra,
return 0; return 0;
} }
struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client, int host1x_client_iommu_attach(struct host1x_client *client, bool shared)
bool shared)
{ {
struct drm_device *drm = dev_get_drvdata(client->parent); struct drm_device *drm = dev_get_drvdata(client->parent);
struct tegra_drm *tegra = drm->dev_private; struct tegra_drm *tegra = drm->dev_private;
...@@ -1080,7 +1079,7 @@ struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client, ...@@ -1080,7 +1079,7 @@ struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client,
group = iommu_group_get(client->dev); group = iommu_group_get(client->dev);
if (!group) { if (!group) {
dev_err(client->dev, "failed to get IOMMU group\n"); dev_err(client->dev, "failed to get IOMMU group\n");
return ERR_PTR(-ENODEV); return -ENODEV;
} }
if (!shared || (shared && (group != tegra->group))) { if (!shared || (shared && (group != tegra->group))) {
...@@ -1095,7 +1094,7 @@ struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client, ...@@ -1095,7 +1094,7 @@ struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client,
err = iommu_attach_group(tegra->domain, group); err = iommu_attach_group(tegra->domain, group);
if (err < 0) { if (err < 0) {
iommu_group_put(group); iommu_group_put(group);
return ERR_PTR(err); return err;
} }
if (shared && !tegra->group) if (shared && !tegra->group)
...@@ -1103,22 +1102,23 @@ struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client, ...@@ -1103,22 +1102,23 @@ struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client,
} }
} }
return group; client->group = group;
return 0;
} }
void host1x_client_iommu_detach(struct host1x_client *client, void host1x_client_iommu_detach(struct host1x_client *client)
struct iommu_group *group)
{ {
struct drm_device *drm = dev_get_drvdata(client->parent); struct drm_device *drm = dev_get_drvdata(client->parent);
struct tegra_drm *tegra = drm->dev_private; struct tegra_drm *tegra = drm->dev_private;
if (group) { if (client->group) {
if (group == tegra->group) { if (client->group == tegra->group) {
iommu_detach_group(tegra->domain, group); iommu_detach_group(tegra->domain, client->group);
tegra->group = NULL; tegra->group = NULL;
} }
iommu_group_put(group); iommu_group_put(client->group);
} }
} }
......
...@@ -100,10 +100,8 @@ int tegra_drm_register_client(struct tegra_drm *tegra, ...@@ -100,10 +100,8 @@ int tegra_drm_register_client(struct tegra_drm *tegra,
struct tegra_drm_client *client); struct tegra_drm_client *client);
int tegra_drm_unregister_client(struct tegra_drm *tegra, int tegra_drm_unregister_client(struct tegra_drm *tegra,
struct tegra_drm_client *client); struct tegra_drm_client *client);
struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client, int host1x_client_iommu_attach(struct host1x_client *client, bool shared);
bool shared); void host1x_client_iommu_detach(struct host1x_client *client);
void host1x_client_iommu_detach(struct host1x_client *client,
struct iommu_group *group);
int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm); int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
int tegra_drm_exit(struct tegra_drm *tegra); int tegra_drm_exit(struct tegra_drm *tegra);
......
...@@ -17,7 +17,6 @@ struct gr2d_soc { ...@@ -17,7 +17,6 @@ struct gr2d_soc {
}; };
struct gr2d { struct gr2d {
struct iommu_group *group;
struct tegra_drm_client client; struct tegra_drm_client client;
struct host1x_channel *channel; struct host1x_channel *channel;
struct clk *clk; struct clk *clk;
...@@ -51,9 +50,8 @@ static int gr2d_init(struct host1x_client *client) ...@@ -51,9 +50,8 @@ static int gr2d_init(struct host1x_client *client)
goto put; goto put;
} }
gr2d->group = host1x_client_iommu_attach(client, false); err = host1x_client_iommu_attach(client, false);
if (IS_ERR(gr2d->group)) { if (err < 0) {
err = PTR_ERR(gr2d->group);
dev_err(client->dev, "failed to attach to domain: %d\n", err); dev_err(client->dev, "failed to attach to domain: %d\n", err);
goto free; goto free;
} }
...@@ -67,7 +65,7 @@ static int gr2d_init(struct host1x_client *client) ...@@ -67,7 +65,7 @@ static int gr2d_init(struct host1x_client *client)
return 0; return 0;
detach: detach:
host1x_client_iommu_detach(client, gr2d->group); host1x_client_iommu_detach(client);
free: free:
host1x_syncpt_free(client->syncpts[0]); host1x_syncpt_free(client->syncpts[0]);
put: put:
...@@ -87,7 +85,7 @@ static int gr2d_exit(struct host1x_client *client) ...@@ -87,7 +85,7 @@ static int gr2d_exit(struct host1x_client *client)
if (err < 0) if (err < 0)
return err; return err;
host1x_client_iommu_detach(client, gr2d->group); host1x_client_iommu_detach(client);
host1x_syncpt_free(client->syncpts[0]); host1x_syncpt_free(client->syncpts[0]);
host1x_channel_put(gr2d->channel); host1x_channel_put(gr2d->channel);
......
...@@ -23,7 +23,6 @@ struct gr3d_soc { ...@@ -23,7 +23,6 @@ struct gr3d_soc {
}; };
struct gr3d { struct gr3d {
struct iommu_group *group;
struct tegra_drm_client client; struct tegra_drm_client client;
struct host1x_channel *channel; struct host1x_channel *channel;
struct clk *clk_secondary; struct clk *clk_secondary;
...@@ -60,9 +59,8 @@ static int gr3d_init(struct host1x_client *client) ...@@ -60,9 +59,8 @@ static int gr3d_init(struct host1x_client *client)
goto put; goto put;
} }
gr3d->group = host1x_client_iommu_attach(client, false); err = host1x_client_iommu_attach(client, false);
if (IS_ERR(gr3d->group)) { if (err < 0) {
err = PTR_ERR(gr3d->group);
dev_err(client->dev, "failed to attach to domain: %d\n", err); dev_err(client->dev, "failed to attach to domain: %d\n", err);
goto free; goto free;
} }
...@@ -76,7 +74,7 @@ static int gr3d_init(struct host1x_client *client) ...@@ -76,7 +74,7 @@ static int gr3d_init(struct host1x_client *client)
return 0; return 0;
detach: detach:
host1x_client_iommu_detach(client, gr3d->group); host1x_client_iommu_detach(client);
free: free:
host1x_syncpt_free(client->syncpts[0]); host1x_syncpt_free(client->syncpts[0]);
put: put:
...@@ -95,7 +93,7 @@ static int gr3d_exit(struct host1x_client *client) ...@@ -95,7 +93,7 @@ static int gr3d_exit(struct host1x_client *client)
if (err < 0) if (err < 0)
return err; return err;
host1x_client_iommu_detach(client, gr3d->group); host1x_client_iommu_detach(client);
host1x_syncpt_free(client->syncpts[0]); host1x_syncpt_free(client->syncpts[0]);
host1x_channel_put(gr3d->channel); host1x_channel_put(gr3d->channel);
......
...@@ -34,7 +34,6 @@ struct vic { ...@@ -34,7 +34,6 @@ struct vic {
void __iomem *regs; void __iomem *regs;
struct tegra_drm_client client; struct tegra_drm_client client;
struct host1x_channel *channel; struct host1x_channel *channel;
struct iommu_group *group;
struct device *dev; struct device *dev;
struct clk *clk; struct clk *clk;
struct reset_control *rst; struct reset_control *rst;
...@@ -188,9 +187,8 @@ static int vic_init(struct host1x_client *client) ...@@ -188,9 +187,8 @@ static int vic_init(struct host1x_client *client)
struct vic *vic = to_vic(drm); struct vic *vic = to_vic(drm);
int err; int err;
vic->group = host1x_client_iommu_attach(client, false); err = host1x_client_iommu_attach(client, false);
if (IS_ERR(vic->group)) { if (err < 0) {
err = PTR_ERR(vic->group);
dev_err(vic->dev, "failed to attach to domain: %d\n", err); dev_err(vic->dev, "failed to attach to domain: %d\n", err);
return err; return err;
} }
...@@ -224,7 +222,7 @@ static int vic_init(struct host1x_client *client) ...@@ -224,7 +222,7 @@ static int vic_init(struct host1x_client *client)
free_channel: free_channel:
host1x_channel_put(vic->channel); host1x_channel_put(vic->channel);
detach: detach:
host1x_client_iommu_detach(client, vic->group); host1x_client_iommu_detach(client);
return err; return err;
} }
...@@ -246,7 +244,7 @@ static int vic_exit(struct host1x_client *client) ...@@ -246,7 +244,7 @@ static int vic_exit(struct host1x_client *client)
host1x_syncpt_free(client->syncpts[0]); host1x_syncpt_free(client->syncpts[0]);
host1x_channel_put(vic->channel); host1x_channel_put(vic->channel);
host1x_client_iommu_detach(client, vic->group); host1x_client_iommu_detach(client);
return 0; return 0;
} }
......
...@@ -18,6 +18,7 @@ enum host1x_class { ...@@ -18,6 +18,7 @@ enum host1x_class {
}; };
struct host1x_client; struct host1x_client;
struct iommu_group;
/** /**
* struct host1x_client_ops - host1x client operations * struct host1x_client_ops - host1x client operations
...@@ -34,6 +35,7 @@ struct host1x_client_ops { ...@@ -34,6 +35,7 @@ struct host1x_client_ops {
* @list: list node for the host1x client * @list: list node for the host1x client
* @parent: pointer to struct device representing the host1x controller * @parent: pointer to struct device representing the host1x controller
* @dev: pointer to struct device backing this host1x client * @dev: pointer to struct device backing this host1x client
* @group: IOMMU group that this client is a member of
* @ops: host1x client operations * @ops: host1x client operations
* @class: host1x class represented by this client * @class: host1x class represented by this client
* @channel: host1x channel associated with this client * @channel: host1x channel associated with this client
...@@ -44,6 +46,7 @@ struct host1x_client { ...@@ -44,6 +46,7 @@ struct host1x_client {
struct list_head list; struct list_head list;
struct device *parent; struct device *parent;
struct device *dev; struct device *dev;
struct iommu_group *group;
const struct host1x_client_ops *ops; const struct host1x_client_ops *ops;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment