Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4458552pxb; Tue, 31 Aug 2021 05:50:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlC2kqajWS6ZwaHpaxT5XyKuDBY8gAA9XRBmg6AVa6onWAENBq17Fn4Yn2hSdNyxSkL2ww X-Received: by 2002:a17:907:2137:: with SMTP id qo23mr28282361ejb.508.1630414254314; Tue, 31 Aug 2021 05:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630414254; cv=none; d=google.com; s=arc-20160816; b=t7tLA/H5Pi25mqr59ThYXHI6XQPy8yyU3NjPr9KY0kiWeMXneBen3vcwIksVd+BCBH ohOZLhK0B7knhpH7UvljCTr6Rh7Pkv5ZjlpHL1cRR42F5Y1k8QAU6l2eXNQ4i1RJlWEV JMLbdaV7Z267CBRtN1uZLv+fmHPzoxz9iBA1p95DaKqiVxB1GW0zsUBGo4ndqe6KbjUX c3VU5FW6gjz12ESi6LagrI3ekkIiMxHoMkjUGQblH+VHNWHckUitbwwPVft/LNQGKbgO ESjUqCHTLP6m90Cb+rpIllr29MCU8mf2zKKOQBKJfyNZbNXnYOraGD0d8DTK3XTW3ez9 tStA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=lqW6r2QxBjf3naPSK7ElejDN0miJGNk4JeUrWNu5dFo=; b=CxQXYdabrfHjaJBD0Xv/Xvd0jbI6qdZ8b6Dvht0Ig/73RksA2XHSA6Ib1Ymo7rVxqt zM5BDvmHWPYx9xhgyO/Zytnynswh7e7GC1EqsC4UUmAoQTrHa0osph3ljpWERxXONNuH bKCL5mmfLhUs0bfQy+egorh0eQMFmAYUScNT+2TAds/8zIpGUGeiMo9og7+OblKaxGqE dp1vi8RioamrLfd+8iaPBZMpiemHFIyA2NHcCdxY8r9o6PfltJvzOyTiBh0oCOMNmhAD Aq9DuqlQqoMyG/BE7aM0LZHuRIk+c/DCiCU5cey16LTSTrTjIdrl2fdFHLdwtclDqh9Q LrUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=P7GUI4rz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j4si7053123ejj.357.2021.08.31.05.49.56; Tue, 31 Aug 2021 05:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=P7GUI4rz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbhHaMsD (ORCPT + 99 others); Tue, 31 Aug 2021 08:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbhHaMsC (ORCPT ); Tue, 31 Aug 2021 08:48:02 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BA1BC061575 for ; Tue, 31 Aug 2021 05:47:07 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id g18so19996979wrc.11 for ; Tue, 31 Aug 2021 05:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=lqW6r2QxBjf3naPSK7ElejDN0miJGNk4JeUrWNu5dFo=; b=P7GUI4rzpcJORZdrR45U9tZBVNt+YutkUgaZAyUSoo0hNOv5YFYj2LVa3BDKBVLlEZ 8P09RZ77gdJ/9bmvIGELMImn15ss9sRZV4C/seGIidibDM6yqDjkjA6TuRj46kpJciNn Jh7pnUHhLdusLFGeigWIF2NedtczE/Aou9GJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=lqW6r2QxBjf3naPSK7ElejDN0miJGNk4JeUrWNu5dFo=; b=dWZeQHmH2lT83WC55b1kELioUDNsQI8vKRkV93Dm9KVpY6PEAqjckQBJhnTi2zPrAi o+IUDEO2jhLq5JSk9Aaqs4B7BuoActzAznW/bvrUPHRQvFyPow6k8WTs02RnzvOGkI9M tkxLHivwwFSOA6mQJQ4IxxLgXH0q/4qUPm5y7OU/mvrxxqk+E+xig0yRzc//2qxowfBM JpWs1T/9Cn9XshVSkMtsI6OEov5P4/W4eiecYNv9clja4YlXP9kD1bAIcM4qRtpAXr1k yJGZCxZll0a+NCAK6pEXI0Apz3v5clLA003kZG0uEwgqKJfgT3UnWK6b+w1uAbn7vmh7 YYjQ== X-Gm-Message-State: AOAM533GJ8+vZuZt7+jElTPRwKDMIzakc8RLkOczFRQdAb9+FgyywbXE f15Tw18kMyWDudmLF8wBuPQIUg== X-Received: by 2002:adf:c40d:: with SMTP id v13mr29016331wrf.388.1630414026094; Tue, 31 Aug 2021 05:47:06 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id q14sm11701297wrc.31.2021.08.31.05.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 05:47:05 -0700 (PDT) Date: Tue, 31 Aug 2021 14:47:03 +0200 From: Daniel Vetter To: guangming.cao@mediatek.com Cc: Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , Christian =?iso-8859-1?Q?K=F6nig?= , Matthias Brugger , "open list:DMA-BUF HEAPS FRAMEWORK" , "open list:DMA-BUF HEAPS FRAMEWORK" , "moderated list:DMA-BUF HEAPS FRAMEWORK" , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , wsd_upstream@mediatek.com, isaacm@codeaurora.org, sspatil@google.com, hridya@google.com Subject: Re: [PATCH] dma-buf: Add support for mapping buffers with DMA attributes Message-ID: Mail-Followup-To: guangming.cao@mediatek.com, Sumit Semwal , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , Christian =?iso-8859-1?Q?K=F6nig?= , Matthias Brugger , "open list:DMA-BUF HEAPS FRAMEWORK" , "open list:DMA-BUF HEAPS FRAMEWORK" , "moderated list:DMA-BUF HEAPS FRAMEWORK" , open list , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , wsd_upstream@mediatek.com, isaacm@codeaurora.org, sspatil@google.com, hridya@google.com References: <20210830023911.4410-1-guangming.cao@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210830023911.4410-1-guangming.cao@mediatek.com> X-Operating-System: Linux phenom 5.10.0-8-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 30, 2021 at 10:39:11AM +0800, guangming.cao@mediatek.com wrote: > From: Guangming Cao > > When mapping the memory represented by a dma-buf into a device's > address space, it might be desireable to map the memory with > certain DMA attributes. Thus, introduce the dma_mapping_attrs > field in the dma_buf_attachment structure so that when > the memory is mapped with dma_buf_map_attachment, it is mapped > with the desired DMA attributes. > > Signed-off-by: Isaac J. Manjarres > Signed-off-by: Sandeep Patil > Signed-off-by: Guangming Cao Can you pls include the code that's going to use this here too? At a glance all the attributes you might want to set are supposed to be under the control of the exporter, not the importer. -Daniel > --- > drivers/dma-buf/heaps/cma_heap.c | 6 ++++-- > drivers/dma-buf/heaps/system_heap.c | 6 ++++-- > include/linux/dma-buf.h | 3 +++ > 3 files changed, 11 insertions(+), 4 deletions(-) > > diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c > index 0c05b79870f9..2c9feb3bfc3e 100644 > --- a/drivers/dma-buf/heaps/cma_heap.c > +++ b/drivers/dma-buf/heaps/cma_heap.c > @@ -99,9 +99,10 @@ static struct sg_table *cma_heap_map_dma_buf(struct dma_buf_attachment *attachme > { > struct dma_heap_attachment *a = attachment->priv; > struct sg_table *table = &a->table; > + int attrs = attachment->dma_map_attrs; > int ret; > > - ret = dma_map_sgtable(attachment->dev, table, direction, 0); > + ret = dma_map_sgtable(attachment->dev, table, direction, attrs); > if (ret) > return ERR_PTR(-ENOMEM); > a->mapped = true; > @@ -113,9 +114,10 @@ static void cma_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, > enum dma_data_direction direction) > { > struct dma_heap_attachment *a = attachment->priv; > + int attrs = attachment->dma_map_attrs; > > a->mapped = false; > - dma_unmap_sgtable(attachment->dev, table, direction, 0); > + dma_unmap_sgtable(attachment->dev, table, direction, attrs); > } > > static int cma_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, > diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c > index 23a7e74ef966..fc7b1e02988e 100644 > --- a/drivers/dma-buf/heaps/system_heap.c > +++ b/drivers/dma-buf/heaps/system_heap.c > @@ -130,9 +130,10 @@ static struct sg_table *system_heap_map_dma_buf(struct dma_buf_attachment *attac > { > struct dma_heap_attachment *a = attachment->priv; > struct sg_table *table = a->table; > + int attrs = attachment->dma_map_attrs; > int ret; > > - ret = dma_map_sgtable(attachment->dev, table, direction, 0); > + ret = dma_map_sgtable(attachment->dev, table, direction, attrs); > if (ret) > return ERR_PTR(ret); > > @@ -145,9 +146,10 @@ static void system_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, > enum dma_data_direction direction) > { > struct dma_heap_attachment *a = attachment->priv; > + int attrs = attachment->dma_map_attrs; > > a->mapped = false; > - dma_unmap_sgtable(attachment->dev, table, direction, 0); > + dma_unmap_sgtable(attachment->dev, table, direction, attrs); > } > > static int system_heap_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, > diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h > index efdc56b9d95f..4d650731766e 100644 > --- a/include/linux/dma-buf.h > +++ b/include/linux/dma-buf.h > @@ -379,6 +379,8 @@ struct dma_buf_attach_ops { > * @importer_ops: importer operations for this attachment, if provided > * dma_buf_map/unmap_attachment() must be called with the dma_resv lock held. > * @importer_priv: importer specific attachment data. > + * @dma_map_attrs: DMA attributes to be used when the exporter maps the buffer > + * through dma_buf_map_attachment. > * > * This structure holds the attachment information between the dma_buf buffer > * and its user device(s). The list contains one attachment struct per device > @@ -399,6 +401,7 @@ struct dma_buf_attachment { > const struct dma_buf_attach_ops *importer_ops; > void *importer_priv; > void *priv; > + unsigned long dma_map_attrs; > }; > > /** > -- > 2.17.1 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch