From patchwork Tue Mar 2 00:46:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 12111991 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 54EFAC433DB for ; Tue, 2 Mar 2021 17:32:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF71F64F17 for ; Tue, 2 Mar 2021 17:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383367AbhCBR24 (ORCPT ); Tue, 2 Mar 2021 12:28:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377607AbhCBAsA (ORCPT ); Mon, 1 Mar 2021 19:48:00 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0D17C061797 for ; Mon, 1 Mar 2021 16:46:49 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id l2so12755127pgb.1 for ; Mon, 01 Mar 2021 16:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GnDeRO/j1w/QVZkAmF6agz16S+YCeHvomLKLisDrprM=; b=e3Hr0D9Bgpw78YXJMQ4cGP3DQgtrHpZRiU6/C7m6yXuAueAU2Isj/EcCGyOCmnbtFZ Oh9kq13F2My4mq03JPZBlYPvlnD7g+BSDfUFMPhdfm9efwUxf5eG509fBVDwwtbxyKFY oWGqbkF1+zJBLetNbSfGyQwQo0ACaJ4JSv5VU= 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=GnDeRO/j1w/QVZkAmF6agz16S+YCeHvomLKLisDrprM=; b=lic/KRWYo4ssFhKZaH4y6oJmMlbzMA66st4uQrFRoHTAmBaQOn2IE/Hv7FcNhxziNw ztULmnkUSyStETAjJmbTjYWpXSC+iuvky+X4ae9Vdzy+Ad+UdbdgqoOLmL0siDAk3O8q 30FuTPYxiGct6V0cJWxmhaQP6zhoiUsT9i+Ek2IuffBAM7mu/RvqdZbJMU3Kv3n2sS5W fyaXHmT1lWuVzZt0BhYCfUL9wrAsADSfCATTfVTLq4uc+jo2nNJ8VgLi4E2okcf2U/Le izapQPaqA7iELleFjCELuZk88R/Q8q7CeDr8sIWKVKmQ2qwg7DnXZFb/8SILgizv09JA qt9g== X-Gm-Message-State: AOAM531yO+v6CuGFvTL1ByZ+NycQkKUxwotEWFlm0n1O140QU+wz9RQc EHn/tfT+MDH+hovvdYqSDChSag== X-Google-Smtp-Source: ABdhPJwIcjHnXAgUKtCwUPPIrPjv83wOcpxlxkHeDkqQPTDh7JRCwjEjgT3iulEHADYFdxy4K4GBlg== X-Received: by 2002:a63:5557:: with SMTP id f23mr16013439pgm.242.1614646009380; Mon, 01 Mar 2021 16:46:49 -0800 (PST) Received: from senozhatsky.flets-east.jp ([2409:10:2e40:5100:d5d7:1a61:2cdf:273c]) by smtp.gmail.com with ESMTPSA id b14sm678881pji.14.2021.03.01.16.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 16:46:49 -0800 (PST) From: Sergey Senozhatsky To: Tomasz Figa , Hans Verkuil Cc: Christoph Hellwig , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH 3/8] videobuf2: split buffer cache_hints initialisation Date: Tue, 2 Mar 2021 09:46:19 +0900 Message-Id: <20210302004624.31294-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210302004624.31294-1-senozhatsky@chromium.org> References: <20210302004624.31294-1-senozhatsky@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org V4L2 is not the perfect place to manage vb2 buffer cache hints. It works for V4L2 users, but there are backends that use vb2 core and don't use V4L2. Factor buffer cache hints init and call it when we allocate vb2 buffer. Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-core.c | 22 +++++++++++++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 18 --------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 23e41fec9880..76210c006958 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -382,6 +382,27 @@ static void __setup_offsets(struct vb2_buffer *vb) } } +static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) +{ + /* + * 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->skip_cache_sync_on_finish = 1; + vb->skip_cache_sync_on_prepare = 1; + return; + } + + /* + * ->finish() cache sync can be avoided when queue direction is + * TO_DEVICE. + */ + if (q->dma_dir == DMA_TO_DEVICE) + vb->skip_cache_sync_on_finish = 1; +} + /* * __vb2_queue_alloc() - allocate videobuf buffer structures and (for MMAP type) * video buffer memory for all buffers/planes on the queue and initializes the @@ -415,6 +436,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, vb->index = q->num_buffers + buffer; vb->type = q->type; vb->memory = memory; + init_buffer_cache_hints(q, vb); for (plane = 0; plane < num_planes; ++plane) { vb->planes[plane].length = plane_sizes[plane]; vb->planes[plane].min_length = plane_sizes[plane]; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index db93678860bd..a02f365bbe60 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -345,17 +345,6 @@ 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->skip_cache_sync_on_finish = 1; - vb->skip_cache_sync_on_prepare = 1; - return; - } - if (!vb2_queue_allows_cache_hints(q)) { /* * Clear buffer cache flags if queue does not support user @@ -367,13 +356,6 @@ static void set_buffer_cache_hints(struct vb2_queue *q, return; } - /* - * ->finish() cache sync can be avoided when queue direction is - * TO_DEVICE. - */ - if (q->dma_dir == DMA_TO_DEVICE) - vb->skip_cache_sync_on_finish = 1; - if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE) vb->skip_cache_sync_on_finish = 1;