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
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Subject: [PATCH v6 23/24] v4l: subdev: Take routing information into account in link validation
Date: Tue, 27 Apr 2021 15:45:22 +0300	[thread overview]
Message-ID: <20210427124523.990938-24-tomi.valkeinen@ideasonboard.com> (raw)
In-Reply-To: <20210427124523.990938-1-tomi.valkeinen@ideasonboard.com>

The routing information is essential in link validation for multiplexed
links: the pads at the ends of a multiplexed link have no single format
defined for them. Instead, the format is accessible in the sink (or
source) pads of the sub-devices at both ends of that link.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 144 +++++++++++++++++++++++++-
 1 file changed, 142 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index f08847341a6b..2dd78a293b03 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1096,14 +1096,154 @@ int v4l2_subdev_get_format_dir(struct media_pad *pad, u16 stream,
 }
 EXPORT_SYMBOL_GPL(v4l2_subdev_get_format_dir);
 
+static int v4l2_subdev_link_validate_routing_stream(
+	struct media_link *link, struct media_pad *sink_pad, u16 sink_stream,
+	struct media_pad *source_pad, u16 source_stream)
+{
+	struct v4l2_subdev_format source_fmt;
+	struct v4l2_subdev_format sink_fmt;
+	struct v4l2_subdev *sink_sd;
+	int ret;
+
+	ret = v4l2_subdev_get_format_dir(sink_pad, sink_stream,
+					 V4L2_DIR_SINKWARD, &sink_fmt);
+	if (ret)
+		return ret;
+
+	ret = v4l2_subdev_get_format_dir(source_pad, source_stream,
+					 V4L2_DIR_SOURCEWARD, &source_fmt);
+	if (ret)
+		return ret;
+
+	sink_sd = media_entity_to_v4l2_subdev(sink_pad->entity);
+
+	ret = v4l2_subdev_call(sink_sd, pad, link_validate, link, &source_fmt,
+			       &sink_fmt);
+	if (ret != -ENOIOCTLCMD)
+		return ret;
+
+	ret = v4l2_subdev_link_validate_default(sink_sd, link, &source_fmt,
+						&sink_fmt);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int v4l2_subdev_link_validate_routing(struct media_link *link)
+{
+	int ret;
+	unsigned int i, j;
+
+	struct route_info {
+		struct v4l2_subdev_krouting routing;
+		struct media_pad *pad;
+		struct v4l2_subdev *subdev;
+	};
+
+	struct route_info source_route_info = {
+		.pad = link->source,
+		.subdev = media_entity_to_v4l2_subdev(link->source->entity),
+	};
+
+	struct route_info sink_route_info = {
+		.pad = link->sink,
+		.subdev = media_entity_to_v4l2_subdev(link->sink->entity),
+	};
+
+	struct device *dev = sink_route_info.subdev->entity.graph_obj.mdev->dev;
+
+	dev_dbg(dev, "validating link \"%s\":%u -> \"%s\":%u\n",
+		link->source->entity->name, link->source->index,
+		link->sink->entity->name, link->sink->index);
+
+	ret = v4l2_subdev_get_krouting(source_route_info.subdev,
+				       &source_route_info.routing);
+	if (ret)
+		return ret;
+
+	ret = v4l2_subdev_get_krouting(sink_route_info.subdev,
+				       &sink_route_info.routing);
+	if (ret) {
+		v4l2_subdev_free_routing(&source_route_info.routing);
+		return ret;
+	}
+
+	/*
+	 * Every active sink route needs an active source route, but it's ok
+	 * to have active source routes without matching sink route.
+	 */
+	for (i = 0; i < sink_route_info.routing.num_routes; ++i) {
+		struct v4l2_subdev_route *sink_route =
+			&sink_route_info.routing.routes[i];
+
+		if (!(sink_route->flags & V4L2_SUBDEV_ROUTE_FL_ACTIVE))
+			continue;
+
+		if (sink_route->sink_pad != sink_route_info.pad->index)
+			continue;
+
+		for (j = 0; j < source_route_info.routing.num_routes; ++j) {
+			struct v4l2_subdev_route *source_route =
+				&source_route_info.routing.routes[j];
+
+			if (!(source_route->flags &
+			      V4L2_SUBDEV_ROUTE_FL_ACTIVE))
+				continue;
+
+			if (source_route->source_pad !=
+			    source_route_info.pad->index)
+				continue;
+
+			if (source_route->source_stream !=
+			    sink_route->sink_stream)
+				continue;
+
+			ret = v4l2_subdev_link_validate_routing_stream(
+				link,
+				&sink_route_info.pad->entity
+					 ->pads[sink_route->sink_pad],
+				sink_route->sink_stream,
+				&source_route_info.pad->entity
+					 ->pads[source_route->source_pad],
+				source_route->source_stream);
+			if (ret)
+				goto out;
+
+			break;
+		}
+
+		if (j == source_route_info.routing.num_routes) {
+			dev_err(dev,
+				"%s: no active source route found for sink route '%s':%u:%u\n",
+				__func__, sink_route_info.pad->entity->name,
+				sink_route->sink_pad, sink_route->sink_stream);
+			ret = -EINVAL;
+			goto out;
+		}
+	}
+
+out:
+	v4l2_subdev_free_routing(&source_route_info.routing);
+	v4l2_subdev_free_routing(&sink_route_info.routing);
+
+	return ret;
+}
+
 int v4l2_subdev_link_validate(struct media_link *link)
 {
 	struct v4l2_subdev *sink;
 	struct v4l2_subdev_format sink_fmt, source_fmt;
 	int rval;
 
-	rval = v4l2_subdev_link_validate_get_format(
-		link->source, &source_fmt);
+	if (WARN_ON((link->source->flags & MEDIA_PAD_FL_MULTIPLEXED) !=
+		    (link->sink->flags & MEDIA_PAD_FL_MULTIPLEXED)))
+		return -EINVAL;
+
+	if (link->source->flags & MEDIA_PAD_FL_MULTIPLEXED)
+		return v4l2_subdev_link_validate_routing(link);
+
+	rval = v4l2_subdev_link_validate_get_format(link->source, &source_fmt);
 	if (rval < 0)
 		return 0;
 
-- 
2.25.1


  parent reply	other threads:[~2021-04-27 12:46 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27 12:44 [PATCH v6 00/24] v4l: subdev internal routing Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 01/24] media: entity: Use pad as a starting point for graph walk Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 02/24] media: entity: Use pads instead of entities in the media graph walk stack Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 03/24] media: entity: Walk the graph based on pads Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 04/24] v4l: mc: Start walk from a specific pad in use count calculation Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 05/24] media: entity: Add iterator helper for entity pads Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 06/24] media: entity: Move the pipeline from entity to pads Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 07/24] media: entity: Use pad as the starting point for a pipeline Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 08/24] media: entity: Add has_route entity operation Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 09/24] media: entity: Add media_entity_has_route() function Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 10/24] media: entity: Use routing information during graph traversal Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 11/24] media: entity: Skip link validation for pads to which there is no route to Tomi Valkeinen
2021-04-29  2:30   ` Laurent Pinchart
2021-04-27 12:45 ` [PATCH v6 12/24] media: entity: Add an iterator helper for connected pads Tomi Valkeinen
2021-04-29  2:18   ` Laurent Pinchart
2021-05-04  6:53     ` Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 13/24] media: entity: Add only connected pads to the pipeline Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 14/24] media: entity: Add debug information in graph walk route check Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 15/24] v4l: Add bus type to frame descriptors Tomi Valkeinen
2021-04-29  2:46   ` Laurent Pinchart
2021-04-27 12:45 ` [PATCH v6 16/24] v4l: Add CSI-2 bus configuration " Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 17/24] v4l: Add stream to frame descriptor Tomi Valkeinen
2021-04-29  2:50   ` Laurent Pinchart
2021-04-27 12:45 ` [PATCH v6 18/24] v4l: subdev: Add [GS]_ROUTING subdev ioctls and operations Tomi Valkeinen
2021-04-29  2:28   ` Laurent Pinchart
2021-04-29  6:15     ` Tomi Valkeinen
2021-05-04  7:04     ` Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 19/24] media: Documentation: Add GS_ROUTING documentation Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 20/24] v4l: subdev: routing kernel helper functions Tomi Valkeinen
2021-04-29  3:46   ` Laurent Pinchart
2021-04-27 12:45 ` [PATCH v6 21/24] v4l: subdev: add v4l2_subdev_get_format_dir() Tomi Valkeinen
2021-04-27 12:45 ` [PATCH v6 22/24] media: uapi: add MEDIA_PAD_FL_MULTIPLEXED flag Tomi Valkeinen
2021-04-29  2:53   ` Laurent Pinchart
2021-04-27 12:45 ` Tomi Valkeinen [this message]
2021-04-27 12:45 ` [PATCH v6 24/24] v4l: subdev: increase V4L2_FRAME_DESC_ENTRY_MAX to 8 Tomi Valkeinen
2021-04-29 10:28 ` [PATCH v6 00/24] v4l: subdev internal routing 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=20210427124523.990938-24-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=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.