Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1865136ybf; Sun, 1 Mar 2020 20:14:14 -0800 (PST) X-Google-Smtp-Source: ADFU+vuWNHWQhBEMqSECSaEzC7dA4FtayAkphGyJZlNclkhmK4r3tOFBZCJU9ShR6u7iry1pkvB5 X-Received: by 2002:a9d:4d8f:: with SMTP id u15mr4137748otk.261.1583122454379; Sun, 01 Mar 2020 20:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583122454; cv=none; d=google.com; s=arc-20160816; b=Ty9pD6LkWUJg12/UXr4/bXEeLotO+YmcC0L2Vrz9KKCDchMSUyYaNbbgG1ZitSewAK eJ85k1GSrGmwHCW36t5dmsimiEOdhVOPuEj+kAuiAY6ju8KIOR2wWUK0r4PHTAhC7ca2 pa3amNG5YKabSoBkULT/oOSXy/4bDANIslCzJz9eG1j8fHoK5jmMUyGjJKFZ7Nc+ke/B jAgGsq/tG07t5VaJxjE7OHwOJJfHmjF7mTmQyF20q388DiEFTYLaRDntJo1wWs1TLQ03 +wxwLhwxFj2bsUxgIjZ4p1EA8zJoUvOjWIElXJ88YKtyizVk/WllrF8iUSp0EuLeNGY2 K0Jg== 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=vqnI8gtSZFQZzEwQepw4bYm9gKT2/CP5tzXnaA3LBtQ=; b=dwxAfwi020CEYgWBuRomDJ3dhuEtCvH8Zsu8FVYfcQkMlb27/FBSWK6QY5v3UqgelS 55IIC1Io0beBFcmBH4GIh5Twv4xldZsNugwRzSXOB7h9Qw4T0+EtXh3U+eapOy271/Wt w149ASFnxmKRiPT/iE8zQ4iX1p5a0H6S0zkdB/8DmCZmDYLEKNianNimDw8VQKgTIVPr wUaBIW/kZIA2pZ7hw4sBVtahDazCmAEB0Xs2kWWRPOTEhjqEmcxD++ccCitnZ8q4BXgJ D5Q7NtGwE9gYGw2GxRCBacp1aMmSJrrU1psGUyM+MZ7A9QpVqeexCDdXSJ2q5t6VgkHA J/Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h+hb2CDB; 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 y24si5752104oih.24.2020.03.01.20.14.02; Sun, 01 Mar 2020 20:14:14 -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=h+hb2CDB; 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 S1727276AbgCBENU (ORCPT + 99 others); Sun, 1 Mar 2020 23:13:20 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:38408 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727194AbgCBENU (ORCPT ); Sun, 1 Mar 2020 23:13:20 -0500 Received: by mail-pl1-f196.google.com with SMTP id p7so3663278pli.5 for ; Sun, 01 Mar 2020 20:13:19 -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=vqnI8gtSZFQZzEwQepw4bYm9gKT2/CP5tzXnaA3LBtQ=; b=h+hb2CDBO3It2UCMkrG6UzXN8ZD97LJ2y7IP1ZA7oK9uwPR3WHp/TwSiOUMa49OxJn PAgUXLXDG+kcoQ1a72e4ZpOzvGyAQOsDNGAQi+JCI2CA9mgpy3nNVexqzHZOrEd0q/pf DOy3XfvenMlwx2AtPL/jpZjYDi93yW2odD17k= 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=vqnI8gtSZFQZzEwQepw4bYm9gKT2/CP5tzXnaA3LBtQ=; b=geRKJTiqvB/aKFPxGwFWXyshOCrniEIvA3ZcsIOBXqUb/gqx51OdH+pBlFYfPuGPls pK82nHO/vSQMiLDdE36mXfPLOboKAlq6bPFoZU5HZF5fxUmdCSP+U/Y69eIIbFbAlNKa jT3xBkR3t3SbJLt8ERM9QDy9s5tqkzhmT/7yUyPIG5Va1wYvskiSljCi5maJUE2gIA1l 7HgHn7rj3kfffuvsO4oQVI8mcKrjaB7xCm8O6RgXi5TUSJYpjAiQbArPzpgbycPnffJA ppo5iUNiHWLzDQIxQrnTWL2ozm/HsUAu1A6GeoXrUYKVLjGja3FP/DdeEKLBE6zVUq1G jUAw== X-Gm-Message-State: APjAAAU1KEpHXMOk0/ophmWb7ENtsdwicfoPNf7udSCKTYcSxzR8+JTE e3NSlJdWjQWr6lF47AEVxrHw6A== X-Received: by 2002:a17:90a:664c:: with SMTP id f12mr17907257pjm.61.1583122399076; Sun, 01 Mar 2020 20:13:19 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 20:13:18 -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 10/11] videobuf2: add begin/end cpu_access callbacks to dma-sg Date: Mon, 2 Mar 2020 13:12:12 +0900 Message-Id: <20200302041213.27662-11-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() 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 | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/media/common/videobuf2/videobuf2-dma-sg.c b/drivers/media/common/videobuf2/videobuf2-dma-sg.c index 6db60e9d5183..ddc67c9aaedb 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) @@ -470,6 +476,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 +514,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.265.gbab2e86ba0-goog