From patchwork Thu Aug 23 13:25:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10573869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94AA5139B for ; Thu, 23 Aug 2018 13:28:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D4862B72C for ; Thu, 23 Aug 2018 13:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81EF22BDF5; Thu, 23 Aug 2018 13:28:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2581C2B72C for ; Thu, 23 Aug 2018 13:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730682AbeHWQ54 (ORCPT ); Thu, 23 Aug 2018 12:57:56 -0400 Received: from vsp-unauthed02.binero.net ([195.74.38.227]:12316 "EHLO vsp-unauthed02.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730718AbeHWQ5z (ORCPT ); Thu, 23 Aug 2018 12:57:55 -0400 X-Halon-ID: 61c61fb8-a6d8-11e8-8edf-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 61c61fb8-a6d8-11e8-8edf-005056917f90; Thu, 23 Aug 2018 15:28:12 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Laurent Pinchart , Sakari Ailus , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org Subject: [PATCH 15/30] media: entity: Look for indirect routes Date: Thu, 23 Aug 2018 15:25:29 +0200 Message-Id: <20180823132544.521-16-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180823132544.521-1-niklas.soderlund+renesas@ragnatech.se> References: <20180823132544.521-1-niklas.soderlund+renesas@ragnatech.se> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sakari Ailus Two pads are considered having an active route for the purpose of has_route() if an indirect active route can be found between the two pads. An simple example of this is that a source pad has an active route to another source pad if both of the pads have an active route to the same sink pad. Make media_entity_has_route() return true in that case, and do not rely on drivers performing this by themselves. Signed-off-by: Sakari Ailus --- drivers/media/media-entity.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index 3912bc75651fe0b7..29e732a130667ae9 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -240,6 +240,9 @@ EXPORT_SYMBOL_GPL(media_entity_pads_init); bool media_entity_has_route(struct media_entity *entity, unsigned int pad0, unsigned int pad1) { + unsigned int i; + bool has_route; + if (pad0 >= entity->num_pads || pad1 >= entity->num_pads) return false; @@ -253,7 +256,34 @@ bool media_entity_has_route(struct media_entity *entity, unsigned int pad0, && entity->pads[pad1].flags & MEDIA_PAD_FL_SINK) swap(pad0, pad1); - return entity->ops->has_route(entity, pad0, pad1); + has_route = entity->ops->has_route(entity, pad0, pad1); + /* A direct route is returned immediately */ + if (has_route || + (entity->pads[pad0].flags & MEDIA_PAD_FL_SINK && + entity->pads[pad1].flags & MEDIA_PAD_FL_SOURCE)) + return true; + + /* Look for indirect routes */ + for (i = 0; i < entity->num_pads; i++) { + if (i == pad0 || i == pad1) + continue; + + /* + * There are no direct routes between same types of + * pads, so skip checking this route + */ + if (!((entity->pads[pad0].flags ^ entity->pads[i].flags) & + (MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_SINK))) + continue; + + /* Is there an indirect route? */ + if (entity->ops->has_route(entity, i, pad0) && + entity->ops->has_route(entity, i, pad1)) + return true; + } + + return false; + } EXPORT_SYMBOL_GPL(media_entity_has_route);