From: Frank Li <Frank.li@nxp.com>
To: Rob Herring <robh@kernel.org>
Cc: "Tomeu Vizoso" <tomeu@tomeuvizoso.net>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"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>,
"Christian König" <christian.koenig@amd.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Steven Price" <steven.price@arm.com>,
"Daniel Stone" <daniel@fooishbar.org>,
"Sui Jingfeng" <sui.jingfeng@linux.dev>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org,
linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH v4 2/2] accel: Add Arm Ethos-U NPU driver
Date: Wed, 15 Oct 2025 17:02:35 -0400 [thread overview]
Message-ID: <aPAL67Oct5yJv8/d@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <CAL_Jsq+L2RHgP9FaEpxzzVRybyjeNr84xgEBbU4KEyZtrz63FA@mail.gmail.com>
On Wed, Oct 15, 2025 at 03:36:05PM -0500, Rob Herring wrote:
> On Wed, Oct 15, 2025 at 2:39 PM Frank Li <Frank.li@nxp.com> wrote:
> >
> > On Wed, Oct 15, 2025 at 12:47:40PM -0500, Rob Herring (Arm) wrote:
> > > Add a driver for Arm Ethos-U65/U85 NPUs. The Ethos-U NPU has a
> > > relatively simple interface with single command stream to describe
> > > buffers, operation settings, and network operations. It supports up to 8
> > > memory regions (though no h/w bounds on a region). The Ethos NPUs
> > > are designed to use an SRAM for scratch memory. Region 2 is reserved
> > > for SRAM (like the downstream driver stack and compiler). Userspace
> > > doesn't need access to the SRAM.
> > >
> > > The h/w has no MMU nor external IOMMU and is a DMA engine which can
> > > read and write anywhere in memory without h/w bounds checks. The user
> > > submitted command streams must be validated against the bounds of the
> > > GEM BOs. This is similar to the VC4 design which validates shaders.
> > >
> > > The job submit is based on the rocket driver for the Rockchip NPU
> > > utilizing the GPU scheduler. It is simpler as there's only 1 core rather
> > > than 3.
> > >
> > > Tested on i.MX93 platform (U65) and FVP (U85) with WIP Mesa Teflon
> > > support.
> > >
> > > Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
> > > Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
> > > ---
> >
> > How to test this driver?
>
> You need to add the DT node to i.MX93 .dts like the example, build the
> mesa ethosu branch, and then run tflite with it pointed to the mesa
> delegate.
>
> I can send an i.MX93 dts patch after this is merged.
>
> > > v4:
> > > - Use bulk clk API
> > > - Various whitespace fixes mostly due to ethos->ethosu rename
> > > - Drop error check on dma_set_mask_and_coherent()
> > > - Drop unnecessary pm_runtime_mark_last_busy() call
> > > - Move variable declarations out of switch (a riscv/clang build failure)
> > > - Use lowercase hex in all defines
> > > - Drop unused ethosu_device.coherent member
> > > - Add comments on all locks
> > >
> > ...
> > > diff --git a/drivers/accel/ethosu/ethosu_device.h b/drivers/accel/ethosu/ethosu_device.h
> > > new file mode 100644
> > > index 000000000000..69d610c5c2d7
> > > --- /dev/null
> > > +++ b/drivers/accel/ethosu/ethosu_device.h
> > > @@ -0,0 +1,190 @@
> > > +/* SPDX-License-Identifier: GPL-2.0-only or MIT */
> > > +/* Copyright 2025 Arm, Ltd. */
> > > +
> > > +#ifndef __ETHOSU_DEVICE_H__
> > > +#define __ETHOSU_DEVICE_H__
> > > +
> > > +#include <linux/types.h>
> > > +
> > > +#include <drm/drm_device.h>
> > > +#include <drm/gpu_scheduler.h>
> > > +
> > > +#include <drm/ethosu_accel.h>
> > > +
> > > +struct clk;
> > > +struct gen_pool;
> >
> > Supposed should include clk.h instead declear a struct.
>
> Headers should only use a forward declaration if that's all they need.
> It keeps the struct opaque for starters.
>
> > ...
> > > +
> > > +static int ethosu_open(struct drm_device *ddev, struct drm_file *file)
> > > +{
> > > + int ret = 0;
> > > + struct ethosu_file_priv *priv;
> > > +
> > > + if (!try_module_get(THIS_MODULE))
> > > + return -EINVAL;
> > > +
> > > + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> > > + if (!priv) {
> > > + ret = -ENOMEM;
> > > + goto err_put_mod;
> > > + }
> > > + priv->edev = to_ethosu_device(ddev);
> > > +
> > > + ret = ethosu_job_open(priv);
> > > + if (ret)
> > > + goto err_free;
> > > +
> > > + file->driver_priv = priv;
> >
> > slice simple.
> >
> > struct ethosu_file_priv __free(kfree) *priv = NULL;
> > ...
> > priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>
> Linus has voiced his opinion that the above should not be done. It
> should be all one line *only*. But now we allow C99 declarations, so
> we can move it down. We can't get rid of the goto for module_put(), so
> it only marginally helps here.
>
> > ...
> >
> > file->driver_priv = no_free_ptr(priv);
> >
> >
> > > + return 0;
> > > +
> > > +err_free:
> > > + kfree(priv);
> > > +err_put_mod:
> > > + module_put(THIS_MODULE);
> > > + return ret;
> > > +}
> > > +
> > ...
> > > +
> > > +
> > > +static int ethosu_init(struct ethosu_device *ethosudev)
> > > +{
> > > + int ret;
> > > + u32 id, config;
> > > +
> > > + ret = devm_pm_runtime_enable(ethosudev->base.dev);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + ret = pm_runtime_resume_and_get(ethosudev->base.dev);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + pm_runtime_set_autosuspend_delay(ethosudev->base.dev, 50);
> > > + pm_runtime_use_autosuspend(ethosudev->base.dev);
> > > +
> > > + /* If PM is disabled, we need to call ethosu_device_resume() manually. */
> > > + if (!IS_ENABLED(CONFIG_PM)) {
> > > + ret = ethosu_device_resume(ethosudev->base.dev);
> > > + if (ret)
> > > + return ret;
> > > + }
> >
> > I think it should call ethosu_device_resume() unconditional before
> > devm_pm_runtime_enable();
> >
> > ethosu_device_resume();
> > pm_runtime_set_active();
> > pm_runtime_set_autosuspend_delay(ethosudev->base.dev, 50);
> > devm_pm_runtime_enable();
>
> Why do you think this? Does this do a get?
>
> I don't think it is good to call the resume hook on our own, but we
> have no choice with !CONFIG_PM. With CONFIG_PM, we should only use the
> pm_runtime API.
Enable clock and do some init work at probe() is quite common. But I never
seen IS_ENABLED(CONFIG_PM) check. It is quite weird and not necessary to
check CONFIG_PM flags. The most CONFIG_PM is enabled, so the branch !CONFIG_PM
almost never tested.
probe()
{
devm_clk_bulk_get_all_enabled();
... did some init work
pm_runtime_set_active();
devm_pm_runtime_enable();
...
pm_runtime_put_autosuspend(ethosudev->base.dev);
}
ethosu_init() only is called by ethosu_probe(). with above pattern,
needn't check CONFIG_PM and call resume hook ethosu_device_resume();
Frank
>
> Rob
next prev parent reply other threads:[~2025-10-15 21:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 17:47 [PATCH v4 0/2] accel: Add Arm Ethos-U NPU Rob Herring (Arm)
2025-10-15 17:47 ` [PATCH v4 1/2] dt-bindings: npu: Add Arm Ethos-U65/U85 Rob Herring (Arm)
2025-10-15 17:47 ` [PATCH v4 2/2] accel: Add Arm Ethos-U NPU driver Rob Herring (Arm)
2025-10-15 19:39 ` Frank Li
2025-10-15 20:36 ` Rob Herring
2025-10-15 21:02 ` Frank Li [this message]
2025-10-16 12:35 ` Rob Herring
2025-10-16 14:48 ` Frank Li
2025-10-15 17:53 ` [PATCH v4 0/2] accel: Add Arm Ethos-U NPU Tomeu Vizoso
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=aPAL67Oct5yJv8/d@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=conor+dt@kernel.org \
--cc=daniel@fooishbar.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=krzk+dt@kernel.org \
--cc=linaro-mm-sig@lists.linaro.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=robin.murphy@arm.com \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=sui.jingfeng@linux.dev \
--cc=sumit.semwal@linaro.org \
--cc=tomeu@tomeuvizoso.net \
--cc=tzimmermann@suse.de \
/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;
as well as URLs for NNTP newsgroup(s).