All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
To: linux-media@vger.kernel.org, sakari.ailus@linux.intel.com,
	Jacopo Mondi <jacopo+renesas@jmondi.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	niklas.soderlund+renesas@ragnatech.se,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Pratyush Yadav <p.yadav@ti.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Subject: [PATCH v5 5/6] media: subdev: add v4l2_subdev_call_state_active()
Date: Tue,  1 Mar 2022 12:55:47 +0200	[thread overview]
Message-ID: <20220301105548.305191-6-tomi.valkeinen@ideasonboard.com> (raw)
In-Reply-To: <20220301105548.305191-1-tomi.valkeinen@ideasonboard.com>

Add v4l2_subdev_call_state_active() macro to help calling subdev ops
that take a subdev state as a parameter. Normally the v4l2 framework
will lock and pass the correct subdev state to the subdev ops, but there
are legacy situations where this is not the case (e.g. non-MC video
device driver calling set_fmt in a source subdev).

As this macro is only needed for legacy use cases, the macro is added in
a new header file, v4l2-subdev-legacy.h.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 include/media/v4l2-subdev-legacy.h | 42 ++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 include/media/v4l2-subdev-legacy.h

diff --git a/include/media/v4l2-subdev-legacy.h b/include/media/v4l2-subdev-legacy.h
new file mode 100644
index 000000000000..6a61e579b629
--- /dev/null
+++ b/include/media/v4l2-subdev-legacy.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ *  V4L2 sub-device legacy support header.
+ *
+ *  Copyright (C) 2022  Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
+ */
+
+#ifndef _V4L2_SUBDEV_LEGACY_H
+#define _V4L2_SUBDEV_LEGACY_H
+
+/**
+ * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which
+ *				   takes state as a parameter, passing the
+ *				   subdev its active state.
+ *
+ * @sd: pointer to the &struct v4l2_subdev
+ * @o: name of the element at &struct v4l2_subdev_ops that contains @f.
+ *     Each element there groups a set of callbacks functions.
+ * @f: callback function to be called.
+ *     The callback functions are defined in groups, according to
+ *     each element at &struct v4l2_subdev_ops.
+ * @args: arguments for @f.
+ *
+ * This is similar to v4l2_subdev_call(), except that this version can only be
+ * used for ops that take a subdev state as a parameter. The macro will get the
+ * active state and lock it before calling the op, and unlock it after the
+ * call.
+ */
+#define v4l2_subdev_call_state_active(sd, o, f, args...)		\
+	({								\
+		int __result;						\
+		struct v4l2_subdev_state *state;			\
+		state = v4l2_subdev_get_active_state(sd);		\
+		if (state)						\
+			v4l2_subdev_lock_state(state);			\
+		__result = v4l2_subdev_call(sd, o, f, state, ##args);	\
+		if (state)						\
+			v4l2_subdev_unlock_state(state);		\
+		__result;						\
+	})
+
+#endif
-- 
2.25.1


  parent reply	other threads:[~2022-03-01 10:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 10:55 [PATCH v5 0/6] v4l: subdev active state Tomi Valkeinen
2022-03-01 10:55 ` [PATCH v5 1/6] media: subdev: rename subdev-state alloc & free Tomi Valkeinen
2022-03-01 10:55 ` [PATCH v5 2/6] media: subdev: add active state to struct v4l2_subdev Tomi Valkeinen
2022-03-01 10:55 ` [PATCH v5 3/6] media: subdev: pass also the active state to subdevs from ioctls Tomi Valkeinen
2022-03-01 10:55 ` [PATCH v5 4/6] media: subdev: add subdev state locking Tomi Valkeinen
2022-03-04 13:25   ` Hans Verkuil
2022-03-07  7:38     ` Tomi Valkeinen
2022-03-01 10:55 ` Tomi Valkeinen [this message]
2022-03-02  9:36   ` [PATCH v5 5/6] media: subdev: add v4l2_subdev_call_state_active() Laurent Pinchart
2022-03-02 10:13     ` Sakari Ailus
2022-03-04 13:34   ` Hans Verkuil
2022-03-07  7:16     ` Tomi Valkeinen
2022-03-07  8:36       ` Hans Verkuil
2022-03-07  9:16         ` Tomi Valkeinen
2022-03-07  9:51           ` Hans Verkuil
2022-03-07 14:00             ` Tomi Valkeinen
2022-03-22  8:20               ` Tomi Valkeinen
2022-03-22  9:23               ` Hans Verkuil
2022-03-22  9:46                 ` Tomi Valkeinen
2022-03-22 19:38               ` Laurent Pinchart
2022-03-01 10:55 ` [PATCH v5 6/6] media: Documentation: add documentation about subdev state Tomi Valkeinen
2022-03-02  9:26   ` Tomi Valkeinen

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=20220301105548.305191-6-tomi.valkeinen@ideasonboard.com \
    --to=tomi.valkeinen@ideasonboard.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jacopo+renesas@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=p.yadav@ti.com \
    --cc=sakari.ailus@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.