From: Thomas Zimmermann <tzimmermann@suse.de>
To: alexander.deucher@amd.com, christian.koenig@amd.com,
Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch,
felix.kuehling@amd.com
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
Thomas Zimmermann <tzimmermann@suse.de>
Subject: [PATCH 2/2] drm/amdgpu: Convert to ttm_bo_vmap() et al
Date: Thu, 20 Jun 2024 16:44:41 +0200 [thread overview]
Message-ID: <20240620145238.25295-3-tzimmermann@suse.de> (raw)
In-Reply-To: <20240620145238.25295-1-tzimmermann@suse.de>
Replace each call to ttm_bo_kmap() with a call to ttm_bo_vmap().
Same for ttm_bo_kunmap() and ttm_bo_vunmap(). There's now one less
driver depending on the deprecated ttm_bo_kmap().
Also allows for dropping struct ttm_bo_kmap_obj in favor of struct
iosys_map, which is the preferred representation of BO memory mappings.
Manual type conversion in amdgpu_bo_kptr() is required to make the
returned pointer usable within amdgpu. In a follow-up patch, amdgpu
should be convert to use struct iosys_map directly.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 16 ++++++++++------
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 +++-
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d58b11ea0ead5..baa60e25c13e1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -62,7 +62,7 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
* BO memory pages should be unmapped at this point. Call
* amdgpu_bo_kunmap() before releasing the BO.
*/
- if (drm_WARN_ON_ONCE(bo->tbo.base.dev, bo->kmap.bo))
+ if (drm_WARN_ON_ONCE(bo->tbo.base.dev, !iosys_map_is_null(&bo->map)))
amdgpu_bo_kunmap(bo);
if (bo->tbo.base.import_attach)
@@ -802,7 +802,7 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
return 0;
}
- r = ttm_bo_kmap(&bo->tbo, 0, PFN_UP(bo->tbo.base.size), &bo->kmap);
+ r = ttm_bo_vmap(&bo->tbo, &bo->map);
if (r)
return r;
@@ -823,9 +823,12 @@ int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr)
*/
void *amdgpu_bo_kptr(struct amdgpu_bo *bo)
{
- bool is_iomem;
+ if (iosys_map_is_null(&bo->map))
+ return NULL;
+ if (bo->map.is_iomem)
+ return (void __force *)bo->map.vaddr_iomem;
- return ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
+ return bo->map.vaddr;
}
/**
@@ -836,8 +839,9 @@ void *amdgpu_bo_kptr(struct amdgpu_bo *bo)
*/
void amdgpu_bo_kunmap(struct amdgpu_bo *bo)
{
- if (bo->kmap.bo)
- ttm_bo_kunmap(&bo->kmap);
+ if (iosys_map_is_null(&bo->map))
+ return;
+ ttm_bo_vunmap(&bo->tbo, &bo->map);
}
/**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index bc42ccbde659a..553a92303339f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -28,6 +28,8 @@
#ifndef __AMDGPU_OBJECT_H__
#define __AMDGPU_OBJECT_H__
+#include <linux/iosys-map.h>
+
#include <drm/amdgpu_drm.h>
#include "amdgpu.h"
#include "amdgpu_res_cursor.h"
@@ -99,7 +101,7 @@ struct amdgpu_bo {
struct ttm_place placements[AMDGPU_BO_MAX_PLACEMENTS];
struct ttm_placement placement;
struct ttm_buffer_object tbo;
- struct ttm_bo_kmap_obj kmap;
+ struct iosys_map map;
u64 flags;
/* per VM structure for page tables and with virtual addresses */
struct amdgpu_vm_bo_base *vm_bo;
--
2.45.2
prev parent reply other threads:[~2024-06-20 14:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 14:44 [RFC PATCH 0/2] drm/amdgpu: Convert to ttm_bo_vmap() Thomas Zimmermann
2024-06-20 14:44 ` [PATCH 1/2] drm/amdgpu: Unmap BO memory before calling amdgpu_bo_unref() Thomas Zimmermann
2024-06-20 15:50 ` Christian König
2024-06-21 7:32 ` Thomas Zimmermann
2024-06-21 8:21 ` Christian König
2024-06-20 14:44 ` Thomas Zimmermann [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240620145238.25295-3-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=felix.kuehling@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox