Skip to content

Commit d640853

Browse files
committed
drm/etnaviv: reference MMU context when setting up hardware state
Move the refcount manipulation of the MMU context to the point where the hardware state is programmed. At that point it is also known if a previous MMU state is still there, or the state needs to be reprogrammed with a potentially different context. Cc: [email protected] # 5.4 Signed-off-by: Lucas Stach <[email protected]> Tested-by: Michael Walle <[email protected]> Tested-by: Marek Vasut <[email protected]> Reviewed-by: Christian Gmeiner <[email protected]>
1 parent f978a53 commit d640853

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

drivers/gpu/drm/etnaviv/etnaviv_gpu.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,19 @@ void etnaviv_gpu_start_fe(struct etnaviv_gpu *gpu, u32 address, u16 prefetch)
647647
gpu->fe_running = true;
648648
}
649649

650-
static void etnaviv_gpu_start_fe_idleloop(struct etnaviv_gpu *gpu)
650+
static void etnaviv_gpu_start_fe_idleloop(struct etnaviv_gpu *gpu,
651+
struct etnaviv_iommu_context *context)
651652
{
652-
u32 address = etnaviv_cmdbuf_get_va(&gpu->buffer,
653-
&gpu->mmu_context->cmdbuf_mapping);
654653
u16 prefetch;
654+
u32 address;
655655

656656
/* setup the MMU */
657-
etnaviv_iommu_restore(gpu, gpu->mmu_context);
657+
etnaviv_iommu_restore(gpu, context);
658658

659659
/* Start command processor */
660660
prefetch = etnaviv_buffer_init(gpu);
661+
address = etnaviv_cmdbuf_get_va(&gpu->buffer,
662+
&gpu->mmu_context->cmdbuf_mapping);
661663

662664
etnaviv_gpu_start_fe(gpu, address, prefetch);
663665
}
@@ -1375,14 +1377,12 @@ struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit)
13751377
goto out_unlock;
13761378
}
13771379

1378-
if (!gpu->fe_running) {
1379-
gpu->mmu_context = etnaviv_iommu_context_get(submit->mmu_context);
1380-
etnaviv_gpu_start_fe_idleloop(gpu);
1381-
} else {
1382-
if (submit->prev_mmu_context)
1383-
etnaviv_iommu_context_put(submit->prev_mmu_context);
1384-
submit->prev_mmu_context = etnaviv_iommu_context_get(gpu->mmu_context);
1385-
}
1380+
if (!gpu->fe_running)
1381+
etnaviv_gpu_start_fe_idleloop(gpu, submit->mmu_context);
1382+
1383+
if (submit->prev_mmu_context)
1384+
etnaviv_iommu_context_put(submit->prev_mmu_context);
1385+
submit->prev_mmu_context = etnaviv_iommu_context_get(gpu->mmu_context);
13861386

13871387
if (submit->nr_pmrs) {
13881388
gpu->event[event[1]].sync_point = &sync_point_perfmon_sample_pre;

drivers/gpu/drm/etnaviv/etnaviv_iommu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ static void etnaviv_iommuv1_restore(struct etnaviv_gpu *gpu,
9292
struct etnaviv_iommuv1_context *v1_context = to_v1_context(context);
9393
u32 pgtable;
9494

95+
if (gpu->mmu_context)
96+
etnaviv_iommu_context_put(gpu->mmu_context);
97+
gpu->mmu_context = etnaviv_iommu_context_get(context);
98+
9599
/* set base addresses */
96100
gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_RA, context->global->memory_base);
97101
gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_FE, context->global->memory_base);

drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ static void etnaviv_iommuv2_restore_nonsec(struct etnaviv_gpu *gpu,
172172
if (gpu_read(gpu, VIVS_MMUv2_CONTROL) & VIVS_MMUv2_CONTROL_ENABLE)
173173
return;
174174

175+
if (gpu->mmu_context)
176+
etnaviv_iommu_context_put(gpu->mmu_context);
177+
gpu->mmu_context = etnaviv_iommu_context_get(context);
178+
175179
prefetch = etnaviv_buffer_config_mmuv2(gpu,
176180
(u32)v2_context->mtlb_dma,
177181
(u32)context->global->bad_page_dma);
@@ -192,6 +196,10 @@ static void etnaviv_iommuv2_restore_sec(struct etnaviv_gpu *gpu,
192196
if (gpu_read(gpu, VIVS_MMUv2_SEC_CONTROL) & VIVS_MMUv2_SEC_CONTROL_ENABLE)
193197
return;
194198

199+
if (gpu->mmu_context)
200+
etnaviv_iommu_context_put(gpu->mmu_context);
201+
gpu->mmu_context = etnaviv_iommu_context_get(context);
202+
195203
gpu_write(gpu, VIVS_MMUv2_PTA_ADDRESS_LOW,
196204
lower_32_bits(context->global->v2.pta_dma));
197205
gpu_write(gpu, VIVS_MMUv2_PTA_ADDRESS_HIGH,

0 commit comments

Comments
 (0)