From patchwork Tue Dec 17 03:20:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F2A1112B for ; Tue, 17 Dec 2019 03:22:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D20C218AC for ; Tue, 17 Dec 2019 03:22:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YVDNNgjM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727205AbfLQDUs (ORCPT ); Mon, 16 Dec 2019 22:20:48 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:46611 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727135AbfLQDUs (ORCPT ); Mon, 16 Dec 2019 22:20:48 -0500 Received: by mail-pj1-f67.google.com with SMTP id z21so3890894pjq.13 for ; Mon, 16 Dec 2019 19:20:47 -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=0gw2WS97E5ShS4EFOOCzORU1xpTlrM5Z/donDWDF7mI=; b=YVDNNgjM5etiFQrJcTUTaollxlxvDIKwIvPu2HtyAPe++/UBQSrkXOF7/m9WgS14NU Nec4nDWahlnGX0mjpbyTqhtxEfsAcEPDjd6cRFSkqlIJXnYX5pyEg2ae5wewd7j7g58N 68NqpsQEc+/pSLg8LYCtQy9kfaNbZRoAIy+3M= 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=0gw2WS97E5ShS4EFOOCzORU1xpTlrM5Z/donDWDF7mI=; b=Wr+zgxmcSmicJwMaHdhgFemMAzE8+AU9rt11RqrnGSIrCS8wF/cCVYKVDGDn1R62Gl HMzxMV+4X6qtZ1i9Q3o1a1sZ+9GLbtcj0DvQjwnu9aWXA4o1dJvXb7raHpfaqZvQruLW na8BzRQawbw5IBj1Ayo/l3eEb2XP6CnttPYie1k9olUu0nIBAwxTrALu4bB+BOfTTBhj QRKM6IlImYqOxnKp5ZQSbdKXOApTWDFi7qXbm5r6D9ZROmVBPU1wVmF0FC/4+UfnfrpV 1c43+fNnneilMk5sN5BWHUmebc6Uljl1mnuTj2pmwRjlDzdtnZvyqSmnXcJtuN4uz0vq lXZQ== X-Gm-Message-State: APjAAAXRn0UxoL6GkWMTFquIXtqsNVdtmD+GjtgFld75eUXuL7F4iyMe oEW4ekT4TGyx8tikm5sxCk0v3w== X-Google-Smtp-Source: APXvYqzXQPTSjofGjWn62rO0KIyfidaxbVkZuEOZ9EyPk6iQ9ahpXwmaqzpUpWu9UAP4nsApVBNuLg== X-Received: by 2002:a17:902:6b0a:: with SMTP id o10mr19518464plk.15.1576552847255; Mon, 16 Dec 2019 19:20:47 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.20.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:20:46 -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][PATCH 01/15] videobuf2: add cache management members Date: Tue, 17 Dec 2019 12:20:20 +0900 Message-Id: <20191217032034.54897-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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. 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 Dec 17 03:20:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5C7DE139A for ; Tue, 17 Dec 2019 03:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39A8524672 for ; Tue, 17 Dec 2019 03:20:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="AuyeJPrs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727298AbfLQDUw (ORCPT ); Mon, 16 Dec 2019 22:20:52 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36308 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbfLQDUv (ORCPT ); Mon, 16 Dec 2019 22:20:51 -0500 Received: by mail-pg1-f193.google.com with SMTP id k3so4853215pgc.3 for ; Mon, 16 Dec 2019 19:20:51 -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=XQU25h5Spo3bbOg5zOxdwOlScB+ZgzGM7jWNIFKX5qo=; b=AuyeJPrs+C5UHSNUQ1/hQz67goI/N0/Nb7veYBfr9IiTDOqWSusJ64kUodFVC+g3ju au+IMXsBOOZJm/80/2yPSIoD4G7H/AuV0fgOMGhlZ+l9PRwgliwtPFaMCOCxbynLR6Xq X4KY88/Vc75Hfm3bFXlrPJ0Sn1Jd+guYRU5jw= 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=XQU25h5Spo3bbOg5zOxdwOlScB+ZgzGM7jWNIFKX5qo=; b=lEHkiHZTMyXkvBu6eKujuWi5Dgok5Est+p2xaVuXBpg5cVdh/XE/9WCRGeCNtzjlY0 nTDFlPVM5SmvK3mAapV/AjKw1Uz49kE7dT/2ohur/YmRtVYbsyfeQJ9tNUiGxcbG6mE0 euMtU3MbZ4VbarAyZ9raovqjG0lemqtidNMc2HUpRv8LPk6DLT26tHV2m4+fZTOZ0Jwu 2MBB0oT8+csufwuVfOn/OeJAX4tlXboPTCLv579l8iRu30HkwpUTcdGzHSYnXVsuXF6/ 21XfLsFvSDG3uOB3qcfgrrxya/wqNx7H+AP7aP+92vcvp3a/Nwi8Ye8YBMDxU6tkqY2i XmBA== X-Gm-Message-State: APjAAAU6DtVciti4fgYrECg1gZzmWy7U/h5OcJVIqG3f7p3uJk3up0HH e5FV2Sd6ECiRF6biqMN9z9VZdg== X-Google-Smtp-Source: APXvYqyJzexYK0ODH7UR7ZIPwhL2sqGBeU3kvXT48fiBc4VyqOBa54ERKTM3FDd+ldv7CbjUZmf5Rw== X-Received: by 2002:a62:d449:: with SMTP id u9mr20535023pfl.225.1576552851080; Mon, 16 Dec 2019 19:20:51 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:20:50 -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][PATCH 02/15] videobuf2: handle V4L2 buffer cache flags Date: Tue, 17 Dec 2019 12:20:21 +0900 Message-Id: <20191217032034.54897-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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. Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-v4l2.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index e652f4318284..2fccfe2a57f8 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -337,6 +337,27 @@ 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) +{ + vb->need_cache_sync_on_prepare = 1; + + if (q->dma_dir != DMA_TO_DEVICE) + vb->need_cache_sync_on_finish = 1; + else + vb->need_cache_sync_on_finish = 0; + + if (!q->allow_cache_hints) + return; + + 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 +402,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 Dec 17 03:20:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EAAFA112B for ; Tue, 17 Dec 2019 03:22:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8DD021835 for ; Tue, 17 Dec 2019 03:22:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ciRLBiY6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727338AbfLQDU4 (ORCPT ); Mon, 16 Dec 2019 22:20:56 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38141 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727327AbfLQDUz (ORCPT ); Mon, 16 Dec 2019 22:20:55 -0500 Received: by mail-pl1-f196.google.com with SMTP id f20so3641135plj.5 for ; Mon, 16 Dec 2019 19:20:54 -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=ZqrDhJWgamLEnJ0f+brWH5beGZW3pxf2EqtCOMwdJgg=; b=ciRLBiY63+o+8cMoR1Kw48sNUnjhyOCQZtFN2AexGo3e5cIwHq1miF7ZBa7MvDakPj /XjXlF1uV+68e45tDtV3jKx4Mo7VbE05xzqMQ+dyNh64lG84W/oJE6YZRej99Sv8KTzb KOIl/O69xGS4G0jgY7L+2CUeit4CwKF9N3QYM= 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=ZqrDhJWgamLEnJ0f+brWH5beGZW3pxf2EqtCOMwdJgg=; b=AtC2sx9K2QdmgRyoOV6GXreN/s7TDunSApA7arrepGyNK7MZCOq5B0kIO3EvZ0EXyD +uu0BCfpxnLvAgzCCP6/BZWxQ2a9pJ0GeMs6G1iS1zMVdfgL/tu9NmPAn8bOxWWDk1p4 iWo+6L2+2hOcwHrlFjjWl1w8as2s2aj/Qk93Mmu9wLf5LRUFWvi7UTGTbeSQ+PEA64oD Je455zGXDLNNlEkM0fZaacQLqfB3TNGI33k1mSrh+0FpEbzKGIxMQ8LykYvPoG2wPi/O xHclt/IpCXGjV8bDJfALTcKKR5L5IXLaBR1scd2fM3UUIsSfDud1rXVhbLtC+OMbjCiz fozg== X-Gm-Message-State: APjAAAW2hJYuRXq4k+CNKqra57QtpVnzw4Wq6DhBymlJidh1GtaFyy+J DB4NIUQGBnToar5V6awJzVDL6A== X-Google-Smtp-Source: APXvYqw5ABjXI02YnEoGwgEOZOpJzyu7CZRg0ZYyfTMRaQSNW88K9oAZ4u+zuKSnSQ3smW8TIFh0rQ== X-Received: by 2002:a17:90a:2710:: with SMTP id o16mr3311690pje.110.1576552854487; Mon, 16 Dec 2019 19:20:54 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:20:54 -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][PATCH 03/15] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Tue, 17 Dec 2019 12:20:22 +0900 Message-Id: <20191217032034.54897-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 user-space will be able to request consistent or non-consistent memory allocations. Signed-off-by: Sergey Senozhatsky --- Documentation/media/uapi/v4l/buffer.rst | 19 +++++++++++++++++++ include/uapi/linux/videodev2.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst index 9149b57728e5..b08b5609f5f3 100644 --- a/Documentation/media/uapi/v4l/buffer.rst +++ b/Documentation/media/uapi/v4l/buffer.rst @@ -705,6 +705,25 @@ 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 + - Set DMA_ATTR_NON_CONSISTENT queue memory consistency bit, + so all queue buffers may be allocated in non-consistent memory. + enum v4l2_memory ================ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 04481c717fee..d352997f2b62 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 Dec 17 03:20:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70515139A for ; Tue, 17 Dec 2019 03:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43ED1218AC for ; Tue, 17 Dec 2019 03:21:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="UP/Ni4kC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbfLQDU7 (ORCPT ); Mon, 16 Dec 2019 22:20:59 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40189 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbfLQDU6 (ORCPT ); Mon, 16 Dec 2019 22:20:58 -0500 Received: by mail-pf1-f194.google.com with SMTP id q8so6728174pfh.7 for ; Mon, 16 Dec 2019 19:20:58 -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=FZaVeJ1PcpIK1+RAgv+t01ZSozUenljGrTod0GVW8cM=; b=UP/Ni4kCwtM4CJbIx5FkbMSeWzYLsbm1yhBu3gEXT7WHHlsPXSgA56HyxkEfh8qdjJ IDej9jhliSUBzQlQIJ43tGwEaL0dXZn3s7B+oSOzivKuVX5C3UIPhpmj9J3ZhS6lVeFW 3MeMCMBEx3bAgTUK9xKU8tleckIZDR9Q8ITG4= 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=FZaVeJ1PcpIK1+RAgv+t01ZSozUenljGrTod0GVW8cM=; b=o/+pbTfiIsoXwudJSV1ZHTG6K3aCf/I5rnEutx06AC0GesQeSIlf6cMCt2Q4YjaP/L I0wvraS6uOQrmP937bn4pZP686jEHAaI26F685J7KzO/XPVzXvt6BdM48Mha4eIzEOnz yM4Zrha3hv2pEI016XVm9VCQqOvb+0Rri8sGba8s9BWDljlUU7de4NscimiAaUz1d8XV mT82SMmTmAe4IICIcfdDZCt1m85qGP1pT5dDnBe3RgM5kI35NZKDHWX7hAf+NTAI6DaF i3LaerTv9TNhMkSJUlbL/8sc4ZZEDJzYKIa9dGBkKniB7RL5+lrP5t2aj/zGfQ/VMQCP YgAw== X-Gm-Message-State: APjAAAW/KEbZtZzEFK35qH4/P0RAlXFQZpZbVu7rsNu9dj/C859HrRv9 mnRdSr9TNdfy+0LEjMnt8InHpg== X-Google-Smtp-Source: APXvYqzWlMHyMZoG/nm6t6U32w0jijpNQVnnJZCAUGdgiXRK3mUZ6A/LrGPH/s4Aa5Q1o38IzWq1dA== X-Received: by 2002:a62:f842:: with SMTP id c2mr20092420pfm.104.1576552857748; Mon, 16 Dec 2019 19:20:57 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:20:57 -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][PATCH 04/15] videobuf2: add queue memory consistency parameter Date: Tue, 17 Dec 2019 12:20:23 +0900 Message-Id: <20191217032034.54897-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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. API permits queue's consistency attribute adjustment only if the queue has no allocated buffers, not busy, and does not have buffers waiting to be de-queued. If user-space attempts to allocate a buffer with consistency requirements which don't match queue's consistency model such allocation requests will be failed. Signed-off-by: Sergey Senozhatsky --- drivers/media/common/videobuf2/videobuf2-core.c | 17 +++++++++++++---- drivers/media/common/videobuf2/videobuf2-v4l2.c | 4 ++-- drivers/media/dvb-core/dvb_vb2.c | 2 +- include/media/videobuf2-core.h | 3 ++- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 4489744fbbd9..668c56df13f6 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -664,8 +664,16 @@ 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 (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 +728,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. @@ -2498,7 +2507,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 +2564,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 +2584,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 2fccfe2a57f8..f1e88c9398c7 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -695,7 +695,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); @@ -945,7 +945,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..810af5cf5742 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,7 +751,7 @@ 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 From patchwork Tue Dec 17 03:20:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74CDB112B for ; Tue, 17 Dec 2019 03:21:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48E6F21835 for ; Tue, 17 Dec 2019 03:21:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Ui0YYV/v" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727420AbfLQDVC (ORCPT ); Mon, 16 Dec 2019 22:21:02 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35031 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727404AbfLQDVB (ORCPT ); Mon, 16 Dec 2019 22:21:01 -0500 Received: by mail-pl1-f195.google.com with SMTP id g6so2794423plt.2 for ; Mon, 16 Dec 2019 19:21:01 -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=YT5zPdi996NXjchiwCDqVrjFoOKLt3bLnZH+tVb9/cU=; b=Ui0YYV/vw7P9G0lo0Y1sMgKALXnDBU/1UuD8ANc+wq1Yx7zco/LjVCgBzjejWw2DGQ 0SNg0OnPnCC4ixuLPiBkPfPEOhibXdreAC4HTi+Mq4S6LJGSe7sMpAhKOak33ma2EWxy aias37z7+v1UA3EQLPmFro4zEdMJnB74zEHAQ= 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=YT5zPdi996NXjchiwCDqVrjFoOKLt3bLnZH+tVb9/cU=; b=sfsyRsXKCRI4H8qewvXJCtS5nRHl8hYkjILcHTcxjivhJxUz4EaPqxWo4BGLfkwX6y MMsEsYzo/jjvgPifcdXt8HBKyGKxEujMOaLkoqJmNqvoUmi8aQJcYMHBkLc9rIz+JrM4 hOZl1DS3jDOAB+NL2yLKOEHzkyzHr5/GjcJ53rqDQrPzvQ5lYxpsNhn8dDqufaK/+Mvj 2UTMDtrDTd8b1g1f5ZhjpKoMcEjiyHjb6pyZHgp6SK0t7NAp9lnfhj4JL3J1ztAPhKsj 3STuruql2EjmEU0t848WERzeYTSjVTfcd1tjcQbRhFl2hiIq2q6lAE5u/ZXaCsI6c9us H0UA== X-Gm-Message-State: APjAAAUdMlIkY9GvnG5JQr2WFhFpqzIxzq+5Yckh4Udku6pkOJjCAK/0 98H2VExiodUh8Lfc+cOqelMoUQ== X-Google-Smtp-Source: APXvYqxzE0ZN2M7MmqYjMlHuc5TaV0+MgkaG2yIcNH/4jH6GMMY2mueWihj+lF2Qdzbxj3sAqtQ19g== X-Received: by 2002:a17:90a:2201:: with SMTP id c1mr3355615pje.31.1576552861030; Mon, 16 Dec 2019 19:21:01 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:00 -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][PATCH 05/15] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT in REQBUFS Date: Tue, 17 Dec 2019 12:20:24 +0900 Message-Id: <20191217032034.54897-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 REQBUFS ioctl call. We use one bit of a ->reserved[1] member of struct v4l2_requestbuffers, which is now renamed to ->flags. There is just 1 four-byte reserved area in v4l2_requestbuffers struct, therefore for backward compatibility ->reserved and ->flags were put into anonymous union. Signed-off-by: Sergey Senozhatsky --- Documentation/media/uapi/v4l/vidioc-reqbufs.rst | 14 ++++++++++++-- drivers/media/common/videobuf2/videobuf2-v4l2.c | 14 ++++++++++++-- drivers/media/v4l2-core/v4l2-ioctl.c | 3 --- include/uapi/linux/videodev2.h | 5 ++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst index d0c643db477a..9b69a61d9fd4 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -112,10 +112,20 @@ 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. E.g. when + ``V4L2_FLAG_MEMORY_NON_CONSISTENT`` set vb2 backends may be allocated + in non-consistent memory. + * - + - __u32 - ``reserved``\ [1] - A place holder for future extensions. Drivers and applications - must set the array to zero. + must set the array to zero, unless application wants to specify + buffer management ``flags``. .. 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 f1e88c9398c7..0eabb589684f 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -693,9 +693,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); @@ -939,13 +945,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 003b7422aeef..225d06819bce 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); } diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index d352997f2b62..73a4854f71bd 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -919,7 +919,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 */ From patchwork Tue Dec 17 03:20:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296461 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09351112B for ; Tue, 17 Dec 2019 03:21:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D10CE218AC for ; Tue, 17 Dec 2019 03:21:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="i/ffzUXf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbfLQDVF (ORCPT ); Mon, 16 Dec 2019 22:21:05 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:39847 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727403AbfLQDVF (ORCPT ); Mon, 16 Dec 2019 22:21:05 -0500 Received: by mail-pj1-f67.google.com with SMTP id v93so3899686pjb.6 for ; Mon, 16 Dec 2019 19:21:05 -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=XSIy5bU94C7ExHq7Mxstf+ZVIzUJSJLIevrqaI1BwGQ=; b=i/ffzUXfVt9ZVc0stEesFNrjgw0DgFTgnazWdSmVjUdaF4UrOQ8Dx/ZZc1CEuUCPuT mCPabxbaIHgCWY0xCCjYAoWVl/gSJBIqwpvrDwpa6USXPGH+8OaZiutiAoXWRlv9u1nn q1mMlBvhiYlY0fOPqOM/R+6fKPHw4oxi3PwWs= 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=XSIy5bU94C7ExHq7Mxstf+ZVIzUJSJLIevrqaI1BwGQ=; b=QvcRqQPSxBF3XxJb9VMX/ng59KZA0BoNHk26Tif7cOR7O0ufRkfnch1jECRvlo0HgC QjTnkbx3A5Gbn2QJz2PPZOowS9RMQRCQYRu0Fr32B5dZ8wwqQ4VJQFgROEOlF6vnVIsW y26K19LK7BNtmJKPRsKG5ULC9qJdA3GdVSoZeVUQXZFwgIY/wmOJSleYiYLVyYukago4 fcSj34YL3/JNwcZCOiz7D7awtcHZsCbX4WFdT54k2aKAIBqx+oMkICVdZVb+8Bz3gPLh 9BXTb+5IQSp5+xchJQGgbHNOTIcLQEILE3DLKlOi7hJHqFEwZDM2O1/zv2nGsoX9JGz6 frAQ== X-Gm-Message-State: APjAAAU6V8CtsJW7tM8Sgwllj9TnxzhFAvmeGUIgVoU8MwWOTZZm40Aj Xzbs/1Bq5JAtCSNMgfcKs19Z4Q== X-Google-Smtp-Source: APXvYqw7z1newpbr75KraDdAFl8jI8gFHUGldCPXISbX2B+3Bvi/c6fT5pmaTId5yAiaOHSv8AHUzw== X-Received: by 2002:a17:902:70c1:: with SMTP id l1mr5558074plt.26.1576552864564; Mon, 16 Dec 2019 19:21:04 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:04 -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][PATCH 06/15] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT in CREATE_BUFS Date: Tue, 17 Dec 2019 12:20:25 +0900 Message-Id: <20191217032034.54897-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 ioctl call. 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. Signed-off-by: Sergey Senozhatsky --- .../media/uapi/v4l/vidioc-create-bufs.rst | 8 +++++- .../media/common/videobuf2/videobuf2-core.c | 27 +++++++++++++++---- .../media/common/videobuf2/videobuf2-v4l2.c | 7 ++++- drivers/media/v4l2-core/v4l2-ioctl.c | 2 +- include/media/videobuf2-core.h | 4 ++- include/uapi/linux/videodev2.h | 3 ++- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst index bd08e4f77ae4..c56e80659b4a 100644 --- a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst @@ -121,7 +121,13 @@ 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. E.g. when + ``V4L2_FLAG_MEMORY_NON_CONSISTENT`` set vb2 backends may be allocated + in non-consistent memory. + + * - __u32 + - ``reserved``\ [6] - A place holder for future extensions. Drivers and applications must set the array to zero. diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 668c56df13f6..d1012a24755d 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -812,9 +812,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] = { }; @@ -832,10 +844,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); diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 0eabb589684f..48d123a1ac2a 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -730,6 +730,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); @@ -775,7 +776,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, + + 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); diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 225d06819bce..793cb6534de4 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -2012,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/media/videobuf2-core.h b/include/media/videobuf2-core.h index 810af5cf5742..5e5450bdabbd 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -757,6 +757,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * 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. @@ -774,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[]); /** diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 73a4854f71bd..82e2ded5a136 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -2419,7 +2419,8 @@ struct v4l2_create_buffers { __u32 memory; struct v4l2_format format; __u32 capabilities; - __u32 reserved[7]; + __u32 flags; + __u32 reserved[6]; }; /* From patchwork Tue Dec 17 03:20:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296463 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BC8D139A for ; Tue, 17 Dec 2019 03:21:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F9AF24676 for ; Tue, 17 Dec 2019 03:21:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JuuHTj7J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbfLQDVJ (ORCPT ); Mon, 16 Dec 2019 22:21:09 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34101 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727490AbfLQDVI (ORCPT ); Mon, 16 Dec 2019 22:21:08 -0500 Received: by mail-pg1-f195.google.com with SMTP id r11so4863513pgf.1 for ; Mon, 16 Dec 2019 19:21: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=Ej/RcdrFG7I5h21qch/EfpaB8ZDY7oPr0PYcdyttmnc=; b=JuuHTj7JvaiZedUrJCfHiCf6RQkVD16TxV/PkyG4BS4uIEZkVWX0sGB6LA0Dx5PTju 41XOdwITYe577fjGfzFvpivruURkH7Z01wnrZ0FT4crH+pG6hUC+/o9L8jlNUN0uD4HI Z7B1fPuRMEDeKDYffEuzMs46hja0cIHqYneac= 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=Ej/RcdrFG7I5h21qch/EfpaB8ZDY7oPr0PYcdyttmnc=; b=Jx68yV0ntCNTFaDrNQmtXMY7LDzaGLDJNqDOERaE7kQbijPmGOzz+r1b07mQRPnGs1 5kuMZL2MJy/il2y5JKx+3juXBKX6wC1l1DLvhJen6tkFmM3aq5MNqXnw+es3+nWAldUO JZ/85gCeTstbNlPNrdAF2SemBwxu0ka2NzJ/ABBxi3BB/C0y6MrKUgcy/tkArFv1XOYi LyNHhtZAAqhm2A7AAkTfbXPnE5ZmOgmBi+e/2cw6HV0JOTub7ZfkNkxurtv+zBOHQk9h +3HQ9tF//Bv6xb7YmnIGrPFIIL7lAutDQ0yEHXuvn48H2Rm3+nU6unh+EQDKUxO17sM8 dfIA== X-Gm-Message-State: APjAAAW10zXRQpkUiL4MYFY58/3hjjuDl33AbePia/7aqE1iMp+WbvVQ iMeaCGb78PstYnXpnzlSkLJi1PRCRRI= X-Google-Smtp-Source: APXvYqzg1hoSwFIM3BoSZfc7Iw2qROpqjjZt0tHFcE4/EsgoChomyU3ntCswNMphxXxycQdPzPUlQA== X-Received: by 2002:a65:5cc2:: with SMTP id b2mr4958161pgt.51.1576552867920; Mon, 16 Dec 2019 19:21:07 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:07 -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][PATCH 07/15] videobuf2: factor out planes prepare/finish functions Date: Tue, 17 Dec 2019 12:20:26 +0900 Message-Id: <20191217032034.54897-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 d1012a24755d..492ed2577219 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. @@ -948,7 +974,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; @@ -968,12 +993,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) { @@ -1298,7 +1319,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) { @@ -1342,11 +1362,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; @@ -1966,14 +1982,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 Dec 17 03:20:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B6C7139A for ; Tue, 17 Dec 2019 03:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 583DD2176D for ; Tue, 17 Dec 2019 03:21:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Dyrw3mAK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727704AbfLQDVu (ORCPT ); Mon, 16 Dec 2019 22:21:50 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44628 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727513AbfLQDVN (ORCPT ); Mon, 16 Dec 2019 22:21:13 -0500 Received: by mail-pl1-f196.google.com with SMTP id az3so5393370plb.11 for ; Mon, 16 Dec 2019 19:21:11 -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=dTJtBCRtUW3V7cvpTHf5hNJH6T4sX7RfeAH8a1VqWM0=; b=Dyrw3mAK7lS1NG/iW0+Kzcp8KdP5+6eyVm6g0DnFK9kY9Qj5cRN7SWSXKGJCTqyJsd R+sqX9sfDXF7mQlJPgrE9sPOnUBv3oJTDhF75o1OHTBkONfv2zdCmST1VI0KjrRNeHUm UyYsC5Bxuv9hC6gqmRhxTx+Psj4VLUhsKxCzE= 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=dTJtBCRtUW3V7cvpTHf5hNJH6T4sX7RfeAH8a1VqWM0=; b=O6tN9ItHck4Vm1KbFgGF2Fo0OL0y+N8chB+fYLjzpGcZBTB1vJQz/bfUiQYJN6ICm6 cxE9YoF1Qq6QmeQ5YGdKWtTbquIKybvMHhE+5CwnmJhTl9m3ZwAlIIXXC0b6OoIbold7 Q0rdSiZJwZRIdH5D4YD7OwQerADmGtj+XRju+4kA2JLZGUIY23KXn8NvJyu8dHjhgvb7 R0xlELvNkxdAEf4tTwcRoET9i+3Webj1VEg+tozQfAKkb5cX3ghSo+1mJuXvrCBthUuG KsuNkig0KzmmAgcJ5/gB783AFNNTAUVvoKbafsm2ty/emXwu69nljrwF8z96F2oo2F/T /rCw== X-Gm-Message-State: APjAAAWsW73jzGoE65TxhirvAUofsrIWIMg1uF5G0FqR0ONLg8yq7IsV i9F5uZq7EZsnEZwyG52riCOmgA== X-Google-Smtp-Source: APXvYqx4WvFFvGRdNjuNVketu96/9otNgHem3YkTRcw9GCeLvmQ7pzz7YlHGkDHF6Jbzu+Fg5vVrlA== X-Received: by 2002:a17:90a:77c6:: with SMTP id e6mr3353366pjs.129.1576552871239; Mon, 16 Dec 2019 19:21:11 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21: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][PATCH 08/15] videobuf2: do not sync caches when we are allowed not to Date: Tue, 17 Dec 2019 12:20:27 +0900 Message-Id: <20191217032034.54897-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 492ed2577219..4e81a8447472 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 Dec 17 03:20:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1F55139A for ; Tue, 17 Dec 2019 03:21:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91BE824680 for ; Tue, 17 Dec 2019 03:21:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="j4/agWyg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727541AbfLQDVQ (ORCPT ); Mon, 16 Dec 2019 22:21:16 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:42676 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727526AbfLQDVP (ORCPT ); Mon, 16 Dec 2019 22:21:15 -0500 Received: by mail-pj1-f67.google.com with SMTP id o11so3895925pjp.9 for ; Mon, 16 Dec 2019 19:21: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=escyPo0HyMcbQwbzT/wvxCSXmIv+1oW68eibce/V5cA=; b=j4/agWygYcZZdJSrUqdHMfoy7ZrNwSLYHD46v9PEAcD+2NUGXaqaPKGTx9JsKQJuUk 3S7MWCeEEwb523wrtIp9jn0e1nggY8ylldONjSgs5IBJY9Qey8vec2DMmYlNtHaZR/Mm XTYdKnRVy4vK6+9pbx94z+oFuhr93QtQFX4j0= 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=escyPo0HyMcbQwbzT/wvxCSXmIv+1oW68eibce/V5cA=; b=R34gbxRlD1HwggUYHhZdClC63jr/fPuV+TE7eZ6IVuCeKTjeAmV1AYupXEhTPWleVd vPCUeLGzYiQCqUD3qpIfLYplt5GeYlxwbgqmcvkdQ9xtO1IivGLFxsYW76Kp6UVFWJ64 i/5ofN9uCBKl4DAH5W87n5jvAk298yefRUcBYO/7EQdT1TNStel2Uyk4tpuOcRNYeGIL 0jq0iiYKUZZEHx5W5SAcAYhVgo0UrUUePKYdWZ2fgQwyHhmd7jpHbtG0hUvwvrwgHIc9 +axsBFums2brSunMSSeoMeJExe9itNYYE/QFOaRhHK02qiN9XbfBf5N6vM6v+jJDwe// hLgA== X-Gm-Message-State: APjAAAXTKA9zsdRCiDIdH/OXTjgJKy6KUC+4FZY5xlElyl8ANDLW3c9x BHUXHtHnBsbMnEHl4Xl6ib6aNw== X-Google-Smtp-Source: APXvYqz0XbKVQBHosaIaTdMXI13Y9uP2Oac2PjiqyPaTx4WhhBquQTr2b1xrAYABg1zWyMH9xpj+iQ== X-Received: by 2002:a17:902:9682:: with SMTP id n2mr19731860plp.336.1576552874555; Mon, 16 Dec 2019 19:21:14 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:14 -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][PATCH 09/15] videobuf2: check ->synced flag in prepare() and finish() Date: Tue, 17 Dec 2019 12:20:28 +0900 Message-Id: <20191217032034.54897-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 4e81a8447472..0ec10802e9f6 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, @@ -1988,8 +1994,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 Dec 17 03:20:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296467 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B6A5112B for ; Tue, 17 Dec 2019 03:21:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58928218AC for ; Tue, 17 Dec 2019 03:21:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="BBtVGsMs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727572AbfLQDVT (ORCPT ); Mon, 16 Dec 2019 22:21:19 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44642 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbfLQDVS (ORCPT ); Mon, 16 Dec 2019 22:21:18 -0500 Received: by mail-pg1-f195.google.com with SMTP id x7so4835898pgl.11 for ; Mon, 16 Dec 2019 19:21:18 -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=9bAWCFHMKxSYudc9xD0mtxl2wph3ZizEkb+ltF/fPnw=; b=BBtVGsMs2whxo8gii2bpcI+p/QNQAnqcFhqYz4KHXqpr6gixuGZiqazsuOXfgEd31W 0NACv8eevYTpBfRxG02yAOShCwGqI1Fs7roWvTYQMUNAMPa7DdFMaiUBKE5W0hF59KCn BH5JRiI0Dn6x4z3XKFHNHyJK8pL5xFO50IW3k= 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=9bAWCFHMKxSYudc9xD0mtxl2wph3ZizEkb+ltF/fPnw=; b=bbstkyWo8m0CtCeaDMufoEAO1DwueWSBAdt0HeD2qXpBSzomDjrJNUhrntvmS0b7VD dYbun0ELnojo07fi6V/u6DOxzWBu+d4RIb8HF0mYI0AsZZz7QXwiupEwTsLgWKFi6XR0 MRv5HpxlmIeWi3LkxXcZpu5LU33ZF8w3RaFWpZYbMH2Y1SjfpZ5Vkw/7SLxuojLDgGXu 5g0MmQgCKJSSJNMlkwLMZJ8gEqyYoOnOOj4Hvmbc32/l2BUp3uJ1f3R67AouWQ2mU3Q7 ZoBCynqBqSjdgVtsRyxtwFkPKWiDmZZeH1jXzCeSCwp+M+4pFF4YRyEB4tOpz4mq4UQp EMPA== X-Gm-Message-State: APjAAAXeCE/V1jGkwxSKGA1WZtFe/Ld3gG9Waf8/e+bHiu4r7ytV9jz9 uEHyv04BkOm3kF0RTVPaqUHYXQ== X-Google-Smtp-Source: APXvYqyZLTtmMRSnUha4K7/FcPhyMSiJtduh+2WvfTUf+qckUNomryze1L6EP3IgVb1v2AShg3jObQ== X-Received: by 2002:a65:58ce:: with SMTP id e14mr22577119pgu.153.1576552878016; Mon, 16 Dec 2019 19:21:18 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21: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][PATCH 10/15] videobuf2: let user-space know when driver supports cache hints Date: Tue, 17 Dec 2019 12:20:29 +0900 Message-Id: <20191217032034.54897-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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. Signed-off-by: Sergey Senozhatsky --- Documentation/media/uapi/v4l/vidioc-reqbufs.rst | 5 +++++ drivers/media/common/videobuf2/videobuf2-v4l2.c | 2 ++ include/uapi/linux/videodev2.h | 1 + 3 files changed, 8 insertions(+) diff --git a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst index 9b69a61d9fd4..13eab807fdfb 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -166,6 +166,11 @@ 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 + - This buffer supports :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE` and + :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN` user-space cache hints. + Return Value ============ diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 48d123a1ac2a..1762849288ae 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -684,6 +684,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 82e2ded5a136..b5d6b8d4ae93 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -932,6 +932,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 Dec 17 03:20:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1351A112B for ; Tue, 17 Dec 2019 03:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E554D2465E for ; Tue, 17 Dec 2019 03:21:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TkZntt8f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727598AbfLQDVX (ORCPT ); Mon, 16 Dec 2019 22:21:23 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44637 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727563AbfLQDVW (ORCPT ); Mon, 16 Dec 2019 22:21:22 -0500 Received: by mail-pl1-f196.google.com with SMTP id az3so5393541plb.11 for ; Mon, 16 Dec 2019 19:21: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=sKpso3dYUpegkM+13TDZVLSc9HejGiHeDBGlLaBiNPU=; b=TkZntt8fEmKw6hceaNO9bkAbi74L8qrJ0OFAzLrKVD5utQiR4HzeU6o/8ucDhZlH6C njwJ21Q3JOKkRMBoXxWeV7/7ldlqmM0rmhMo04rGOIdrl9khww28BnfekRpilL/aLP2C 0FYhDqxL1CKVQmJc7ifSPfMbTo+ybynMjgdK8= 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=sKpso3dYUpegkM+13TDZVLSc9HejGiHeDBGlLaBiNPU=; b=dOnKO+2zYiJxxWjzwCMyl2X5ou651K3QOG+l8OpTQ9W+a5S+QsIJXWdQTmP9r/Oc9q SX5bNKMDxeRNnMFEZTEFIru0HxyVfeMbFSIEmQYa8PVdg6AHVOeeVzlY6NtbXnJto1Id JGsqTgtVNegpWSHsjumTnQuaW/1fOdY+KPHmG/Thr8oq6ehyAQtOlKhkR4xtcObTdov5 OJb8kcGwg5BJGHY/+5lbe1cHubIDLmP0PDsLaQlylRNufEDhvSWftYsBvdi4G7m1pAxe 9eZ7ZA5/bYwkodnzrsvsuCYm6dYZTQZyn/TRKRT5tAar5MMuKGuzzbt3TnBWFFwfVzjF Hmgw== X-Gm-Message-State: APjAAAXr2UYsC01ikg4ni5fKsa4DcVP6ka5a1uXNfeejuMaUrJi+IoA4 E+MclWxj+JlUAf2xj6jrJB9WCA== X-Google-Smtp-Source: APXvYqxPugT4hclwDVA+EXjf2wIQk1iSgic+RebeA058Lav/MO7sUXve5wYCEQ0D7qGywpjHfB61Nw== X-Received: by 2002:a17:90a:c790:: with SMTP id gn16mr3487094pjb.76.1576552881605; Mon, 16 Dec 2019 19:21:21 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:21 -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][PATCH 11/15] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Tue, 17 Dec 2019 12:20:30 +0900 Message-Id: <20191217032034.54897-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 Tue Dec 17 03:20:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7154A139A for ; Tue, 17 Dec 2019 03:21:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EBE02176D for ; Tue, 17 Dec 2019 03:21:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="D6qNRxrN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727628AbfLQDV1 (ORCPT ); Mon, 16 Dec 2019 22:21:27 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37568 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727615AbfLQDV1 (ORCPT ); Mon, 16 Dec 2019 22:21:27 -0500 Received: by mail-pl1-f196.google.com with SMTP id c23so5418919plz.4 for ; Mon, 16 Dec 2019 19:21: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=w7BgC38Q++csLgKFC6p+4OJvyrlb3C/SOyZ7s22Frw0=; b=D6qNRxrNiByaYF3P2krgxc9qaMsAGuWOVyPKI+3IaZScIOd1bmthdyxh6cUySj7BoJ Gt7WM70dDxw55NQLonwaLHDv5sAiNSlwcxBtiFYufj7u47QEpb+59IChUhHUkRgUS5ku +IedKtqVE5v5xywRdfu1HByIpKnlv1C6JO1ao= 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=w7BgC38Q++csLgKFC6p+4OJvyrlb3C/SOyZ7s22Frw0=; b=ZVZ5RQEB2DrDktFBM1XLaMrB8/OeJpgZ0AY00Fx9mmrijxC3BswHkvLeExAbDcXWMJ Jqv1NLZ5kgaNZAlSV0cmXGvtN+PItbZ32vI420jYMEMJzWfLLvNBx6qSKThJn9M+phBV Ptevkt0xaJ3fVuGC50ejDsQh2MDtWBetqn5Tc5yVVgNgTCmP/o7O74GfFM1/KbeYgpn3 ogNXbussdUs3aPcYtpbNWBPVFDt5+fdfpaZQgYODl3rDRWKZVUu2zeN3svoHDVSSjd2g JLC3U1PxtCQjpmms6+CKO6iSk7UvU0b3FznEwNlT31H2Q7zSXNB4RmqJTsI9RZl9yXht 3bdQ== X-Gm-Message-State: APjAAAXx7TwkuQ+SMqaru6FOj0Kjcc2xEopMM4W6jPjNFUsJO2O/eU0R P8LXuwwUol4c+KOpDYsgFDLnig== X-Google-Smtp-Source: APXvYqzG2MAqV6YaHs0r4AKBZp8nz4G5wu16YR6deYslM0U/r044lJfXdUNlSJk7wL5nlXggt+GmlQ== X-Received: by 2002:a17:902:b418:: with SMTP id x24mr20126099plr.85.1576552885537; Mon, 16 Dec 2019 19:21:25 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:25 -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][PATCH 12/15] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Tue, 17 Dec 2019 12:20:31 +0900 Message-Id: <20191217032034.54897-13-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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. 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 Dec 17 03:20:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1311C139A for ; Tue, 17 Dec 2019 03:21:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E601D24673 for ; Tue, 17 Dec 2019 03:21:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="oZeCVq/h" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727656AbfLQDVa (ORCPT ); Mon, 16 Dec 2019 22:21:30 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:37212 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727646AbfLQDV3 (ORCPT ); Mon, 16 Dec 2019 22:21:29 -0500 Received: by mail-pj1-f67.google.com with SMTP id ep17so3907006pjb.4 for ; Mon, 16 Dec 2019 19:21:29 -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=gLtgY/i7b05+S0YBZciCIKSTFFVYN6319xkmCCskTpQ=; b=oZeCVq/hPIb3xxcfajQ5UCYzJhDjrTKoI88hT6q9n5jtZhfAczWwh2b87k3RDH/L7x VtpK3IlBurnJzyYXucvjKhimVHVfjHzNnAP2J7W5g1XoMGLLsLf2tr5vWsanGgKjQSVN ZVeIy69+i79n+vQdHPu0kw/MSdgWwPmQd+yGY= 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=gLtgY/i7b05+S0YBZciCIKSTFFVYN6319xkmCCskTpQ=; b=EbwX1GmSDkwpDCW7ojf6f18TymoSF+uqyXZjEbTX+lwErNDdf7X9yflEf/ZklWd9Pm fYO9d4z4G0jxF4Qy9cZf7Dc6H+/S/FZDnTq4sg1a/N0yPgfUwfvLxWzzOcUL9jpWeelI bS2rrw11XpJrv5b6q+mCkbig2oQDmOjjvK96zAGO1qmNcM5scAHshPxxMylKI1V9L8Lz BVaS6008D13q26w36EryuhOievS0GsGTrv88bJIO5odDg/FlHNgl4gNGd0pznWCMTLdx Uk+Yt9hkLNe01CTCQvb+jnShBSLI7NoRjXBBSeuI28efQNzmL6B48GxaNS+rSkObtU3V l4yA== X-Gm-Message-State: APjAAAWzgh1bPzUYBXIQ+8G8BpEIwjy3u53QX8lClxG4u5fvBT2iL8kv E+PJZ4EYHoZWgT1N2uqd2O4zHQ== X-Google-Smtp-Source: APXvYqy9neE00p2QbLZnLgRtVcCyK+YWY7iVQlwytjfc2kPnP1pU+M0e4nObBdie3cLEqsIJ7ZArgw== X-Received: by 2002:a17:902:fe05:: with SMTP id g5mr20418282plj.3.1576552889059; Mon, 16 Dec 2019 19:21:29 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:28 -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][PATCH 13/15] videobuf2: do not sync buffers for DMABUF queues Date: Tue, 17 Dec 2019 12:20:32 +0900 Message-Id: <20191217032034.54897-14-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 DMA-exporter is supposed to handle cache syncs, so we can avoid ->prepare()/->finish() syncs from videobuf2 core for DMABUF buffers. Signed-off-by: Sergey Senozhatsky --- drivers/media/common/videobuf2/videobuf2-v4l2.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 1762849288ae..2b9d3318e6fb 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -341,8 +341,22 @@ static void set_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb, struct v4l2_buffer *b) { - vb->need_cache_sync_on_prepare = 1; + /* + * DMA exporter should take care of cache syncs, so we can avoid + * explicit ->prepare()/->finish() syncs. + */ + if (q->memory == VB2_MEMORY_DMABUF) { + vb->need_cache_sync_on_finish = 0; + vb->need_cache_sync_on_prepare = 0; + return; + } + /* + * For other ->memory types we always need ->prepare() cache + * sync. ->finish() cache sync, however, can be avoided when queue + * direction is TO_DEVICE. + */ + vb->need_cache_sync_on_prepare = 1; if (q->dma_dir != DMA_TO_DEVICE) vb->need_cache_sync_on_finish = 1; else From patchwork Tue Dec 17 03:20:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1AB1139A for ; Tue, 17 Dec 2019 03:21:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E2CA2072B for ; Tue, 17 Dec 2019 03:21:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IlxyAEG9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727691AbfLQDVe (ORCPT ); Mon, 16 Dec 2019 22:21:34 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:41681 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727683AbfLQDVd (ORCPT ); Mon, 16 Dec 2019 22:21:33 -0500 Received: by mail-pj1-f66.google.com with SMTP id ca19so3903981pjb.8 for ; Mon, 16 Dec 2019 19:21:33 -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=IFEIyoVpgIiZPWgOi7cYDTwwo0QeHnWmkB+lTxTskhE=; b=IlxyAEG9H/d0X8DB0Z97LY5Y3XW0s5ZYxQ3MmndkfKOb0ZiUNZvSCxwCfJQGOQ/HJT uoVYD/BmTAPepE2OnS+P6ouBsghsigzA1bA/Ko72rb9HNKMwDgWRzGQLPRJXtI86l/5E NL82cHZA0XI3Hs3aSjMb1LXFeCy3LWPlQaDkY= 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=IFEIyoVpgIiZPWgOi7cYDTwwo0QeHnWmkB+lTxTskhE=; b=a7P9UrbNMhx0qg/Ma7jYeeBDMT4MPhOHSbyp4YH3NwdNYEuMyvg5WJhAkYdN5Q5JeH 1KOhn6VLo29wLZa47ebEuiFLE1vLs4CQ4+49SZXchONGuOdhQvBqEfAtehUjE0/cbVCJ CN4Og5shHqLugnOSHAXekqXCj1R3JvN2P/YbSYCujxch3sdi+m4tRgC1HBYiDr1yu+XP QZ3gvgloZnS0vmyUHfHzV7bhuuT1I0vundzI9pDdqtG0yp3Q6dPNEXVicCn/oN5zURDf esc8AcB1ge1MMfOuplenmIu8AJd0uuQbLJo9jI/Xr3IZWz62Upcl16NbOMJ1DnYm4lvT 1Zcg== X-Gm-Message-State: APjAAAUr458dLRBRcZ+EHi7vLKsX5qoWjEsoUR9M3fup5M+xmERzmNpX FXfUjLmoxK99DKmdSee7PfPEYA== X-Google-Smtp-Source: APXvYqzSX2fZ/19yWoefdlEe3u9XKfYlWYyOFbp2pV5FyZoP76hMRJsxZLzKzJ7hQKjOUUMcizqTow== X-Received: by 2002:a17:902:7e49:: with SMTP id a9mr8152934pln.230.1576552892689; Mon, 16 Dec 2019 19:21:32 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:32 -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][PATCH 14/15] videobuf2: don't test db_attach in dma-contig prepare and finish Date: Tue, 17 Dec 2019 12:20:33 +0900 Message-Id: <20191217032034.54897-15-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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 ++---- 1 file changed, 2 insertions(+), 4 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); From patchwork Tue Dec 17 03:20:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C427112B for ; Tue, 17 Dec 2019 03:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08E5D2176D for ; Tue, 17 Dec 2019 03:21:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VOwSHww6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727706AbfLQDVi (ORCPT ); Mon, 16 Dec 2019 22:21:38 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:43790 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727678AbfLQDVg (ORCPT ); Mon, 16 Dec 2019 22:21:36 -0500 Received: by mail-pj1-f65.google.com with SMTP id g4so3900221pjs.10 for ; Mon, 16 Dec 2019 19:21:36 -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=b2nJ0J7FGVQs+cpVk65h/j8h/oCaBmyGaNfS1BBVfwU=; b=VOwSHww64UK8lVnbq0iie30j1G3kCzbmqDSOhcMLrOe1O+CLUVhFWniqYW7RexNBge nBo2pt0lpjO6GvdrKabkT2piCGI88RcSxWH3bpSny9qWrYjuqDmoiDmhe/6CIfeLvSxg Z91V+OE6M3KYE5Cl5zKnukl8t0LV2JfH5n3ms= 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=b2nJ0J7FGVQs+cpVk65h/j8h/oCaBmyGaNfS1BBVfwU=; b=dk4PJm2yTEvpdQ/bTBW41mImCIw8SPJAbcIuBUmJ1sCEMqWIa7xEtfUw66P4DDpT96 DNbNm9lhVsLs4z3phEgBQhHntp4UOBUekPWy9FfSx3XuJR6r/vbahcY+hBT2UH3bYwlr rQFVLaDjBLAkrWiv4NXgIUhgPxty6Kfdcuye3ol8HfQMbj+VuvRhTwek9eOTnOkoUjfP AXkguy8B4DU9F1RfdxkNR+orSt+s8DQvxf9w+nOhhlrL4Rh1xF79ApWpmooaZFnwbwdB pspi8FXSLk8ldMXDJWW5yhNqWUQBV0QfWwg4xg9x4ggpqsaVhE56j11cbjaUUfSLp3DV pcAw== X-Gm-Message-State: APjAAAU8DLYBqRSvokQlXn43VyGKfkbK9AsP35kR+AntzobJU+w4ZjCv s/P2AQXJR+FbZBtznCFrTyzcSQ== X-Google-Smtp-Source: APXvYqxAjpVAxx2qEeWMjQAtg7fvYC66i2cf6WUgxx/HIt3Z3bLSSdGnEBg84jo3LiW5Fp8gRLMzXw== X-Received: by 2002:a17:90a:f005:: with SMTP id bt5mr3433452pjb.16.1576552896240; Mon, 16 Dec 2019 19:21:36 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:35 -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][PATCH 15/15] videobuf2: don't test db_attach in dma-sg prepare and finish Date: Tue, 17 Dec 2019 12:20:34 +0900 Message-Id: <20191217032034.54897-16-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-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. Signed-off-by: Sergey Senozhatsky --- drivers/media/common/videobuf2/videobuf2-dma-sg.c | 8 -------- 1 file changed, 8 deletions(-) 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); }