From: Qiang Yu <yuq825@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: lima@lists.freedesktop.org, David Airlie <airlied@linux.ie>,
Vasily Khoruzhick <anarsoul@gmail.com>,
Andreas Baierl <ichgeh@imkreisrum.de>,
Qiang Yu <yuq825@gmail.com>, Icenowy Zheng <icenowy@aosc.io>,
Erico Nunes <nunes.erico@gmail.com>
Subject: [PATCH 5/5] drm/lima: add LIMA_BO_FLAG_FORCE_VA
Date: Sat, 22 Feb 2020 10:42:10 +0800 [thread overview]
Message-ID: <20200222024210.18697-6-yuq825@gmail.com> (raw)
In-Reply-To: <20200222024210.18697-1-yuq825@gmail.com>
User can force created buffer to be mapped to GPU VM at a user
specified address. This is used for debug tools in user space to
replay some task.
Signed-off-by: Qiang Yu <yuq825@gmail.com>
---
drivers/gpu/drm/lima/lima_drv.c | 26 +++++++++++++++++++-------
drivers/gpu/drm/lima/lima_gem.c | 7 +++++--
drivers/gpu/drm/lima/lima_gem.h | 4 +++-
drivers/gpu/drm/lima/lima_vm.c | 13 ++++++++++++-
include/uapi/drm/lima_drm.h | 9 +++++++--
5 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c
index 8c5adc025902..f65021ea9598 100644
--- a/drivers/gpu/drm/lima/lima_drv.c
+++ b/drivers/gpu/drm/lima/lima_drv.c
@@ -73,16 +73,27 @@ static int lima_ioctl_gem_create(struct drm_device *dev, void *data, struct drm_
{
struct drm_lima_gem_create *args = data;
- if (args->pad)
- return -EINVAL;
-
- if (args->flags & ~(LIMA_BO_FLAG_HEAP))
+ if (args->flags & ~(LIMA_BO_FLAG_HEAP | LIMA_BO_FLAG_FORCE_VA))
return -EINVAL;
if (args->size == 0)
return -EINVAL;
- return lima_gem_create_handle(dev, file, args->size, args->flags, &args->handle);
+ if (args->flags & LIMA_BO_FLAG_FORCE_VA) {
+ u64 max = (u64)args->va + (u64)args->size;
+
+ if (max > LIMA_VA_RESERVE_START)
+ return -EINVAL;
+
+ if (!IS_ALIGNED(args->va, PAGE_SIZE))
+ return -EINVAL;
+ } else {
+ if (args->va)
+ return -EINVAL;
+ }
+
+ return lima_gem_create_handle(dev, file, args->size, args->flags,
+ &args->handle, args->va);
}
static int lima_ioctl_gem_info(struct drm_device *dev, void *data, struct drm_file *file)
@@ -253,6 +264,7 @@ DEFINE_DRM_GEM_FOPS(lima_drm_driver_fops);
* Changelog:
*
* - 1.1.0 - add heap buffer support
+ * - 1.2.0 - add force va support
*/
static struct drm_driver lima_drm_driver = {
@@ -264,9 +276,9 @@ static struct drm_driver lima_drm_driver = {
.fops = &lima_drm_driver_fops,
.name = "lima",
.desc = "lima DRM",
- .date = "20191231",
+ .date = "20200215",
.major = 1,
- .minor = 1,
+ .minor = 2,
.patchlevel = 0,
.gem_create_object = lima_gem_create_object,
diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
index 5404e0d668db..c28d90756584 100644
--- a/drivers/gpu/drm/lima/lima_gem.c
+++ b/drivers/gpu/drm/lima/lima_gem.c
@@ -95,7 +95,7 @@ int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm)
}
int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
- u32 size, u32 flags, u32 *handle)
+ u32 size, u32 flags, u32 *handle, u32 va)
{
int err;
gfp_t mask;
@@ -116,8 +116,11 @@ int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
mask |= __GFP_DMA32;
mapping_set_gfp_mask(obj->filp->f_mapping, mask);
+ bo = to_lima_bo(obj);
+ bo->flags = flags;
+ bo->force_va = va;
+
if (is_heap) {
- bo = to_lima_bo(obj);
err = lima_heap_alloc(bo, NULL);
if (err)
goto out;
diff --git a/drivers/gpu/drm/lima/lima_gem.h b/drivers/gpu/drm/lima/lima_gem.h
index ccea06142f4b..2a6db0c0be89 100644
--- a/drivers/gpu/drm/lima/lima_gem.h
+++ b/drivers/gpu/drm/lima/lima_gem.h
@@ -15,6 +15,8 @@ struct lima_bo {
struct mutex lock;
struct list_head va;
+ u32 flags;
+ u32 force_va;
size_t heap_size;
};
@@ -37,7 +39,7 @@ static inline struct dma_resv *lima_bo_resv(struct lima_bo *bo)
int lima_heap_alloc(struct lima_bo *bo, struct lima_vm *vm);
struct drm_gem_object *lima_gem_create_object(struct drm_device *dev, size_t size);
int lima_gem_create_handle(struct drm_device *dev, struct drm_file *file,
- u32 size, u32 flags, u32 *handle);
+ u32 size, u32 flags, u32 *handle, u32 va);
int lima_gem_get_info(struct drm_file *file, u32 handle, u32 *va, u64 *offset);
int lima_gem_submit(struct drm_file *file, struct lima_submit *submit);
int lima_gem_wait(struct drm_file *file, u32 handle, u32 op, s64 timeout_ns);
diff --git a/drivers/gpu/drm/lima/lima_vm.c b/drivers/gpu/drm/lima/lima_vm.c
index 5b92fb82674a..be0510032538 100644
--- a/drivers/gpu/drm/lima/lima_vm.c
+++ b/drivers/gpu/drm/lima/lima_vm.c
@@ -3,6 +3,7 @@
#include <linux/slab.h>
#include <linux/dma-mapping.h>
+#include <drm/lima_drm.h>
#include "lima_device.h"
#include "lima_vm.h"
@@ -93,6 +94,7 @@ int lima_vm_bo_add(struct lima_vm *vm, struct lima_bo *bo, bool create)
struct lima_bo_va *bo_va;
struct sg_dma_page_iter sg_iter;
int offset = 0, err;
+ u64 start, end;
mutex_lock(&bo->lock);
@@ -120,7 +122,16 @@ int lima_vm_bo_add(struct lima_vm *vm, struct lima_bo *bo, bool create)
mutex_lock(&vm->lock);
- err = drm_mm_insert_node(&vm->mm, &bo_va->node, lima_bo_size(bo));
+ if (bo->flags & LIMA_BO_FLAG_FORCE_VA) {
+ start = bo->force_va;
+ end = start + lima_bo_size(bo);
+ } else {
+ start = 0;
+ end = U64_MAX;
+ }
+
+ err = drm_mm_insert_node_in_range(&vm->mm, &bo_va->node, lima_bo_size(bo),
+ 0, 0, start, end, 0);
if (err)
goto err_out1;
diff --git a/include/uapi/drm/lima_drm.h b/include/uapi/drm/lima_drm.h
index 1ec58d652a5a..3e699bb78394 100644
--- a/include/uapi/drm/lima_drm.h
+++ b/include/uapi/drm/lima_drm.h
@@ -37,7 +37,12 @@ struct drm_lima_get_param {
* due to lack of heap memory. size field of heap buffer is an up bound of
* the backup memory which can be set to a fairly large value.
*/
-#define LIMA_BO_FLAG_HEAP (1 << 0)
+#define LIMA_BO_FLAG_HEAP (1 << 0)
+/*
+ * force buffer GPU virtual address to be drm_lima_gem_create.va, this is
+ * used to replay some task with fixed GPU virtual address
+ */
+#define LIMA_BO_FLAG_FORCE_VA (1 << 1)
/**
* create a buffer for used by GPU
@@ -46,7 +51,7 @@ struct drm_lima_gem_create {
__u32 size; /* in, buffer size */
__u32 flags; /* in, buffer flags */
__u32 handle; /* out, GEM buffer handle */
- __u32 pad; /* pad, must be zero */
+ __u32 va; /* in, buffer va */
};
/**
--
2.17.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-02-22 2:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-22 2:42 [PATCH 0/5] drm/lima: add error debug functionality Qiang Yu
2020-02-22 2:42 ` [PATCH 1/5] drm/lima: save process info for debug usage Qiang Yu
2020-02-22 2:42 ` [PATCH 2/5] drm/lima: add max_error_tasks module parameter Qiang Yu
2020-02-22 2:42 ` [PATCH 3/5] drm/lima: save task info dump when task fail Qiang Yu
2020-02-23 2:07 ` kbuild test robot
2020-03-03 9:06 ` Vasily Khoruzhick
2020-03-07 13:44 ` [PATCH v2 3/6] " Qiang Yu
2020-02-22 2:42 ` [PATCH 4/5] drm/lima: add error sysfs to export error task dump Qiang Yu
2020-02-22 2:42 ` Qiang Yu [this message]
2020-03-04 11:40 ` [PATCH 0/5] drm/lima: add error debug functionality Andreas Baierl
2020-03-15 4:33 ` Vasily Khoruzhick
2020-03-22 1:47 ` Qiang Yu
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=20200222024210.18697-6-yuq825@gmail.com \
--to=yuq825@gmail.com \
--cc=airlied@linux.ie \
--cc=anarsoul@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=icenowy@aosc.io \
--cc=ichgeh@imkreisrum.de \
--cc=lima@lists.freedesktop.org \
--cc=nunes.erico@gmail.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;
as well as URLs for NNTP newsgroup(s).