public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Xia Jiang <xia.jiang@mediatek.com>
To: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Rick Chang <rick.chang@mediatek.com>
Cc: <linux-media@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-mediatek@lists.infradead.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Tomasz Figa <tfiga@chromium.org>, <srv_heupstream@mediatek.com>,
	<senozhatsky@chromium.org>, <mojahsu@chromium.org>,
	<drinkcat@chromium.org>, <maoguang.meng@mediatek.com>,
	Pi-Hsun Shih <pihsun@chromium.org>,
	Jerry-ch Chen <jerry-ch.chen@mediatek.corp-partner.google.com>
Subject: [PATCH v12 07/29] media: v4l2-mem2mem: add v4l2_m2m_suspend, v4l2_m2m_resume
Date: Fri, 14 Aug 2020 15:11:40 +0800	[thread overview]
Message-ID: <20200814071202.25067-9-xia.jiang@mediatek.com> (raw)
In-Reply-To: <20200814071202.25067-1-xia.jiang@mediatek.com>

From: Pi-Hsun Shih <pihsun@chromium.org>

Add two functions that can be used to stop new jobs from being queued /
continue running queued job. This can be used while a driver using m2m
helper is going to suspend / wake up from resume, and can ensure that
there's no job running in suspend process.

BUG=b:143046833
TEST=build

Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
Signed-off-by: Jerry-ch Chen <jerry-ch.chen@mediatek.corp-partner.google.com>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
---
v12: add this relied patch to the series
---
 drivers/media/v4l2-core/v4l2-mem2mem.c | 41 ++++++++++++++++++++++++++
 include/media/v4l2-mem2mem.h           | 22 ++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 62ac9424c92a..ddfdb6375064 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -43,6 +43,10 @@ module_param(debug, bool, 0644);
 #define TRANS_ABORT		(1 << 2)
 
 
+/* The job queue is not running new jobs */
+#define QUEUE_PAUSED		(1 << 0)
+
+
 /* Offset base for buffers on the destination queue - used to distinguish
  * between source and destination buffers when mmapping - they receive the same
  * offsets but for different queues */
@@ -84,6 +88,7 @@ static const char * const m2m_entity_name[] = {
  * @job_queue:		instances queued to run
  * @job_spinlock:	protects job_queue
  * @job_work:		worker to run queued jobs.
+ * @job_queue_flags:	flags of the queue status, %QUEUE_PAUSED.
  * @m2m_ops:		driver callbacks
  */
 struct v4l2_m2m_dev {
@@ -101,6 +106,7 @@ struct v4l2_m2m_dev {
 	struct list_head	job_queue;
 	spinlock_t		job_spinlock;
 	struct work_struct	job_work;
+	unsigned long		job_queue_flags;
 
 	const struct v4l2_m2m_ops *m2m_ops;
 };
@@ -263,6 +269,12 @@ static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev)
 		return;
 	}
 
+	if (m2m_dev->job_queue_flags & QUEUE_PAUSED) {
+		spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+		dprintk("Running new jobs is paused\n");
+		return;
+	}
+
 	m2m_dev->curr_ctx = list_first_entry(&m2m_dev->job_queue,
 				   struct v4l2_m2m_ctx, queue);
 	m2m_dev->curr_ctx->job_flags |= TRANS_RUNNING;
@@ -504,6 +516,7 @@ void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev,
 
 	if (WARN_ON(!src_buf || !dst_buf))
 		goto unlock;
+	v4l2_m2m_buf_done(src_buf, state);
 	dst_buf->is_held = src_buf->flags & V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF;
 	if (!dst_buf->is_held) {
 		v4l2_m2m_dst_buf_remove(m2m_ctx);
@@ -528,6 +541,34 @@ void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev,
 }
 EXPORT_SYMBOL(v4l2_m2m_buf_done_and_job_finish);
 
+void v4l2_m2m_suspend(struct v4l2_m2m_dev *m2m_dev)
+{
+	unsigned long flags;
+	struct v4l2_m2m_ctx *curr_ctx;
+
+	spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+	m2m_dev->job_queue_flags |= QUEUE_PAUSED;
+	curr_ctx = m2m_dev->curr_ctx;
+	spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+
+	if (curr_ctx)
+		wait_event(curr_ctx->finished,
+			   !(curr_ctx->job_flags & TRANS_RUNNING));
+}
+EXPORT_SYMBOL(v4l2_m2m_suspend);
+
+void v4l2_m2m_resume(struct v4l2_m2m_dev *m2m_dev)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+	m2m_dev->job_queue_flags &= ~QUEUE_PAUSED;
+	spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+
+	v4l2_m2m_try_run(m2m_dev);
+}
+EXPORT_SYMBOL(v4l2_m2m_resume);
+
 int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
 		     struct v4l2_requestbuffers *reqbufs)
 {
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index 98753f00df7e..5a91b548ecc0 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -304,6 +304,28 @@ v4l2_m2m_is_last_draining_src_buf(struct v4l2_m2m_ctx *m2m_ctx,
 void v4l2_m2m_last_buffer_done(struct v4l2_m2m_ctx *m2m_ctx,
 			       struct vb2_v4l2_buffer *vbuf);
 
+/**
+ * v4l2_m2m_suspend() - stop new jobs from being run and wait for current job
+ * to finish
+ *
+ * @m2m_dev: opaque pointer to the internal data to handle M2M context
+ *
+ * Called by a driver in the suspend hook. Stop new jobs from being run, and
+ * wait for current running job to finish.
+ */
+void v4l2_m2m_suspend(struct v4l2_m2m_dev *m2m_dev);
+
+/**
+ * v4l2_m2m_resume() - resume job running and try to run a queued job
+ *
+ * @m2m_dev: opaque pointer to the internal data to handle M2M context
+ *
+ * Called by a driver in the resume hook. This reverts the operation of
+ * v4l2_m2m_suspend() and allows job to be run. Also try to run a queued job if
+ * there is any.
+ */
+void v4l2_m2m_resume(struct v4l2_m2m_dev *m2m_dev);
+
 /**
  * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer
  *
-- 
2.18.0

  parent reply	other threads:[~2020-08-14  7:13 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14  7:11 [PATCH v12 00/29] Add support for mt2701 JPEG ENC support Xia Jiang
2020-08-14  7:11 ` Xia Jiang
2020-08-14  7:11 ` [PATCH v12 01/29] media: platform: Improve subscribe event flow for bug fixing Xia Jiang
2020-08-14  7:11 ` [PATCH v12 02/29] media: platform: Improve queue set up " Xia Jiang
2020-08-14  7:11 ` [PATCH v12 03/29] media: platform: Improve getting and requesting irq " Xia Jiang
2020-08-14  7:11 ` [PATCH v12 04/29] media: platform: Change the fixed device node number to unfixed value Xia Jiang
2020-08-14  7:11 ` [PATCH v12 05/29] media: platform: Improve power on and power off flow Xia Jiang
2020-08-14  7:11 ` [PATCH v12 06/29] media: platform: Delete the resetting hardware flow in the system PM ops Xia Jiang
2020-08-14  7:11 ` Xia Jiang [this message]
2020-09-25 17:53   ` [PATCH v12 07/29] media: v4l2-mem2mem: add v4l2_m2m_suspend, v4l2_m2m_resume Adrian Ratiu
2020-09-25 17:57     ` Tomasz Figa
2020-09-28 14:03   ` [PATCH] media: v4l2-mem2mem: Fix spurious v4l2_m2m_buf_done Ezequiel Garcia
2020-09-28 14:12     ` Hans Verkuil
2020-09-28 14:13     ` Adrian Ratiu
2020-08-14  7:11 ` [PATCH v12 08/29] media: platform: Improve the implementation of the system PM ops Xia Jiang
2020-08-14  7:11 ` [PATCH v12 09/29] media: platform: Add mechanism to handle jpeg hardware's locking up Xia Jiang
2020-08-14  7:11 ` [PATCH v12 10/29] media: platform: Cancel the last frame handling flow Xia Jiang
2020-08-14  7:11 ` [PATCH v12 11/29] media: platform: Delete zeroing the reserved fields Xia Jiang
2020-08-14  7:11 ` [PATCH v12 12/29] media: platform: Stylistic changes for improving code quality Xia Jiang
2020-08-14  7:11 ` [PATCH v12 13/29] media: platform: Use generic rounding helpers Xia Jiang
2020-08-14  7:11 ` [PATCH v12 14/29] media: platform: Change MTK_JPEG_COMP_MAX macro definition location Xia Jiang
2020-08-14  7:11 ` [PATCH v12 15/29] media: platform: Delete redundant code and add annotation for an enum Xia Jiang
2020-08-14  7:11 ` [PATCH v12 16/29] media: platform: Delete vidioc_s_selection ioctl of jpeg dec Xia Jiang
2020-08-14  7:11 ` [PATCH v12 17/29] media: platform: Change the maximum width and height supported by JPEG dec Xia Jiang
2020-08-14  7:11 ` [PATCH v12 18/29] media: platform: Refactor mtk_jpeg_try_fmt_mplane() Xia Jiang
2020-08-14  7:11 ` [PATCH v12 19/29] media: platform: Refactor mtk_jpeg_find_format() Xia Jiang
2020-08-14  7:11 ` [PATCH v12 20/29] media: platform: Redefinition of mtk_jpeg_q_data structure Xia Jiang
2020-08-14  7:11 ` [PATCH v12 21/29] media: platform: Change the colorspace of jpeg to the fixed value Xia Jiang
2020-08-14  7:11 ` [PATCH v12 22/29] media: platform: Refactor mtk_jpeg_set_default_params() Xia Jiang
2020-08-14  7:11 ` [PATCH v12 23/29] media: platform: Change the call functions of getting/enable/disable the jpeg's clock Xia Jiang
2020-08-14  7:11 ` [PATCH v12 24/29] media: dt-bindings: Add jpeg enc device tree node document Xia Jiang
2020-08-14  7:11 ` [PATCH v12 25/29] arm: dts: mt2701: Add jpeg enc device tree node Xia Jiang
2020-08-19 11:37   ` Hans Verkuil
2020-08-19 14:12     ` Matthias Brugger
2020-08-14  7:11 ` [PATCH v12 26/29] media: platform: Rename jpeg dec file name Xia Jiang
2020-08-14  7:12 ` [PATCH v12 27/29] media: platform: Rename existing functions/defines/variables Xia Jiang
2020-08-14  7:12 ` [PATCH v12 28/29] media: platform: Using the variant structure to contain the varability between dec and enc Xia Jiang
2020-08-14  7:12 ` [PATCH v12 29/29] media: platform: Add jpeg enc feature Xia Jiang

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=20200814071202.25067-9-xia.jiang@mediatek.com \
    --to=xia.jiang@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=drinkcat@chromium.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jerry-ch.chen@mediatek.corp-partner.google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maoguang.meng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab+samsung@kernel.org \
    --cc=mojahsu@chromium.org \
    --cc=pihsun@chromium.org \
    --cc=rick.chang@mediatek.com \
    --cc=robh+dt@kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=srv_heupstream@mediatek.com \
    --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