From patchwork Fri May 22 07:55:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11564899 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 DC8E7739 for ; Fri, 22 May 2020 07:56:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C44AF20825 for ; Fri, 22 May 2020 07:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728468AbgEVH4K (ORCPT ); Fri, 22 May 2020 03:56:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728319AbgEVH4J (ORCPT ); Fri, 22 May 2020 03:56:09 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 732D7C05BD43 for ; Fri, 22 May 2020 00:56:09 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 443A22A3537 From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org, skhan@linuxfoundation.org, niklas.soderlund@ragnatech.se--annotate Subject: [PATCH v4 1/5] media: mc-entity.c: add media_graph_walk_next_stream() Date: Fri, 22 May 2020 09:55:18 +0200 Message-Id: <20200522075522.6190-2-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> References: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Helen Koike 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 Reviewed-by: Niklas Söderlund [Dafna: fixing coding style issues] Signed-off-by: Dafna Hirschfeld --- 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 12b45e669bcc..555f9dd9f7f2 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 cde80ad029b7..9035a36e9442 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -928,6 +928,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 Fri May 22 07:55:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11564903 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 B23FB60D for ; Fri, 22 May 2020 07:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5CDE2085B for ; Fri, 22 May 2020 07:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728648AbgEVH4L (ORCPT ); Fri, 22 May 2020 03:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728152AbgEVH4K (ORCPT ); Fri, 22 May 2020 03:56:10 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A352C061A0E for ; Fri, 22 May 2020 00:56:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 0A09E2A354C From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org, skhan@linuxfoundation.org, niklas.soderlund@ragnatech.se--annotate Subject: [PATCH v4 2/5] media: v4l2-common: add helper functions to call s_stream() callbacks Date: Fri, 22 May 2020 09:55:19 +0200 Message-Id: <20200522075522.6190-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> References: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Helen Koike 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. If .s_stream(true) fails, call .s_stream(false) in the reverse order. Signed-off-by: Helen Koike Signed-off-by: Dafna Hirschfeld --- drivers/media/v4l2-core/v4l2-common.c | 99 +++++++++++++++++++++++++++ include/media/v4l2-common.h | 39 +++++++++++ 2 files changed, 138 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 9e8eb45a5b03..734db2bf5ca9 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -442,3 +442,102 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, return 0; } EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt); + +#if defined(CONFIG_MEDIA_CONTROLLER) + +/* + * v4l2_pipeline_subdevs_get - Assemble a list of subdevices in a pipeline + * @subdevs: the array to be filled. + * @max_size: max number of elements that can fit in subdevs array. + * + * Walk from a video node, following links from sink to source and fill the + * array with subdevices in the path. + * The walker performs a depth-first traversal, which means that, in a topology + * sd1->sd2->sd3->vdev, sd1 will be the first element placed in the array. + * + * Return the number of subdevices filled in the array. + */ +static int v4l2_pipeline_subdevs_get(struct video_device *vdev, + struct v4l2_subdev **subdevs, + unsigned int max_size) +{ + struct media_entity *entity = &vdev->entity; + struct media_device *mdev = entity->graph_obj.mdev; + struct media_graph graph; + int idx = 0; + int ret; + + ret = media_graph_walk_init(&graph, mdev); + if (ret) + return ret; + + media_graph_walk_start(&graph, entity); + + while ((entity = media_graph_walk_next_stream(&graph))) { + if (!is_media_entity_v4l2_subdev(entity)) + continue; + if (WARN_ON(idx >= max_size)) + return -EINVAL; + subdevs[idx++] = media_entity_to_v4l2_subdev(entity); + } + + media_graph_walk_cleanup(&graph); + + return idx; +} + +static void v4l2_subdevs_stream_disable(struct v4l2_subdev **subdevs, int size) +{ + int i; + + for (i = 0; i < size; i++) { + struct v4l2_subdev *sd = subdevs[i]; + + dev_dbg(sd->dev, + "disabling stream for '%s'\n", sd->entity.name); + v4l2_subdev_call(sd, video, s_stream, false); + } +} + +__must_check int v4l2_pipeline_stream_enable(struct video_device *vdev) +{ + struct media_device *mdev = vdev->entity.graph_obj.mdev; + struct v4l2_subdev *subdevs[MEDIA_ENTITY_ENUM_MAX_DEPTH]; + struct v4l2_subdev *sd; + int i, size, ret; + + size = v4l2_pipeline_subdevs_get(vdev, subdevs, ARRAY_SIZE(subdevs)); + if (size <= 0) + return size; + + /* Call s_stream() in reverse order to enable sensors last */ + for (i = size - 1; i >= 0; i--) { + sd = subdevs[i]; + dev_dbg(mdev->dev, + "enabling stream for '%s'\n", sd->entity.name); + ret = v4l2_subdev_call(sd, video, s_stream, true); + if (ret && ret != -ENOIOCTLCMD) { + v4l2_subdevs_stream_disable(subdevs + i + 1, + size - i - 1); + return ret; + } + } + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_pipeline_stream_enable); + +int v4l2_pipeline_stream_disable(struct video_device *vdev) +{ + struct v4l2_subdev *subdevs[MEDIA_ENTITY_ENUM_MAX_DEPTH]; + int size; + + size = v4l2_pipeline_subdevs_get(vdev, subdevs, ARRAY_SIZE(subdevs)); + if (size < 0) + return size; + + v4l2_subdevs_stream_disable(subdevs, size); + return 0; +} +EXPORT_SYMBOL_GPL(v4l2_pipeline_stream_disable); + +#endif /* CONFIG_MEDIA_CONTROLLER */ diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 150ee16ebd81..a278bcf3c5bc 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -539,4 +539,43 @@ static inline void v4l2_buffer_set_timestamp(struct v4l2_buffer *buf, buf->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC; } +#if defined(CONFIG_MEDIA_CONTROLLER) + +/** + * v4l2_pipeline_stream_enable - Call .s_stream(true) callbacks in the stream + * @vdev: Starting video device. + * + * Call .s_stream(true) callback in all the subdevices participating in the + * stream, i.e. following links from sink to source. + * + * .s_stream(true) is also called from sink to source, i.e. in a topology + * sd1->sd2->sd3->vdev, .s_stream(true) of sd3 is called first. + * + * Calls to this function can be nested, in which case the same number of + * v4l2_pipeline_stream_disable() calls will be required to disable streaming + * through subdevices in the pipeline. + * The pipeline pointer must be identical for all nested calls to + * v4l2_pipeline_stream_enable(). + */ +__must_check int v4l2_pipeline_stream_enable(struct video_device *vdev); + +/** + * v4l2_pipeline_stream_disable - Call .s_stream(false) callbacks in the stream + * @vdev: Starting video device. + * + * Call .s_stream(false) callback in all the subdevices participating in the + * stream, i.e. following links from sink to source. + * + * s_stream(false) is called in a reverse order from + * v4l2_pipeline_stream_enable(), i.e. in a topology sd1->sd2->sd3->vdev, + * .s_stream(false) of sd1 is called first. + * + * If multiple calls to v4l2_pipeline_stream_enable() have been made, the same + * number of calls to this function are required to disable streaming through + * subdevices in the pipeline. + */ +int v4l2_pipeline_stream_disable(struct video_device *vdev); + +#endif /* CONFIG_MEDIA_CONTROLLER */ + #endif /* V4L2_COMMON_H_ */ From patchwork Fri May 22 07:55:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11564905 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 16DC613B1 for ; Fri, 22 May 2020 07:56:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09D1E2085B for ; Fri, 22 May 2020 07:56:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728659AbgEVH4L (ORCPT ); Fri, 22 May 2020 03:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728544AbgEVH4K (ORCPT ); Fri, 22 May 2020 03:56:10 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9437C05BD43 for ; Fri, 22 May 2020 00:56:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id D13712A3550 From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org, skhan@linuxfoundation.org, niklas.soderlund@ragnatech.se--annotate Subject: [PATCH v4 3/5] media: staging: rkisp1: validate links before powering and streaming Date: Fri, 22 May 2020 09:55:20 +0200 Message-Id: <20200522075522.6190-4-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> References: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In function rkisp1_vb2_start_streaming, the call to media_pipeline_start should be the first thing in order to validate the links and prevents their state from being modified before power up and streaming. Adjust stop streaming to the same logic, call media_pipeline_stop after we disable streaming on the entities in the topology. Signed-off-by: Helen Koike Signed-off-by: Dafna Hirschfeld Reviewed-by: Tomasz Figa --- drivers/staging/media/rkisp1/rkisp1-capture.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-capture.c b/drivers/staging/media/rkisp1/rkisp1-capture.c index f69235f82c45..008c070373f8 100644 --- a/drivers/staging/media/rkisp1/rkisp1-capture.c +++ b/drivers/staging/media/rkisp1/rkisp1-capture.c @@ -898,7 +898,6 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue) mutex_lock(&cap->rkisp1->stream_lock); rkisp1_stream_stop(cap); - media_pipeline_stop(&node->vdev.entity); ret = rkisp1_pipeline_sink_walk(&node->vdev.entity, NULL, rkisp1_pipeline_disable_cb); if (ret) @@ -914,6 +913,8 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue) rkisp1_dummy_buf_destroy(cap); + media_pipeline_stop(&node->vdev.entity); + mutex_unlock(&cap->rkisp1->stream_lock); } @@ -961,9 +962,15 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count) mutex_lock(&cap->rkisp1->stream_lock); + ret = media_pipeline_start(entity, &cap->rkisp1->pipe); + if (ret) { + dev_err(cap->rkisp1->dev, "start pipeline failed %d\n", ret); + goto err_ret_buffers; + } + ret = rkisp1_dummy_buf_create(cap); if (ret) - goto err_ret_buffers; + goto err_pipeline_stop; ret = pm_runtime_get_sync(cap->rkisp1->dev); if (ret < 0) { @@ -984,18 +991,10 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count) if (ret) goto err_stop_stream; - ret = media_pipeline_start(entity, &cap->rkisp1->pipe); - if (ret) { - dev_err(cap->rkisp1->dev, "start pipeline failed %d\n", ret); - goto err_pipe_disable; - } - mutex_unlock(&cap->rkisp1->stream_lock); return 0; -err_pipe_disable: - rkisp1_pipeline_sink_walk(entity, NULL, rkisp1_pipeline_disable_cb); err_stop_stream: rkisp1_stream_stop(cap); v4l2_pipeline_pm_put(entity); @@ -1003,6 +1002,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count) pm_runtime_put(cap->rkisp1->dev); err_destroy_dummy: rkisp1_dummy_buf_destroy(cap); +err_pipeline_stop: + media_pipeline_stop(entity); err_ret_buffers: rkisp1_return_all_buffers(cap, VB2_BUF_STATE_QUEUED); mutex_unlock(&cap->rkisp1->stream_lock); From patchwork Fri May 22 07:55:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11564907 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 352F760D for ; Fri, 22 May 2020 07:56:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26E0D20757 for ; Fri, 22 May 2020 07:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728771AbgEVH4M (ORCPT ); Fri, 22 May 2020 03:56:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728544AbgEVH4L (ORCPT ); Fri, 22 May 2020 03:56:11 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64DDAC061A0E for ; Fri, 22 May 2020 00:56:11 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id A660B2A356A From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org, skhan@linuxfoundation.org, niklas.soderlund@ragnatech.se--annotate Subject: [PATCH v4 4/5] media: staging: rkisp1: cap: use v4l2_pipeline_stream_{enable,disable} helpers Date: Fri, 22 May 2020 09:55:21 +0200 Message-Id: <20200522075522.6190-5-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> References: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Helen Koike Use v4l2_pipeline_stream_{enable,disable} to call .s_stream() subdevice callbacks through the pipeline. Those helpers are called only if the other capture is not streaming. If the other capture is streaming then he already did that for us so we call s_stream only on the resizer that is connected to the capture node. Signed-off-by: Helen Koike Signed-off-by: Dafna Hirschfeld --- drivers/staging/media/rkisp1/rkisp1-capture.c | 104 ++++++------------ 1 file changed, 32 insertions(+), 72 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-capture.c b/drivers/staging/media/rkisp1/rkisp1-capture.c index 008c070373f8..d53a8549da77 100644 --- a/drivers/staging/media/rkisp1/rkisp1-capture.c +++ b/drivers/staging/media/rkisp1/rkisp1-capture.c @@ -806,71 +806,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; @@ -888,6 +823,36 @@ static void rkisp1_stream_stop(struct rkisp1_capture *cap) } } +static int rkisp1_s_stream_subdev(struct rkisp1_capture *cap, int enable) +{ + struct rkisp1_device *rkisp1 = cap->rkisp1; + struct rkisp1_capture *other = &rkisp1->capture_devs[cap->id ^ 1]; + int ret; + + /* + * if the other capture is already streaming then we only need to + * call s_stream of our reszier + */ + if (other->is_streaming) { + struct v4l2_subdev *rsz_sd = &rkisp1->resizer_devs[cap->id].sd; + + ret = v4l2_subdev_call(rsz_sd, video, s_stream, enable); + if (ret && ret != -ENOIOCTLCMD) + dev_err(rkisp1->dev, + "stream %s resizer '%s' failed (%d)\n", + enable ? "on" : "off", rsz_sd->name, ret); + } else { + if (enable) + ret = v4l2_pipeline_stream_enable(&cap->vnode.vdev); + else + ret = v4l2_pipeline_stream_disable(&cap->vnode.vdev); + if (ret < 0) + dev_err(rkisp1->dev, "stream subdevs %s failed %d\n", + enable ? "on" : "off", ret); + } + return ret; +} + static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue) { struct rkisp1_capture *cap = queue->drv_priv; @@ -898,11 +863,7 @@ static void rkisp1_vb2_stop_streaming(struct vb2_queue *queue) mutex_lock(&cap->rkisp1->stream_lock); rkisp1_stream_stop(cap); - ret = rkisp1_pipeline_sink_walk(&node->vdev.entity, NULL, - rkisp1_pipeline_disable_cb); - if (ret) - dev_err(rkisp1->dev, - "pipeline stream-off failed error:%d\n", ret); + rkisp1_s_stream_subdev(cap, 0); rkisp1_return_all_buffers(cap, VB2_BUF_STATE_ERROR); @@ -986,8 +947,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 = rkisp1_s_stream_subdev(cap, 1); if (ret) goto err_stop_stream; From patchwork Fri May 22 07:55:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11564909 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 C4634739 for ; Fri, 22 May 2020 07:56:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B89EE20878 for ; Fri, 22 May 2020 07:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728802AbgEVH4N (ORCPT ); Fri, 22 May 2020 03:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728544AbgEVH4M (ORCPT ); Fri, 22 May 2020 03:56:12 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2049EC061A0E for ; Fri, 22 May 2020 00:56:12 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dafna) with ESMTPSA id 673BE2A357F From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org, skhan@linuxfoundation.org, niklas.soderlund@ragnatech.se--annotate Subject: [PATCH v4 5/5] media: vimc: use v4l2_pipeline_stream_{enable,disable} helpers Date: Fri, 22 May 2020 09:55:22 +0200 Message-Id: <20200522075522.6190-6-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> References: <20200522075522.6190-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Helen Koike 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 Signed-off-by: Dafna Hirschfeld --- .../media/test-drivers/vimc/vimc-capture.c | 31 ++++++++---- .../media/test-drivers/vimc/vimc-streamer.c | 49 ++----------------- 2 files changed, 26 insertions(+), 54 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index c63496b17b9a..36ba664db092 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -245,21 +245,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(&vcap->vdev); + 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(&vcap->vdev); +err_stop_media_pipe: + media_pipeline_stop(entity); +err_return_all_buffers: + vimc_cap_return_all_buffers(vcap, VB2_BUF_STATE_QUEUED); + return ret; } /* @@ -269,9 +275,14 @@ static int vimc_cap_start_streaming(struct vb2_queue *vq, unsigned int count) static void vimc_cap_stop_streaming(struct vb2_queue *vq) { struct vimc_cap_device *vcap = vb2_get_drv_priv(vq); + int ret; vimc_streamer_s_stream(&vcap->stream, &vcap->ved, 0); + ret = v4l2_pipeline_stream_disable(&vcap->vdev); + if (ret) + dev_err(vcap->ved.dev, "stream disable failed: %d\n", ret); + /* Stop the media pipeline */ media_pipeline_stop(&vcap->vdev.entity); diff --git a/drivers/media/test-drivers/vimc/vimc-streamer.c b/drivers/media/test-drivers/vimc/vimc-streamer.c index 65feb3c596db..c0085f4695c2 100644 --- a/drivers/media/test-drivers/vimc/vimc-streamer.c +++ b/drivers/media/test-drivers/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;