From patchwork Tue Dec 17 03:20:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11296469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1351A112B for ; Tue, 17 Dec 2019 03:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E554D2465E for ; Tue, 17 Dec 2019 03:21:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TkZntt8f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727598AbfLQDVX (ORCPT ); Mon, 16 Dec 2019 22:21:23 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44637 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727563AbfLQDVW (ORCPT ); Mon, 16 Dec 2019 22:21:22 -0500 Received: by mail-pl1-f196.google.com with SMTP id az3so5393541plb.11 for ; Mon, 16 Dec 2019 19:21:21 -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=sKpso3dYUpegkM+13TDZVLSc9HejGiHeDBGlLaBiNPU=; b=TkZntt8fEmKw6hceaNO9bkAbi74L8qrJ0OFAzLrKVD5utQiR4HzeU6o/8ucDhZlH6C njwJ21Q3JOKkRMBoXxWeV7/7ldlqmM0rmhMo04rGOIdrl9khww28BnfekRpilL/aLP2C 0FYhDqxL1CKVQmJc7ifSPfMbTo+ybynMjgdK8= 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=sKpso3dYUpegkM+13TDZVLSc9HejGiHeDBGlLaBiNPU=; b=dOnKO+2zYiJxxWjzwCMyl2X5ou651K3QOG+l8OpTQ9W+a5S+QsIJXWdQTmP9r/Oc9q SX5bNKMDxeRNnMFEZTEFIru0HxyVfeMbFSIEmQYa8PVdg6AHVOeeVzlY6NtbXnJto1Id JGsqTgtVNegpWSHsjumTnQuaW/1fOdY+KPHmG/Thr8oq6ehyAQtOlKhkR4xtcObTdov5 OJb8kcGwg5BJGHY/+5lbe1cHubIDLmP0PDsLaQlylRNufEDhvSWftYsBvdi4G7m1pAxe 9eZ7ZA5/bYwkodnzrsvsuCYm6dYZTQZyn/TRKRT5tAar5MMuKGuzzbt3TnBWFFwfVzjF Hmgw== X-Gm-Message-State: APjAAAXr2UYsC01ikg4ni5fKsa4DcVP6ka5a1uXNfeejuMaUrJi+IoA4 E+MclWxj+JlUAf2xj6jrJB9WCA== X-Google-Smtp-Source: APXvYqxPugT4hclwDVA+EXjf2wIQk1iSgic+RebeA058Lav/MO7sUXve5wYCEQ0D7qGywpjHfB61Nw== X-Received: by 2002:a17:90a:c790:: with SMTP id gn16mr3487094pjb.76.1576552881605; Mon, 16 Dec 2019 19:21:21 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:250d:e71d:5a0a:9afe]) by smtp.gmail.com with ESMTPSA id j3sm24387455pfi.8.2019.12.16.19.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 19:21:21 -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][PATCH 11/15] videobuf2: add begin/end cpu_access callbacks to dma-contig Date: Tue, 17 Dec 2019 12:20:30 +0900 Message-Id: <20191217032034.54897-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog In-Reply-To: <20191217032034.54897-1-senozhatsky@chromium.org> References: <20191217032034.54897-1-senozhatsky@chromium.org> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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,