Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1865553ybf; Sun, 1 Mar 2020 20:14:51 -0800 (PST) X-Google-Smtp-Source: APXvYqzIOMp0u/fglLkaU4BZyYzCWfwMHiRLRGjIFXKRKeiuiPGejfj0nrfm4xMofHgGLLJ2w9wU X-Received: by 2002:a9d:6655:: with SMTP id q21mr6123498otm.70.1583122491792; Sun, 01 Mar 2020 20:14:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583122491; cv=none; d=google.com; s=arc-20160816; b=DsfLycU8wD6vi3gw38mxLkzkSLzq6wfi12plX9z9EkP8iaVh/eJcJ30WSMnDv3bYNu n/USmhL9VQ2JfCsO+Ay2S5c75++mexeK2nQfk/gNezCO7h+tbGZJSO1NigVC4HuFYlY0 Ut5y/vRWKHpQIkSF+quY2cS+2zB1Lbhdb/uB3HeP95o/O3tajR22B+DXZLjUyPMmGi3b aNMBWMr8oBNhb1gWrKZk+CVLzAJeqjMe1S7uGT3nz5VtP9raSbqEPae3rEBKkflvXrBB v6WRTnrrxjMC5NeQ0vFeLuCBhVJSYlSLXnr9rL5YJrD6j0g4a3e3MY3OHFLyryicychb JDgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JCmxjKYr6h+HQkJ8I2sAt9HA3Gj5LCEzRtahfHgdo0A=; b=zQAMfdQmKjOlGkEr+ufLImOV5PYIe5M1LXo7J2FSQQO7TqjG5XXeK9GJboHBR3xu41 7XKFpXJTJNioDTDUi6hiGCGZBDJkyzMsD1alhUW5UCR6yezrt7RByVEI4flQZqKW0BVr gFZjreME/7Cxc+17ZEljWySQ5y6gufO2VyqtEjQWlTiiOHkYy7VAtliFEjZDJ9v2RVBb w5k2E9YJ2r2VxY7tKjVgeifcmowLfF3eqlLp5nDGfuRV/7o0mxxPzxvw4+i/NJRx8wZy 0t8On9g3xlwl3m/SF1g76K9eUV1wxUcqf1YrZjnVTPJPw0lx8yPfSKV1hdOrhaSkt56g y2HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dvSjq7Zw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 24si5303651oiq.162.2020.03.01.20.14.40; Sun, 01 Mar 2020 20:14:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dvSjq7Zw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbgCBENQ (ORCPT + 99 others); Sun, 1 Mar 2020 23:13:16 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:33915 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgCBENP (ORCPT ); Sun, 1 Mar 2020 23:13:15 -0500 Received: by mail-pj1-f66.google.com with SMTP id f2so5526500pjq.1 for ; Sun, 01 Mar 2020 20:13:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JCmxjKYr6h+HQkJ8I2sAt9HA3Gj5LCEzRtahfHgdo0A=; b=dvSjq7Zw/Qc5F8sFmiaMtJkkUXhJhepVHY2UABgyeaMKBuNgDzwVtU68FnJijUdrMQ WmBiIWa7qp+6yC1mTg+ZFE0LqEybSHbuC+TOmGZ83GdhiFOvOuowkiKC+eXkPH2v1zsk q8K9wZwejOY3M98hsOW8Y8SVJxtMyMRXvnokE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JCmxjKYr6h+HQkJ8I2sAt9HA3Gj5LCEzRtahfHgdo0A=; b=fYIL4/C39n4VcEqA4LKQDoXaiJeF+JaflUaj26DaVMk9hNpHuZwQg6yFs3XRwsC8XP bMU7RZqFe9iLYmxbvo9qEmDE2MNQIx9fvupueMGK9TnfK+WfY7A404U6ux8bGpf4xbHK yelzAvvfHLNIlp345sA4iV1PAI43QGwjZdhUqB7R71xnl8wYV/6a25zZ6IsfT/K7y5zX ddWxXh7r4QIS4YWmJ7vViJeFoQyFMGpNxYdIvTempyoR59fsiy93fXjL/pIXJyq4SKkz AaDUxYVnTYcUs/wU/sZdzaT4Ci0B/q3lIZgv2/YECs7N6viyoleDG4L6EzUqmnfqRemX SJlg== X-Gm-Message-State: APjAAAUpmv63EF4ncioDswLcySl6x1tK0/2L959h5RB+wmQO7ZkzYPJV 7JAgnxUbXbbDAz4SXTza9YzUjQ== X-Received: by 2002:a17:90a:c301:: with SMTP id g1mr18799146pjt.88.1583122394164; Sun, 01 Mar 2020 20:13:14 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id d82sm1698114pfd.187.2020.03.01.20.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:13 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa Cc: Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski , Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv4 09/11] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Mon, 2 Mar 2020 13:12:11 +0900 Message-Id: <20200302041213.27662-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200302041213.27662-1-senozhatsky@chromium.org> References: <20200302041213.27662-1-senozhatsky@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide begin_cpu_access() and end_cpu_access() callbacks for cache synchronisation on exported buffers. The patch also adds a new helper function - vb2_dc_buffer_consistent(), which returns true is if the buffer is consistent (DMA_ATTR_NON_CONSISTENT bit cleared), so then we don't need to sync anything. Signed-off-by: Sergey Senozhatsky --- .../common/videobuf2/videobuf2-dma-contig.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c index d0c9dffe49e5..a387260fb321 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c @@ -42,6 +42,11 @@ struct vb2_dc_buf { struct dma_buf_attachment *db_attach; }; +static inline bool vb2_dc_buffer_consistent(unsigned long attr) +{ + return !(attr & DMA_ATTR_NON_CONSISTENT); +} + /*********************************************/ /* scatterlist table functions */ /*********************************************/ @@ -335,6 +340,32 @@ static void vb2_dc_dmabuf_ops_release(struct dma_buf *dbuf) vb2_dc_put(dbuf->priv); } +static int vb2_dc_dmabuf_ops_begin_cpu_access(struct dma_buf *dbuf, + enum dma_data_direction direction) +{ + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (vb2_dc_buffer_consistent(buf->attrs)) + return 0; + + dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + return 0; +} + +static int vb2_dc_dmabuf_ops_end_cpu_access(struct dma_buf *dbuf, + enum dma_data_direction direction) +{ + struct vb2_dc_buf *buf = dbuf->priv; + struct sg_table *sgt = buf->dma_sgt; + + if (vb2_dc_buffer_consistent(buf->attrs)) + return 0; + + dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir); + return 0; +} + static void *vb2_dc_dmabuf_ops_vmap(struct dma_buf *dbuf) { struct vb2_dc_buf *buf = dbuf->priv; @@ -353,6 +384,8 @@ static const struct dma_buf_ops vb2_dc_dmabuf_ops = { .detach = vb2_dc_dmabuf_ops_detach, .map_dma_buf = vb2_dc_dmabuf_ops_map, .unmap_dma_buf = vb2_dc_dmabuf_ops_unmap, + .begin_cpu_access = vb2_dc_dmabuf_ops_begin_cpu_access, + .end_cpu_access = vb2_dc_dmabuf_ops_end_cpu_access, .vmap = vb2_dc_dmabuf_ops_vmap, .mmap = vb2_dc_dmabuf_ops_mmap, .release = vb2_dc_dmabuf_ops_release, -- 2.25.0.265.gbab2e86ba0-goog