Skip to content

Commit 41c3068

Browse files
committed
gpu: host1x: Use IOMMU groups
Use IOMMU groups to attach the host1x device to its IOMMU domain. This is not strictly necessary because the domain isn't shared with any other device, but it makes the code consistent with how IOMMU is handled in other drivers and provides an easy way to detect when no IOMMU has been attached via device tree. Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent ab7d3f5 commit 41c3068

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎drivers/gpu/host1x/dev.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,24 @@ static int host1x_probe(struct platform_device *pdev)
218218
return err;
219219
}
220220

221-
if (iommu_present(&platform_bus_type)) {
221+
host->group = iommu_group_get(&pdev->dev);
222+
if (host->group) {
222223
struct iommu_domain_geometry *geometry;
223224
unsigned long order;
224225

225226
host->domain = iommu_domain_alloc(&platform_bus_type);
226-
if (!host->domain)
227-
return -ENOMEM;
227+
if (!host->domain) {
228+
err = -ENOMEM;
229+
goto put_group;
230+
}
228231

229-
err = iommu_attach_device(host->domain, &pdev->dev);
232+
err = iommu_attach_group(host->domain, host->group);
230233
if (err) {
231234
if (err == -ENODEV) {
232235
iommu_domain_free(host->domain);
233236
host->domain = NULL;
237+
iommu_group_put(host->group);
238+
host->group = NULL;
234239
goto skip_iommu;
235240
}
236241

@@ -296,13 +301,15 @@ static int host1x_probe(struct platform_device *pdev)
296301
fail_free_channels:
297302
host1x_channel_list_free(&host->channel_list);
298303
fail_detach_device:
299-
if (host->domain) {
304+
if (host->group && host->domain) {
300305
put_iova_domain(&host->iova);
301-
iommu_detach_device(host->domain, &pdev->dev);
306+
iommu_detach_group(host->domain, host->group);
302307
}
303308
fail_free_domain:
304309
if (host->domain)
305310
iommu_domain_free(host->domain);
311+
put_group:
312+
iommu_group_put(host->group);
306313

307314
return err;
308315
}
@@ -319,8 +326,9 @@ static int host1x_remove(struct platform_device *pdev)
319326

320327
if (host->domain) {
321328
put_iova_domain(&host->iova);
322-
iommu_detach_device(host->domain, &pdev->dev);
329+
iommu_detach_group(host->domain, host->group);
323330
iommu_domain_free(host->domain);
331+
iommu_group_put(host->group);
324332
}
325333

326334
return 0;

‎drivers/gpu/host1x/dev.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct host1x {
117117
struct clk *clk;
118118
struct reset_control *rst;
119119

120+
struct iommu_group *group;
120121
struct iommu_domain *domain;
121122
struct iova_domain iova;
122123
dma_addr_t iova_end;

0 commit comments

Comments
 (0)