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: 210060 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 AE83BC55186 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 8E9E720736 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: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: 210059 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 36836C55186 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 1369520736 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: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: 210058 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 86100C2BA1A 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 5B4AC20736 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: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: 210057 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 A4DCBC55186 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 858E32098B 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: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: 210056 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 D6BD7C55186 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 B589B2084D 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: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: 210055 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 D3FA1C2BA1A 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 B198D2084D 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: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: 210054 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 D6BF9C55196 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 B1A1420767 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]);