From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Hans Verkuil <hans.verkuil@cisco.com>,
Tomasz Figa <tfiga@chromium.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Kyungmin Park <kyungmin.park@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Pawel Osciak <posciak@chromium.org>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: [RFC][PATCH 06/15] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT in CREATE_BUFS
Date: Tue, 17 Dec 2019 12:20:25 +0900 [thread overview]
Message-ID: <20191217032034.54897-7-senozhatsky@chromium.org> (raw)
In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org>
This patch lets user-space to request a non-consistent memory
allocation during CREATE_BUFS ioctl call. struct v4l2_create_buffers
has seven 4-byte reserved areas, so reserved[0] is renamed to ->flags.
The struct, thus, now has six reserved 4-byte regions.
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
.../media/uapi/v4l/vidioc-create-bufs.rst | 8 +++++-
.../media/common/videobuf2/videobuf2-core.c | 27 +++++++++++++++----
.../media/common/videobuf2/videobuf2-v4l2.c | 7 ++++-
drivers/media/v4l2-core/v4l2-ioctl.c | 2 +-
include/media/videobuf2-core.h | 4 ++-
include/uapi/linux/videodev2.h | 3 ++-
6 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst
index bd08e4f77ae4..c56e80659b4a 100644
--- a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst
+++ b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst
@@ -121,7 +121,13 @@ than the number requested.
other changes, then set ``count`` to 0, ``memory`` to
``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type.
* - __u32
- - ``reserved``\ [7]
+ - ``flags``
+ - Specifies additional buffer management attributes. E.g. when
+ ``V4L2_FLAG_MEMORY_NON_CONSISTENT`` set vb2 backends may be allocated
+ in non-consistent memory.
+
+ * - __u32
+ - ``reserved``\ [6]
- A place holder for future extensions. Drivers and applications
must set the array to zero.
diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 668c56df13f6..d1012a24755d 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -812,9 +812,21 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
}
EXPORT_SYMBOL_GPL(vb2_core_reqbufs);
+static bool verify_consistency_attr(struct vb2_queue *q, bool consistent_mem)
+{
+ bool queue_attr = q->dma_attrs & DMA_ATTR_NON_CONSISTENT;
+
+ if (consistent_mem != queue_attr) {
+ dprintk(1, "memory consistency model mismatch\n");
+ return false;
+ }
+ return true;
+}
+
int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
- unsigned int *count, unsigned requested_planes,
- const unsigned requested_sizes[])
+ bool consistent_mem, unsigned int *count,
+ unsigned requested_planes,
+ const unsigned requested_sizes[])
{
unsigned int num_planes = 0, num_buffers, allocated_buffers;
unsigned plane_sizes[VB2_MAX_PLANES] = { };
@@ -832,10 +844,15 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
}
memset(q->alloc_devs, 0, sizeof(q->alloc_devs));
q->memory = memory;
+ __set_queue_consistency(q, consistent_mem);
q->waiting_for_buffers = !q->is_output;
- } else if (q->memory != memory) {
- dprintk(1, "memory model mismatch\n");
- return -EINVAL;
+ } else {
+ if (q->memory != memory) {
+ dprintk(1, "memory model mismatch\n");
+ return -EINVAL;
+ }
+ if (!verify_consistency_attr(q, consistent_mem))
+ return -EINVAL;
}
num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers);
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 0eabb589684f..48d123a1ac2a 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -730,6 +730,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
unsigned requested_sizes[VIDEO_MAX_PLANES];
struct v4l2_format *f = &create->format;
int ret = vb2_verify_memory_type(q, create->memory, f->type);
+ bool consistent = true;
unsigned i;
fill_buf_caps(q, &create->capabilities);
@@ -775,7 +776,11 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
for (i = 0; i < requested_planes; i++)
if (requested_sizes[i] == 0)
return -EINVAL;
- return ret ? ret : vb2_core_create_bufs(q, create->memory,
+
+ if (create->flags & V4L2_FLAG_MEMORY_NON_CONSISTENT)
+ consistent = false;
+
+ return ret ? ret : vb2_core_create_bufs(q, create->memory, consistent,
&create->count, requested_planes, requested_sizes);
}
EXPORT_SYMBOL_GPL(vb2_create_bufs);
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 225d06819bce..793cb6534de4 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2012,7 +2012,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
if (ret)
return ret;
- CLEAR_AFTER_FIELD(create, capabilities);
+ CLEAR_AFTER_FIELD(create, flags);
v4l_sanitize_format(&create->format);
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 810af5cf5742..5e5450bdabbd 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -757,6 +757,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
* vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs
* @q: pointer to &struct vb2_queue with videobuf2 queue.
* @memory: memory type, as defined by &enum vb2_memory.
+ * @consistent_mem: memory consistency model.
* @count: requested buffer count.
* @requested_planes: number of planes requested.
* @requested_sizes: array with the size of the planes.
@@ -774,7 +775,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory,
* Return: returns zero on success; an error code otherwise.
*/
int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory,
- unsigned int *count, unsigned int requested_planes,
+ bool consistent_mem, unsigned int *count,
+ unsigned int requested_planes,
const unsigned int requested_sizes[]);
/**
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 73a4854f71bd..82e2ded5a136 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2419,7 +2419,8 @@ struct v4l2_create_buffers {
__u32 memory;
struct v4l2_format format;
__u32 capabilities;
- __u32 reserved[7];
+ __u32 flags;
+ __u32 reserved[6];
};
/*
--
2.24.1.735.g03f4e72817-goog
next prev parent reply other threads:[~2019-12-17 3:21 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-17 3:20 [RFC][PATCH 00/15] Implement V4L2_BUF_FLAG_NO_CACHE_* flags Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 01/15] videobuf2: add cache management members Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 02/15] videobuf2: handle V4L2 buffer cache flags Sergey Senozhatsky
2020-01-10 10:24 ` Hans Verkuil
2020-01-22 1:39 ` Sergey Senozhatsky
2020-01-22 2:53 ` Sergey Senozhatsky
2020-01-28 4:35 ` Tomasz Figa
2019-12-17 3:20 ` [RFC][PATCH 03/15] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Sergey Senozhatsky
2020-01-10 9:36 ` Hans Verkuil
2020-01-10 9:46 ` Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 04/15] videobuf2: add queue memory consistency parameter Sergey Senozhatsky
2020-01-10 9:47 ` Hans Verkuil
2020-01-22 2:05 ` Sergey Senozhatsky
2020-01-23 11:02 ` Hans Verkuil
2020-01-24 2:04 ` Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 05/15] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT in REQBUFS Sergey Senozhatsky
2020-01-10 9:55 ` Hans Verkuil
2020-01-22 2:18 ` Sergey Senozhatsky
2020-01-22 3:48 ` Sergey Senozhatsky
2020-01-23 11:08 ` Hans Verkuil
2020-01-28 4:45 ` Tomasz Figa
2020-01-28 8:38 ` Hans Verkuil
2019-12-17 3:20 ` Sergey Senozhatsky [this message]
2020-01-10 9:59 ` [RFC][PATCH 06/15] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT in CREATE_BUFS Hans Verkuil
2020-01-23 3:41 ` Sergey Senozhatsky
2020-01-23 11:41 ` Hans Verkuil
2020-01-24 1:28 ` Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 07/15] videobuf2: factor out planes prepare/finish functions Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 08/15] videobuf2: do not sync caches when we are allowed not to Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 09/15] videobuf2: check ->synced flag in prepare() and finish() Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 10/15] videobuf2: let user-space know when driver supports cache hints Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 11/15] videobuf2: add begin/end cpu_access callbacks to dma-contig Sergey Senozhatsky
2019-12-17 3:20 ` [RFC][PATCH 12/15] videobuf2: add begin/end cpu_access callbacks to dma-sg Sergey Senozhatsky
2020-01-10 10:13 ` Hans Verkuil
2020-01-22 6:37 ` Sergey Senozhatsky
2020-01-28 4:38 ` Tomasz Figa
2020-01-28 8:36 ` Hans Verkuil
2020-01-30 11:02 ` Tomasz Figa
2020-01-30 12:18 ` Hans Verkuil
2020-02-03 10:04 ` Tomasz Figa
2020-02-04 2:50 ` Sergey Senozhatsky
2020-02-06 8:51 ` Tomasz Figa
2019-12-17 3:20 ` [RFC][PATCH 13/15] videobuf2: do not sync buffers for DMABUF queues Sergey Senozhatsky
2020-01-10 10:30 ` Hans Verkuil
2020-01-22 5:05 ` Sergey Senozhatsky
2020-01-23 11:35 ` Hans Verkuil
2020-01-24 2:25 ` Sergey Senozhatsky
2020-01-24 7:32 ` Sergey Senozhatsky
2020-01-28 7:22 ` Tomasz Figa
2020-01-28 7:34 ` Sergey Senozhatsky
2020-01-28 7:19 ` Tomasz Figa
2020-01-28 8:47 ` Hans Verkuil
2019-12-17 3:20 ` [RFC][PATCH 14/15] videobuf2: don't test db_attach in dma-contig prepare and finish Sergey Senozhatsky
2020-01-10 10:32 ` Hans Verkuil
2019-12-17 3:20 ` [RFC][PATCH 15/15] videobuf2: don't test db_attach in dma-sg " Sergey Senozhatsky
2020-01-08 2:27 ` [RFC][PATCH 00/15] Implement V4L2_BUF_FLAG_NO_CACHE_* flags Sergey Senozhatsky
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=20191217032034.54897-7-senozhatsky@chromium.org \
--to=senozhatsky@chromium.org \
--cc=hans.verkuil@cisco.com \
--cc=kyungmin.park@samsung.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=posciak@chromium.org \
--cc=sakari.ailus@iki.fi \
--cc=tfiga@chromium.org \
/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).