From patchwork Fri Apr 24 09:29:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507361 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 AC34615AB for ; Fri, 24 Apr 2020 09:30:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9439820767 for ; Fri, 24 Apr 2020 09:30:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pDxPOHvW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726851AbgDXJak (ORCPT ); Fri, 24 Apr 2020 05:30:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJak (ORCPT ); Fri, 24 Apr 2020 05:30:40 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D01C09B045; Fri, 24 Apr 2020 02:30:40 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 7so4570218pjo.0; Fri, 24 Apr 2020 02:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PnRbc31NNtJk9tFYJKwcEqOlUSl+vuVKarKs0i2/PM0=; b=pDxPOHvWZ3cgHZ1XYJ03IyzGoG+JXH+2/HBBGIR3219YABQPHhHmxsvmSTJ7MzoJY1 3cQo1WYCEU5HIO0UmNhodH49KKuNRH5FhQsOh7IgAPxEsQf0Ild4l8lFKiL5bHwZWQP8 nyYpQxOTH2Ylv9jiM5THkinvn8HHuuSZTGGvWDNUC0Hb9HpYWmls1vfcGSPdtWAM9hlF njb5WxU5yLlJ1wjaQGlSO5UJqumzNeXUIfx4sFXjSmu3dh2h4SPcqQ34rq+puQb6D6Do fVtxUWM9xpnv8oDmW8dbQ2KUwXSCC51VV6CJcWWbDBo4q+hb5Kry941/g03yOFAiZa5O I08w== 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=PnRbc31NNtJk9tFYJKwcEqOlUSl+vuVKarKs0i2/PM0=; b=WBYA3dc2Esr9MZAdINTaruT15sn4F+j5SgbRu2/VSpnbWeQnvaG+7yh2ehFNM/lDGj bTEZq4J7jnL0BRUIDqqYzmOuhyb5gE6O/O2uY5yf7yt1+Hr7UyE4RWryzOXe/iqpcDaQ 0Nx82ID5Jtnoi3YqdnaohxsVaf2YklSNVzsRXUsPspEqTjP/pfkAUy5WSmzBKxPmsWVN 9PFBjzpDU99/47/MCUbvfZa3/pvLk+dr9jFeYFCMUXzH/zlxeTT9k6ZhKUXnYwPKX5xg +PbZwzzNZbbqdkNQBh0L0qegiaPRfaRwnaWwQeLPyCh9ZlwkhZfpHREJ9zFrnPrEz9/I lwbA== X-Gm-Message-State: AGi0PuZ3jcWa7/I3m0xWx9Kvzq6MIM+sEpO5/9MnFSQV6kJEsHDnGil6 yQmvIbkowZX/iZAKALXpe2c= X-Google-Smtp-Source: APiQypKYfsb89CG8UIY5O5Gldu5tg5+E917n3JgQZ7mDFSuJPk7yoJ0s81OtjnkcvJq/rYS6/NQYCA== X-Received: by 2002:a17:902:968a:: with SMTP id n10mr7784459plp.96.1587720639576; Fri, 24 Apr 2020 02:30:39 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:30:39 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 01/13] videobuf2: use explicit unsigned int in vb2_queue Date: Fri, 24 Apr 2020 18:29:08 +0900 Message-Id: <20200424092920.4801-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky Switch from 'unsigned' to 'unsigned int' so that checkpatch doesn't complain. Signed-off-by: Sergey Senozhatsky --- include/media/videobuf2-core.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index f11b96514cf7..9e522bd2acc7 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -558,15 +558,15 @@ struct vb2_queue { unsigned int io_modes; struct device *dev; unsigned long dma_attrs; - unsigned bidirectional:1; - unsigned fileio_read_once:1; - unsigned fileio_write_immediately:1; - unsigned allow_zero_bytesused:1; - unsigned quirk_poll_must_check_waiting_for_buffers:1; - unsigned supports_requests:1; - unsigned requires_requests:1; - unsigned uses_qbuf:1; - unsigned uses_requests:1; + unsigned int bidirectional:1; + unsigned int fileio_read_once:1; + unsigned int fileio_write_immediately:1; + unsigned int allow_zero_bytesused:1; + unsigned int quirk_poll_must_check_waiting_for_buffers:1; + unsigned int supports_requests:1; + unsigned int requires_requests:1; + unsigned int uses_qbuf:1; + unsigned int uses_requests:1; struct mutex *lock; void *owner; From patchwork Fri Apr 24 09:29:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507363 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 EBD22112C for ; Fri, 24 Apr 2020 09:30:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D390C20736 for ; Fri, 24 Apr 2020 09:30:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="coQf79/t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726882AbgDXJaq (ORCPT ); Fri, 24 Apr 2020 05:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJap (ORCPT ); Fri, 24 Apr 2020 05:30:45 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFF4C09B045; Fri, 24 Apr 2020 02:30:45 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id 18so3317075pfv.8; Fri, 24 Apr 2020 02:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TrR6hu+KWMBem9LHeFisBnjrXsleHdt+kHq4K2nQnVk=; b=coQf79/tohbUyvHCkg30RJItibeQ8r6DiSTQdI28pRykvZRlJMWBf2Mq2XT8cr1Wfu DsF1AKRLnw17gIa/cpTj7rJAdgdH9jpzfGsPh2zXzNdsjDTfFGi10TMuzSERyjfr+ZsB AtxaWIXXXvZjoWmAJhgE0B3TOjRl2ZG3QqWEG23uab5j18CC9q2+S2n0FSonFHHARLDf xekRpukadUoTXeste5AsJI6qSQA/furPJXOi3jQE+lVw0X+eospkNS/C2Ib+6RlrFYZ1 U6zv30Z9xptmVyQqDz1rUeBVe2McgCnNpyA/dsbVPYQNWeoDFDG59OLRR1dye6RjxY5R hkuw== 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=TrR6hu+KWMBem9LHeFisBnjrXsleHdt+kHq4K2nQnVk=; b=Px5I8Qv3wEDkrvvhTr8EqHVx52GCyiIJjde4YU1gGkw7ZPLQ7/qIrDKJRjLRSiZeiu t+vb4uYETqGFg6lxbJXcv2WEpSkuKVXdIQb7OBmKMFznd7fiJPpCPXQJ7fQUZDzAnE01 c8vrClf/0dJmAMgsI+A2lsV8sQu+gcUWaWRaSZ1HKILdvKyyXUw1WsReh0IIdmHeaMrc jMGYJLIaMHDH2Qwdr17ftVCesAdeEjmpe/Pj4X+DqrzHbLodZyeEGh7rwswN7/s3p8Sj 5UZa7nzNaXGOWoLXmYmTqrT7xeySJOzf2/wbkZoxchJXeQd70V/O2zcyKgltCXA4QYPT FxsA== X-Gm-Message-State: AGi0PuY6DySr+UNQGifa1mn2OO1FQ7612qYBt0Xud87M9RVUzsLC2Q29 3Qkt3EPEhOgNa9/tH3ozHu8= X-Google-Smtp-Source: APiQypIjrsReeaTEieis94Y1UNkB6IbucDaHec7qMAvO0YLzzuyz4GRM81zPKZb67ReiT1RB/lJBIw== X-Received: by 2002:aa7:9251:: with SMTP id 17mr8096696pfp.315.1587720644697; Fri, 24 Apr 2020 02:30:44 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:30:44 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 02/13] videobuf2: add cache management members Date: Fri, 24 Apr 2020 18:29:09 +0900 Message-Id: <20200424092920.4801-3-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky Extend vb2_buffer and vb2_queue structs with cache management members. V4L2 UAPI already contains two buffer flags which user-space, supposedly, can use to control buffer cache sync: - V4L2_BUF_FLAG_NO_CACHE_INVALIDATE - V4L2_BUF_FLAG_NO_CACHE_CLEAN None of these, however, do anything at the moment. This patch set is intended to change it. Since user-space cache management hints are supposed to be implemented on a per-buffer basis we need to extend vb2_buffer struct with two new members ->need_cache_sync_on_prepare and ->need_cache_sync_on_finish, which will store corresponding user-space hints. In order to preserve the existing behaviour, user-space cache managements flags will be handled only by those drivers that permit user-space cache hints. That's the purpose of vb2_queue ->allow_cache_hints member. Driver must set ->allow_cache_hints during queue initialisation to enable cache management hints mechanism. Only drivers that set ->allow_cache_hints during queue initialisation will handle user-space cache management hints. Otherwise hints will be ignored. Signed-off-by: Sergey Senozhatsky --- include/media/videobuf2-core.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 9e522bd2acc7..7f39d9fffc8c 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 @@ -567,6 +576,7 @@ struct vb2_queue { unsigned int requires_requests:1; unsigned int uses_qbuf:1; unsigned int uses_requests:1; + unsigned int allow_cache_hints:1; struct mutex *lock; void *owner; From patchwork Fri Apr 24 09:29:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507365 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 31B52112C for ; Fri, 24 Apr 2020 09:30:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16A7220767 for ; Fri, 24 Apr 2020 09:30:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EwqLXlZw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726896AbgDXJaw (ORCPT ); Fri, 24 Apr 2020 05:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJaw (ORCPT ); Fri, 24 Apr 2020 05:30:52 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18119C09B045; Fri, 24 Apr 2020 02:30:52 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id o15so4389061pgi.1; Fri, 24 Apr 2020 02:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=41prVte/MxVN8rT+cmjF7KZHxVdpTKw2jaomXqXMCyU=; b=EwqLXlZwJ+cCoRK6cJZ9gMIiWoiv5nANq3T7n4A0Dp4PBDjB9xl8NutCDZiCWuMPnx AU2uod83uEjFBObvGTws8ymzhvSanj4dR1by6f4omlVTUsWhUADseUUlnObLQ8sFma8p +Hdf9gQ0ZRBkMLIyz1FZijOm8kvqAIJioBd6hhKGuo+YmYBbn5y2+KOsn4saHUewBTy1 ODxDfu6stREZqDlvVIXFxITanQV1vD6m+jUePrcuA5vlnVVa6+zod30ZHpwC8XjXDuGK xieyCvxTgqs61nXbd7Xs0AHLkUezBBq5UB8yyBlGwQ54Lz6WdoYNnE19P9sxD3NTOaP4 Mywg== 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=41prVte/MxVN8rT+cmjF7KZHxVdpTKw2jaomXqXMCyU=; b=t6RM+VYlHJUIapJ9GwZY2WTHA16ILPNIaf+dHkDqgoE9f2esWNvesP1tZ0piuvrTIj paIB8YSY1yXDCcZOpGi1RBY/oPD+ydpmeG/zhSUTGESnbqoMKBgmORNneIVVlts8koL0 /7b3T4/MNbqwRM/7+5qlh/E1a7h4JHFqVf0z3Qy8vFj3wbpeHz82Qti7EQcwMcKcnS2M Ch7+OS7p2LZi2HNmr0U/9Hjb2CGLAtw8wmWTNra6Whue8KVGljR1sAql9oDzAy5+yMzD udnFzjTwRsxEQ9Ww2r5PqVqMw3mTrp6p69F9Fd9pl2nJgpO685L8Q3eZsSoefiBepbu/ Ra6A== X-Gm-Message-State: AGi0PuYN30xirivk6yWOprmFeeRmpWHcTaSUSPU2ylR3lWRZzqoZzPlG iLChRFsFXylNNH8v12JDpC0= X-Google-Smtp-Source: APiQypKjkmfsFU9zHxc2sJsKL/YOujcpzgmhfTVNZK+x4JRN0bv9h3ueUQ6EoXadQiBn8XLnF/eMfQ== X-Received: by 2002:a62:1801:: with SMTP id 1mr8741392pfy.230.1587720651578; Fri, 24 Apr 2020 02:30:51 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:30:51 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 03/13] videobuf2: handle V4L2 buffer cache flags Date: Fri, 24 Apr 2020 18:29:10 +0900 Message-Id: <20200424092920.4801-4-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky Set video buffer cache management flags corresponding to V4L2 cache flags. Both ->prepare() and ->finish() cache management hints should be passed during this stage (buffer preparation), because there is no other way for user-space to tell V4L2 to avoid ->finish() cache flush. Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-v4l2.c | 48 +++++++++++++++++++ include/media/videobuf2-core.h | 11 +++++ 2 files changed, 59 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index eb5d5db96552..f13851212cc8 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -337,6 +337,53 @@ 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)) { + /* + * Clear buffer cache flags if queue does not support user + * space hints. That's to indicate to userspace that these + * flags won't work. + */ + b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_INVALIDATE; + b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_CLEAN; + 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 +428,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 7f39d9fffc8c..ccc5c498d3e3 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -635,6 +635,17 @@ struct vb2_queue { #endif }; +/** + * vb2_queue_allows_cache_hints() - Return true if the queue allows cache + * and memory consistency hints. + * + * @q: pointer to &struct vb2_queue with videobuf2 queue + */ +static inline bool vb2_queue_allows_cache_hints(struct vb2_queue *q) +{ + return q->allow_cache_hints && q->memory == VB2_MEMORY_MMAP; +} + /** * vb2_plane_vaddr() - Return a kernel virtual address of a given plane. * @vb: pointer to &struct vb2_buffer to which the plane in From patchwork Fri Apr 24 09:29:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507367 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 87DA981 for ; Fri, 24 Apr 2020 09:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B47420767 for ; Fri, 24 Apr 2020 09:31:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nwhmm0A7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726914AbgDXJa4 (ORCPT ); Fri, 24 Apr 2020 05:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJa4 (ORCPT ); Fri, 24 Apr 2020 05:30:56 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E7C5C09B045; Fri, 24 Apr 2020 02:30:56 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id h11so3527465plr.11; Fri, 24 Apr 2020 02:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G0xctamNJu1msFWVd4QpdKYPAbJYyEVk/cdrZOhkeOk=; b=Nwhmm0A7B7gwomsfkbhj63eHPp79fr/MSsyAn9ss1PIVfOIgum1MaPG+xmmyW2OYjZ L4HKsb7RiUoG4Hy35+iYX8jc0182OCUIt3Ir38eVJ5ix8NSgcwFsb6pr3qD0o3pipsOQ TXVRgxYxk0LU6FittisZ24au4KJpOEhporFJ8XBc3S+Dm08uL8ctAEMKDnnZKaUF/Hgu PheUDX7Q+/M2r3V2ruPLsPW56I8WbkawfFvwTJsYkzx7E+hEssVZU2K48/99dk50QGio QTELmI6Lr+8+ivS1Z9zubVfbpnGnTsu82DSmNaQbSW7VmpShRK/sb6E6DxA4DZ4pnbay m8Fg== 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=G0xctamNJu1msFWVd4QpdKYPAbJYyEVk/cdrZOhkeOk=; b=IyffHgsCWN3n2wC0DbhIGTNCNZUto4c+Ut2jW5kPjefJ8FP1o/6ynjqcDdMxG8pQ4x Hh4bfMc7GAmDUr9QbQVdJZjLbCkczwblHfwXeOfd+x2e20MM7vTW8xDbXS1HZ0FwvaSs 1HgoRxrzQvpTetsmRz+ukOTCavvPUgVqysuRf1Qgct+pWyJIFI01AMq0GH3OvZJcLJ9w dljllVzt2hEohW0MlV7y/WTXWhNn6pbhf7tJnbnyLnL4VvHGJo/uG9VUXvnp3a6MzGeQ k5gOZee6Zjyz8IS5XKGK7/K+wZ88ZuhZR9Hwaa9onBY7sUr+sUwvFPsoInwsL44xGYZy O3DQ== X-Gm-Message-State: AGi0PuZxBrZCe6vtGuSWKay/H+z1iTQXdI1t3xAGIJFiIQD0sKql9hNh Er7u717omi2BO4McvKu2vlA= X-Google-Smtp-Source: APiQypJIfv0iYz1m19Gj3STtOVVkn50bVrZVXIn7taeUg0X9qe3iez8oNlrLzwIRbewi4DLDlKOcdA== X-Received: by 2002:a17:90a:ce05:: with SMTP id f5mr5320802pju.39.1587720655730; Fri, 24 Apr 2020 02:30:55 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:30:55 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 04/13] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Fri, 24 Apr 2020 18:29:11 +0900 Message-Id: <20200424092920.4801-5-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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. Note that queue should be set up and initialized, since it's the driver that sets ->allow_cache_hints. Signed-off-by: Sergey Senozhatsky --- .../userspace-api/media/v4l/buffer.rst | 41 ++++++++++++++++++- .../media/v4l/vidioc-reqbufs.rst | 9 ++++ .../media/common/videobuf2/videobuf2-v4l2.c | 2 + include/uapi/linux/videodev2.h | 3 ++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/buffer.rst b/Documentation/userspace-api/media/v4l/buffer.rst index 951ae1ed485f..66023658270c 100644 --- a/Documentation/userspace-api/media/v4l/buffer.rst +++ b/Documentation/userspace-api/media/v4l/buffer.rst @@ -577,7 +577,10 @@ Buffer Flags applications shall use this flag if the data captured in the buffer is not going to be touched by the CPU, instead the buffer will, probably, be passed on to a DMA-capable hardware unit for - further processing or output. + further processing or output. This flag is ignored unless the + queue reports + :ref:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS ` + capability. * .. _`V4L2-BUF-FLAG-NO-CACHE-CLEAN`: - ``V4L2_BUF_FLAG_NO_CACHE_CLEAN`` @@ -585,7 +588,10 @@ Buffer Flags - Caches do not have to be cleaned for this buffer. Typically applications shall use this flag for output buffers if the data in this buffer has not been created by the CPU but by some - DMA-capable unit, in which case caches have not been used. + DMA-capable unit, in which case caches have not been used. This flag + is ignored unless the queue reports + :ref:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS ` + capability. * .. _`V4L2-BUF-FLAG-M2M-HOLD-CAPTURE-BUF`: - ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` @@ -681,6 +687,37 @@ Buffer Flags \normalsize +.. _memory-flags: + +Memory Consistency Flags +======================== + +.. tabularcolumns:: |p{7.0cm}|p{2.2cm}|p{8.3cm}| + +.. cssclass:: longtable + +.. flat-table:: + :header-rows: 0 + :stub-columns: 0 + :widths: 3 1 4 + + * .. _`V4L2-FLAG-MEMORY-NON-CONSISTENT`: + + - ``V4L2_FLAG_MEMORY_NON_CONSISTENT`` + - 0x00000001 + - A buffer is allocated either in consistent (it will be automatically + coherent between the CPU and the bus) or non-consistent memory. The + latter can provide performance gains, for instance the CPU cache + sync/flush operations can be avoided if the buffer is accessed by the + corresponding device only and the CPU does not read/write to/from that + buffer. However, this requires extra care from the driver -- it must + guarantee memory consistency by issuing a cache flush/sync when + consistency is needed. If this flag is set V4L2 will attempt to + allocate the buffer in non-consistent memory. The flag takes effect + only if the buffer is used for :ref:`memory mapping ` I/O and the + queue reports the + :ref:`V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS ` + capability. .. c:type:: v4l2_memory diff --git a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst index 79884bb4893b..893570af617b 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst @@ -126,6 +126,7 @@ aborting or finishing any DMA in progress, an implicit .. _V4L2-BUF-CAP-SUPPORTS-REQUESTS: .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS: .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: +.. _V4L2-BUF-CAP-SUPPORTS-CACHE-HINTS: .. cssclass:: longtable @@ -156,6 +157,14 @@ 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 for ``V4L2_MEMORY_MMAP`` queues which 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 f13851212cc8..26716055d914 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -710,6 +710,8 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) *caps |= V4L2_BUF_CAP_SUPPORTS_DMABUF; if (q->subsystem_flags & VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF) *caps |= V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF; + if (q->allow_cache_hints && q->io_modes & VB2_MMAP) + *caps |= V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS; #ifdef CONFIG_MEDIA_CONTROLLER_REQUEST_API if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 9817b7e2c968..0d4deba8fe30 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 { /* @@ -951,6 +953,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 Fri Apr 24 09:29:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507369 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 7F76014B4 for ; Fri, 24 Apr 2020 09:31:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BB7C2076C for ; Fri, 24 Apr 2020 09:31:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eQkQOYAW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726936AbgDXJbC (ORCPT ); Fri, 24 Apr 2020 05:31:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJbB (ORCPT ); Fri, 24 Apr 2020 05:31:01 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DF16C09B045; Fri, 24 Apr 2020 02:31:01 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id 18so3317343pfv.8; Fri, 24 Apr 2020 02:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NEHGaOKTyM7ltSmSqSSPuMjPTHDepy0wQfm/rh0jftw=; b=eQkQOYAWcKeKTkYqv65i+rFA9v4AkYZ/Oi8LwPno8uAT+5Mr7WDmp2XKAtWBIcmDPC NiChVxfjDs8swxW8i7Q0h2te+LYPVEwBhM/ieqzIZtGc7LhQpMqSiHVldv59YU9R8dld xgO+fjBYsm11sKZP+YvlpiuR3YYW/XQ5QtrJaO244dh636TGSV9Ef9ZNfIOamI0/vJGG Y1qqKbjO73X30q9fkIM6qBBBONk3j+oE53XXghiQcXTKkMVG9F9iQE8abNhPk/IprFCX sSNLPhYmaD5Sva3OaKOG0Z8s7EgXPZQ/MvpmQYcgW8yLIt1AfY1+F9JqkIO7tbfLtQcK i46g== 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=NEHGaOKTyM7ltSmSqSSPuMjPTHDepy0wQfm/rh0jftw=; b=SuPwZgZAL6C3FFcvLTMEcG1eM9L26qFIwrbK93dYzhfdGn94SgV90A0BUkNN3IhRT5 RK+SF2wLzfHfHkoeCeeR4xDdG7jpcybOMn2aJcy0L3Csk/HgxMdu/fq5qkJI5omyzrFX bwDcADzSCZpXBe9OjaJBsBd94T77TfS/c3GFkyzp5kidllvVXtx7A4tkHrHhi0V210V7 cIjP+a/OVOflRt5DXn0j71VUmnlMI8ck7q8wisstlhmD6T2gzk9BFQclP8PUr4KDYAbh TtmR9G4+oumYuttsQ8voBsDCfwh2jUvJpQ/+p6izVW8+wT8aEH6FbAWyBVC1aZo3TikZ HXAA== X-Gm-Message-State: AGi0PuZlpK6ymzPcWjip5REVz3E8Rn425m/OWjXKLBi2oJsk3FO7NoRn DJEzaD9O3dg8kE558t+hLGU= X-Google-Smtp-Source: APiQypJLuqN9lXB07Tgliam/7giAkQ2pmRXSCXO/RcfAA+GJbEt4yGo+WLggcZYxNvBEeEsV/ECUGg== X-Received: by 2002:aa7:951b:: with SMTP id b27mr8650374pfp.2.1587720660565; Fri, 24 Apr 2020 02:31:00 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.30.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:00 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 05/13] videobuf2: add queue memory consistency parameter Date: Fri, 24 Apr 2020 18:29:12 +0900 Message-Id: <20200424092920.4801-6-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 | 52 +++++++++++++++---- .../media/common/videobuf2/videobuf2-v4l2.c | 6 +-- drivers/media/dvb-core/dvb_vb2.c | 2 +- include/media/videobuf2-core.h | 8 ++- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 44d65f5be845..f1a65925bc17 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -664,11 +664,34 @@ 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; +} + +static bool verify_consistency_attr(struct vb2_queue *q, bool consistent_mem) +{ + bool queue_is_consistent = !(q->dma_attrs & DMA_ATTR_NON_CONSISTENT); + + if (consistent_mem != queue_is_consistent) { + dprintk(1, "memory consistency model mismatch\n"); + return false; + } + return true; +} + int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, - unsigned int *count) + unsigned int flags, unsigned int *count) { unsigned int num_buffers, allocated_buffers, num_planes = 0; unsigned plane_sizes[VB2_MAX_PLANES] = { }; + bool consistent_mem = true; unsigned int i; int ret; @@ -683,7 +706,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, } if (*count == 0 || q->num_buffers != 0 || - (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory)) { + (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory) || + !verify_consistency_attr(q, consistent_mem)) { /* * We already have buffers allocated, so first check if they * are not in use and can be freed. @@ -730,6 +754,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (ret) return ret; + set_queue_consistency(q, consistent_mem); /* Check that driver has set sane values */ if (WARN_ON(!num_planes)) return -EINVAL; @@ -804,11 +829,13 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, EXPORT_SYMBOL_GPL(vb2_core_reqbufs); int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, - unsigned int *count, unsigned requested_planes, - const unsigned requested_sizes[]) + unsigned int flags, unsigned int *count, + unsigned int requested_planes, + const unsigned int requested_sizes[]) { unsigned int num_planes = 0, num_buffers, allocated_buffers; unsigned plane_sizes[VB2_MAX_PLANES] = { }; + bool consistent_mem = true; int ret; if (q->num_buffers == VB2_MAX_FRAME) { @@ -824,9 +851,13 @@ 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; 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); @@ -845,6 +876,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, if (ret) return ret; + set_queue_consistency(q, consistent_mem); /* Finally, allocate buffers and video memory */ allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes); @@ -2498,7 +2530,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, 0, &fileio->count); if (ret) goto err_kfree; @@ -2555,7 +2587,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, 0, &fileio->count); err_kfree: q->fileio = NULL; @@ -2575,7 +2607,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, 0, &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 26716055d914..04ea332567b1 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -723,7 +723,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, 0, &req->count); } EXPORT_SYMBOL_GPL(vb2_reqbufs); @@ -797,7 +797,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); @@ -973,7 +973,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, 0, &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..959d110407a4 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, 0, &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 ccc5c498d3e3..9e68fe043a6c 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -740,6 +740,8 @@ 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. + * @flags: auxiliary queue/buffer management flags. Currently, the only + * used flag is %V4L2_FLAG_MEMORY_NON_CONSISTENT. * @count: requested buffer count. * * Videobuf2 core helper to implement VIDIOC_REQBUF() operation. It is called @@ -764,12 +766,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); + unsigned int flags, 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. + * @flags: auxiliary queue/buffer management flags. * @count: requested buffer count. * @requested_planes: number of planes requested. * @requested_sizes: array with the size of the planes. @@ -787,7 +790,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, + unsigned int flags, unsigned int *count, + unsigned int requested_planes, const unsigned int requested_sizes[]); /** From patchwork Fri Apr 24 09:29:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507371 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 3828981 for ; Fri, 24 Apr 2020 09:31:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1168D20776 for ; Fri, 24 Apr 2020 09:31:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cNeRtb9k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726946AbgDXJbG (ORCPT ); Fri, 24 Apr 2020 05:31:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJbF (ORCPT ); Fri, 24 Apr 2020 05:31:05 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27D93C09B045; Fri, 24 Apr 2020 02:31:05 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id w65so4520019pfc.12; Fri, 24 Apr 2020 02:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NPEZSYjn+WtLhsReT/texBQ751H/RxS2UXPSFd6gB1M=; b=cNeRtb9kYzMPSdTkXRY5JKPnpCTz/8HD+eL8wusXHqXSp6EfHm1L3SgI59bo/8QY07 5dQBY1UDb3PsG75n7Hy31eHxi0xyGdojH6EnIcJ9UkOUuX0j/+6mywflIyc4An9e7Sv6 ZaIwFd6i9O9msiK3sOBOWsQgqwGGToz+W10Zqjcf+5TEsW+aOUdYmCswkujvcb/RLBr6 /HWNAqfKRO10v33Ut9vAVUhd7UNW1TWItrsV/TCZX19a43PamLt+hVrePQ9f5glgTM3t mrm+WvQLlmw/Ao2P/jCN9SnO+UC1H10hhNpRt/A6Q8LUTYmUck3oiqwqk7Wj1RsMCbw+ 975w== 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=NPEZSYjn+WtLhsReT/texBQ751H/RxS2UXPSFd6gB1M=; b=DHkANJQQS/ZnVxlwU+mM6yEn5eGHxhKu3GnOpFOf89IWKrhTlwzfcUWMU2JhxyEAS0 t40iszq/zwmN0mCZKlf02fAT+luDDnN8Tkub5Llk01CyWNjfORgB6hFjdu61dt4iyMwE jn0NGSThsj6CMreeG8c6jA5WV5ggrcvBXLlBzW+YDFAnSmELhTFORxin0kPcszHzbcMo Dv32OZkvMHedbBmKHe56zUyuXxgDaB41kpEU9dRdQbF7LmkgANWWhMbKtlW/KJoEh8zW Xrb/tSsJZkW0txvFbtZg9Oqd7dH+gJvMHf5r/6aUQDsCDFOEcAKhX0kwiXCK/a9rK3Nh DB2A== X-Gm-Message-State: AGi0PuaFfOS6poCuivEFjgy6GNGUJ/b4vZy8mT1g8r6jGxfQu7alBUaw lkS9yD/llxlGGAx9FzV8Aug= X-Google-Smtp-Source: APiQypLcxm/wAIl8BywbmY78/iUqZf8yZpiKPoA3//haU4AORueSzM4KxElh9Sm3eSBMXce7n5D0xA== X-Received: by 2002:a65:611a:: with SMTP id z26mr8046715pgu.341.1587720664462; Fri, 24 Apr 2020 02:31:04 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:03 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 06/13] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Fri, 24 Apr 2020 18:29:13 +0900 Message-Id: <20200424092920.4801-7-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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. = CREATE_BUFS32 struct v4l2_create_buffers32 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/v4l/vidioc-create-bufs.rst | 7 ++- .../media/v4l/vidioc-reqbufs.rst | 11 ++++- .../media/common/videobuf2/videobuf2-core.c | 6 +++ .../media/common/videobuf2/videobuf2-v4l2.c | 43 +++++++++++++++++-- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 9 +++- drivers/media/v4l2-core/v4l2-ioctl.c | 5 +-- include/uapi/linux/videodev2.h | 10 ++++- 7 files changed, 76 insertions(+), 15 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst b/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst index bd580232be10..4ece2551b355 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst @@ -121,7 +121,12 @@ than the number requested. other changes, then set ``count`` to 0, ``memory`` to ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type. * - __u32 - - ``reserved``\ [7] + - ``flags`` + - Specifies additional buffer management attributes. + See :ref:`memory-flags`. + + * - __u32 + - ``reserved``\ [6] - A place holder for future extensions. Drivers and applications must set the array to zero. diff --git a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst index 893570af617b..a933a72dab1f 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst @@ -112,10 +112,17 @@ aborting or finishing any DMA in progress, an implicit ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will free any previously allocated buffers, so this is typically something that will be done at the start of the application. + * - union { + - (anonymous) + * - __u32 + - ``flags`` + - Specifies additional buffer management attributes. + See :ref:`memory-flags`. * - __u32 - ``reserved``\ [1] - - A place holder for future extensions. Drivers and applications - must set the array to zero. + - Kept for backwards compatibility. Use ``flags`` instead. + * - } + - .. tabularcolumns:: |p{6.1cm}|p{2.2cm}|p{8.7cm}| diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index f1a65925bc17..d16f47022552 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -695,6 +695,9 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int i; int ret; + if (flags & V4L2_FLAG_MEMORY_NON_CONSISTENT) + consistent_mem = false; + if (q->streaming) { dprintk(1, "streaming active\n"); return -EBUSY; @@ -838,6 +841,9 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, bool consistent_mem = true; int ret; + if (flags & V4L2_FLAG_MEMORY_NON_CONSISTENT) + consistent_mem = false; + if (q->num_buffers == VB2_MAX_FRAME) { dprintk(1, "maximum number of buffers already allocated\n"); return -ENOBUFS; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 04ea332567b1..aeb29c33984e 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -718,12 +718,36 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) #endif } +/* + * vb2_core_reqbufs()/vb2_core_create_bufs() can re-initialize the queue, + * change its memory, type and invoke driver's ->queue_setup(), so we need + * to adjust consistency flag and caps accordingly. + */ +static void fixup_consistency_attr(struct vb2_queue *q, unsigned int *flags) +{ + if (!vb2_queue_allows_cache_hints(q)) + *flags &= ~V4L2_FLAG_MEMORY_NON_CONSISTENT; +} + +static void fixup_cache_hints_cap(struct vb2_queue *q, unsigned int *caps) +{ + if (!vb2_queue_allows_cache_hints(q)) + *caps &= ~V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS; + else + *caps |= V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS; +} + 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, 0, &req->count); + if (ret) + return ret; + ret = vb2_core_reqbufs(q, req->memory, req->flags, &req->count); + fixup_consistency_attr(q, &req->flags); + fixup_cache_hints_cap(q, &req->capabilities); + return ret; } EXPORT_SYMBOL_GPL(vb2_reqbufs); @@ -797,8 +821,16 @@ 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, - &create->count, requested_planes, requested_sizes); + + if (ret) + return ret; + + ret = vb2_core_create_bufs(q, create->memory, + create->flags, &create->count, + requested_planes, requested_sizes); + fixup_consistency_attr(q, &create->flags); + fixup_cache_hints_cap(q, &create->capabilities); + return ret; } EXPORT_SYMBOL_GPL(vb2_create_bufs); @@ -973,7 +1005,10 @@ 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, 0, &p->count); + + res = vb2_core_reqbufs(vdev->queue, p->memory, p->flags, &p->count); + fixup_consistency_attr(vdev->queue, &p->flags); + fixup_cache_hints_cap(vdev->queue, &p->capabilities); /* 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-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index a99e82ec9ab6..aa162ed6d01c 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -246,6 +246,8 @@ struct v4l2_format32 { * @memory: buffer memory type * @format: frame format, for which buffers are requested * @capabilities: capabilities of this buffer type. + * @flags: additional buffer management attributes (ignored if queue + * does not have V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS capability). * @reserved: future extensions */ struct v4l2_create_buffers32 { @@ -254,7 +256,8 @@ struct v4l2_create_buffers32 { __u32 memory; /* enum v4l2_memory */ struct v4l2_format32 format; __u32 capabilities; - __u32 reserved[7]; + __u32 flags; + __u32 reserved[6]; }; static int __bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size) @@ -355,7 +358,8 @@ static int get_v4l2_create32(struct v4l2_create_buffers __user *p64, { if (!access_ok(p32, sizeof(*p32)) || copy_in_user(p64, p32, - offsetof(struct v4l2_create_buffers32, format))) + offsetof(struct v4l2_create_buffers32, format)) || + assign_in_user(&p64->flags, &p32->flags)) return -EFAULT; return __get_v4l2_format32(&p64->format, &p32->format, aux_buf, aux_space); @@ -417,6 +421,7 @@ static int put_v4l2_create32(struct v4l2_create_buffers __user *p64, copy_in_user(p32, p64, offsetof(struct v4l2_create_buffers32, format)) || assign_in_user(&p32->capabilities, &p64->capabilities) || + assign_in_user(&p32->flags, &p64->flags) || copy_in_user(p32->reserved, p64->reserved, sizeof(p64->reserved))) return -EFAULT; return __put_v4l2_format32(&p64->format, &p32->format); diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 833e79a2cb98..4c2dadbeefdc 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1978,9 +1978,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); } @@ -2020,7 +2017,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 0d4deba8fe30..f0a4694dd7c6 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -943,7 +943,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 */ @@ -2447,6 +2450,8 @@ struct v4l2_dbg_chip_info { * @memory: enum v4l2_memory; buffer memory type * @format: frame format, for which buffers are requested * @capabilities: capabilities of this buffer type. + * @flags: additional buffer management attributes (ignored if queue + * does not have V4L2_BUF_CAP_SUPPORTS_CACHE_HINTS capability). * @reserved: future extensions */ struct v4l2_create_buffers { @@ -2455,7 +2460,8 @@ struct v4l2_create_buffers { __u32 memory; struct v4l2_format format; __u32 capabilities; - __u32 reserved[7]; + __u32 flags; + __u32 reserved[6]; }; /* From patchwork Fri Apr 24 09:29:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507373 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 9F48B81 for ; Fri, 24 Apr 2020 09:31:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8867D2168B for ; Fri, 24 Apr 2020 09:31:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KOoSQgCg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726958AbgDXJbJ (ORCPT ); Fri, 24 Apr 2020 05:31:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJbI (ORCPT ); Fri, 24 Apr 2020 05:31:08 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D404C09B045; Fri, 24 Apr 2020 02:31:08 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id r4so4373932pgg.4; Fri, 24 Apr 2020 02:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vCJfyab6Lo+SPYpGKD5yA65RisCBDWHIbluNYYAXFSY=; b=KOoSQgCgjSfL6JMrj9wJl3MF6nl9GRtsWNYFxIhC7E7QBdVjjjW47D7zv6ayp/dunQ 2c3Q/5Ro4+h0M7dKvnaW8VeLd+12xe5RChvC/injaidyGLxaiYnXbQbaR/egNTpPMpxP hX/fPvHIK8KwPxN3Zf5tOqZK8WrhYfophs0vWTsxPwNJH7CsnNMHRo4JSmz5/uoRydof PYl9tFCm1WiF7zefu/X30kf7vM4R8SB++bBA9hhfBQ9+RAJ5nzC6YTL9l21PFTNA6Mis k2rLo1nPToZVo1KHJum7JM/gVIf89ZiTMTMHbTGIG0JfXfVie62ARFpOtmgoxS9W2RRZ V1lA== 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=vCJfyab6Lo+SPYpGKD5yA65RisCBDWHIbluNYYAXFSY=; b=IoQke+8KwkgX2QKEg3NWjcvdVLw8ZFAe+mj2p1V3jcdgHUUq6KVnbdVaAxWFT3+geb uVDVxnmTVae07jQgU+1ZyiKys57ya7dl2LcsiLM2UBnZ/a041zq7s8st6PU+osMOmJ2e XRJltdz7RgDxtV4w9CBsZVyYXqwtdq2nsjYHvX5NfzRLnNL8iLRNzX77lCEZ4ynHzaKK zeD+D19V5qQAOmqbiNIFoPkwrFRmbEEc4WWFRMCSZg5EGSwwluVcHEPfVWydMa+lEbXT QZZNSXtIwCv9/VNuJS9ilhCEvlu47KRHf6jOGFrTQmoG7T4RHP1WvJdc3dSDkGW1OU2H 3csw== X-Gm-Message-State: AGi0PuYb5/9/l8EIffSSbUnQCASsGZcn7oOYfA3dwW8Ihg+n+Pg2BRTc XtfpbzxyHiV9gm8f7S6S8tw= X-Google-Smtp-Source: APiQypLXTk5Gj+sQxqdtDHpEza1UKhleKdeeAE6zusP+0PyDfWuSWQE6i83UH4667OZKkUYjv/Hn8g== X-Received: by 2002:a63:c149:: with SMTP id p9mr8089925pgi.389.1587720668136; Fri, 24 Apr 2020 02:31:08 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:07 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 07/13] videobuf2: factor out planes prepare/finish functions Date: Fri, 24 Apr 2020 18:29:14 +0900 Message-Id: <20200424092920.4801-8-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 d16f47022552..0be31a11c913 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. @@ -960,7 +986,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; @@ -980,12 +1005,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) { @@ -1310,7 +1331,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) { @@ -1354,11 +1374,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; @@ -1978,14 +1994,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 Fri Apr 24 09:29:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507375 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 0CE9981 for ; Fri, 24 Apr 2020 09:31:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA28D2166E for ; Fri, 24 Apr 2020 09:31:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tkScItcp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbgDXJbO (ORCPT ); Fri, 24 Apr 2020 05:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJbN (ORCPT ); Fri, 24 Apr 2020 05:31:13 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E8E6C09B045; Fri, 24 Apr 2020 02:31:13 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id h12so2549029pjz.1; Fri, 24 Apr 2020 02:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JTwvpWckzKCbbPdLWK9YgE3TO5c8WM7mL5Hmnl5TrQk=; b=tkScItcpVTDbU9EfQBJaZSOGlVq5800YrbhrwJcICRbKL2zFihATbNG4v85Y4muI9D 9vbxdAJdYN14wckkmncrIu1U+OHAmOhqiRvoqIf40z6tTm5ZNF061DpE9+XhB6Q5LYX3 fcuMoaPinAb5nyMsSp01F2MQvHLHoLNCVlsZTCZmny6teErJujOgQwmrqUa71bG61L6f eiTWlqp2AgP8tmXUQqTWsK+A5ZylpBtGhBfhpCGEF3s3d32xL4WoD+qtXjyI1D5nMb7Q 7NKWc63nV4QSneOqNQik6Tvl63TAD3hLmSmGI5TnI0wpwL4POjWNsq3TH8CtspmqqHsQ 0g9g== 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=JTwvpWckzKCbbPdLWK9YgE3TO5c8WM7mL5Hmnl5TrQk=; b=PDE3j/KNsbLlt9AnVmHPejLQTZ1yFaymkrYiOneiG2bMGZzbIJ7lH4yxIkn9/yQKIo wSKwAMCvg3H+y6bGZ6L+q3VQIEbV5YPZiMozM2wvQsftbfMibYrR224zOPiBTOKzFF7c tIiIIoVBWjxHZmbhyedQ6fa7/XEh2A3yCMU9C1ZwVH+bcSUPjzWnVMHKmFJ8zsqJmcKX bleJlR7hcf3eeXKanAms8XTYYQyM0Vry2wzkAJ58ap2ttWJrLSm48D8yDWXzmJ4r14Id YLGsVOkVVR8LY6NWyYuXSy3IXpYlBP8JhbijZEZaNKIcZu1QS36Eo5dywD4MGJxDYO2R zTRg== X-Gm-Message-State: AGi0PuYjZ1XhuwbhjOFR+wXM876P+qyXHXla/wh6mhwlUQudAunfNqlp pDHDIQFyHpiXyW+mfOpHnlM= X-Google-Smtp-Source: APiQypIuQd/lmMRL07Xtm534jd3jbgvw2i/UAlIYjki7EoKijQVGMzRrg44qkKaUY8Hwdn6afBfg0g== X-Received: by 2002:a17:90a:930c:: with SMTP id p12mr5257632pjo.64.1587720672604; Fri, 24 Apr 2020 02:31:12 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:12 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 08/13] videobuf2: do not sync caches when we are allowed not to Date: Fri, 24 Apr 2020 18:29:15 +0900 Message-Id: <20200424092920.4801-9-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 0be31a11c913..5409e15b6af4 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 Fri Apr 24 09:29:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507377 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 CB5EE81 for ; Fri, 24 Apr 2020 09:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B40BA2076C for ; Fri, 24 Apr 2020 09:31:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CHtX2Wtn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726983AbgDXJbS (ORCPT ); Fri, 24 Apr 2020 05:31:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJbR (ORCPT ); Fri, 24 Apr 2020 05:31:17 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D25B3C09B045; Fri, 24 Apr 2020 02:31:17 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id w3so3543540plz.5; Fri, 24 Apr 2020 02:31:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=THhKNtjH/uEj0jg+pesiBCJg+1ebmbvJUD6/foS9B1Q=; b=CHtX2WtnxNzO5uPFdApzvX/OoTxAoC69nGtsgdoImceGkYQD7NbFKuYA4qP9+1MJdl LjBRNEJf2z4kqzPrmTCQVhDbYC2wW4auT2BNUrZjUAxnH/ipmKYxTKCZD5OyDLjqG50i GuCH+nINsRgloq6SarEYFB7S3yXi2RJ0pgmNGSvLYIjhmaxoo6DsYlwdp/X7U7E87K0Q rdS2B7SeQGS6YqNUK8rIHLiUiz1Th3624BMOcZXmT/E46UYmRf9miVgoM7sAfHsZDFgk /DET/s363DrnEv7+QogISyK6+1f9Nlzx1tUHPiKvG6ZSSZgCE3nwYDFhaX99dojPolPP 7ybg== 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=THhKNtjH/uEj0jg+pesiBCJg+1ebmbvJUD6/foS9B1Q=; b=FI0BfwhpvLoCj54KONUYa4jPYD5WbAGBj5J9CXkr76RkRYRvzouQa6OLYVqxwxGobu mSiVZAWvyJ2rKLp5Eu0k/9hxWafyS11DUQyh5ySC00zhQPYuVISxZWv8PDdsIAxI8KpV VMcE2E+7IAwA+/tcjtQLkryRXN/KYsHTyxTC2dFl0SvUVq1XLnyyn+x1IajI6zp5qdHp ZsINjCB4BDtsEYg9Upd7HUjT9WzJsIIrBDen/74RRPib7Qb0Q5dPB/4seHJ0Qc4DLpF8 cu3AE2enhPSWXJ1PSM29SW2iugG69bDqgjphgTwwVWKbqXQPVxygWPrzOgQeAXLFsz9G 8+Xg== X-Gm-Message-State: AGi0PubNIqaF+Vt/QfP5iFe/iS3KH3iAOzgQtRnLLDYJO7U6oIQMANHx /oGwtYy0UsLdMLHGQKAKyE8= X-Google-Smtp-Source: APiQypKd9OHBDoHGBTRLyj3+BsnI6AnjtLIwL2qeULNLoU5v1bAXJV0jKf71cTgLrMkzA7LH7e3pTw== X-Received: by 2002:a17:90a:ad02:: with SMTP id r2mr5294423pjq.63.1587720677333; Fri, 24 Apr 2020 02:31:17 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:16 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 09/13] videobuf2: check ->synced flag in prepare() and finish() Date: Fri, 24 Apr 2020 18:29:16 +0900 Message-Id: <20200424092920.4801-10-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 5409e15b6af4..5a69005b7d59 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, @@ -2000,8 +2006,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 Fri Apr 24 09:29:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507379 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 EB0EB81 for ; Fri, 24 Apr 2020 09:31:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D25162074F for ; Fri, 24 Apr 2020 09:31:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b36VpCzV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbgDXJbY (ORCPT ); Fri, 24 Apr 2020 05:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJbX (ORCPT ); Fri, 24 Apr 2020 05:31:23 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB07AC09B045; Fri, 24 Apr 2020 02:31:21 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id y6so3685173pjc.4; Fri, 24 Apr 2020 02:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+rsYbWWzoE0lVJTAtJ90p8tOUmwZIRJ0zy7fKEnpH4c=; b=b36VpCzV7zti4L8z9p4NJt/YfJChnE42aDZFhVYDX4Ysh0fulcs8UGIkiwGWLYuEEf dQQDeBMcoPSsO/s4CqMt++DRIxpMZF5n5vQvrl83F4N+7Q1FErqOSY6d4NKuOCCQFW/H YmacrQ/0T1Qn5tx1SmHHLne+B3eWRhNdQ2ehD7VyXjgNngu83vQy5AZA8MTmB4DhLCKM W9j5tCP8E6xsOjV2cEdTk24REYkiBWhKTqLtQ9YLYMbo7SpFFfUFxedsSh+0DA98ENKL m3u09CKUtlTYuJrp05n//2mBrRgpBb5tjGn1pGk8CYi8rcdahC6MCyjmZcA9Tmo3GllQ N1fQ== 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=+rsYbWWzoE0lVJTAtJ90p8tOUmwZIRJ0zy7fKEnpH4c=; b=Hs0KT+ESu6fXgKB5XeSlZwFgEk7I6RJ4MKZqeLgkZecpZr+rvdUnMfG+qSAFu/elNC eM5krbaEhwIZcJROMyqETxbxRHxV/iuX4YZQQpmbXtL7dbVrIQ0E/Fz9C8hAmLb3Y00k lM1cJ9UjHtavr4M8cEIdIadPvmT0axKqznZKFHNJMyDLIJOnbbpeJmzmXylT4nKMpWuJ 46oA0jG9h/Q5qOmyJfJAptK7PJZl+ryoYn6LNSo5aUdRGRgjkRNAgbHEjnUbtz9Gh9i/ /gSFsn+yFfcd8Dh57e5wFvHJTWB7+NDHJClQrr1wmjgKKq8ai5inlSVwLxGCO2z9oxLc wSWw== X-Gm-Message-State: AGi0PubAo/4hG/tSmdz+NySPgGi8X2lHVvIMe4RyuPm27vE40Qsot12m OoxTYL7BqXtWETP71q+sGJY= X-Google-Smtp-Source: APiQypJp7ndABcDIcAJcH/x3UIeGvoQUWaE7aoN/rWhfc8p42rvhjgMLDfX1vf1A2j1n+lDtxAPu+A== X-Received: by 2002:a17:90a:30a5:: with SMTP id h34mr5050464pjb.171.1587720681431; Fri, 24 Apr 2020 02:31:21 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:20 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 10/13] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Fri, 24 Apr 2020 18:29:17 +0900 Message-Id: <20200424092920.4801-11-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index d3a3ee5b597b..6787e2cb905e 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,34 @@ 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 +386,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 Fri Apr 24 09:29:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11507381 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 C9D1A92A for ; Fri, 24 Apr 2020 09:31:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0B8F20767 for ; Fri, 24 Apr 2020 09:31:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mc5wOBEo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727009AbgDXJb2 (ORCPT ); Fri, 24 Apr 2020 05:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJb1 (ORCPT ); Fri, 24 Apr 2020 05:31:27 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19104C09B045; Fri, 24 Apr 2020 02:31:26 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id f7so4531873pfa.9; Fri, 24 Apr 2020 02:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j+7rcI71ob1TCh3mFTQUYSyuPNtTEDwVHxFopC5n+l4=; b=Mc5wOBEovvA8VKll9zKSSt0ov271hrgBPfmA98Z/XaypAeo4uqXxobP2NkwsWHnxdt 3Bv3O1RGAjVThwSCEzfhN49ebUXyAw4Ubyn1hbyxrOAWofEsDym7QLxFboksPhWHMEgg 5UdlfSkEp1oH83GhIqzbkwEZsYzmctmnvsKzMcCn3F/ERW4kPSLmXJTeVNmkwgRzpYPO tcfrONxc7B0ZWbDUnxe4wCh/JoTPR3oMSjN7WFgaMYpL/ZcUjCI67FGYsp33XThvR1+i 5d8gKhDMXf/7Umf0UkO7LudWIs2jgm7TJMvwSYZmKwY1GSOqtjEyrhUQaqWUcdDlKoBF pZdQ== 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=j+7rcI71ob1TCh3mFTQUYSyuPNtTEDwVHxFopC5n+l4=; b=VRV+rHUcexv8jcuiFgVF1+SMmalAk6q2TK3I2bSWr2jYpLQBraDFtz35k30PUUdLwI l/1f9lIxjpJhQQvS8Cx4ohboXN2pwK9TpY53Wx0n/zgG4yrtWp3aLbsj+tPrsvjt0dI2 ELXx8d0WgYGZSFOZmSjFRKboyH7kTBZFtm+CL7nNAS11Tbjmow8wnSFnonHdg2WWdkHD Hr8y6DMJGngWC9fJY41sk8xyj94fqOuF9UfAD0wcN63PG3xM70cgH8ydrzWhdmvzub5p omVFjzNIBXAr45crer+kUAM9mUI3D/bQaa1cchXgMYlMfLLRhKT8GacUCCGW/p9b4ACC 3KHQ== X-Gm-Message-State: AGi0PuZ+GrN2EdWeHIRtMs21OdKmAg6U+g7udP6x+CtFqTkta9QhIHCo nU31JCatHlLtYBetSm/7hEU= X-Google-Smtp-Source: APiQypLhXYrHZOSJHOuryWHWBpBYQsMMElc0pgZq88wVU1rhQQzjGKMWRz+S0LVctnvH1GMN4CW+Eg== X-Received: by 2002:aa7:850f:: with SMTP id v15mr8386664pfn.204.1587720685442; Fri, 24 Apr 2020 02:31:25 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:24 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 11/13] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Fri, 24 Apr 2020 18:29:18 +0900 Message-Id: <20200424092920.4801-12-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 92072a08af25..595137e358e7 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) @@ -469,6 +475,28 @@ 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; @@ -487,6 +515,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 Fri Apr 24 09:29: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: 11507383 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 3CEDA92A for ; Fri, 24 Apr 2020 09:31:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2430820767 for ; Fri, 24 Apr 2020 09:31:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SFkGkznq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727020AbgDXJbb (ORCPT ); Fri, 24 Apr 2020 05:31:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726523AbgDXJba (ORCPT ); Fri, 24 Apr 2020 05:31:30 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42511C09B045; Fri, 24 Apr 2020 02:31:30 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id o10so4375637pgb.6; Fri, 24 Apr 2020 02:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PKtrJsIKIcsIj8dnmTqgxVou7+4jAhZAHReCNI0jtao=; b=SFkGkznqV1H1/UpaNUH8mKQuDrsQo/npf8DckslCy1QCaEV0kqH92LyVP+K1inquE4 H6NxgIaHlXj2KeAFmsbekH7Mgb7vxRC3jNCDsS2S2Gxj0qD+Uvzlnwns921f/ObsSt4P 9MGsa8MwHAyYBKEJrha+kZApYkhzLeSj6gOIN8lDQynJyt0JYDP+OnnlQ+TO5KxROYNC QvMoPwEkJ5r46nP1nElwu/o565NcHyl23gy94BSVo3jT0c68/v+sVGo81RCmRqVudcYH CmY3l5KYqp6B0UGR2OGqx9ZsrTHcOcKVRz9rFN3OhuHIWGL/DFkZPB6d+FDYIvDPoeQs HE6g== 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=PKtrJsIKIcsIj8dnmTqgxVou7+4jAhZAHReCNI0jtao=; b=KRa0Z1D5DptlG5snJRCYcoIlcYYFoyk1haZxW2juL4UvYc7hkrmte6O7GJC9zqGNdZ 6lG8PeM/Iz830OxtI+ls/j1so3jwG8tRqH4VMs1/9QlTLnqBmkDeAayO8HCBZWmPwI1W 11WdBTqkiDHYJuFMW6cgXDGGoZTiTFtb0euZuqnLP06+VRbhuNOjcnJqHcB5mK7bx7ic 6QNTbkQBYP7q0zpYC9gU6OXHr40Hk3Kzs5j7je9N7vZCY2OwnrrEF6Y5dQiXReRHKwxj qwLKpCtclvhhT3F9ECmnGLRJEaX1PTK/3YijhmsKRNXY5EGJjZ/gNaR6jwG3r3eJci2p HgwA== X-Gm-Message-State: AGi0PuYwsZQZKI5ooXLHf8DrXd6M5eWaTBT+TE82phnsrjsgf9yUayk8 xjCyy3Dmt6e4UWnvj6Op4BQ= X-Google-Smtp-Source: APiQypLbJvcncmRPQILZGS9hggGkztQpLq5XxJGNQqomKanvk4oYLWy6JiUfB935YNBgFj3GZvzBUw== X-Received: by 2002:a62:1549:: with SMTP id 70mr8126648pfv.43.1587720689741; Fri, 24 Apr 2020 02:31:29 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:29 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCHv5 12/13] videobuf2: don't test db_attach in dma-contig prepare and finish Date: Fri, 24 Apr 2020 18:29:19 +0900 Message-Id: <20200424092920.4801-13-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky 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 6787e2cb905e..5a3e1c3b556f 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 595137e358e7..0a40e00f0d7e 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); } From patchwork Fri Apr 24 09:29: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: 11507385 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 CFC3781 for ; Fri, 24 Apr 2020 09:31:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B294E214AF for ; Fri, 24 Apr 2020 09:31:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jfdfDUo7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727033AbgDXJbg (ORCPT ); Fri, 24 Apr 2020 05:31:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726851AbgDXJbe (ORCPT ); Fri, 24 Apr 2020 05:31:34 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEF9C09B045; Fri, 24 Apr 2020 02:31:34 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id d184so4542768pfd.4; Fri, 24 Apr 2020 02:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hJmixU2PrWkj0dk3qkCF/oIlS2qMsZOQ6WSeOMDMwe4=; b=jfdfDUo7m5mp06Ypfyw/D2rrmYGOh1zDXOzzXPhV0hPC7QpjGZt5E9PFv4Hx38T0Vt 19Bsk+Sx/ENO7hknGQ8fXAi3rP7P0yK1TYDNwKdy7I5kRHfxAtU+NQGrlV1nWBDpz75/ D8U2+mRYzQScrH4OBCmDWpwbNYrfQZmc9+VseB62w6ZG0wEt0j5rL5OiSS7AAQnMZA48 L+U8FcKxS0CLY+r6eQb8SuFeyGgoUzgWWfGX6EwylVPvyU5WP6Htmu7tZqzeYYQhvKba 726KkLhnCButncSilMtFqr/waw6Jolb7qPACPetkYWva/JaMBtrPVxOFndFYLqcAi+RQ MebQ== 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=hJmixU2PrWkj0dk3qkCF/oIlS2qMsZOQ6WSeOMDMwe4=; b=IPjInLusdOVDrC7kOuCRnsy/9ur3Na+0q5r7Dnouv5JmQzcGKphoVA8oTHLCRKcsLA xxaSp4MxKrd4wBOjpw3m0F9BqAGpGWRLYOfij+e18C4CpfoSneN08M6Iou/j2wFJYvAF Si5C3u27clxcNO81yhNAZ4d0rXlAxnSMY5A59AFbiIGW5CdAQ5fC4MeS/upA03uYntlF 5KdYSH1kmNG18OeDI0ZJafeZ8B0VJecJl4Xthdyew6ohAIIhEDl52wo9QGxFBl4Ujg2D vBS4uKiLw8MPvN/ssSvCdasgpEiJFfG1+ZfoZGt3hekO+IgwiukubLBfQf91rEtl887U UmXw== X-Gm-Message-State: AGi0PuaE116DNnBB3L5x/JWGk9UJVgBQewIZLoze5o0q6TNr24ceb9YM yC5r14mX8pNRM2Gk2uDDXCw= X-Google-Smtp-Source: APiQypIYVrp4eIX/1QCWzmFSQOWsmg0KhkwamqOlSsyLw3MgSL45w+5CYH2qqPshjBDRojasLyZlmQ== X-Received: by 2002:aa7:9251:: with SMTP id 17mr8100836pfp.315.1587720694144; Fri, 24 Apr 2020 02:31:34 -0700 (PDT) Received: from localhost.localdomain (146.85.30.125.dy.iij4u.or.jp. [125.30.85.146]) by smtp.gmail.com with ESMTPSA id 185sm5541315pfv.9.2020.04.24.02.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 02:31:33 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv5 13/13] media: vivid: add cache_hints module param Date: Fri, 24 Apr 2020 18:29:20 +0900 Message-Id: <20200424092920.4801-14-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> References: <20200424092920.4801-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a cache_hints module param to control per-queue user space cache hints support. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/media/vivid.rst | 9 +++++++++ drivers/media/test-drivers/vivid/vivid-core.c | 9 +++++++++ drivers/media/test-drivers/vivid/vivid-core.h | 1 + drivers/media/test-drivers/vivid/vivid-meta-cap.c | 5 +++++ drivers/media/test-drivers/vivid/vivid-meta-out.c | 5 +++++ drivers/media/test-drivers/vivid/vivid-sdr-cap.c | 7 +++++++ drivers/media/test-drivers/vivid/vivid-touch-cap.c | 5 +++++ drivers/media/test-drivers/vivid/vivid-vbi-cap.c | 5 +++++ drivers/media/test-drivers/vivid/vivid-vbi-out.c | 5 +++++ drivers/media/test-drivers/vivid/vivid-vid-cap.c | 5 +++++ drivers/media/test-drivers/vivid/vivid-vid-out.c | 5 +++++ 11 files changed, 61 insertions(+) diff --git a/Documentation/admin-guide/media/vivid.rst b/Documentation/admin-guide/media/vivid.rst index 52e57b773f07..a41fa7129dec 100644 --- a/Documentation/admin-guide/media/vivid.rst +++ b/Documentation/admin-guide/media/vivid.rst @@ -293,6 +293,15 @@ all configurable using the following module options: - 0: vmalloc - 1: dma-contig +- cache_hints: + + user-space cache hints selection, default is 0. It specifies if the + device supports user-space cache (for MMAP queues only) and memory + consistency hints. + + - 0: forbid hints + - 1: allow hints + Taken together, all these module options allow you to precisely customize the driver behavior and test your application with all sorts of permutations. It is also very suitable to emulate hardware that is not yet available, e.g. diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index 6c740e3e6999..b1bea405f382 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -169,6 +169,14 @@ MODULE_PARM_DESC(allocators, " memory allocator selection, default is 0.\n" "\t\t 0 == vmalloc\n" "\t\t 1 == dma-contig"); +static unsigned int cache_hints[VIVID_MAX_DEVS] = { + [0 ... (VIVID_MAX_DEVS - 1)] = 0 +}; +module_param_array(cache_hints, uint, NULL, 0444); +MODULE_PARM_DESC(cache_hints, " user-space cache hints, default is 0.\n" + "\t\t 0 == forbid\n" + "\t\t 1 == allow"); + static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS]; const struct v4l2_rect vivid_min_rect = { @@ -819,6 +827,7 @@ static int vivid_create_queue(struct vivid_dev *dev, q->lock = &dev->mutex; q->dev = dev->v4l2_dev.dev; q->supports_requests = true; + dev->allow_cache_hints = (cache_hints[dev->inst] == 1); return vb2_queue_init(q); } diff --git a/drivers/media/test-drivers/vivid/vivid-core.h b/drivers/media/test-drivers/vivid/vivid-core.h index 99e69b8f770f..75ab627ba91f 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.h +++ b/drivers/media/test-drivers/vivid/vivid-core.h @@ -572,6 +572,7 @@ struct vivid_dev { bool meta_pts; bool meta_scr; + bool allow_cache_hints; }; static inline bool vivid_is_webcam(const struct vivid_dev *dev) diff --git a/drivers/media/test-drivers/vivid/vivid-meta-cap.c b/drivers/media/test-drivers/vivid/vivid-meta-cap.c index 780f96860a6d..0ba8fff47106 100644 --- a/drivers/media/test-drivers/vivid/vivid-meta-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-meta-cap.c @@ -34,6 +34,11 @@ static int meta_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, *nbuffers = 2 - vq->num_buffers; *nplanes = 1; + + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-meta-out.c b/drivers/media/test-drivers/vivid/vivid-meta-out.c index ff8a039aba72..6be56f1230d4 100644 --- a/drivers/media/test-drivers/vivid/vivid-meta-out.c +++ b/drivers/media/test-drivers/vivid/vivid-meta-out.c @@ -34,6 +34,11 @@ static int meta_out_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, *nbuffers = 2 - vq->num_buffers; *nplanes = 1; + + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-sdr-cap.c b/drivers/media/test-drivers/vivid/vivid-sdr-cap.c index 2b7522e16efc..f87cd7d0fada 100644 --- a/drivers/media/test-drivers/vivid/vivid-sdr-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-sdr-cap.c @@ -211,9 +211,16 @@ static int sdr_cap_queue_setup(struct vb2_queue *vq, unsigned *nbuffers, unsigned *nplanes, unsigned sizes[], struct device *alloc_devs[]) { + struct vivid_dev *dev = vb2_get_drv_priv(vq); + /* 2 = max 16-bit sample returned */ sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2; *nplanes = 1; + + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-touch-cap.c b/drivers/media/test-drivers/vivid/vivid-touch-cap.c index ebb00b128030..af43a5f69ea0 100644 --- a/drivers/media/test-drivers/vivid/vivid-touch-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-touch-cap.c @@ -27,6 +27,11 @@ static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, *nbuffers = 2 - vq->num_buffers; *nplanes = 1; + + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c index 1a9348eea781..126754c0bee4 100644 --- a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c @@ -138,6 +138,11 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq, *nbuffers = 2 - vq->num_buffers; *nplanes = 1; + + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-out.c b/drivers/media/test-drivers/vivid/vivid-vbi-out.c index cd56476902a2..d35b458c01d2 100644 --- a/drivers/media/test-drivers/vivid/vivid-vbi-out.c +++ b/drivers/media/test-drivers/vivid/vivid-vbi-out.c @@ -34,6 +34,11 @@ static int vbi_out_queue_setup(struct vb2_queue *vq, *nbuffers = 2 - vq->num_buffers; *nplanes = 1; + + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c index e94beef008c8..d0dfd3632ba9 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c @@ -129,6 +129,11 @@ static int vid_cap_queue_setup(struct vb2_queue *vq, *nplanes = buffers; + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; + dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers); for (p = 0; p < buffers; p++) dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]); diff --git a/drivers/media/test-drivers/vivid/vivid-vid-out.c b/drivers/media/test-drivers/vivid/vivid-vid-out.c index ee3446e3217c..4af8aaa13ffa 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-out.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-out.c @@ -78,6 +78,11 @@ static int vid_out_queue_setup(struct vb2_queue *vq, *nplanes = planes; + if (dev->allow_cache_hints && vq->memory == VB2_MEMORY_MMAP) + vq->allow_cache_hints = 1; + else + vq->allow_cache_hints = 0; + dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers); for (p = 0; p < planes; p++) dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]);