From nobody Tue Apr 7 12:38:52 2026 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 3032A33A6E4; Wed, 25 Feb 2026 15:50:55 +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=1772034656; cv=none; b=JVQQOw+PaY/II0XYK9cBkNZZQCxBZBCATJX19l5QmlcgfWydtRivoqVcPF5fQSrBn5/EdegLgEljGY8xSCpdyuwbwXEesjBqcYBXRv0EQSx7I4cSrgnSwWJb22dNd0+jWiURRw6Tb3mKFkrMkGFrNALrWq+6xK4E7mXkkZ/Wu78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772034656; c=relaxed/simple; bh=smFfrRzEKdNjoLYHRo0jhHdJaoYxZoxc2lryZdiBvv4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p8EOopVZGWP2V+D2rVAhbIbq9GvRSakWuf1PCecI0b5Oyz0lLqqbxXD0Egr+lc23++ZlsyN6f3Q7oofvrDZzqBuGAAArzee4Lt0xq+PV9p4kZPaGkpThSIapU2P83wmcUqipSjszZsyklaEoPborwHctOsO+wyxF24DeJwglgfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (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=N/gRcgA+; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (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="N/gRcgA+" Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:cd05:b041:1dc3:f62c]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 3380BE79; Wed, 25 Feb 2026 16:49:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1772034596; bh=smFfrRzEKdNjoLYHRo0jhHdJaoYxZoxc2lryZdiBvv4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=N/gRcgA+KV77fREJ0MmYeN/v9n/MefI+pufdL4qAXUYXi8ow53Hywz+li3Ipc8ph+ RBBhkF5E8xJMhuKu4MFwC1Bx6qBeeXMkZVvKzkthBZpkTcQloRXk3WDYdW0jRQyNVn TOrpcP1wJC7PF+e1ZurWkqxLNIqH8IUTRKslf2Xw= From: Stefan Klug Date: Wed, 25 Feb 2026 16:50:47 +0100 Subject: [PATCH v4 1/4] media: dw100: Implement V4L2 requests support 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-Transfer-Encoding: quoted-printable Message-Id: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-1-53536d08de91@ideasonboard.com> References: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> In-Reply-To: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> To: Xavier Roumegue , Mauro Carvalho Chehab , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Nicolas Dufresne , Stefan Klug X-Mailer: b4 0.14.2 The dw100 dewarper hardware present on the NXP i.MX8MP allows very flexible dewarping using a freely configurable vertex map. Aside from lens dewarping the vertex map can be used to implement things like arbitrary zoom, pan and rotation. The current driver supports setting that vertex map before calling VIDIOC_STREAMON. To control above mentioned features during streaming it is necessary to update the vertex map dynamically. To do that in a race free manner V4L2 requests support is required. Add V4L2 requests support to prepare for dynamic vertex map updates. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart --- Changes in v4: - Improved commit message - Added comment above v4l2_ctrl_request_complete() - Collected tag Changes in v2: - Use v4l2_m2m_buf_done_and_job_finish() to mark the buffers as done in the correct order. Changes in v1: - Moved v4l2_ctrl_request_complete into dw100_device_run --- drivers/media/platform/nxp/dw100/dw100.c | 53 +++++++++++++++++++++++++---= ---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platf= orm/nxp/dw100/dw100.c index 4aaf9c3fff5397f0441944ee926f2c8ba6fc864a..e05a65e0122a2584992aefd1b8f= c70ce64e86bfb 100644 --- a/drivers/media/platform/nxp/dw100/dw100.c +++ b/drivers/media/platform/nxp/dw100/dw100.c @@ -459,6 +459,15 @@ static int dw100_queue_setup(struct vb2_queue *vq, return 0; } =20 +static int dw100_buf_out_validate(struct vb2_buffer *vb) +{ + struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); + + vbuf->field =3D V4L2_FIELD_NONE; + + return 0; +} + static int dw100_buf_prepare(struct vb2_buffer *vb) { unsigned int i; @@ -500,6 +509,13 @@ static void dw100_buf_queue(struct vb2_buffer *vb) v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vbuf); } =20 +static void dw100_buf_request_complete(struct vb2_buffer *vb) +{ + struct dw100_ctx *ctx =3D vb2_get_drv_priv(vb->vb2_queue); + + v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->hdl); +} + static void dw100_return_all_buffers(struct vb2_queue *q, enum vb2_buffer_state state) { @@ -553,11 +569,13 @@ static void dw100_stop_streaming(struct vb2_queue *q) } =20 static const struct vb2_ops dw100_qops =3D { - .queue_setup =3D dw100_queue_setup, - .buf_prepare =3D dw100_buf_prepare, - .buf_queue =3D dw100_buf_queue, - .start_streaming =3D dw100_start_streaming, - .stop_streaming =3D dw100_stop_streaming, + .queue_setup =3D dw100_queue_setup, + .buf_out_validate =3D dw100_buf_out_validate, + .buf_prepare =3D dw100_buf_prepare, + .buf_queue =3D dw100_buf_queue, + .start_streaming =3D dw100_start_streaming, + .stop_streaming =3D dw100_stop_streaming, + .buf_request_complete =3D dw100_buf_request_complete, }; =20 static int dw100_m2m_queue_init(void *priv, struct vb2_queue *src_vq, @@ -575,6 +593,7 @@ static int dw100_m2m_queue_init(void *priv, struct vb2_= queue *src_vq, src_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; src_vq->lock =3D &ctx->vq_mutex; src_vq->dev =3D ctx->dw_dev->v4l2_dev.dev; + src_vq->supports_requests =3D true; =20 ret =3D vb2_queue_init(src_vq); if (ret) @@ -1058,7 +1077,6 @@ static const struct v4l2_ioctl_ops dw100_ioctl_ops = =3D { static void dw100_job_finish(struct dw100_device *dw_dev, bool with_error) { struct dw100_ctx *curr_ctx; - struct vb2_v4l2_buffer *src_vb, *dst_vb; enum vb2_buffer_state buf_state; =20 curr_ctx =3D v4l2_m2m_get_curr_priv(dw_dev->m2m_dev); @@ -1069,16 +1087,13 @@ static void dw100_job_finish(struct dw100_device *d= w_dev, bool with_error) return; } =20 - src_vb =3D v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); - dst_vb =3D v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); - if (likely(!with_error)) buf_state =3D VB2_BUF_STATE_DONE; else buf_state =3D VB2_BUF_STATE_ERROR; =20 - v4l2_m2m_buf_done(src_vb, buf_state); - v4l2_m2m_buf_done(dst_vb, buf_state); + v4l2_m2m_buf_done_and_job_finish(dw_dev->m2m_dev, curr_ctx->fh.m2m_ctx, + buf_state); =20 dev_dbg(&dw_dev->pdev->dev, "Finishing transaction with%s error(s)\n", with_error ? "" : "out"); @@ -1460,6 +1475,16 @@ static void dw100_device_run(void *priv) src_buf =3D v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); dst_buf =3D v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); =20 + v4l2_ctrl_request_setup(src_buf->vb2_buf.req_obj.req, + &ctx->hdl); + + /* + * As the hardware does not update any volatile controls, we can + * complete control handling before starting the dewarper. + */ + v4l2_ctrl_request_complete(src_buf->vb2_buf.req_obj.req, + &ctx->hdl); + dw100_start(ctx, src_buf, dst_buf); } =20 @@ -1467,6 +1492,11 @@ static const struct v4l2_m2m_ops dw100_m2m_ops =3D { .device_run =3D dw100_device_run, }; =20 +static const struct media_device_ops dw100_m2m_media_ops =3D { + .req_validate =3D vb2_request_validate, + .req_queue =3D v4l2_m2m_request_queue, +}; + static struct video_device *dw100_init_video_device(struct dw100_device *d= w_dev) { struct video_device *vfd =3D &dw_dev->vfd; @@ -1578,6 +1608,7 @@ static int dw100_probe(struct platform_device *pdev) dw_dev->mdev.dev =3D &pdev->dev; strscpy(dw_dev->mdev.model, "dw100", sizeof(dw_dev->mdev.model)); media_device_init(&dw_dev->mdev); + dw_dev->mdev.ops =3D &dw100_m2m_media_ops; dw_dev->v4l2_dev.mdev =3D &dw_dev->mdev; =20 ret =3D video_register_device(vfd, VFL_TYPE_VIDEO, -1); --=20 2.51.0 From nobody Tue Apr 7 12:38:52 2026 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 619BE3D7D9F; Wed, 25 Feb 2026 15:50:57 +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=1772034659; cv=none; b=oji5Gnj1YxJnQksiii25cu3/CWLmK47wIrTqkp6Nqx8pGTIv/BO9bjKeL7PKWdPBRrpFBoV8K2yTR1vymVQFDdUWzq7Vw0izpF1fpmVvleLakPPgyeq/ogHoQtMdbZR78R4sOGfh2SPiy2vaT4EcmgFux8eGo5sQ7UOMdnpmbB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772034659; c=relaxed/simple; bh=OoG/1K9A8qjXykeY48UsilyxIkViXFpGFJO8t9YtmLI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iKcXZipk+upjf1LebVVqDw6MTjV+No5obERpudlnifLn5Is+CTAB0ptJVTmXNvNed3c5tO36MVKFolnZol08AMI9tSKeY7UIqXFMI5cVyRpkiRuUHAQpo1L4jgwIcI/v3U3xhE+jX1l0xTKA0HScclsyguqYr4QqXGxfnBiumac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (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=shP7c0sV; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (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="shP7c0sV" Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:cd05:b041:1dc3:f62c]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 96F94121A; Wed, 25 Feb 2026 16:49:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1772034598; bh=OoG/1K9A8qjXykeY48UsilyxIkViXFpGFJO8t9YtmLI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=shP7c0sVVi7zA8isn2bG8vmDyAnczDGsPxuABYKS7ByuDhHerIYhDz7MDMA2zjLCc shtGvFjDMgStmojxH+7q8knT9F5SZx0l6OaJuE+/s37kpkt/9IBE/4MWCJq4vhfu0t ygYvzAbxCC0bKtGYpbJNdVwWPLeU5D6i4g3olGLE= From: Stefan Klug Date: Wed, 25 Feb 2026 16:50:48 +0100 Subject: [PATCH v4 2/4] media: dw100: Implement dynamic vertex map update 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-Transfer-Encoding: quoted-printable Message-Id: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-2-53536d08de91@ideasonboard.com> References: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> In-Reply-To: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> To: Xavier Roumegue , Mauro Carvalho Chehab , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Nicolas Dufresne , Stefan Klug X-Mailer: b4 0.14.2 Implement dynamic vertex map updates by handling the V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP control during streaming. This allows to implement features like dynamic zoom, pan, rotate and dewarp. To stay compatible with the old version, updates of V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP are ignored during streaming when requests are not used. Print a corresponding warning once. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart --- Changes in v4: - Added missing newline at end of warning message - Fixed position of closing parenthesis - Collected tag Changes in v2: - Replaced the manual warn once by dev_warn_once(). This changes the frequency from once per context to once per boot which was agreed to be enough. - Renamed user_map_needs_update to user_map_is_dirty as it is more expressive and fits to user_map_is_set - Fixed indentation issue found by Media CI --- drivers/media/platform/nxp/dw100/dw100.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platf= orm/nxp/dw100/dw100.c index e05a65e0122a2584992aefd1b8fc70ce64e86bfb..2d5c3199428dfa38d1bb2539238= 63b8137a8bea4 100644 --- a/drivers/media/platform/nxp/dw100/dw100.c +++ b/drivers/media/platform/nxp/dw100/dw100.c @@ -98,6 +98,7 @@ struct dw100_ctx { unsigned int map_width; unsigned int map_height; bool user_map_is_set; + bool user_map_is_dirty; =20 /* Source and destination queue data */ struct dw100_q_data q_data[2]; @@ -293,11 +294,15 @@ static u32 dw100_map_format_coordinates(u16 xq, u16 y= q) return (u32)((yq << 16) | xq); } =20 -static u32 *dw100_get_user_map(struct dw100_ctx *ctx) +static void dw100_update_mapping(struct dw100_ctx *ctx) { struct v4l2_ctrl *ctrl =3D ctx->ctrls[DW100_CTRL_DEWARPING_MAP]; =20 - return ctrl->p_cur.p_u32; + if (!ctx->user_map_is_dirty) + return; + + memcpy(ctx->map, ctrl->p_cur.p_u32, ctx->map_size); + ctx->user_map_is_dirty =3D false; } =20 /* @@ -306,8 +311,6 @@ static u32 *dw100_get_user_map(struct dw100_ctx *ctx) */ static int dw100_create_mapping(struct dw100_ctx *ctx) { - u32 *user_map; - if (ctx->map) dma_free_coherent(&ctx->dw_dev->pdev->dev, ctx->map_size, ctx->map, ctx->map_dma); @@ -318,8 +321,8 @@ static int dw100_create_mapping(struct dw100_ctx *ctx) if (!ctx->map) return -ENOMEM; =20 - user_map =3D dw100_get_user_map(ctx); - memcpy(ctx->map, user_map, ctx->map_size); + ctx->user_map_is_dirty =3D true; + dw100_update_mapping(ctx); =20 dev_dbg(&ctx->dw_dev->pdev->dev, "%ux%u %s mapping created (d:%pad-c:%p) for stream %ux%u->%ux%u\n", @@ -351,6 +354,7 @@ static int dw100_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP: ctx->user_map_is_set =3D true; + ctx->user_map_is_dirty =3D true; break; } =20 @@ -405,6 +409,7 @@ static void dw100_ctrl_dewarping_map_init(const struct = v4l2_ctrl *ctrl, } =20 ctx->user_map_is_set =3D false; + ctx->user_map_is_dirty =3D true; } =20 static const struct v4l2_ctrl_type_ops dw100_ctrl_type_ops =3D { @@ -1478,6 +1483,12 @@ static void dw100_device_run(void *priv) v4l2_ctrl_request_setup(src_buf->vb2_buf.req_obj.req, &ctx->hdl); =20 + if (src_buf->vb2_buf.req_obj.req) + dw100_update_mapping(ctx); + else if (ctx->user_map_is_dirty) + dev_warn_once(&ctx->dw_dev->pdev->dev, + "V4L2 requests are required to update the vertex map dynamically\= n"); + /* * As the hardware does not update any volatile controls, we can * complete control handling before starting the dewarper. --=20 2.51.0 From nobody Tue Apr 7 12:38:52 2026 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 3713A3D905A; Wed, 25 Feb 2026 15:51:00 +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=1772034661; cv=none; b=MQuAlxWcDGyVTWOxW+1LUPY8OJPlAYq++3AfGj9NCjcMQbaimtIAZGVrcxInI1aCxZUQcUk1vLU0bJiaFzRx1OJwl7YpV2Tohb+dJnEF3lpzO8ziC/Lo9Zce5rt9/dfgNwbRrZXU6NczJ45iiXBHIT95GwOA5RHHnVafLIYaugw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772034661; c=relaxed/simple; bh=SdyL16nC6V4cyutE1SUgo0NkRwcZhSRaWCkr27A6hkA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uNcsX28L4+GE4GqXkSGMjm3A382oAoWlKHJuSvztZVnaBpCINPVzSfGZwL4CYJpoOgr684y9z59GBmJypizLMfmkdahWBfBJJTMwettyX6NCqXRKQKwV2dokYWzjkSqZqHOL98O8qBmC4lcld8mIcHYBZb+Dlor1ba4btRo6rB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (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=SirGKD0h; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (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="SirGKD0h" Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:cd05:b041:1dc3:f62c]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 6A0F1448; Wed, 25 Feb 2026 16:50:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1772034601; bh=SdyL16nC6V4cyutE1SUgo0NkRwcZhSRaWCkr27A6hkA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SirGKD0hljakAXS/gqJOQlKrmX94SWCCMzv/wwGkzp5bS9zNv4kpcwZiE6+xCzQR6 tHjOn2eiblTGG7NJIGxJd4IaDDY2afbkZg66bT6gSnsen8JBOtzb8oRMyUbfh5dKDe KHP7q4+Odv8sYSrbrF1NUkcLSN6GmHCih2osovZU= From: Stefan Klug Date: Wed, 25 Feb 2026 16:50:49 +0100 Subject: [PATCH v4 3/4] media: dw100: Fix kernel oops with PREEMPT_RT enabled 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-Transfer-Encoding: quoted-printable Message-Id: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-3-53536d08de91@ideasonboard.com> References: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> In-Reply-To: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> To: Xavier Roumegue , Mauro Carvalho Chehab , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Nicolas Dufresne , Stefan Klug X-Mailer: b4 0.14.2 On kernels with PREEMPT_RT enabled, a "BUG: scheduling while atomic" kernel oops occurs inside dw100_irq_handler -> vb2_buffer_done. This is because vb2_buffer_done takes a spinlock which is not allowed within interrupt context on PREEMPT_RT. The first attempt to fix this was to just drop the IRQF_ONESHOT so that the interrupt is handled threaded on PREEMPT_RT systems. This introduced a new issue. The dw100 has an internal timeout counter that is gated by the DW100_BUS_CTRL_AXI_MASTER_ENABLE bit. Depending on the time it takes for the threaded handler to run and the geometry of the data being processed it is possible to reach the timeout resulting in DW100_INTERRUPT_STATUS_INT_ERR_TIME_OUT being set and "dw100 32e30000.dwe: Interrupt error: 0x1" errors in dmesg. To properly fix that, split the interrupt into two halves, reset the DW100_BUS_CTRL_AXI_MASTER_ENABLE bit in the hard interrupt handler and do the v4l2 buffer handling in the threaded half. The IRQF_ONESHOT can still be dropped as the interrupt gets disabled in the hard handler and will only be reenabled on the next dw100_device_run which will not be called before the current job has finished. Signed-off-by: Stefan Klug Reviewed-by: Xavier Roumegue Reviewed-by: Laurent Pinchart --- Thank you Xavier for the technical support and further details on the interrupt bit. Changes in v4: - Collected tags - Fixed include order Changes in v3: - Split interrupt in two halves to prevent timeout error - Dropped rby tags, as the patch changed substantially Changes in v2: - Dropped the IRQF_ONESHOT instead of making the interrupt handler threaded to fix the issue. - I didn't keep the r-by tag from Nicolas as the solution is now a different one. --- drivers/media/platform/nxp/dw100/dw100.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platf= orm/nxp/dw100/dw100.c index 2d5c3199428dfa38d1bb253923863b8137a8bea4..a80139427f19942cdc61838afdc= cb8ef45bcda34 100644 --- a/drivers/media/platform/nxp/dw100/dw100.c +++ b/drivers/media/platform/nxp/dw100/dw100.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,7 @@ struct dw100_device { struct clk_bulk_data *clks; int num_clks; struct dentry *debugfs_root; + bool frame_failed; }; =20 struct dw100_q_data { @@ -1406,7 +1408,8 @@ static irqreturn_t dw100_irq_handler(int irq, void *d= ev_id) { struct dw100_device *dw_dev =3D dev_id; u32 pending_irqs, err_irqs, frame_done_irq; - bool with_error =3D true; + + dw_dev->frame_failed =3D true; =20 pending_irqs =3D dw_hw_get_pending_irqs(dw_dev); frame_done_irq =3D pending_irqs & DW100_INTERRUPT_STATUS_INT_FRAME_DONE; @@ -1414,7 +1417,7 @@ static irqreturn_t dw100_irq_handler(int irq, void *d= ev_id) =20 if (frame_done_irq) { dev_dbg(&dw_dev->pdev->dev, "Frame done interrupt\n"); - with_error =3D false; + dw_dev->frame_failed =3D false; err_irqs &=3D ~DW100_INTERRUPT_STATUS_INT_ERR_STATUS (DW100_INTERRUPT_STATUS_INT_ERR_FRAME_DONE); } @@ -1427,7 +1430,14 @@ static irqreturn_t dw100_irq_handler(int irq, void *= dev_id) dw100_hw_clear_irq(dw_dev, pending_irqs | DW100_INTERRUPT_STATUS_INT_ERR_TIME_OUT); =20 - dw100_job_finish(dw_dev, with_error); + return IRQ_WAKE_THREAD; +} + +static irqreturn_t dw100_irq_thread_fn(int irq, void *dev_id) +{ + struct dw100_device *dw_dev =3D dev_id; + + dw100_job_finish(dw_dev, dw_dev->frame_failed); =20 return IRQ_HANDLED; } @@ -1596,8 +1606,9 @@ static int dw100_probe(struct platform_device *pdev) =20 pm_runtime_put_sync(&pdev->dev); =20 - ret =3D devm_request_irq(&pdev->dev, irq, dw100_irq_handler, IRQF_ONESHOT, - dev_name(&pdev->dev), dw_dev); + ret =3D devm_request_threaded_irq(&pdev->dev, irq, dw100_irq_handler, + dw100_irq_thread_fn, 0, + dev_name(&pdev->dev), dw_dev); if (ret < 0) { dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); goto err_pm; --=20 2.51.0 From nobody Tue Apr 7 12:38:52 2026 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 66D553DA7F8; Wed, 25 Feb 2026 15:51:03 +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=1772034664; cv=none; b=DebtWuHwjqCgZX86ZSDoKYIdLoKNjIqP9vKiKAiyzCySdyP9cts2WhxzM0HVKmy6S+44phNBs11uQVNP6RMmS9WNwcpmbrhtKAnrwApNjZyUXNDTjgwUszv/Jp79WDfFIwduIJ05sVXCzwq1d1OKqPhqpNPGfiriYQUGXUPPemM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772034664; c=relaxed/simple; bh=IPoW0hAdPmyxLojSbJoofjfzT0HDKdluoXNZXbT9mVI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q1tEE/etmunzR+2J9mnoobyWFzV/sey1Kz2uhEnjvXi83yzXb4AYNX3iYCAWoiBWmjk5zmVVHYZn0tJGalY6t0BFyLUNGZIPLMCM8ilf2kBv0En9eJzLYSOGB17RDz+nxZHlEZxsDIyrGSiogE1StyEz4Yzra6mWxGJtSzYBAeI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (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=kQzTaUXU; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (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="kQzTaUXU" Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:cd05:b041:1dc3:f62c]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id A7237E79; Wed, 25 Feb 2026 16:50:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1772034604; bh=IPoW0hAdPmyxLojSbJoofjfzT0HDKdluoXNZXbT9mVI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kQzTaUXU6ctUbmvQCO0JZkMQJfYnddMqmYpmoMUPfov3rWN40OheEmUPEEuk/Jj9/ itvvMoY0rkO0EVJ2d5OXL/AKqW6zzOtn/1GirM+GJ5JoaTzd0QjgQdFgWRjuym+bR7 4y/S2w9RlGEdnzoLAkgMvfn8I18nMlWFWgOr9ujQ= From: Stefan Klug Date: Wed, 25 Feb 2026 16:50:50 +0100 Subject: [PATCH v4 4/4] media: dw100: Merge dw100_device_run and dw100_start 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-Transfer-Encoding: quoted-printable Message-Id: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-4-53536d08de91@ideasonboard.com> References: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> In-Reply-To: <20260225-sklug-v6-16-topic-dw100-v3-1-dev-v4-0-53536d08de91@ideasonboard.com> To: Xavier Roumegue , Mauro Carvalho Chehab , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev, Nicolas Dufresne , Stefan Klug X-Mailer: b4 0.14.2 The dw100_start() function is only called from dw100_device_run(). As both functions are not too big, move the code directly into dw100_device_run() and drop dw100_start() to improve readability. This patch contains no functional changes. Signed-off-by: Stefan Klug Reviewed-by: Xavier Roumegue Reviewed-by: Laurent Pinchart --- Changes in v4: - Collected tags Changes in v3: - Added this patch as proposed in the review of v1 --- drivers/media/platform/nxp/dw100/dw100.c | 77 +++++++++++++++-------------= ---- 1 file changed, 35 insertions(+), 42 deletions(-) diff --git a/drivers/media/platform/nxp/dw100/dw100.c b/drivers/media/platf= orm/nxp/dw100/dw100.c index a80139427f19942cdc61838afdccb8ef45bcda34..e59361aeeec73ee0df0b86159c3= b3c19f2eb8b5f 100644 --- a/drivers/media/platform/nxp/dw100/dw100.c +++ b/drivers/media/platform/nxp/dw100/dw100.c @@ -1442,49 +1442,10 @@ static irqreturn_t dw100_irq_thread_fn(int irq, voi= d *dev_id) return IRQ_HANDLED; } =20 -static void dw100_start(struct dw100_ctx *ctx, struct vb2_v4l2_buffer *in_= vb, - struct vb2_v4l2_buffer *out_vb) -{ - struct dw100_device *dw_dev =3D ctx->dw_dev; - - out_vb->sequence =3D - dw100_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)->sequence++; - in_vb->sequence =3D - dw100_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)->sequence++; - - dev_dbg(&ctx->dw_dev->pdev->dev, - "Starting queues %p->%p, sequence %u->%u\n", - v4l2_m2m_get_vq(ctx->fh.m2m_ctx, - V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE), - v4l2_m2m_get_vq(ctx->fh.m2m_ctx, - V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE), - in_vb->sequence, out_vb->sequence); - - v4l2_m2m_buf_copy_metadata(in_vb, out_vb); - - /* Now, let's deal with hardware ... */ - dw100_hw_master_bus_disable(dw_dev); - dw100_hw_init_ctrl(dw_dev); - dw100_hw_set_pixel_boundary(dw_dev); - dw100_hw_set_src_crop(dw_dev, &ctx->q_data[DW100_QUEUE_SRC], - &ctx->q_data[DW100_QUEUE_DST]); - dw100_hw_set_source(dw_dev, &ctx->q_data[DW100_QUEUE_SRC], - &in_vb->vb2_buf); - dw100_hw_set_destination(dw_dev, &ctx->q_data[DW100_QUEUE_DST], - ctx->q_data[DW100_QUEUE_SRC].fmt, - &out_vb->vb2_buf); - dw100_hw_set_mapping(dw_dev, ctx->map_dma, - ctx->map_width, ctx->map_height); - dw100_hw_enable_irq(dw_dev); - dw100_hw_dewarp_start(dw_dev); - - /* Enable Bus */ - dw100_hw_master_bus_enable(dw_dev); -} - static void dw100_device_run(void *priv) { struct dw100_ctx *ctx =3D priv; + struct dw100_device *dw_dev =3D ctx->dw_dev; struct vb2_v4l2_buffer *src_buf, *dst_buf; =20 src_buf =3D v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); @@ -1496,7 +1457,7 @@ static void dw100_device_run(void *priv) if (src_buf->vb2_buf.req_obj.req) dw100_update_mapping(ctx); else if (ctx->user_map_is_dirty) - dev_warn_once(&ctx->dw_dev->pdev->dev, + dev_warn_once(&dw_dev->pdev->dev, "V4L2 requests are required to update the vertex map dynamically\= n"); =20 /* @@ -1506,7 +1467,39 @@ static void dw100_device_run(void *priv) v4l2_ctrl_request_complete(src_buf->vb2_buf.req_obj.req, &ctx->hdl); =20 - dw100_start(ctx, src_buf, dst_buf); + src_buf->sequence =3D + dw100_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)->sequence++; + dst_buf->sequence =3D + dw100_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)->sequence++; + + dev_dbg(&dw_dev->pdev->dev, + "Starting queues %p->%p, sequence %u->%u\n", + v4l2_m2m_get_vq(ctx->fh.m2m_ctx, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE), + v4l2_m2m_get_vq(ctx->fh.m2m_ctx, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE), + src_buf->sequence, dst_buf->sequence); + + v4l2_m2m_buf_copy_metadata(src_buf, dst_buf); + + /* Now, let's deal with hardware ... */ + dw100_hw_master_bus_disable(dw_dev); + dw100_hw_init_ctrl(dw_dev); + dw100_hw_set_pixel_boundary(dw_dev); + dw100_hw_set_src_crop(dw_dev, &ctx->q_data[DW100_QUEUE_SRC], + &ctx->q_data[DW100_QUEUE_DST]); + dw100_hw_set_source(dw_dev, &ctx->q_data[DW100_QUEUE_SRC], + &src_buf->vb2_buf); + dw100_hw_set_destination(dw_dev, &ctx->q_data[DW100_QUEUE_DST], + ctx->q_data[DW100_QUEUE_SRC].fmt, + &dst_buf->vb2_buf); + dw100_hw_set_mapping(dw_dev, ctx->map_dma, + ctx->map_width, ctx->map_height); + dw100_hw_enable_irq(dw_dev); + dw100_hw_dewarp_start(dw_dev); + + /* Enable Bus */ + dw100_hw_master_bus_enable(dw_dev); } =20 static const struct v4l2_m2m_ops dw100_m2m_ops =3D { --=20 2.51.0