mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Tomasz Figa <tfiga@chromium.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Subject: [PATCHv5 13/13] media: vivid: add cache_hints module param
Date: Fri, 24 Apr 2020 18:29:20 +0900	[thread overview]
Message-ID: <20200424092920.4801-14-sergey.senozhatsky@gmail.com> (raw)
In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com>

Add a cache_hints module param to control per-queue user space cache
hints support.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 Documentation/admin-guide/media/vivid.rst          | 9 +++++++++
 drivers/media/test-drivers/vivid/vivid-core.c      | 9 +++++++++
 drivers/media/test-drivers/vivid/vivid-core.h      | 1 +
 drivers/media/test-drivers/vivid/vivid-meta-cap.c  | 5 +++++
 drivers/media/test-drivers/vivid/vivid-meta-out.c  | 5 +++++
 drivers/media/test-drivers/vivid/vivid-sdr-cap.c   | 7 +++++++
 drivers/media/test-drivers/vivid/vivid-touch-cap.c | 5 +++++
 drivers/media/test-drivers/vivid/vivid-vbi-cap.c   | 5 +++++
 drivers/media/test-drivers/vivid/vivid-vbi-out.c   | 5 +++++
 drivers/media/test-drivers/vivid/vivid-vid-cap.c   | 5 +++++
 drivers/media/test-drivers/vivid/vivid-vid-out.c   | 5 +++++
 11 files changed, 61 insertions(+)

diff --git a/Documentation/admin-guide/media/vivid.rst b/Documentation/admin-guide/media/vivid.rst
index 52e57b773f07..a41fa7129dec 100644
--- a/Documentation/admin-guide/media/vivid.rst
+++ b/Documentation/admin-guide/media/vivid.rst
@@ -293,6 +293,15 @@ all configurable using the following module options:
 		- 0: vmalloc
 		- 1: dma-contig
 
+- cache_hints:
+
+	user-space cache hints selection, default is 0. It specifies if the
+	device supports user-space cache (for MMAP queues only) and memory
+	consistency hints.
+
+		- 0: forbid hints
+		- 1: allow hints
+
 Taken together, all these module options allow you to precisely customize
 the driver behavior and test your application with all sorts of permutations.
 It is also very suitable to emulate hardware that is not yet available, e.g.
diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c
index 6c740e3e6999..b1bea405f382 100644
--- a/drivers/media/test-drivers/vivid/vivid-core.c
+++ b/drivers/media/test-drivers/vivid/vivid-core.c
@@ -169,6 +169,14 @@ MODULE_PARM_DESC(allocators, " memory allocator selection, default is 0.\n"
 			     "\t\t    0 == vmalloc\n"
 			     "\t\t    1 == dma-contig");
 
+static unsigned int cache_hints[VIVID_MAX_DEVS] = {
+	[0 ... (VIVID_MAX_DEVS - 1)] = 0
+};
+module_param_array(cache_hints, uint, NULL, 0444);
+MODULE_PARM_DESC(cache_hints, " user-space cache hints, default is 0.\n"
+			     "\t\t    0 == forbid\n"
+			     "\t\t    1 == allow");
+
 static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS];
 
 const struct v4l2_rect vivid_min_rect = {
@@ -819,6 +827,7 @@ static int vivid_create_queue(struct vivid_dev *dev,
 	q->lock = &dev->mutex;
 	q->dev = dev->v4l2_dev.dev;
 	q->supports_requests = true;
+	dev->allow_cache_hints = (cache_hints[dev->inst] == 1);
 
 	return vb2_queue_init(q);
 }
diff --git a/drivers/media/test-drivers/vivid/vivid-core.h b/drivers/media/test-drivers/vivid/vivid-core.h
index 99e69b8f770f..75ab627ba91f 100644
--- a/drivers/media/test-drivers/vivid/vivid-core.h
+++ b/drivers/media/test-drivers/vivid/vivid-core.h
@@ -572,6 +572,7 @@ struct vivid_dev {
 
 	bool				meta_pts;
 	bool				meta_scr;
+	bool				allow_cache_hints;
 };
 
 static inline bool vivid_is_webcam(const struct vivid_dev *dev)
diff --git a/drivers/media/test-drivers/vivid/vivid-meta-cap.c b/drivers/media/test-drivers/vivid/vivid-meta-cap.c
index 780f96860a6d..0ba8fff47106 100644
--- a/drivers/media/test-drivers/vivid/vivid-meta-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-meta-cap.c
@@ -34,6 +34,11 @@ static int meta_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
 		*nbuffers = 2 - vq->num_buffers;
 
 	*nplanes = 1;
+
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vivid/vivid-meta-out.c b/drivers/media/test-drivers/vivid/vivid-meta-out.c
index ff8a039aba72..6be56f1230d4 100644
--- a/drivers/media/test-drivers/vivid/vivid-meta-out.c
+++ b/drivers/media/test-drivers/vivid/vivid-meta-out.c
@@ -34,6 +34,11 @@ static int meta_out_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
 		*nbuffers = 2 - vq->num_buffers;
 
 	*nplanes = 1;
+
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vivid/vivid-sdr-cap.c b/drivers/media/test-drivers/vivid/vivid-sdr-cap.c
index 2b7522e16efc..f87cd7d0fada 100644
--- a/drivers/media/test-drivers/vivid/vivid-sdr-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-sdr-cap.c
@@ -211,9 +211,16 @@ static int sdr_cap_queue_setup(struct vb2_queue *vq,
 		       unsigned *nbuffers, unsigned *nplanes,
 		       unsigned sizes[], struct device *alloc_devs[])
 {
+	struct vivid_dev *dev = vb2_get_drv_priv(vq);
+
 	/* 2 = max 16-bit sample returned */
 	sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2;
 	*nplanes = 1;
+
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vivid/vivid-touch-cap.c b/drivers/media/test-drivers/vivid/vivid-touch-cap.c
index ebb00b128030..af43a5f69ea0 100644
--- a/drivers/media/test-drivers/vivid/vivid-touch-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-touch-cap.c
@@ -27,6 +27,11 @@ static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
 		*nbuffers = 2 - vq->num_buffers;
 
 	*nplanes = 1;
+
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c
index 1a9348eea781..126754c0bee4 100644
--- a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c
@@ -138,6 +138,11 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq,
 		*nbuffers = 2 - vq->num_buffers;
 
 	*nplanes = 1;
+
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-out.c b/drivers/media/test-drivers/vivid/vivid-vbi-out.c
index cd56476902a2..d35b458c01d2 100644
--- a/drivers/media/test-drivers/vivid/vivid-vbi-out.c
+++ b/drivers/media/test-drivers/vivid/vivid-vbi-out.c
@@ -34,6 +34,11 @@ static int vbi_out_queue_setup(struct vb2_queue *vq,
 		*nbuffers = 2 - vq->num_buffers;
 
 	*nplanes = 1;
+
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
 	return 0;
 }
 
diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
index e94beef008c8..d0dfd3632ba9 100644
--- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
@@ -129,6 +129,11 @@ static int vid_cap_queue_setup(struct vb2_queue *vq,
 
 	*nplanes = buffers;
 
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
+
 	dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers);
 	for (p = 0; p < buffers; p++)
 		dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]);
diff --git a/drivers/media/test-drivers/vivid/vivid-vid-out.c b/drivers/media/test-drivers/vivid/vivid-vid-out.c
index ee3446e3217c..4af8aaa13ffa 100644
--- a/drivers/media/test-drivers/vivid/vivid-vid-out.c
+++ b/drivers/media/test-drivers/vivid/vivid-vid-out.c
@@ -78,6 +78,11 @@ static int vid_out_queue_setup(struct vb2_queue *vq,
 
 	*nplanes = planes;
 
+	if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP)
+		vq->allow_cache_hints = 1;
+	else
+		vq->allow_cache_hints = 0;
+
 	dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers);
 	for (p = 0; p < planes; p++)
 		dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]);
-- 
2.26.2


  parent reply	other threads:[~2020-04-24  9:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24  9:29 [PATCHv5 00/13] Implement V4L2_BUF_FLAG_NO_CACHE_* flags Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 01/13] videobuf2: use explicit unsigned int in vb2_queue Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 02/13] videobuf2: add cache management members Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 03/13] videobuf2: handle V4L2 buffer cache flags Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 04/13] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 05/13] videobuf2: add queue memory consistency parameter Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 06/13] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 07/13] videobuf2: factor out planes prepare/finish functions Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 08/13] videobuf2: do not sync caches when we are allowed not to Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 09/13] videobuf2: check ->synced flag in prepare() and finish() Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 10/13] videobuf2: add begin/end cpu_access callbacks to dma-contig Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 11/13] videobuf2: add begin/end cpu_access callbacks to dma-sg Sergey Senozhatsky
2020-04-24  9:29 ` [PATCHv5 12/13] videobuf2: don't test db_attach in dma-contig prepare and finish Sergey Senozhatsky
2020-04-24  9:29 ` Sergey Senozhatsky [this message]
2020-04-28 14:47 ` [PATCHv5 00/13] Implement V4L2_BUF_FLAG_NO_CACHE_* flags Hans Verkuil
2020-05-14 15:36   ` 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=20200424092920.4801-14-sergey.senozhatsky@gmail.com \
    --to=sergey.senozhatsky@gmail.com \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --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

all inboxes | Powered by JetHome®