[v14,21/34] media: subdev: add v4l2_subdev_has_pad_interdep()
Commit Message
Add a v4l2_subdev_has_pad_interdep() helper function which can be used
for media_entity_operations.has_pad_interdep op.
It considers two pads interdependent if there is an active route between
pad0 and pad1.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
drivers/media/v4l2-core/v4l2-subdev.c | 31 +++++++++++++++++++++++++++
include/media/v4l2-subdev.h | 17 +++++++++++++++
2 files changed, 48 insertions(+)
Comments
Moi,
On Wed, Aug 31, 2022 at 05:13:44PM +0300, Tomi Valkeinen wrote:
> Add a v4l2_subdev_has_pad_interdep() helper function which can be used
> for media_entity_operations.has_pad_interdep op.
>
> It considers two pads interdependent if there is an active route between
> pad0 and pad1.
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
> drivers/media/v4l2-core/v4l2-subdev.c | 31 +++++++++++++++++++++++++++
> include/media/v4l2-subdev.h | 17 +++++++++++++++
> 2 files changed, 48 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index af1f53d99507..1ce9a7dc0c6e 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -1045,6 +1045,37 @@ int v4l2_subdev_link_validate(struct media_link *link)
> }
> EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate);
>
> +bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
> + unsigned int pad0, unsigned int pad1)
> +{
> + struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
> + struct v4l2_subdev_krouting *routing;
> + unsigned int i;
> + struct v4l2_subdev_state *state;
Please declare i after state.
> +
> + state = v4l2_subdev_lock_and_get_active_state(sd);
> +
> + routing = &state->routing;
> +
> + for (i = 0; i < routing->num_routes; ++i) {
> + struct v4l2_subdev_route *route = &routing->routes[i];
> +
> + if (!(route->flags & V4L2_SUBDEV_ROUTE_FL_ACTIVE))
> + continue;
> +
> + if ((route->sink_pad == pad0 && route->source_pad == pad1) ||
> + (route->source_pad == pad0 && route->sink_pad == pad1)) {
> + v4l2_subdev_unlock_state(state);
> + return true;
> + }
> + }
> +
> + v4l2_subdev_unlock_state(state);
> +
> + return false;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_subdev_has_pad_interdep);
> +
> struct v4l2_subdev_state *
> __v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name,
> struct lock_class_key *lock_key)
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index f38943932cfe..2d1509556ce0 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -1235,6 +1235,23 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
> */
> int v4l2_subdev_link_validate(struct media_link *link);
>
> +/**
> + * v4l2_subdev_has_pad_interdep - MC has_pad_interdep implementation for subdevs
> + *
> + * @entity: pointer to &struct media_entity
> + * @pad0: pad number for the first pad
> + * @pad1: pad number for the second pad
> + *
> + * This function is an implementation of the media_entity_operations.has_pad_interdep
Please run
$ scripts/checkpatch.pl --strict --max-line-length=80
on this.
> + * operation for subdevs that implement the multiplexed streams API (as
> + * indicated by the V4L2_SUBDEV_FL_STREAMS subdev flag).
> + *
> + * It considers two pads interdependent if there is an active route between pad0
> + * and pad1.
> + */
> +bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
> + unsigned int pad0, unsigned int pad1);
> +
> /**
> * __v4l2_subdev_state_alloc - allocate v4l2_subdev_state
> *
@@ -1045,6 +1045,37 @@ int v4l2_subdev_link_validate(struct media_link *link)
}
EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate);
+bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
+ unsigned int pad0, unsigned int pad1)
+{
+ struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
+ struct v4l2_subdev_krouting *routing;
+ unsigned int i;
+ struct v4l2_subdev_state *state;
+
+ state = v4l2_subdev_lock_and_get_active_state(sd);
+
+ routing = &state->routing;
+
+ for (i = 0; i < routing->num_routes; ++i) {
+ struct v4l2_subdev_route *route = &routing->routes[i];
+
+ if (!(route->flags & V4L2_SUBDEV_ROUTE_FL_ACTIVE))
+ continue;
+
+ if ((route->sink_pad == pad0 && route->source_pad == pad1) ||
+ (route->source_pad == pad0 && route->sink_pad == pad1)) {
+ v4l2_subdev_unlock_state(state);
+ return true;
+ }
+ }
+
+ v4l2_subdev_unlock_state(state);
+
+ return false;
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_has_pad_interdep);
+
struct v4l2_subdev_state *
__v4l2_subdev_state_alloc(struct v4l2_subdev *sd, const char *lock_name,
struct lock_class_key *lock_key)
@@ -1235,6 +1235,23 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
*/
int v4l2_subdev_link_validate(struct media_link *link);
+/**
+ * v4l2_subdev_has_pad_interdep - MC has_pad_interdep implementation for subdevs
+ *
+ * @entity: pointer to &struct media_entity
+ * @pad0: pad number for the first pad
+ * @pad1: pad number for the second pad
+ *
+ * This function is an implementation of the media_entity_operations.has_pad_interdep
+ * operation for subdevs that implement the multiplexed streams API (as
+ * indicated by the V4L2_SUBDEV_FL_STREAMS subdev flag).
+ *
+ * It considers two pads interdependent if there is an active route between pad0
+ * and pad1.
+ */
+bool v4l2_subdev_has_pad_interdep(struct media_entity *entity,
+ unsigned int pad0, unsigned int pad1);
+
/**
* __v4l2_subdev_state_alloc - allocate v4l2_subdev_state
*