drm/etnaviv: allow to request specific virtual address for gem mapping
authorLucas Stach <l.stach@pengutronix.de>
Fri, 2 Aug 2019 12:19:38 +0000 (14:19 +0200)
committerLucas Stach <l.stach@pengutronix.de>
Thu, 15 Aug 2019 09:58:59 +0000 (11:58 +0200)
Allow the mapping code to request a specific virtual address for the gem
mapping. If the virtual address is zero we fall back to the old mode of
allocating a virtual address for the mapping.

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>
drivers/gpu/drm/etnaviv/etnaviv_gem.c
drivers/gpu/drm/etnaviv/etnaviv_gem.h
drivers/gpu/drm/etnaviv/etnaviv_mmu.c
drivers/gpu/drm/etnaviv/etnaviv_mmu.h

index b9354f2..8c62c5e 100644 (file)
@@ -308,7 +308,8 @@ struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
        mapping->use = 1;
 
        ret = etnaviv_iommu_map_gem(mmu_context, etnaviv_obj,
-                                   mmu_context->global->memory_base, mapping);
+                                   mmu_context->global->memory_base,
+                                   mapping, 0);
        if (ret < 0) {
                etnaviv_iommu_context_put(mmu_context);
                kfree(mapping);
index 1e11659..2d01ee1 100644 (file)
@@ -120,7 +120,8 @@ struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
 void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
 
 struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
-       struct drm_gem_object *obj, struct etnaviv_iommu_context *mmu_context);
+       struct drm_gem_object *obj, struct etnaviv_iommu_context *mmu_context,
+       u64 va);
 void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
 
 #endif /* __ETNAVIV_GEM_H__ */
index 82822e3..35ebae6 100644 (file)
@@ -220,9 +220,16 @@ static int etnaviv_iommu_find_iova(struct etnaviv_iommu_context *context,
        return ret;
 }
 
+static int etnaviv_iommu_insert_exact(struct etnaviv_iommu_context *context,
+                  struct drm_mm_node *node, size_t size, u64 va)
+{
+       return drm_mm_insert_node_in_range(&context->mm, node, size, 0, 0, va,
+                                          va + size, DRM_MM_INSERT_LOWEST);
+}
+
 int etnaviv_iommu_map_gem(struct etnaviv_iommu_context *context,
        struct etnaviv_gem_object *etnaviv_obj, u32 memory_base,
-       struct etnaviv_vram_mapping *mapping)
+       struct etnaviv_vram_mapping *mapping, u64 va)
 {
        struct sg_table *sgt = etnaviv_obj->sgt;
        struct drm_mm_node *node;
@@ -248,7 +255,12 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu_context *context,
 
        node = &mapping->vram_node;
 
-       ret = etnaviv_iommu_find_iova(context, node, etnaviv_obj->base.size);
+       if (va)
+               ret = etnaviv_iommu_insert_exact(context, node,
+                                                etnaviv_obj->base.size, va);
+       else
+               ret = etnaviv_iommu_find_iova(context, node,
+                                             etnaviv_obj->base.size);
        if (ret < 0)
                goto unlock;
 
index c01491a..d1d6902 100644 (file)
@@ -88,7 +88,7 @@ struct etnaviv_gem_object;
 
 int etnaviv_iommu_map_gem(struct etnaviv_iommu_context *context,
        struct etnaviv_gem_object *etnaviv_obj, u32 memory_base,
-       struct etnaviv_vram_mapping *mapping);
+       struct etnaviv_vram_mapping *mapping, u64 va);
 void etnaviv_iommu_unmap_gem(struct etnaviv_iommu_context *context,
        struct etnaviv_vram_mapping *mapping);