From: Ioana Ciocoi-Radulescu <ruxandra.radulescu@nxp.com>
To: "Oded Gabbay" <ogabbay@kernel.org>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Shawn Guo" <shawnguo@kernel.org>, "Frank Li" <Frank.Li@nxp.com>,
"Christian König" <christian.koenig@amd.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, devicetree@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
Jiwei Fu <jiwei.fu@nxp.com>, Forrest Shi <xuelin.shi@nxp.com>,
Alexandru Taran <alexandru.taran@nxp.com>,
Daniel Baluta <daniel.baluta@nxp.com>,
Ioana Ciocoi-Radulescu <ruxandra.radulescu@nxp.com>
Subject: [PATCH v2 1/9] drm/gem-dma: Add flag for bidirectional mapping of non-coherent GEM DMA buffers
Date: Fri, 06 Mar 2026 15:27:18 +0200 [thread overview]
Message-ID: <20260306-neutron-v2-1-3019bd8c91ef@nxp.com> (raw)
In-Reply-To: <20260306-neutron-v2-0-3019bd8c91ef@nxp.com>
Introduce a flag that allows a user to request non-coherent buffers
allocated via the GEM DMA helper for bidirectional use.
Keep current behaviour (DMA_TO_DEVICE mapping) as default, with no change
required for existing GEM DMA users.
While it hasn't been the case until now, some devices like NXP's Neutron
Neural Processing Unit (NPU) require contiguous, non-coherent DMA buffers
they can both read from and write to. Unlike traditional DRM devices,
Neutron uses the same DMA buffer both for reading model data and for
writing inference output.
Neutron's usage scenario is a good match for the GEM DMA helpers, except
for the fact that current implementation only considers the DMA_TO_DEVICE
direction.
Signed-off-by: Ioana Ciocoi-Radulescu <ruxandra.radulescu@nxp.com>
---
drivers/gpu/drm/drm_gem_dma_helper.c | 6 ++++--
include/drm/drm_gem_dma_helper.h | 3 +++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c
index ecb9746f4da8..dbf5ad4426d3 100644
--- a/drivers/gpu/drm/drm_gem_dma_helper.c
+++ b/drivers/gpu/drm/drm_gem_dma_helper.c
@@ -148,7 +148,8 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
if (dma_obj->map_noncoherent) {
dma_obj->vaddr = dma_alloc_noncoherent(drm->dev, size,
&dma_obj->dma_addr,
- DMA_TO_DEVICE,
+ dma_obj->map_bidirectional ?
+ DMA_BIDIRECTIONAL : DMA_TO_DEVICE,
GFP_KERNEL | __GFP_NOWARN);
} else {
dma_obj->vaddr = dma_alloc_wc(drm->dev, size,
@@ -238,7 +239,8 @@ void drm_gem_dma_free(struct drm_gem_dma_object *dma_obj)
if (dma_obj->map_noncoherent)
dma_free_noncoherent(gem_obj->dev->dev, dma_obj->base.size,
dma_obj->vaddr, dma_obj->dma_addr,
- DMA_TO_DEVICE);
+ dma_obj->map_bidirectional ?
+ DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
else
dma_free_wc(gem_obj->dev->dev, dma_obj->base.size,
dma_obj->vaddr, dma_obj->dma_addr);
diff --git a/include/drm/drm_gem_dma_helper.h b/include/drm/drm_gem_dma_helper.h
index f2678e7ecb98..e0022f2fdfef 100644
--- a/include/drm/drm_gem_dma_helper.h
+++ b/include/drm/drm_gem_dma_helper.h
@@ -17,6 +17,8 @@ struct drm_mode_create_dumb;
* DMA addresses.
* @vaddr: kernel virtual address of the backing memory
* @map_noncoherent: if true, the GEM object is backed by non-coherent memory
+ * @map_bidirectional: valid only if map_noncoherent flag is set. If true, allow
+ * bidirectional use of the non-coherent memory buffer
*/
struct drm_gem_dma_object {
struct drm_gem_object base;
@@ -27,6 +29,7 @@ struct drm_gem_dma_object {
void *vaddr;
bool map_noncoherent;
+ bool map_bidirectional;
};
#define to_drm_gem_dma_obj(gem_obj) \
--
2.34.1
next prev parent reply other threads:[~2026-03-06 13:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 13:27 [PATCH v2 0/9] accel: New driver for NXP's Neutron NPU Ioana Ciocoi-Radulescu
2026-03-06 13:27 ` Ioana Ciocoi-Radulescu [this message]
2026-03-06 13:27 ` [PATCH v2 2/9] accel/neutron: Add documentation for NXP Neutron accelerator driver Ioana Ciocoi-Radulescu
2026-03-06 13:27 ` [PATCH v2 3/9] dt-bindings: npu: Add NXP Neutron Ioana Ciocoi-Radulescu
2026-03-06 14:17 ` Krzysztof Kozlowski
2026-03-06 13:27 ` [PATCH v2 4/9] accel/neutron: Add driver for NXP Neutron NPU Ioana Ciocoi-Radulescu
2026-03-06 14:21 ` Krzysztof Kozlowski
2026-03-24 13:36 ` Ioana Ciocoi Radulescu
2026-03-06 13:27 ` [PATCH v2 5/9] accel/neutron: Add GEM buffer object support Ioana Ciocoi-Radulescu
2026-03-06 13:27 ` [PATCH v2 6/9] accel/neutron: Add mailbox support Ioana Ciocoi-Radulescu
2026-03-06 13:27 ` [PATCH v2 7/9] accel/neutron: Add job submission IOCTL Ioana Ciocoi-Radulescu
2026-03-06 17:02 ` Frank Li
2026-03-24 13:38 ` Ioana Ciocoi Radulescu
2026-03-06 13:27 ` [PATCH v2 8/9] accel/neutron: Add logging support Ioana Ciocoi-Radulescu
2026-03-06 13:27 ` [PATCH v2 9/9] arm64: dts: imx95: Add Neutron node Ioana Ciocoi-Radulescu
2026-03-21 17:19 ` [PATCH v2 0/9] accel: New driver for NXP's Neutron NPU Tomeu Vizoso
2026-03-24 12:12 ` Ioana Ciocoi Radulescu
[not found] ` <CAPsqS2QXcgbi9_e4QmCn1Cgkr-bOVsY-E9qpZsFw3WYWWLugEw@mail.gmail.com>
2026-03-26 7:18 ` Ioana Ciocoi Radulescu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260306-neutron-v2-1-3019bd8c91ef@nxp.com \
--to=ruxandra.radulescu@nxp.com \
--cc=Frank.Li@nxp.com \
--cc=airlied@gmail.com \
--cc=alexandru.taran@nxp.com \
--cc=christian.koenig@amd.com \
--cc=conor+dt@kernel.org \
--cc=daniel.baluta@nxp.com \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=imx@lists.linux.dev \
--cc=jiwei.fu@nxp.com \
--cc=krzk+dt@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=ogabbay@kernel.org \
--cc=robh@kernel.org \
--cc=shawnguo@kernel.org \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
--cc=xuelin.shi@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox