From patchwork Thu May 14 16:01:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B57E2C433E1 for ; Thu, 14 May 2020 16:02:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F0AC206DC for ; Thu, 14 May 2020 16:02:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cWM6Cil1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727939AbgENQCP (ORCPT ); Thu, 14 May 2020 12:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQCO (ORCPT ); Thu, 14 May 2020 12:02:14 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D7B1C061A0C; Thu, 14 May 2020 09:02:13 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ms17so12639127pjb.0; Thu, 14 May 2020 09:02: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=PnRbc31NNtJk9tFYJKwcEqOlUSl+vuVKarKs0i2/PM0=; b=cWM6Cil1GSYHTo1M0pZ3oFkajjBsCJZsgLupozV/22XkpDN9n+dwxVACbGKEcRqwzG +IeR5qCbzhTXmsl4QhGPB3Njp5wnk+N9OHbNtWlAg4szvy2F5DsmeoF3WOXseT7Gygez LWNBa6oBN7+0ASqRQRNHFyp0WjzLLuejUZ1gGhmoTVvPMZ+J/rsbYLdauwMF4d+F0tuN s3i/t/HR/pcKAl/CKFI1WhmFIe55w6/9yYullim+UwmFTgyYxiFY+cUoyfDJTvXC72s/ JFAfGMBAMpMoBE4Q2lopRNRhZT1G6gbXy5E1o75ZBtikglp1mZJAOWj9Arizxlxd6PYt zaeQ== 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=DSg+zeZ1T/nIoeEgPTiZofkl6D1Kw1roe2V7AVcyVgbOiTvE61VEh1gNVqrHPmdKKH 6MF/IHL2MCZZRNnE/o2jVcGzsJK4qwaS/gBdEajs46Gm5Suktm1kl950Id63uX/R1SMI e1+Uz0AsHnJ4mh+CR79fI6M/2PZi4LB45/66O7++KQc7QZnlnepwYS+zZOU1QppY4+9q AugcSGzI5JLgtRa+hTRTY1Y3vGdfeMaQwRZdKLZVHsc8/mxAks1N7TByuNvjyvsdRJBk be2I95OZwb4l3rYqkspb/iFmJflQiBjlOq2J2yIDrDG0+aTtwjof5GD5nZDea0ui+4zp qxwQ== X-Gm-Message-State: AOAM531HxP1BPvNuWCFeDZV8OD5S9uvPbjFhOhxAg1ZAP0S4o6XRLpFb HLozRxejlZP4Bzzz/h7TfDw= X-Google-Smtp-Source: ABdhPJyEOpXzs7cbcSVjDSlUeR6mxqwNO0lH+67oQUTKg3KFm9trgf8wKVG2yFGUh1xOHbnS7mllRw== X-Received: by 2002:a17:902:c406:: with SMTP id k6mr4492717plk.203.1589472132868; Thu, 14 May 2020 09:02:12 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:02:11 -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: [PATCH v6 01/14] videobuf2: use explicit unsigned int in vb2_queue Date: Fri, 15 May 2020 01:01:40 +0900 Message-Id: <20200514160153.3646-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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 Thu May 14 16:01:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74274C433E0 for ; Thu, 14 May 2020 16:02:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EBA0206D8 for ; Thu, 14 May 2020 16:02:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bVyzPlij" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728017AbgENQCb (ORCPT ); Thu, 14 May 2020 12:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQCa (ORCPT ); Thu, 14 May 2020 12:02:30 -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 59584C061A0C; Thu, 14 May 2020 09:02:30 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id x2so1493075pfx.7; Thu, 14 May 2020 09:02: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=0nRxVz0Tz30cjvXMeYztWae2hdLtVm4GWG5AnsWwh9o=; b=bVyzPlijkSkZlbCvdUbf1g+pH293J7R1MR8vpSY6yJo/rBafYOozJh46NVAdvgp75R Uy/urpjq4AIVjgHm0HboabzXqZ5tvRJdh5EBxcQERTwZY/mCZ0YwXhhGIFfRloKyzznB eGhZ5FdH1LfO5Bk932yyGpHrARbJnQ7J47k3hhfGQa5ZcMEUHCtePxK7dc5qbWY+POjm aCaitRFYEg6oZzAcAqgDTjc8PDnJYHHMJc8fFTfdRzyLJvHGiRK4q4d2fiedfTA0tQvK 6g01uat2W5EOOCoDql8Q1Jpo5BqYfYGxUO97CTOyang8PaHiOz6YzIoMstXPbiUHgAuz AF6w== 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=0nRxVz0Tz30cjvXMeYztWae2hdLtVm4GWG5AnsWwh9o=; b=hP/x5n0sO0ipvzskhWi90BvnRAqTT27bfjL/mvMnLTc3Dg2UOzP0R0akY8SVR7S1pk AZHodOP3Yr0Xo7Im5CEiTYek03K3iJgao8kxwn26YqQx8hdvCpLYpsPs2AH0Sg1h4b8b 0yP3SeW98uBVd3tKkjFeJ2CRXfKtdhOml8hYUbOKMYRBfZunGL120OG2PL1R7gy5BgLq uEva5juM26a7eJMdIpThqbYJz+nuWdjNPBMQjDI+SK4toEzOu0z7naKFzBwIEsBxyQVy eUsj+dpRQ428KTzH95YpAImCVXAL9mFXYKlv9tEU4ETpNHwWplEIkg7TFJP5ClnPsvfp WzKA== X-Gm-Message-State: AOAM533ou3vdKI/vgkXs30C4K4uKUVhWUHuxZz3P9SVPXFemI0y5H8xe UjtWKT+3p9qA5CT/ZSXSfnk= X-Google-Smtp-Source: ABdhPJxZxaWwQYEORNOgkUWk+iNUbo0rhFHvJ3rFEVel+iotEuGDoB8UiwWcBiY6b+sE0Bav5PThXw== X-Received: by 2002:a63:1160:: with SMTP id 32mr4509278pgr.441.1589472149580; Thu, 14 May 2020 09:02:29 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:02:28 -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: [PATCH v6 04/14] videobuf2: add V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Fri, 15 May 2020 01:01:43 +0900 Message-Id: <20200514160153.3646-5-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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_MMAP_CACHE_HINTS when queue supports user-space cache management hints. Note, however, that MMAP_CACHE_HINTS capability only valid when the queue is used for memory MMAP-ed streaming I/O. Signed-off-by: Sergey Senozhatsky --- .../userspace-api/media/v4l/buffer.rst | 40 ++++++++++++++++++- .../media/v4l/vidioc-reqbufs.rst | 10 +++++ .../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..5088393b5a5c 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 is used for :ref:`memory mapping ` streaming I/O and + reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_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 is used for :ref:`memory mapping ` + streaming I/O and reports :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS + ` capability. * .. _`V4L2-BUF-FLAG-M2M-HOLD-CAPTURE-BUF`: - ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` @@ -681,6 +687,36 @@ 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_MMAP_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 b6d52083707b..96a59793d857 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-MMAP-CACHE-HINTS: .. cssclass:: longtable @@ -156,6 +157,15 @@ 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_MMAP_CACHE_HINTS`` + - 0x00000040 + - This capability is set by the driver to indicate that the queue supports + cache and memory management hints. However, it's only valid when the + queue is used for :ref:`memory mapping ` streaming I/O. 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..e4b4354b42b8 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_MMAP_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 c3a1cf1c507f..34ba1017b89b 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 { /* @@ -954,6 +956,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_MMAP_CACHE_HINTS (1 << 6) /** * struct v4l2_plane - plane info for multi-planar buffers From patchwork Thu May 14 16:01:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE24FC433E2 for ; Thu, 14 May 2020 16:02:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E287206D8 for ; Thu, 14 May 2020 16:02:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MBJye/eg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728052AbgENQCl (ORCPT ); Thu, 14 May 2020 12:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQCk (ORCPT ); Thu, 14 May 2020 12:02:40 -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 A4B2FC061A0C; Thu, 14 May 2020 09:02:40 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id n18so1503156pfa.2; Thu, 14 May 2020 09:02: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=/nDwNvXr4FS6HqLEsFTMtUWrI4iLPFgT1txuDcLdyIs=; b=MBJye/egwR6TxGrbtL0w/Q4nb5bnV4gLNqPzm/2vbO1WM9hA3pTewxdbboZSYN+aO6 oFqjfW4XgVVK3FkOSfBSZfsCg6ELdGhCuGVHnc6ha3iEIerTE04xtCQiUfEQMRcDxY3s ZwJT4wyLkLdAg2Y0/tezBeH6xhM7rmT07kDowv9NxCEx/cyQBp8EWWK6xnWw/RyLBXhS BVm/0NsH/HjxUgOiDle6lojI4uxOXIsTpkC+yfuJeH+0ojrjMUWaMjK2gZv47FNzdPMw yYw+UHRLBE/dN4jvzHMeFRiuM/R1ddDlBgj7v3HpLNVqdM49mWfeFeze69G78SnchiHi b+hQ== 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=/nDwNvXr4FS6HqLEsFTMtUWrI4iLPFgT1txuDcLdyIs=; b=HaJ+kSk9PHbJTWplholcgibpyyo/aPT4DwfJjtbFwdF3GdJVD4+Bmz1ETc6KE9ct62 IAZ19fZ7bJUVR/M2fq2gMmCaE88n4guUsoNZ96faUUhu+LvD9fnEtJ0yt41yGoatxksz gvbKrinE/sEogInKvSZd3IqnHtaD01HgB/E6CbSZWH18NlcXw3f4O43sO0XLrqO3S2uw Z4hXHOq2bFCyX+xBX1axvk25M8TK3p+dzy5hHC30SXIJ86WdkUN78HUNx8Jgh4oYe82t IWiMvcmZm2jIran0entTcWxc9Ds+R1/8rZeX3UpzieZmrYORv1xM9olUhtf5rIfhRXnl j5cw== X-Gm-Message-State: AOAM531thfpTGRhPVhkhwaEs5KPdFS4L/lw7NXYtw3nZkRQTe1kdiCOa 0EbnTqeDDACZSpGF+habSDo= X-Google-Smtp-Source: ABdhPJy9V7+BBnL1yo2cmrr5jKObiD1Fls7tfCvJ8hi9EaEnNuM3iD9psR/hqlXAircY1GqwTkNI+Q== X-Received: by 2002:a63:f242:: with SMTP id d2mr923438pgk.212.1589472159758; Thu, 14 May 2020 09:02:39 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:02:38 -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: [PATCH v6 06/14] videobuf2: handle V4L2_FLAG_MEMORY_NON_CONSISTENT flag Date: Fri, 15 May 2020 01:01:45 +0900 Message-Id: <20200514160153.3646-7-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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 | 24 +++++++++++++++---- drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 10 ++++++-- drivers/media/v4l2-core/v4l2-ioctl.c | 5 +--- include/uapi/linux/videodev2.h | 11 +++++++-- 7 files changed, 59 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 e1afc5b504c2..f2a702870fad 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 96a59793d857..75d894d9c36c 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 b1332f7f1aad..6efac531006f 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 26a3ec333bb7..559a229cac41 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -718,12 +718,22 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) #endif } +static void clear_consistency_attr(struct vb2_queue *q, + int memory, + unsigned int *flags) +{ + if (!q->allow_cache_hints || memory != V4L2_MEMORY_MMAP) + *flags &= ~V4L2_FLAG_MEMORY_NON_CONSISTENT; +} + 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); + clear_consistency_attr(q, req->memory, &req->flags); + return ret ? ret : vb2_core_reqbufs(q, req->memory, + req->flags, &req->count); } EXPORT_SYMBOL_GPL(vb2_reqbufs); @@ -755,6 +765,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) unsigned i; fill_buf_caps(q, &create->capabilities); + clear_consistency_attr(q, create->memory, &create->flags); create->index = q->num_buffers; if (create->count == 0) return ret != -EBUSY ? ret : 0; @@ -797,8 +808,11 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) for (i = 0; i < requested_planes; i++) if (requested_sizes[i] == 0) return -EINVAL; - return ret ? ret : vb2_core_create_bufs(q, create->memory, 0, - &create->count, requested_planes, requested_sizes); + return ret ? ret : vb2_core_create_bufs(q, create->memory, + create->flags, + &create->count, + requested_planes, + requested_sizes); } EXPORT_SYMBOL_GPL(vb2_create_bufs); @@ -969,11 +983,12 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type); fill_buf_caps(vdev->queue, &p->capabilities); + clear_consistency_attr(vdev->queue, p->memory, &p->flags); if (res) 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); /* 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) @@ -991,6 +1006,7 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv, p->index = vdev->queue->num_buffers; fill_buf_caps(vdev->queue, &p->capabilities); + clear_consistency_attr(vdev->queue, p->memory, &p->flags); /* * If count == 0, then just check if memory and type are valid. * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0. diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c index a99e82ec9ab6..593bcf6c3735 100644 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c @@ -246,6 +246,9 @@ 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 unless the + * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability and + * configured for MMAP streaming I/O). * @reserved: future extensions */ struct v4l2_create_buffers32 { @@ -254,7 +257,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 +359,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 +422,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 2322f08a98be..02bfef0da76d 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -2038,9 +2038,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); } @@ -2080,7 +2077,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 34ba1017b89b..fec2607a07e3 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -946,7 +946,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 */ @@ -2450,6 +2453,9 @@ 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 unless the + * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability + * and configured for MMAP streaming I/O). * @reserved: future extensions */ struct v4l2_create_buffers { @@ -2458,7 +2464,8 @@ struct v4l2_create_buffers { __u32 memory; struct v4l2_format format; __u32 capabilities; - __u32 reserved[7]; + __u32 flags; + __u32 reserved[6]; }; /* From patchwork Thu May 14 16:01:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D68DCC433DF for ; Thu, 14 May 2020 16:02:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B369520675 for ; Thu, 14 May 2020 16:02:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c/t5Jl5g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728079AbgENQCx (ORCPT ); Thu, 14 May 2020 12:02:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQCw (ORCPT ); Thu, 14 May 2020 12:02:52 -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 1272BC061A0C; Thu, 14 May 2020 09:02:52 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id x77so1506225pfc.0; Thu, 14 May 2020 09:02: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=ulQxFo56i5vrppKta1ls/Sq8Rcp1nNk3Qy4EKXx/4ww=; b=c/t5Jl5g8lFXZfuf3nZbC7oQlaQmgFg+60o70eSocAWJDtUwnnPLceyXl99RzpngpU N+5Huu3ue9Cn5K8aZasUtgPD48FUYqbStmxv2xOe3ICBJbl4xMor+xyzh+a3WmO95FDB S/mAMlWecrOVzR5bkP3HDtJLCdyAlNCpGFDFyh/SWbD+V3Gx5t0qfyY9EOkzZwfTKJ0c N/mbVOc6rQV8bw1fkaXkVFGOFUs79LBTAk53SqoFJ1gYlQQSB2nOzeS17RBDkiVdS/oL ZaoBejnJtVUZ7UY1juL/GxmtAx6H1SKTDvnOW+GUHI9f+NvpfXEkMFmjpihaeKEfgN6D Wjag== 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=ulQxFo56i5vrppKta1ls/Sq8Rcp1nNk3Qy4EKXx/4ww=; b=MufwnQkXOXL063uBOrTnrl/tbBfs2vNB0YRUKEJqxQFrBvAAMr2GxcHKGTCaUOeVZ4 AHzLM+Nwbb/bBM5frAzx/s+csrHorqCrt8aheyt8D7h+tjr9UsR5Fj9ZRV6zjwmWWWBU jdhgsYPPjBPtBouMr3e9tnbAqjGcop7Q5mta7fjwk4+bMwItik81GjCrbTEduA/KGjxQ lYxC5M0FQuDNSgSdulBRsV30RYQxkyRbHyLKa8L4z6f3iiBiahqvET24G6yOM1ul7GaE TA+PctRJ7kMs5nNjqXHDi1uuLrvbL+kG/6JBCrGo/huKp9I/HorqayHPyYUeGKSuIqKW J3tA== X-Gm-Message-State: AOAM5332NkeTATQ0KTdASVYOpZxvMl+P0MpyNbx653SETr0FJYx7ubRi 38AXEG/uImrawiBmvvBv3rKMihIb X-Google-Smtp-Source: ABdhPJx2V94Ocgq4TiFRizz86wbf/g4JGYFoXw26J8PS9HBwBYEgB1KY/9epKLPTDzYHQw556wTEfA== X-Received: by 2002:a65:468f:: with SMTP id h15mr4420789pgr.452.1589472171546; Thu, 14 May 2020 09:02:51 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.02.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:02:49 -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: [PATCH v6 08/14] videobuf2: do not sync caches when we are allowed not to Date: Fri, 15 May 2020 01:01:47 +0900 Message-Id: <20200514160153.3646-9-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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 6a95663afcd1..1a55ea19160b 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 Thu May 14 16:01:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A3E3C433E1 for ; Thu, 14 May 2020 16:03:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75D9E2065F for ; Thu, 14 May 2020 16:03:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JJgTIpa1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728128AbgENQDE (ORCPT ); Thu, 14 May 2020 12:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQDD (ORCPT ); Thu, 14 May 2020 12:03:03 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C98BC061A0C; Thu, 14 May 2020 09:03:03 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id g11so1336354plp.1; Thu, 14 May 2020 09:03:03 -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=JJgTIpa177G1g0t2/Mq1+zCRWT3dT37LodLd6/zM4GFuX6pTfFPVPtBDD+yF+0ALE7 dQxBugaoZ4Yc2Pd70QxPBt0ZRtdT74syniIbcU/7bcE63Uu/nEc/iiYVtLhk82A1ZVGp gbcL7TiWO6L0e29O68eJxMzcJx+kSMyXkkB3/PIXs8hSpLVd9HmiCeT6HFB7813rILVY uY1/cs8w4t1IOOFKsEAbb2meO7vWxn9PLXnBFWMffGleCfCbXkuskC7cfTYbAGxd6jnF tM+jJqrJRBajXFFR/LgaX5ULbCl8tBqUi4h0jMDmMCv1rWxPy0+xelcTsKuDauiFYDxt fYTw== 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=knmmsgJwF7MNf1s1OvDAqa0JxJWf88YezkTBCx/sgY8kN1f+rOJfvKepjU0exjNfLn ek51rAhLxsMgJk0U3tPCIKbxbyTkP2so7fQTVJiehujgoqnUJjpSbZGbhNnDpwDeh7+k obNV+sYPGxSQeppiu1ypwN+sF5jGDnCkFlMxFzYP7F05B2kX38lm80XU2IhGmBlAlnkU 9qbeCh9hNY6/lvlhrHsB87AevTDrE9BoCbwfzuWZ6nuwGIDZ99txP3ETbktzPFxkXEFk ZsXMVanuwt0z1Sw+jAoue8RmSLdVteN8f1zfHeZPTHZeQpLS4NGrlbsYY0zuwuftl7zO A5ow== X-Gm-Message-State: AGi0PuagHjPVNF9SriXhY/A2IWvcuTPppXgDl6bG0S/wGLyi8Cg8rlya q8vEB1LndX9xMJTRc0wXmPQ= X-Google-Smtp-Source: APiQypIdGN05I3fIGd1VSS2ERkqZM4A/HXsk1rzePBoHHvXonMX/GsFAVkm7EYF3JLyGqyplReEB8Q== X-Received: by 2002:a17:90a:7349:: with SMTP id j9mr42272939pjs.196.1589472182286; Thu, 14 May 2020 09:03:02 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:03:01 -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: [PATCH v6 10/14] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Fri, 15 May 2020 01:01:49 +0900 Message-Id: <20200514160153.3646-11-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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 Thu May 14 16:01:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0661C433E0 for ; Thu, 14 May 2020 16:03:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76CA820675 for ; Thu, 14 May 2020 16:03:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gwQOAWBj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728163AbgENQDM (ORCPT ); Thu, 14 May 2020 12:03:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQDM (ORCPT ); Thu, 14 May 2020 12:03:12 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43AE6C061A0C; Thu, 14 May 2020 09:03:12 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id k19so1320118pll.9; Thu, 14 May 2020 09:03:12 -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=gwQOAWBjWWnG2AqH5DTjNJpsC6zUy3MFzX7R/HV+gqZ9Mw6EKB0u6NVJpejG2oE4Jl AJ4JPtAdTbIpeXZweRWqujYuIzYPVuqgwyQQxpqg3LNZZ171mZ8MF6Gx2SxPW+QPP2YS dd/g3geG39A1JSj7LvHDyNzdY2/d2pOIa0GqCbnYAJk2/ueKmllM1gNUDr0fkIkpYq5A RKqRoXX4XxWMjXCZ4FX/mTpNMdm+FmxO+Qz4gbQC+WlQqh+Nd0TGgS9WYVXXbWAePP85 /nJt3ACtsBic2NPoodwQK8m7WhzOf3RAls4vUtEumomGpjt3xJjmHQSuxfhR0UNEZGD5 T5kQ== 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=A1CdOF4v1PayP/Vis+ROAVKv9BrXy+zV1Tb+ZBlen2p/7Y7tCcmNAToLZRNit0noTl fOzK6C8wd83ffuDVF8rIfDnACozOOTHyjcmkgBjyLisXjOqT0xpUFGZzSmeE5kQIHmbf h6Yvk3udgLP2a2NlB2KQqEp+fqX8J1lXA7uS9wyfE30bKFn0sUhX3oeA7QG4R92zmXrc bDtZ0HsZkE1nMoY4c1bPoOHoka4NrUbFK4TlWsm3G/y346dslbx3HgnElcluZeejGn/P YGeRtPHodLpTk/DndLdviAO4/JYGAOv0cZ2MlA/aayFKZhnTgzoUcsDvdsBL5SnJat4U BT3A== X-Gm-Message-State: AGi0PuaEpembtH+OfrM4E/WfCdToKynHkBRj32Pw+wdr7A7T4Zc0xc6y MmMmjBkTCQV3MVIQMT0qUWs= X-Google-Smtp-Source: APiQypKtjDTYx4RCQAAj+mPgWBCzKNKzVXPOLmvMs9pUol75XZj27dlRosSZjo7iYkZI2ClGqel5bg== X-Received: by 2002:a17:90b:234e:: with SMTP id ms14mr41042651pjb.212.1589472191667; Thu, 14 May 2020 09:03:11 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:03:11 -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: [PATCH v6 12/14] videobuf2: don't test db_attach in dma-contig prepare and finish Date: Fri, 15 May 2020 01:01:51 +0900 Message-Id: <20200514160153.3646-13-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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 Thu May 14 16:01:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 209813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AF85C433DF for ; Thu, 14 May 2020 16:03:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 792D420727 for ; Thu, 14 May 2020 16:03:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a3sxaPR6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728201AbgENQDW (ORCPT ); Thu, 14 May 2020 12:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQDV (ORCPT ); Thu, 14 May 2020 12:03:21 -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 1A1E1C061A0C; Thu, 14 May 2020 09:03:21 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id u5so1423002pgn.5; Thu, 14 May 2020 09:03: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=0+vgRUi2Cw6OQUIzVG2SQIiqB95rjj/yXNRfFtp+ZZQ=; b=a3sxaPR6bZoBkYvsbXEEqvNMgq9czEdqOb/JwY6+1C7HJ+bw7FFbu9t7mSJ409L+kE tTbWX82kuQn674VDPeyT4NqEFtzpo83hrc2W5qugwKE4ET6mWcnty+5fIBm5n1syZXzI 0HLNgB7uFsbVcTmz7BbEr1qEF3IMROfcXYvLbcTzajjtIniLoBkvT7x/lHVm+SvYkCXD VhqdRpGNgW42MtinKI3Lh5gK1IMYZ8C9EEULuPpdpzz4JtirccqAheMHaCm9n0Iss2IY fJ2Ct/yxJ+GyqObaQD5eLgSwqZV25PcAGaGyFXm8O9MjgLzrkOI9IX5BdBysw5o/Wknx n+wQ== 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=0+vgRUi2Cw6OQUIzVG2SQIiqB95rjj/yXNRfFtp+ZZQ=; b=keFFG1rAgROwa4C7iLiP7i/mzKA9tA4DtMlgxlrb8cF1HIUbZ5Nu86Ds5mP1wn24GB CTrVCaQmd9IX9oPvFw9i6R4OPOSiLsjONKojxncZfLYoeJ8oDHVMYW1rbqOsAMhmq2C6 yKlPwjho/DEaekQuH1YHfPqZnEvE1uXMMqZ6DyxX4901D4qZnq6FM2pg88vNohmf+VBo 9EeR+AzRiNHODvzzw5hUXrWZRyz070vsBQJcx/w/vXLoRIUHGpn7Gsw82RxLNP1kpLu2 Kqynyd+ZMny137O4icImqmnvc0zeqA7dG6xPnHHVmZD5Qhie1/OAb/EWr6ul71Y/h5cU PC7A== X-Gm-Message-State: AOAM533XsWhxAVDez8PV3kpcKqoDoOx/EZUat4+hDs4XedvNmlD99lmv n+gnxa78WTexJUVVKfBWIhY= X-Google-Smtp-Source: ABdhPJxS1tydaOlU0q18OhkSEwfnyWX7EesrdokZbnrifiBg3PN6dwqQZBzpXF7MTJFRRAzwqcfbeQ== X-Received: by 2002:a62:1b87:: with SMTP id b129mr5031639pfb.162.1589472200343; Thu, 14 May 2020 09:03:20 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:03:19 -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: [PATCH v6 14/14] media: vivid: add cache_hints module param Date: Fri, 15 May 2020 01:01:53 +0900 Message-Id: <20200514160153.3646-15-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-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 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 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/admin-guide/media/vivid.rst b/Documentation/admin-guide/media/vivid.rst index 52e57b773f07..6d7175f96f74 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: + + specifies if the device should set queues' user-space cache and memory + consistency hint capability (V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS). + The hints are valid only when using MMAP streaming I/O. Default is 0. + + - 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..5c986df4a8d4 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; + q->allow_cache_hints = (cache_hints[dev->inst] == 1); return vb2_queue_init(q); }