From patchwork Thu Apr 4 10:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13617571 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 ED6D7763EE; Thu, 4 Apr 2024 10:50:21 +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=1712227823; cv=none; b=R/Kto6UkNegD+jxzLnZhpORoq4YoQ4dx9ppEWIQFvNYvcvJWuTw0fli+XntboWDyqoMTysZdZjKJJvbQvEobGIEdWlKm6fBvaocP8CVACYhxGVYcwRAN7QYaKFweLDxBHuzjx0F7ecN81f6hyssiamIy7C8Hke4sfM/dF+pBCzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712227823; c=relaxed/simple; bh=7+2nXWnaOTSsKOVrfNaX7gAxdvGAJKcw65XNN4PJTwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LfO+GYIJi9VCbB9WvBKhnDt8E9aHxXNKH0hQ4qLFfTI6Kwy4ko4zuMY+Od5wZgClXD53RYa5X9WP4/LQ1hSEyOrNKzoxR8G/TuEvSdEdydTAfrvwNXD4UcP1dJXYwCX07FqkfYW0J13aC1D4iyUEBr86m4e+lBL4TX2mTEBzhis= 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=OLh9z78u; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OLh9z78u" Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E98F0497; Thu, 4 Apr 2024 12:49:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712227782; bh=7+2nXWnaOTSsKOVrfNaX7gAxdvGAJKcw65XNN4PJTwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OLh9z78uq4/6oxcxx8HUKvN1cVGnWoTJd+O7pSlZyHtGgRsXXjptHt94pT1wMO9O2 IrE2lc2rp90y6SxkK26LFN5T48by6xG6QF99FFQwpu/LTo5xEaLBQVUhYYZNdK58Kn UOg46PcSPjWsqct/APPTy85f4n+sMBeHZ+taZ/Ds= From: Tomi Valkeinen Date: Thu, 04 Apr 2024 13:50:00 +0300 Subject: [PATCH 1/4] media: subdev: Add checks for subdev features Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240404-enable-streams-impro-v1-1-1017a35bbe07@ideasonboard.com> References: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> In-Reply-To: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2166; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=7+2nXWnaOTSsKOVrfNaX7gAxdvGAJKcw65XNN4PJTwE=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmDoXp9Ioox00px095fK3OkdCk2nenPvIPOBdo9 yS5VNab3nKJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZg6F6QAKCRD6PaqMvJYe 9dIrD/4ihVQivaoXNrP5+biyesLF18AwDelyQtwSl9Bv28mUwz2yiTbVSbKqe99MJcH1rGqDdMa sqTQflMpXgTffa0J5oaXnYN6Dz6dsu4Hz0xpjRtD5NlGemmVUfC5DbhrX1hMlZR97j8k0zAX/67 xzg+I+5HcvpN9tLG30hoSRawtF5nwWTKWFg/ktP6E78eqYcObuC+FBTJ9mzZp+I+1DAgnSlD8M7 52hFg+CzzJSCVOYw67dzk8fKMFfIBXyBZzxnnJvV64kXtK9w6S1vrHOaJSR1V3hW04Qc3dD3KjA ECJtGGYLLwTPCChhynw6SKMwgkkGvinzEjwE0e7sER8RzhYsaeqW/v6DGBS4Z7UFrYQ0pe099/p s5NJV71C24y4vbvWo6k6ZoUTvPM8RcW/y/xxu+p3jSWVBTCU9YQvUrkbh/KNxTyZn5yeEsUqxzO Y96DXVZHWJBwEJ/FGWieGnB4bub4l7aecID4m6+eWfntPPBKfwDwwM3BGxiSZuJGRAHRwoT8+Fr xE5Y2COyl8ILnKxdZqoBFNOEo5T6o2dJ+uLx9K2LJx3bvEjWnnw+o6NYILwC7M5q/8DC90XoSCz DI1Ik++/ZPEz5dzOZbkUuSJVDslzvbEfbjGVci385wj1wWvtfjckaWIxPi9gBrFZJWkzS2exDyJ WrcZ8ZyfGB+/S/A== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 Add some checks to verify that the subdev driver implements required features. A subdevice that supports streams (V4L2_SUBDEV_FL_STREAMS) must do one of the following: - Implement neither .enable/disable_streams() nor .s_stream(), if the subdev is part of a video driver that uses an internal method to enable the subdev. - Implement only .enable/disable_streams(), if support for legacy sink-side subdevices is not needed. - Implement .enable/disable_streams() and .s_stream(), if support for legacy sink-side subdevices is needed. At the moment the framework doesn't check this requirement. Add the check. Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 4c6198c48dd6..b90b5185e87f 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -1519,6 +1519,33 @@ int __v4l2_subdev_init_finalize(struct v4l2_subdev *sd, const char *name, struct lock_class_key *key) { struct v4l2_subdev_state *state; + struct device *dev = sd->dev; + bool has_disable_streams; + bool has_enable_streams; + bool has_s_stream; + + /* Check that the subdevice implements the required features */ + + has_s_stream = sd->ops && sd->ops->video && sd->ops->video->s_stream; + has_enable_streams = sd->ops && sd->ops->pad && sd->ops->pad->enable_streams; + has_disable_streams = sd->ops && sd->ops->pad && sd->ops->pad->disable_streams; + + if (has_enable_streams != has_disable_streams) { + dev_err(dev, + "subdev '%s' must implement both or neither of .enable_streams() and .disable_streams()\n", + sd->name); + return -EINVAL; + } + + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + if (has_s_stream && !has_enable_streams) { + dev_err(dev, + "subdev '%s' must implement .enable/disable_streams()\n", + sd->name); + + return -EINVAL; + } + } state = __v4l2_subdev_state_alloc(sd, name, key); if (IS_ERR(state)) From patchwork Thu Apr 4 10:50:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13617572 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 DBCB282860; Thu, 4 Apr 2024 10:50:23 +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=1712227826; cv=none; b=Av0/favNXtxwelYp6n2Xm4X035g1YuAsk45OwRVrcix4+1z4k6qxiYzd9Z7yY1Uszxup9kQAuZ0Ppjt7H0x/ieA21LnT4KACWa5UrDJVmah/ryIxeQ1Z/LGqPCgMlMaq9FOI/0fzxJwwfqlx6BuBzimxhchV9ZWtlYBB4YERDic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712227826; c=relaxed/simple; bh=GfjARRmYhZQQsiUkYR1m3t1+Io8a3x14bSPuokN30zY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LH4ht/x9htuMRNJmngKc6+p+k+1qm6PYS9o/x6iLm78JmC8tK4tOa0IbBeKNc/rPWPBBw3lmoYvoULekIACanUFDIC5w41R4xIf6uYSVzWjJuQ2+12igxtIR4imiGlkPJfC3mnQHo3JVxXLg3SyJtE4OOWRzCvApYtIHDn3QJE0= 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=ihy3tg0d; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ihy3tg0d" Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A366ACB; Thu, 4 Apr 2024 12:49:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712227782; bh=GfjARRmYhZQQsiUkYR1m3t1+Io8a3x14bSPuokN30zY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ihy3tg0dZPV6Bt3xYK0eZe+cdWAMU2MUm8LiS+WK+ijSXZ34YoVVMXfT2sItMqrPB ysHpbWTqMuUq9Qo4Elm5IYP3hmguxOYvJnfnNM7+Ee+5CaBf5ds8107QEcuRYts2Mz CdcQ+Ez9Ra1tgEMpunyasgscjVcS8IG7d1g0n7p0= From: Tomi Valkeinen Date: Thu, 04 Apr 2024 13:50:01 +0300 Subject: [PATCH 2/4] media: subdev: Fix use of sd->enabled_streams in call_s_stream() Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240404-enable-streams-impro-v1-2-1017a35bbe07@ideasonboard.com> References: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> In-Reply-To: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2700; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=GfjARRmYhZQQsiUkYR1m3t1+Io8a3x14bSPuokN30zY=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmDoXpLG4W/viQuMN8fixmJX02jfyMjPk5nfhuP w2V72zWN9yJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZg6F6QAKCRD6PaqMvJYe 9fCgEACId0SnI01QKLidTGMOuwL/WsE0olMUSEllLGkgkw37UZOMWlgpHaapDDrUZgLyXSJruSd nOJHB25TptA7MxtAh6W5bicCgOzoCHg9nxDqZ1xzNwUVRxfEq6Ao/D9Wj3pTNPZlIA5EFtcTbMs NVlUtyR5pwxZfvORcqkxwTVSpOWNXPb95OLjUI1sKRc9HliQcgj/oAOkP1XVinh+aMzKFW7JsrW ZwNHUEjqxwq/TZaMQvBX87g4vgB5IMYZFMY1aaivQtZNy01SppftmfbRzMXil2qY056qlz7Rt25 uNv8xOPkiDQdd6zdgqn56OKFiIYHEmyEhheCbHYx4xobcza4T2QpYwKXTXOKaeIpjPjvNYS/pYy kGt9YuHjfUuOo1AUBnuMUfHKFT5TUB5UFTf5NehKYKpX99GIBa30GnIequ57Vx5TE42di8qtX+n 8tKnDSGeX9tcmecFwl6lbgqYSTrAKUSobho/RGvv/GTBMZGb0v7mo56wVl59DbZn9r8p+vBr/w3 KKL1srryl1w53p2h8oMlLaKq+BpRBggZvDHJE3ChFdsAjXilNcaQnsCHzMH8nVkgRUn6mkqSe0w yYSNCCFRx1/F2AiO2ChA3stWN68aNjWRJO5Sg0uT/t7w6Dh5wpnt+eJkmjQ2ByKmYn7KLQSvA1m hOTET1CCsgn+XBw== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 call_s_stream() uses sd->enabled_streams to track whether streaming has already been enabled. However, v4l2_subdev_enable/disable_streams_fallback(), which was the original user of this field, already uses it, and v4l2_subdev_enable/disable_streams_fallback() will call call_s_stream(). This leads to a conflict as both functions set the field. Afaics, both functions set the field to the same value, so it won't cause a runtime bug, but it's still wrong and if we, e.g., change how v4l2_subdev_enable/disable_streams_fallback() operates we might easily cause bugs. Fix this by adding a new field, 'streaming_enabled', for call_s_stream(). Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 8 ++------ include/media/v4l2-subdev.h | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index b90b5185e87f..3b3310bce5d4 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -404,12 +404,8 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) * The .s_stream() operation must never be called to start or stop an * already started or stopped subdev. Catch offenders but don't return * an error yet to avoid regressions. - * - * As .s_stream() is mutually exclusive with the .enable_streams() and - * .disable_streams() operation, we can use the enabled_streams field - * to store the subdev streaming state. */ - if (WARN_ON(!!sd->enabled_streams == !!enable)) + if (WARN_ON(!!sd->streaming_enabled == !!enable)) return 0; #if IS_REACHABLE(CONFIG_LEDS_CLASS) @@ -429,7 +425,7 @@ static int call_s_stream(struct v4l2_subdev *sd, int enable) } if (!ret) - sd->enabled_streams = enable ? BIT(0) : 0; + sd->streaming_enabled = !!enable; return ret; } diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index a9e6b8146279..8bd1e3c96d2b 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1043,6 +1043,7 @@ struct v4l2_subdev_platform_data { * 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 * stand-alone or embedded in a larger struct. @@ -1091,6 +1092,7 @@ struct v4l2_subdev { */ struct v4l2_subdev_state *active_state; u64 enabled_streams; + bool streaming_enabled; }; From patchwork Thu Apr 4 10:50:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13617573 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 CFCF9823DC; Thu, 4 Apr 2024 10:50:24 +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=1712227826; cv=none; b=PwT7Tht0tmsRCzMQ3nBDvZfDZRZxDV5/r8kQUo5Q2h5/JxSzgR3EqYR7KpbCJXsVUE7Q3q2OwgLS2/RaBRVoaO0RolNVCDdEZhDRA6+gyEyaxCjUYTfRvriARhWf3e393CeimBiRfWL9DqUQETsPwjinTnzz5bnoEq+meMsMx+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712227826; c=relaxed/simple; bh=6xModmV44eQ1wxMDDoC5M/XSmbDHzCEIS6vWiAXlbQU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Wbvw2qJhj+dZvQ6cqJGVr02sYhKBiIup0UqBoJV6arM0NnlMPnQIyHOswYUMIWapBVr6hzKOn2oNLMSALmQKvEAAirrJmI0QTF4k+Tet51wV13RpX7tvwWWkmD7xsQ/WmRKPD05VXSFJZC2zEAgmezbRcwXvMQKaANjfPDIgCKc= 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=hzMlX1H9; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="hzMlX1H9" Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 09069B9A; Thu, 4 Apr 2024 12:49:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712227783; bh=6xModmV44eQ1wxMDDoC5M/XSmbDHzCEIS6vWiAXlbQU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hzMlX1H9lL6oPnwooCWCEgcrpgxiVIhzb/EplIMg3N4hoLSn9WNwKrZmdSTfeC1WT PCP4jmnMehQhSdjx56nWx2iM0Co9P1Xa3P9zZ781WzcXlMJxPNTuSOrVO5WUGS9Ya9 SFRAWcqX9jWA0Mc3gPwPfmzNBCXZNXQdgJi7HDvA= From: Tomi Valkeinen Date: Thu, 04 Apr 2024 13:50:02 +0300 Subject: [PATCH 3/4] media: subdev: Improve v4l2_subdev_enable/disable_streams_fallback Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240404-enable-streams-impro-v1-3-1017a35bbe07@ideasonboard.com> References: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> In-Reply-To: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6382; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=6xModmV44eQ1wxMDDoC5M/XSmbDHzCEIS6vWiAXlbQU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmDoXqzUOii7XDdjTJn6I2i0gRonETw2qZXprZ3 l7KU4JNzyOJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZg6F6gAKCRD6PaqMvJYe 9XEjD/9MskIxC7waa4ouYtk/VC23zfMtGwJyPLaCqGqllsD4e/1Ygq8TXUPvLJjF7islq6teylQ 3hrNAzF84aIZt9gfmM1wc4p+0UiRHuZTr2fZR6ZElDMVLEd50i0xINIBYlwUGpyIp+m+rfk9TDb uJKKDzDaM0oM+7W6QMA0yHaDm8Ax9hsswu9sfRhGIL7uExA8L1REzQW3TIqCQdXFReACu2m7z+n cNPvXowTrJmJb7o+UiM39/7WO+juTRyozothrD1CHV8QSAUpbSp/NEMY2EoVMn3MXIQ9XNIkx5M XZcYR89HFnT905iOfynqVooEs1vv4Y6VC4zz/IyAcbWDf+/mJBRTfUN0Tvjf9GaDdKQsFtf3XmK 34xN2IOVaGdNrwY+9TY7t7uXRqujy3yCeMUUs/mFkmdx1TTP05Lr2Jclcftn+mZTEh+T+YAAQvP cwG9cXEd5jFJd0VTBuLbnwBlc3hKU/lfpub4ZFKkC+qt86YGmbgSYKFjlCHF6B1ey+JQ7ugKU9P JkBosrdtg0LGhPVAZSMnfazMFCx/BQtjcJrPtTbVq2ZMN5ibU9SqRdTkrXLFBAe4rh2dZeSu9KY x6HmyOiKMPB8/CEhbT+kjmxKHjexm0H0DHhiYfT9ZEJyZpDHwi2uYVx2EjlEQBeeVVoEC/HzCps RGD0zASxfNQ2shQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 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. 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. */ 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) + 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) + 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)) { + 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; }; From patchwork Thu Apr 4 10:50:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 13617574 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 1099680049; Thu, 4 Apr 2024 10:50: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=1712227829; cv=none; b=WlyTm0aJvbrlSdJ1O+zizwU0y/oqFSgUdgdnXgjKnn8HyWNN9WM7o5Lo7wxwySpEPlUShBOhyOgkdxbQMATCJ0aXondKrhcMQKF0X6SQMsL//muUrKJthZIb0Fm1ckscXFs/m19/lsruycsi5g2OpjIll3HBMXmvEDKDn1aLG0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712227829; c=relaxed/simple; bh=NEDsCxZIlpnO7rRc8IyLQGQLGkbh0uyi1WhbgqXQfFU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AMC+OSH1VIf7VIB7eOsQeblT/6Fy7IWAaJzSBua0G0ZukIjC7S6OZGahhcTzMsOS5sldqFX8SlaTPvVD8LQrPFK7fQ9w3VajbDDBhefDz4l2bnCay7TC7r2aVWkEihgVv+ffmyf7V6IJc14/hC+bKfLabuMVYsthFe4L7Ugp77A= 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=VhMFlkk6; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="VhMFlkk6" Received: from [127.0.1.1] (91-154-34-181.elisa-laajakaista.fi [91.154.34.181]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8DDF1DD9; Thu, 4 Apr 2024 12:49:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1712227783; bh=NEDsCxZIlpnO7rRc8IyLQGQLGkbh0uyi1WhbgqXQfFU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VhMFlkk6pEcu3tuxF+3fDunD2xwm7M0D6CWtUE5oHCw2KBUzWqxKWgkBI1OTFo6IK Pye//Wcm8AmRIm4JaXaB7uBqi+hKpZbX35pEiIJHXR0PF7ioDPrcmMJx6VXhDANOaB r+7vxfnF5E+T6jB8/xofQAQm18ca669ChR5tnTMs= From: Tomi Valkeinen Date: Thu, 04 Apr 2024 13:50:03 +0300 Subject: [PATCH 4/4] media: subdev: Support enable/disable_streams for non-streams subdevs Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240404-enable-streams-impro-v1-4-1017a35bbe07@ideasonboard.com> References: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> In-Reply-To: <20240404-enable-streams-impro-v1-0-1017a35bbe07@ideasonboard.com> To: Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , Sakari Ailus , Umang Jain Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Tomi Valkeinen X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5337; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=NEDsCxZIlpnO7rRc8IyLQGQLGkbh0uyi1WhbgqXQfFU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBmDoXqFohVFpUULWBUlLIViIKk91Jfv6PhrsZkZ fMmw/XvZmqJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZg6F6gAKCRD6PaqMvJYe 9Z+fD/9KOrPVPah8SEwDmaDK1l2KIzbllSd+JkpeTiqTQIO2TyV10TuAMp68mbjmYmNF38u+MhL R00MsxGzbAQB7QOnYtwK3x2L1LGNXE0d3vgOVDxvp0F7qw/LmB7gWDZ+IRo76URaynfI1VuXDaU r2yBktXURUK4XCHSkVbZdIrcb82aCSjlMA8+odLXXI3MrD1mioCNvqLKmBce2HWsnEhDwe5FnM8 gLcmpwcq4ikLmP0JMaBgq5dlXqPNJHEzpRDtEVyp/V5d45//XYvrwwYaf+8e0Cl+gijhmHpPjmr kmyoXADA3vxtXOr2P8zE/a8trcQUZjCMNC1ABTRzkYaOGcLfHZhI/Bc0gCWMi65T9Io2/joqJuP 3oJE43cJOs5kpfNLd6R6WPNRZyHrZhHsq/qK7IdPHXdOdMfJ/ox3KuqWo8THiG0jVDTRW7Pt+Lu jb68A0rgbl0OEROulg9jJwvazcIKwfsV9UB1crTMqW40BlU1RAA9Z2UoMlmdbs0zN64FwC2sGor zRjnnN6T7a9GeHd19xCexMklaLyfglK+mr0Z2ZxbJHvOe29WLYfJg4Xs6HGP1R8UeiIWPAfWzI3 6r7vKjn7SEJYHZX2Gy4g1xjmtRMFAq5kygIwexpse6XMgjEF2KHQ5eZhfRlX2dAuSZR6OP91Zld 3diEj4ToaQDF7Pg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 Currently a subdevice without streams support (V4L2_SUBDEV_FL_STREAMS), e.g. a sensor subdevice with a single source pad, must use the v4l2_subdev_video_ops.s_stream op, instead of v4l2_subdev_pad_ops.enable/disable_streams. This is because the enable/disable_streams machinery requires a routing table which a subdev cannot have with a single pad. Implement enable/disable_streams support for subdevs without streams support. As they don't support multiple streams, each pad must contain a single stream, with stream ID 0, and rather than tracking enabled streams, we can track enabled pads similarly to the enable/disable_streams_fallback by using the sd->enabled_pads field. Signed-off-by: Tomi Valkeinen --- drivers/media/v4l2-core/v4l2-subdev.c | 86 +++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 91298bb84e6b..d86f930be2c4 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -2158,21 +2158,32 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, * Verify that the requested streams exist and that they are not * already enabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + for (i = 0; i < state->stream_configs.num_configs; ++i) { + struct v4l2_subdev_stream_config *cfg = + &state->stream_configs.configs[i]; - if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) - continue; + if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) + continue; - found_streams |= BIT_ULL(cfg->stream); + found_streams |= BIT_ULL(cfg->stream); - if (cfg->enabled) { - dev_dbg(dev, "stream %u already enabled on %s:%u\n", - cfg->stream, sd->entity.name, pad); + if (cfg->enabled) { + dev_dbg(dev, "stream %u already enabled on %s:%u\n", + cfg->stream, sd->entity.name, pad); + ret = -EALREADY; + goto done; + } + } + } else { + if (sd->enabled_pads & BIT_ULL(pad)) { + dev_dbg(dev, "stream 0 already enabled on %s:%u\n", + sd->entity.name, pad); ret = -EALREADY; goto done; } + + found_streams = BIT_ULL(0); } if (found_streams != streams_mask) { @@ -2194,12 +2205,16 @@ int v4l2_subdev_enable_streams(struct v4l2_subdev *sd, u32 pad, } /* Mark the streams as enabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + for (i = 0; i < state->stream_configs.num_configs; ++i) { + struct v4l2_subdev_stream_config *cfg = + &state->stream_configs.configs[i]; - if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) - cfg->enabled = true; + if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) + cfg->enabled = true; + } + } else { + sd->enabled_pads |= BIT_ULL(pad); } done: @@ -2281,21 +2296,32 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, * Verify that the requested streams exist and that they are not * already disabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + for (i = 0; i < state->stream_configs.num_configs; ++i) { + struct v4l2_subdev_stream_config *cfg = + &state->stream_configs.configs[i]; - if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) - continue; + if (cfg->pad != pad || !(streams_mask & BIT_ULL(cfg->stream))) + continue; - found_streams |= BIT_ULL(cfg->stream); + found_streams |= BIT_ULL(cfg->stream); - if (!cfg->enabled) { - dev_dbg(dev, "stream %u already disabled on %s:%u\n", - cfg->stream, sd->entity.name, pad); + if (!cfg->enabled) { + dev_dbg(dev, "stream %u already disabled on %s:%u\n", + cfg->stream, sd->entity.name, pad); + ret = -EALREADY; + goto done; + } + } + } else { + if (!(sd->enabled_pads & BIT_ULL(pad))) { + dev_dbg(dev, "stream 0 already disabled on %s:%u\n", + sd->entity.name, pad); ret = -EALREADY; goto done; } + + found_streams = BIT_ULL(0); } if (found_streams != streams_mask) { @@ -2317,12 +2343,16 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad, } /* Mark the streams as disabled. */ - for (i = 0; i < state->stream_configs.num_configs; ++i) { - struct v4l2_subdev_stream_config *cfg = - &state->stream_configs.configs[i]; + if (sd->flags & V4L2_SUBDEV_FL_STREAMS) { + for (i = 0; i < state->stream_configs.num_configs; ++i) { + struct v4l2_subdev_stream_config *cfg = + &state->stream_configs.configs[i]; - if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) - cfg->enabled = false; + if (cfg->pad == pad && (streams_mask & BIT_ULL(cfg->stream))) + cfg->enabled = false; + } + } else { + sd->enabled_pads &= ~BIT_ULL(pad); } done: