Skip to content

Commit e6364d7

Browse files
committed
drm/etnaviv: provide MMU context to etnaviv_gem_mapping_get
In preparation to having a context per process, etnaviv_gem_mapping_get should not use the current GPU context, but needs to be told which context to use. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Reviewed-by: Guido Günther <agx@sigxcpu.org>
1 parent d80d842 commit e6364d7

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎drivers/gpu/drm/etnaviv/etnaviv_gem.c‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,16 @@ void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping)
248248
}
249249

250250
struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
251-
struct drm_gem_object *obj, struct etnaviv_gpu *gpu)
251+
struct drm_gem_object *obj, struct etnaviv_gpu *gpu,
252+
struct etnaviv_iommu_context *mmu_context)
252253
{
253254
struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
254255
struct etnaviv_vram_mapping *mapping;
255256
struct page **pages;
256257
int ret = 0;
257258

258259
mutex_lock(&etnaviv_obj->lock);
259-
mapping = etnaviv_gem_get_vram_mapping(etnaviv_obj, gpu->mmu_context);
260+
mapping = etnaviv_gem_get_vram_mapping(etnaviv_obj, mmu_context);
260261
if (mapping) {
261262
/*
262263
* Holding the object lock prevents the use count changing
@@ -265,12 +266,12 @@ struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
265266
* the MMU owns this mapping to close this race.
266267
*/
267268
if (mapping->use == 0) {
268-
mutex_lock(&gpu->mmu_context->lock);
269-
if (mapping->context == gpu->mmu_context)
269+
mutex_lock(&mmu_context->lock);
270+
if (mapping->context == mmu_context)
270271
mapping->use += 1;
271272
else
272273
mapping = NULL;
273-
mutex_unlock(&gpu->mmu_context->lock);
274+
mutex_unlock(&mmu_context->lock);
274275
if (mapping)
275276
goto out;
276277
} else {
@@ -303,15 +304,18 @@ struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
303304
list_del(&mapping->obj_node);
304305
}
305306

306-
mapping->context = gpu->mmu_context;
307+
etnaviv_iommu_context_get(mmu_context);
308+
mapping->context = mmu_context;
307309
mapping->use = 1;
308310

309-
ret = etnaviv_iommu_map_gem(gpu->mmu_context, etnaviv_obj,
310-
gpu->memory_base, mapping);
311-
if (ret < 0)
311+
ret = etnaviv_iommu_map_gem(mmu_context, etnaviv_obj, gpu->memory_base,
312+
mapping);
313+
if (ret < 0) {
314+
etnaviv_iommu_context_put(mmu_context);
312315
kfree(mapping);
313-
else
316+
} else {
314317
list_add_tail(&mapping->obj_node, &etnaviv_obj->vram_list);
318+
}
315319

316320
out:
317321
mutex_unlock(&etnaviv_obj->lock);
@@ -529,8 +533,10 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj)
529533

530534
WARN_ON(mapping->use);
531535

532-
if (context)
536+
if (context) {
533537
etnaviv_iommu_unmap_gem(context, mapping);
538+
etnaviv_iommu_context_put(context);
539+
}
534540

535541
list_del(&mapping->obj_node);
536542
kfree(mapping);

‎drivers/gpu/drm/etnaviv/etnaviv_gem.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
119119
void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
120120

121121
struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
122-
struct drm_gem_object *obj, struct etnaviv_gpu *gpu);
122+
struct drm_gem_object *obj, struct etnaviv_gpu *gpu,
123+
struct etnaviv_iommu_context *mmu_context);
123124
void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
124125

125126
#endif /* __ETNAVIV_GEM_H__ */

‎drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ static int submit_pin_objects(struct etnaviv_gem_submit *submit)
224224
struct etnaviv_vram_mapping *mapping;
225225

226226
mapping = etnaviv_gem_mapping_get(&etnaviv_obj->base,
227-
submit->gpu);
227+
submit->gpu,
228+
submit->gpu->mmu_context);
228229
if (IS_ERR(mapping)) {
229230
ret = PTR_ERR(mapping);
230231
break;

0 commit comments

Comments
 (0)