Use the newer ttm_bo_vmap() instead of ttm_bo_kmap(). The new interface
uses struct iomap_map, which helps with pointer setup and memcpy() ops.
Removes a TODO item and quite a bit of workarounds from the code.

Signed-off-by: Thomas Zimmermann <tzimmerm...@suse.de>
---
 .../compat-i915-headers/gem/i915_gem_object.h | 17 +++-------
 drivers/gpu/drm/xe/xe_bo.c                    | 32 ++++---------------
 drivers/gpu/drm/xe/xe_bo_types.h              |  2 --
 3 files changed, 10 insertions(+), 41 deletions(-)

diff --git a/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h 
b/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h
index 777c20ceabab1..25ae56d700431 100644
--- a/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h
@@ -34,28 +34,19 @@ static inline bool i915_gem_object_is_userptr(const struct 
xe_bo *bo)
 static inline int i915_gem_object_read_from_page(struct xe_bo *bo,
                                          u32 ofs, u64 *ptr, u32 size)
 {
-       struct ttm_bo_kmap_obj map;
-       void *src;
-       bool is_iomem;
+       struct iosys_map src;
        int ret;
 
        ret = xe_bo_lock(bo, true);
        if (ret)
                return ret;
 
-       ret = ttm_bo_kmap(&bo->ttm, ofs >> PAGE_SHIFT, 1, &map);
+       ret = ttm_bo_vmap(&bo->ttm, ofs, size, &src);
        if (ret)
                goto out_unlock;
+       iosys_map_memcpy_from(ptr, &src, ofs & ~PAGE_MASK, size);
+       ttm_bo_vunmap(&bo->ttm, &src);
 
-       ofs &= ~PAGE_MASK;
-       src = ttm_kmap_obj_virtual(&map, &is_iomem);
-       src += ofs;
-       if (is_iomem)
-               memcpy_fromio(ptr, (void __iomem *)src, size);
-       else
-               memcpy(ptr, src, size);
-
-       ttm_bo_kunmap(&map);
 out_unlock:
        xe_bo_unlock(bo);
        return ret;
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index a98d857ff1e5a..6158e1a959cd4 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -1888,10 +1888,6 @@ dma_addr_t xe_bo_addr(struct xe_bo *bo, u64 offset, 
size_t page_size)
 
 int xe_bo_vmap(struct xe_bo *bo)
 {
-       void *virtual;
-       bool is_iomem;
-       int ret;
-
        xe_bo_assert_held(bo);
 
        if (!(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS))
@@ -1900,32 +1896,16 @@ int xe_bo_vmap(struct xe_bo *bo)
        if (!iosys_map_is_null(&bo->vmap))
                return 0;
 
-       /*
-        * We use this more or less deprecated interface for now since
-        * ttm_bo_vmap() doesn't offer the optimization of kmapping
-        * single page bos, which is done here.
-        * TODO: Fix up ttm_bo_vmap to do that, or fix up ttm_bo_kmap
-        * to use struct iosys_map.
-        */
-       ret = ttm_bo_kmap(&bo->ttm, 0, bo->size >> PAGE_SHIFT, &bo->kmap);
-       if (ret)
-               return ret;
-
-       virtual = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
-       if (is_iomem)
-               iosys_map_set_vaddr_iomem(&bo->vmap, (void __iomem *)virtual);
-       else
-               iosys_map_set_vaddr(&bo->vmap, virtual);
-
-       return 0;
+       return ttm_bo_vmap(&bo->ttm, 0, bo->size, &bo->vmap);
 }
 
 static void __xe_bo_vunmap(struct xe_bo *bo)
 {
-       if (!iosys_map_is_null(&bo->vmap)) {
-               iosys_map_clear(&bo->vmap);
-               ttm_bo_kunmap(&bo->kmap);
-       }
+       if (iosys_map_is_null(&bo->vmap))
+               return;
+
+       ttm_bo_vunmap(&bo->ttm, &bo->vmap);
+       iosys_map_clear(&bo->vmap);
 }
 
 void xe_bo_vunmap(struct xe_bo *bo)
diff --git a/drivers/gpu/drm/xe/xe_bo_types.h b/drivers/gpu/drm/xe/xe_bo_types.h
index 86422e113d396..5cba681ba73c2 100644
--- a/drivers/gpu/drm/xe/xe_bo_types.h
+++ b/drivers/gpu/drm/xe/xe_bo_types.h
@@ -42,8 +42,6 @@ struct xe_bo {
        struct drm_mm_node ggtt_node;
        /** @vmap: iosys map of this buffer */
        struct iosys_map vmap;
-       /** @ttm_kmap: TTM bo kmap object for internal use only. Keep off. */
-       struct ttm_bo_kmap_obj kmap;
        /** @pinned_link: link to present / evicted list of pinned BO */
        struct list_head pinned_link;
 #ifdef CONFIG_PROC_FS
-- 
2.45.2

Reply via email to