diff mbox series

[1/2] media: subdev: Add v4l2_subdev_call_state_try() macro

Message ID 20220701131559.66715-1-tomi.valkeinen@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series [1/2] media: subdev: Add v4l2_subdev_call_state_try() macro | expand

Commit Message

Tomi Valkeinen July 1, 2022, 1:15 p.m. UTC
Add a helper macro for the situations where a non-MC driver needs to
call a state-operation (operation which takes a subdev state as a
parameter) in try-context in another subdev.

The macro allocates a new subdev state for the called subdev and frees
the state afterwards.

An example use case is a media platform driver testing if a
v4l2_subdev_format would be accepted by a source subdev.

This should not be used in MC drivers.

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

Comments

Laurent Pinchart July 1, 2022, 3:26 p.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Fri, Jul 01, 2022 at 04:15:58PM +0300, Tomi Valkeinen wrote:
> Add a helper macro for the situations where a non-MC driver needs to
> call a state-operation (operation which takes a subdev state as a
> parameter) in try-context in another subdev.
> 
> The macro allocates a new subdev state for the called subdev and frees
> the state afterwards.
> 
> An example use case is a media platform driver testing if a
> v4l2_subdev_format would be accepted by a source subdev.
> 
> This should not be used in MC drivers.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

> ---
>  include/media/v4l2-subdev.h | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index b661e1817470..9689f38a0af1 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -1433,6 +1433,40 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
>  		__result;						\
>  	})
>  
> +/**
> + * v4l2_subdev_call_state_try - call an operation of a v4l2_subdev which
> + *				takes state as a parameter, passing the
> + *				subdev a newly allocated try 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_state_active(), except that as this
> + * version allocates a new state, this is only usable for
> + * V4L2_SUBDEV_FORMAT_TRY use cases.
> + *
> + * Note: only legacy non-MC drivers may need this macro.
> + */
> +#define v4l2_subdev_call_state_try(sd, o, f, args...)                 \
> +	({                                                            \
> +		int __result;                                         \
> +		static struct lock_class_key __key;                   \
> +		const char *name = KBUILD_BASENAME                    \
> +			":" __stringify(__LINE__) ":state->lock";     \
> +		struct v4l2_subdev_state *state =                     \
> +			__v4l2_subdev_state_alloc(sd, name, &__key);  \
> +		v4l2_subdev_lock_state(state);                        \
> +		__result = v4l2_subdev_call(sd, o, f, state, ##args); \
> +		v4l2_subdev_unlock_state(state);                      \
> +		__v4l2_subdev_state_free(state);                      \
> +		__result;                                             \
> +	})
> +
>  /**
>   * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
>   *
> -- 
> 2.34.1
>
Hans Verkuil July 4, 2022, 10:06 a.m. UTC | #2
On 7/1/22 15:15, Tomi Valkeinen wrote:
> Add a helper macro for the situations where a non-MC driver needs to
> call a state-operation (operation which takes a subdev state as a
> parameter) in try-context in another subdev.
> 
> The macro allocates a new subdev state for the called subdev and frees
> the state afterwards.
> 
> An example use case is a media platform driver testing if a
> v4l2_subdev_format would be accepted by a source subdev.
> 
> This should not be used in MC drivers.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

Thanks!

	Hans

> ---
>  include/media/v4l2-subdev.h | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index b661e1817470..9689f38a0af1 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -1433,6 +1433,40 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
>  		__result;						\
>  	})
>  
> +/**
> + * v4l2_subdev_call_state_try - call an operation of a v4l2_subdev which
> + *				takes state as a parameter, passing the
> + *				subdev a newly allocated try 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_state_active(), except that as this
> + * version allocates a new state, this is only usable for
> + * V4L2_SUBDEV_FORMAT_TRY use cases.
> + *
> + * Note: only legacy non-MC drivers may need this macro.
> + */
> +#define v4l2_subdev_call_state_try(sd, o, f, args...)                 \
> +	({                                                            \
> +		int __result;                                         \
> +		static struct lock_class_key __key;                   \
> +		const char *name = KBUILD_BASENAME                    \
> +			":" __stringify(__LINE__) ":state->lock";     \
> +		struct v4l2_subdev_state *state =                     \
> +			__v4l2_subdev_state_alloc(sd, name, &__key);  \
> +		v4l2_subdev_lock_state(state);                        \
> +		__result = v4l2_subdev_call(sd, o, f, state, ##args); \
> +		v4l2_subdev_unlock_state(state);                      \
> +		__v4l2_subdev_state_free(state);                      \
> +		__result;                                             \
> +	})
> +
>  /**
>   * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
>   *
Marek Vasut July 10, 2022, 1:50 a.m. UTC | #3
On 7/1/22 15:15, Tomi Valkeinen wrote:
> Add a helper macro for the situations where a non-MC driver needs to
> call a state-operation (operation which takes a subdev state as a
> parameter) in try-context in another subdev.
> 
> The macro allocates a new subdev state for the called subdev and frees
> the state afterwards.
> 
> An example use case is a media platform driver testing if a
> v4l2_subdev_format would be accepted by a source subdev.
> 
> This should not be used in MC drivers.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

Tested-by: Marek Vasut <marex@denx.de>
diff mbox series

Patch

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index b661e1817470..9689f38a0af1 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1433,6 +1433,40 @@  extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers;
 		__result;						\
 	})
 
+/**
+ * v4l2_subdev_call_state_try - call an operation of a v4l2_subdev which
+ *				takes state as a parameter, passing the
+ *				subdev a newly allocated try 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_state_active(), except that as this
+ * version allocates a new state, this is only usable for
+ * V4L2_SUBDEV_FORMAT_TRY use cases.
+ *
+ * Note: only legacy non-MC drivers may need this macro.
+ */
+#define v4l2_subdev_call_state_try(sd, o, f, args...)                 \
+	({                                                            \
+		int __result;                                         \
+		static struct lock_class_key __key;                   \
+		const char *name = KBUILD_BASENAME                    \
+			":" __stringify(__LINE__) ":state->lock";     \
+		struct v4l2_subdev_state *state =                     \
+			__v4l2_subdev_state_alloc(sd, name, &__key);  \
+		v4l2_subdev_lock_state(state);                        \
+		__result = v4l2_subdev_call(sd, o, f, state, ##args); \
+		v4l2_subdev_unlock_state(state);                      \
+		__v4l2_subdev_state_free(state);                      \
+		__result;                                             \
+	})
+
 /**
  * v4l2_subdev_has_op - Checks if a subdev defines a certain operation.
  *