From patchwork Tue Feb 4 02:56:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61412 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNF-001Yko-Dp; Tue, 04 Feb 2020 02:55:37 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727168AbgBDC4x (ORCPT + 1 other); Mon, 3 Feb 2020 21:56:53 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:36827 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727156AbgBDC4w (ORCPT ); Mon, 3 Feb 2020 21:56:52 -0500 Received: by mail-pf1-f196.google.com with SMTP id 185so8673264pfv.3 for ; Mon, 03 Feb 2020 18:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lhU4J28AzAlrdMUPALtytVfuN5Yhod7wdbGSvYMz3F8=; b=muHmPuyoCTTbGsxdFeW4XnvKzj5kxEDC1dK1cy56ahD5bPl9L5v9UYWOTrPmxKWB3I 1Lk/FXpJ/3WXExHGrbVLXmCif8cxKj3WShbNj332c01j6jMtfin4+WtIl+M5B/2XRBbP iBVPpf9rHg3n6feFJx6toqhUAsSuLJjVJEh5g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lhU4J28AzAlrdMUPALtytVfuN5Yhod7wdbGSvYMz3F8=; b=Gj3fHa2PzId0ZeTFOJSbVGyjZUeOhmgJBITHiz6FnktOTjXUy1TA3hnQb3A4RDXZmO avf3tPBV26ZVDJ+QEXpG6aVcKHc7ao2N8My8RSRCWWcGYEUeUvw7/SBbjxWkXiOGtOBS Ny7JSoXstvOmK5iBudMkzQXr/EALivnar7ipTYG664opFtC/Md1gISiv9BIMF8JDNG3z iE6mHxuny8pdPsksEEtgKDdLBKZre80vbZXeSNPQGuajWrtHGR7spYERFRw/dRMVp6Zf brWAZO2zfrwxk8dyfn5enUkIR9TNLowGrHAgNXwpogwqtwsNToNzzYJnZuAVjixTD3t5 R8yQ== X-Gm-Message-State: APjAAAXVGMnQwDWo28pjPcpMkjVVyi2sApsnD2Jx+BeOQ6OsaX+evDsd IDHFwyTWvxu443v04NPefGWkag== X-Google-Smtp-Source: APXvYqz4oR3U12LaNHp02A8K3pwme+uNUkv5IJt9AOpO4nZhEp79Ndgx7m4e6B5jGvq+Oz1zanI3/A== X-Received: by 2002:a63:610a:: with SMTP id v10mr16629313pgb.211.1580785012160; Mon, 03 Feb 2020 18:56:52 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:56:51 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 01/12] videobuf2: add cache management members Date: Tue, 4 Feb 2020 11:56:30 +0900 Message-Id: <20200204025641.218376-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Extend vb2_buffer and vb2_queue structs with cache management members. V4L2 UAPI already contains two buffer flags which user-space, supposedly, can use to control buffer cache sync: - V4L2_BUF_FLAG_NO_CACHE_INVALIDATE - V4L2_BUF_FLAG_NO_CACHE_CLEAN None of these, however, do anything at the moment. This patch set is intended to change it. Since user-space cache management hints are supposed to be implemented on a per-buffer basis we need to extend vb2_buffer struct with two new memebers ->need_cache_sync_on_prepare and ->need_cache_sync_on_finish, which will store corresponding user-space hints. In order to preserve the existing behaviour, user-space cache managements flags will be handled only by those drivers that permit user-space cache hints. That's the purpose of vb2_queue ->allow_cache_hints member. Driver must set ->allow_cache_hints during queue initialisation to enable cache management hints mechanism. Only drivers that set ->allow_cache_hints during queue initialisation will handle user-space cache management hints. Otherwise hints will be ignored. Change-Id: I52beec2a0d021b7a3715b4f6ae4bfd9dc5e94f0d Signed-off-by: Sergey Senozhatsky --- include/media/videobuf2-core.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index a2b2208b02da..026004180440 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -263,6 +263,10 @@ struct vb2_buffer { * after the 'buf_finish' op is called. * copied_timestamp: the timestamp of this capture buffer was copied * from an output buffer. + * need_cache_sync_on_prepare: do not sync/invalidate cache from + * buffer's ->prepare() callback. + * need_cache_sync_on_finish: do not sync/invalidate cache from buffer's + * ->finish() callback. * queued_entry: entry on the queued buffers list, which holds * all buffers queued from userspace * done_entry: entry on the list that stores all buffers ready @@ -273,6 +277,8 @@ struct vb2_buffer { unsigned int synced:1; unsigned int prepared:1; unsigned int copied_timestamp:1; + unsigned int need_cache_sync_on_prepare:1; + unsigned int need_cache_sync_on_finish:1; struct vb2_plane planes[VB2_MAX_PLANES]; struct list_head queued_entry; @@ -491,6 +497,9 @@ struct vb2_buf_ops { * @uses_requests: requests are used for this queue. Set to 1 the first time * a request is queued. Set to 0 when the queue is canceled. * If this is 1, then you cannot queue buffers directly. + * @allow_cache_hints: when set user-space can pass cache management hints in + * order to skip cache flush/invalidation on ->prepare() or/and + * ->finish(). * @lock: pointer to a mutex that protects the &struct vb2_queue. The * driver can set this to a mutex to let the v4l2 core serialize * the queuing ioctls. If the driver wants to handle locking @@ -564,6 +573,7 @@ struct vb2_queue { unsigned requires_requests:1; unsigned uses_qbuf:1; unsigned uses_requests:1; + unsigned allow_cache_hints:1; struct mutex *lock; void *owner; From patchwork Tue Feb 4 02:56:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61413 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNK-001Yl8-UB; Tue, 04 Feb 2020 02:55:43 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727190AbgBDC46 (ORCPT + 1 other); Mon, 3 Feb 2020 21:56:58 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42663 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727160AbgBDC44 (ORCPT ); Mon, 3 Feb 2020 21:56:56 -0500 Received: by mail-pl1-f194.google.com with SMTP id e8so4034161plt.9 for ; Mon, 03 Feb 2020 18:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0Dke3it4jAnnj8WZ58EOkoMCd5ygI2w9KJwtDCLTtPs=; b=WBTkzktPfQdyYJ/1Dp7tR7niJ57O1QuyCseggC0VAGq6KLGfx8m5m0cbGFUWSOl9oS 1b2VUGd1r6Vfy3ZaYWNwj7GS3vAKBbrDy6MCWr5GteDpDpOYRuYabQKVfXh9M2wJfAgV 1ENDVx0kml5b/I1+xEeFL9HJ8vL0yLWw/1UC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Dke3it4jAnnj8WZ58EOkoMCd5ygI2w9KJwtDCLTtPs=; b=OzZRRQ//GyzOGyhWFIcIcLANUkAFepo7sQtzOlesRVvt+pPJsK5WsFZCsokMzmd0D3 P96fjYQ1v8Fzc/vsxMMcsETyv47quzOEe1/AJE3/hr93rlH+cff8MqaASnJImSxlbNXS lmMyjsEmr3269x2fQnV815sSozCpuZgsRIT+JDlMwUGWAaPYkBvKOgSclCA/eFYwFsO8 VKnV0cZLnj2KWhWvxQCi9GaoBPoOHpMpX54xyZSvyhuA5J4P3QEn8HBY+dXlkxin2dmj HFUEDImRcSXMD6E0VjijjjwLDPfpna/oXjAF4R8wxaJX8f7YJnprQC1M4QbOQFLyJ19u yAww== X-Gm-Message-State: APjAAAV2fvOQnwZCovq8XRq/kn2BVp79auk/oC7kxASi2XWLFSo5Ma0u mFIJdf9edt69HqtjMP5hGzF1gw== X-Google-Smtp-Source: APXvYqwFXZwVlWO8JJd9nP2tmu7pAXbLJCOTiydwVfbrp3yoOhZx3asfPWnN3Ku98Czzg/Yns7mIXg== X-Received: by 2002:a17:90a:fb41:: with SMTP id iq1mr3133875pjb.89.1580785016239; Mon, 03 Feb 2020 18:56:56 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:56:55 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 02/12] videobuf2: handle V4L2 buffer cache flags Date: Tue, 4 Feb 2020 11:56:31 +0900 Message-Id: <20200204025641.218376-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Set video buffer cache management flags corresponding to V4L2 cache flags. Both ->prepare() and ->finish() cache management hints should be passed during this stage (buffer preparation), because there is no other way for user-space to skip ->finish() cache flush. There are two possible alternative approaches: - The first one is to move cache sync from ->finish() to dqbuf(). But this breaks some drivers, that need to fix-up buffers before dequeueing them. - The second one is to move ->finish() call from ->done() to dqbuf. Change-Id: I3bef1d1fb93a5fba290ce760eaeecdc8e7d6885a Signed-off-by: Sergey Senozhatsky Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-v4l2.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index eb5d5db96552..2da06a2ad6c4 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -337,6 +337,41 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b return 0; } +static void set_buffer_cache_hints(struct vb2_queue *q, + struct vb2_buffer *vb, + struct v4l2_buffer *b) +{ + /* + * DMA exporter should take care of cache syncs, so we can avoid + * explicit ->prepare()/->finish() syncs. For other ->memory types + * we always need ->prepare() or/and ->finish() cache sync. + */ + if (q->memory == VB2_MEMORY_DMABUF) { + vb->need_cache_sync_on_finish = 0; + vb->need_cache_sync_on_prepare = 0; + return; + } + + if (!q->allow_cache_hints) + return; + + vb->need_cache_sync_on_prepare = 1; + /* + * ->finish() cache sync can be avoided when queue direction is + * TO_DEVICE. + */ + if (q->dma_dir != DMA_TO_DEVICE) + vb->need_cache_sync_on_finish = 1; + else + vb->need_cache_sync_on_finish = 0; + + if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE) + vb->need_cache_sync_on_finish = 0; + + if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN) + vb->need_cache_sync_on_prepare = 0; +} + static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mdev, struct v4l2_buffer *b, bool is_prepare, struct media_request **p_req) @@ -381,6 +416,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md } if (!vb->prepared) { + set_buffer_cache_hints(q, vb, b); /* Copy relevant information provided by the userspace */ memset(vbuf->planes, 0, sizeof(vbuf->planes[0]) * vb->num_planes); From patchwork Tue Feb 4 02:56:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61414 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNO-001YlN-HC; Tue, 04 Feb 2020 02:55:46 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbgBDC5C (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:02 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:35016 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbgBDC5A (ORCPT ); Mon, 3 Feb 2020 21:57:00 -0500 Received: by mail-pj1-f67.google.com with SMTP id q39so704456pjc.0 for ; Mon, 03 Feb 2020 18:57:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Icxfnp9HKjOCxxd8LHDLtBzlH++tvRBMGK02TWhaPYI=; b=hAKlVKM+cc2osv8Wzq1OdoAIc0gwS/b7aByJyCTRrUEWILDvQchLX65IYYHuMNs4E8 CDdgtxQC2e//gNJXvwuLkaf1Jc6tsm0AM6UNh8PI1AR7GVWNABSDRdQOvy4qpiV35OHK TF/pS1ub1obJ8GAdEHFN4DuUFdUjCgTQrZDuQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Icxfnp9HKjOCxxd8LHDLtBzlH++tvRBMGK02TWhaPYI=; b=s1KSxyjBnftOBMEz9bTCm9KxhzZPMLVd4m6QWbCkFtTKtab2URexxttH2Wr7RPBKMd i4LzAj6DSrGojFywLyWS6vrRMI60+ygtUmuXxTEDfXSklaGZt6oeu6ivbNtBLCthLNvI 9ef58ArY5r1kzSaC+MCK2Oay69wxlsxPR8aEpCNwL4KEAQttyz0LthOHVSpgU716ueDi 2DlhIpnnsu536xxn0QrD+MTq7Vpx135WinK9Re4BH7xIQqtMRhRSOiLhPKMphuOMRLAE DHR8bBna27drlBoZvadMrqibqOrkGV79cjiz78YaENaGxTXoDH/iBjaUKeCKX/2gK0jm x8/A== X-Gm-Message-State: APjAAAVnzSqwUicpBtzNUlghIMFj+8yqSrWnkvO6Pm6vBNnRfLxCRsOG xRteUOb+B+Q/gaH03l4RYjRC3w== X-Google-Smtp-Source: APXvYqxBCz/RGzHXqMGg+UqQdt1FKzjwr4xjT+V51b+Hm23Ljn0PARusbNY2zOgAv7oXSEfUA81/Qw== X-Received: by 2002:a17:902:8f8a:: with SMTP id z10mr27668871plo.169.1580785019903; Mon, 03 Feb 2020 18:56:59 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:56:59 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 03/12] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Tue, 4 Feb 2020 11:56:32 +0900 Message-Id: <20200204025641.218376-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org By setting or clearing V4L2_FLAG_MEMORY_NON_CONSISTENT flag user-space should be able to set or clear queue's NON_CONSISTENT ->dma_attrs. Queue's ->dma_attrs are passed to the underlying allocator in __vb2_buf_mem_alloc(), so thus user-space is able to request vb2 buffer's memory to be either consistent (coherent) or non-consistent. Change-Id: Ib333081c482e23c9a89386078293e19c3fd59076 Signed-off-by: Sergey Senozhatsky --- Documentation/media/uapi/v4l/buffer.rst | 27 +++++++++++++++++++++++++ include/uapi/linux/videodev2.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst index 9149b57728e5..af007daf0591 100644 --- a/Documentation/media/uapi/v4l/buffer.rst +++ b/Documentation/media/uapi/v4l/buffer.rst @@ -705,6 +705,33 @@ Buffer Flags .. c:type:: v4l2_memory +Memory Consistency Flags +======================== + +.. tabularcolumns:: |p{7.0cm}|p{2.2cm}|p{8.3cm}| + +.. cssclass:: longtable + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + :widths: 3 1 4 + + * .. _`V4L2_FLAG_MEMORY_NON_CONSISTENT`: + + - ``V4L2_FLAG_MEMORY_NON_CONSISTENT`` + - 0x00000001 + - vb2 buffer is allocated either in consistent (it will be automatically + coherent between CPU and bus) or non-consistent memory. The latter + can provide performance gains, for instance CPU cache sync/flush + operations can be avoided if the buffer is accesed by the corresponding + device only and CPU does not read/write to/from that buffer. However, + this requires extra care from the driver -- it must guarantee memory + consistency by issuing cache flush/sync when consistency is needed. + If this flag is set V4L2 will attempt to allocate vb2 buffer in + non-consistent memory. This flag is ignored if queue does not report + :ret:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS` capability. + enum v4l2_memory ================ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 5f9357dcb060..72efc1c544cd 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -189,6 +189,8 @@ enum v4l2_memory { V4L2_MEMORY_DMABUF = 4, }; +#define V4L2_FLAG_MEMORY_NON_CONSISTENT (1 << 0) + /* see also http://vektor.theorem.ca/graphics/ycbcr/ */ enum v4l2_colorspace { /* From patchwork Tue Feb 4 02:56:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61415 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNR-001Ylf-G0; Tue, 04 Feb 2020 02:55:49 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727247AbgBDC5G (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:06 -0500 Received: from mail-pf1-f182.google.com ([209.85.210.182]:45937 "EHLO mail-pf1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727209AbgBDC5F (ORCPT ); Mon, 3 Feb 2020 21:57:05 -0500 Received: by mail-pf1-f182.google.com with SMTP id 2so8648154pfg.12 for ; Mon, 03 Feb 2020 18:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ynjMjGRfG1bUjxJQNZ1F73iayP+/byptvDIws6P29NM=; b=XpxzCTmJjkNl9Thw+PLpSUFXcWgAsaBLq+8wh3qacsFWOKa+7ZHdItPx+Fca0WbVI0 U4URpLup5mfURIqJfAyF6vWQkVTsdgLZ1HTjislehyYWYRRT96VUrLFd0a6An62qe9y3 0Okc1fLq2z7t++cJf/uqLbhQyL43iaqKOOVzk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ynjMjGRfG1bUjxJQNZ1F73iayP+/byptvDIws6P29NM=; b=owCfquSLPisYbUCHnRruTeIdixCw06TCuMKuAyb2XqcG6zwD0+5mqvS1/VAGC2YKIe DoIK497xDVq7VYxQO6WPVYxW1aho3HAegLlzEGojwg4K+nsP6xfrQ/L/Dxtnbckvxo6l FMPLbKEchnz3A+reRJ8iuEwmm51IsC30sEjBMsuF//jXWIMlANxYsZHoLAfojQr7gHMH bZ9zkjz4T7Dbg1wkXKFlQPjmhZn7nfPFmKzB0CyHToCAQ2cXaWLjnflwOTngbATW3CfP LsPPLpzM49ZO+3CznKjUSe1jVux02b8htkWDxpzViC5XpYNYbbPPglqaZetcasIYzRSj m7PQ== X-Gm-Message-State: APjAAAUdR2OxoxjZ0BYAACYhZGUu0hPW9prwYpd+TnVdsBxk+KkyQSKM XNPMXCp7rih0cm0Fqz8NzOlAX8fxaon7LQ== X-Google-Smtp-Source: APXvYqznDDT+Vo7xL2rL9nEuP0bCv0UNR9+m5bCNp047RV+Le8xlpd5sN5h1pH1Gm3qlcLMCXyMedw== X-Received: by 2002:a63:f202:: with SMTP id v2mr28272709pgh.420.1580785023546; Mon, 03 Feb 2020 18:57:03 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:03 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 04/12] videobuf2: add queue memory consistency parameter Date: Tue, 4 Feb 2020 11:56:33 +0900 Message-Id: <20200204025641.218376-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Preparations for future V4L2_FLAG_MEMORY_NON_CONSISTENT support. Extend vb2_core_reqbufs() with queue memory consistency flag that is applied to the newly allocated buffers. An attempt to allocate a buffer with consistency requirements which don't match queue's consistency model will fail. Change-Id: Ia40362553b6bd96fea3b652f4a376e7a3467df0a Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-core.c | 47 +++++++++++++++---- .../media/common/videobuf2/videobuf2-v4l2.c | 6 +-- drivers/media/dvb-core/dvb_vb2.c | 2 +- include/media/videobuf2-core.h | 7 ++- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 4489744fbbd9..56fd17eafb6c 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -664,8 +664,19 @@ int vb2_verify_memory_type(struct vb2_queue *q, } EXPORT_SYMBOL(vb2_verify_memory_type); +static void set_queue_consistency(struct vb2_queue *q, bool consistent_mem) +{ + if (!q->allow_cache_hints) + return; + + if (consistent_mem) + q->dma_attrs &= ~DMA_ATTR_NON_CONSISTENT; + else + q->dma_attrs |= DMA_ATTR_NON_CONSISTENT; +} + int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, - unsigned int *count) + bool consistent_mem, unsigned int *count) { unsigned int num_buffers, allocated_buffers, num_planes = 0; unsigned plane_sizes[VB2_MAX_PLANES] = { }; @@ -720,6 +731,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); q->memory = memory; + set_queue_consistency(q, consistent_mem); /* * Ask the driver how many buffers and planes per buffer it requires. @@ -803,9 +815,21 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, } EXPORT_SYMBOL_GPL(vb2_core_reqbufs); +static bool verify_consistency_attr(struct vb2_queue *q, bool consistent_mem) +{ + bool queue_attr = q->dma_attrs & DMA_ATTR_NON_CONSISTENT; + + if (consistent_mem != queue_attr) { + dprintk(1, "memory consistency model mismatch\n"); + return false; + } + return true; +} + int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, - unsigned int *count, unsigned requested_planes, - const unsigned requested_sizes[]) + bool consistent_mem, unsigned int *count, + unsigned requested_planes, + const unsigned requested_sizes[]) { unsigned int num_planes = 0, num_buffers, allocated_buffers; unsigned plane_sizes[VB2_MAX_PLANES] = { }; @@ -823,10 +847,15 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, } memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); q->memory = memory; + set_queue_consistency(q, consistent_mem); q->waiting_for_buffers = !q->is_output; - } else if (q->memory != memory) { - dprintk(1, "memory model mismatch\n"); - return -EINVAL; + } else { + if (q->memory != memory) { + dprintk(1, "memory model mismatch\n"); + return -EINVAL; + } + if (!verify_consistency_attr(q, consistent_mem)) + return -EINVAL; } num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers); @@ -2498,7 +2527,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) fileio->memory = VB2_MEMORY_MMAP; fileio->type = q->type; q->fileio = fileio; - ret = vb2_core_reqbufs(q, fileio->memory, &fileio->count); + ret = vb2_core_reqbufs(q, fileio->memory, true, &fileio->count); if (ret) goto err_kfree; @@ -2555,7 +2584,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) err_reqbufs: fileio->count = 0; - vb2_core_reqbufs(q, fileio->memory, &fileio->count); + vb2_core_reqbufs(q, fileio->memory, true, &fileio->count); err_kfree: q->fileio = NULL; @@ -2575,7 +2604,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q) vb2_core_streamoff(q, q->type); q->fileio = NULL; fileio->count = 0; - vb2_core_reqbufs(q, fileio->memory, &fileio->count); + vb2_core_reqbufs(q, fileio->memory, true, &fileio->count); kfree(fileio); dprintk(3, "file io emulator closed\n"); } diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 2da06a2ad6c4..7cdfcd1baf82 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -709,7 +709,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) int ret = vb2_verify_memory_type(q, req->memory, req->type); fill_buf_caps(q, &req->capabilities); - return ret ? ret : vb2_core_reqbufs(q, req->memory, &req->count); + return ret ? ret : vb2_core_reqbufs(q, req->memory, true, &req->count); } EXPORT_SYMBOL_GPL(vb2_reqbufs); @@ -783,7 +783,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) for (i = 0; i < requested_planes; i++) if (requested_sizes[i] == 0) return -EINVAL; - return ret ? ret : vb2_core_create_bufs(q, create->memory, + return ret ? ret : vb2_core_create_bufs(q, create->memory, true, &create->count, requested_planes, requested_sizes); } EXPORT_SYMBOL_GPL(vb2_create_bufs); @@ -959,7 +959,7 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, return res; if (vb2_queue_is_busy(vdev, file)) return -EBUSY; - res = vb2_core_reqbufs(vdev->queue, p->memory, &p->count); + res = vb2_core_reqbufs(vdev->queue, p->memory, true, &p->count); /* If count == 0, then the owner has released all buffers and he is no longer owner of the queue. Otherwise we have a new owner. */ if (res == 0) diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c index 6974f1731529..e60063652164 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -342,7 +342,7 @@ int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req) ctx->buf_siz = req->size; ctx->buf_cnt = req->count; - ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, &req->count); + ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, true, &req->count); if (ret) { ctx->state = DVB_VB2_STATE_NONE; dprintk(1, "[%s] count=%d size=%d errno=%d\n", ctx->name, diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 026004180440..5e5450bdabbd 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -726,6 +726,7 @@ void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); * vb2_core_reqbufs() - Initiate streaming. * @q: pointer to &struct vb2_queue with videobuf2 queue. * @memory: memory type, as defined by &enum vb2_memory. + * @consistent_mem: memory consistency model. * @count: requested buffer count. * * Videobuf2 core helper to implement VIDIOC_REQBUF() operation. It is called @@ -750,12 +751,13 @@ void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); * Return: returns zero on success; an error code otherwise. */ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, - unsigned int *count); + bool consistent_mem, unsigned int *count); /** * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs * @q: pointer to &struct vb2_queue with videobuf2 queue. * @memory: memory type, as defined by &enum vb2_memory. + * @consistent_mem: memory consistency model. * @count: requested buffer count. * @requested_planes: number of planes requested. * @requested_sizes: array with the size of the planes. @@ -773,7 +775,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * Return: returns zero on success; an error code otherwise. */ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, - unsigned int *count, unsigned int requested_planes, + bool consistent_mem, unsigned int *count, + unsigned int requested_planes, const unsigned int requested_sizes[]); /** From patchwork Tue Feb 4 02:56:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61416 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNW-001Ylv-NA; Tue, 04 Feb 2020 02:55:55 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727266AbgBDC5K (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:10 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40722 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727257AbgBDC5J (ORCPT ); Mon, 3 Feb 2020 21:57:09 -0500 Received: by mail-pf1-f193.google.com with SMTP id q8so8662196pfh.7 for ; Mon, 03 Feb 2020 18:57:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GvJQz/sjsiNa3Q1UEmIdKwgVvFAZeh869jBsgc8r4pg=; b=UfB4HPscgZp/SJ7PW6PIQO1t6SGzG/PhSmnkSl1HmtHTSgzcbFVp0J+Scn5VXlhHPz Nu3yBbP7PYddEFrl3WGnl4WvAO/PymsNFCG9cD58XWJzm7iHNyj0Hynf3Mw9qOV7zoHH mlIq1Dbp29L7B8k/pBGUo+0ZLyaGXjaEaYT9E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GvJQz/sjsiNa3Q1UEmIdKwgVvFAZeh869jBsgc8r4pg=; b=MLYDVYWyFl5nzcnIu+CnXShDzEu5Q4CYMMCW4d/oFay7Flt/fim3+LjRY8gO6+TIgG RcoeNPxC0CNYx+Rwwz/VLY2YN77PxUAONmVfENjtxVPDVcL6Kd0tHHISyzafuy3YXhzZ 7HdPw724nD8x1eewAUhPYFrcAxsi4WfWKJvTYFTRAwS7evsmxC6ZMBRerY+N25xrE23t ZJroUs8vedcymi5W/xU0MDcELbCeGTA8Veb/cfN6UEDu0cdUt745ZtL0IRaO3hqfyqc7 p6mR4CD5rCDgIBRLiLVvn29l7pZJN9lyNPxof5XzSycCgO+7+BeRbcJMI9RJxe6qq0+B /llw== X-Gm-Message-State: APjAAAV44728yOL5UJMtC3p3dkoRti2/frrAVH3pq4g6C+nuiLNqSXgh gGeCCQoZuKko7tsBjdrRfXKDKA== X-Google-Smtp-Source: APXvYqwpw9CNzxMlyf5JStAP2sZ6crtBiybGq9mMXiWx3QEyjfSSqKG38CdAdhtco9UzVHYRlPs1kQ== X-Received: by 2002:a63:4b49:: with SMTP id k9mr28771860pgl.269.1580785027062; Mon, 03 Feb 2020 18:57:07 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:06 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 05/12] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Tue, 4 Feb 2020 11:56:34 +0900 Message-Id: <20200204025641.218376-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This patch lets user-space to request a non-consistent memory allocation during CREATE_BUFS and REQBUFS ioctl calls. = CREATE_BUFS struct v4l2_create_buffers has seven 4-byte reserved areas, so reserved[0] is renamed to ->flags. The struct, thus, now has six reserved 4-byte regions. = REQBUFS We use one bit of a ->reserved[1] member of struct v4l2_requestbuffers, which is now renamed to ->flags. Unlike v4l2_create_buffers, struct v4l2_requestbuffers does not have enough reserved room. Therefore for backward compatibility ->reserved and ->flags were put into anonymous union. Change-Id: I0eaab3428de499ce1bce6fc6b26c5ca5ff405882 Signed-off-by: Sergey Senozhatsky --- .../media/uapi/v4l/vidioc-create-bufs.rst | 9 +++++++- .../media/uapi/v4l/vidioc-reqbufs.rst | 15 ++++++++++--- .../media/common/videobuf2/videobuf2-v4l2.c | 21 ++++++++++++++++--- drivers/media/v4l2-core/v4l2-ioctl.c | 5 +---- include/uapi/linux/videodev2.h | 8 +++++-- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst index bd08e4f77ae4..68185e94b686 100644 --- a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst @@ -121,7 +121,14 @@ than the number requested. other changes, then set ``count`` to 0, ``memory`` to ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type. * - __u32 - - ``reserved``\ [7] + - ``flags`` + - Specifies additional buffer management attributes. Valid only when + queue reports :ref:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS` capability. + Old drivers and applications must set it to zero. + + + * - __u32 + - ``reserved``\ [6] - A place holder for future extensions. Drivers and applications must set the array to zero. diff --git a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst index d0c643db477a..9741dac0d5b3 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -112,10 +112,19 @@ aborting or finishing any DMA in progress, an implicit ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will free any previously allocated buffers, so this is typically something that will be done at the start of the application. - * - __u32 + * - union + - (anonymous) + * - + - __u32 + - ``flags``\ [1] + - Specifies additional buffer management attributes. Valid only when + queue reports :ref:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS` capability. + Old drivers and applications must set it to zero. + + * - + - __u32 - ``reserved``\ [1] - - A place holder for future extensions. Drivers and applications - must set the array to zero. + - Kept for backwards compatibility. Use ``flags`` instead. .. tabularcolumns:: |p{6.1cm}|p{2.2cm}|p{8.7cm}| diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 7cdfcd1baf82..eb5d1306cb03 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -707,9 +707,15 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) { int ret = vb2_verify_memory_type(q, req->memory, req->type); + bool consistent = true; + + if (req->flags & V4L2_FLAG_MEMORY_NON_CONSISTENT) + consistent = false; fill_buf_caps(q, &req->capabilities); - return ret ? ret : vb2_core_reqbufs(q, req->memory, true, &req->count); + if (ret) + return ret; + return vb2_core_reqbufs(q, req->memory, consistent, &req->count); } EXPORT_SYMBOL_GPL(vb2_reqbufs); @@ -738,6 +744,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) unsigned requested_sizes[VIDEO_MAX_PLANES]; struct v4l2_format *f = &create->format; int ret = vb2_verify_memory_type(q, create->memory, f->type); + bool consistent = true; unsigned i; fill_buf_caps(q, &create->capabilities); @@ -783,7 +790,11 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) for (i = 0; i < requested_planes; i++) if (requested_sizes[i] == 0) return -EINVAL; - return ret ? ret : vb2_core_create_bufs(q, create->memory, true, + + if (create->flags & V4L2_FLAG_MEMORY_NON_CONSISTENT) + consistent = false; + + return ret ? ret : vb2_core_create_bufs(q, create->memory, consistent, &create->count, requested_planes, requested_sizes); } EXPORT_SYMBOL_GPL(vb2_create_bufs); @@ -953,13 +964,17 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, { struct video_device *vdev = video_devdata(file); int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type); + bool consistent = true; fill_buf_caps(vdev->queue, &p->capabilities); if (res) return res; if (vb2_queue_is_busy(vdev, file)) return -EBUSY; - res = vb2_core_reqbufs(vdev->queue, p->memory, true, &p->count); + if (p->flags & V4L2_FLAG_MEMORY_NON_CONSISTENT) + consistent = false; + + res = vb2_core_reqbufs(vdev->queue, p->memory, consistent, &p->count); /* If count == 0, then the owner has released all buffers and he is no longer owner of the queue. Otherwise we have a new owner. */ if (res == 0) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index aaf83e254272..9791e2882382 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1973,9 +1973,6 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, if (ret) return ret; - - CLEAR_AFTER_FIELD(p, capabilities); - return ops->vidioc_reqbufs(file, fh, p); } @@ -2015,7 +2012,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, if (ret) return ret; - CLEAR_AFTER_FIELD(create, capabilities); + CLEAR_AFTER_FIELD(create, flags); v4l_sanitize_format(&create->format); diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 72efc1c544cd..169a8cf345ed 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -938,7 +938,10 @@ struct v4l2_requestbuffers { __u32 type; /* enum v4l2_buf_type */ __u32 memory; /* enum v4l2_memory */ __u32 capabilities; - __u32 reserved[1]; + union { + __u32 flags; + __u32 reserved[1]; + }; }; /* capabilities for struct v4l2_requestbuffers and v4l2_create_buffers */ @@ -2445,7 +2448,8 @@ struct v4l2_create_buffers { __u32 memory; struct v4l2_format format; __u32 capabilities; - __u32 reserved[7]; + __u32 flags; + __u32 reserved[6]; }; /* From patchwork Tue Feb 4 02:56:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61417 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNX-001Ylv-MZ; Tue, 04 Feb 2020 02:55:55 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727256AbgBDC5N (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:13 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:50672 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727159AbgBDC5M (ORCPT ); Mon, 3 Feb 2020 21:57:12 -0500 Received: by mail-pj1-f68.google.com with SMTP id r67so688852pjb.0 for ; Mon, 03 Feb 2020 18:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rSyGuFAVZnXzr+zAXWI5hLV+qnkzbpD8GsyCzJNdKrQ=; b=mxIQk2YLkshOw7vJ6iQvQQCce+oSmqrmG5XFCsSQJ/4BKhar12+Sifz2M/V7e8nrmr ISbu9DVITcNCb/Vs5/J3sDuDcHN2dg2BsZVowUuljbbW/BTmU6iPtiMCLc3Pi2eYo75S 10iztGHMfd6G/0yJ1hFE4AmJsc9nxccT76B+c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rSyGuFAVZnXzr+zAXWI5hLV+qnkzbpD8GsyCzJNdKrQ=; b=evo2HNivOKnCm+62BELJDojNUoip/YhgHYZoOEzIj58jM1Daeof1rUreRHYUg6Qr+K l74iYTWio18vPPxMZbX8XleiFASsHKmiHQi/7aiPvGCuyZbv0gWaLjJ2l9GdzepNy+z8 iWy87AdAww26sJ7jUixfgipqhSU01eOJvNBIRABD2An+rjTZNI8iduFcLz+tGSTUim6D Omw6dYaO+8lhr+0UHx1qa7wLn5hV/UsPhA1BSn8WXmTDLb1ooYUyRZjTrNjirXqqg8tA 964IhgHm0xBCV5ieGm2ALVM61o6JAq/xwFXwhlx+xmIf4BkYIK3AbRNQAJ8QHyH0auaT W43Q== X-Gm-Message-State: APjAAAWqBY48Q6b+rmxxj4TGa0dp03+445ut5khkLV7wh143DtX+DKbP ZsCBHTCd4qbl0csP3qHxEXmZsCTdnf9nfg== X-Google-Smtp-Source: APXvYqw44cJEolkg75aNUS+361dd/1QeuT/ek/JjyJbHVZG2AagjQmg09/xRta5P8wjnCUEBOjUvZA== X-Received: by 2002:a17:90a:7784:: with SMTP id v4mr3136782pjk.134.1580785030594; Mon, 03 Feb 2020 18:57:10 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:10 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 06/12] videobuf2: factor out planes prepare/finish functions Date: Tue, 4 Feb 2020 11:56:35 +0900 Message-Id: <20200204025641.218376-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Factor out the code, no functional changes. Change-Id: I47044c0ba57ccc47a5d23f36976ce9f1e3b0f67f Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-core.c | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 56fd17eafb6c..46be9c790ff6 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -296,6 +296,32 @@ static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb) __vb2_plane_dmabuf_put(vb, &vb->planes[plane]); } +/* + * __vb2_buf_mem_prepare() - call ->prepare() on buffer's private memory + * to sync caches + */ +static void __vb2_buf_mem_prepare(struct vb2_buffer *vb) +{ + unsigned int plane; + + for (plane = 0; plane < vb->num_planes; ++plane) + call_void_memop(vb, prepare, vb->planes[plane].mem_priv); + vb->synced = 1; +} + +/* + * __vb2_buf_mem_finish() - call ->finish on buffer's private memory + * to sync caches + */ +static void __vb2_buf_mem_finish(struct vb2_buffer *vb) +{ + unsigned int plane; + + for (plane = 0; plane < vb->num_planes; ++plane) + call_void_memop(vb, finish, vb->planes[plane].mem_priv); + vb->synced = 0; +} + /* * __setup_offsets() - setup unique offsets ("cookies") for every plane in * the buffer. @@ -951,7 +977,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) { struct vb2_queue *q = vb->vb2_queue; unsigned long flags; - unsigned int plane; if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) return; @@ -971,12 +996,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) dprintk(4, "done processing on buffer %d, state: %d\n", vb->index, state); - if (state != VB2_BUF_STATE_QUEUED) { - /* sync buffers */ - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, finish, vb->planes[plane].mem_priv); - vb->synced = 0; - } + if (state != VB2_BUF_STATE_QUEUED) + __vb2_buf_mem_finish(vb); spin_lock_irqsave(&q->done_lock, flags); if (state == VB2_BUF_STATE_QUEUED) { @@ -1301,7 +1322,6 @@ static int __buf_prepare(struct vb2_buffer *vb) { struct vb2_queue *q = vb->vb2_queue; enum vb2_buffer_state orig_state = vb->state; - unsigned int plane; int ret; if (q->error) { @@ -1345,11 +1365,7 @@ static int __buf_prepare(struct vb2_buffer *vb) return ret; } - /* sync buffers */ - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, prepare, vb->planes[plane].mem_priv); - - vb->synced = 1; + __vb2_buf_mem_prepare(vb); vb->prepared = 1; vb->state = orig_state; @@ -1969,14 +1985,8 @@ static void __vb2_queue_cancel(struct vb2_queue *q) call_void_vb_qop(vb, buf_request_complete, vb); } - if (vb->synced) { - unsigned int plane; - - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, finish, - vb->planes[plane].mem_priv); - vb->synced = 0; - } + if (vb->synced) + __vb2_buf_mem_finish(vb); if (vb->prepared) { call_void_vb_qop(vb, buf_finish, vb); From patchwork Tue Feb 4 02:56:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61418 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNa-001YmM-Qv; Tue, 04 Feb 2020 02:55:58 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727063AbgBDC5R (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:17 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41407 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727305AbgBDC5P (ORCPT ); Mon, 3 Feb 2020 21:57:15 -0500 Received: by mail-pg1-f193.google.com with SMTP id l3so4804100pgi.8 for ; Mon, 03 Feb 2020 18:57:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3NyRU2xy1z/nYwBRLVUPtO+ZHRnpI9P9k60fSC2X+DE=; b=j3Fq0i83ztEE46oH9dTHoPUFBJ9tpWElVSi0sKJRUZcsRbsxCRK+bWgt1i6ZdvjhO8 ZV7hTIydDJatMj68kNoBQQ/DWG5kqPpCeiEGZheluT9CfCXmnX4rmfk92P97gjhc1IzM EFAdrs3PsNDg1PIBW0b1qc0dRsThBCU7KFkmQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3NyRU2xy1z/nYwBRLVUPtO+ZHRnpI9P9k60fSC2X+DE=; b=dxCwMTFOQIhdqK6+3DGx7osu1Qe5xsQHZSaXAXHrrL+ysy7bkssvEIoEsVS+BYXpKM oDig09Q81qYfqfjr9065bTIF1VdO8tG125zHBaiOuruX6c3DI8PG8TcSDcBvRFeaaNOy 2xOAKrXGc3grTiFmoiOI5pyPK6V731mAr5Fa1G/4GibvLwLJKwATWgbDtpUJG/iPWVp4 TQ2IYpOaHlOceg9MOy9Wy/vTJwBQyBlmRb3DS9IMLg6ZrGBzcqP+mUzyplNjulUHSJ9y fa4pmNnL/7yOSiCCDuxBBfFo9KqFYs48NxO3C8ympn0qUr7aQVgOO2c8gYJQd5uV2tHx SKPA== X-Gm-Message-State: APjAAAUc4+61+hUkM9E7m0yC+20UmqUEDpMp/m0zeYzsRQQp1T+JyygN JigOonjBZNqKWp+yglZ9+xjLPA== X-Google-Smtp-Source: APXvYqwFBek9VnVsgN4EGGqi1nNxFt8Z4wI/xHpJb1NQ4wxHusH5uLLX8YW9xr/VCW1sE1Muy5gUqg== X-Received: by 2002:a63:ed4a:: with SMTP id m10mr25299793pgk.99.1580785034064; Mon, 03 Feb 2020 18:57:14 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:13 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 07/12] videobuf2: do not sync caches when we are allowed not to Date: Tue, 4 Feb 2020 11:56:36 +0900 Message-Id: <20200204025641.218376-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Skip ->prepare() or/and ->finish() cache synchronisation if user-space requested us to do so (or when queue dma direction permits us to skip cache syncs). Change-Id: I37c89d666542ed8d536eac329953d921bb1c94b6 Signed-off-by: Sergey Senozhatsky --- drivers/media/common/videobuf2/videobuf2-core.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 46be9c790ff6..c3637ca0c65b 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -304,8 +304,11 @@ static void __vb2_buf_mem_prepare(struct vb2_buffer *vb) { unsigned int plane; - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, prepare, vb->planes[plane].mem_priv); + if (vb->need_cache_sync_on_prepare) { + for (plane = 0; plane < vb->num_planes; ++plane) + call_void_memop(vb, prepare, + vb->planes[plane].mem_priv); + } vb->synced = 1; } @@ -317,8 +320,11 @@ static void __vb2_buf_mem_finish(struct vb2_buffer *vb) { unsigned int plane; - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, finish, vb->planes[plane].mem_priv); + if (vb->need_cache_sync_on_finish) { + for (plane = 0; plane < vb->num_planes; ++plane) + call_void_memop(vb, finish, + vb->planes[plane].mem_priv); + } vb->synced = 0; } From patchwork Tue Feb 4 02:56:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61423 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNy-001Yx2-66; Tue, 04 Feb 2020 02:56:22 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727327AbgBDC5V (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:21 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36837 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727308AbgBDC5S (ORCPT ); Mon, 3 Feb 2020 21:57:18 -0500 Received: by mail-pl1-f195.google.com with SMTP id a6so6651006plm.3 for ; Mon, 03 Feb 2020 18:57:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1pXTWkZoMBIf1iKBkXLSAWapvVeX9VPPX3FIrIBSBVo=; b=bvNna1e6NxD9FZJneV6BaVLd7xK66kO+n4o1HRdkwGa/lOtkLP8+vWFybesFggnBPz /QZc+YoCBP0xZDz/bpxih4eEIOQbA2H/ivUeH+ZcgGaVzXMp6G2/ILwOuPksAR5X/Sgf gAf5jCoAkm+1nZN19uQ+hRL4PbJ19Rzk6nTYU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1pXTWkZoMBIf1iKBkXLSAWapvVeX9VPPX3FIrIBSBVo=; b=re/CoRB/jzvb3RAWhtPMgA4/HkwUNNzzgrkwxze+YXKMmheR300vKUpe9Vgp1ZeEJN bV6HVOgyFE8G0BQZFNXIxnwn8qC8qZfPBOKHxIzEAHyhvw/HvuFtPLcduaRofT5XhH84 fmOig09llenHbHPSeva63RKYujEY/eKhSHRboOoUvXyMjoR0h7Yn2ISdDgbhngzkunVf 43c8OpLKNrNxqJmFesnGXqpDoGamIkYvnErKgU+rgjAM+mmC8FKlKr2JQTHJAiJ0ar2r thVDBIJPgEgQaRpB8CAK2SXOTAZ0cOqLBbMjYjaSB8+KVlwj6Cr5hOGqWH39inUKW34I 1wOg== X-Gm-Message-State: APjAAAW5MQWGw0qAmfdo6X3dxPI6+cu+nbOuDc+Zw9oA+ihnErtEwQL3 ExGBJCrhI7Z0X1cPyxOq3lE2GEjwkiMM1w== X-Google-Smtp-Source: APXvYqzDTARrYg6qPArxaStR0lWXrAEmWXTgHZRpYxBMYcpQMiClm40tAMEKMl7YxvXoCxGbDUKgRQ== X-Received: by 2002:a17:902:8545:: with SMTP id d5mr25714862plo.116.1580785037637; Mon, 03 Feb 2020 18:57:17 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:17 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 08/12] videobuf2: check ->synced flag in prepare() and finish() Date: Tue, 4 Feb 2020 11:56:37 +0900 Message-Id: <20200204025641.218376-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This simplifies the code a tiny bit and let's us to avoid unneeded ->prepare()/->finish() calls. Change-Id: Ia7c8b4d75a72d0fe1bf37382780e173f6dd9b7ff Signed-off-by: Sergey Senozhatsky --- drivers/media/common/videobuf2/videobuf2-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index c3637ca0c65b..631667db7094 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -304,6 +304,9 @@ static void __vb2_buf_mem_prepare(struct vb2_buffer *vb) { unsigned int plane; + if (vb->synced) + return; + if (vb->need_cache_sync_on_prepare) { for (plane = 0; plane < vb->num_planes; ++plane) call_void_memop(vb, prepare, @@ -320,6 +323,9 @@ static void __vb2_buf_mem_finish(struct vb2_buffer *vb) { unsigned int plane; + if (!vb->synced) + return; + if (vb->need_cache_sync_on_finish) { for (plane = 0; plane < vb->num_planes; ++plane) call_void_memop(vb, finish, @@ -1991,8 +1997,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) call_void_vb_qop(vb, buf_request_complete, vb); } - if (vb->synced) - __vb2_buf_mem_finish(vb); + __vb2_buf_mem_finish(vb); if (vb->prepared) { call_void_vb_qop(vb, buf_finish, vb); From patchwork Tue Feb 4 02:56:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61422 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNx-001Yx2-Bi; Tue, 04 Feb 2020 02:56:21 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbgBDC5Y (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:24 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35388 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727323AbgBDC5W (ORCPT ); Mon, 3 Feb 2020 21:57:22 -0500 Received: by mail-pf1-f193.google.com with SMTP id y73so8683987pfg.2 for ; Mon, 03 Feb 2020 18:57:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=raQvSM5V/uMvgqOsdMStTvPP8E1jqsk9wa9DPg9FZM8=; b=FHz9qg9vqBt1VTVoYCNd2qaYaNJG/29qmMaSm30O/XXyzEZe4S/DF7cLRmDUeCoytY UikEMN5nN/TsyisDq8bLb9d3/9TkBMebeVUnBNtqg3gnJ/FMhrsZvYtni0l134SO5H76 VYfoFzJW5VGyyJ+wGiX0LjKbVeKPI+Dgvb93A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=raQvSM5V/uMvgqOsdMStTvPP8E1jqsk9wa9DPg9FZM8=; b=n4Ix2hGYZWmTmQGlzDUyApYZ7IJOlLP+E3NnKavXJ6H0ZrDVpBLoRDmzHHUfc7ccEv Ubl+ye4u5MyPnZi+k1FJ9qLgDG7nDf0wHljlIMcvGrZfl4dPMy5OqKa50QPgdzKyKhVD drbDGnk/DOJr490JFO4znk6MxtbMJu/pvRxG3vJwSLQ9tWsG/FSTmsp/hXozg36dqCh/ t2ZUlBconshbk4y8XH9ngNnoUHtbLiZ7oMnuUXpqxKvURhG1c88et+zOzxXf9eB3oIw+ jmC/XXbozsUbZEXNiWegRnOghxIvugj5NNP0oFU1vA7pYF978RfhONQEIVGL0BzANYia vlFQ== X-Gm-Message-State: APjAAAW3RcvhXOo7VxGgwuNge+8CC3nyWsksAlM1q/HWRNbbOBsS9LvW bTY1/Ofsrafh0BzetrTy/BDYOw== X-Google-Smtp-Source: APXvYqyniqRgXTBNCmKcTESug8rjHaeK7Uxfak70Cz/Vrue0dxlUhVtDJIqEBQzy/JDyESeD9UdZ0w== X-Received: by 2002:a62:be0a:: with SMTP id l10mr29348868pff.110.1580785041112; Mon, 03 Feb 2020 18:57:21 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:20 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 09/12] videobuf2: let user-space know if driver supports cache hints Date: Tue, 4 Feb 2020 11:56:38 +0900 Message-Id: <20200204025641.218376-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS to fill_buf_caps(), which is set when queue supports user-space cache management hints. Change-Id: Ieac93f3726c61fd3b88e02c36980c1f3c7a82ecc Signed-off-by: Sergey Senozhatsky --- Documentation/media/uapi/v4l/vidioc-reqbufs.rst | 7 +++++++ drivers/media/common/videobuf2/videobuf2-v4l2.c | 2 ++ include/uapi/linux/videodev2.h | 1 + 3 files changed, 10 insertions(+) diff --git a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst index 9741dac0d5b3..80603f57eb8a 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -165,6 +165,13 @@ aborting or finishing any DMA in progress, an implicit - Only valid for stateless decoders. If set, then userspace can set the ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag to hold off on returning the capture buffer until the OUTPUT timestamp changes. + * - ``V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS`` + - 0x00000040 + - Set when the queue/buffer support memory consistency and cache + management hints. See :ref:`V4L2_FLAG_MEMORY_NON_CONSISTENT`, + :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE` and + :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN`. + Return Value ============ diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index eb5d1306cb03..22ae0ff64684 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -698,6 +698,8 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) *caps |= V4L2_BUF_CAP_SUPPORTS_DMABUF; if (q->subsystem_flags & VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF) *caps |= V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF; + if (q->allow_cache_hints) + *caps |= V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS; #ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 169a8cf345ed..12b1bd220347 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -951,6 +951,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_REQUESTS (1 << 3) #define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4) #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) +#define V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS (1 << 6) /** * struct v4l2_plane - plane info for multi-planar buffers From patchwork Tue Feb 4 02:56:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61419 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNl-001Ywj-Ip; Tue, 04 Feb 2020 02:56:09 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727364AbgBDC51 (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:27 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36844 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727348AbgBDC5Z (ORCPT ); Mon, 3 Feb 2020 21:57:25 -0500 Received: by mail-pl1-f195.google.com with SMTP id a6so6651134plm.3 for ; Mon, 03 Feb 2020 18:57:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QggxwG9xXj9/Y8aTLUoH0ga4g8iQi+a/2zxkwKUkbVk=; b=XVafVv2FGd5SwvcOmpasGzgMAcJ0QWnLsWBGTqB9pizESHAispXx4sC7Jb10NDMUYo H2OK7XfQiWozQxXr5Ewhm3UycEJTq0kdAH2QB+8JHzciaEJTVx/sS21Pag1mdLwtNKD0 8z4VHvNvtsFWkqfB5taldMN3QBu50CAZzJQZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QggxwG9xXj9/Y8aTLUoH0ga4g8iQi+a/2zxkwKUkbVk=; b=Ax+BHAJt1RCWRThrj/6GU1XEFQsSAsa8BKkD7wm7quOmRZSocl9z3e9l4Pp/THn9LL BZ+S5Xt8/yKULTNnkEDU4S6bNYwtUO4JZKeTDA4thcL593fkg8kB8OFLzB+ralMvCPPR ATtwysszX33erUu92wUqWC39jJNiIxHYIVNwdEd+yTiajlak6SAVSadU8+OChn2UiQqO nvJGTYMW7C/MhJuLsrEzVDRM+1YgM0xw7FxvvUhpDDW6kN4TJEBGFa7WHpl3qs8o3vG3 hYwssvFg+MR2YhiGMtjLJK+75Fp0onB97q2iYMKXYB7a20feKRur/zou7sDMA44MziiO /27g== X-Gm-Message-State: APjAAAV09Q3iWexenkCr4iWjvmBai14SbG/0uL+NnPJKk+v0YhnEq4va tHuEOsYYiNiMlo2Q46WFDQspag== X-Google-Smtp-Source: APXvYqw4EPSp/jHl1ZP1MjHFiCpedVdzBc7i6MSfYRUBK4L0qMuQu2sYSCzXYdECmOkCL1RgPljgCA== X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr17785871plo.259.1580785044745; Mon, 03 Feb 2020 18:57:24 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:24 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 10/12] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Tue, 4 Feb 2020 11:56:39 +0900 Message-Id: <20200204025641.218376-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Provide begin_cpu_access() and end_cpu_access() callbacks for cache synchronisation on exported buffers. The patch also adds a new helper function - vb2_dc_buffer_consistent(), which returns true is if the buffer is consistent (DMA_ATTR_NON_CONSISTENT bit cleared), so then we don't need to sync anything. Change-Id: I653ee20302014920b4705f3eba27c0b1232ab89d Signed-off-by: Sergey Senozhatsky --- .../common/videobuf2/videobuf2-dma-contig.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index d0c9dffe49e5..a387260fb321 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -42,6 +42,11 @@ struct vb2_dc_buf { struct dma_buf_attachment *db_attach; }; +static inline bool vb2_dc_buffer_consistent(unsigned long attr) +{ + return !(attr & DMA_ATTR_NON_CONSISTENT); +} + /*********************************************/ /* scatterlist table functions */ /*********************************************/ @@ -335,6 +340,32 @@ static void vb2_dc_dmabuf_ops_release(struct dma_buf *dbuf) vb2_dc_put(dbuf->priv); } +static int vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, + enum dma_data_direction direction) +{ + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (vb2_dc_buffer_consistent(buf->attrs)) + return 0; + + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + return 0; +} + +static int vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, + enum dma_data_direction direction) +{ + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (vb2_dc_buffer_consistent(buf->attrs)) + return 0; + + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + return 0; +} + static void *vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf) { struct vb2_dc_buf *buf = dbuf->priv; @@ -353,6 +384,8 @@ static const struct dma_buf_ops vb2_dc_dmabuf_ops = { .detach = vb2_dc_dmabuf_ops_detach, .map_dma_buf = vb2_dc_dmabuf_ops_map, .unmap_dma_buf = vb2_dc_dmabuf_ops_unmap, + .begin_cpu_access = vb2_dc_dmabuf_ops_begin_cpu_access, + .end_cpu_access = vb2_dc_dmabuf_ops_end_cpu_access, .vmap = vb2_dc_dmabuf_ops_vmap, .mmap = vb2_dc_dmabuf_ops_mmap, .release = vb2_dc_dmabuf_ops_release, From patchwork Tue Feb 4 02:56:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61421 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNu-001Yx2-RT; Tue, 04 Feb 2020 02:56:19 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727386AbgBDC53 (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:29 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34730 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727369AbgBDC53 (ORCPT ); Mon, 3 Feb 2020 21:57:29 -0500 Received: by mail-pf1-f194.google.com with SMTP id i6so8690717pfc.1 for ; Mon, 03 Feb 2020 18:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8h+I8oxNIcMrbLvsm+8Df46AS8oNWipq59orM6/5OoQ=; b=Qb+Op0063itwM7zF2RFmjrsNv3YJmj5LgRFLABUotYSOIhCarSuW8fKd+TFe9XAhyi y1ZRx1+0rv6FfLP0lVijNYckb3zEXXivjrOQaNC4SBXY5Dv0OvJxacxjg90Y2rMqYSk4 JfoBGGHHMGDkDOmZFLdXGlhmgp73izBpnIVP4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8h+I8oxNIcMrbLvsm+8Df46AS8oNWipq59orM6/5OoQ=; b=rHT2y3SHU6i7wfQIJvIhwHy2GtFEVb8GJxGpwDZGTAIkDPq4y5IQcUSV3kbGx0ZFhH YKDPMIZC2kEJZfXxyajXGTgxac5ELvuez0TnuA4V1dChckm4L8scu7JF2fQxdRDYA7dL 7sPJZ4VUH5ci6ujRL1HIhVWvOn9daF1Pc01NSv0K3G3hopak92UUmPLlc/qIxAg86ZB5 IicA/n2bpl4mFX8q25kzdpKzn4QsjdfRxotgmQ+aXsUZ0ZqtwJCqJ7VBd3Wt5/Dnq1Dm uuPrbQV2pWYHY3k4I5jHEo8HP2lNmndfMJHrv79DMpYxkUoJu2vx3JbcRv7EGiF/CGYy ZHBg== X-Gm-Message-State: APjAAAXoZym67yX3eUEQ5z7bWfQnET0w3LWNaFy0H7+lGmOscEsFnkZm dbxaDZxo+qj11U8Oa3sFyT4lFA== X-Google-Smtp-Source: APXvYqxu/ATw/8OV8+fM2uhq19GOMnYoGMlei5elIfGBc5xRNveJHWeIEJNo6C01L8N+dDLi+C7fvw== X-Received: by 2002:a63:f57:: with SMTP id 23mr18739474pgp.46.1580785048241; Mon, 03 Feb 2020 18:57:28 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:27 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 11/12] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Tue, 4 Feb 2020 11:56:40 +0900 Message-Id: <20200204025641.218376-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Provide begin_cpu_access() and end_cpu_access() dma_buf_ops callbacks for cache synchronisation on exported buffers. V4L2_FLAG_MEMORY_NON_CONSISTENT has no effect on dma-sg buffers. dma-sg allocates memory using the page allocator directly, so there is no memory consistency guarantee. Change-Id: Ia0d9d72a8c2a9fe3264ac148f59201573289ed2c Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-dma-sg.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 6db60e9d5183..bfc99a0cb7b9 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -470,6 +470,26 @@ static void vb2_dma_sg_dmabuf_ops_release(struct dma_buf *dbuf) vb2_dma_sg_put(dbuf->priv); } +static int vb2_dma_sg_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, + enum dma_data_direction direction) +{ + struct vb2_dma_sg_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + return 0; +} + +static int vb2_dma_sg_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, + enum dma_data_direction direction) +{ + struct vb2_dma_sg_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + return 0; +} + static void *vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf) { struct vb2_dma_sg_buf *buf = dbuf->priv; @@ -488,6 +508,8 @@ static const struct dma_buf_ops vb2_dma_sg_dmabuf_ops = { .detach = vb2_dma_sg_dmabuf_ops_detach, .map_dma_buf = vb2_dma_sg_dmabuf_ops_map, .unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap, + .begin_cpu_access = vb2_dma_sg_dmabuf_ops_begin_cpu_access, + .end_cpu_access = vb2_dma_sg_dmabuf_ops_end_cpu_access, .vmap = vb2_dma_sg_dmabuf_ops_vmap, .mmap = vb2_dma_sg_dmabuf_ops_mmap, .release = vb2_dma_sg_dmabuf_ops_release, From patchwork Tue Feb 4 02:56:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61420 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyoNu-001Yx2-0w; Tue, 04 Feb 2020 02:56:18 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727416AbgBDC5g (ORCPT + 1 other); Mon, 3 Feb 2020 21:57:36 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:33574 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727399AbgBDC5d (ORCPT ); Mon, 3 Feb 2020 21:57:33 -0500 Received: by mail-pf1-f194.google.com with SMTP id n7so8691097pfn.0 for ; Mon, 03 Feb 2020 18:57:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T/+Rlp1jPgPXZXDmW6x1Q8uODIAHg+YuyNKI1rs3+AQ=; b=EmXtHEzCTNUp3JHhN5KhU5HPB15eaWUPG0ltTwgDk3DdzSA1PfYHzVTn+DARhxhgo3 nLvjBLEeGYMn+Hort7T3uc1tofVXrSkMNya6eRirfPIj/Xws052UlgRc+wOaGRCpqAJT 9DM7TnFZsdY71blpcWhOSwZx/fpuJxEyQEWeY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T/+Rlp1jPgPXZXDmW6x1Q8uODIAHg+YuyNKI1rs3+AQ=; b=OZLlO1raJinDjz4+pgkgEAOAuYgfzyCFf2bFQChp45XGo22eeeS17tk2Nd4sQ3JhRX ju3EhGQKgJIbOg9XNBQBLGAxGEaimSgiqC44x7UiY1vZyJf/ycKoccu9euQgS36nwYlt OuuOS/5h1SDkFz0iwf30F1DOa/HDjdy8b+Unrkc+Yb+Txrn10OVvW/wouW4wWoglIVbt dRECfiEcu6mcZ8lOjrOV6pXRPBGv/52KjMJZqbmBhVov5mwK+zQfZo1UbBsvFe1x/mmX 0QP+743En2tELga1CiIrI3J52AGMwrayZ4eyoEMZ/BcA1BZK/i2t/O8D/J4m5uaY4may +kDQ== X-Gm-Message-State: APjAAAVIrzNbPwzzvUf5OEm5JbHxlXcXgBxukKV2kRKCi1JUlmLOKPvO OW6YXUtccm0qlP8a3BvHc8LaHA== X-Google-Smtp-Source: APXvYqzwUzAu92hNw9mJr15XxdwgDVAgES5XWUbnXAprF2iwJ17UqkCKPZnhqvly83TDtJ8RTtz32w== X-Received: by 2002:a62:7a8a:: with SMTP id v132mr29363613pfc.111.1580785051956; Mon, 03 Feb 2020 18:57:31 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:31 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 12/12] videobuf2: don't test db_attach in dma-contig prepare and finish Date: Tue, 4 Feb 2020 11:56:41 +0900 Message-Id: <20200204025641.218376-13-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org We moved cache management decision making to the upper layer and rely on buffer's need_cache_sync flags and videobuf2 core. If the upper layer (core) has decided to invoke ->prepare() or ->finish() then we must sync. For DMABUF ->need_cache_sync_on_prepare and ->need_cache_sync_on_flush are always false so videobuf core does not call ->prepare() and ->finish() on such buffers. Additionally, scratch the DMABUF comment. Change-Id: I8f6c0b246ccb63f775dcf7881dd5f848c38e7604 Signed-off-by: Sergey Senozhatsky --- drivers/media/common/videobuf2/videobuf2-dma-contig.c | 6 ++---- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 8 -------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index a387260fb321..6ea0961149d7 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -100,8 +100,7 @@ static void vb2_dc_prepare(void *buf_priv) struct vb2_dc_buf *buf = buf_priv; struct sg_table *sgt = buf->dma_sgt; - /* DMABUF exporter will flush the cache for us */ - if (!sgt || buf->db_attach) + if (!sgt) return; dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, @@ -113,8 +112,7 @@ static void vb2_dc_finish(void *buf_priv) struct vb2_dc_buf *buf = buf_priv; struct sg_table *sgt = buf->dma_sgt; - /* DMABUF exporter will flush the cache for us */ - if (!sgt || buf->db_attach) + if (!sgt) return; dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index bfc99a0cb7b9..1fd25eda0bf2 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -198,10 +198,6 @@ static void vb2_dma_sg_prepare(void *buf_priv) struct vb2_dma_sg_buf *buf = buf_priv; struct sg_table *sgt = buf->dma_sgt; - /* DMABUF exporter will flush the cache for us */ - if (buf->db_attach) - return; - dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } @@ -211,10 +207,6 @@ static void vb2_dma_sg_finish(void *buf_priv) struct vb2_dma_sg_buf *buf = buf_priv; struct sg_table *sgt = buf->dma_sgt; - /* DMABUF exporter will flush the cache for us */ - if (buf->db_attach) - return; - dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); }