Message ID | 20240830070351.2855919-2-jens.wiklander@linaro.org (mailing list archive) |
---|---|
State | New |
Headers |
Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <linux-media+bounces-17210-patchwork=linuxtv.org@vger.kernel.org>) id 1sjvgl-0007jQ-1E for patchwork@linuxtv.org; Fri, 30 Aug 2024 07:04:56 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 38C8A1F23539 for <patchwork@linuxtv.org>; Fri, 30 Aug 2024 07:04:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E9B1155C80; Fri, 30 Aug 2024 07:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IS1i2oeh" X-Original-To: linux-media@vger.kernel.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DA8515217F for <linux-media@vger.kernel.org>; Fri, 30 Aug 2024 07:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001480; cv=none; b=b8gfGLJwHx7MQoaUF4C3ucG9cTPrkFtOkvXMm8dEsx7DrBsKsUX8Ai9KONrsKfr2chXmkagmrZHXVslmptoP2jLfKvAK2OWuWRTlTrLjFPq7812IuO7A4r7XY9TEEqzIrOprk8poBhEXB827xg/GZayJSDBESSdanvT18yJ4t0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725001480; c=relaxed/simple; bh=mrYsgAuZfGUR8a8DXSlScOmgUWNB5y3kFvuvISaLR1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nto5CiM/j0p5lXxb9vhdSWG4+gggD+s7b+kmR5ebmU1Hgg6SNUKQTJ5HOhR3WXxEq8apikLYwT0ucloIPjIN2dOywM4ebldwN9wDwpoLr8CdMbHsr9hJkTMqqb5whE+NSgAh5L2V8CnbEZKxouhxI1cEx35licf9hzYkT71SdFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=IS1i2oeh; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a86abbd68ffso257860566b.0 for <linux-media@vger.kernel.org>; Fri, 30 Aug 2024 00:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725001477; x=1725606277; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MJjNgUGJenoBaIKVAgwwwsHux2S25WdElfpi6ReEk9U=; b=IS1i2oeh7nx1IhLLzty3pFy84g1mP50uDp/ay0GlWXdfZRoJ/ei2hRnvOxFBW1vmy6 fj+iD8nzzU2td1dtxsL/qpF0CKsifrshVUVYgWUobJTCwCD0GBOfci/CANsbFiEj1e2l /HOnriDbpGJaAx9RQ7WaEiIVzJD+jAHn8JqWaSmw3g9Q6OJppIvGcljwyGKPY04BFHDW OLM96OqXuxEU0miBhWkeMna8I0WDGnM5LDESHrmkRophogQ9CCdSUk90OhZ2hAxMcHyw LRiF6GhRO1LD6W76kcnj02rAhQsPNnPWZHRgmXho9AhJ4vBDialYrJWTDl4UMD++2dKI Q28g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725001477; x=1725606277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MJjNgUGJenoBaIKVAgwwwsHux2S25WdElfpi6ReEk9U=; b=iuhJemGgODMWLwIRzVK9vwEiQyKM5cLMWE+M9RurCPGGWMlGNBQ9ZAHd05tCXr9KXh taX0RGPLcFtkbT8g0O20h1kLKaTxfMoCvkshI2NyF5WKqw1srYNf38i3ZefmC5lnzdtT CourIDXLbtyzPRMvqCTYmU2Qn4HetIKW/xSWKMeGEC9i1BauKN9P3pvKIwDSNCai8Ec1 4wT/m+LExmopT7/C9M9BVa2xS2UNWk3QNYK/s3vX+BIAtFQS18Btx+KxLKQ4ZlEF/KTz AwGGMgcq2VU3MEF4a5ez8n7V3zVye8p2vqwtFCr8yRCzoNScLz+ou+7yHfFdrVIX7sL0 4TtA== X-Forwarded-Encrypted: i=1; AJvYcCUOVzPhrhZQKpuR4ElyI5M0J4evah/LYuUwaXjIDzFo2Z20Npey7Kf0FZr+XNKmosXcQGeJPxvf4sQ9Lg==@vger.kernel.org X-Gm-Message-State: AOJu0YyhbP4me8FUwGz6M7wpTffuxtyorGzLdt8KS09Hm6MIWHA54tfk XT9ZDVMy4Y5pMw4UGEf01LR28VCl9ySyRffFulB7gWyD0phlLPytX5WcP4zsXNM= X-Google-Smtp-Source: AGHT+IH87EkQZslfXd1cN/MuD1B1+tjpJHcDRiz/ebksiuYOXdKRtj8j5p8EyAgrD5jVzjEwQczjhA== X-Received: by 2002:a17:906:4788:b0:a7d:89ac:9539 with SMTP id a640c23a62f3a-a898231fe8emr528271266b.7.1725001477275; Fri, 30 Aug 2024 00:04:37 -0700 (PDT) Received: from rayden.urgonet (h-217-31-164-171.A175.priv.bahnhof.se. [217.31.164.171]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89892232c7sm178026866b.222.2024.08.30.00.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 00:04:36 -0700 (PDT) From: Jens Wiklander <jens.wiklander@linaro.org> To: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, op-tee@lists.trustedfirmware.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Olivier Masse <olivier.masse@nxp.com>, Thierry Reding <thierry.reding@gmail.com>, Yong Wu <yong.wu@mediatek.com>, Sumit Semwal <sumit.semwal@linaro.org>, Benjamin Gaignard <benjamin.gaignard@collabora.com>, Brian Starkey <Brian.Starkey@arm.com>, John Stultz <jstultz@google.com>, "T . J . Mercier" <tjmercier@google.com>, =?utf-8?q?Christian_K=C3=B6nig?= <christian.koenig@amd.com>, Sumit Garg <sumit.garg@linaro.org>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Rob Herring <robh@kernel.org>, Krzysztof Kozlowski <krzk+dt@kernel.org>, Conor Dooley <conor+dt@kernel.org>, Jens Wiklander <jens.wiklander@linaro.org> Subject: [RFC PATCH 1/4] dma-buf: heaps: restricted_heap: add no_map attribute Date: Fri, 30 Aug 2024 09:03:48 +0200 Message-Id: <20240830070351.2855919-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240830070351.2855919-1-jens.wiklander@linaro.org> References: <20240830070351.2855919-1-jens.wiklander@linaro.org> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: <linux-media.vger.kernel.org> List-Subscribe: <mailto:linux-media+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-media+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-LSpam-Score: -6.3 (------) X-LSpam-Report: No, score=-6.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no |
Series |
Linaro restricted heap
|
|
Commit Message
Jens Wiklander
Aug. 30, 2024, 7:03 a.m. UTC
Add a no_map attribute to struct restricted_heap_attachment and struct
restricted_heap to skip the call to dma_map_sgtable() if set. This
avoids trying to map a dma-buf that doens't refer to memory accessible
by the kernel.
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
---
drivers/dma-buf/heaps/restricted_heap.c | 17 +++++++++++++----
drivers/dma-buf/heaps/restricted_heap.h | 2 ++
2 files changed, 15 insertions(+), 4 deletions(-)
Comments
Am 30.08.24 um 09:03 schrieb Jens Wiklander: > Add a no_map attribute to struct restricted_heap_attachment and struct > restricted_heap to skip the call to dma_map_sgtable() if set. This > avoids trying to map a dma-buf that doens't refer to memory accessible > by the kernel. You seem to have a misunderstanding here dma_map_sgtable() is called to map a table into IOMMU and not any kernel address space. So please explain why you need that? Regards, Christian. > > Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> > --- > drivers/dma-buf/heaps/restricted_heap.c | 17 +++++++++++++---- > drivers/dma-buf/heaps/restricted_heap.h | 2 ++ > 2 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/drivers/dma-buf/heaps/restricted_heap.c b/drivers/dma-buf/heaps/restricted_heap.c > index 8bc8a5e3f969..4bf28e3727ca 100644 > --- a/drivers/dma-buf/heaps/restricted_heap.c > +++ b/drivers/dma-buf/heaps/restricted_heap.c > @@ -16,6 +16,7 @@ > struct restricted_heap_attachment { > struct sg_table *table; > struct device *dev; > + bool no_map; > }; > > static int > @@ -54,6 +55,8 @@ restricted_heap_memory_free(struct restricted_heap *rheap, struct restricted_buf > static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attachment) > { > struct restricted_buffer *restricted_buf = dmabuf->priv; > + struct dma_heap *heap = restricted_buf->heap; > + struct restricted_heap *rheap = dma_heap_get_drvdata(heap); > struct restricted_heap_attachment *a; > struct sg_table *table; > > @@ -70,6 +73,7 @@ static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachm > sg_dma_mark_restricted(table->sgl); > a->table = table; > a->dev = attachment->dev; > + a->no_map = rheap->no_map; > attachment->priv = a; > > return 0; > @@ -92,9 +96,12 @@ restricted_heap_map_dma_buf(struct dma_buf_attachment *attachment, > struct sg_table *table = a->table; > int ret; > > - ret = dma_map_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); > - if (ret) > - return ERR_PTR(ret); > + if (!a->no_map) { > + ret = dma_map_sgtable(attachment->dev, table, direction, > + DMA_ATTR_SKIP_CPU_SYNC); > + if (ret) > + return ERR_PTR(ret); > + } > return table; > } > > @@ -106,7 +113,9 @@ restricted_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_t > > WARN_ON(a->table != table); > > - dma_unmap_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); > + if (!a->no_map) > + dma_unmap_sgtable(attachment->dev, table, direction, > + DMA_ATTR_SKIP_CPU_SYNC); > } > > static int > diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/heaps/restricted_heap.h > index 7dec4b8a471b..94cc0842f70d 100644 > --- a/drivers/dma-buf/heaps/restricted_heap.h > +++ b/drivers/dma-buf/heaps/restricted_heap.h > @@ -27,6 +27,8 @@ struct restricted_heap { > unsigned long cma_paddr; > unsigned long cma_size; > > + bool no_map; > + > void *priv_data; > }; >
On Fri, Aug 30, 2024 at 10:47 AM Christian König <christian.koenig@amd.com> wrote: > > Am 30.08.24 um 09:03 schrieb Jens Wiklander: > > Add a no_map attribute to struct restricted_heap_attachment and struct > > restricted_heap to skip the call to dma_map_sgtable() if set. This > > avoids trying to map a dma-buf that doens't refer to memory accessible > > by the kernel. > > You seem to have a misunderstanding here dma_map_sgtable() is called to > map a table into IOMMU and not any kernel address space. > > So please explain why you need that? You're right, I had misunderstood dma_map_sgtable(). There's no need for the no_map attribute, so I'll remove it. Perhaps you have a suggestion on how to fix a problem when using dma_map_sgtable()? Without it, I'll have to assign a pointer to teedev->dev.dma_mask when using the restricted heap with the OP-TEE driver or there will be a warning in __dma_map_sg_attrs() ending with a failure when trying to register the dma-buf fd. OP-TEE is probed with a platform device, and taking the dma_mask pointer from that device works. Is that a good approach or is there a better way of assigning dma_mask? Thanks, Jens > > Regards, > Christian. > > > > > Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> > > --- > > drivers/dma-buf/heaps/restricted_heap.c | 17 +++++++++++++---- > > drivers/dma-buf/heaps/restricted_heap.h | 2 ++ > > 2 files changed, 15 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/dma-buf/heaps/restricted_heap.c b/drivers/dma-buf/heaps/restricted_heap.c > > index 8bc8a5e3f969..4bf28e3727ca 100644 > > --- a/drivers/dma-buf/heaps/restricted_heap.c > > +++ b/drivers/dma-buf/heaps/restricted_heap.c > > @@ -16,6 +16,7 @@ > > struct restricted_heap_attachment { > > struct sg_table *table; > > struct device *dev; > > + bool no_map; > > }; > > > > static int > > @@ -54,6 +55,8 @@ restricted_heap_memory_free(struct restricted_heap *rheap, struct restricted_buf > > static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attachment) > > { > > struct restricted_buffer *restricted_buf = dmabuf->priv; > > + struct dma_heap *heap = restricted_buf->heap; > > + struct restricted_heap *rheap = dma_heap_get_drvdata(heap); > > struct restricted_heap_attachment *a; > > struct sg_table *table; > > > > @@ -70,6 +73,7 @@ static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachm > > sg_dma_mark_restricted(table->sgl); > > a->table = table; > > a->dev = attachment->dev; > > + a->no_map = rheap->no_map; > > attachment->priv = a; > > > > return 0; > > @@ -92,9 +96,12 @@ restricted_heap_map_dma_buf(struct dma_buf_attachment *attachment, > > struct sg_table *table = a->table; > > int ret; > > > > - ret = dma_map_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); > > - if (ret) > > - return ERR_PTR(ret); > > + if (!a->no_map) { > > + ret = dma_map_sgtable(attachment->dev, table, direction, > > + DMA_ATTR_SKIP_CPU_SYNC); > > + if (ret) > > + return ERR_PTR(ret); > > + } > > return table; > > } > > > > @@ -106,7 +113,9 @@ restricted_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_t > > > > WARN_ON(a->table != table); > > > > - dma_unmap_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); > > + if (!a->no_map) > > + dma_unmap_sgtable(attachment->dev, table, direction, > > + DMA_ATTR_SKIP_CPU_SYNC); > > } > > > > static int > > diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/heaps/restricted_heap.h > > index 7dec4b8a471b..94cc0842f70d 100644 > > --- a/drivers/dma-buf/heaps/restricted_heap.h > > +++ b/drivers/dma-buf/heaps/restricted_heap.h > > @@ -27,6 +27,8 @@ struct restricted_heap { > > unsigned long cma_paddr; > > unsigned long cma_size; > > > > + bool no_map; > > + > > void *priv_data; > > }; > > >
Am 05.09.24 um 08:56 schrieb Jens Wiklander: > On Fri, Aug 30, 2024 at 10:47 AM Christian König > <christian.koenig@amd.com> wrote: >> Am 30.08.24 um 09:03 schrieb Jens Wiklander: >>> Add a no_map attribute to struct restricted_heap_attachment and struct >>> restricted_heap to skip the call to dma_map_sgtable() if set. This >>> avoids trying to map a dma-buf that doens't refer to memory accessible >>> by the kernel. >> You seem to have a misunderstanding here dma_map_sgtable() is called to >> map a table into IOMMU and not any kernel address space. >> >> So please explain why you need that? > You're right, I had misunderstood dma_map_sgtable(). There's no need > for the no_map attribute, so I'll remove it. > > Perhaps you have a suggestion on how to fix a problem when using > dma_map_sgtable()? > > Without it, I'll have to assign a pointer to teedev->dev.dma_mask when > using the restricted heap with the OP-TEE driver or there will be a > warning in __dma_map_sg_attrs() ending with a failure when trying to > register the dma-buf fd. OP-TEE is probed with a platform device, and > taking the dma_mask pointer from that device works. Is that a good > approach or is there a better way of assigning dma_mask? Mhm, I don't know the full picture so I have to make some assumptions. The teedev is just a virtual device which represents the restricted memory access paths of a real device? If that is true then taking the dma-mask from the real device is most likely the right thing to do. Regards, Christian. > > Thanks, > Jens > >> Regards, >> Christian. >> >>> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> >>> --- >>> drivers/dma-buf/heaps/restricted_heap.c | 17 +++++++++++++---- >>> drivers/dma-buf/heaps/restricted_heap.h | 2 ++ >>> 2 files changed, 15 insertions(+), 4 deletions(-) >>> >>> diff --git a/drivers/dma-buf/heaps/restricted_heap.c b/drivers/dma-buf/heaps/restricted_heap.c >>> index 8bc8a5e3f969..4bf28e3727ca 100644 >>> --- a/drivers/dma-buf/heaps/restricted_heap.c >>> +++ b/drivers/dma-buf/heaps/restricted_heap.c >>> @@ -16,6 +16,7 @@ >>> struct restricted_heap_attachment { >>> struct sg_table *table; >>> struct device *dev; >>> + bool no_map; >>> }; >>> >>> static int >>> @@ -54,6 +55,8 @@ restricted_heap_memory_free(struct restricted_heap *rheap, struct restricted_buf >>> static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attachment) >>> { >>> struct restricted_buffer *restricted_buf = dmabuf->priv; >>> + struct dma_heap *heap = restricted_buf->heap; >>> + struct restricted_heap *rheap = dma_heap_get_drvdata(heap); >>> struct restricted_heap_attachment *a; >>> struct sg_table *table; >>> >>> @@ -70,6 +73,7 @@ static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachm >>> sg_dma_mark_restricted(table->sgl); >>> a->table = table; >>> a->dev = attachment->dev; >>> + a->no_map = rheap->no_map; >>> attachment->priv = a; >>> >>> return 0; >>> @@ -92,9 +96,12 @@ restricted_heap_map_dma_buf(struct dma_buf_attachment *attachment, >>> struct sg_table *table = a->table; >>> int ret; >>> >>> - ret = dma_map_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); >>> - if (ret) >>> - return ERR_PTR(ret); >>> + if (!a->no_map) { >>> + ret = dma_map_sgtable(attachment->dev, table, direction, >>> + DMA_ATTR_SKIP_CPU_SYNC); >>> + if (ret) >>> + return ERR_PTR(ret); >>> + } >>> return table; >>> } >>> >>> @@ -106,7 +113,9 @@ restricted_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_t >>> >>> WARN_ON(a->table != table); >>> >>> - dma_unmap_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); >>> + if (!a->no_map) >>> + dma_unmap_sgtable(attachment->dev, table, direction, >>> + DMA_ATTR_SKIP_CPU_SYNC); >>> } >>> >>> static int >>> diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/heaps/restricted_heap.h >>> index 7dec4b8a471b..94cc0842f70d 100644 >>> --- a/drivers/dma-buf/heaps/restricted_heap.h >>> +++ b/drivers/dma-buf/heaps/restricted_heap.h >>> @@ -27,6 +27,8 @@ struct restricted_heap { >>> unsigned long cma_paddr; >>> unsigned long cma_size; >>> >>> + bool no_map; >>> + >>> void *priv_data; >>> }; >>>
diff --git a/drivers/dma-buf/heaps/restricted_heap.c b/drivers/dma-buf/heaps/restricted_heap.c index 8bc8a5e3f969..4bf28e3727ca 100644 --- a/drivers/dma-buf/heaps/restricted_heap.c +++ b/drivers/dma-buf/heaps/restricted_heap.c @@ -16,6 +16,7 @@ struct restricted_heap_attachment { struct sg_table *table; struct device *dev; + bool no_map; }; static int @@ -54,6 +55,8 @@ restricted_heap_memory_free(struct restricted_heap *rheap, struct restricted_buf static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachment *attachment) { struct restricted_buffer *restricted_buf = dmabuf->priv; + struct dma_heap *heap = restricted_buf->heap; + struct restricted_heap *rheap = dma_heap_get_drvdata(heap); struct restricted_heap_attachment *a; struct sg_table *table; @@ -70,6 +73,7 @@ static int restricted_heap_attach(struct dma_buf *dmabuf, struct dma_buf_attachm sg_dma_mark_restricted(table->sgl); a->table = table; a->dev = attachment->dev; + a->no_map = rheap->no_map; attachment->priv = a; return 0; @@ -92,9 +96,12 @@ restricted_heap_map_dma_buf(struct dma_buf_attachment *attachment, struct sg_table *table = a->table; int ret; - ret = dma_map_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); - if (ret) - return ERR_PTR(ret); + if (!a->no_map) { + ret = dma_map_sgtable(attachment->dev, table, direction, + DMA_ATTR_SKIP_CPU_SYNC); + if (ret) + return ERR_PTR(ret); + } return table; } @@ -106,7 +113,9 @@ restricted_heap_unmap_dma_buf(struct dma_buf_attachment *attachment, struct sg_t WARN_ON(a->table != table); - dma_unmap_sgtable(attachment->dev, table, direction, DMA_ATTR_SKIP_CPU_SYNC); + if (!a->no_map) + dma_unmap_sgtable(attachment->dev, table, direction, + DMA_ATTR_SKIP_CPU_SYNC); } static int diff --git a/drivers/dma-buf/heaps/restricted_heap.h b/drivers/dma-buf/heaps/restricted_heap.h index 7dec4b8a471b..94cc0842f70d 100644 --- a/drivers/dma-buf/heaps/restricted_heap.h +++ b/drivers/dma-buf/heaps/restricted_heap.h @@ -27,6 +27,8 @@ struct restricted_heap { unsigned long cma_paddr; unsigned long cma_size; + bool no_map; + void *priv_data; };