From patchwork Tue Dec 20 14:36:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 635534 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00EB0C3DA6E for ; Tue, 20 Dec 2022 14:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234035AbiLTOhE (ORCPT ); Tue, 20 Dec 2022 09:37:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233881AbiLTOgs (ORCPT ); Tue, 20 Dec 2022 09:36:48 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F60BAC for ; Tue, 20 Dec 2022 06:36:47 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7BDA356D; Tue, 20 Dec 2022 15:36:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671547005; bh=j5f0IG+PJIhceiA/3r8lRcq2vcxoloztWn9ZsRHa8+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kuzr9VRcUs+n7M9VRsfYG8HmRwdM9BLfAd5e/KwhVENWV/qMXlWQVG9xPbtNMB/7x DtHhcZF8lVasbb5CKnsqrK1zahYVslvAerBOyiunnlH2exk0T+f8JROS0sK8LQykOc W/0Shc0w+tTN1txpgCJYCkGqy+Z+m0ctjb3tOn1U= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Sakari Ailus , Tomi Valkeinen , Michal Simek , Sylwester Nawrocki Subject: [PATCH v2 1/5] media: mc: entity: Add pad iterator for media_pipeline Date: Tue, 20 Dec 2022 16:36:35 +0200 Message-Id: <20221220143639.764-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20221220143639.764-1-laurent.pinchart@ideasonboard.com> References: <20221220143639.764-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a media_pipeline_for_each_pad() macro to iterate over pads in a pipeline. This should be used by driver as a replacement of the media_graph_walk API, as iterating over the media_pipeline uses the cached list of pads and is thus more efficient. Signed-off-by: Laurent Pinchart --- drivers/media/mc/mc-entity.c | 18 ++++++++++++++++++ include/media/media-entity.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index b8bcbc734eaf..70df2050951c 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -932,6 +932,24 @@ __must_check int media_pipeline_alloc_start(struct media_pad *pad) } EXPORT_SYMBOL_GPL(media_pipeline_alloc_start); +struct media_pad * +__media_pipeline_pad_iter_next(struct media_pipeline *pipe, + struct media_pipeline_pad_iter *iter, + struct media_pad *pad) +{ + if (!pad) + iter->cursor = pipe->pads.next; + + if (iter->cursor == &pipe->pads) + return NULL; + + pad = list_entry(iter->cursor, struct media_pipeline_pad, list)->pad; + iter->cursor = iter->cursor->next; + + return pad; +} +EXPORT_SYMBOL_GPL(__media_pipeline_pad_iter_next); + /* ----------------------------------------------------------------------------- * Links management */ diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 85ed08ddee9d..e881e483b550 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -130,6 +130,15 @@ struct media_pipeline_pad { struct media_pad *pad; }; +/** + * struct media_pipeline_pad_iter - Iterator for media_pipeline_for_each_pad + * + * @cursor: The current element + */ +struct media_pipeline_pad_iter { + struct list_head *cursor; +}; + /** * struct media_link - A link object part of a media graph. * @@ -1163,6 +1172,26 @@ void media_pipeline_stop(struct media_pad *pad); */ void __media_pipeline_stop(struct media_pad *pad); +struct media_pad * +__media_pipeline_pad_iter_next(struct media_pipeline *pipe, + struct media_pipeline_pad_iter *iter, + struct media_pad *pad); + +/** + * media_pipeline_for_each_pad - Iterate on all pads in a media pipeline + * @pipe: The pipeline + * @iter: The iterator (struct media_pipeline_pad_iter) + * @pad: The iterator pad + * + * Iterate on all pads in a media pipeline. This is only valid after the + * pipeline has been built with media_pipeline_start() and before it gets + * destroyed with media_pipeline_stop(). + */ +#define media_pipeline_for_each_pad(pipe, iter, pad) \ + for (pad = __media_pipeline_pad_iter_next((pipe), iter, NULL); \ + pad != NULL; \ + pad = __media_pipeline_pad_iter_next((pipe), iter, pad)) + /** * media_pipeline_alloc_start - Mark a pipeline as streaming * @pad: Starting pad From patchwork Tue Dec 20 14:36:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 635533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE9CFC4167B for ; Tue, 20 Dec 2022 14:37:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbiLTOhH (ORCPT ); Tue, 20 Dec 2022 09:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234118AbiLTOhB (ORCPT ); Tue, 20 Dec 2022 09:37:01 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC460DF41 for ; Tue, 20 Dec 2022 06:36:52 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5CF9C824; Tue, 20 Dec 2022 15:36:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671547011; bh=Fb7MdxaJgeTT0M/4OXoCGOHM2BX75ZiaDp5rK0PuQ3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wozuu6LaI2dkU4a5kHB5SP2+neeeduSRNAi+C4n+BoWh3hqK1z2GCl3qPK61r02BB 5oMMmEXmFTVZq+8OtgGFB4KTN9uc4OdHKrjJb/MiPlBPExpy2N5oR/CGpHj1jZ61nz uWs3fW4YJ7sRYu0YLetnpBeF9cqrcXtI3H+VRl9Q= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Sakari Ailus , Tomi Valkeinen , Michal Simek , Sylwester Nawrocki Subject: [PATCH v2 3/5] media: ti: omap3isp: Use media_pipeline_for_each_entity() Date: Tue, 20 Dec 2022 16:36:37 +0200 Message-Id: <20221220143639.764-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20221220143639.764-1-laurent.pinchart@ideasonboard.com> References: <20221220143639.764-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Replace usage of the deprecated media graph walk API with the new media_pipeline_for_each_entity() macro. Signed-off-by: Laurent Pinchart --- Changes since v1: - Initialize and cleanup the iterator --- drivers/media/platform/ti/omap3isp/ispvideo.c | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/ti/omap3isp/ispvideo.c b/drivers/media/platform/ti/omap3isp/ispvideo.c index 3e5348c63773..f1eeca36674f 100644 --- a/drivers/media/platform/ti/omap3isp/ispvideo.c +++ b/drivers/media/platform/ti/omap3isp/ispvideo.c @@ -221,22 +221,16 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad) static int isp_video_get_graph_data(struct isp_video *video, struct isp_pipeline *pipe) { - struct media_graph graph; - struct media_entity *entity = &video->video.entity; - struct media_device *mdev = entity->graph_obj.mdev; + struct media_pipeline_entity_iter iter; + struct media_entity *entity; struct isp_video *far_end = NULL; int ret; - mutex_lock(&mdev->graph_mutex); - ret = media_graph_walk_init(&graph, mdev); - if (ret) { - mutex_unlock(&mdev->graph_mutex); + ret = media_pipeline_entity_iter_init(&pipe->pipe, &iter); + if (ret) return ret; - } - media_graph_walk_start(&graph, entity); - - while ((entity = media_graph_walk_next(&graph))) { + media_pipeline_for_each_entity(&pipe->pipe, &iter, entity) { struct isp_video *__video; media_entity_enum_set(&pipe->ent_enum, entity); @@ -255,9 +249,7 @@ static int isp_video_get_graph_data(struct isp_video *video, far_end = __video; } - mutex_unlock(&mdev->graph_mutex); - - media_graph_walk_cleanup(&graph); + media_pipeline_entity_iter_init(&iter); if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { pipe->input = far_end; From patchwork Tue Dec 20 14:36:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 635532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AA70C10F1E for ; Tue, 20 Dec 2022 14:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234090AbiLTOhP (ORCPT ); Tue, 20 Dec 2022 09:37:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234089AbiLTOhI (ORCPT ); Tue, 20 Dec 2022 09:37:08 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF636BB4 for ; Tue, 20 Dec 2022 06:36:58 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B0755886; Tue, 20 Dec 2022 15:36:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1671547012; bh=gWpjx1PzNfWrMuBSryKJatFh2V6ZhBNjf1kERFSwlNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h7PGcfe/G17zxUPSHTCLszt9QVOEE1rzWi6Mve6rc/2AwBuyb3IiAn972uFBhdiHF HJlwnOPkPg/zDYUkzA5V/J0RjS4k/Tzyfhef1Ok+rMSoYhsNGKKd7cTwOk4QGrBDv5 hE8IIYPu+j9uX0/ftI/edxWsityKZMXg8EtzBIZs= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Sakari Ailus , Tomi Valkeinen , Michal Simek , Sylwester Nawrocki Subject: [PATCH v2 4/5] media: ti: omap4iss: Use media_pipeline_for_each_entity() Date: Tue, 20 Dec 2022 16:36:38 +0200 Message-Id: <20221220143639.764-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20221220143639.764-1-laurent.pinchart@ideasonboard.com> References: <20221220143639.764-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Replace usage of the deprecated media graph walk API with the new media_pipeline_for_each_entity() and media_pipeline_for_each_pad() macros. Even though the entity iterator may seem a better match when build the entity bitmap in iss_video_stream(), it would not be more efficient as it would still iterate internally over all pads. As the entity iterator requires explicit iterator initialization and cleanup calls, the code would be more complex. Signed-off-by: Laurent Pinchart --- Changes since v1: - Initialize and cleanup the iterator - Use pad iterator in iss_video_streamon() --- drivers/staging/media/omap4iss/iss_video.c | 62 ++++++++-------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c index 0ad70faa9ba0..6b5022808618 100644 --- a/drivers/staging/media/omap4iss/iss_video.c +++ b/drivers/staging/media/omap4iss/iss_video.c @@ -201,39 +201,34 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad) /* Return a pointer to the ISS video instance at the far end of the pipeline. */ static struct iss_video * -iss_video_far_end(struct iss_video *video) +iss_video_far_end(struct iss_video *video, struct iss_pipeline *pipe) { - struct media_graph graph; - struct media_entity *entity = &video->video.entity; - struct media_device *mdev = entity->graph_obj.mdev; + struct media_pipeline_entity_iter iter; + struct media_entity *entity; struct iss_video *far_end = NULL; + int ret; - mutex_lock(&mdev->graph_mutex); + ret = media_pipeline_entity_iter_init(&pipe->pipe, &iter); + if (ret) + return ret; - if (media_graph_walk_init(&graph, mdev)) { - mutex_unlock(&mdev->graph_mutex); - return NULL; - } + media_pipeline_for_each_entity(&pipe->pipe, &iter, entity) { + struct iss_video *other; - media_graph_walk_start(&graph, entity); - - while ((entity = media_graph_walk_next(&graph))) { if (entity == &video->video.entity) continue; if (!is_media_entity_v4l2_video_device(entity)) continue; - far_end = to_iss_video(media_entity_to_video_device(entity)); - if (far_end->type != video->type) + other = to_iss_video(media_entity_to_video_device(entity)); + if (other->type != video->type) { + far_end = other; break; - - far_end = NULL; + } } - mutex_unlock(&mdev->graph_mutex); - - media_graph_walk_cleanup(&graph); + media_pipeline_entity_iter_cleanup(&iter); return far_end; } @@ -850,12 +845,12 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) { struct iss_video_fh *vfh = to_iss_video_fh(fh); struct iss_video *video = video_drvdata(file); - struct media_graph graph; - struct media_entity *entity = &video->video.entity; - struct media_device *mdev = entity->graph_obj.mdev; + struct media_device *mdev = video->video.entity.graph_obj.mdev; + struct media_pipeline_pad_iter iter; enum iss_pipeline_state state; struct iss_pipeline *pipe; struct iss_video *far_end; + struct media_pad *pad; unsigned long flags; int ret; @@ -873,13 +868,9 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) pipe->external_rate = 0; pipe->external_bpp = 0; - ret = media_entity_enum_init(&pipe->ent_enum, entity->graph_obj.mdev); + ret = media_entity_enum_init(&pipe->ent_enum, mdev); if (ret) - goto err_graph_walk_init; - - ret = media_graph_walk_init(&graph, entity->graph_obj.mdev); - if (ret) - goto err_graph_walk_init; + goto err_entity_enum_init; if (video->iss->pdata->set_constraints) video->iss->pdata->set_constraints(video->iss, true); @@ -888,11 +879,8 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) if (ret < 0) goto err_media_pipeline_start; - mutex_lock(&mdev->graph_mutex); - media_graph_walk_start(&graph, entity); - while ((entity = media_graph_walk_next(&graph))) - media_entity_enum_set(&pipe->ent_enum, entity); - mutex_unlock(&mdev->graph_mutex); + media_pipeline_for_each_pad(&pipe->pipe, &iter, pad) + media_entity_enum_set(&pipe->ent_enum, pad->entity); /* * Verify that the currently configured format matches the output of @@ -909,7 +897,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) * Find the ISS video node connected at the far end of the pipeline and * update the pipeline. */ - far_end = iss_video_far_end(video); + far_end = iss_video_far_end(video, pipe); if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { state = ISS_PIPELINE_STREAM_OUTPUT | ISS_PIPELINE_IDLE_OUTPUT; @@ -966,8 +954,6 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) spin_unlock_irqrestore(&video->qlock, flags); } - media_graph_walk_cleanup(&graph); - mutex_unlock(&video->stream_lock); return 0; @@ -981,9 +967,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type) video->iss->pdata->set_constraints(video->iss, false); video->queue = NULL; - media_graph_walk_cleanup(&graph); - -err_graph_walk_init: +err_entity_enum_init: media_entity_enum_cleanup(&pipe->ent_enum); mutex_unlock(&video->stream_lock);