drm/etnaviv: move MMU context ref/unref into map/unmap_gem
authorLucas Stach <l.stach@pengutronix.de>
Wed, 23 Mar 2022 16:08:23 +0000 (17:08 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Wed, 13 Mar 2024 06:58:54 +0000 (15:58 +0900)
This makes it a little more clear that the mapping holds a reference
to the context once the buffer has been successfully mapped into that
context and simplifies the error handling a bit.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Tested-by: Guido Günther <agx@sigxcpu.org>
Acked-by: Guido Günther <agx@sigxcpu.org>
(cherry picked from commit 0f89c7db165cbf0ead3fbf2ea652b1c5ed7e098b)
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/gpu/drm/etnaviv/etnaviv_gem.c
drivers/gpu/drm/etnaviv/etnaviv_mmu.c

index 429094cb77a5006f26320989fc04b39889520665..6e2bbb19650a38b54ed755f3fdd68827573ff0ec 100644 (file)
@@ -305,18 +305,15 @@ struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
                list_del(&mapping->obj_node);
        }
 
-       mapping->context = etnaviv_iommu_context_get(mmu_context);
        mapping->use = 1;
 
        ret = etnaviv_iommu_map_gem(mmu_context, etnaviv_obj,
                                    mmu_context->global->memory_base,
                                    mapping, va);
-       if (ret < 0) {
-               etnaviv_iommu_context_put(mmu_context);
+       if (ret < 0)
                kfree(mapping);
-       } else {
+       else
                list_add_tail(&mapping->obj_node, &etnaviv_obj->vram_list);
-       }
 
 out:
        mutex_unlock(&etnaviv_obj->lock);
@@ -532,10 +529,8 @@ void etnaviv_gem_free_object(struct drm_gem_object *obj)
 
                WARN_ON(mapping->use);
 
-               if (context) {
+               if (context)
                        etnaviv_iommu_unmap_gem(context, mapping);
-                       etnaviv_iommu_context_put(context);
-               }
 
                list_del(&mapping->obj_node);
                kfree(mapping);
index 2de806173b3aaa4c96ac05e9a6bb2c19ffd49c77..eeda6d0cd6cc6c7e663ee2ea998473bea0a6c6fc 100644 (file)
@@ -245,6 +245,7 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu_context *context,
                iova = sg_dma_address(sgt->sgl) - memory_base;
                if (iova < 0x80000000 - sg_dma_len(sgt->sgl)) {
                        mapping->iova = iova;
+                       mapping->context = etnaviv_iommu_context_get(context);
                        list_add_tail(&mapping->mmu_node, &context->mappings);
                        ret = 0;
                        goto unlock;
@@ -271,6 +272,7 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu_context *context,
                goto unlock;
        }
 
+       mapping->context = etnaviv_iommu_context_get(context);
        list_add_tail(&mapping->mmu_node, &context->mappings);
        context->flush_seq++;
 unlock:
@@ -299,6 +301,7 @@ void etnaviv_iommu_unmap_gem(struct etnaviv_iommu_context *context,
        list_del(&mapping->mmu_node);
        context->flush_seq++;
        mutex_unlock(&context->lock);
+       etnaviv_iommu_context_put(context);
 }
 
 static void etnaviv_iommu_context_free(struct kref *kref)