From patchwork Thu Nov 1 23:31:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10664747 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 CFBDB13B5 for ; Thu, 1 Nov 2018 23:33:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C19F62C43C for ; Thu, 1 Nov 2018 23:33:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B584F2C519; Thu, 1 Nov 2018 23:33:07 +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 54CC32C451 for ; Thu, 1 Nov 2018 23:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728325AbeKBIiK (ORCPT ); Fri, 2 Nov 2018 04:38:10 -0400 Received: from bin-mail-out-06.binero.net ([195.74.38.229]:13784 "EHLO bin-mail-out-06.binero.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728296AbeKBIiJ (ORCPT ); Fri, 2 Nov 2018 04:38:09 -0400 X-Halon-ID: 75c4e938-de2e-11e8-9adf-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 75c4e938-de2e-11e8-9adf-005056917a89; Fri, 02 Nov 2018 00:32:56 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Laurent Pinchart , Sakari Ailus , Benoit Parrot , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org Subject: [PATCH v2 15/30] media: entity: Look for indirect routes Date: Fri, 2 Nov 2018 00:31:29 +0100 Message-Id: <20181101233144.31507-16-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181101233144.31507-1-niklas.soderlund+renesas@ragnatech.se> References: <20181101233144.31507-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 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 Reviewed-by: Niklas Söderlund --- 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 42977634d7102852..e45fc2549017615a 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);