Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp75121lqp; Thu, 4 Apr 2024 07:28:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXt4WBxTUNAlIGIsZfWNd9Ls0RNFQkmz2LVlVCrqQx+vZd3QtGsufbF9lRvKKhGpk1A+YkWZPozSmDaEOzSAnR0t1eGmdq5lz6gYBwjtQ== X-Google-Smtp-Source: AGHT+IFjNkwq+ZGs9y2gPPuF3US67RV4uk8jROzbMcvPIODrHrH/V8gl1ZCCPCKHwyWXH18upYJ5 X-Received: by 2002:a05:620a:a58:b0:78d:3649:2594 with SMTP id j24-20020a05620a0a5800b0078d36492594mr3893164qka.22.1712240933600; Thu, 04 Apr 2024 07:28:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712240933; cv=pass; d=google.com; s=arc-20160816; b=dvLqnfnX8n5G42je0XBPcoNr2iPYDMyV+fQXveISI9GSjZQsbSyakYNt/TFSCPp+pU Dz0AjCP613aqn/WSE1lqdgDrTBrZ+DYV70d4MS4+mcTEuj8vDc7k1ZttXnSShOQpcHtr 12ekYgiPFg7AHe9/YFgeMgH41Upe7nS8yD10BBORsNahO6HUqhv8R3gb5Ki7hYzn/lya d2Fm6wPsyGQjnX6WH8cbk5tJbG8qeawFFFaOU6Hccu1cVA57hwsynRrg8+v5W0QzKiWi +mRkH/eB4Thi3GykUFC7b/8oYvj+AQc9kvQLugnkGfuTo7u1f5rcsPL7fH1TUa6yrNUm P+RA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=q+QaCW2uQAufdlxpQqBG9C//0EiCb1Rb8XlfWh0YImc=; fh=X2CKUxpHmwmhsfC7SYjJR2U0I/NLGaisPOa+EKY2hY4=; b=aNO+sDY3jciTpB7nPT46RZ0fpFrj1e0gmGJ5l66MRiRSCIBBzfgjtL8Q6A2Gw/WIY6 7JTOS5iqxvx0dAoVIrQqJplvjOhwfMFeyzUIrfWKp+L5vqMXjpzpDd7XN37YpecNTY55 TT4XoDuTlEsVGjHkh7K9rvl2XZPBbHRGVR8FRu/qjFZlNZ88u/tTydZiUJKYCGj+N5Y+ LK8bWQKJOm6N4vrS85L9kJkExAXdurTqxhD29wrEKANs1rSixHSVN2XC/GveylwLyBSl a7yOAQJTEejbJXUba4PFfxrW+KAhwztgzCM0ktnweV7rp2AkH/Rj/VPDvxYjaxoFQfoB LimQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=qCyKjovu; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-131613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131613-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b26-20020a05620a089a00b0078bbefc50desi16204364qka.281.2024.04.04.07.28.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 07:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=qCyKjovu; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-131613-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131613-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 57D9C1C2AAE8 for ; Thu, 4 Apr 2024 14:25:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96B8E74267; Thu, 4 Apr 2024 14:25:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qCyKjovu" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C26B128834; Thu, 4 Apr 2024 14:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712240729; cv=none; b=ikgdwzj7+Itma50Hn0xr4FLFc/IUwBMvoar4MGMo0kRlFdFsbNCMGFVbPyYvBVoIDdVU7U3ITiWmscmWq7pbHuuh/EaHf2x+lj00Yi2hc46RFxRu6i9abYle8CV1lniruRg4bzyJxgAlY3QeUmFrvnNs5/O6LwsEjwkmhzyH0nY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712240729; c=relaxed/simple; bh=aAPOzc2+WreCpo8XIFq0ibbeJ127vpP4ofKSCjSQELA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P3IhkngBdZO2/FelFu+hvvH+zkVHz0EeWQ+hagl44zYx/SWfrkINa/KD0e7t5a8LhncaXh2sp2w6eo66niXrAojd8/SS/g0n/yJsMlSytrsSz/3QgeQitE7/E3k53ER64kJqPEC02075ZpguPmkRPQeZS4MoDgDxAL4FpsZedMA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=qCyKjovu; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 954C41A2; Thu, 4 Apr 2024 16:24:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712240687; bh=aAPOzc2+WreCpo8XIFq0ibbeJ127vpP4ofKSCjSQELA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qCyKjovuI8/S+h12ILTJ5ge2Cma1S6qOdcCljeTFLPLt85Rv91fyLU6XPt1XSx0mH 8mvRXED2L+NtUpWoDUuMBHv8M4v8MFLjTvEcgr6ao6e1wfVZK1flXHW+GhsKiHCK32 Z34XNv993zv71njMU6IIY4FA9rTZaS14RoaQSywg= Date: Thu, 4 Apr 2024 17:25:14 +0300 From: Laurent Pinchart To: Tomi Valkeinen Cc: Sakari Ailus , Mauro Carvalho Chehab , Hans Verkuil , Umang Jain , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] media: subdev: Improve v4l2_subdev_enable/disable_streams_fallback Message-ID: <20240404142514.GT23803@pendragon.ideasonboard.com> References: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> <20240404-enable-streams-impro-v1-3-1017a35bbe07@ideasonboard.com> <20240404130617.GR23803@pendragon.ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Thu, Apr 04, 2024 at 04:47:41PM +0300, Tomi Valkeinen wrote: > On 04/04/2024 16:06, Laurent Pinchart wrote: > > On Thu, Apr 04, 2024 at 03:38:45PM +0300, Tomi Valkeinen wrote: > >> On 04/04/2024 15:18, Sakari Ailus wrote: > >>> On Thu, Apr 04, 2024 at 01:50:02PM +0300, Tomi Valkeinen wrote: > >>>> v4l2_subdev_enable/disable_streams_fallback() supports falling back to > >>>> .s_stream() for subdevs with a single source pad. It also tracks the > >>>> enabled streams for that one pad in the sd->enabled_streams field. > >>>> > >>>> Tracking the enabled streams with sd->enabled_streams does not make > >>>> sense, as with .s_stream() there can only be a single stream per pad. > >>>> Thus, as the v4l2_subdev_enable/disable_streams_fallback() only supports > >>>> a single source pad, all we really need is a boolean which tells whether > >>>> streaming has been enabled on this pad or not. > >>>> > >>>> However, as we only need a true/false state for a pad (instead of > >>>> tracking which streams have been enabled for a pad), we can easily > >>>> extend the fallback mechanism to support multiple source pads as we only > >>>> need to keep track of which pads have been enabled. > >>>> > >>>> Change the sd->enabled_streams field to sd->enabled_pads, which is a > >>>> 64-bit bitmask tracking the enabled source pads. With this change we can > >>>> remove the restriction that > >>>> v4l2_subdev_enable/disable_streams_fallback() only supports a single > >>>> soruce pad. > > > > s/soruce/source/ > > > >>>> > >>>> Signed-off-by: Tomi Valkeinen > >>>> --- > >>>> drivers/media/v4l2-core/v4l2-subdev.c | 68 ++++++++++++++++++++--------------- > >>>> include/media/v4l2-subdev.h | 9 +++-- > >>>> 2 files changed, 44 insertions(+), 33 deletions(-) > >>>> > >>>> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c > >>>> index 3b3310bce5d4..91298bb84e6b 100644 > >>>> --- a/drivers/media/v4l2-core/v4l2-subdev.c > >>>> +++ b/drivers/media/v4l2-core/v4l2-subdev.c > >>>> @@ -2090,37 +2090,43 @@ static int v4l2_subdev_enable_streams_fallback(struct v4l2_subdev *sd, u32 pad, > >>>> u64 streams_mask) > >>>> { > >>>> struct device *dev = sd->entity.graph_obj.mdev->dev; > >>>> - unsigned int i; > >>>> int ret; > >>>> > >>>> /* > >>>> * The subdev doesn't implement pad-based stream enable, fall back > >>>> - * on the .s_stream() operation. This can only be done for subdevs that > >>>> - * have a single source pad, as sd->enabled_streams is global to the > >>>> - * subdev. > >>>> + * on the .s_stream() operation. > > > > While at it, s/on/to/ > > Actually, now that we support multiple pads here... Should the comment > and the if below, checking whether the pad is a source pad, be removed? > Is there any reason to require a source pad here (but not in the > non-fallback case)? Mostly the lack of test platforms where we handle stream start/stop from source to sink, calling the operations on sink pads. I'm sure there will be unforeseen issues :-) > > Same below. > > > >>>> */ > >>>> if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) > >>>> return -EOPNOTSUPP; > >>>> > >>>> - for (i = 0; i < sd->entity.num_pads; ++i) { > >>>> - if (i != pad && sd->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE) > >>>> - return -EOPNOTSUPP; > >>>> - } > >>>> + /* > >>>> + * .s_stream() means there is no streams support, so only allowed stream > >>>> + * is the imlicit stream 0. > > > > s/imlicit/implicit/ > > > > Same below. > > > >>>> + */ > >>>> + if (streams_mask != BIT_ULL(0)) > >>>> + return -EOPNOTSUPP; > >>>> + > >>>> + /* > >>>> + * We use a 64-bit bitmask for tracking enabled pads, so only subdevices > >>>> + * with 64 pads or less can be supported. > >>>> + */ > >>>> + if (pad >= sizeof(sd->enabled_pads) * 8) > >>> > >>> s/8/BITS_PER_BYTE/ > >>> > >>>> + return -EOPNOTSUPP; > >>>> > >>>> - if (sd->enabled_streams & streams_mask) { > >>>> - dev_dbg(dev, "set of streams %#llx already enabled on %s:%u\n", > >>>> - streams_mask, sd->entity.name, pad); > >>>> + if (sd->enabled_pads & BIT_ULL(pad)) { > >>>> + dev_dbg(dev, "pad %u already enabled on %s\n", > >>>> + pad, sd->entity.name); > >>>> return -EALREADY; > >>>> } > >>>> > >>>> - /* Start streaming when the first streams are enabled. */ > >>>> - if (!sd->enabled_streams) { > >>>> + /* Start streaming when the first pad is enabled. */ > >>>> + if (!sd->enabled_pads) { > >>>> ret = v4l2_subdev_call(sd, video, s_stream, 1); > >>>> if (ret) > >>>> return ret; > >>>> } > >>>> > >>>> - sd->enabled_streams |= streams_mask; > >>>> + sd->enabled_pads |= BIT_ULL(pad); > >>>> > >>>> return 0; > >>>> } > >>>> @@ -2207,37 +2213,43 @@ static int v4l2_subdev_disable_streams_fallback(struct v4l2_subdev *sd, u32 pad, > >>>> u64 streams_mask) > >>>> { > >>>> struct device *dev = sd->entity.graph_obj.mdev->dev; > >>>> - unsigned int i; > >>>> int ret; > >>>> > >>>> /* > >>>> - * If the subdev doesn't implement pad-based stream enable, fall back > >>>> - * on the .s_stream() operation. This can only be done for subdevs that > >>>> - * have a single source pad, as sd->enabled_streams is global to the > >>>> - * subdev. > >>>> + * If the subdev doesn't implement pad-based stream enable, fall back > >>>> + * on the .s_stream() operation. > >>>> */ > >>>> if (!(sd->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)) > >>>> return -EOPNOTSUPP; > >>>> > >>>> - for (i = 0; i < sd->entity.num_pads; ++i) { > >>>> - if (i != pad && sd->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE) > >>>> - return -EOPNOTSUPP; > >>>> - } > >>>> + /* > >>>> + * .s_stream() means there is no streams support, so only allowed stream > >>>> + * is the imlicit stream 0. > >>>> + */ > >>>> + if (streams_mask != BIT_ULL(0)) > >>>> + return -EOPNOTSUPP; > >>>> + > >>>> + /* > >>>> + * We use a 64-bit bitmask for tracking enabled pads, so only subdevices > >>>> + * with 64 pads or less can be supported. > >>>> + */ > >>>> + if (pad >= sizeof(sd->enabled_pads) * 8) > >>> > >>> Ditto. > >>> > >>> How much of the code of the two functions is the same? Could some of this > >>> be put to a common function both would call? They look (almost) exactly the > >>> same. > >> > >> v4l2_subdev_enable_streams_fallback and v4l2_subdev_enable_streams? They > >> have similar parts, but I don't right away see how combining them or > >> making some common functions would help. > > > > You could move the three checks to a > > v4l2_subdev_streams_fallback_check() function (bikeshedding the name is > > allowed). > > > >>>> + return -EOPNOTSUPP; > >>>> > >>>> - if ((sd->enabled_streams & streams_mask) != streams_mask) { > >>>> - dev_dbg(dev, "set of streams %#llx already disabled on %s:%u\n", > >>>> - streams_mask, sd->entity.name, pad); > >>>> + if ((sd->enabled_pads & BIT_ULL(pad)) != BIT_ULL(pad)) { > > > > if (!(sd->enabled_pads & BIT_ULL(pad))) { > > > >>>> + dev_dbg(dev, "pad %u already disabled on %s\n", > >>>> + pad, sd->entity.name); > >>>> return -EALREADY; > >>>> } > >>>> > >>>> /* Stop streaming when the last streams are disabled. */ > >>>> - if (!(sd->enabled_streams & ~streams_mask)) { > >>>> + if (!(sd->enabled_pads & ~BIT_ULL(pad))) { > >>>> ret = v4l2_subdev_call(sd, video, s_stream, 0); > >>>> if (ret) > >>>> return ret; > >>>> } > >>>> > >>>> - sd->enabled_streams &= ~streams_mask; > >>>> + sd->enabled_pads &= ~BIT_ULL(pad); > >>>> > >>>> return 0; > >>>> } > >>>> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h > >>>> index 8bd1e3c96d2b..7077aec3176c 100644 > >>>> --- a/include/media/v4l2-subdev.h > >>>> +++ b/include/media/v4l2-subdev.h > >>>> @@ -1039,10 +1039,9 @@ struct v4l2_subdev_platform_data { > >>>> * @active_state: Active state for the subdev (NULL for subdevs tracking the > >>>> * state internally). Initialized by calling > >>>> * v4l2_subdev_init_finalize(). > >>>> - * @enabled_streams: Bitmask of enabled streams used by > >>>> - * v4l2_subdev_enable_streams() and > >>>> - * v4l2_subdev_disable_streams() helper functions for fallback > >>>> - * cases. > >>>> + * @enabled_pads: Bitmask of enabled pads used by v4l2_subdev_enable_streams() > >>>> + * and v4l2_subdev_disable_streams() helper functions for > >>>> + * fallback cases. > >>>> * @streaming_enabled: Tracks whether streaming has been enabled with s_stream. > >>>> * > >>>> * Each instance of a subdev driver should create this struct, either > >>>> @@ -1091,7 +1090,7 @@ struct v4l2_subdev { > >>>> * doesn't support it. > >>>> */ > >>>> struct v4l2_subdev_state *active_state; > >>>> - u64 enabled_streams; > >>>> + u64 enabled_pads; > >>>> bool streaming_enabled; > >>>> }; > >>>> -- Regards, Laurent Pinchart