Skip to content

Commit ccac7ce

Browse files
Jordan Crouserobclark
authored andcommitted
drm/msm: Refactor address space initialization
Refactor how address space initialization works. Instead of having the address space function create the MMU object (and thus require separate but equal functions for gpummu and iommu) use a single function and pass the MMU struct in. Make the generic code cleaner by using target specific functions to create the address space so a2xx can do its own thing in its own space. For all the other targets use a generic helper to initialize IOMMU but leave the door open for newer targets to use customization if they need it. Reviewed-by: Rob Clark <[email protected]> Signed-off-by: Jordan Crouse <[email protected]> Tested-by: Shawn Guo <[email protected]> [squash in rebase fixups] Signed-off-by: Rob Clark <[email protected]>
1 parent 52da6d5 commit ccac7ce

File tree

17 files changed

+85
-118
lines changed

17 files changed

+85
-118
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,21 @@ static struct msm_gpu_state *a2xx_gpu_state_get(struct msm_gpu *gpu)
401401
return state;
402402
}
403403

404+
static struct msm_gem_address_space *
405+
a2xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)
406+
{
407+
struct msm_mmu *mmu = msm_gpummu_new(&pdev->dev, gpu);
408+
struct msm_gem_address_space *aspace;
409+
410+
aspace = msm_gem_address_space_create(mmu, "gpu", SZ_16M,
411+
SZ_16M + 0xfff * SZ_64K);
412+
413+
if (IS_ERR(aspace) && !IS_ERR(mmu))
414+
mmu->funcs->destroy(mmu);
415+
416+
return aspace;
417+
}
418+
404419
/* Register offset defines for A2XX - copy of A3XX */
405420
static const unsigned int a2xx_register_offsets[REG_ADRENO_REGISTER_MAX] = {
406421
REG_ADRENO_DEFINE(REG_ADRENO_CP_RB_BASE, REG_AXXX_CP_RB_BASE),
@@ -429,6 +444,7 @@ static const struct adreno_gpu_funcs funcs = {
429444
#endif
430445
.gpu_state_get = a2xx_gpu_state_get,
431446
.gpu_state_put = adreno_gpu_state_put,
447+
.create_address_space = a2xx_create_address_space,
432448
},
433449
};
434450

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static const struct adreno_gpu_funcs funcs = {
441441
#endif
442442
.gpu_state_get = a3xx_gpu_state_get,
443443
.gpu_state_put = adreno_gpu_state_put,
444+
.create_address_space = adreno_iommu_create_address_space,
444445
},
445446
};
446447

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ static const struct adreno_gpu_funcs funcs = {
583583
#endif
584584
.gpu_state_get = a4xx_gpu_state_get,
585585
.gpu_state_put = adreno_gpu_state_put,
586+
.create_address_space = adreno_iommu_create_address_space,
586587
},
587588
.get_timestamp = a4xx_get_timestamp,
588589
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ static const struct adreno_gpu_funcs funcs = {
14451445
.gpu_busy = a5xx_gpu_busy,
14461446
.gpu_state_get = a5xx_gpu_state_get,
14471447
.gpu_state_put = a5xx_gpu_state_put,
1448+
.create_address_space = adreno_iommu_create_address_space,
14481449
},
14491450
.get_timestamp = a5xx_get_timestamp,
14501451
};

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,15 +1114,14 @@ 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+
struct msm_mmu *mmu;
11171118

11181119
domain = iommu_domain_alloc(&platform_bus_type);
11191120
if (!domain)
11201121
return -ENODEV;
11211122

1122-
domain->geometry.aperture_start = 0x00000000;
1123-
domain->geometry.aperture_end = 0x7fffffff;
1124-
1125-
gmu->aspace = msm_gem_address_space_create(gmu->dev, domain, "gmu");
1123+
mmu = msm_iommu_new(gmu->dev, domain);
1124+
gmu->aspace = msm_gem_address_space_create(mmu, "gmu", 0x0, 0x7fffffff);
11261125
if (IS_ERR(gmu->aspace)) {
11271126
iommu_domain_free(domain);
11281127
return PTR_ERR(gmu->aspace);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ static const struct adreno_gpu_funcs funcs = {
893893
#if defined(CONFIG_DRM_MSM_GPU_STATE)
894894
.gpu_state_get = a6xx_gpu_state_get,
895895
.gpu_state_put = a6xx_gpu_state_put,
896+
.create_address_space = adreno_iommu_create_address_space,
896897
#endif
897898
},
898899
.get_timestamp = a6xx_get_timestamp,

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,23 @@ int adreno_zap_shader_load(struct msm_gpu *gpu, u32 pasid)
185185
return zap_shader_load_mdt(gpu, adreno_gpu->info->zapfw, pasid);
186186
}
187187

188+
struct msm_gem_address_space *
189+
adreno_iommu_create_address_space(struct msm_gpu *gpu,
190+
struct platform_device *pdev)
191+
{
192+
struct iommu_domain *iommu = iommu_domain_alloc(&platform_bus_type);
193+
struct msm_mmu *mmu = msm_iommu_new(&pdev->dev, iommu);
194+
struct msm_gem_address_space *aspace;
195+
196+
aspace = msm_gem_address_space_create(mmu, "gpu", SZ_16M,
197+
0xfffffff);
198+
199+
if (IS_ERR(aspace) && !IS_ERR(mmu))
200+
mmu->funcs->destroy(mmu);
201+
202+
return aspace;
203+
}
204+
188205
int adreno_get_param(struct msm_gpu *gpu, uint32_t param, uint64_t *value)
189206
{
190207
struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu);
@@ -988,12 +1005,6 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,
9881005

9891006
adreno_gpu_config.ioname = "kgsl_3d0_reg_memory";
9901007

991-
adreno_gpu_config.va_start = SZ_16M;
992-
adreno_gpu_config.va_end = 0xffffffff;
993-
/* maximum range of a2xx mmu */
994-
if (adreno_is_a2xx(adreno_gpu))
995-
adreno_gpu_config.va_end = SZ_16M + 0xfff * SZ_64K;
996-
9971008
adreno_gpu_config.nr_rings = nr_rings;
9981009

9991010
adreno_get_pwrlevels(&pdev->dev, gpu);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ void adreno_gpu_state_destroy(struct msm_gpu_state *state);
287287
int adreno_gpu_state_get(struct msm_gpu *gpu, struct msm_gpu_state *state);
288288
int adreno_gpu_state_put(struct msm_gpu_state *state);
289289

290+
/*
291+
* Common helper function to initialize the default address space for arm-smmu
292+
* attached targets
293+
*/
294+
struct msm_gem_address_space *
295+
adreno_iommu_create_address_space(struct msm_gpu *gpu,
296+
struct platform_device *pdev);
297+
290298
/*
291299
* For a5xx and a6xx targets load the zap shader that is used to pull the GPU
292300
* out of secure mode

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -794,18 +794,18 @@ 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+
struct msm_mmu *mmu;
797798

798799
domain = iommu_domain_alloc(&platform_bus_type);
799800
if (!domain)
800801
return 0;
801802

802-
domain->geometry.aperture_start = 0x1000;
803-
domain->geometry.aperture_end = 0xffffffff;
803+
mmu = msm_iommu_new(dpu_kms->dev->dev, domain);
804+
aspace = msm_gem_address_space_create(mmu, "dpu1",
805+
0x1000, 0xfffffff);
804806

805-
aspace = msm_gem_address_space_create(dpu_kms->dev->dev,
806-
domain, "dpu1");
807807
if (IS_ERR(aspace)) {
808-
iommu_domain_free(domain);
808+
mmu->funcs->destroy(mmu);
809809
return PTR_ERR(aspace);
810810
}
811811

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,15 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev)
510510
mdelay(16);
511511

512512
if (config->iommu) {
513-
aspace = msm_gem_address_space_create(&pdev->dev,
514-
config->iommu, "mdp4");
513+
struct msm_mmu *mmu = msm_iommu_new(&pdev->dev,
514+
config->iommu);
515+
516+
aspace = msm_gem_address_space_create(mmu,
517+
"mdp4", 0x1000, 0xffffffff);
518+
515519
if (IS_ERR(aspace)) {
520+
if (!IS_ERR(mmu))
521+
mmu->funcs->destroy(mmu);
516522
ret = PTR_ERR(aspace);
517523
goto fail;
518524
}
@@ -565,10 +571,6 @@ static struct mdp4_platform_config *mdp4_get_config(struct platform_device *dev)
565571
/* TODO: Chips that aren't apq8064 have a 200 Mhz max_clk */
566572
config.max_clk = 266667000;
567573
config.iommu = iommu_domain_alloc(&platform_bus_type);
568-
if (config.iommu) {
569-
config.iommu->geometry.aperture_start = 0x1000;
570-
config.iommu->geometry.aperture_end = 0xffffffff;
571-
}
572574

573575
return &config;
574576
}

0 commit comments

Comments
 (0)