Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp931978rwb; Thu, 15 Dec 2022 04:31:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXsRGLWKmYyrjUmYephtdo9N5HqGW86rxke1ItfgE+X9OdV0hnasI6kcn1+SZaQiWClye6Sn X-Received: by 2002:a05:6a20:171b:b0:af:9538:ec5f with SMTP id bn27-20020a056a20171b00b000af9538ec5fmr2153921pzb.38.1671107482885; Thu, 15 Dec 2022 04:31:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671107482; cv=none; d=google.com; s=arc-20160816; b=q1Mts05G/TDe8Reo4Jn5BHFpBQW2DZSMuBjSIcp3FozcOBZyKPypMI2D7btZiwLGO7 zPhLP6sZOSB3/6gCoY6JSRbhs8A5hlcGLKGolXo8hCCzmWZTscfA3XfRG4bguTFdRFBj N9cTrVepqA0lSnxbRuPzLhD29i52zSduifp7/y10l6bQaMivkiNBfwDvN7w4hS21AoLe /V9doWBaX/KTsF0Yx4R+co4TwSE8JjIeQv+qvsjmvtVFhEVE+MeJ9I4VO2nD8IC+d0xO 2UvvKWUIGW3tEuiBxwCkyh9j8psDGNBPtJYbmTqRUoOGXqODuX72a+1Etun4V0kvS2Hl 0sXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5UwCjwBwEpCds6OJdhLnzBFVcG4ZLT/sVz1UfWPxEKk=; b=w0xHAHccmOwVKQtAKecpTAUOEklpgN0GDS2NlgsOMn0xd3EOhlN0WJPzD5C1rLCKny eiCZRk4eFXWuojGAwsLk/AHN1Sk1e0g6TFVWAvkxxtvtx8I19D8iXEcImmdS8ZD6ESUc 6EvaFe+Gf5NIpPQ58wNqwTbNMrVUkMp/Su2G9XUmmNzWrRVeG7avEAjpq/x93xEHBImA Nk4XvqvkDfEpxfIrwzDHWQurEe1p7O72EbOH97B49UtwLecIVzCbcYLI1Zi/LJY9rjao ETgxteU79uigd3neeOyhgxZ6zmlSNuBKUsCqIQVVI4LEd1uPUMqmPns2oVYyvlvb58We YwDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Yj4npORT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020a170902c3c500b001782a6fbc7csi5285424plj.463.2022.12.15.04.31.13; Thu, 15 Dec 2022 04:31:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Yj4npORT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbiLOMSi (ORCPT + 68 others); Thu, 15 Dec 2022 07:18:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230250AbiLOMRf (ORCPT ); Thu, 15 Dec 2022 07:17:35 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EACA52ED5C; Thu, 15 Dec 2022 04:17:30 -0800 (PST) Received: from desky.lan (91-154-32-225.elisa-laajakaista.fi [91.154.32.225]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F2EC618A2; Thu, 15 Dec 2022 13:17:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671106640; bh=fzxb+bO63Dt2iOrVRGhxqtzB/aQqDw1PMvkN2JkYKHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yj4npORTwjYj2w7N0I8FQomdWFDgDXty9ykZC3YvZ0VvClfiyu9dCODIMC/2RDY+E Cm570JgPIyFX6qbwY1C/hCRqIgrnVwy3vbb03Gn5dq9RpokaTM1JKF6E3nSkPW+IP1 +oJ8Ecg3Stx5xGPzXe6WEI0+5Ip6uE+0KDzADaW0= From: Tomi Valkeinen To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, sakari.ailus@linux.intel.com, Jacopo Mondi , Laurent Pinchart , niklas.soderlund+renesas@ragnatech.se, Mauro Carvalho Chehab , Hans Verkuil , satish.nagireddy@getcruise.com, Tomasz Figa Cc: Tomi Valkeinen Subject: [PATCH v16 17/20] media: v4l2-subdev: Add v4l2_subdev_state_xlate_streams() helper Date: Thu, 15 Dec 2022 14:16:31 +0200 Message-Id: <20221215121634.287100-18-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221215121634.287100-1-tomi.valkeinen@ideasonboard.com> References: <20221215121634.287100-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Laurent Pinchart Add a helper function to translate streams between two pads of a subdev, using the subdev's internal routing table. Signed-off-by: Laurent Pinchart Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 26 ++++++++++++++++++++++++++ include/media/v4l2-subdev.h | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index f775b7980de1..d9ece0fd1b75 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1598,6 +1598,32 @@ v4l2_subdev_state_get_opposite_stream_format(struct v4l2_subdev_state *state, } EXPORT_SYMBOL_GPL(v4l2_subdev_state_get_opposite_stream_format); +u64 v4l2_subdev_state_xlate_streams(const struct v4l2_subdev_state *state, + u32 pad0, u32 pad1, u64 *streams) +{ + const struct v4l2_subdev_krouting *routing = &state->routing; + struct v4l2_subdev_route *route; + u64 streams0 = 0; + u64 streams1 = 0; + + for_each_active_route(routing, route) { + if (route->sink_pad == pad0 && route->source_pad == pad1 && + (*streams & BIT_ULL(route->sink_stream))) { + streams0 |= BIT_ULL(route->sink_stream); + streams1 |= BIT_ULL(route->source_stream); + } + if (route->source_pad == pad0 && route->sink_pad == pad1 && + (*streams & BIT_ULL(route->source_stream))) { + streams0 |= BIT_ULL(route->source_stream); + streams1 |= BIT_ULL(route->sink_stream); + } + } + + *streams = streams0; + return streams1; +} +EXPORT_SYMBOL_GPL(v4l2_subdev_state_xlate_streams); + int v4l2_subdev_routing_validate(struct v4l2_subdev *sd, const struct v4l2_subdev_krouting *routing, enum v4l2_subdev_routing_restriction disallow) diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 6661887536bf..8c002d65e08e 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1579,6 +1579,29 @@ struct v4l2_mbus_framefmt * v4l2_subdev_state_get_opposite_stream_format(struct v4l2_subdev_state *state, u32 pad, u32 stream); +/** + * v4l2_subdev_state_xlate_streams() - Translate streams from one pad to another + * + * @state: Subdevice state + * @pad0: The first pad + * @pad1: The second pad + * @streams: Streams bitmask on the first pad + * + * Streams on sink pads of a subdev are routed to source pads as expressed in + * the subdev state routing table. Stream numbers don't necessarily match on + * the sink and source side of a route. This function translates stream numbers + * on @pad0, expressed as a bitmask in @streams, to the corresponding streams + * on @pad1 using the routing table from the @state. It returns the stream mask + * on @pad1, and updates @streams with the streams that have been found in the + * routing table. + * + * @pad0 and @pad1 must be a sink and a source, in any order. + * + * Return: The bitmask of streams of @pad1 that are routed to @streams on @pad0. + */ +u64 v4l2_subdev_state_xlate_streams(const struct v4l2_subdev_state *state, + u32 pad0, u32 pad1, u64 *streams); + /** * enum v4l2_subdev_routing_restriction - Subdevice internal routing restrictions * -- 2.34.1