Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4435707ybl; Mon, 3 Feb 2020 19:00:04 -0800 (PST) X-Google-Smtp-Source: APXvYqzVFmEqfN0NEm0HFFIy/BcZr7yKGo8wJ/dxtFyVEoxEGhkYnb0+27XPleNUI73EGC916svx X-Received: by 2002:a9d:75da:: with SMTP id c26mr20667668otl.40.1580785204600; Mon, 03 Feb 2020 19:00:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580785204; cv=none; d=google.com; s=arc-20160816; b=PM8AKq51/Ag8fWcxzozVQ0evVivSJuXI6X03/20mqfBmeTFnf+Qxi48JHtqEaieqWo apHSrdrTUumArnqKMD9t8Iqb5MGWfLAm5cyBAWzcnEGmsiXZ/WUv34KxvmX/YN+DHovH qAMf1URAH0V24DBF7dth7PRVEjSH/ruAO5ePBw95WRnklRtk8y25pqmN7VcQSDNLDIQz 4BjVXz3WpNH4U1/PIiMkKHYohiDJOnR4KqzG1hEyZ+XerNW2GiaWlnt+HBo/uDqpxKZC TgTdZK7GeidEQ5Pvcjpml69pyK9u7nlCcEniA0InE7Or+bSClm0+5LhT/MqYkgma1r0E 08Bw== 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=QggxwG9xXj9/Y8aTLUoH0ga4g8iQi+a/2zxkwKUkbVk=; b=VEIf4WEq3Ky8jaWNsFXAhpEQ4GdhbTswToeOhFDpXfD6vLRpUDUE2ZQUZbQ6uYGFo7 1BO+j0doD79CidVucwu6iuhmKt+T4Ci02m17jNLZMzLYpM3EdOeR88clTAxnDU+QniXG KKrlRA3CH4CnmnDgwiBDzAA8ZWS0XQxZ8D9R72pv7TUuBPb/3FvbOVGjDodJrOpvS0a7 0ClnFDoebxf5lNET4pPLoou5+vlHdRxHYEwVkZBaTKJXgWFoZmCv1NQtTm8wiv7A7pPS ekp0ZRCB3A1gppn9aqtpf/c4syKSPnTLoKXMOGLfXaN93PjAZkAil40GpKihdVNDL91E ldxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XVafVv2F; 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 g6si10581692otk.171.2020.02.03.18.59.52; Mon, 03 Feb 2020 19:00:04 -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=XVafVv2F; 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 S1727337AbgBDC52 (ORCPT + 99 others); Mon, 3 Feb 2020 21:57:28 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38937 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727349AbgBDC5Z (ORCPT ); Mon, 3 Feb 2020 21:57:25 -0500 Received: by mail-pl1-f195.google.com with SMTP id g6so6648026plp.6 for ; Mon, 03 Feb 2020 18:57:25 -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=QggxwG9xXj9/Y8aTLUoH0ga4g8iQi+a/2zxkwKUkbVk=; b=XVafVv2FGd5SwvcOmpasGzgMAcJ0QWnLsWBGTqB9pizESHAispXx4sC7Jb10NDMUYo H2OK7XfQiWozQxXr5Ewhm3UycEJTq0kdAH2QB+8JHzciaEJTVx/sS21Pag1mdLwtNKD0 8z4VHvNvtsFWkqfB5taldMN3QBu50CAZzJQZE= 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=QggxwG9xXj9/Y8aTLUoH0ga4g8iQi+a/2zxkwKUkbVk=; b=LaSg3vrbpPJmZ1AptjMqfne4Pox00jfX1ssL+7F8+ixNM5jmjE7M0zptDZkHygqLfN bvoa0sLbLXCKaOcud7mISLwiquEE9deWqcsFZJcXYlUqTUtxoY23K3nJv2X9ZDMJgkqH 4DLdLggWHsbctsAnA6I/cz7kw0bnj8fO1c5onPNRDEQHs2up8ftlo99sXqUSatFlr0Mc +TVgLGkaWRe+4p21ukbSRlIr0VJ880QkM9gtR6BhcNSvFc2iPKF5nu4LxKuztZOk+S7L yf57L0eaDc0rz1RodvfPcyiNljmUBs9wFsimWAY0Yp3p/v0ibm14nJH2z11JAkRdJfZx XE8Q== X-Gm-Message-State: APjAAAXIWxJG2DTNEKK8X/oHBQG+n3lxRAuCcbtL9n/6tAScwCVwLp9w ByUcK9dq4cQ5TANp8A8nHUq0Ow== X-Received: by 2002:a17:902:8d94:: with SMTP id v20mr17785871plo.259.1580785044745; Mon, 03 Feb 2020 18:57:24 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5bbb:c872:f2b1:f53b]) by smtp.gmail.com with ESMTPSA id e1sm22491971pfl.98.2020.02.03.18.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:24 -0800 (PST) From: Sergey Senozhatsky To: Hans Verkuil , Tomasz Figa , Mauro Carvalho Chehab , Kyungmin Park , Marek Szyprowski Cc: Sakari Ailus , Laurent Pinchart , Pawel Osciak , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC][PATCHv2 10/12] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Tue, 4 Feb 2020 11:56:39 +0900 Message-Id: <20200204025641.218376-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200204025641.218376-1-senozhatsky@chromium.org> References: <20200204025641.218376-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. Change-Id: I653ee20302014920b4705f3eba27c0b1232ab89d 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.341.g760bfbb309-goog