From patchwork Mon Mar 16 19:33:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helen Mae Koike Fornazier X-Patchwork-Id: 11441227 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7EA4F14DD for ; Mon, 16 Mar 2020 19:33:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 55CC720738 for ; Mon, 16 Mar 2020 19:33:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EP6v0bdy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55CC720738 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IvUnyGRNshqQ7uoBn20FsG73Fl7Id+d252jviSRrtYo=; b=EP6v0bdy1Vddx6 di/LX+oA/FzGceKlb1WluMr3tXxMy1T4BLZnwD/ALFTVSkFG7NuVR/0gXtYzy5+aoZng82boQ2q+X UbH23Henih/UsodIy1hbATKqVUdZN4wJfFw/KKpjpgN43RgRI/nwolz1feqFajnSiSsZkFxxvET6f RtB49JmN7LENBteyK1RhfhKbLYEvGmFvkkDTu4BiaOhdGwQazYDlclA/KJeWgADVd7gSbjbEpVq7w O6pmPU5Uxx7222rRE0HJS0HAtw4N+lU3eyynruI+qm7ptInAzWGkkv9SWERwOydoPdqiF9HKTnWiM idLFPSlWOT5gAhGAbwGQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUP-0003iI-Gq; Mon, 16 Mar 2020 19:33:29 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUL-0003g0-Vp for linux-rockchip@lists.infradead.org; Mon, 16 Mar 2020 19:33:27 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: koike) with ESMTPSA id 29BE6293517 From: Helen Koike To: linux-media@vger.kernel.org Subject: [PATCH 1/4] media: mc-entity.c: add media_graph_walk_next_stream() Date: Mon, 16 Mar 2020 16:33:02 -0300 Message-Id: <20200316193305.428378-2-helen.koike@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200316193305.428378-1-helen.koike@collabora.com> References: <20200316193305.428378-1-helen.koike@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200316_123326_167313_A743C19F X-CRM114-Status: GOOD ( 11.52 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Helen Koike , hans.verkuil@cisco.com, niklas.soderlund@ragnatech.se, mchehab@kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org Add media_graph_walk_next_stream() function to follow links only from sink to source (not the opposite) to allow iteration only through the entities participating in a given stream. This is useful to allow calling .s_stream() callback only in the subdevices that requires to be enabled/disabled, and avoid calling this callback when not required. Signed-off-by: Helen Koike --- drivers/media/mc/mc-entity.c | 34 +++++++++++++++++++++++++++++++--- include/media/media-entity.h | 15 +++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c index 211279c5fd77..0d44c2de23e6 100644 --- a/drivers/media/mc/mc-entity.c +++ b/drivers/media/mc/mc-entity.c @@ -228,6 +228,11 @@ EXPORT_SYMBOL_GPL(media_entity_pads_init); * Graph traversal */ +enum media_graph_walk_type { + MEDIA_GRAPH_WALK_CONNECTED_NODES, + MEDIA_GRAPH_WALK_STREAM_NODES, +}; + static struct media_entity * media_entity_other(struct media_entity *entity, struct media_link *link) { @@ -305,7 +310,8 @@ void media_graph_walk_start(struct media_graph *graph, } EXPORT_SYMBOL_GPL(media_graph_walk_start); -static void media_graph_walk_iter(struct media_graph *graph) +static void media_graph_walk_iter(struct media_graph *graph, + enum media_graph_walk_type type) { struct media_entity *entity = stack_top(graph); struct media_link *link; @@ -326,6 +332,15 @@ static void media_graph_walk_iter(struct media_graph *graph) /* Get the entity in the other end of the link . */ next = media_entity_other(entity, link); + if (type == MEDIA_GRAPH_WALK_STREAM_NODES + && next == link->sink->entity) { + link_top(graph) = link_top(graph)->next; + dev_dbg(entity->graph_obj.mdev->dev, + "walk: skipping '%s' (outside of the stream path)\n", + link->sink->entity->name); + return; + } + /* Has the entity already been visited? */ if (media_entity_enum_test_and_set(&graph->ent_enum, next)) { link_top(graph) = link_top(graph)->next; @@ -342,7 +357,9 @@ static void media_graph_walk_iter(struct media_graph *graph) next->name); } -struct media_entity *media_graph_walk_next(struct media_graph *graph) +static struct media_entity * +__media_graph_walk_next(struct media_graph *graph, + enum media_graph_walk_type type) { struct media_entity *entity; @@ -355,7 +372,7 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph) * found. */ while (link_top(graph) != &stack_top(graph)->links) - media_graph_walk_iter(graph); + media_graph_walk_iter(graph, type); entity = stack_pop(graph); dev_dbg(entity->graph_obj.mdev->dev, @@ -363,8 +380,19 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph) return entity; } + +struct media_entity *media_graph_walk_next(struct media_graph *graph) +{ + return __media_graph_walk_next(graph, MEDIA_GRAPH_WALK_CONNECTED_NODES); +} EXPORT_SYMBOL_GPL(media_graph_walk_next); +struct media_entity *media_graph_walk_next_stream(struct media_graph *graph) +{ + return __media_graph_walk_next(graph, MEDIA_GRAPH_WALK_STREAM_NODES); +} +EXPORT_SYMBOL_GPL(media_graph_walk_next_stream); + int media_entity_get_fwnode_pad(struct media_entity *entity, struct fwnode_handle *fwnode, unsigned long direction_flags) diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 8cb2c504a05c..f17a5180ce52 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -927,6 +927,21 @@ void media_graph_walk_start(struct media_graph *graph, */ struct media_entity *media_graph_walk_next(struct media_graph *graph); +/** + * media_graph_walk_next_stream - Get the next entity in the graph + * @graph: Media graph structure + * + * Perform a depth-first traversal of the given media entities graph only + * following links from sink to source (and not the opposite). + * + * The graph structure must have been previously initialized with a call to + * media_graph_walk_start(). + * + * Return: returns the next entity in the graph in the stream path + * or %NULL if the whole stream path have been traversed. + */ +struct media_entity *media_graph_walk_next_stream(struct media_graph *graph); + /** * media_pipeline_start - Mark a pipeline as streaming * @entity: Starting entity From patchwork Mon Mar 16 19:33:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helen Mae Koike Fornazier X-Patchwork-Id: 11441229 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80B3213B1 for ; Mon, 16 Mar 2020 19:33:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 556DC206E2 for ; Mon, 16 Mar 2020 19:33:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ffu2ZPTW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 556DC206E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iNbaeCTGVczlRMOO883X3Wi4Nnrsc5o8AgIax4WWT5w=; b=ffu2ZPTWkUFGB2 jhbqKv3PwEbePwf4ookyeFYwkeQaNT75XM2Fh/XMYMNDpzUYScOIyu8QB0Y024owPpbEOLY/8KRCW iLX2ZVMid2D6O7v+SZont4Eb/yX9VgOq2Ep6d+r0MjXYpi/2rNYkVGu1VGQ5MTP7a+p8vxZIY6zyh 7dvpew0HvoQnNiiWanfnSRIlM2BVwpnvphYak+zQSCK09aMcLQ7AeLkJYvfFJeDEAlXPd6bHNIWZX 6Mw/hUvCbj6ZM7w604r1DTwuujrignUVcppEtqtp9t5ZyenMqpZjBKj9/3kDrEYYJHvAOBqLag3Y7 Td1PxeMhqiPz6dsWZ+gw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUR-0003ju-BP; Mon, 16 Mar 2020 19:33:31 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUO-0003hU-Kt for linux-rockchip@lists.infradead.org; Mon, 16 Mar 2020 19:33:30 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: koike) with ESMTPSA id 2B27B293369 From: Helen Koike To: linux-media@vger.kernel.org Subject: [PATCH 2/4] media: v4l2-common: add helper functions to call s_stream() callbacks Date: Mon, 16 Mar 2020 16:33:03 -0300 Message-Id: <20200316193305.428378-3-helen.koike@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200316193305.428378-1-helen.koike@collabora.com> References: <20200316193305.428378-1-helen.koike@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200316_123328_949791_90A1502A X-CRM114-Status: GOOD ( 11.70 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [46.235.227.227 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Helen Koike , hans.verkuil@cisco.com, niklas.soderlund@ragnatech.se, mchehab@kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org Add v4l2_pipeline_stream_{enable,disable} helper functions to iterate through the subdevices in a given stream (i.e following links from sink to source) and call .s_stream() callback. Add stream_count on the subdevice object for simultaneous streaming from different video devices which shares subdevices. Prevent calling .s_stream(true) if it was already called previously by another stream. Prevent calling .s_stream(false) from one stream when there are still others active. Signed-off-by: Helen Koike --- drivers/media/v4l2-core/v4l2-common.c | 99 +++++++++++++++++++++++++++ include/media/v4l2-common.h | 30 ++++++++ include/media/v4l2-subdev.h | 2 + 3 files changed, 131 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index d0e5ebc736f9..6a5a3d2c282e 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -441,3 +441,102 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, return 0; } EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt); + +int v4l2_pipeline_stream_disable(struct media_entity *entity, + struct media_pipeline *pipe) +{ + struct media_device *mdev = entity->graph_obj.mdev; + int ret = 0; + + mutex_lock(&mdev->graph_mutex); + + if (!pipe->streaming_count) { + ret = media_graph_walk_init(&pipe->graph, mdev); + if (ret) { + mutex_unlock(&mdev->graph_mutex); + return ret; + } + } + + media_graph_walk_start(&pipe->graph, entity); + + while ((entity = media_graph_walk_next_stream(&pipe->graph))) { + struct v4l2_subdev *sd; + + if (!is_media_entity_v4l2_subdev(entity)) + continue; + + sd = media_entity_to_v4l2_subdev(entity); + if (!sd->stream_count || --sd->stream_count) + continue; + + ret = v4l2_subdev_call(sd, video, s_stream, false); + if (ret && ret != -ENOIOCTLCMD) + dev_dbg(mdev->dev, + "couldn't disable stream for subdevice '%s'\n", + entity->name); + break; + } + + dev_dbg(mdev->dev, + "stream disabled for subdevice '%s'\n", entity->name); + } + + if (!pipe->streaming_count) + media_graph_walk_cleanup(&pipe->graph); + + mutex_unlock(&mdev->graph_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(v4l2_pipeline_stream_disable); + +__must_check int v4l2_pipeline_stream_enable(struct media_entity *entity, + struct media_pipeline *pipe) +{ + struct media_device *mdev = entity->graph_obj.mdev; + int ret = 0; + + mutex_lock(&mdev->graph_mutex); + + if (!pipe->streaming_count) { + ret = media_graph_walk_init(&pipe->graph, mdev); + if (ret) { + mutex_unlock(&mdev->graph_mutex); + return ret; + } + } + + media_graph_walk_start(&pipe->graph, entity); + + while ((entity = media_graph_walk_next_stream(&pipe->graph))) { + struct v4l2_subdev *sd; + + if (!is_media_entity_v4l2_subdev(entity)) + continue; + + sd = media_entity_to_v4l2_subdev(entity); + if (sd->stream_count++) + continue; + + ret = v4l2_subdev_call(sd, video, s_stream, true); + if (ret && ret != -ENOIOCTLCMD) + dev_dbg(mdev->dev, + "couldn't enable stream for subdevice '%s'\n", + entity->name); + v4l2_pipeline_stream_disable(entity, pipe); + break; + } + + dev_dbg(mdev->dev, + "stream enabled for subdevice '%s'\n", entity->name); + } + + if (!pipe->streaming_count) + media_graph_walk_cleanup(&pipe->graph); + + mutex_unlock(&mdev->graph_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(v4l2_pipeline_stream_enable); diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 150ee16ebd81..46c0857d07c4 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -519,6 +519,36 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, int v4l2_fill_pixfmt_mp(struct v4l2_pix_format_mplane *pixfmt, u32 pixelformat, u32 width, u32 height); +/** + * media_pipeline_stop - Mark a pipeline as not streaming + * @entity: Starting entity + * @pipe: Media pipeline to iterate through the topology + * + * Call .s_stream(false) callback in all the subdevices participating in the + * stream, i.e. following links from sink to source. + * + * If multiple calls to v4l2_pipeline_stream_enable() have been made, the + * same number of calls to this function are required. + */ +int v4l2_pipeline_stream_disable(struct media_entity *entity, + struct media_pipeline *pipe); + +/** + * v4l2_pipeline_stream_enable - Call .s_stream(true) callbacks in the stream + * @entity: Starting entity + * @pipe: Media pipeline to iterate through the topology + * + * Call .s_stream(true) callback in all the subdevices participating in the + * stream, i.e. following links from sink to source. + * + * Calls to this function can be nested, in which case the same number of + * v4l2_pipeline_stream_disable() calls will be required to stop streaming. + * The pipeline pointer must be identical for all nested calls to + * v4l2_pipeline_stream_enable(). + */ +__must_check int v4l2_pipeline_stream_enable(struct media_entity *entity, + struct media_pipeline *pipe); + static inline u64 v4l2_buffer_get_timestamp(const struct v4l2_buffer *buf) { /* diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a4848de59852..20f913a9f70c 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -838,6 +838,7 @@ struct v4l2_subdev_platform_data { * @subdev_notifier: A sub-device notifier implicitly registered for the sub- * device using v4l2_device_register_sensor_subdev(). * @pdata: common part of subdevice platform data + * @stream_count: Stream count for the subdevice. * * Each instance of a subdev driver should create this struct, either * stand-alone or embedded in a larger struct. @@ -869,6 +870,7 @@ struct v4l2_subdev { struct v4l2_async_notifier *notifier; struct v4l2_async_notifier *subdev_notifier; struct v4l2_subdev_platform_data *pdata; + unsigned int stream_count; }; From patchwork Mon Mar 16 19:33:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helen Mae Koike Fornazier X-Patchwork-Id: 11441235 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 331B714DD for ; Mon, 16 Mar 2020 19:33:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 10B91206E2 for ; Mon, 16 Mar 2020 19:33:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nMPxGQBk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10B91206E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KMiFApT6jH+MG/lqxa4F0RAz1Dqz3zZ8wQnEvH04OrQ=; b=nMPxGQBk2n9C8U zNFQGbOlS5VHjck0yXy/I7m/Aof9HNNF9zVbeHi/cCnYLqm2TV2igXzh99lmXTeVfwARUQIChcdO+ 9yMQS8MBk1/GSXmhdw8Misy6wrKlDiW6zN9WgSeLmHxuaSmcBSDK41QuT0RJR1bjKMYbAxVl5XjVq ASfV1GVmZGpgyJ+r1VCe7wgi1FA26yHd4zqf83g40hycnp0EGN5vpPakfxL2CYw7tdKjrQpjkeorp 0K/9RO5MbBGf+eB7Fa9iy8f8knL2gZaUogzlYruOd9ATVLyKCDHdoXGjroqrRu9W2E4R2f69z9BJ/ A7nwVMwB5d7QBgZI3TVg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUV-0003na-7k; Mon, 16 Mar 2020 19:33:35 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUR-0003jo-T8 for linux-rockchip@lists.infradead.org; Mon, 16 Mar 2020 19:33:33 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: koike) with ESMTPSA id 2B18E294879 From: Helen Koike To: linux-media@vger.kernel.org Subject: [PATCH 3/4] media: staging: rkisp1: use v4l2_pipeline_stream_{enable, disable} helpers Date: Mon, 16 Mar 2020 16:33:04 -0300 Message-Id: <20200316193305.428378-4-helen.koike@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200316193305.428378-1-helen.koike@collabora.com> References: <20200316193305.428378-1-helen.koike@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200316_123332_094165_31000832 X-CRM114-Status: GOOD ( 10.05 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [46.235.227.227 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Helen Koike , hans.verkuil@cisco.com, niklas.soderlund@ragnatech.se, mchehab@kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org Use v4l2_pipeline_stream_{enable,disable} to call .s_stream() subdevice callbacks through the pipeline. Tested by streaming on RockPi4 with imx219. Signed-off-by: Helen Koike --- drivers/staging/media/rkisp1/rkisp1-capture.c | 74 +------------------ 1 file changed, 4 insertions(+), 70 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-capture.c b/drivers/staging/media/rkisp1/rkisp1-capture.c index 24fe6a7888aa..9e1f3e022016 100644 --- a/drivers/staging/media/rkisp1/rkisp1-capture.c +++ b/drivers/staging/media/rkisp1/rkisp1-capture.c @@ -838,71 +838,6 @@ static void rkisp1_return_all_buffers(struct rkisp1_capture *cap, spin_unlock_irqrestore(&cap->buf.lock, flags); } -/* - * rkisp1_pipeline_sink_walk - Walk through the pipeline and call cb - * @from: entity at which to start pipeline walk - * @until: entity at which to stop pipeline walk - * - * Walk the entities chain starting at the pipeline video node and stop - * all subdevices in the chain. - * - * If the until argument isn't NULL, stop the pipeline walk when reaching the - * until entity. This is used to disable a partially started pipeline due to a - * subdev start error. - */ -static int rkisp1_pipeline_sink_walk(struct media_entity *from, - struct media_entity *until, - int (*cb)(struct media_entity *from, - struct media_entity *curr)) -{ - struct media_entity *entity = from; - struct media_pad *pad; - unsigned int i; - int ret; - - while (1) { - pad = NULL; - /* Find remote source pad */ - for (i = 0; i < entity->num_pads; i++) { - struct media_pad *spad = &entity->pads[i]; - - if (!(spad->flags & MEDIA_PAD_FL_SINK)) - continue; - pad = media_entity_remote_pad(spad); - if (pad && is_media_entity_v4l2_subdev(pad->entity)) - break; - } - if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) - break; - - entity = pad->entity; - if (entity == until) - break; - - ret = cb(from, entity); - if (ret) - return ret; - } - - return 0; -} - -static int rkisp1_pipeline_disable_cb(struct media_entity *from, - struct media_entity *curr) -{ - struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(curr); - - return v4l2_subdev_call(sd, video, s_stream, false); -} - -static int rkisp1_pipeline_enable_cb(struct media_entity *from, - struct media_entity *curr) -{ - struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(curr); - - return v4l2_subdev_call(sd, video, s_stream, true); -} - static void rkisp1_stream_stop(struct rkisp1_capture *cap) { int ret; @@ -929,8 +864,8 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue) rkisp1_stream_stop(cap); media_pipeline_stop(&node->vdev.entity); - ret = rkisp1_pipeline_sink_walk(&node->vdev.entity, NULL, - rkisp1_pipeline_disable_cb); + ret = v4l2_pipeline_stream_disable(&node->vdev.entity, + &cap->rkisp1->pipe); if (ret) dev_err(rkisp1->dev, "pipeline stream-off failed error:%d\n", ret); @@ -1005,8 +940,7 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count) rkisp1_stream_start(cap); /* start sub-devices */ - ret = rkisp1_pipeline_sink_walk(entity, NULL, - rkisp1_pipeline_enable_cb); + ret = v4l2_pipeline_stream_enable(entity, &cap->rkisp1->pipe); if (ret) goto err_stop_stream; @@ -1019,7 +953,7 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count) return 0; err_pipe_disable: - rkisp1_pipeline_sink_walk(entity, NULL, rkisp1_pipeline_disable_cb); + v4l2_pipeline_stream_disable(entity, &cap->rkisp1->pipe); err_stop_stream: rkisp1_stream_stop(cap); v4l2_pipeline_pm_put(entity); From patchwork Mon Mar 16 19:33:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helen Mae Koike Fornazier X-Patchwork-Id: 11441239 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19EBB13B1 for ; Mon, 16 Mar 2020 19:33:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB6E120719 for ; Mon, 16 Mar 2020 19:33:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XhuuXqxQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB6E120719 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2gTFHKTHnN68WvkUPcV+riPUZ3g/6fY7cVCLf643Suk=; b=XhuuXqxQ2sBdCw GIKsepoWQYyCAK0noBem9ND9pIlfKYVBduTfcl6NAqnuqysyqN8F5WeVpcgm84aTRmVclKcNGl8ZG BIUMwIjL2y/8+qQzyVTuchpyQOyHwlX50uVXe7OJk4TDx8QWu/+Wl7LsHW+qTSifCUEpLcihUorp9 sTT1H8tlzaJPoZBJvL4c4q5IAfX9p4AnHBK9MZbGmTqmGf2DCmcFWMFUW3YwVs8O4Ps3gJR+sXYck Tj3KOTrADNWFU69kWhTIbjB5c1gJlxQMwbEvNOG25Z7NIs2gnj1R00kjDawP5Vdcie9a22nQ47YeF 3GVjf0j5ov3JP3XanfTg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUZ-0003qj-4c; Mon, 16 Mar 2020 19:33:39 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jDvUW-0003nl-4u for linux-rockchip@lists.infradead.org; Mon, 16 Mar 2020 19:33:37 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: koike) with ESMTPSA id 574E5293369 From: Helen Koike To: linux-media@vger.kernel.org Subject: [PATCH 4/4] media: vimc: use v4l2_pipeline_stream_{enable, disable} helpers Date: Mon, 16 Mar 2020 16:33:05 -0300 Message-Id: <20200316193305.428378-5-helen.koike@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200316193305.428378-1-helen.koike@collabora.com> References: <20200316193305.428378-1-helen.koike@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200316_123336_459990_B88E90F6 X-CRM114-Status: GOOD ( 12.54 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Helen Koike , hans.verkuil@cisco.com, niklas.soderlund@ragnatech.se, mchehab@kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org Use v4l2_pipeline_stream_{enable,disable} to call .s_stream() subdevice callbacks through the pipeline. Tested streaming works with: media-ctl -d /dev/media0 -V '"Sensor A":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d /dev/media0 -V '"Debayer A":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d /dev/media0 -V '"Sensor B":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d /dev/media0 -V '"Debayer B":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d /dev/media0 -V '"Scaler":0[fmt:RGB888_1X24/640x480]' media-ctl -d /dev/media0 -V '"Scaler":0[crop:(100,50)/400x150]' media-ctl -d /dev/media0 -V '"Scaler":1[fmt:RGB888_1X24/1920x1440]' v4l2-ctl -d /dev/video2 -v width=1200,height=450 v4l2-ctl -d /dev/video0 -v pixelformat=BA81 v4l2-ctl -d /dev/video1 -v pixelformat=BA81 v4l2-ctl --stream-mmap --stream-count=10 -d /dev/video2 --stream-to=/tmp/test.raw Signed-off-by: Helen Koike --- drivers/media/platform/vimc/vimc-capture.c | 28 +++++++----- drivers/media/platform/vimc/vimc-streamer.c | 49 +++------------------ 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c index 23e740c1c5c0..f65d59728d8f 100644 --- a/drivers/media/platform/vimc/vimc-capture.c +++ b/drivers/media/platform/vimc/vimc-capture.c @@ -233,21 +233,27 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) vcap->sequence = 0; - /* Start the media pipeline */ ret = media_pipeline_start(entity, &vcap->stream.pipe); - if (ret) { - vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); - return ret; - } + if (ret) + goto err_return_all_buffers; + + ret = v4l2_pipeline_stream_enable(entity, &vcap->stream.pipe); + if (ret) + goto err_stop_media_pipe; ret = vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 1); - if (ret) { - media_pipeline_stop(entity); - vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); - return ret; - } + if (ret) + goto err_stop_stream; return 0; + +err_stop_stream: + v4l2_pipeline_stream_disable(entity, &vcap->stream.pipe); +err_stop_media_pipe: + media_pipeline_stop(entity); +err_return_all_buffers: + vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); + return ret; } /* @@ -260,6 +266,8 @@ static void vimc_cap_stop_streaming(struct vb2_queue *vq) vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 0); + v4l2_pipeline_stream_disable(&vcap->vdev.entity, &vcap->stream.pipe); + /* Stop the media pipeline */ media_pipeline_stop(&vcap->vdev.entity); diff --git a/drivers/media/platform/vimc/vimc-streamer.c b/drivers/media/platform/vimc/vimc-streamer.c index 65feb3c596db..c0085f4695c2 100644 --- a/drivers/media/platform/vimc/vimc-streamer.c +++ b/drivers/media/platform/vimc/vimc-streamer.c @@ -36,33 +36,6 @@ static struct media_entity *vimc_get_source_entity(struct media_entity *ent) return NULL; } -/** - * vimc_streamer_pipeline_terminate - Disable stream in all ved in stream - * - * @stream: the pointer to the stream structure with the pipeline to be - * disabled. - * - * Calls s_stream to disable the stream in each entity of the pipeline - * - */ -static void vimc_streamer_pipeline_terminate(struct vimc_stream *stream) -{ - struct vimc_ent_device *ved; - struct v4l2_subdev *sd; - - while (stream->pipe_size) { - stream->pipe_size--; - ved = stream->ved_pipeline[stream->pipe_size]; - stream->ved_pipeline[stream->pipe_size] = NULL; - - if (!is_media_entity_v4l2_subdev(ved->ent)) - continue; - - sd = media_entity_to_v4l2_subdev(ved->ent); - v4l2_subdev_call(sd, video, s_stream, 0); - } -} - /** * vimc_streamer_pipeline_init - Initializes the stream structure * @@ -82,27 +55,15 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, struct media_entity *entity; struct video_device *vdev; struct v4l2_subdev *sd; - int ret = 0; stream->pipe_size = 0; while (stream->pipe_size < VIMC_STREAMER_PIPELINE_MAX_SIZE) { if (!ved) { - vimc_streamer_pipeline_terminate(stream); + stream->pipe_size = 0; return -EINVAL; } stream->ved_pipeline[stream->pipe_size++] = ved; - if (is_media_entity_v4l2_subdev(ved->ent)) { - sd = media_entity_to_v4l2_subdev(ved->ent); - ret = v4l2_subdev_call(sd, video, s_stream, 1); - if (ret && ret != -ENOIOCTLCMD) { - dev_err(ved->dev, "subdev_call error %s\n", - ved->ent->name); - vimc_streamer_pipeline_terminate(stream); - return ret; - } - } - entity = vimc_get_source_entity(ved->ent); /* Check if the end of the pipeline was reached */ if (!entity) { @@ -111,7 +72,7 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, dev_err(ved->dev, "first entity in the pipe '%s' is not a source\n", ved->ent->name); - vimc_streamer_pipeline_terminate(stream); + stream->pipe_size = 0; return -EPIPE; } return 0; @@ -129,7 +90,7 @@ static int vimc_streamer_pipeline_init(struct vimc_stream *stream, } } - vimc_streamer_pipeline_terminate(stream); + stream->pipe_size = 0; return -EINVAL; } @@ -210,7 +171,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, if (IS_ERR(stream->kthread)) { ret = PTR_ERR(stream->kthread); dev_err(ved->dev, "kthread_run failed with %d\n", ret); - vimc_streamer_pipeline_terminate(stream); + stream->pipe_size = 0; stream->kthread = NULL; return ret; } @@ -231,7 +192,7 @@ int vimc_streamer_s_stream(struct vimc_stream *stream, stream->kthread = NULL; - vimc_streamer_pipeline_terminate(stream); + stream->pipe_size = 0; } return 0;