From patchwork Wed Feb 26 11:15:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406093 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 7504492A for ; Wed, 26 Feb 2020 11:15:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B47824687 for ; Wed, 26 Feb 2020 11:15:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hgGJv/4t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728138AbgBZLPp (ORCPT ); Wed, 26 Feb 2020 06:15:45 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41657 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727882AbgBZLPp (ORCPT ); Wed, 26 Feb 2020 06:15:45 -0500 Received: by mail-pl1-f195.google.com with SMTP id t14so1162389plr.8 for ; Wed, 26 Feb 2020 03:15:44 -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=mzosCDZ9YSkD/x4CCM+TaObJ9SD2EhDn00lJAJGOJhs=; b=hgGJv/4tzhQcLOBcc/oQKPAvgMG5HdG3R7vF6+dy0tfDt6DNt8vwlhTkLLQHQtgmew AdKqPhxNAFtkbDckat1++ysPaq5N/nin9ZBshKcLxhs6aUKDT7mPipfD+waTH0z7gmz5 7Kp9AAwW5bwjbW2sBfXXtYN8pmHF1pPN00KjM= 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=mzosCDZ9YSkD/x4CCM+TaObJ9SD2EhDn00lJAJGOJhs=; b=mVFEUzQ8ZhreNrjgfl3IC7lPaQ159Q6AtYqgUGY1DbWaFQJ/w6QV+qq8lZnefoH0UX w6BIOohWveRcmbjMATOyRZf0CgDUQ1Dql/UkDeSauGsX2ydkmVcrKrnMPojt/uyb7X3+ TO3NW2OcUBOVeiEaFNe6o5QcO5fcxDBkvLCBPHXLhUgT1TQtidmXJJ9nCDQYopKdc0JP WO7fgKqnx9WPFeMsOnKPezuU1akE7OcrftePt3b8WG3JkFF28crO2X0qHzuYwO0sOS9k V8KVRffkkwjaPNBH91aToOquUPux+x6MOy5VwwenNpAKVGFYBZnqyevw4px6bNgDj5/Z ct2Q== X-Gm-Message-State: APjAAAVxM4s7oIR/MWiQVkyDUlMn33DEynz6eLrFDMGKNBesuqR2TV1l D536R8vK0IhiXOW/bW0Z7jklWw== X-Google-Smtp-Source: APXvYqybUJN72qIN2y1/NNv4gWlcpqoFsWdHco+b6//p64lA5aV0ddJ2Jev92l9odEBQqvrAMcPRlw== X-Received: by 2002:a17:90b:3011:: with SMTP id hg17mr4562016pjb.90.1582715743951; Wed, 26 Feb 2020 03:15:43 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:15:43 -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: [PATCHv3 01/11] videobuf2: add cache management members Date: Wed, 26 Feb 2020 20:15:19 +0900 Message-Id: <20200226111529.180197-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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..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 Wed Feb 26 11:15:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406095 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 4B6A492A for ; Wed, 26 Feb 2020 11:15:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2953424687 for ; Wed, 26 Feb 2020 11:15:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dGSlZTIv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728160AbgBZLPu (ORCPT ); Wed, 26 Feb 2020 06:15:50 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:51196 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbgBZLPu (ORCPT ); Wed, 26 Feb 2020 06:15:50 -0500 Received: by mail-pj1-f66.google.com with SMTP id r67so1133237pjb.0 for ; Wed, 26 Feb 2020 03:15:49 -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=651wZiCcSmbV7EdnlDBC6r7lVVXMfelvMaONtYmH5Sc=; b=dGSlZTIvJALW0Ay/Q86Z+WoPDnCql0ogphNSdFSY0lvUlYtbF0wdZ7Iyzq/TppcNoL uKuSqWf8vPkr+vKBufWZCjHUVP5ZItQZ8qn8d4gVsDRIou9z5n2//ZWMJOqWpX0lzgHh pMqZxOqkD/6BQymfCQRu1LTuTfEvYRCi4/rCA= 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=651wZiCcSmbV7EdnlDBC6r7lVVXMfelvMaONtYmH5Sc=; b=B8vacu/DmPcekBYdNOUSRNvv3hndb6Xa59rVMe7gC4EBVT6YoY2gnSjqW65gkxWxPB YG5TJj4JEHlKtyIivT+cRxcvlrXI1a7RWHxYTfgfhfYzxIe0+O9DdX9InoGzhYVxPvnO s+v6QqjqIkDiCfdjpouT3mbUKksILnURC5vt4T7ycBnnypsWF3CN0QVWO+MI424yfs8a IXsWnxFxKuxMwrzpro+DYsD6orOiFt1gLx14R8+dBuKsaG8SklQwpP1dSwXGfYAQea0/ fStL5NMVeu1Mny0JMmeHvKpCbYX/w8bw/CVHfbNSicRiVhlz9FnAH8UTCf6o8USZjiqF Kt7w== X-Gm-Message-State: APjAAAVUzMDQ078tstvH7Dvb9fuB/VaxBbUNlprkW5Sj68QqggnyoQVF Yo3iYbxAr0se0aErwXJX5/zOvQ== X-Google-Smtp-Source: APXvYqxdKX8sN7quJ9bA+4Kv9yTzyPFicnaAjFDpvgexcvC8WL7uuTb2IwlO7oaD1C1sN5+79VQUwg== X-Received: by 2002:a17:90a:f17:: with SMTP id 23mr4414995pjy.84.1582715749377; Wed, 26 Feb 2020 03:15:49 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:15:48 -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: [PATCHv3 02/11] videobuf2: handle V4L2 buffer cache flags Date: Wed, 26 Feb 2020 20:15:20 +0900 Message-Id: <20200226111529.180197-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 | 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..d307869bfb15 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 != 0) && (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 Wed Feb 26 11:15:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406097 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 07CAD1395 for ; Wed, 26 Feb 2020 11:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1BF024689 for ; Wed, 26 Feb 2020 11:15:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DDbUrQU2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728157AbgBZLPz (ORCPT ); Wed, 26 Feb 2020 06:15:55 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:50178 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728028AbgBZLPy (ORCPT ); Wed, 26 Feb 2020 06:15:54 -0500 Received: by mail-pj1-f67.google.com with SMTP id r67so1133308pjb.0 for ; Wed, 26 Feb 2020 03:15: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=dInyMMiO3B5Auyp+XoZ00SzbOn+qaqzJwnevTdhh3/M=; b=DDbUrQU25+ManguKFK0CSk1hrAdVVy3sv/5QFIwJ058MEcyjNp3E0kVkB9u6Nm25E6 aBjieYH4r5sICujusOPMbRZPVVyX7d3kTMWT848r6lM318DpmRaYCg5KrymIcPZV8qCZ AEuJkTSNb/9V0Y18tDFapDvev/+XjrxFegonA= 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=dInyMMiO3B5Auyp+XoZ00SzbOn+qaqzJwnevTdhh3/M=; b=MJIWwzPEpUKsMGsiyT7cCWvEcJMOQCj1VOPrEEQSbVSJgAwBNTNxRI4T9Ora8fUAdS KuJ5PX4vyDmV4rj4AP79TT6x+PozoaqllaMRLWCaVwiLfV5/1UAN3k1Hn2Dhw+gVtcdG xqWJ3fHuKVR3Vh7eTqs77w6jQlyvDvFA95Pz2DGVjjncsjvQB6SmY7Dro8GlNmP18tpQ HvgOQjdnVrDE2y3J9odlxiLldaCnKoadZ4aweL7uVZZjp+yoF2/BK4SRHm5+ZCvd4B3N aE6xVjSGUZsEzJVRUi0jvIUPY7LQp++8+eTpEhVFJF94oIiLG2aYLEPl/jB+3GDYqRc6 1XeA== X-Gm-Message-State: APjAAAUIGhPQpNTAeVLK2aHxxrJFXJr2I6NW+0klG5xxPJjq32arLWEm YxQvedG7IDSO+D9TZcfuq4T05A== X-Google-Smtp-Source: APXvYqzlE+0Xt04PkiDpaAzoFzh8Y4KU3UmBvPjsCEuiitF9ae2DzHMuIZBhRog3SH06R2E1eFeYfA== X-Received: by 2002:a17:90a:1e63:: with SMTP id w90mr4595296pjw.36.1582715753766; Wed, 26 Feb 2020 03:15:53 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:15:53 -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: [PATCHv3 03/11] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Wed, 26 Feb 2020 20:15:21 +0900 Message-Id: <20200226111529.180197-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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..6b629ac59bf2 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 + - vb2 buffer is allocated either in consistent (it will be automatically + coherent between CPU and bus) or non-consistent memory. The latter + can provide performance gains, for instance CPU cache sync/flush + operations can be avoided if the buffer is accessed by the corresponding + device only and CPU does not read/write to/from that buffer. However, + this requires extra care from the driver -- it must guarantee memory + consistency by issuing cache flush/sync when consistency is needed. + If this flag is set V4L2 will attempt to allocate vb2 buffer in + non-consistent memory. The flag takes effect only if the buffer is + used for :ref:`memory mapping ` I/O and the queue reports + :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..917df6fb6486 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 support memory consistency and cache + management hints. See :ref:`V4L2_FLAG_MEMORY_NON_CONSISTENT`, + :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE` and + :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN`. + Return Value ============ diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 2a604bd7793a..f91cba37e223 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 != 0) && (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 Wed Feb 26 11:15:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406099 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 0005F1395 for ; Wed, 26 Feb 2020 11:16:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C1CCA24695 for ; Wed, 26 Feb 2020 11:16:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SAZOfwtK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728214AbgBZLQC (ORCPT ); Wed, 26 Feb 2020 06:16:02 -0500 Received: from mail-pf1-f181.google.com ([209.85.210.181]:42274 "EHLO mail-pf1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728194AbgBZLQA (ORCPT ); Wed, 26 Feb 2020 06:16:00 -0500 Received: by mail-pf1-f181.google.com with SMTP id 4so1292174pfz.9 for ; Wed, 26 Feb 2020 03:15: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=1b4BHY4Of9J2wXt5wOHz3QidKmwZ0F/AozbgxSE3cO8=; b=SAZOfwtK6SSVQoymLsa5PAHPUJIPybhx/Gej0uJL9fQ/kheu+rsXHdueZiDi/dGu/t KgBIhBO8uooNALnzkBzgVMZcNhdhHaQ7iRvyz9rISGBn5pN915cpQxn3O0U5/NtoY9Vf 0d4zoIb6+rwFQfyB2IEiIlve4DLTY6+RPAyms= 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=1b4BHY4Of9J2wXt5wOHz3QidKmwZ0F/AozbgxSE3cO8=; b=k6nxRuhghnKKIxJx7RQjYTOIlHO54sR0ycbMVlmH29OByAptBA1J/uLo6ZuoiVtumu r4l1Rm60Dh5Hxtohm+29MBKEkwJjl5eNvEnONccjQJIJVknG8XZJIVwcM2wJpxYvwgZX WUFRfjGPc726syKzPX06KE4yt24zQhbRnJgzndDJU1LCvLuTtiUld1EgY080Uuo8ZO1E MSCnwNggv2m3imXvU3+MXeMK6CtsEo5GMikH8nhQvL4D2vOMlqgmwZPUjxHGhFEzf3pV BZ34zjnxYBDIaQFs77Rh8N5NhKe0S/KvSvNZG9pZ30tfKyBQmnX+vsyMckPTt7kwUyNL 4s1g== X-Gm-Message-State: APjAAAUFcyIqCa+gt+Zz8K4LDGnVWTw+sHoUtXd40Pu0i4nbKkBUT1fy apx/XVC2L2sVeYJAlhdqy0Ulew== X-Google-Smtp-Source: APXvYqy7REmbeSoGabrHJosEy+e9RIQwVJI6151RJ0mudVDjtZ0j1zOMaWSoaqNNZbRhk5uoQyCWIQ== X-Received: by 2002:a63:da49:: with SMTP id l9mr3394339pgj.125.1582715758282; Wed, 26 Feb 2020 03:15:58 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:15:57 -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: [PATCHv3 04/11] videobuf2: add queue memory consistency parameter Date: Wed, 26 Feb 2020 20:15:22 +0900 Message-Id: <20200226111529.180197-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 f91cba37e223..cc31629c06dc 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 d307869bfb15..d7fbf2ae9979 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 Wed Feb 26 11:15:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406127 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 249E81395 for ; Wed, 26 Feb 2020 11:17:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F01092468B for ; Wed, 26 Feb 2020 11:17:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OzEWrhhD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728217AbgBZLQG (ORCPT ); Wed, 26 Feb 2020 06:16:06 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45349 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728194AbgBZLQE (ORCPT ); Wed, 26 Feb 2020 06:16:04 -0500 Received: by mail-pl1-f196.google.com with SMTP id b22so1153277pls.12 for ; Wed, 26 Feb 2020 03:16: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=uF68l6pWBOiipuGt+QB0XHw1hdaZSLBPWRelk7RmcTw=; b=OzEWrhhDS5aI7yjjFwvlHMPtj5DGuS/uYJeZ/I0yf3gNx0rf1AAi0SWFklcpWadhLv IBkBMh+Z6aziyfq1fEKORepH20RIZmQbTaTxCwDYnZelm9hhHsEAgbcTv2jJwQWYI0aR CUQWVmEFQua3CmGb2npROJxJ18JX2UKuMh0K8= 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=uF68l6pWBOiipuGt+QB0XHw1hdaZSLBPWRelk7RmcTw=; b=SFlN2+VuRBQWO62V+xrAgf+cBefAlmfBLoTyfxT1MXO8SCqcpAE26b27Mow6embYLq j50FUWkj5fMg/E4lUsOZu9c1ENsJKmU3LApUYVkLE+cNvynJ/zMl3+lR4fY1tDji2/he KTIqXSlACfoL/4tmDvHu59tywOkRn8rtHOL2cC0P4n4WczzguBNkwbHgTrWV9UGopLy8 hZZrriC7pF9B3b29v1CO4NdqT70HYNJnwMIraAXkDB7mCGu5I0amRdOP/x2N/Ie2obKf U1GlfK1+zE8LCs5mIJ7FzRpHytTfQ92FubqPdteU5Uf6JdkOXZI2rwsyeLGLigC20NYm ohXA== X-Gm-Message-State: APjAAAXLoDoqPywB617PFw/1fu/igknz9jJasSasxcHfERa2ZO/jHPdN 4dJdl4sgCGC8Og6hkfUrbrr6JA== X-Google-Smtp-Source: APXvYqyvPwRmsGKi67pAMkoV8kPJFQFO34GA9Xa40kc1XQqFkdJHotzt73tuqmDLqnT/QKdl5To5nw== X-Received: by 2002:a17:902:a710:: with SMTP id w16mr3609455plq.43.1582715762287; Wed, 26 Feb 2020 03:16:02 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.15.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16: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: [PATCHv3 05/11] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Wed, 26 Feb 2020 20:15:23 +0900 Message-Id: <20200226111529.180197-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 | 8 ++++- .../media/uapi/v4l/vidioc-reqbufs.rst | 15 +++++++-- .../media/common/videobuf2/videobuf2-v4l2.c | 31 +++++++++++++++++-- drivers/media/v4l2-core/v4l2-ioctl.c | 5 +-- include/uapi/linux/videodev2.h | 8 +++-- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Documentation/media/uapi/v4l/vidioc-create-bufs.rst b/Documentation/media/uapi/v4l/vidioc-create-bufs.rst index bd08e4f77ae4..6a8a4d5de2f1 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. + See :ref:`memory-flags`. Old drivers and applications must set it to + zero. + + * - __u32 + - ``reserved``\ [6] - A place holder for future extensions. Drivers and applications must set the array to zero. diff --git a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst index 917df6fb6486..e52cc4401fba 100644 --- a/Documentation/media/uapi/v4l/vidioc-reqbufs.rst +++ b/Documentation/media/uapi/v4l/vidioc-reqbufs.rst @@ -112,10 +112,19 @@ aborting or finishing any DMA in progress, an implicit ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will free any previously allocated buffers, so this is typically something that will be done at the start of the application. - * - __u32 + * - union + - (anonymous) + * - + - __u32 + - ``flags``\ [1] + - Specifies additional buffer management attributes. + See :ref:`memory-flags`. Old drivers and applications must set it to + zero. + + * - + - __u32 - ``reserved``\ [1] - - A place holder for future extensions. Drivers and applications - must set the array to zero. + - Kept for backwards compatibility. Use ``flags`` instead. .. tabularcolumns:: |p{6.1cm}|p{2.2cm}|p{8.7cm}| diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index cc31629c06dc..4954c9fc678d 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 Wed Feb 26 11:15:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406101 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 7C3DF92A for ; Wed, 26 Feb 2020 11:16:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 530D524699 for ; Wed, 26 Feb 2020 11:16:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TpHVYoel" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728236AbgBZLQI (ORCPT ); Wed, 26 Feb 2020 06:16:08 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37630 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728205AbgBZLQH (ORCPT ); Wed, 26 Feb 2020 06:16:07 -0500 Received: by mail-pg1-f193.google.com with SMTP id z12so1154890pgl.4 for ; Wed, 26 Feb 2020 03:16:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eaNPcBjkoKZw1bZcJWbUbEpJEQzWw7qCsLqY7OuM15k=; b=TpHVYoelr2i7JTAn1zYgosT0gH2KCmVfBT2mcDRYFYxvwsUI34gyZWfPfrn9IuVVjG wqI599qBr/LlzAbOKH7aTgWWkqmpgCCiD07a/Q8O41vl61QBBKU0HFaGKiQPlLtbjCWX 5CyL6JfDgjKo/0vlbyNIXGTSj7hV8NmDaV2hQ= 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=AYSvmP26OSjtF/roUO7MVQ6XBvnODSQj0pZuGoAu4qaK+D25KHo+aJStwms3IIsrfS lamOfuuFR7eP1oFgb3/FQjQ4Qx0j72cnDs+tbflGH3LAWfVMh/bsn0EFGBg2O0dpg/1J 9pTXwcYiskbceKFOwiW6Oo3L/fMPxYMtIvdS0E/QMdJET9Ne8vrKjzI5TvDZ711S/G8I aexTYBXNlE6EamSZtuNhNwxpb05O7WgBnFFt+hJF1xFXNcRs+h8dTltDyKR8C/DtUIqw s8/rXrFoJ8wlAGf6zJ/0kynLhiRZau7ZCFHUnzfBi/cMr74H0A8WvQKGdmt7Ay2W1k4b PMCw== X-Gm-Message-State: APjAAAXxvCCiulTB/vPs8looOwe83RNQhgRrdqm+nSgpofdF4YoEdkJh DXtohKd0Uwuz2m4bBWYyPLNlSeQD9Xk= X-Google-Smtp-Source: APXvYqwLk21jax9uCKTboCDZ+LjJJHjnos3aVaS6S8vk1tenX3zUCVD/KCSsuaijssiAixcnDfa63Q== X-Received: by 2002:aa7:96ea:: with SMTP id i10mr3722985pfq.58.1582715766793; Wed, 26 Feb 2020 03:16:06 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16:05 -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: [PATCHv3 06/11] videobuf2: factor out planes prepare/finish functions Date: Wed, 26 Feb 2020 20:15:24 +0900 Message-Id: <20200226111529.180197-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 Wed Feb 26 11:15:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406125 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 ABB8E1395 for ; Wed, 26 Feb 2020 11:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8AA642468D for ; Wed, 26 Feb 2020 11:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="n6EsLSjV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728279AbgBZLQ5 (ORCPT ); Wed, 26 Feb 2020 06:16:57 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41263 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728259AbgBZLQM (ORCPT ); Wed, 26 Feb 2020 06:16:12 -0500 Received: by mail-pg1-f195.google.com with SMTP id b1so949343pgm.8 for ; Wed, 26 Feb 2020 03:16: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=3A85FNkQVK15E41Jw/YnZSYCbOfj7OMPE9KsvpyVprI=; b=n6EsLSjVofOAsY+qTD5ur3tvt3prP4xIE81hW3UMhCK6Hk6vLYUPfTjkViyHlLSx0e PKq9SBkZBIKgkKw3b6iA0jU98G93dGz/e0kV3RB+SOZ9jHG0bHjc/CED2Z1L7O8Inq/Z a6GKZuegrK/74Y/D7g2+3chSko2GVSugqRbc8= 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=SHXscZiofOsWXlWEPRWlPSBYdl/5LMpyLi4Avi7kWWHb9F//TysPYC1LpJjtELAacE 3BToaSE46U3+SycBSbF7XnzEKQf0BufGioXIGuxSGOGeiHtqb4eFh9a/9lXOfE1X/EDp P3xP0Pe1d8NfuvDafG3hphT0qMiI+jDBWCq+C9HFOe59cUsWQm6O0hNr+f4JyealJybx HKdcKiqcxZhEbeXk7T4LHnYO505HcSavZbH4NnA9d+u4AyLY4FH8uvm+5ee4m3giT5z8 x04FfRKrBrzCCGSSdRK1WuCprIL9P08EtudUHX4c/gvpuv4wC3XL7IwWB4qfPMlOY94y wcgg== X-Gm-Message-State: APjAAAX953NfbwzMq0uRwsSJI9JoAFMdfDEuhNNm9QOqUInM88sYSm82 IzXyGJ8xKkUmwVxCMmfXU96wSg== X-Google-Smtp-Source: APXvYqx53QRjLLJVxV+EPa6syDS3795FvGUqOREY3XhchQlBTgMZD1MOJX/1R5o9fROynap/WI3GVA== X-Received: by 2002:aa7:85d8:: with SMTP id z24mr4029724pfn.202.1582715771062; Wed, 26 Feb 2020 03:16:11 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16:10 -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: [PATCHv3 07/11] videobuf2: do not sync caches when we are allowed not to Date: Wed, 26 Feb 2020 20:15:25 +0900 Message-Id: <20200226111529.180197-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 Wed Feb 26 11:15:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406105 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 5F9341395 for ; Wed, 26 Feb 2020 11:16:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FB3E24688 for ; Wed, 26 Feb 2020 11:16:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SUEP5H4I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728321AbgBZLQU (ORCPT ); Wed, 26 Feb 2020 06:16:20 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:37528 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728298AbgBZLQS (ORCPT ); Wed, 26 Feb 2020 06:16:18 -0500 Received: by mail-pj1-f66.google.com with SMTP id m13so1145740pjb.2 for ; Wed, 26 Feb 2020 03:16:15 -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=SUEP5H4If0hedHG+d1NujE25rC/qeuZmRHTrnVGnP0EIN3aaxg3mNjZGx2NZLg0L6w BOjyNWvn6w5PLu3+1thwu2S39c0ZMJOEpiV0jIh63SUKGnK9wzObCjQpy3nyaVXE/y7/ lSqKT+KAtiRGykb+8CKaOgFHqGlbBk78g480U= 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=L38lwbV1SesKi2Rc5PkPbi4rO4+yApuhtQkGxSx09yTDdR1ShlnSRJg2RG+kowJtGi JYlphfS8JQOpHkj+U4oj58N1v1ihX0x8lXulglOUU8mRKa8HLTBfQcKEo3Jw3/75IDU5 6lpeMk6XZVBHIf1OotU+RlNfZw0KJRdPZ5dJy5XSLCPpF1GOamkrSaL8n6BODyx6q8K4 7oxgPMFdYUNtB/6iTwgAlH8ZcgA4X6L2arqfroHD9qYotO5/DN5Wz1B5faBtvJTzFH7Z 4SFqZ2e6klyWRcOkk757fu0qyb+skA7n+q76m0WCRRCSMw2OBpavNattuhvPy6jlKjEd RLTQ== X-Gm-Message-State: APjAAAWydUpVYabUIdl13NN4fQcRgQbFcPMFSYln6utVngGSsLUubiad qw+1Jwc5zh5HsenGjDjMxmpBblNRH/M= X-Google-Smtp-Source: APXvYqzyt+rpfyMZ4RL10CxYR7SLP1N/LsYvlz4aIcvuEf9JypIqMqdBTCcFIPRxhcL3Oo1KRvY9oQ== X-Received: by 2002:a17:90b:94c:: with SMTP id dw12mr4482184pjb.13.1582715775331; Wed, 26 Feb 2020 03:16:15 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16:14 -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: [PATCHv3 08/11] videobuf2: check ->synced flag in prepare() and finish() Date: Wed, 26 Feb 2020 20:15:26 +0900 Message-Id: <20200226111529.180197-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 Wed Feb 26 11:15:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406111 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 405F71395 for ; Wed, 26 Feb 2020 11:16:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1E4DF2468B for ; Wed, 26 Feb 2020 11:16:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="lw0yY2Qo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728339AbgBZLQW (ORCPT ); Wed, 26 Feb 2020 06:16:22 -0500 Received: from mail-pj1-f65.google.com ([209.85.216.65]:54293 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728326AbgBZLQV (ORCPT ); Wed, 26 Feb 2020 06:16:21 -0500 Received: by mail-pj1-f65.google.com with SMTP id dw13so1124139pjb.4 for ; Wed, 26 Feb 2020 03:16:20 -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=lw0yY2Qor//ZEUu1GpyfA2emUMnuSoecVy9q8cJzKNy2GUuZwK16AIKpL4A5Czlo90 KeHG1xGlmhagCJhp6nThjt3QE0uu83oA5EekEoMuVn+WeSzaM64/yGzyiw5/oVt0UVhC 2f4qYBy8qEx4Cw7EN8DVkuIpdeoeJl5mmmcm4= 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=IUhELBnClSawZWftoK93LbkinBQg/eHoaIKJNIr16ABTaVXBc/CuZMU/PIpPsMynf8 kLDOAXIG5DJqWnCeCKk7k8hwYUL4rOMvDGjN6AcuiBguZNZHzv4lAnUKdAu8ln4tOt7T 79BsXOMWaDKLW7ZBwR62hovhS0tI4sEqT3VhQPcD14PFkp/IUt4U+fy52c4MF44DTaK0 cx9iNMp/gFx+8wNZQRfsnlyiddiO6mPLszALVTm/5ZmeFZbh3Q7/FI+pVVWscOWfdEYp Z30KpJxFplDcZMFlOyoTihyUp3p+lGKdHsnzy86FKXCjSKc7l2asbP7x3wHapFJw9v3y lxlg== X-Gm-Message-State: APjAAAVFw8cn0KrecOtcrP3e1XbNKQjZtQ/sVfGbk+qjA5Cz2W7x+piJ RLCbKo8pRKmsCwuSP+bL0tNN8Q== X-Google-Smtp-Source: APXvYqxtS5WDiX+fS/IvZhS9qTmEMxpoSGMWZO9YA9VURvHi53gevzaMm9d7V9HHbkgzuOKa50WCUw== X-Received: by 2002:a17:90a:178f:: with SMTP id q15mr4767582pja.132.1582715779415; Wed, 26 Feb 2020 03:16: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 o22sm2429993pgj.58.2020.02.26.03.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16: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: [PATCHv3 09/11] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Wed, 26 Feb 2020 20:15:27 +0900 Message-Id: <20200226111529.180197-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 Wed Feb 26 11:15:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406109 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 E2DE992A for ; Wed, 26 Feb 2020 11:16:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C279A24685 for ; Wed, 26 Feb 2020 11:16:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="geNq2EXf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728355AbgBZLQZ (ORCPT ); Wed, 26 Feb 2020 06:16:25 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:36026 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728347AbgBZLQY (ORCPT ); Wed, 26 Feb 2020 06:16:24 -0500 Received: by mail-pj1-f67.google.com with SMTP id gv17so1148263pjb.1 for ; Wed, 26 Feb 2020 03:16:24 -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=geNq2EXfBike1hJuxtOmzbDGmZhTw10QbWW/5PJpq0K8lAJXxQQv7XP8IRT/oQjC85 /6vgd1mLwaHPSGSDlCELRu9d2b2DugBCNJBjPfPqiKHgznRKffVevlMSs51mkxMCYFMV YxWpgSJBAwLB4hpisWuehWaxAUSmOr4NJE5EE= 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=W81JfQbslcjj4rTOfJUAeLpHA6KUT41PXKANAmk+5kRwge6N9KdEUiPBq3JeYLbla8 TtBhRDpLhkTRTz/vy4hEbqaqYvK97ejMNqJyLdDOL/F0dBXQv9ZVbaNX/zWqQUyEva/6 0pvO16QK3f+KBdNq6p4DDPQoAXBiqctQ0/ycyJjIyBvWM32a2WcA00pN9hAFbvasTg7j 7mI28zrFEKS/w5FXIRGCp9NEFlSwVg9uxaBWuKWG20xyOavoOndJSqR6sUCjbZKdIrD0 PWYmHUKJ6GbrI/1NprWTnx3l/tUzPwJqfIxlbyc1h451199ZxuI1VLsRv3ehOpvX9ITo wjMw== X-Gm-Message-State: APjAAAXoll0wmeEGdrGX/CXgMakR/OynYAdQvO/CspUc8H7EbRhSgGrN Hd5TqwHAhr2Qkzoie7LKtPBKIg== X-Google-Smtp-Source: APXvYqyv+iska2Eim0BK6W5wb56qt7LUqloQ/7gNoQ/GwfqHGj0R2iuxoBePy/vYFjWu0MYyKrh3kg== X-Received: by 2002:a17:902:8215:: with SMTP id x21mr3817650pln.59.1582715783534; Wed, 26 Feb 2020 03:16:23 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16:22 -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: [PATCHv3 10/11] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Wed, 26 Feb 2020 20:15:28 +0900 Message-Id: <20200226111529.180197-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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 Wed Feb 26 11:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11406107 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 A92D992A for ; Wed, 26 Feb 2020 11:16:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8801D2469D for ; Wed, 26 Feb 2020 11:16:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="drOYBsxY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728373AbgBZLQa (ORCPT ); Wed, 26 Feb 2020 06:16:30 -0500 Received: from mail-pf1-f180.google.com ([209.85.210.180]:42295 "EHLO mail-pf1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728370AbgBZLQ3 (ORCPT ); Wed, 26 Feb 2020 06:16:29 -0500 Received: by mail-pf1-f180.google.com with SMTP id 4so1292809pfz.9 for ; Wed, 26 Feb 2020 03:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CxsIIu+/8DSr9yF0CIvvdp+l+R1SqYNd7xvzR+EPPKE=; b=drOYBsxYOXn2Xeb56l6caTledM7axnNRIci8lv/j5g0baIJWB2DvjJbjzDaydlaz2L 8PMa4wUDNdoQrnRBx6edGr6JU/YzLzA7uRqCV24MS4D09M+Fp7JXOB1OalwDH0Scu9Zh 3Le4Sjj4Akni+tjxM0v6nRkRPGUUYyP90oACM= 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=YaBwoiLkckwhrILHGj9U6lE+9Xh9RslIys6Hkb5OkpyDdqoHnighq5ig6y7mGeMI3E 2Ck/P+XFcnL/1Y8F5iwNSZ8KEbOE2/RTvRauN/RxkvB1Qjl/6X9CZG4hj5CX6OjNsHSb p9o6WA7+h8emzNKga+fmUbKizjePTIPRtJmQTi+sGv1j0i2++xlKs+uoUn8MneCT1BG4 liIddUHrOccLQCeelXs9wr0WpyGPARXnGZnBPoPkFFFonSfQ19g83wo8VHFm9uDv4U66 34jqGwtcAkNagZlqZ2tZp+PzxhQxMq0nKn94Usm4qk9YUXejoKFIM3pJIszYwvGpqFx/ vEdQ== X-Gm-Message-State: APjAAAV1FTpX6K8PraMYeb0Gzp4nzNFtz0BfoYva9b2OrvQjqPFvG8vS rgNBAhh1mMWDvwWIT7MzA+yR0A== X-Google-Smtp-Source: APXvYqw7geSaJHKQXNxHd+nJsVEm3hH3f9VMmmCHh3bRl9MgtjuMWJBqY01Dt28pW7thPsYChjxijA== X-Received: by 2002:a62:25c6:: with SMTP id l189mr3901463pfl.136.1582715788057; Wed, 26 Feb 2020 03:16:28 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id o22sm2429993pgj.58.2020.02.26.03.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 03:16:27 -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: [PATCHv3 11/11] videobuf2: don't test db_attach in dma-contig prepare and finish Date: Wed, 26 Feb 2020 20:15:29 +0900 Message-Id: <20200226111529.180197-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200226111529.180197-1-senozhatsky@chromium.org> References: <20200226111529.180197-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); }