From patchwork Mon Mar 2 04:12:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61868 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 1j8cPl-00H0dZ-TP; Mon, 02 Mar 2020 04:10:46 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726925AbgCBEMb (ORCPT + 1 other); Sun, 1 Mar 2020 23:12:31 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:36434 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726775AbgCBEMb (ORCPT ); Sun, 1 Mar 2020 23:12:31 -0500 Received: by mail-pj1-f65.google.com with SMTP id d7so883184pjw.1 for ; Sun, 01 Mar 2020 20:12:30 -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=YrB85oXgJhPm+yjrRVrxS1vwiq4+Adj4zLtVRTDt1IY=; b=XqIhMNtbLPC20ZwxGlrkZD/qxwtoK++BXMtCphV5QLovF6Grd/E5Zw8z0k1h8LgD9G as4crmLVxevYfc9ajn7rFWoDyg1yswpuvDTToB3lDmBPNNirXwXnml7bt1ZQP4bQgTrY jfpUW698BM97X5gJcCgKv+ixr39NpERrknA38= 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=YrB85oXgJhPm+yjrRVrxS1vwiq4+Adj4zLtVRTDt1IY=; b=MsMZRmeSELU20j/Gq+QqmcH237JoHNb9m5OxQW3lsufjN6pECN914vBiavu+KgnfyZ prZtxBCognIoRgAWUD68fWwNuo/PE3PqsJXJUfvt6m/egxkjSBeWdpaKM0HeSaMbNAgb K1EiN/XsTw74yiAAa9i2p3L59Ol2jEvKRTdGn/YY7zfWTKADoyNLCJ/mYByTbS8Q1PaU q5ldKxDB11b0Wk2IEom/FUD2f+1DW8NyIflRLVkYF521b9UreGCa0OlTwIJihacRMQU2 62aj86lD2OGAFX0TeiORFRPsPH1910Pw4bfvbHRpe2vkGoczxNX2bPl3Hla5oDwm+fbn Oc1Q== X-Gm-Message-State: APjAAAVrErBca5EDSg9r1nzls4wR0f4Y6B6DhI8EJJmpJ8KE0rbybiuL ddiN5g1R0LDp+ALxBKoFmpe/eYFUjiA= X-Google-Smtp-Source: APXvYqzD0LdRygbrs+muxMi8M08sNfLRRpnD5+s8MAmr+1S1rhkGzEDHXU8xd4ELsMDSGe81J9hLpA== X-Received: by 2002:a17:90a:c301:: with SMTP id g1mr18796339pjt.88.1583122349094; Sun, 01 Mar 2020 20:12:29 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:12:28 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 01/11] videobuf2: add cache management members Date: Mon, 2 Mar 2020 13:12:03 +0900 Message-Id: <20200302041213.27662-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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 members ->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. 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..4a19170672ac 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: when set buffer's ->prepare() function + * performs cache sync/invalidation. + * need_cache_sync_on_finish: when set buffer's ->finish() function + * performs cache sync/invalidation. * 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 Mon Mar 2 04:12:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61869 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 1j8cPq-00H0dl-Gq; Mon, 02 Mar 2020 04:10:50 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727049AbgCBEMj (ORCPT + 1 other); Sun, 1 Mar 2020 23:12:39 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:53257 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbgCBEMg (ORCPT ); Sun, 1 Mar 2020 23:12:36 -0500 Received: by mail-pj1-f66.google.com with SMTP id cx7so664155pjb.3 for ; Sun, 01 Mar 2020 20:12:35 -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=v6z/dbpsAJ3nyjiLy5ZTWHYE+yf0r+oxWKfI3Of1Dd4=; b=cMCH26pCmXb3Ya2wfhiu8tj4o9hBtdJTJvGiu/xRjRKtuOF90yWeozt5trOBt/q2Uh oJ/Yr5KSJIkgOBWJVex2mw3e9nakc8rJFN4iqFW+ZZwfgBAdxs6ubuCYhs1vG4eypZBQ UP/sm6YJo8UaB2p71u2a6c/QskLzlYYJHAH38= 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=v6z/dbpsAJ3nyjiLy5ZTWHYE+yf0r+oxWKfI3Of1Dd4=; b=Af9OF62bq5EC/7p256J1liniwLBSrnFCDsXQtu35+K5cKsYTL5kzZbYj4FmxV1Vo5S nVGXo38NSGopMX4MZHzQWquBNL1GCw4lzUwJ5U8yRue3KAIRgu+rqxTYF1KNLBjRKpdy smLLP5hP6rDSLnIPWxLai14NsDnBt3JS17QOFjpmEcxs0+aX4hX79X2SbvLl8pZYsz+9 5yol4MvQlbqwkf9VXu52UJNePx0fhu6jsXThGf99lqkodJbsUifvepUI7IKgjtZhQQrP 5yhHSYTHe4TcGGGyTLFtLvD4XFvHu7QBVKjeiskzk22fpPVQpXdzR227eDUBRcMX/7Xy yiVA== X-Gm-Message-State: APjAAAV8d/bG8dsCjcQBesSDs5f+/WrATPW+0RjoK0odGzdjbEZhBJwY ttnQc6d9WHmxc/qkHyiSLuz6CQ== X-Google-Smtp-Source: APXvYqwtEuZtuxBPXd8Au6k+ScE/CbCrd3xcRWfZ+WvodYsbeu4koyiICkTyQCwIBXocLulDsiOH7w== X-Received: by 2002:a17:902:8f91:: with SMTP id z17mr16134724plo.234.1583122355107; Sun, 01 Mar 2020 20:12:35 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:12:34 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 02/11] videobuf2: handle V4L2 buffer cache flags Date: Mon, 2 Mar 2020 13:12:04 +0900 Message-Id: <20200302041213.27662-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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 tell V4L2 to avoid ->finish() cache flush. Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-v4l2.c | 49 +++++++++++++++++++ include/media/videobuf2-core.h | 11 +++++ 2 files changed, 60 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index eb5d5db96552..2a604bd7793a 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -199,6 +199,15 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b vbuf->request_fd = -1; vbuf->is_held = false; + /* + * Clear buffer cache flags if queue does not support user space hints. + * That's to indicate to userspace that these flags won't work. + */ + if (!vb2_queue_allows_cache_hints(q)) { + b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_INVALIDATE; + b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_CLEAN; + } + if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { switch (b->memory) { case VB2_MEMORY_USERPTR: @@ -337,6 +346,45 @@ 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; + } + + /* + * Cache sync/invalidation flags are set by default in order to + * preserve existing behaviour for old apps/drivers. + */ + vb->need_cache_sync_on_prepare = 1; + vb->need_cache_sync_on_finish = 1; + + if (!vb2_queue_allows_cache_hints(q)) + return; + + /* + * ->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 = 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 +429,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); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 4a19170672ac..731fd9fbd506 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -632,6 +632,17 @@ struct vb2_queue { #endif }; +/** + * vb2_queue_allows_cache_hints() - Return true if the queue allows cache + * and memory consistency hints. + * + * @q: pointer to &struct vb2_queue with videobuf2 queue + */ +static inline bool vb2_queue_allows_cache_hints(struct vb2_queue *q) +{ + return q->allow_cache_hints && q->memory == VB2_MEMORY_MMAP; +} + /** * vb2_plane_vaddr() - Return a kernel virtual address of a given plane. * @vb: pointer to &struct vb2_buffer to which the plane in From patchwork Mon Mar 2 04:12:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61870 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 1j8cPt-00H0dl-9U; Mon, 02 Mar 2020 04:10:53 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727060AbgCBEMm (ORCPT + 1 other); Sun, 1 Mar 2020 23:12:42 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:44686 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726876AbgCBEMm (ORCPT ); Sun, 1 Mar 2020 23:12:42 -0500 Received: by mail-pl1-f194.google.com with SMTP id d9so3652961plo.11 for ; Sun, 01 Mar 2020 20:12:41 -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=CoetZS9vuxTZ+PyAPLZRJLnoTD2MnEuUAYGHdJwiBqs=; b=LeRfzwHi8oJoYEV2ftWQe6u50EWhhQZErNapDPcIjTb+Sd6R+fd6x2IjxUt+XQhNf8 j3ZI4/4J3cIKXc7PaiH6lBD/2Pp+QwBfngL7jp79eovCh7kgZhzCiYbhKnbAVb5NPsbJ F0Ds2wnMtOJjpW89Q27zB3LGw0t3dUbPoNZ98= 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=CoetZS9vuxTZ+PyAPLZRJLnoTD2MnEuUAYGHdJwiBqs=; b=jDT5TyExsuHOaViN1hL2LsOHLtMD91NOo3OEhS3Im5A840Xtqp0wtObqEiCUQ6HzEO KSP4y2D2ymncR9ikW+xptaRUkpJ13ztwNYxwxqKWsuMOHa1myIwQZJDULONEDwjSQ7Lm mngfp7L46ml6jIQuD3K0qHqKRUpmyy746Nx32jUNGHmjwB72FV+XYkqYt1v4PDgqXN6N yupss444U3KxuezDFbv/piYpwgegyP8XGD4TfwyYlmz4/MziWrcjBgywsOciGCnSxgxY eL9B9LTSxIq1zIcQWV+Erz0rWVPPPrOT+kamqf0LjbZfSxjoWhPr8J2DICViopK1ibFk Vs1g== X-Gm-Message-State: APjAAAVaP9wHHj402ojADTNQIyqK1b0gKVwXmQ8yGaRG04CoguXyIHYf xJaEKmqknN+Xqjpn/KQwYfy24A== X-Google-Smtp-Source: APXvYqwY5WpLZv1Aq5NZ/mOTGi+TcrYj2pNF50u0UD6ple9/IyZ6BApso8aJfGPcuzqnCQ/dbUaULQ== X-Received: by 2002:a17:90a:a88d:: with SMTP id h13mr17972603pjq.55.1583122360698; Sun, 01 Mar 2020 20:12:40 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:12:40 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 03/11] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Mon, 2 Mar 2020 13:12:05 +0900 Message-Id: <20200302041213.27662-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. The patch set also adds a corresponding capability flag: fill_buf_caps() reports V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS when queue supports user-space cache management hints. Signed-off-by: Sergey Senozhatsky --- Documentation/media/uapi/v4l/buffer.rst | 29 +++++++++++++++++++ .../media/uapi/v4l/vidioc-reqbufs.rst | 7 +++++ .../media/common/videobuf2/videobuf2-v4l2.c | 2 ++ include/uapi/linux/videodev2.h | 3 ++ 4 files changed, 41 insertions(+) diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst index 3112300c2fa0..8084e3f2a58d 100644 --- a/Documentation/media/uapi/v4l/buffer.rst +++ b/Documentation/media/uapi/v4l/buffer.rst @@ -681,6 +681,35 @@ Buffer Flags \normalsize +.. _memory-flags: + +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 + - A buffer is allocated either in consistent (it will be automatically + coherent between the CPU and the bus) or non-consistent memory. The + latter can provide performance gains, for instance the CPU cache + sync/flush operations can be avoided if the buffer is accessed by the + corresponding device only and the CPU does not read/write to/from that + buffer. However, this requires extra care from the driver -- it must + guarantee memory consistency by issuing a cache flush/sync when + consistency is needed. If this flag is set V4L2 will attempt to + allocate the buffer in non-consistent memory. The flag takes effect + only if the buffer is used for :ref:`memory mapping ` I/O and the + queue reports the :ref:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS` capability. .. c:type:: v4l2_memory diff --git a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst index d0c643db477a..21ecacc72487 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -156,6 +156,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 supports 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 2a604bd7793a..c847bcea6e95 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -711,6 +711,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 && (q->io_modes & VB2_MMAP)) + *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 5f9357dcb060..e92c29864730 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 { /* @@ -946,6 +948,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 Mon Mar 2 04:12:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61871 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 1j8cPx-00H0eC-Uv; Mon, 02 Mar 2020 04:10:58 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727092AbgCBEMq (ORCPT + 1 other); Sun, 1 Mar 2020 23:12:46 -0500 Received: from mail-pg1-f170.google.com ([209.85.215.170]:38155 "EHLO mail-pg1-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbgCBEMq (ORCPT ); Sun, 1 Mar 2020 23:12:46 -0500 Received: by mail-pg1-f170.google.com with SMTP id d6so4749319pgn.5 for ; Sun, 01 Mar 2020 20:12:45 -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=OPhC0uGdWtK6uqXkI9lBErx3+QeFq4eF7/uoPZxJkTQ=; b=FmgJNDpIAoxVhImLQMSu3dC3dzeJZR5gAA5tBj3L9KybU4mZrYWDKCykSFHzhiNwHn 8XlBR3Boa1wfENsAnxDtR34d44O/W+GUyZ2emMgXw/GJBharvYXLqaPwF/qcDC1VW55v Ro4oJYLrlQvgA7V4wWCIgNRhgTlS38xk3z/Hg= 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=OPhC0uGdWtK6uqXkI9lBErx3+QeFq4eF7/uoPZxJkTQ=; b=hg1FTH8QBrGpcFtgaSfOWkbN2IOb3U46AbbIUUbPgTJrRbs3TTQqKVgXJZP9i5wLyy RxmzkGX0LoEvdqZtGq7Q2WLtl8R3iUADpBZ2MnwW6MkcwU56lsfQiaUX4MLHYzg2nN0l yFG0sw+NAknNw56XgHwNttJD2yvJysF07sTudPCVw0S7+f8E9dn3bW2CenXK+/bbv4jH 1ivFFZ+vTppeB9Wks41O4p5jmMJPyqT/tEvoF6XAeUL4b7RiCHE22nMQVCNsovm8Psua SKh7agCuFwQEeFO+K0FFReWcaB4ZQg+/UjvTxHU896/VMnqCiQeil/8ldzyfI7Pmzmxp t7Qw== X-Gm-Message-State: APjAAAUCGcNNTouI0qIP8rEyl+/+ucqp/YxXkTxcin2QIInnDQhAfTdw X8GO3TzzBwDlzrn5hOTUwFG9+g== X-Google-Smtp-Source: APXvYqxurk5Uwet4tGl1PKrI5IWghbR2AtLBTDvWBo0KtgvRhJ7BvNHxii3NEjh4cWxHxNr4+H+U6Q== X-Received: by 2002:a63:3d44:: with SMTP id k65mr18176896pga.349.1583122365094; Sun, 01 Mar 2020 20:12:45 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:12:44 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 04/11] videobuf2: add queue memory consistency parameter Date: Mon, 2 Mar 2020 13:12:06 +0900 Message-Id: <20200302041213.27662-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. 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..3ca0545db7ee 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 (!vb2_queue_allows_cache_hints(q)) + 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 c847bcea6e95..6111d74f68c9 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -724,7 +724,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); @@ -798,7 +798,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); @@ -974,7 +974,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 731fd9fbd506..ba83ac754c21 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -737,6 +737,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 @@ -761,12 +762,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. @@ -784,7 +786,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 Mon Mar 2 04:12:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61872 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 1j8cQ3-00H0hD-3q; Mon, 02 Mar 2020 04:11:03 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727113AbgCBEMv (ORCPT + 1 other); Sun, 1 Mar 2020 23:12:51 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35804 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgCBEMv (ORCPT ); Sun, 1 Mar 2020 23:12:51 -0500 Received: by mail-pf1-f196.google.com with SMTP id i19so4905024pfa.2 for ; Sun, 01 Mar 2020 20:12:50 -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=KcBsmcqC9Zy3qd/UWgqdrnUuk/NhCvM/xrZuIvcDti8=; b=j4PQZrVlcD4GIoWCZnGkyRCynfgZmeRPchSumCRpuon/RnuCEeohc7LokPDbSULOxu 72a31S9tWTvxleYFiXnDMvuEF0GcAiuo0m6Ks7qPK65Si9/Ajl9tOkgGpCJ5hFYHM7JK bcs4tyjSrkgHQWt2yaTeiC+rUS+G6Z36G2Yv4= 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=KcBsmcqC9Zy3qd/UWgqdrnUuk/NhCvM/xrZuIvcDti8=; b=YykFWK1U5gl0+ZCMnjTzMNqIeDBo9lO1cK/WCbZWReA/Aq37+kEsxf63R5044HHjoF pp6aThIGtsHsExw6CwEImz3WOyFap6x/kHW7SmEB6rwOk1UW+Kld9zPwEmIr//Qbx/9W HFJ7AMSf3a3Wvl+heiKyvM5GJon7jeUKmFhJLJGWE64TTNJhVFs7970zsgXVC5lv9D+Y K0mbI0fOJNUlOkrWI1mNxNC60AsgX0S+q3rcL/LtpeCYSvzGW+oDzoK3DlPnd7Lq7M+D udJVGH1foIOTspodoGX966Nr4awjm59UX3HOn53ZLGF/hWI0JRz075C5/+7Hhsnobt1l imdA== X-Gm-Message-State: APjAAAX0DBhOmFe7LNA/ddM1FFhhl+Lt2y3jPnxCW6poCPT+6E7vs7+V 5b2xwA8EBizOYFans2LAgtFebQ== X-Google-Smtp-Source: APXvYqzWqYzaARJVSR+9sCYfnEzigtts3d3/gmrHrjKJhg8SRyJHiNsPGWNbQI8izO51VFAShoXAHQ== X-Received: by 2002:aa7:9218:: with SMTP id 24mr15996303pfo.145.1583122370242; Sun, 01 Mar 2020 20:12:50 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:12:49 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 05/11] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Mon, 2 Mar 2020 13:12:07 +0900 Message-Id: <20200302041213.27662-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. Signed-off-by: Sergey Senozhatsky --- .../media/uapi/v4l/vidioc-create-bufs.rst | 7 ++++- .../media/uapi/v4l/vidioc-reqbufs.rst | 11 +++++-- .../media/common/videobuf2/videobuf2-v4l2.c | 31 +++++++++++++++++-- drivers/media/v4l2-core/v4l2-ioctl.c | 5 +-- include/uapi/linux/videodev2.h | 8 +++-- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst index bd08e4f77ae4..a9c6c89f5098 100644 --- a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst @@ -121,7 +121,12 @@ 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. + See :ref:`memory-flags`. + + * - __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 21ecacc72487..faf0df4f9bb6 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -112,10 +112,17 @@ 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. + * - union { + - (anonymous) + * - __u32 + - ``flags`` + - Specifies additional buffer management attributes. + See :ref:`memory-flags`. * - __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 6111d74f68c9..b4b379f3bf98 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -722,9 +722,18 @@ 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 (!vb2_queue_allows_cache_hints(q)) + req->flags &= ~V4L2_FLAG_MEMORY_NON_CONSISTENT; + + 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); @@ -753,6 +762,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); @@ -798,7 +808,14 @@ 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 (!vb2_queue_allows_cache_hints(q)) + create->flags &= ~V4L2_FLAG_MEMORY_NON_CONSISTENT; + + 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); @@ -968,13 +985,21 @@ 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 (!vb2_queue_allows_cache_hints(vdev->queue)) + p->flags &= ~V4L2_FLAG_MEMORY_NON_CONSISTENT; + + 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 fbcc7a20eedf..53b87bfd50d7 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 e92c29864730..12b1bd220347 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 */ @@ -2446,7 +2449,8 @@ struct v4l2_create_buffers { __u32 memory; struct v4l2_format format; __u32 capabilities; - __u32 reserved[7]; + __u32 flags; + __u32 reserved[6]; }; /* From patchwork Mon Mar 2 04:12:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61873 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 1j8cQA-00H0oi-Ck; Mon, 02 Mar 2020 04:11:10 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbgCBEM5 (ORCPT + 1 other); Sun, 1 Mar 2020 23:12:57 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41655 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727142AbgCBEM4 (ORCPT ); Sun, 1 Mar 2020 23:12:56 -0500 Received: by mail-pg1-f193.google.com with SMTP id b1so4744679pgm.8 for ; Sun, 01 Mar 2020 20:12: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=eaNPcBjkoKZw1bZcJWbUbEpJEQzWw7qCsLqY7OuM15k=; b=oWp+xew/5VjbY2VZwDp/ZZ+7rQIDc5nONr9JZ0WBHtYgxkp8TZKiW6Xt4YDwrvz/wQ 48yqizhHxj8W+QO0pIzDkLiTUq8OlPJp90EVOR8A/tYZgWea2xDVx9T89gpr0Xd3WfN3 T0EeKnLT5zM4RdcMPkPrY5pyjmF83jONU0rms= 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=eaNPcBjkoKZw1bZcJWbUbEpJEQzWw7qCsLqY7OuM15k=; b=CkPKG0cmvQT8MOzE6kh0kvi3v3assIKhEjzZixBI+sgXWrtYCMLI4hqVbmFV4Eqg0Z 5NSrNkKD0mLK4PJuc9SsHvL8PPQCjDxLILoRMeHautgWD+s7BaJCLFhUOx44IJjbP2pq QtySkwRfPRx4Gm3Pnq+5oXGO9old6iExd8CzzXUb4Fmskz3eZk+YKxyH50dSgCmn5SxI aMBnbgpNZHCLVVZy9MAr33RIIIt3VBwr/DcZlqGTXNtN/hhM6pOWc5/gQTOSlRJmQbwt p44zwDM7gyfB1hO/u3+dbLQYqvEYk59uUKvGeL/XFShJKheEbfaNYMJqCW2wyiYAbCxQ Qs0w== X-Gm-Message-State: APjAAAW4IMSicSJmo2HObpmV/EONb9JiyV97q4JlF3q884C8GfwUAyXE zBeHgwn2cMubu+pj2rtfmtwDIw== X-Google-Smtp-Source: APXvYqxV8HL12nYDfQCZsn/ISpkGM1DIsy5iTaoNK/U3rk4TatYUKSuRZ0YeY+zUlf2XkmWLJvKI5g== X-Received: by 2002:a63:2b0a:: with SMTP id r10mr18087328pgr.213.1583122375798; Sun, 01 Mar 2020 20:12:55 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:12:55 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 06/11] videobuf2: factor out planes prepare/finish functions Date: Mon, 2 Mar 2020 13:12:08 +0900 Message-Id: <20200302041213.27662-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. 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 3ca0545db7ee..c2a1eadb26cf 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 Mon Mar 2 04:12:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61874 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 1j8cQD-00H0oi-PU; Mon, 02 Mar 2020 04:11:13 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727181AbgCBEND (ORCPT + 1 other); Sun, 1 Mar 2020 23:13:03 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41649 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727084AbgCBENC (ORCPT ); Sun, 1 Mar 2020 23:13:02 -0500 Received: by mail-pf1-f195.google.com with SMTP id j9so4891253pfa.8 for ; Sun, 01 Mar 2020 20:13:02 -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=3A85FNkQVK15E41Jw/YnZSYCbOfj7OMPE9KsvpyVprI=; b=iQoz4D3GwiW8h0XeU8c1Et605eWVY/JK+54169MH68UJ0X99a18+0g9Tm8xc/DDmAp mj8ZAhEVfO7rt3RTDu/RzFnPjOY4zldofCKucp1E6RT9nL4gfhu0c5e3+dEF17zFAFSg Td/fdZ3uqYCSPBmyLKwkHZa3JvzRlak5lPFXU= 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=3A85FNkQVK15E41Jw/YnZSYCbOfj7OMPE9KsvpyVprI=; b=nyQhSenojjpS2qe/2knI4zFVO9oqSn40wliohncD68PlqPpqumM/uIOwI4OszgzW2a 02UwjFscOqQ0JJHvGHXIm9S5GkcJeSX8UfW5nPPqG02ETpxBbV7Nrndw4MLHFl837pW9 5vbzfAXI/KLVxasJLDz+EKhvnS1WcYcbC4bbieEr/pfejqQBvgrQlGHfXhjRQg2Tn4sD 9nYNdwAEjcpAxJb5T8q06e49ZJbDDIjqqTIF1Ck/k/T5zR9pmXlVjASXmqOjx9dnFAWh XwkK8gq0lSz9aEmNnkpCOyp34rdgydtMWHNLFYKvMVxzrV+EO/X7pHEPlQv50zCesnH+ 21Eg== X-Gm-Message-State: APjAAAXUeHFdw7LTGbu6BwDIr25DzsfE+Re5uqKiBYgyPxUrwfVE2x3a NoXHOSZUFHAdaTedBpnjGRpkQYsiX68= X-Google-Smtp-Source: APXvYqzfiVrxV9y838Pte2LCUED/pNzCk7VJWEWdqJQlV3pzdVO6cxXqP0Ax/IK/3vv50IjpTeBGBw== X-Received: by 2002:aa7:8299:: with SMTP id s25mr15628477pfm.261.1583122381683; Sun, 01 Mar 2020 20:13:01 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:01 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 07/11] videobuf2: do not sync caches when we are allowed not to Date: Mon, 2 Mar 2020 13:12:09 +0900 Message-Id: <20200302041213.27662-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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). 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 c2a1eadb26cf..988e8796de4f 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 Mon Mar 2 04:12:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61875 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 1j8cQO-00H0pC-CZ; Mon, 02 Mar 2020 04:11:24 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbgCBENJ (ORCPT + 1 other); Sun, 1 Mar 2020 23:13:09 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46698 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbgCBENJ (ORCPT ); Sun, 1 Mar 2020 23:13:09 -0500 Received: by mail-pf1-f193.google.com with SMTP id o24so4875928pfp.13 for ; Sun, 01 Mar 2020 20:13:08 -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=n1tFCzw75kCxqGljRqUUqQ24ppDX2CtviVmHlh9ZwXI=; b=SVTwb9xCDylxA8meFAf4DNHy1L02yYnt+Xnqp7zusYHBzO777tMWuyug3GcSsAPwDz Afs+J9ArrufHaKwPHWwVG6Orv3Pcf8BzOc7FTjbdW7LOw4N79tS+Up+hBW+/3WzsjDn3 D4Cg4w9UK83GxIvJmjR3tAKaoyO8fbMFtX5D4= 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=n1tFCzw75kCxqGljRqUUqQ24ppDX2CtviVmHlh9ZwXI=; b=txZCG5q3zuFwGcke1INcBir8kqh/tbVwCPMDovFCg+1g7z013SpN8JEfLfDgqs8JW8 uvgpCuYGyx/MbFLbt/0e4BfpTyYqUB+mB/sJTOELM66moC2TdFqLvlUPZ+GRn1NDKT8Q R6UrNkLSjVOImSbPBqeuknnM7qxA24lhsmQVqJWFCecD4spE0Ti+Wx/v50dkAqKK1ybd sH+tWuOptrxXYvZjleEEqSjCCh0vCihrnaSaq2fgJ4D3I04p0Nit0ezIiIK0S//9hvp2 bbvdmzox699LRggsQRc13oFbjd922bMwYzyoRkFNVrgPkShCYiM5a4o6VZ8vf5QrMkx9 +PGA== X-Gm-Message-State: APjAAAUydbW/8kTUhiOsftmBr5JGLr+PJ7zOytOdkWNewtf+i0wloaJL dTVZGdqOImsCgWRF5lidQTE6BA== X-Google-Smtp-Source: APXvYqybi5EYjqyckazY+Gfhnp9nuxz2JxRXBkIO1IkSF+K1quDA1KeL8eaBFfOWeBHOItlSEUgZgA== X-Received: by 2002:a62:768d:: with SMTP id r135mr15601049pfc.108.1583122388345; Sun, 01 Mar 2020 20:13:08 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:07 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 08/11] videobuf2: check ->synced flag in prepare() and finish() Date: Mon, 2 Mar 2020 13:12:10 +0900 Message-Id: <20200302041213.27662-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. 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 988e8796de4f..7f637e3a50ab 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 Mon Mar 2 04:12:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61876 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 1j8cQT-00H0pQ-W0; Mon, 02 Mar 2020 04:11:30 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbgCBENP (ORCPT + 1 other); Sun, 1 Mar 2020 23:13:15 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:38428 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727226AbgCBENP (ORCPT ); Sun, 1 Mar 2020 23:13:15 -0500 Received: by mail-pj1-f68.google.com with SMTP id a16so3520292pju.3 for ; Sun, 01 Mar 2020 20:13: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=JCmxjKYr6h+HQkJ8I2sAt9HA3Gj5LCEzRtahfHgdo0A=; b=dvSjq7Zw/Qc5F8sFmiaMtJkkUXhJhepVHY2UABgyeaMKBuNgDzwVtU68FnJijUdrMQ WmBiIWa7qp+6yC1mTg+ZFE0LqEybSHbuC+TOmGZ83GdhiFOvOuowkiKC+eXkPH2v1zsk q8K9wZwejOY3M98hsOW8Y8SVJxtMyMRXvnokE= 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=JCmxjKYr6h+HQkJ8I2sAt9HA3Gj5LCEzRtahfHgdo0A=; b=gONer4ecTkLexRFnlFZJTMXuC3lwpRXe7Qv0A/LeQGhpw4yxUTs+4W0QUmAINKqkwh Zi+WSUiT3mpcSQCDWVeolCDsHDoypUqp34Qgea0pacmzcXiRW7jciDrIYTyFeci/sya9 IMp/unU0A9aUQtBZDJkuRtCB71sjrxP1sDYld6zKkMbVStk4MYelVzKSMgamfaAShN18 WF+aIMdccWTKeqhT8Fbm9pGvKgbqA0L8pbxptbtCj1h+WFTSqiwpVSy87MZ3VBGS4+u/ 8hGd1svFpwBp42SlxUyMwJxyKsH5D0A+oac9ilUjr6dTzvZQeLXoa+ATFy69Fh3E9Utv W31w== X-Gm-Message-State: APjAAAVfLqXZ1yJ/5VB2ZEPpq1Yqq5VjARLyhgkP8FnVrYHw2nICqTp3 +h7SzC4vOJrnI0C+9t143jDugzUIh98= X-Google-Smtp-Source: APXvYqy4WoGZXuS24GnnShv66EtDO3MG/qipYpf7F76NoK5QMZG39PHMDR+xMttQy4YKpzrD4GK2bQ== X-Received: by 2002:a17:90a:c301:: with SMTP id g1mr18799146pjt.88.1583122394164; Sun, 01 Mar 2020 20:13: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 d82sm1698114pfd.187.2020.03.01.20.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:13 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 09/11] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Mon, 2 Mar 2020 13:12:11 +0900 Message-Id: <20200302041213.27662-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. 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 Mon Mar 2 04:12:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61877 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 1j8cQU-00H0pQ-T0; Mon, 02 Mar 2020 04:11:31 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbgCBENU (ORCPT + 1 other); Sun, 1 Mar 2020 23:13:20 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43823 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgCBENU (ORCPT ); Sun, 1 Mar 2020 23:13:20 -0500 Received: by mail-pl1-f194.google.com with SMTP id p11so3650775plq.10 for ; Sun, 01 Mar 2020 20:13:19 -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=vqnI8gtSZFQZzEwQepw4bYm9gKT2/CP5tzXnaA3LBtQ=; b=h+hb2CDBO3It2UCMkrG6UzXN8ZD97LJ2y7IP1ZA7oK9uwPR3WHp/TwSiOUMa49OxJn PAgUXLXDG+kcoQ1a72e4ZpOzvGyAQOsDNGAQi+JCI2CA9mgpy3nNVexqzHZOrEd0q/pf DOy3XfvenMlwx2AtPL/jpZjYDi93yW2odD17k= 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=vqnI8gtSZFQZzEwQepw4bYm9gKT2/CP5tzXnaA3LBtQ=; b=nbTbmIAykihvPAQhnPV68YqDz19Z20h6OSeoEJc9goVLP+hxZscj61pSD/NUqdSkIe 1pSmG227r0nnxZv6NfiZoUXuDcqV3j22//XSBpZaAICGLa4zHwRyoX3DQ3tqMfDX8DaM RL4jl3vlsRsndUBH3MtR9vlyQ5a18MShamgJmTCGuuUsTIkLqFTUNa80eaB16LPSjeX0 xm8/Ipy4H7EkqsHgdoUOxyms/XsAIOu3h3Q3uoVURJyLe/GKmq3SjGYeNPsfvYwpTk3V Ht1aDcXgpH2tmkkD5tOnofuZj8s82Qe31M38+/XK8W+J3W37WMak3o1YsfWcdA9oWgaU 43pQ== X-Gm-Message-State: APjAAAXoT+XdGXTfofJbbx2RIN/Wqq8isfziEw1f0fWNWm/CxgiR+RJn ithgfWM6jzgYFa+8dXQ2POPkXA== X-Google-Smtp-Source: APXvYqwfxxAXtiIt2hNbFb1EKkOpeM1qWBuwmSb8pUM3hAaRD5PccjlfUFm6MgFAeFfQPW80413mwQ== X-Received: by 2002:a17:90a:664c:: with SMTP id f12mr17907257pjm.61.1583122399076; Sun, 01 Mar 2020 20:13:19 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:18 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 10/11] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Mon, 2 Mar 2020 13:12:12 +0900 Message-Id: <20200302041213.27662-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-dma-sg.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 6db60e9d5183..ddc67c9aaedb 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -120,6 +120,12 @@ static void *vb2_dma_sg_alloc(struct device *dev, unsigned long dma_attrs, buf->num_pages = size >> PAGE_SHIFT; buf->dma_sgt = &buf->sg_table; + /* + * NOTE: dma-sg allocates memory using the page allocator directly, so + * there is no memory consistency guarantee, hence dma-sg ignores DMA + * attributes passed from the upper layer. That means that + * V4L2_FLAG_MEMORY_NON_CONSISTENT has no effect on dma-sg buffers. + */ buf->pages = kvmalloc_array(buf->num_pages, sizeof(struct page *), GFP_KERNEL | __GFP_ZERO); if (!buf->pages) @@ -470,6 +476,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 +514,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 Mon Mar 2 04:12:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 61878 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 1j8cQd-00H0pt-QJ; Mon, 02 Mar 2020 04:11:39 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727307AbgCBEN0 (ORCPT + 1 other); Sun, 1 Mar 2020 23:13:26 -0500 Received: from mail-pf1-f173.google.com ([209.85.210.173]:44777 "EHLO mail-pf1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727194AbgCBENZ (ORCPT ); Sun, 1 Mar 2020 23:13:25 -0500 Received: by mail-pf1-f173.google.com with SMTP id y5so4882997pfb.11 for ; Sun, 01 Mar 2020 20:13: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=CxsIIu+/8DSr9yF0CIvvdp+l+R1SqYNd7xvzR+EPPKE=; b=NfkXxwE0BJXx6VznfLq3+TLrkcYj+Bd8JMt7XwZ/gLY6AnA12lM4KgasNRpqCaHJ/3 WZDZRB0oBnZGfd9KLE+ZF4S+mVBeMuImh9aIpm+02SemxBUTOmOHkPwlK0TxSw87erKC EHpO7rLpaKKo5/AgmsafdCRkBQkS3yWp37CsE= 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=CxsIIu+/8DSr9yF0CIvvdp+l+R1SqYNd7xvzR+EPPKE=; b=jVEf2cE1Q9dzK9nWT0cgIOv2PXlH/7MP25WEwhCDP2uAchJvRxdWQIrwmNbniRIBt+ LlkbVodQs9B4Gz9RBUAFTY2lF1mb4xCh6WBmYFXSgxMYOd/8mgZVbwhw44WLllREBuVH VIyi53lHLh6xfVobQW/chqV+Bbb1F3ZkVRDJ7d7N9xthNhou47bWwhP4TOO+lWd9YO+R 0CqxkXEbM78aDp5jVYOqdwc27Lc66+OpV5L1c0v5jHuiH5I+tDB2b2pko5ptsQwaPEjj I4DJNpnje8oFwReT4+ny9Cg/Y4EsLic6oTzvpeAceeOu7Xqe30F3s4/xqTqC9eLVQkUc w1OA== X-Gm-Message-State: APjAAAWnV6yhmvjaLV3Ul+6zEWhWascXx5/PRDY3ufsZVFvE4ZTvS6WH kpD5FMKnuHWidwmtPFs+dzkQyAaxOfE= X-Google-Smtp-Source: APXvYqy2P0RLXAO/iaD6PSxmAoR9E0Ta7ZhsYA/73Gha5XVmyVbImRUyF/AYogQA0cr6jsaCacRF1A== X-Received: by 2002:aa7:9789:: with SMTP id o9mr14416433pfp.138.1583122404529; Sun, 01 Mar 2020 20:13: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 d82sm1698114pfd.187.2020.03.01.20.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:24 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 11/11] videobuf2: don't test db_attach in dma-contig prepare and finish Date: Mon, 2 Mar 2020 13:12:13 +0900 Message-Id: <20200302041213.27662-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-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. 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 ddc67c9aaedb..2a01bc567321 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -204,10 +204,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); } @@ -217,10 +213,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); }