Skip to content

Commit 3236130

Browse files
committed
drm/msm: move domain allocation into msm_iommu_new()
After the msm_iommu instance is created, the IOMMU domain is completely handled inside the msm_iommu code. Move the iommu_domain_alloc() call into the msm_iommu_new() to simplify callers code. Reported-by: kernel test robot <[email protected]> Signed-off-by: Dmitry Baryshkov <[email protected]> Reviewed-by: Rob Clark <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/509615/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Baryshkov <[email protected]>
1 parent 90d2c87 commit 3236130

File tree

8 files changed

+62
-60
lines changed

8 files changed

+62
-60
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,19 +1213,17 @@ static int a6xx_gmu_memory_alloc(struct a6xx_gmu *gmu, struct a6xx_gmu_bo *bo,
12131213

12141214
static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
12151215
{
1216-
struct iommu_domain *domain;
12171216
struct msm_mmu *mmu;
12181217

1219-
domain = iommu_domain_alloc(&platform_bus_type);
1220-
if (!domain)
1218+
mmu = msm_iommu_new(gmu->dev, 0);
1219+
if (!mmu)
12211220
return -ENODEV;
1221+
if (IS_ERR(mmu))
1222+
return PTR_ERR(mmu);
12221223

1223-
mmu = msm_iommu_new(gmu->dev, domain);
12241224
gmu->aspace = msm_gem_address_space_create(mmu, "gmu", 0x0, 0x80000000);
1225-
if (IS_ERR(gmu->aspace)) {
1226-
iommu_domain_free(domain);
1225+
if (IS_ERR(gmu->aspace))
12271226
return PTR_ERR(gmu->aspace);
1228-
}
12291227

12301228
return 0;
12311229
}

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,35 +1786,34 @@ a6xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
17861786
{
17871787
struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
17881788
struct a6xx_gpu *a6xx_gpu = to_a6xx_gpu(adreno_gpu);
1789-
struct iommu_domain *iommu;
1789+
struct iommu_domain_geometry *geometry;
17901790
struct msm_mmu *mmu;
17911791
struct msm_gem_address_space *aspace;
17921792
u64 start, size;
1793-
1794-
iommu = iommu_domain_alloc(&platform_bus_type);
1795-
if (!iommu)
1796-
return NULL;
1793+
unsigned long quirks = 0;
17971794

17981795
/*
17991796
* This allows GPU to set the bus attributes required to use system
18001797
* cache on behalf of the iommu page table walker.
18011798
*/
18021799
if (!IS_ERR_OR_NULL(a6xx_gpu->htw_llc_slice))
1803-
adreno_set_llc_attributes(iommu);
1800+
quirks |= IO_PGTABLE_QUIRK_ARM_OUTER_WBWA;
18041801

1805-
mmu = msm_iommu_new(&pdev->dev, iommu);
1806-
if (IS_ERR(mmu)) {
1807-
iommu_domain_free(iommu);
1802+
mmu = msm_iommu_new(&pdev->dev, quirks);
1803+
if (IS_ERR_OR_NULL(mmu))
18081804
return ERR_CAST(mmu);
1809-
}
1805+
1806+
geometry = msm_iommu_get_geometry(mmu);
1807+
if (IS_ERR(geometry))
1808+
return ERR_CAST(geometry);
18101809

18111810
/*
18121811
* Use the aperture start or SZ_16M, whichever is greater. This will
18131812
* ensure that we align with the allocated pagetable range while still
18141813
* allowing room in the lower 32 bits for GMEM and whatnot
18151814
*/
1816-
start = max_t(u64, SZ_16M, iommu->geometry.aperture_start);
1817-
size = iommu->geometry.aperture_end - start + 1;
1815+
start = max_t(u64, SZ_16M, geometry->aperture_start);
1816+
size = geometry->aperture_end - start + 1;
18181817

18191818
aspace = msm_gem_address_space_create(mmu, "gpu",
18201819
start & GENMASK_ULL(48, 0), size);

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,37 +191,30 @@ int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid)
191191
return zap_shader_load_mdt(gpu, adreno_gpu->info->zapfw, pasid);
192192
}
193193

194-
void adreno_set_llc_attributes(struct iommu_domain *iommu)
195-
{
196-
iommu_set_pgtable_quirks(iommu, IO_PGTABLE_QUIRK_ARM_OUTER_WBWA);
197-
}
198-
199194
struct msm_gem_address_space *
200195
adreno_iommu_create_address_space(struct msm_gpu *gpu,
201196
struct platform_device *pdev)
202197
{
203-
struct iommu_domain *iommu;
198+
struct iommu_domain_geometry *geometry;
204199
struct msm_mmu *mmu;
205200
struct msm_gem_address_space *aspace;
206201
u64 start, size;
207202

208-
iommu = iommu_domain_alloc(&platform_bus_type);
209-
if (!iommu)
210-
return NULL;
211-
212-
mmu = msm_iommu_new(&pdev->dev, iommu);
213-
if (IS_ERR(mmu)) {
214-
iommu_domain_free(iommu);
203+
mmu = msm_iommu_new(&pdev->dev, 0);
204+
if (IS_ERR_OR_NULL(mmu))
215205
return ERR_CAST(mmu);
216-
}
206+
207+
geometry = msm_iommu_get_geometry(mmu);
208+
if (IS_ERR(geometry))
209+
return ERR_CAST(geometry);
217210

218211
/*
219212
* Use the aperture start or SZ_16M, whichever is greater. This will
220213
* ensure that we align with the allocated pagetable range while still
221214
* allowing room in the lower 32 bits for GMEM and whatnot
222215
*/
223-
start = max_t(u64, SZ_16M, iommu->geometry.aperture_start);
224-
size = iommu->geometry.aperture_end - start + 1;
216+
start = max_t(u64, SZ_16M, geometry->aperture_start);
217+
size = geometry->aperture_end - start + 1;
225218

226219
aspace = msm_gem_address_space_create(mmu, "gpu",
227220
start & GENMASK_ULL(48, 0), size);

drivers/gpu/drm/msm/adreno/adreno_gpu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ struct msm_gem_address_space *
338338
adreno_iommu_create_address_space(struct msm_gpu *gpu,
339339
struct platform_device *pdev);
340340

341-
void adreno_set_llc_attributes(struct iommu_domain *iommu);
342-
343341
int adreno_read_speedbin(struct device *dev, u32 *speedbin);
344342

345343
/*

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static int mdp4_kms_init(struct drm_device *dev)
387387
struct msm_drm_private *priv = dev->dev_private;
388388
struct mdp4_kms *mdp4_kms;
389389
struct msm_kms *kms = NULL;
390-
struct iommu_domain *iommu;
390+
struct msm_mmu *mmu;
391391
struct msm_gem_address_space *aspace;
392392
int irq, ret;
393393
u32 major, minor;
@@ -499,10 +499,15 @@ static int mdp4_kms_init(struct drm_device *dev)
499499
mdp4_disable(mdp4_kms);
500500
mdelay(16);
501501

502-
iommu = iommu_domain_alloc(pdev->dev.bus);
503-
if (iommu) {
504-
struct msm_mmu *mmu = msm_iommu_new(&pdev->dev, iommu);
505-
502+
mmu = msm_iommu_new(&pdev->dev, 0);
503+
if (IS_ERR(mmu)) {
504+
ret = PTR_ERR(mmu);
505+
goto fail;
506+
} else if (!mmu) {
507+
DRM_DEV_INFO(dev->dev, "no iommu, fallback to phys "
508+
"contig buffers for scanout\n");
509+
aspace = NULL;
510+
} else {
506511
aspace = msm_gem_address_space_create(mmu,
507512
"mdp4", 0x1000, 0x100000000 - 0x1000);
508513

@@ -514,10 +519,6 @@ static int mdp4_kms_init(struct drm_device *dev)
514519
}
515520

516521
kms->aspace = aspace;
517-
} else {
518-
DRM_DEV_INFO(dev->dev, "no iommu, fallback to phys "
519-
"contig buffers for scanout\n");
520-
aspace = NULL;
521522
}
522523

523524
ret = modeset_init(mdp4_kms);

drivers/gpu/drm/msm/msm_drv.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ static int msm_drm_uninit(struct device *dev)
277277

278278
struct msm_gem_address_space *msm_kms_init_aspace(struct drm_device *dev)
279279
{
280-
struct iommu_domain *domain;
281280
struct msm_gem_address_space *aspace;
282281
struct msm_mmu *mmu;
283282
struct device *mdp_dev = dev->dev;
@@ -293,22 +292,21 @@ struct msm_gem_address_space *msm_kms_init_aspace(struct drm_device *dev)
293292
else
294293
iommu_dev = mdss_dev;
295294

296-
domain = iommu_domain_alloc(iommu_dev->bus);
297-
if (!domain) {
295+
mmu = msm_iommu_new(iommu_dev, 0);
296+
if (IS_ERR(mmu))
297+
return ERR_CAST(mmu);
298+
299+
if (!mmu) {
298300
drm_info(dev, "no IOMMU, fallback to phys contig buffers for scanout\n");
299301
return NULL;
300302
}
301303

302-
mmu = msm_iommu_new(iommu_dev, domain);
303-
if (IS_ERR(mmu)) {
304-
iommu_domain_free(domain);
305-
return ERR_CAST(mmu);
306-
}
307-
308304
aspace = msm_gem_address_space_create(mmu, "mdp_kms",
309305
0x1000, 0x100000000 - 0x1000);
310-
if (IS_ERR(aspace))
306+
if (IS_ERR(aspace)) {
307+
dev_err(mdp_dev, "aspace create, error %pe\n", aspace);
311308
mmu->funcs->destroy(mmu);
309+
}
312310

313311
return aspace;
314312
}

drivers/gpu/drm/msm/msm_iommu.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ int msm_iommu_pagetable_params(struct msm_mmu *mmu,
186186
return 0;
187187
}
188188

189+
struct iommu_domain_geometry *msm_iommu_get_geometry(struct msm_mmu *mmu)
190+
{
191+
struct msm_iommu *iommu = to_msm_iommu(mmu);
192+
193+
return &iommu->domain->geometry;
194+
}
195+
189196
static const struct msm_mmu_funcs pagetable_funcs = {
190197
.map = msm_iommu_pagetable_map,
191198
.unmap = msm_iommu_pagetable_unmap,
@@ -367,17 +374,23 @@ static const struct msm_mmu_funcs funcs = {
367374
.resume_translation = msm_iommu_resume_translation,
368375
};
369376

370-
struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain)
377+
struct msm_mmu *msm_iommu_new(struct device *dev, unsigned long quirks)
371378
{
379+
struct iommu_domain *domain;
372380
struct msm_iommu *iommu;
373381
int ret;
374382

383+
domain = iommu_domain_alloc(dev->bus);
375384
if (!domain)
376-
return ERR_PTR(-ENODEV);
385+
return NULL;
386+
387+
iommu_set_pgtable_quirks(domain, quirks);
377388

378389
iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
379-
if (!iommu)
390+
if (!iommu) {
391+
iommu_domain_free(domain);
380392
return ERR_PTR(-ENOMEM);
393+
}
381394

382395
iommu->domain = domain;
383396
msm_mmu_init(&iommu->base, dev, &funcs, MSM_MMU_IOMMU);
@@ -386,6 +399,7 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain)
386399

387400
ret = iommu_attach_device(iommu->domain, dev);
388401
if (ret) {
402+
iommu_domain_free(domain);
389403
kfree(iommu);
390404
return ERR_PTR(ret);
391405
}

drivers/gpu/drm/msm/msm_mmu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static inline void msm_mmu_init(struct msm_mmu *mmu, struct device *dev,
4040
mmu->type = type;
4141
}
4242

43-
struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain);
43+
struct msm_mmu *msm_iommu_new(struct device *dev, unsigned long quirks);
4444
struct msm_mmu *msm_gpummu_new(struct device *dev, struct msm_gpu *gpu);
4545

4646
static inline void msm_mmu_set_fault_handler(struct msm_mmu *mmu, void *arg,
@@ -58,5 +58,6 @@ void msm_gpummu_params(struct msm_mmu *mmu, dma_addr_t *pt_base,
5858

5959
int msm_iommu_pagetable_params(struct msm_mmu *mmu, phys_addr_t *ttbr,
6060
int *asid);
61+
struct iommu_domain_geometry *msm_iommu_get_geometry(struct msm_mmu *mmu);
6162

6263
#endif /* __MSM_MMU_H__ */

0 commit comments

Comments
 (0)