From: Lang Yu <Lang.Yu@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Alex Deucher <alexander.deucher@amd.com>,
Felix Kuehling <Felix.Kuehling@amd.com>,
Huang Rui <ray.huang@amd.com>, Lang Yu <Lang.Yu@amd.com>,
Christian Koenig <christian.koenig@amd.com>
Subject: [PATCH 1/3] drm/amdgpu: extract a helper to import dmabuf more flexibly
Date: Mon, 25 Jul 2022 18:32:03 +0800 [thread overview]
Message-ID: <20220725103205.2085630-1-Lang.Yu@amd.com> (raw)
For clients(e.g., kfd) who want to determine whether to
create a buffer object by themselves especially when
importing a gfx BO based dmabuf.
Signed-off-by: Lang Yu <Lang.Yu@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 38 +++++++++++++--------
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h | 2 ++
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
index 579adfafe4d0..83bbf54d5562 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
@@ -429,6 +429,28 @@ static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops = {
.move_notify = amdgpu_dma_buf_move_notify
};
+struct drm_gem_object *
+amdgpu_dma_buf_create_obj_and_attach(struct drm_device *dev, struct dma_buf *dma_buf)
+{
+ struct dma_buf_attachment *attach;
+ struct drm_gem_object *obj;
+
+ obj = amdgpu_dma_buf_create_obj(dev, dma_buf);
+ if (IS_ERR(obj))
+ return obj;
+
+ attach = dma_buf_dynamic_attach(dma_buf, dev->dev,
+ &amdgpu_dma_buf_attach_ops, obj);
+ if (IS_ERR(attach)) {
+ drm_gem_object_put(obj);
+ return ERR_CAST(attach);
+ }
+
+ get_dma_buf(dma_buf);
+ obj->import_attach = attach;
+ return obj;
+}
+
/**
* amdgpu_gem_prime_import - &drm_driver.gem_prime_import implementation
* @dev: DRM device
@@ -442,7 +464,6 @@ static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops = {
struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
struct dma_buf *dma_buf)
{
- struct dma_buf_attachment *attach;
struct drm_gem_object *obj;
if (dma_buf->ops == &amdgpu_dmabuf_ops) {
@@ -457,20 +478,7 @@ struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
}
}
- obj = amdgpu_dma_buf_create_obj(dev, dma_buf);
- if (IS_ERR(obj))
- return obj;
-
- attach = dma_buf_dynamic_attach(dma_buf, dev->dev,
- &amdgpu_dma_buf_attach_ops, obj);
- if (IS_ERR(attach)) {
- drm_gem_object_put(obj);
- return ERR_CAST(attach);
- }
-
- get_dma_buf(dma_buf);
- obj->import_attach = attach;
- return obj;
+ return amdgpu_dma_buf_create_obj_and_attach(dev, dma_buf);
}
/**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h
index 3e93b9b407a9..3b89e3af7c06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h
@@ -27,6 +27,8 @@
struct dma_buf *amdgpu_gem_prime_export(struct drm_gem_object *gobj,
int flags);
+struct drm_gem_object*
+amdgpu_dma_buf_create_obj_and_attach(struct drm_device *dev, struct dma_buf *dma_buf);
struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
struct dma_buf *dma_buf);
bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
--
2.25.1
next reply other threads:[~2022-07-25 10:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 10:32 Lang Yu [this message]
2022-07-25 10:32 ` [PATCH 2/3] drm/amdkfd: refine the gfx BO based dmabuf handling Lang Yu
2022-07-25 14:20 ` Felix Kuehling
2022-07-26 0:15 ` Lang Yu
2022-07-26 0:32 ` Felix Kuehling
2022-07-26 0:40 ` Lang Yu
2022-07-26 1:48 ` Felix Kuehling
2022-07-26 2:18 ` Lang Yu
2022-07-26 3:03 ` Felix Kuehling
2022-07-26 3:40 ` Lang Yu
2022-07-25 10:32 ` [PATCH 3/3] drm/amdkfd: remove an unnecessary amdgpu_bo_ref Lang Yu
2022-07-28 2:33 ` Yu, Lang
2022-07-28 2:45 ` Felix Kuehling
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=20220725103205.2085630-1-Lang.Yu@amd.com \
--to=lang.yu@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=ray.huang@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