accel: New driver for NXP's Neutron NPU
Subsystems (7)
v2 cover accel: New driver for NXP's Neutron NPU
Introduce a new accel driver for the Neutron Neural Processing Unit (NPU), along with associated dt-bindings and DTS node.
The first patch extends the GEM DMA helper APIs to allow bidirectional mapping of non-coherent DMA buffers. While not part of the Neutron driver, it's a prerequisite allowing us to use the GEM DMA helper.
Neutron is a Neural Processing Unit from NXP, providing machine learning (ML) acceleration for edge AI applications. Neutron is integrated on NXP SoCs such as the i.MX95.
The NPU consists of the following:
- RISC-V core running a proprietary firmware
- One or more Neutron cores, representing the main computation engine performing ML operations
- Dedicated fast memory (TCM)
- DMA engine that handles data transfers between DDR and TCM
The firmware is closed source and distributed as a binary here [1].
The Neutron software stack also contains a userspace library [1] and a LiteRT custom delegate [2] that allow integration with standard LiteRT tools.
[1] https://github.com/nxp-upstream/neutron/tree/upstream
[2] https://github.com/nxp-imx/tflite-neutron-delegate
---
Changes in v2:
- rebase on newer drm-misc-next
- dt bindings: clock fixes and renames
- update DTS to match new names
- remove unnecessary fields from neutron_job structure
- fix use of uninitialized variable
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ioana Ciocoi-Radulescu (9):
drm/gem-dma: Add flag for bidirectional mapping of non-coherent GEM DMA buffers accel/neutron: Add documentation for NXP Neutron accelerator driver
dt-bindings: npu: Add NXP Neutron
accel/neutron: Add driver for NXP Neutron NPU
accel/neutron: Add GEM buffer object support
accel/neutron: Add mailbox support
accel/neutron: Add job submission IOCTL
accel/neutron: Add logging support
arm64: dts: imx95: Add Neutron node
Documentation/accel/index.rst | 1 + Documentation/accel/neutron/index.rst | 12 + Documentation/accel/neutron/neutron.rst | 131 ++++++++ .../devicetree/bindings/npu/nxp,imx95-neutron.yaml | 96 ++++++ MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx95.dtsi | 28 ++ drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 3 +- drivers/accel/neutron/Kconfig | 16 + drivers/accel/neutron/Makefile | 12 + drivers/accel/neutron/neutron_debugfs.c | 34 ++ drivers/accel/neutron/neutron_debugfs.h | 15 + drivers/accel/neutron/neutron_device.c | 239 +++++++++++++ drivers/accel/neutron/neutron_device.h | 155 +++++++++ drivers/accel/neutron/neutron_driver.c | 262 +++++++++++++++ drivers/accel/neutron/neutron_driver.h | 16 + drivers/accel/neutron/neutron_gem.c | 116 +++++++ drivers/accel/neutron/neutron_gem.h | 14 + drivers/accel/neutron/neutron_job.c | 372 +++++++++++++++++++++ drivers/accel/neutron/neutron_job.h | 43 +++ drivers/accel/neutron/neutron_mailbox.c | 47 +++ drivers/accel/neutron/neutron_mailbox.h | 42 +++ drivers/gpu/drm/drm_gem_dma_helper.c | 6 +- include/drm/drm_gem_dma_helper.h | 3 + include/uapi/drm/neutron_accel.h | 130 +++++++ 25 files changed, 1801 insertions(+), 3 deletions(-)
---
base-commit: 6716101ae42949e98ad4b9e71eeba08c055be410
change-id: 20260226-neutron-c435e39d167f
Best regards,
Signature · 1 line
Ioana Ciocoi-Radulescu <[email protected]>
PATCH v2 1/9 drm/gem-dma: Add flag for bidirectional mapping of non-coherent GEM DMA buffers
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.
--- drivers/gpu/drm/drm_gem_dma_helper.c | 6 ++++-- include/drm/drm_gem_dma_helper.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_dma_helper.c +4 -2
@@ -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);
include/drm/drm_gem_dma_helper.h +3 -0
@@ -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) \
Signature · 1 line
2.34.1
PATCH v2 2/9 accel/neutron: Add documentation for NXP Neutron accelerator driver
In reply to Ioana Ciocoi-RadulescuNeutron is NXP's Neural Processing Unit (NPU) and it's integrated on the i.MX95 SoC. It is capable of running inferences on a large range of ML models and targets edge AI applications.
--- Documentation/accel/index.rst | 1 + Documentation/accel/neutron/index.rst | 12 +++ Documentation/accel/neutron/neutron.rst | 131 ++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+)
Documentation/accel/index.rst +1 -0
@@ -9,5 +9,6 @@ Compute Accelerators introduction amdxdna/index + neutron/index qaic/index rocket/index
Documentation/accel/neutron/index.rst new file +12 -0
@@ -0,0 +1,12 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +========================== + accel/neutron NPU driver +========================== + +The accel/neutron driver supports the Neutron NPU (Neural Processing Unit) +from NXP. + +.. toctree:: + + neutron
Documentation/accel/neutron/neutron.rst new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 3/9 dt-bindings: npu: Add NXP Neutron
In reply to Ioana Ciocoi-RadulescuAdd the bindings for Neutron, a Neural Processing Unit from NXP.
---
v2:
- clock fixes: add description, rename, make clocks mandatory
- rename node from neutron to npu
- fix indentation
--- .../devicetree/bindings/npu/nxp,imx95-neutron.yaml | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+)
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml new file +96 -0
@@ -0,0 +1,96 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/npu/nxp,imx95-neutron.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NXP Neutron NPU + +maintainers: + - Ioana Ciocoi-Radulescu <[email protected]> + - Jiwei Fu <[email protected]> + +description: + Neutron is an NPU from NXP targeting edge AI inference applications. + Initially supported on i.MX95 SoCs. + +properties: + compatible: + enum: + - nxp,imx95-neutron + + reg: + items: + - description: Register space + - description: Instruction area of the TCM space + - description: Data area of the TCM space + + reg-names: + items: + - const: regs + - const: itcm + - const: dtcm + + memory-region: + description: + Phandle referencing a "shared-dma-pool" to be used for Neutron + inference buffers, which need to be 1MB aligned. + + The memory region must be defined with alignment of 1MB and size + should be large enough to accommodate the targeted ML models. It + should be marked as reusable. + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + items: + - description: Core clock + - description: APB bus clock + + clock-names: + items: + - const: core + - const: apb + + iommus: + maxItems: 1 + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - reg-names + - memory-region + - interrupts + - clocks + - clock-names + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/interrupt-controller/irq.h> + + bus { + #address-cells = <2>; + #size-cells = <2>; + + npu@4ab00000 { + compatible = "nxp,imx95-neutron"; + reg = <0x0 0x4ab00000 0x0 0x00000400>, + <0x0 0x4AB10000 0x0 0x00010000>, + <0x0 0x4AB08000 0x0 0x00008000>; + reg-names = "regs", "itcm", "dtcm"; + memory-region = <&neutron_pool>; + interrupts = <GIC_SPI 318 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&scmi_clk 68>, <&scmi_clk 67>; + clock-names = "core", "apb"; + power-domains = <&scmi_devpd 20>; + }; + }; +...
Signature · 1 line
2.34.1
Re: [PATCH v2 3/9] dt-bindings: npu: Add NXP Neutron
Quoted 5 lines · Ioana Ciocoi-Radulescu
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml new file +5
-0+ + iommus: + maxItems: 1 + + power-domains:
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml line 70
Quoted 10 lines
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml new file +10
-0+ maxItems: 1 + +required: + - compatible + - reg + - reg-names + - memory-region + - interrupts + - clocks + - clock-names
Missing power-domains
Quoted 7 lines
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml new file +7
-0+ +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/interrupt-controller/irq.h>
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml line 87
Quoted 10 lines
Documentation/devicetree/bindings/npu/nxp,imx95-neutron.yaml new file +10
-0+ + bus { + #address-cells = <2>; + #size-cells = <2>; + + npu@4ab00000 { + compatible = "nxp,imx95-neutron"; + reg = <0x0 0x4ab00000 0x0 0x00000400>, + <0x0 0x4AB10000 0x0 0x00010000>, + <0x0 0x4AB08000 0x0 0x00008000>;
Keep consistent code, so lowercase hex.
With these two fixed:
Best regards,
Krzysztof
PATCH v2 4/9 accel/neutron: Add driver for NXP Neutron NPU
In reply to Ioana Ciocoi-RadulescuAdd a driver for the Neutron Neural Processing Unit from NXP.
Neutron NPU provides machine learning (ML) acceleration for edge AI applications. Neutron is integrated on NXP SoCs such as the i.MX95. More information can be found under Documentation/accel/neutron.
For now introduce basic functionalities only: device probe and remove, firmware load, boot and shutdown procedures, interrupt support, power management.
--- MAINTAINERS | 10 ++ drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 3 +- drivers/accel/neutron/Kconfig | 16 +++ drivers/accel/neutron/Makefile | 7 + drivers/accel/neutron/neutron_device.c | 160 +++++++++++++++++++++++ drivers/accel/neutron/neutron_device.h | 120 +++++++++++++++++ drivers/accel/neutron/neutron_driver.c | 228 +++++++++++++++++++++++++++++++++ drivers/accel/neutron/neutron_driver.h | 13 ++ 9 files changed, 557 insertions(+), 1 deletion(-)
MAINTAINERS +10 -0
@@ -19191,6 +19191,16 @@ S: Orphan F: Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml F: drivers/nfc/nxp-nci +NXP Neutron NPU DRIVER +M: Ioana Ciocoi Radulescu <[email protected]> +M: Jiwei Fu <[email protected]> +L: [email protected] +S: Maintained +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: Documentation/accel/neutron/ +F: drivers/accel/neutron/ +F: include/uapi/drm/neutron_accel.h + NXP/Goodix TFA989X (TFA1) DRIVER M: Stephan Gerhold <[email protected]> L: [email protected]
drivers/accel/Kconfig +1 -0
@@ -28,6 +28,7 @@ source "drivers/accel/amdxdna/Kconfig" source "drivers/accel/ethosu/Kconfig" source "drivers/accel/habanalabs/Kconfig" source "drivers/accel/ivpu/Kconfig" +source "drivers/accel/neutron/Kconfig" source "drivers/accel/qaic/Kconfig" source "drivers/accel/rocket/Kconfig"
drivers/accel/Makefile +2 -1
@@ -4,5 +4,6 @@ obj-$(CONFIG_DRM_ACCEL_AMDXDNA) += amdxdna/ obj-$(CONFIG_DRM_ACCEL_ARM_ETHOSU) += ethosu/ obj-$(CONFIG_DRM_ACCEL_HABANALABS) += habanalabs/ obj-$(CONFIG_DRM_ACCEL_IVPU) += ivpu/ +obj-$(CONFIG_DRM_ACCEL_NXP_NEUTRON) += neutron/ obj-$(CONFIG_DRM_ACCEL_QAIC) += qaic/ -obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/ +obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/
drivers/accel/neutron/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0+ + +config DRM_ACCEL_NXP_NEUTRON + tristate "NXP Neutron NPU" + depends on HAS_IOMEM + depends on DRM_ACCEL + depends on ARCH_MXC + select DRM_GEM_DMA_HELPER + select DRM_SCHED + help + Enables driver for NXP Neutron NPU. + + Select this if you have an NXP SoC with Neutron, like i.MX95, + and want to run machine learning applications. + + If built as module, the module is named neutron.
drivers/accel/neutron/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_DRM_ACCEL_NXP_NEUTRON) := neutron.o + +neutron-y := \ + neutron_driver.o \ + neutron_device.o
drivers/accel/neutron/neutron_device.c new file +160 -0
160 lines not on this page · raw message
drivers/accel/neutron/neutron_device.h new file +120 -0
120 lines not on this page · raw message
drivers/accel/neutron/neutron_driver.c new file +228 -0
228 lines not on this page · raw message
drivers/accel/neutron/neutron_driver.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright 2025 NXP */ + +#ifndef __NEUTRON_DRIVER_H__ +#define __NEUTRON_DRIVER_H__ + +struct neutron_device ; + +struct neutron_file_priv { +struct neutron_device *ndev; +}; + +#endif /* __NEUTRON_DRIVER_H__ */
Signature · 1 line
2.34.1
Re: [PATCH v2 4/9] accel/neutron: Add driver for NXP Neutron NPU
MAINTAINERS S: Orphan · line 19194
Quoted 10 lines · Ioana Ciocoi-Radulescu
MAINTAINERS +1
-0@@ -19191,6 +19191,16 @@ S: Orphan F: Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml F: drivers/nfc/nxp-nci +NXP Neutron NPU DRIVER
s/Neutron/NEUTRON/ as everything here is in uppercase
Quoted 16 lines
MAINTAINERS +8
-0+M: Ioana Ciocoi Radulescu <[email protected]> +M: Jiwei Fu <[email protected]> +L: [email protected] +S: Maintained +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: Documentation/accel/neutron/ +F: drivers/accel/neutron/ +F: include/uapi/drm/neutron_accel.hdrivers/accel/Makefile +0
-0
drivers/accel/Makefile obj-$(CONFIG_DRM_ACCEL_AMDXDNA) += amdxdna/ · line 8
Quoted 7 lines
drivers/accel/Makefile +1
-1@@ -4,5 +4,6 @@ obj-$(CONFIG_DRM_ACCEL_AMDXDNA) += amdxdna/ obj-$(CONFIG_DRM_ACCEL_ARM_ETHOSU) += ethosu/ obj-$(CONFIG_DRM_ACCEL_HABANALABS) += habanalabs/ obj-$(CONFIG_DRM_ACCEL_IVPU) += ivpu/ +obj-$(CONFIG_DRM_ACCEL_NXP_NEUTRON) += neutron/ obj-$(CONFIG_DRM_ACCEL_QAIC) += qaic/ -obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/
You still have patch warnings.
Quoted 7 lines
drivers/accel/Makefile +1
-0+obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/drivers/accel/neutron/Kconfig new file +0
-0
drivers/accel/neutron/Kconfig line 7
Quoted 7 lines
drivers/accel/neutron/Kconfig new file +7
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0+ + +config DRM_ACCEL_NXP_NEUTRON + tristate "NXP Neutron NPU" + depends on HAS_IOMEM + depends on DRM_ACCEL + depends on ARCH_MXC
Missing compile test
Quoted 9 lines
drivers/accel/neutron/Kconfig new file +9
-0+ select DRM_GEM_DMA_HELPER + select DRM_SCHED + help + Enables driver for NXP Neutron NPU. + + Select this if you have an NXP SoC with Neutron, like i.MX95, + and want to run machine learning applications. + + If built as module, the module is named neutron.
...
drivers/accel/neutron/Kconfig
Quoted 6 lines
drivers/accel/neutron/Kconfig new file +6
-0+ + ret = devm_request_threaded_irq(dev, ndev->irq, NULL, + neutron_irq_handler_thread, + IRQF_ONESHOT, KBUILD_MODNAME, ndev); + if (ret) { + dev_err(dev, "Failed to request irq %d\n", ndev->irq);
Drop, not needed.
Quoted 76 lines
drivers/accel/neutron/Kconfig new file +76
-0+ return ret; + } + + ret = of_reserved_mem_device_init(&pdev->dev); + if (ret) { + dev_err(dev, "Failed to initialize reserved memory\n"); + return ret; + } + + ret = devm_pm_runtime_enable(dev); + if (ret) + goto free_reserved; + + pm_runtime_set_autosuspend_delay(dev, NEUTRON_SUSPEND_DELAY_MS); + pm_runtime_use_autosuspend(dev); + + ret = drm_dev_register(&ndev->base, 0); + if (ret) + goto free_reserved; + + return 0; + +free_reserved: + of_reserved_mem_device_release(&pdev->dev); + + return ret; +} + +static void neutron_remove(struct platform_device *pdev) +{ + struct neutron_device *ndev = platform_get_drvdata(pdev); + + drm_dev_unregister(&ndev->base); + of_reserved_mem_device_release(&pdev->dev); +} + +static int neutron_runtime_suspend(struct device *dev) +{ + struct neutron_device *ndev = dev_get_drvdata(dev); + + neutron_disable_irq(ndev); + neutron_shutdown(ndev); + + clk_bulk_disable_unprepare(ndev->num_clks, ndev->clks); + + return 0; +} + +static int neutron_runtime_resume(struct device *dev) +{ + struct neutron_device *ndev = dev_get_drvdata(dev); + int ret; + + ret = clk_bulk_prepare_enable(ndev->num_clks, ndev->clks); + if (ret) + return ret; + + ret = neutron_boot(ndev); + if (ret) { + clk_bulk_disable_unprepare(ndev->num_clks, ndev->clks); + return ret; + } + + neutron_enable_irq(ndev); + + return 0; +} + +static const struct dev_pm_ops neutron_pm_ops = { + SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) + RUNTIME_PM_OPS(neutron_runtime_suspend, neutron_runtime_resume, NULL) +}; + +static const struct of_device_id neutron_match_table[] = { + { .compatible = "nxp,imx95-neutron" }, + {}
drivers/accel/neutron/Kconfig
Quoted 10 lines
drivers/accel/neutron/Kconfig new file +10
-0+}; + +MODULE_DEVICE_TABLE(of, neutron_match_table); + +static struct platform_driver neutron_driver = { + .probe = &neutron_probe, + .remove = &neutron_remove, + .driver = { + .name = "neutron", + .of_match_table = of_match_ptr(neutron_match_table),
Drop of_match_ptr. You will have (or you have already same as v1) here warning.
drivers/accel/neutron/Kconfig
Quoted 3 lines
drivers/accel/neutron/Kconfig new file +3
-0+ .pm = pm_ptr(&neutron_pm_ops), + }, +};
Best regards,
Krzysztof
RE: [PATCH v2 4/9] accel/neutron: Add driver for NXP Neutron NPU
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Ioana Ciocoi-Radulescu
MAINTAINERS index renamed from MAINTAINERS +0
-0
8a5b27b061da..f7a687eb6b54100644MAINTAINERS +0
-0@@ -19191,6 +19191,16 @@ S: Orphan F: Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml F: drivers/nfc/nxp-nci
Quoted 3 lines
MAINTAINERS S: Orphan · line 19194
Quoted 1 line
MAINTAINERS +1
-0+NXP Neutron NPU DRIVERs/Neutron/NEUTRON/ as everything here is in uppercase
Ok.
Quoted 18 lines
drivers/accel/Makefile obj-$(CONFIG_DRM_ACCEL_AMDXDNA) +=
Quoted 17 lines
MAINTAINERS +8
-0+M: Ioana Ciocoi Radulescu <[email protected]> +M: Jiwei Fu <[email protected]> +L: [email protected] +S: Maintained +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: Documentation/accel/neutron/ +F: drivers/accel/neutron/ +F: include/uapi/drm/neutron_accel.hdrivers/accel/Makefile index renamed from drivers/accel/Makefile +0
-0
1d3a7251b950..698136e12cce100644drivers/accel/Makefile +0
-0@@ -4,5 +4,6 @@ obj-$(CONFIG_DRM_ACCEL_AMDXDNA) +=amdxdna/
Quoted 9 lines
drivers/accel/Makefile obj-$(CONFIG_DRM_ACCEL_AMDXDNA) += amdxdna/ · line 8
Quoted 7 lines
drivers/accel/Makefile +1
-1obj-$(CONFIG_DRM_ACCEL_ARM_ETHOSU) += ethosu/ obj-$(CONFIG_DRM_ACCEL_HABANALABS) += habanalabs/ obj-$(CONFIG_DRM_ACCEL_IVPU) += ivpu/ +obj-$(CONFIG_DRM_ACCEL_NXP_NEUTRON) += neutron/ obj-$(CONFIG_DRM_ACCEL_QAIC) += qaic/ -obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/You still have patch warnings.
Yeah, so the last line of this Makefile lacked the line ending and vim fixed that on its own when I edited the file. I can add the neutron line and leave the rest untouched, just making sure this is what you're requesting?
Quoted 17 lines
Quoted 8 lines
drivers/accel/Makefile +1
-0+obj-$(CONFIG_DRM_ACCEL_ROCKET) += rocket/(quoted diff) +0
-0b/drivers/accel/neutron/Kconfig new file mode 100644 index 000000000000..37b8ecb49804
drivers/accel/neutron/Kconfig line 7
Quoted 7 lines
drivers/accel/neutron/Kconfig new file +7
-0@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0+ + +config DRM_ACCEL_NXP_NEUTRON + tristate "NXP Neutron NPU" + depends on HAS_IOMEM + depends on DRM_ACCEL + depends on ARCH_MXCMissing compile test
Will add.
Quoted 18 lines
Quoted 10 lines
drivers/accel/neutron/Kconfig new file +9
-0+ select DRM_GEM_DMA_HELPER + select DRM_SCHED + help + Enables driver for NXP Neutron NPU. + + Select this if you have an NXP SoC with Neutron, like i.MX95, + and want to run machine learning applications. + + If built as module, the module is named neutron....
drivers/accel/neutron/Kconfig
Quoted 4 lines
drivers/accel/neutron/Kconfig new file +4
-0+ + ret = devm_request_threaded_irq(dev, ndev->irq, NULL, + neutron_irq_handler_thread, + IRQF_ONESHOT, KBUILD_MODNAME,ndev);
Quoted 4 lines
drivers/accel/neutron/Kconfig
Quoted 2 lines
drivers/accel/neutron/Kconfig new file +2
-0+ if (ret) { + dev_err(dev, "Failed to request irq %d\n", ndev->irq);Drop, not needed.
Ok
Quoted 89 lines
Quoted 5 lines
drivers/accel/neutron/Kconfig new file +4
-0+ return ret; + } + + ret = of_reserved_mem_device_init(&pdev->dev);drivers/accel/neutron/Kconfig
Quoted 10 lines
drivers/accel/neutron/Kconfig new file +10
-0+ if (ret) { + dev_err(dev, "Failed to initialize reserved memory\n"); + return ret; + } + + ret = devm_pm_runtime_enable(dev); + if (ret) + goto free_reserved; + + pm_runtime_set_autosuspend_delay(dev,
NEUTRON_SUSPEND_DELAY_MS);Quoted 43 lines
drivers/accel/neutron/Kconfig new file +43
-0+ pm_runtime_use_autosuspend(dev); + + ret = drm_dev_register(&ndev->base, 0); + if (ret) + goto free_reserved; + + return 0; + +free_reserved: + of_reserved_mem_device_release(&pdev->dev); + + return ret; +} + +static void neutron_remove(struct platform_device *pdev) { + struct neutron_device *ndev = platform_get_drvdata(pdev); + + drm_dev_unregister(&ndev->base); + of_reserved_mem_device_release(&pdev->dev); +} + +static int neutron_runtime_suspend(struct device *dev) { + struct neutron_device *ndev = dev_get_drvdata(dev); + + neutron_disable_irq(ndev); + neutron_shutdown(ndev); + + clk_bulk_disable_unprepare(ndev->num_clks, ndev->clks); + + return 0; +} + +static int neutron_runtime_resume(struct device *dev) { + struct neutron_device *ndev = dev_get_drvdata(dev); + int ret; + + ret = clk_bulk_prepare_enable(ndev->num_clks, ndev->clks); + if (ret) + return ret; + + ret = neutron_boot(ndev); + if (ret) { + clk_bulk_disable_unprepare(ndev->num_clks, ndev->clks);drivers/accel/neutron/Kconfig
Quoted 10 lines
drivers/accel/neutron/Kconfig new file +10
-0+ return ret; + } + + neutron_enable_irq(ndev); + + return 0; +} + +static const struct dev_pm_ops neutron_pm_ops = { + SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
pm_runtime_force_resume)drivers/accel/neutron/Kconfig
Quoted 1 line
drivers/accel/neutron/Kconfig new file +1
-0+ RUNTIME_PM_OPS(neutron_runtime_suspend,
neutron_runtime_resume,Quoted 5 lines
drivers/accel/neutron/Kconfig new file +5
-0+NULL) }; + +static const struct of_device_id neutron_match_table[] = { + { .compatible = "nxp,imx95-neutron" }, + {}drivers/accel/neutron/Kconfig
Quoted 10 lines
drivers/accel/neutron/Kconfig new file +10
-0+}; + +MODULE_DEVICE_TABLE(of, neutron_match_table); + +static struct platform_driver neutron_driver = { + .probe = &neutron_probe, + .remove = &neutron_remove, + .driver = { + .name = "neutron", + .of_match_table =
of_match_ptr(neutron_match_table),
Quoted 2 lines
Drop
of_match_ptr. You will have (or you have already same as v1) here warning.
Will fix. But how do I get to see the warning here? Tried building with W=1 and OF support disabled but it didn't complain.
Thanks!
Ioana
Quoted 6 lines
drivers/accel/neutron/Kconfig
Quoted 4 lines
drivers/accel/neutron/Kconfig new file +3
-0+ .pm = pm_ptr(&neutron_pm_ops), + }, +};Best regards,
Krzysztof
PATCH v2 5/9 accel/neutron: Add GEM buffer object support
In reply to Ioana Ciocoi-RadulescuAdd the following IOCTLs:
- CREATE_BO - for creating a new buffer object and passing BO info back to user
- SYNC_BO - for explicit DMA sync operations on the BO memory, since Neutron isn't guaranteed to be cache coherent. User controls which portions of the buffer memory to sync and the direction.
The Neutron device requires contiguous DMA buffers, so use the GEM DMA helpers for creating and managing the BOs. Depending on the platform it is integrated on, Neutron device may or may not be cache coherent. On i.MX95, the first platform for which we add Neutron support, it is not.
---
v2: Fix use of uninitialized variable
--- drivers/accel/neutron/Makefile | 3 +- drivers/accel/neutron/neutron_driver.c | 13 +++- drivers/accel/neutron/neutron_gem.c | 116 +++++++++++++++++++++++++++++++++ drivers/accel/neutron/neutron_gem.h | 14 ++++ include/uapi/drm/neutron_accel.h | 79 ++++++++++++++++++++++ 5 files changed, 223 insertions(+), 2 deletions(-)
drivers/accel/neutron/Makefile +2 -1
@@ -4,4 +4,5 @@ obj-$(CONFIG_DRM_ACCEL_NXP_NEUTRON) := neutron.o neutron-y := \ neutron_driver.o \ - neutron_device.o + neutron_device.o \ + neutron_gem.o
drivers/accel/neutron/neutron_driver.c +12 -1
@@ -14,12 +14,19 @@#include <drm/drm_drv.h> #include <drm/drm_ioctl.h> #include <drm/drm_gem.h> +#include <drm/neutron_accel.h> #include "neutron_device.h" #include "neutron_driver.h" +#include "neutron_gem.h" #define NEUTRON_SUSPEND_DELAY_MS 1000 +static const struct drm_ioctl_desc neutron_drm_ioctls[] = { +DRM_IOCTL_DEF_DRV (NEUTRON_CREATE_BO , neutron_ioctl_create_bo,0 ), +DRM_IOCTL_DEF_DRV (NEUTRON_SYNC_BO , neutron_ioctl_sync_bo,0 ), +}; +static int neutron_open (struct drm_device *drm,struct drm_file *file) {struct neutron_device *ndev =to_neutron_device (drm);
@@ -45,7 +52,7 @@ static void neutron_postclose(struct drm_device *drm, struct drm_file *file)DEFINE_DRM_ACCEL_FOPS (neutron_drm_driver_fops);static const struct drm_driver neutron_drm_driver = { - .driver_features =DRIVER_COMPUTE_ACCEL , + .driver_features =DRIVER_COMPUTE_ACCEL |DRIVER_GEM , .name ="neutron" , .desc ="NXP Neutron driver" , .major =1 ,
@@ -54,6 +61,10 @@ static const struct drm_driver neutron_drm_driver = { .fops = &neutron_drm_driver_fops, .open = neutron_open, .postclose = neutron_postclose, + .ioctls = neutron_drm_ioctls, + .num_ioctls = ARRAY_SIZE(neutron_drm_ioctls), + + .gem_create_object = neutron_gem_create_object, };static irqreturn_t neutron_irq_handler_thread (int irq,void *data)
drivers/accel/neutron/neutron_gem.c new file +116 -0
116 lines not on this page · raw message
drivers/accel/neutron/neutron_gem.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright 2025-2026 NXP */ + +#ifndef __NEUTRON_GEM_H__ +#define __NEUTRON_GEM_H__ + +#include <drm/drm_gem.h> + +struct drm_gem_object *neutron_gem_create_object (struct drm_device *drm,size_t size); + +int neutron_ioctl_create_bo (struct drm_device *drm,void *data,struct drm_file *filp); +int neutron_ioctl_sync_bo (struct drm_device *drm,void *data,struct drm_file *filp); + +#endif /* __NEUTRON_GEM_H__ */
include/uapi/drm/neutron_accel.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 6/9 accel/neutron: Add mailbox support
In reply to Ioana Ciocoi-RadulescuThe driver communicates with the Neutron firmware via eight register-backed mailboxes. A subset of the mailbox registers are used to pass commands from driver to Neutron, while the rest are written by Neutron firmware with status/ack info.
--- drivers/accel/neutron/Makefile | 3 ++- drivers/accel/neutron/neutron_device.c | 4 +++ drivers/accel/neutron/neutron_mailbox.c | 47 +++++++++++++++++++++++++++++++++ drivers/accel/neutron/neutron_mailbox.h | 42 +++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-)
drivers/accel/neutron/Makefile +2 -1
@@ -5,4 +5,5 @@ obj-$(CONFIG_DRM_ACCEL_NXP_NEUTRON) := neutron.o neutron-y := \ neutron_driver.o \ neutron_device.o \ - neutron_gem.o + neutron_gem.o \ + neutron_mailbox.o
drivers/accel/neutron/neutron_device.c +4 -0
@@ -7,6 +7,7 @@#include <linux/iopoll.h> #include "neutron_device.h" +#include "neutron_mailbox.h" void neutron_enable_irq (struct neutron_device *ndev) {
@@ -148,6 +149,9 @@ int neutron_boot(struct neutron_device *ndev)if (ret)return ret; +/* Prepare device to receive jobs */ +neutron_mbox_reset_state (ndev); + ndev->flags |=NEUTRON_BOOTED ;return 0 ;
drivers/accel/neutron/neutron_mailbox.c new file +47 -0
47 lines not on this page · raw message
drivers/accel/neutron/neutron_mailbox.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 7/9 accel/neutron: Add job submission IOCTL
In reply to Ioana Ciocoi-RadulescuNeutron can execute a single job at a time. For now, only inference jobs are supported. Each job has exactly one BO associated with it.
When submitting a job, user also provides a syncobj handle on which it will wait for job completion.
We use the DRM GPU scheduler for job management. Large part of the job submission code is based on the example of the ethosu driver.
---
v2:
- drop fence_lock
- remove unnecessary fields from struct neutron_job
--- drivers/accel/neutron/Makefile | 1 + drivers/accel/neutron/neutron_device.c | 8 +- drivers/accel/neutron/neutron_device.h | 18 ++ drivers/accel/neutron/neutron_driver.c | 28 ++- drivers/accel/neutron/neutron_driver.h | 3 + drivers/accel/neutron/neutron_job.c | 372 +++++++++++++++++++++++++++++++++ drivers/accel/neutron/neutron_job.h | 43 ++++ include/uapi/drm/neutron_accel.h | 51 +++++ 8 files changed, 519 insertions(+), 5 deletions(-)
drivers/accel/neutron/Makefile +1 -0
@@ -6,4 +6,5 @@ neutron-y := \ neutron_driver.o \ neutron_device.o \ neutron_gem.o \ + neutron_job.o \ neutron_mailbox.o
drivers/accel/neutron/neutron_device.c +7 -1
@@ -7,6 +7,7 @@#include <linux/iopoll.h> #include "neutron_device.h" +#include "neutron_job.h" #include "neutron_mailbox.h" void neutron_enable_irq (struct neutron_device *ndev)
@@ -32,9 +33,14 @@ void neutron_handle_irq(struct neutron_device *ndev)/* Write 1 to clear */ writel_relaxed (appstatus &APPSTATUS_CLEAR_MASK ,NEUTRON_REG (ndev,APPSTATUS )); -if (appstatus &APPSTATUS_FAULTCAUSE_MASK ) +if (appstatus &APPSTATUS_FAULTCAUSE_MASK ) {dev_err (ndev->dev,"Neutron halted due to fault: 0x%lx\n" ,FIELD_GET (APPSTATUS_FAULTCAUSE_MASK , appstatus)); +return neutron_job_err_handler (ndev); + } + +if (appstatus &APPSTATUS_INFDONE ) +neutron_job_done_handler (ndev); }#define neutron_boot_done (appctrl) \
drivers/accel/neutron/neutron_device.h +18 -0
@@ -9,8 +9,10 @@#include <linux/spinlock.h> #include <linux/bits.h> #include <drm/drm_device.h> +#include <drm/gpu_scheduler.h> struct clk_bulk_data ; +struct neutron_job ;#define NEUTRON_FIRMWARE_NAME "NeutronFirmware.elf"
@@ -92,6 +94,12 @@ enum neutron_mem_id {* @clks: Neutron clocks * @num_clks: Number of clocks * @flags: Software flags used by driver +* @sched: GPU scheduler +* @sched_lock: Scheduler lock, for neutron_push_job +* @fence_context: Fence context +* @job_seqno: Job sequence number +* @job_lock: Job lock, for active_job handling +* @active_job: Currently active job */ struct neutron_device {struct drm_device base;
@@ -103,6 +111,16 @@ struct neutron_device {struct clk_bulk_data *clks;int num_clks;u32 flags; + +struct drm_gpu_scheduler sched; +/* For neutron_push_job */ +struct mutex sched_lock; +u64 fence_context; +u64 job_seqno; + +/* For active_job handling */ +struct mutex job_lock; +struct neutron_job *active_job; };#define to_neutron_device (drm) \
drivers/accel/neutron/neutron_driver.c +24 -4
@@ -19,40 +19,53 @@#include "neutron_device.h" #include "neutron_driver.h" #include "neutron_gem.h" +#include "neutron_job.h" #define NEUTRON_SUSPEND_DELAY_MS 1000static const struct drm_ioctl_desc neutron_drm_ioctls[] = {DRM_IOCTL_DEF_DRV (NEUTRON_CREATE_BO , neutron_ioctl_create_bo,0 ),DRM_IOCTL_DEF_DRV (NEUTRON_SYNC_BO , neutron_ioctl_sync_bo,0 ), +DRM_IOCTL_DEF_DRV (NEUTRON_SUBMIT_JOB , neutron_ioctl_submit_job,0 ), };static int neutron_open (struct drm_device *drm,struct drm_file *file) {struct neutron_device *ndev =to_neutron_device (drm);struct neutron_file_priv *npriv; +int ret; npriv =kzalloc_obj (*npriv);if (!npriv)return -ENOMEM ; npriv->ndev = ndev; - file->driver_priv = npriv; + ret =neutron_job_open (npriv); +if (ret) + goto err_free; + + file->driver_priv = npriv;return 0 ; + +err_free: +kfree (npriv); +return ret; }static void neutron_postclose (struct drm_device *drm,struct drm_file *file) {struct neutron_file_priv *npriv = file->driver_priv; +neutron_job_close (npriv);kfree (npriv); }DEFINE_DRM_ACCEL_FOPS (neutron_drm_driver_fops);static const struct drm_driver neutron_drm_driver = { - .driver_features =DRIVER_COMPUTE_ACCEL |DRIVER_GEM , + .driver_features =DRIVER_COMPUTE_ACCEL |DRIVER_GEM | +DRIVER_SYNCOBJ , .name ="neutron" , .desc ="NXP Neutron driver" , .major =1 ,
@@ -151,19 +164,25 @@ static int neutron_probe(struct platform_device *pdev)return ret; } - ret =devm_pm_runtime_enable (dev); + ret =neutron_job_init (ndev);if (ret) goto free_reserved; + ret =devm_pm_runtime_enable (dev); +if (ret) + goto free_job; +pm_runtime_set_autosuspend_delay (dev,NEUTRON_SUSPEND_DELAY_MS );pm_runtime_use_autosuspend (dev); ret =drm_dev_register (&ndev->base,0 );if (ret) - goto free_reserved; + goto free_job;return 0 ; +free_job: +neutron_job_fini (ndev); free_reserved:of_reserved_mem_device_release (&pdev->dev);
@@ -175,6 +194,7 @@ static void neutron_remove(struct platform_device *pdev)struct neutron_device *ndev =platform_get_drvdata (pdev);drm_dev_unregister (&ndev->base); +neutron_job_fini (ndev);of_reserved_mem_device_release (&pdev->dev); }
drivers/accel/neutron/neutron_driver.h +3 -0
@@ -4,10 +4,13 @@#ifndef __NEUTRON_DRIVER_H__#define __NEUTRON_DRIVER_H__ +#include <drm/gpu_scheduler.h> +struct neutron_device ;struct neutron_file_priv {struct neutron_device *ndev; +struct drm_sched_entity sched_entity; };#endif /* __NEUTRON_DRIVER_H__ */
drivers/accel/neutron/neutron_job.c new file +372 -0
372 lines not on this page · raw message
drivers/accel/neutron/neutron_job.h new file +43 -0
43 lines not on this page · raw message
include/uapi/drm/neutron_accel.h +51 -0
73 lines not on this page · raw message
Signature · 1 line
2.34.1
Frank Li
maintainerRe: [PATCH v2 7/9] accel/neutron: Add job submission IOCTL
From: Frank Li (AI-BOT) <[email protected]>
drivers/accel/neutron/neutron_device.c void neutron_handle_irq(struct neutron_device *ndev) · line 39
Quoted 4 lines
drivers/accel/neutron/neutron_device.c +4
-0+if (appstatus &APPSTATUS_FAULTCAUSE_MASK ) { +dev_err (ndev->dev,"Neutron halted due to fault: 0x%lx\n" , +FIELD_GET (APPSTATUS_FAULTCAUSE_MASK , appstatus)); +return neutron_job_err_handler (ndev);
AI: neutron_job_err_handler() returns void, not int. Remove 'return'.
Quoted 10 lines
drivers/accel/neutron/neutron_job.c new file +10
-0+ ret =drm_sched_job_init (&job->base, &npriv->sched_entity,1 ,NULL , + filp->client_id); +if (ret) + goto out_put_syncobj; + + ret =neutron_push_job (job, syncobj); +if (ret) + goto out_sched_cleanup; + +neutron_put_job (job);
drivers/accel/neutron/neutron_job.c line 365
Quoted 10 lines
drivers/accel/neutron/neutron_job.c new file +10
-0+drm_syncobj_put (syncobj); + +return 0 ; + +out_sched_cleanup: +drm_sched_job_cleanup (&job->base); +out_put_syncobj: +drm_syncobj_put (syncobj); +out_put_gem: +drm_gem_object_put (job->bo);
AI: In the success path, neutron_put_job(job) is called which decrements refcnt. But if neutron_push_job() fails and we hit out_sched_cleanup, the job refcnt is never decremented. This leaks the job structure.
Consider: if neutron_push_job() succeeds, it calls kref_get() inside sched_lock. If it fails, no kref_get() happens, so don't call
(Need owner do judgment. Not sure if AI said correctly.)
Frank
RE: [PATCH v2 7/9] accel/neutron: Add job submission IOCTL
Quoted 7 lines · Frank Li
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (appstatus & APPSTATUS_FAULTCAUSE_MASK) { + dev_err(ndev->dev, "Neutron halted due to fault: 0x%lx\n", + FIELD_GET(APPSTATUS_FAULTCAUSE_MASK,appstatus));
Review
Quoted 1 line
(quoted diff) +1
-0+ return neutron_job_err_handler(ndev);AI:
neutron_job_err_handler()returns void, not int. Remove 'return'.
Ok, will fix.
Quoted 28 lines
Quoted 11 lines
drivers/accel/neutron/neutron_job.c new file +10
-0+ ret =drm_sched_job_init (&job->base, &npriv->sched_entity,1 ,NULL , + filp->client_id); +if (ret) + goto out_put_syncobj; + + ret =neutron_push_job (job, syncobj); +if (ret) + goto out_sched_cleanup; + +neutron_put_job (job);drivers/accel/neutron/neutron_job.c line 365
Quoted 10 lines
drivers/accel/neutron/neutron_job.c new file +10
-0+drm_syncobj_put (syncobj); + +return 0 ; + +out_sched_cleanup: +drm_sched_job_cleanup (&job->base); +out_put_syncobj: +drm_syncobj_put (syncobj); +out_put_gem: +drm_gem_object_put (job->bo);AI: In the success path,
neutron_put_job(job)is called which decrements refcnt. But ifneutron_push_job()fails and we hitout_sched_cleanup, the job refcnt is never decremented. This leaks the job structure.
Consider: ifneutron_push_job()succeeds, it callskref_get()insidesched_lock. If it fails, nokref_get()happens, so don't call
Quoted 1 line
(Need owner do judgment. Not sure if AI said correctly.)
I don't see an issue here, kref_get() is called at a point where neutron_push_job() can't fail anymore. And if neutron_push_job() fails earlier, error path looks clean, it frees everything in reverse order, including the job struct.
Btw, what agent did you use for review?
Thanks,
Ioana
Quoted 2 lines
Frank
PATCH v2 8/9 accel/neutron: Add logging support
In reply to Ioana Ciocoi-RadulescuExpose the Neutron firmware log via debugfs interface. The log resides in internal device memory.
--- drivers/accel/neutron/Makefile | 2 + drivers/accel/neutron/neutron_debugfs.c | 34 ++++++++++++++++ drivers/accel/neutron/neutron_debugfs.h | 15 +++++++ drivers/accel/neutron/neutron_device.c | 69 +++++++++++++++++++++++++++++++++ drivers/accel/neutron/neutron_device.h | 17 ++++++++ drivers/accel/neutron/neutron_driver.c | 3 ++ 6 files changed, 140 insertions(+)
drivers/accel/neutron/Makefile +2 -0
@@ -8,3 +8,5 @@ neutron-y := \ neutron_gem.o \ neutron_job.o \ neutron_mailbox.o + +neutron-$(CONFIG_DEBUG_FS) += neutron_debugfs.o
drivers/accel/neutron/neutron_debugfs.c new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright 2025 NXP */ + +#include <linux/debugfs.h> + +#include "neutron_device.h" +#include "neutron_debugfs.h" + +static ssize_t fw_log_read (struct file *f,char __user *buf,size_t count,loff_t *pos) +{ +struct neutron_device *ndev =file_inode (f)->i_private; + +if (!ndev->log.size) +return 0 ; + +if (ndev->flags &NEUTRON_BOOTED ) +neutron_read_log (ndev, count); + +return simple_read_from_buffer (buf, count, pos, ndev->log.buf, + ndev->log.buf_count); +} + +static const struct file_operations fw_log_fops = { + .owner =THIS_MODULE , + .read = fw_log_read, +}; + +void neutron_debugfs_init (struct neutron_device *ndev) +{ +struct dentry *debugfs_root; + + debugfs_root = ndev->base.debugfs_root; +debugfs_create_file ("fw_log" ,0444 , debugfs_root, ndev, &fw_log_fops); +}
drivers/accel/neutron/neutron_debugfs.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* Copyright 2025 NXP */ + +#ifndef __NEUTRON_DEBUGFS_H__ +#define __NEUTRON_DEBUGFS_H__ + +struct neutron_device ; + +#if defined(CONFIG_DEBUG_FS ) +void neutron_debugfs_init (struct neutron_device *ndev); +#else +static inline void neutron_debugfs_init (struct neutron_device *ndev) {} +#endif + +#endif /* __NEUTRON_DEBUGFS_H__ */
drivers/accel/neutron/neutron_device.c +69 -0
87 lines not on this page · raw message
drivers/accel/neutron/neutron_device.h +17 -0
@@ -85,11 +85,26 @@ enum neutron_mem_id { NEUTRON_MEM_MAX }; +/** +* struct neutron_log - Neutron log buffer descriptor +* @base: base address of the log buffer in device memory +* @size: Size of the log buffer +* @buf: Kernel buffer for log data +* @buf_count: Number of bytes available in the kernel buffer +*/ +struct neutron_log { +void __iomem *base; +size_t size; +void *buf; +size_t buf_count; +}; +/** * struct neutron_device - Neutron device structure * @base: Base DRM device * @dev: Pointer to underlying device * @mem_regions: Array of memory region descriptors +* @log: Log buffer descriptor * @irq: IRQ number * @clks: Neutron clocks * @num_clks: Number of clocks
@@ -106,6 +121,7 @@ struct neutron_device {struct device *dev;struct neutron_mem_region mem_regions[NEUTRON_MEM_MAX ]; +struct neutron_log log;int irq;struct clk_bulk_data *clks;
@@ -134,5 +150,6 @@ void neutron_shutdown(struct neutron_device *ndev);void neutron_enable_irq (struct neutron_device *ndev);void neutron_disable_irq (struct neutron_device *ndev);void neutron_handle_irq (struct neutron_device *ndev); +void neutron_read_log (struct neutron_device *ndev,size_t bytes);#endif /* __NEUTRON_DEVICE_H__ */
drivers/accel/neutron/neutron_driver.c +3 -0
@@ -18,6 +18,7 @@#include "neutron_device.h" #include "neutron_driver.h" +#include "neutron_debugfs.h" #include "neutron_gem.h" #include "neutron_job.h"
@@ -168,6 +169,8 @@ static int neutron_probe(struct platform_device *pdev)if (ret) goto free_reserved; +neutron_debugfs_init (ndev); + ret =devm_pm_runtime_enable (dev);if (ret) goto free_job;
Signature · 1 line
2.34.1
PATCH v2 9/9 arm64: dts: imx95: Add Neutron node
In reply to Ioana Ciocoi-RadulescuAdd the node for Neutron NPU. Also add a reserved memory region for allocating Neutron buffers, which have a 1MB alignment constraint.
---
v2: Match changes in dt bindings
--- arch/arm64/boot/dts/freescale/imx95.dtsi | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
arch/arm64/boot/dts/freescale/imx95.dtsi +28 -0
@@ -336,6 +336,19 @@ sram1: sram@204c0000 { #size-cells = <1>; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + neutron_pool: neutron-pool { + compatible = "shared-dma-pool"; + size = <0x0 0x8000000>; + alignment = <0x0 0x100000>; + reusable; + }; + }; + firmware { scmi { compatible = "arm,scmi";
@@ -2181,5 +2194,20 @@ ddr-pmu@4e090dc0 { reg = <0x0 0x4e090dc0 0x0 0x200>; interrupts = <GIC_SPI 91 IRQ_TYPE_LEVEL_HIGH>; }; + + neutron: npu@4ab00000 { + compatible = "nxp,imx95-neutron"; + reg = <0x0 0x4ab00000 0x0 0x00000400>, + <0x0 0x4ab10000 0x0 0x00010000>, + <0x0 0x4ab08000 0x0 0x00008000>; + reg-names = "regs", "itcm", "dtcm"; + memory-region = <&neutron_pool>; + interrupts = <GIC_SPI 318 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&scmi_clk IMX95_CLK_NPU>, + <&scmi_clk IMX95_CLK_NPUAPB>; + clock-names = "core", "apb"; + power-domains = <&scmi_devpd IMX95_PD_NPU>; + iommus = <&smmu 0xd>; + }; }; };
Signature · 1 line
2.34.1
Hi Ioana,
Looks like the userspace portion of the driver is closed source (libNeutronDriver.so)?
https://github.com/nxp-imx/tflite-neutron-delegate/blob/lf-6.12.49_2.2.0/CMakeLists.txt
Regards,
Tomeu
Quoted 85 lines · Ioana Ciocoi-Radulescu
Introduce a new accel driver for the Neutron Neural Processing Unit (NPU), along with associated dt-bindings and DTS node.
The first patch extends the GEM DMA helper APIs to allow bidirectional mapping of non-coherent DMA buffers. While not part of the Neutron driver, it's a prerequisite allowing us to use the GEM DMA helper.
Neutron is a Neural Processing Unit from NXP, providing machine learning (ML) acceleration for edge AI applications. Neutron is integrated on NXP SoCs such as the i.MX95.
The NPU consists of the following:
- RISC-V core running a proprietary firmware
- One or more Neutron cores, representing the main computation engine performing ML operations
- Dedicated fast memory (TCM)
- DMA engine that handles data transfers between DDR and TCMThe firmware is closed source and distributed as a binary here [1].
The Neutron software stack also contains a userspace library [1] and a LiteRT custom delegate [2] that allow integration with standard LiteRT tools.
[1] https://github.com/nxp-upstream/neutron/tree/upstream
[2] https://github.com/nxp-imx/tflite-neutron-delegateSigned-off-by Ioana Ciocoi-Radulescu <[email protected]>---
Changes in v2:
- rebase on newer drm-misc-next
- dt bindings: clock fixes and renames
- update DTS to match new names
- remove unnecessary fields fromneutron_jobstructure
- fix use of uninitialized variable- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ioana Ciocoi-Radulescu (9):
drm/gem-dma: Add flag for bidirectional mapping of non-coherent GEM DMA buffers accel/neutron: Add documentation for NXP Neutron accelerator driver
dt-bindings: npu: Add NXP Neutron
accel/neutron: Add driver for NXP Neutron NPU
accel/neutron: Add GEM buffer object support
accel/neutron: Add mailbox support
accel/neutron: Add job submission IOCTL
accel/neutron: Add logging support
arm64: dts: imx95: Add Neutron nodeDocumentation/accel/index.rst | 1 + Documentation/accel/neutron/index.rst | 12 + Documentation/accel/neutron/neutron.rst | 131 ++++++++ .../devicetree/bindings/npu/nxp,imx95-neutron.yaml | 96 ++++++ MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx95.dtsi | 28 ++ drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 3 +- drivers/accel/neutron/Kconfig | 16 + drivers/accel/neutron/Makefile | 12 + drivers/accel/neutron/neutron_debugfs.c | 34 ++ drivers/accel/neutron/neutron_debugfs.h | 15 + drivers/accel/neutron/neutron_device.c | 239 +++++++++++++ drivers/accel/neutron/neutron_device.h | 155 +++++++++ drivers/accel/neutron/neutron_driver.c | 262 +++++++++++++++ drivers/accel/neutron/neutron_driver.h | 16 + drivers/accel/neutron/neutron_gem.c | 116 +++++++ drivers/accel/neutron/neutron_gem.h | 14 + drivers/accel/neutron/neutron_job.c | 372 +++++++++++++++++++++ drivers/accel/neutron/neutron_job.h | 43 +++ drivers/accel/neutron/neutron_mailbox.c | 47 +++ drivers/accel/neutron/neutron_mailbox.h | 42 +++ drivers/gpu/drm/drm_gem_dma_helper.c | 6 +- include/drm/drm_gem_dma_helper.h | 3 + include/uapi/drm/neutron_accel.h | 130 +++++++ 25 files changed, 1801 insertions(+), 3 deletions(-)---
base-commit:6716101ae42949e98ad4b9e71eeba08c055be410
change-id: 20260226-neutron-c435e39d167fBest regards,
--
Ioana Ciocoi-Radulescu <[email protected]>
Quoted 8 lines · Tomeu Vizoso
Hi Ioana,
Looks like the userspace portion of the driver is closed source (libNeutronDriver.so)?
https://github.com/nxp-imx/tflite-neutron-delegate/blob/lf-6.12.49_2.2
.0/CMakeLists.txt
Hi Tomeu,
Yes, it's closed for now. We do plan to publish the source code on github, but I believe that's still a few months away.
Thanks,
Ioana
Quoted 95 lines
Regards,
Tomeu
Quoted 37 lines · Ioana Ciocoi-Radulescu
Introduce a new accel driver for the Neutron Neural Processing Unit (NPU), along with associated dt-bindings and DTS node.
The first patch extends the GEM DMA helper APIs to allow bidirectional mapping of non-coherent DMA buffers. While not part of the Neutron driver, it's a prerequisite allowing us to use the GEM DMA helper.
Neutron is a Neural Processing Unit from NXP, providing machine learning (ML) acceleration for edge AI applications. Neutron is integrated on NXP SoCs such as the i.MX95.
The NPU consists of the following:
- RISC-V core running a proprietary firmware
- One or more Neutron cores, representing the main computation engine performing ML operations
- Dedicated fast memory (TCM)
- DMA engine that handles data transfers between DDR and TCMThe firmware is closed source and distributed as a binary here [1].
The Neutron software stack also contains a userspace library [1] and a LiteRT custom delegate [2] that allow integration with standard LiteRT tools.
[1] https://github.com/nxp-upstream/neutron/tree/upstream
[2] https://github.com/nxp-imx/tflite-neutron-delegateSigned-off-by Ioana Ciocoi-Radulescu <[email protected]>---
Changes in v2:
- rebase on newer drm-misc-next
- dt bindings: clock fixes and renames
- update DTS to match new names
- remove unnecessary fields fromneutron_jobstructure
- fix use of uninitialized variableQuoted 6 lines
- Link to v1:
https://lore.kernel.org/r/[email protected]---
Ioana Ciocoi-Radulescu (9):
drm/gem-dma: Add flag for bidirectional mapping of non-coherent GEMDMA buffers
Quoted 20 lines
accel/neutron: Add documentation for NXP Neutron accelerator driver
dt-bindings: npu: Add NXP Neutron
accel/neutron: Add driver for NXP Neutron NPU accel/neutron: Add GEM buffer object support accel/neutron: Add mailbox support
accel/neutron: Add job submission IOCTL
accel/neutron: Add logging support
arm64: dts: imx95: Add Neutron nodeDocumentation/accel/index.rst | 1 + Documentation/accel/neutron/index.rst | 12 + Documentation/accel/neutron/neutron.rst | 131 ++++++++ .../devicetree/bindings/npu/nxp,imx95-neutron.yaml | 96 ++++++ MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx95.dtsi | 28 ++ drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 3 +- drivers/accel/neutron/Kconfig | 16 + drivers/accel/neutron/Makefile | 12 + drivers/accel/neutron/neutron_debugfs.c | 34 ++Quoted 8 lines
drivers/accel/neutron/neutron_debugfs.h | 15 + drivers/accel/neutron/neutron_device.c | 239 +++++++++++++ drivers/accel/neutron/neutron_device.h | 155 +++++++++ drivers/accel/neutron/neutron_driver.c | 262 +++++++++++++++ drivers/accel/neutron/neutron_driver.h | 16 + drivers/accel/neutron/neutron_gem.c | 116 +++++++ drivers/accel/neutron/neutron_gem.h | 14 + drivers/accel/neutron/neutron_job.c | 372+++++++++++++++++++++
Quoted 15 lines
drivers/accel/neutron/neutron_job.h | 43 +++ drivers/accel/neutron/neutron_mailbox.c | 47 +++ drivers/accel/neutron/neutron_mailbox.h | 42 +++ drivers/gpu/drm/drm_gem_dma_helper.c | 6 +- include/drm/drm_gem_dma_helper.h | 3 + include/uapi/drm/neutron_accel.h | 130 +++++++ 25 files changed, 1801 insertions(+), 3 deletions(-)---
base-commit:6716101ae42949e98ad4b9e71eeba08c055be410
change-id: 20260226-neutron-c435e39d167fBest regards,
--
Ioana Ciocoi-Radulescu <[email protected]>
Quoted 7 lines · Ioana Ciocoi Radulescu
Quoted 6 lines · Tomeu Vizoso
Hi Ioana,
Looks like the userspace portion of the driver is closed source (libNeutronDriver.so)?
Quoted 8 lines
Quoted 2 lines
https://github.com/nxp-imx/tflite-neutron-delegate/blob/lf-6.12.49_2.2
.0/CMakeLists.txtHi Tomeu,
Yes, it's closed for now. We do plan to publish the source code on github, but I believe that's still a few months away.
I think you may want to sync with your userspace team sooner rather than later, so you can comply with this requirement:
https://docs.kernel.org/gpu/drm-uapi.html#open-source-userspace-requirements
It could be good to also share firmware code with other firmware-mediated NPU drivers if possible, or at least the part of the rpmsg protocol that makes sense to share.
You can see my submission for the Thames driver for a link to the firmware code.
I would be happy to help consolidate code between this category of drivers if you want.
Regards,
Tomeu
Quoted 102 lines
Thanks,
IoanaQuoted 50 lines
Regards,
Tomeu
Quoted 43 lines · Ioana Ciocoi-Radulescu
Introduce a new accel driver for the Neutron Neural Processing Unit (NPU), along with associated dt-bindings and DTS node.
The first patch extends the GEM DMA helper APIs to allow bidirectional mapping of non-coherent DMA buffers. While not part of the Neutron driver, it's a prerequisite allowing us to use the GEM DMA helper.
Neutron is a Neural Processing Unit from NXP, providing machine learning (ML) acceleration for edge AI applications. Neutron is integrated on NXP SoCs such as the i.MX95.
The NPU consists of the following:
- RISC-V core running a proprietary firmware
- One or more Neutron cores, representing the main computation engine performing ML operations
- Dedicated fast memory (TCM)
- DMA engine that handles data transfers between DDR and TCMThe firmware is closed source and distributed as a binary here [1].
The Neutron software stack also contains a userspace library [1] and a LiteRT custom delegate [2] that allow integration with standard LiteRT tools.
[1] https://github.com/nxp-upstream/neutron/tree/upstream
[2] https://github.com/nxp-imx/tflite-neutron-delegateSigned-off-by Ioana Ciocoi-Radulescu <[email protected]>---
Changes in v2:
- rebase on newer drm-misc-next
- dt bindings: clock fixes and renames
- update DTS to match new names
- remove unnecessary fields fromneutron_jobstructure
- fix use of uninitialized variable- Link to v1:
https://lore.kernel.org/r/[email protected]---
Ioana Ciocoi-Radulescu (9):
drm/gem-dma: Add flag for bidirectional mapping of non-coherentGEM
Quoted 2 lines
DMA buffers
Quoted 1 line
accel/neutron: Add documentation for NXP Neutron accelerator
driver
Quoted 8 lines
Quoted 8 lines
dt-bindings: npu: Add NXP Neutron accel/neutron: Add driver for NXP Neutron NPU accel/neutron: Add GEM buffer object support accel/neutron: Add mailbox support accel/neutron: Add job submission IOCTL accel/neutron: Add logging support
arm64: dts: imx95: Add Neutron nodeQuoted 15 lines
Quoted 7 lines
Documentation/accel/index.rst | 1 + Documentation/accel/neutron/index.rst | 12 + Documentation/accel/neutron/neutron.rst | 131 ++++++++ .../devicetree/bindings/npu/nxp,imx95-neutron.yaml | 96 ++++++ MAINTAINERS | 10 + arch/arm64/boot/dts/freescale/imx95.dtsi | 28 ++ drivers/accel/Kconfig | 1 +Quoted 8 lines
drivers/accel/Makefile | 3 +- drivers/accel/neutron/Kconfig | 16 + drivers/accel/neutron/Makefile | 12 + drivers/accel/neutron/neutron_debugfs.c | 34 ++ drivers/accel/neutron/neutron_debugfs.h | 15 + drivers/accel/neutron/neutron_device.c | 239 +++++++++++++ drivers/accel/neutron/neutron_device.h | 155 +++++++++ drivers/accel/neutron/neutron_driver.c | 262+++++++++++++++
Quoted 20 lines
Quoted 4 lines
drivers/accel/neutron/neutron_driver.h | 16 + drivers/accel/neutron/neutron_gem.c | 116 +++++++ drivers/accel/neutron/neutron_gem.h | 14 + drivers/accel/neutron/neutron_job.c | 372+++++++++++++++++++++
Quoted 15 lines
drivers/accel/neutron/neutron_job.h | 43 +++ drivers/accel/neutron/neutron_mailbox.c | 47 +++ drivers/accel/neutron/neutron_mailbox.h | 42 +++ drivers/gpu/drm/drm_gem_dma_helper.c | 6 +- include/drm/drm_gem_dma_helper.h | 3 + include/uapi/drm/neutron_accel.h | 130 +++++++ 25 files changed, 1801 insertions(+), 3 deletions(-)---
base-commit:6716101ae42949e98ad4b9e71eeba08c055be410
change-id: 20260226-neutron-c435e39d167fBest regards,
--
Ioana Ciocoi-Radulescu <[email protected]>
Quoted 10 lines · Tomeu Vizoso
Quoted 10 lines
Quoted 7 lines
Hi Ioana,
Looks like the userspace portion of the driver is closed source (libNeutronDriver.so)?
https://github.com/nxp-imx/tflite-neutron-delegate/blob/lf-6.12.49_2.2.0/CMakeLists.txt
Hi Tomeu,
Quoted 7 lines
Quoted 2 lines
Yes, it's closed for now. We do plan to publish the source code on github, but I believe that's still a few months away.
I think you may want to sync with your userspace team sooner rather than later, so you can comply with this requirement:
https://docs.kernel.org/gpu/drm-uapi.html#open-source-userspace-requirements
Thanks for bringing this up, it helps us raise internally the priority for the userspace side. In the meantime, I still hope to gather additional feedback on the kernel driver.
Quoted 9 lines
It could be good to also share firmware code with other firmware-mediated NPU drivers if possible, or at least the part of the rpmsg protocol that makes sense to share.
You can see my submission for the Thames driver for a link to the firmware code.
I would be happy to help consolidate code between this category of drivers if you want.
Thanks for the offer. We are considering our options, I'll get back once we reach an internal decision.
Regards,
Ioana