Skip to content

Commit 52da6d5

Browse files
Jordan Crouserobclark
authored andcommitted
drm/msm: Attach the IOMMU device during initialization
Everywhere an IOMMU object is created by msm_gpu_create_address_space the IOMMU device is attached immediately after. Instead of carrying around the infrastructure to do the attach from the device specific code do it directly in the msm_iommu_init() function. This gets it out of the way for more aggressive cleanups that follow. Reviewed-by: Rob Clark <[email protected]> Signed-off-by: Jordan Crouse <[email protected]> Tested-by: Shawn Guo <[email protected]> [squash in rebase fixups and fix for unused fxn] Signed-off-by: Rob Clark <[email protected]>
1 parent 7d4eedb commit 52da6d5

File tree

9 files changed

+27
-55
lines changed

9 files changed

+27
-55
lines changed

drivers/gpu/drm/msm/adreno/a6xx_gmu.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,6 @@ static int a6xx_gmu_memory_alloc(struct a6xx_gmu *gmu, struct a6xx_gmu_bo *bo,
11141114
static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
11151115
{
11161116
struct iommu_domain *domain;
1117-
int ret;
11181117

11191118
domain = iommu_domain_alloc(&platform_bus_type);
11201119
if (!domain)
@@ -1129,12 +1128,6 @@ static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
11291128
return PTR_ERR(gmu->aspace);
11301129
}
11311130

1132-
ret = gmu->aspace->mmu->funcs->attach(gmu->aspace->mmu);
1133-
if (ret) {
1134-
msm_gem_address_space_put(gmu->aspace);
1135-
return ret;
1136-
}
1137-
11381131
return 0;
11391132
}
11401133

drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
794794
{
795795
struct iommu_domain *domain;
796796
struct msm_gem_address_space *aspace;
797-
int ret;
798797

799798
domain = iommu_domain_alloc(&platform_bus_type);
800799
if (!domain)
@@ -810,13 +809,6 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
810809
return PTR_ERR(aspace);
811810
}
812811

813-
ret = aspace->mmu->funcs->attach(aspace->mmu);
814-
if (ret) {
815-
DPU_ERROR("failed to attach iommu %d\n", ret);
816-
msm_gem_address_space_put(aspace);
817-
return ret;
818-
}
819-
820812
dpu_kms->base.aspace = aspace;
821813
return 0;
822814
}

drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,6 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev)
518518
}
519519

520520
kms->aspace = aspace;
521-
522-
ret = aspace->mmu->funcs->attach(aspace->mmu);
523-
if (ret)
524-
goto fail;
525521
} else {
526522
DRM_DEV_INFO(dev->dev, "no iommu, fallback to phys "
527523
"contig buffers for scanout\n");

drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,6 @@ struct msm_kms *mdp5_kms_init(struct drm_device *dev)
644644
}
645645

646646
kms->aspace = aspace;
647-
648-
ret = aspace->mmu->funcs->attach(aspace->mmu);
649-
if (ret) {
650-
DRM_DEV_ERROR(&pdev->dev, "failed to attach iommu: %d\n",
651-
ret);
652-
goto fail;
653-
}
654647
} else {
655648
DRM_DEV_INFO(&pdev->dev,
656649
"no iommu, fallback to phys contig buffers for scanout\n");

drivers/gpu/drm/msm/msm_gem_vma.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
133133
const char *name)
134134
{
135135
struct msm_gem_address_space *aspace;
136-
u64 size = domain->geometry.aperture_end -
137-
domain->geometry.aperture_start;
136+
u64 start = domain->geometry.aperture_start;
137+
u64 size = domain->geometry.aperture_end - start;
138138

139139
aspace = kzalloc(sizeof(*aspace), GFP_KERNEL);
140140
if (!aspace)
@@ -143,9 +143,18 @@ msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
143143
spin_lock_init(&aspace->lock);
144144
aspace->name = name;
145145
aspace->mmu = msm_iommu_new(dev, domain);
146+
if (IS_ERR(aspace->mmu)) {
147+
int ret = PTR_ERR(aspace->mmu);
146148

147-
drm_mm_init(&aspace->mm, (domain->geometry.aperture_start >> PAGE_SHIFT),
148-
size >> PAGE_SHIFT);
149+
kfree(aspace);
150+
return ERR_PTR(ret);
151+
}
152+
153+
/*
154+
* Attaching the IOMMU device changes the aperture values so use the
155+
* cached values instead
156+
*/
157+
drm_mm_init(&aspace->mm, start >> PAGE_SHIFT, size >> PAGE_SHIFT);
149158

150159
kref_init(&aspace->kref);
151160

@@ -166,6 +175,12 @@ msm_gem_address_space_create_a2xx(struct device *dev, struct msm_gpu *gpu,
166175
spin_lock_init(&aspace->lock);
167176
aspace->name = name;
168177
aspace->mmu = msm_gpummu_new(dev, gpu);
178+
if (IS_ERR(aspace->mmu)) {
179+
int ret = PTR_ERR(aspace->mmu);
180+
181+
kfree(aspace);
182+
return ERR_PTR(ret);
183+
}
169184

170185
drm_mm_init(&aspace->mm, (va_start >> PAGE_SHIFT),
171186
size >> PAGE_SHIFT);

drivers/gpu/drm/msm/msm_gpu.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,6 @@ msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev,
826826
uint64_t va_start, uint64_t va_end)
827827
{
828828
struct msm_gem_address_space *aspace;
829-
int ret;
830829

831830
/*
832831
* Setup IOMMU.. eventually we will (I think) do this once per context
@@ -851,17 +850,9 @@ msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev,
851850
va_start, va_end);
852851
}
853852

854-
if (IS_ERR(aspace)) {
853+
if (IS_ERR(aspace))
855854
DRM_DEV_ERROR(gpu->dev->dev, "failed to init mmu: %ld\n",
856855
PTR_ERR(aspace));
857-
return ERR_CAST(aspace);
858-
}
859-
860-
ret = aspace->mmu->funcs->attach(aspace->mmu);
861-
if (ret) {
862-
msm_gem_address_space_put(aspace);
863-
return ERR_PTR(ret);
864-
}
865856

866857
return aspace;
867858
}

drivers/gpu/drm/msm/msm_gpummu.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ struct msm_gpummu {
2121
#define GPUMMU_PAGE_SIZE SZ_4K
2222
#define TABLE_SIZE (sizeof(uint32_t) * GPUMMU_VA_RANGE / GPUMMU_PAGE_SIZE)
2323

24-
static int msm_gpummu_attach(struct msm_mmu *mmu)
25-
{
26-
return 0;
27-
}
28-
2924
static void msm_gpummu_detach(struct msm_mmu *mmu)
3025
{
3126
}
@@ -85,7 +80,6 @@ static void msm_gpummu_destroy(struct msm_mmu *mmu)
8580
}
8681

8782
static const struct msm_mmu_funcs funcs = {
88-
.attach = msm_gpummu_attach,
8983
.detach = msm_gpummu_detach,
9084
.map = msm_gpummu_map,
9185
.unmap = msm_gpummu_unmap,

drivers/gpu/drm/msm/msm_iommu.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ static int msm_fault_handler(struct iommu_domain *domain, struct device *dev,
2323
return 0;
2424
}
2525

26-
static int msm_iommu_attach(struct msm_mmu *mmu)
27-
{
28-
struct msm_iommu *iommu = to_msm_iommu(mmu);
29-
30-
return iommu_attach_device(iommu->domain, mmu->dev);
31-
}
32-
3326
static void msm_iommu_detach(struct msm_mmu *mmu)
3427
{
3528
struct msm_iommu *iommu = to_msm_iommu(mmu);
@@ -66,7 +59,6 @@ static void msm_iommu_destroy(struct msm_mmu *mmu)
6659
}
6760

6861
static const struct msm_mmu_funcs funcs = {
69-
.attach = msm_iommu_attach,
7062
.detach = msm_iommu_detach,
7163
.map = msm_iommu_map,
7264
.unmap = msm_iommu_unmap,
@@ -76,6 +68,7 @@ static const struct msm_mmu_funcs funcs = {
7668
struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain)
7769
{
7870
struct msm_iommu *iommu;
71+
int ret;
7972

8073
iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
8174
if (!iommu)
@@ -85,5 +78,11 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain)
8578
msm_mmu_init(&iommu->base, dev, &funcs);
8679
iommu_set_fault_handler(domain, msm_fault_handler, iommu);
8780

81+
ret = iommu_attach_device(iommu->domain, dev);
82+
if (ret) {
83+
kfree(iommu);
84+
return ERR_PTR(ret);
85+
}
86+
8887
return &iommu->base;
8988
}

drivers/gpu/drm/msm/msm_mmu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/iommu.h>
1111

1212
struct msm_mmu_funcs {
13-
int (*attach)(struct msm_mmu *mmu);
1413
void (*detach)(struct msm_mmu *mmu);
1514
int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
1615
unsigned len, int prot);

0 commit comments

Comments
 (0)