Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4434919ybl; Mon, 3 Feb 2020 18:59:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwgSoa4M6efhFX7OLHYaYnZnz3diJGNZQS9fgxtyLwWp9BYazgBfJV3g+088twjYtEFw1sj X-Received: by 2002:a05:6830:1d8b:: with SMTP id y11mr12048428oti.4.1580785140209; Mon, 03 Feb 2020 18:59:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580785140; cv=none; d=google.com; s=arc-20160816; b=PTWTTYqyUyLTdjuStSe3PJkGJ2hqLzgjCHB5FZpo/lqfXGjoCS7BpZGT9QR1apmvIa +QP1UZTfG8s2r9LkG1ToOj115YIwQ+CUl+6SqB12ojRGSYwTAaTWTZu1gKvSmrNG6RjG Ch9VFShrlzDMJ+Ai2ghUhHbH7vdY6P0kOyFtWGek/PLH9MufzTzEQTkQj9xBAH4+GbxF Jg/IJpQtCXDmeuMPet8jMOH2eg394/aAlObZsIvLPZ4w90WA1qufnjCpGAFu9A40J6Bi xXoLPlcjcDFess2nAZ+roZ+AoTZronLu1d8zO0b1pwPHa6hJeDYEYwS2P2c+Ir3PK0tR 7+Bg== 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=8h+I8oxNIcMrbLvsm+8Df46AS8oNWipq59orM6/5OoQ=; b=jg/QDleXLbpSg0sB4VoWdMDpy0l7w2CuITYFM8FBlnYj9U6tg4wkdipoEd4YD3FDjA c5f+z43oQrgA+SUFmlPP5IJiAz8Eup+awsIVb9N2QIOSuL8YrErpV05l+KJQdUTwlqKK AEmJrKYgYJDoeMZBt81kKyqDI+b01YXinr7MJtQYYFnEMknb25YS6EPihdpum8x85ATD tsJc+HTbYOkx5tE5EggzLx/olCoG6QxcEWch6Em1QnxE86r9f3ul7CjBNwDRty3uQvc1 BdZ+N92NxkAPdhQ63VQdk4QzdzDgIHAtzUJLl3h9hT3AGYcy8XliwD4AQNDCuvnNjzt5 0Phw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Qb+Op006; 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 q6si5118421otk.78.2020.02.03.18.58.47; Mon, 03 Feb 2020 18:59:00 -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=Qb+Op006; 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 S1727390AbgBDC5a (ORCPT + 99 others); Mon, 3 Feb 2020 21:57:30 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:32941 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727368AbgBDC53 (ORCPT ); Mon, 3 Feb 2020 21:57:29 -0500 Received: by mail-pg1-f195.google.com with SMTP id 6so8923143pgk.0 for ; Mon, 03 Feb 2020 18:57:28 -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=8h+I8oxNIcMrbLvsm+8Df46AS8oNWipq59orM6/5OoQ=; b=Qb+Op0063itwM7zF2RFmjrsNv3YJmj5LgRFLABUotYSOIhCarSuW8fKd+TFe9XAhyi y1ZRx1+0rv6FfLP0lVijNYckb3zEXXivjrOQaNC4SBXY5Dv0OvJxacxjg90Y2rMqYSk4 JfoBGGHHMGDkDOmZFLdXGlhmgp73izBpnIVP4= 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=8h+I8oxNIcMrbLvsm+8Df46AS8oNWipq59orM6/5OoQ=; b=WabFhHKl+XwmZlheapy+hdgW41sLHffad6zKgCT2J+EsmCo8ViqHXq+nPBueCBWxp5 G6ziwiuoimCcU3mBLfeFLPP4Zjco5q2MUVHKFRrlozmL3dYfo8VsKzecD6G1eTldioxk 6M7q+LCsQixKC3qTZ4HTQo+KCB87+23TCe1Cf6TTz/0vdxhJ+G5Z1Zv0HzUn1MTysG2v lyNxM0E9ml63krM8xIQAS9SDUoTMbSC3evNowvMLd9NlaPT/L6WOslIcuC9uhHK5F/cs kNe2IwDnq/pXZNeHotpIF/K/mrrA1FJQSR7MmcgAH8wQPxote8m634zdz/u75YJN52cP kT+A== X-Gm-Message-State: APjAAAW3uo03PEeQq2tdQb3b7KXOGLKVKLd99REC9yc2GlhCysJY0JJr tg7i6Pxu/4nevsamOtHLsYLGOQ== X-Received: by 2002:a63:f57:: with SMTP id 23mr18739474pgp.46.1580785048241; Mon, 03 Feb 2020 18:57:28 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Feb 2020 18:57:27 -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 11/12] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Tue, 4 Feb 2020 11:56:40 +0900 Message-Id: <20200204025641.218376-12-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() 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. Change-Id: Ia0d9d72a8c2a9fe3264ac148f59201573289ed2c Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-dma-sg.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 6db60e9d5183..bfc99a0cb7b9 100644 --- a/drivers/media/common/videobuf2/videobuf2-dma-sg.c +++ b/drivers/media/common/videobuf2/videobuf2-dma-sg.c @@ -470,6 +470,26 @@ 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; @@ -488,6 +508,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, -- 2.25.0.341.g760bfbb309-goog