From patchwork Mon Jun 3 15:25:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 102168 Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sE9Zm-00064V-0X for patchwork@linuxtv.org; Mon, 03 Jun 2024 15:26:22 +0000 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8C17B1F22E4F for ; Mon, 3 Jun 2024 15:26:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAD0B1304BF; Mon, 3 Jun 2024 15:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="H61bxHfG" X-Original-To: linux-media@vger.kernel.org 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 1AA7612CDBA for ; Mon, 3 Jun 2024 15:26:11 +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=1717428373; cv=none; b=mHpZZ//qaYSiAZkTUMUl+UCynn6uAbkEg9sw+zmAdmoE0BI51LwZQPJgSLB8v0vu14meeVcqUKOic0i6SrcLLuTTZtLg2Zu4FrlgPhG7cigS1p1AkwThWkBi70QGPkBVBK7k+5OmK/cy6igss0sz6zaECeShTK7kzTREmRZo9+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717428373; c=relaxed/simple; bh=tiJLXtDkSIMar4/Di3c82hBxDKnQveLEddpdC0yDe40=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ln6NhVGZk1CxguTc9hGvSwp3k5YEeJhKi+M1mA2Eupdvqu+tj8LrRuibmNwYZsHCnAQNCvVk4nh8aVjAGT0os2CfRRSUKkK5cDNxwHeUIMa/zQMfofXnKlqtlLVLm0anT6aOx6dZFWlgzAZtgn1v02s3fBLFfmig8Wsd07DQuFM= 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=H61bxHfG; 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 localhost.localdomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DC454908; Mon, 3 Jun 2024 17:25:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717428357; bh=tiJLXtDkSIMar4/Di3c82hBxDKnQveLEddpdC0yDe40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H61bxHfG0zO7sn9unKgA7ngkzaOzhTUCZwUyBJBctFqMrwZaMhdfftHs95BtJhuSO F1vPW2NpOgS0XZrzByVAd3YkyNDXQkMkbkRI/okHDRgJeLjmCMSL2idQd7Ph6NvTic lqmQW+2sZFJC6+VR3Ilg8xFxJYdCt3/mtHevMHqk= From: Jacopo Mondi To: Hans Verkuil , Laurent Pinchart , Sakari Ailus Cc: Jacopo Mondi , Linux Media Mailing List Subject: [RFC 1/3] media: videobuf2: WARN if !vb2_queue.buf_ops Date: Mon, 3 Jun 2024 17:25:45 +0200 Message-ID: <20240603152548.107158-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> References: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_NONE=-0.0001,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no The videobuf2 framework unconditionally set 'struct vb2_queue.buf_ops' to 'v4l2_buf_ops' in vb2_queue_init_name() and does not allow drivers to overwrite it. The framework then assumes all 'buf_ops' operations to be present and valid. To prepare for allowing drivers to override the 'buf_ops' members implementation but still guarantee all members are correctly populated and valid, WARN() if any of the 'buf_ops' operations is not available in the function call wrappers. Signed-off-by: Jacopo Mondi --- drivers/media/common/videobuf2/videobuf2-core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index b6bf8f232f48..8ceae97a0f08 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -187,15 +187,19 @@ module_param(debug, int, 0644); #define call_bufop(q, op, args...) \ ({ \ int ret = 0; \ - if (q && q->buf_ops && q->buf_ops->op) \ - ret = q->buf_ops->op(args); \ + if (q) { \ + if (!WARN_ON(!q->buf_ops) && !WARN_ON(!q->buf_ops->op)) \ + ret = q->buf_ops->op(args); \ + } \ ret; \ }) #define call_void_bufop(q, op, args...) \ ({ \ - if (q && q->buf_ops && q->buf_ops->op) \ - q->buf_ops->op(args); \ + if (q) { \ + if (!WARN_ON(!q->buf_ops) && !WARN_ON(!q->buf_ops->op)) \ + q->buf_ops->op(args); \ + } \ }) static void __vb2_queue_cancel(struct vb2_queue *q); From patchwork Mon Jun 3 15:25:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 102169 Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sE9Zm-00064f-2v for patchwork@linuxtv.org; Mon, 03 Jun 2024 15:26:23 +0000 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 7899D1C21DE1 for ; Mon, 3 Jun 2024 15:26:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDC73130A68; Mon, 3 Jun 2024 15:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ILUpDM7g" X-Original-To: linux-media@vger.kernel.org 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 1576D1304AB for ; Mon, 3 Jun 2024 15:26:12 +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=1717428374; cv=none; b=AX8l6BQjmFDa4beG259jkm5EBVgIZkhf+Fv8zdHi/pz4X/9mSIeuJUl910oGY6Oj5C61ZH/RiOSAA4NLlFRlnQi1NN3RnRmO6KgPbkrN9wZpARpr/2PqpxIa1LX3wNXui5JlPmFjNCuzYavPkUOV7COj0JYY7DCyN5mmXoQQVp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717428374; c=relaxed/simple; bh=y4loEvae4OFBUxudyLwugcLcy6esOC6dL1h0jU794tA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F9vGqKvW9RtXet57QP5nPfJXgZywCGNzad5iMCYkjlZoyYQUL7M1g5AjM2F/uy96J/8XfSEyW9RFfZ9JSXlCMgH1P77zow4axPoCPnXJHrf3fLCVgx7toZEv0V4x29EM3huX1ejr+TRIxCbTQZxIbGjAr3oSRiPg9UMM0q0te+k= 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=ILUpDM7g; 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 localhost.localdomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5A72EA38; Mon, 3 Jun 2024 17:25:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717428357; bh=y4loEvae4OFBUxudyLwugcLcy6esOC6dL1h0jU794tA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILUpDM7gh/vqdcViDvEP30KqsVUrU6/6fLhdqvhw8Y2JH6b7XKLkbVaX3Qo3WiQ+4 TixtPqn8LpPDXS4tWku82MyJeJXwDtoMaPkAiMNZZ5A29QdktHbyRXBPXE50DkbWQi 2t2sCWlXj5JuOTA2NpAeC3F2ICX9PqmE/twvIvW0= From: Jacopo Mondi To: Hans Verkuil , Laurent Pinchart , Sakari Ailus Cc: Jacopo Mondi , Linux Media Mailing List Subject: [RFC 2/3] media: Allow drivers to overwrite vb2_queue.buf_ops Date: Mon, 3 Jun 2024 17:25:46 +0200 Message-ID: <20240603152548.107158-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> References: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no The 'struct vb2_queue.buf_ops' operations are described as 'driver specific callbacks' in the 'struct vb2_buf_ops' documentation but are actually not overridable by drivers. Allow driver to override the operations by: 1) Exporting core helper function with the vb2_buf_ naming 2) Conditionally set 'struct vb2_queue.buf_ops' in 'vb2_queue_init_name()' only if the driver has not set it already at queue initialization time As the videobuf2 framework assumes all the operations to be available, drivers that are willing to ovveride vb2_queue.buf_ops shall 1) Populate all members of 'struct vb2_buf_ops' 2) Call the core helper as part of their implementations, before or after the driver-specific bits --- .../media/common/videobuf2/videobuf2-v4l2.c | 34 +++++++++++-------- include/media/videobuf2-core.h | 7 ++++ include/media/videobuf2-v4l2.h | 8 +++++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index c575198e8354..30e04ed2e3a5 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -83,10 +83,11 @@ static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer return 0; } -static int __verify_planes_array_core(struct vb2_buffer *vb, const void *pb) +int vb2_buf_verify_planes_array(struct vb2_buffer *vb, const void *pb) { return __verify_planes_array(vb, pb); } +EXPORT_SYMBOL_GPL(vb2_buf_verify_planes_array); /* * __verify_length() - Verify that the bytesused value for each plane fits in @@ -129,16 +130,17 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b) } /* - * __init_vb2_v4l2_buffer() - initialize the vb2_v4l2_buffer struct + * vb2_buf_init_buffer() - initialize the vb2_v4l2_buffer struct */ -static void __init_vb2_v4l2_buffer(struct vb2_buffer *vb) +void vb2_buf_init_buffer(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); vbuf->request_fd = -1; } +EXPORT_SYMBOL_GPL(vb2_buf_init_buffer); -static void __copy_timestamp(struct vb2_buffer *vb, const void *pb) +void vb2_buf_copy_timestamp(struct vb2_buffer *vb, const void *pb) { const struct v4l2_buffer *b = pb; struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); @@ -156,6 +158,7 @@ static void __copy_timestamp(struct vb2_buffer *vb, const void *pb) vbuf->timecode = b->timecode; } }; +EXPORT_SYMBOL_GPL(vb2_buf_copy_timestamp); static void vb2_warn_zero_bytesused(struct vb2_buffer *vb) { @@ -473,10 +476,10 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md } /* - * __fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be + * vb2_buf_fill_v4l2_buffer() - fill in a struct v4l2_buffer with information to be * returned to userspace */ -static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) +void vb2_buf_fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) { struct v4l2_buffer *b = pb; struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); @@ -579,13 +582,14 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) b->request_fd = vbuf->request_fd; } } +EXPORT_SYMBOL_GPL(vb2_buf_fill_v4l2_buffer); /* - * __fill_vb2_buffer() - fill a vb2_buffer with information provided in a + * vb2_buf_fill_vb2_buffer() - fill a vb2_buffer with information provided in a * v4l2_buffer by the userspace. It also verifies that struct * v4l2_buffer has a valid number of planes. */ -static int __fill_vb2_buffer(struct vb2_buffer *vb, struct vb2_plane *planes) +int vb2_buf_fill_vb2_buffer(struct vb2_buffer *vb, struct vb2_plane *planes) { struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); unsigned int plane; @@ -603,13 +607,14 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb, struct vb2_plane *planes) } return 0; } +EXPORT_SYMBOL_GPL(vb2_buf_fill_vb2_buffer); static const struct vb2_buf_ops v4l2_buf_ops = { - .verify_planes_array = __verify_planes_array_core, - .init_buffer = __init_vb2_v4l2_buffer, - .fill_user_buffer = __fill_v4l2_buffer, - .fill_vb2_buffer = __fill_vb2_buffer, - .copy_timestamp = __copy_timestamp, + .verify_planes_array = vb2_buf_verify_planes_array, + .init_buffer = vb2_buf_init_buffer, + .fill_user_buffer = vb2_buf_fill_v4l2_buffer, + .fill_vb2_buffer = vb2_buf_fill_vb2_buffer, + .copy_timestamp = vb2_buf_copy_timestamp, }; struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp) @@ -921,7 +926,8 @@ int vb2_queue_init_name(struct vb2_queue *q, const char *name) if (q->buf_struct_size == 0) q->buf_struct_size = sizeof(struct vb2_v4l2_buffer); - q->buf_ops = &v4l2_buf_ops; + if (!q->buf_ops) + q->buf_ops = &v4l2_buf_ops; q->is_multiplanar = V4L2_TYPE_IS_MULTIPLANAR(q->type); q->is_output = V4L2_TYPE_IS_OUTPUT(q->type); q->copy_timestamp = (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 8b86996b2719..6f8df9acf6a2 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -455,6 +455,13 @@ struct vb2_ops { /** * struct vb2_buf_ops - driver-specific callbacks. * + * These operations are called by the videobuf2 framework unconditionally. + * Drivers are allowed to override some of the operations but shall: + * + * a) Populate all the members of this structure + * b) Call the generic core helper as part of their own implementations (see + * vb2_buf_* helpers in videobuf2-v4l2.h) + * * @verify_planes_array: Verify that a given user space structure contains * enough planes for the buffer. This is called * for each dequeued buffer. diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 5a845887850b..7c6cea933e28 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -383,6 +383,14 @@ void vb2_ops_wait_prepare(struct vb2_queue *vq); */ void vb2_ops_wait_finish(struct vb2_queue *vq); +/* struct vb2_buf_ops helpers */ + +int vb2_buf_verify_planes_array(struct vb2_buffer *vb, const void *pb); +void vb2_buf_init_buffer(struct vb2_buffer *vb); +void vb2_buf_fill_v4l2_buffer(struct vb2_buffer *vb, void *pb); +int vb2_buf_fill_vb2_buffer(struct vb2_buffer *vb, struct vb2_plane *planes); +void vb2_buf_copy_timestamp(struct vb2_buffer *vb, const void *pb); + struct media_request; int vb2_request_validate(struct media_request *req); void vb2_request_queue(struct media_request *req); From patchwork Mon Jun 3 15:25:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 102170 Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sE9Zp-000655-34 for patchwork@linuxtv.org; Mon, 03 Jun 2024 15:26:26 +0000 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 92FF31C21E09 for ; Mon, 3 Jun 2024 15:26:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D6FA1304AB; Mon, 3 Jun 2024 15:26:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZeZZg2+k" X-Original-To: linux-media@vger.kernel.org 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 71AD4130AD7 for ; Mon, 3 Jun 2024 15:26:15 +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=1717428376; cv=none; b=Lc17mr+w68KH/xX6Ibhu0WseH2gMwFgECpz1PDwRMgATRgjk5bNbX9WA8CIXvGBbPeLZwqXw1ue+qpP4VT75zT9H1KeYL0wOPdEaOmbg7J3EVVnBT/YvIfpRPKoij+qNGj4bzRmQ65MXs3/jUPEaDlcUWoQV4wBtbU9eOKMxKY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717428376; c=relaxed/simple; bh=9O8t5m1mlX4rkc/5G9S7+wYDmYmy28rOsQ65BjEzKWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ODxT2uhW4f8S8u5LwN8jYSFEMRp1hD35LGC4eaI3djDFdv4B5QhpoTBQEMHvHhLnqJjYnMJ24st2MTpCG3szVzGELwJhFSl+Hgghoyz8Dcts3fB3PGCVKTjSSJOS4hd54kV3fj7FhfwlZajs7kvpV48+kDALJV+tX5NBU9/snFU= 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=ZeZZg2+k; 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 localhost.localdomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CD0F8C67; Mon, 3 Jun 2024 17:25:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1717428358; bh=9O8t5m1mlX4rkc/5G9S7+wYDmYmy28rOsQ65BjEzKWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZeZZg2+kEw1AHxSoWpVh/9xRVRxOBGSk3r0kU+Jv6yZYFqaXLHdtxqA24tFsgh6Tp eD9F5DlUGke+8TvEsIbTHxUQ0pUOPDBTAFSuGKCfWiPBo2+fBAgXC5YYCZrkGGcT60 jN/IJdaSJMbTToFSTGb7+0FaWhyEio/3e6FmsUnY= From: Jacopo Mondi To: Hans Verkuil , Laurent Pinchart , Sakari Ailus Cc: Jacopo Mondi , Linux Media Mailing List Subject: [RFC 3/3] media: rkisp1-params: Override vb2_queue.buf_ops Date: Mon, 3 Jun 2024 17:25:47 +0200 Message-ID: <20240603152548.107158-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> References: <20240603152548.107158-1-jacopo.mondi@ideasonboard.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_MISSING=0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no Override the implementation of vb2_queue.buf_ops to allow a driver-specific behaviour in the buffer initialization operation. Signed-off-by: Jacopo Mondi --- .../platform/rockchip/rkisp1/rkisp1-params.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c index 0290f25a4ab6..4bb92d076e84 100644 --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-params.c @@ -2455,6 +2455,21 @@ static const struct vb2_ops rkisp1_params_vb2_ops = { }; +static void rkisp1_params_vb2_buf_init_buffer(struct vb2_buffer *vb) +{ + /* TODO */ + + vb2_buf_init_buffer(vb); +} + +static const struct vb2_buf_ops rkisp1_params_vb2_buf_ops = { + .verify_planes_array = vb2_buf_verify_planes_array, + .init_buffer = rkisp1_params_vb2_buf_init_buffer, + .fill_user_buffer = vb2_buf_fill_v4l2_buffer, + .fill_vb2_buffer = vb2_buf_fill_vb2_buffer, + .copy_timestamp = vb2_buf_copy_timestamp, +}; + static const struct v4l2_file_operations rkisp1_params_fops = { .mmap = vb2_fop_mmap, .unlocked_ioctl = video_ioctl2, @@ -2474,12 +2489,13 @@ static int rkisp1_params_init_vb2_queue(struct vb2_queue *q, q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; q->drv_priv = params; q->ops = &rkisp1_params_vb2_ops; + q->buf_ops = &rkisp1_params_vb2_buf_ops; q->mem_ops = &vb2_vmalloc_memops; q->buf_struct_size = sizeof(struct rkisp1_buffer); q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->lock = &node->vlock; - return vb2_queue_init(q); + return vb2_queue_init(q); } int rkisp1_params_register(struct rkisp1_device *rkisp1)