From: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
To: "Tomeu Vizoso" <tomeu@tomeuvizoso.net>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Heiko Stuebner" <heiko@sntech.de>,
"Oded Gabbay" <ogabbay@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"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>,
"Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH v2 4/7] accel/rocket: Add a new driver for Rockchip's NPU
Date: Fri, 21 Mar 2025 09:48:04 -0600 [thread overview]
Message-ID: <f96b313a-fa0d-45d6-b358-8d2da40a9b95@oss.qualcomm.com> (raw)
In-Reply-To: <20250225-6-10-rocket-v2-4-d4dbcfafc141@tomeuvizoso.net>
On 2/25/2025 12:55 AM, Tomeu Vizoso wrote:
>
> diff --git a/Documentation/accel/rocket/index.rst b/Documentation/accel/rocket/index.rst
> new file mode 100644
> index 0000000000000000000000000000000000000000..ad33194dec0325d0dab362768fd349e8dc286970
> --- /dev/null
> +++ b/Documentation/accel/rocket/index.rst
> @@ -0,0 +1,19 @@
> +.. SPDX-License-Identifier: GPL-2.0-only
> +
> +=====================================
> + accel/rocket Rockchip NPU driver
> +=====================================
> +
> +The accel/rocket driver supports the Neural Processing Units (NPUs) inside some Rockchip SoCs such as the RK3588. Rockchip calls it RKNN and sometimes RKNPU.
> +
> +This NPU is closely based on the NVDLA IP released by NVIDIA as open hardware in 2018, along with open source kernel and userspace drivers.
> +
> +The frontend unit in Rockchip's NPU though is completely different from that in the open source IP, so this kernel driver is specific to Rockchip's version.
> +
> +The hardware is described in chapter 36 in the RK3588 TRM.
> +
> +This driver just powers the hardware on and off, allocates and maps buffers to the device and submits jobs to the frontend unit. Everything else is done in userspace, as a Gallium driver that is part of the Mesa3D project.
Nit: name the specific Gallium driver here?
> diff --git a/drivers/accel/rocket/Kconfig b/drivers/accel/rocket/Kconfig
> new file mode 100644
> index 0000000000000000000000000000000000000000..83a401129ab2dc2847ccc30c6364e8802f43648d
> --- /dev/null
> +++ b/drivers/accel/rocket/Kconfig
> @@ -0,0 +1,25 @@
> +# SPDX-License-Identifier: GPL-2.0
I'm curious, is there a specific reason for "GPL-2.0"? This tag is
depreciated and everywhere else in the accel subsystem "GPL-2.0-only" is
used.
Same comment for the Makefile and everything else in this patch.
> +
> +config DRM_ACCEL_ROCKET
> + tristate "Rocket (support for Rockchip NPUs)"
> + depends on DRM
> + depends on ARM64 || COMPILE_TEST
> + depends on MMU
> + select DRM_SCHED
> + select IOMMU_SUPPORT
> + select IOMMU_IO_PGTABLE_LPAE
> + select DRM_GEM_SHMEM_HELPER
> + help
> + Choose this option if you have a Rockchip SoC that contains a
> + compatible Neural Processing Unit (NPU), such as the RK3588. Called by
> + Rockchip either RKNN or RKNPU, it accelerates inference of neural
> + networks.
> +
> + The interface exposed to userspace is described in
> + include/uapi/drm/rocket_accel.h and is used by the userspace driver in
> + Mesa3D.
Nit: name the specific Mesa driver here?
> +
> + If unsure, say N.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called rocket.
> diff --git a/drivers/accel/rocket/rocket_core.c b/drivers/accel/rocket/rocket_core.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..09d966c826b5b1090a18cb24b3aa4aba286a12d4
> --- /dev/null
> +++ b/drivers/accel/rocket/rocket_core.c
> @@ -0,0 +1,71 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright 2024 Tomeu Vizoso <tomeu@tomeuvizoso.net> */
> +
> +#include <linux/clk.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
This list of includes seems insufficient. You use PTR_ERR but don't have
the include for it (linux/err.h). Same for dev_err/dev_info. I'm
guessing this comment applies elsewhere.
> +#include "rocket_core.h"
> +#include "rocket_registers.h"
> +
> +static int rocket_clk_init(struct rocket_core *core)
> +{
> + struct device *dev = core->dev;
> + int err;
> +
> + core->a_clk = devm_clk_get(dev, "aclk");
> + if (IS_ERR(core->a_clk)) {
> + err = PTR_ERR(core->a_clk);
> + dev_err(dev, "devm_clk_get_enabled failed %d for core %d\n", err, core->index);
Do you think it would be useful to mention "aclk" in the message? Seems
like if this or the hclk get fails, you won't know just from the kernel log.
> + return err;
> + }
> +
> + core->h_clk = devm_clk_get(dev, "hclk");
> + if (IS_ERR(core->h_clk)) {
> + err = PTR_ERR(core->h_clk);
> + dev_err(dev, "devm_clk_get_enabled failed %d for core %d\n", err, core->index);
> + clk_disable_unprepare(core->a_clk);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +int rocket_core_init(struct rocket_core *core)
> +{
> + struct device *dev = core->dev;
> + struct platform_device *pdev = to_platform_device(dev);
> + uint32_t version;
> + int err = 0;
> +
> + err = rocket_clk_init(core);
> + if (err) {
> + dev_err(dev, "clk init failed %d\n", err);
This feels redundant since rocket_clk_init() already printed an error
message with more details.
> + return err;
> + }
> +
> + core->iomem = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(core->iomem))
> + return PTR_ERR(core->iomem);
> +
> + pm_runtime_use_autosuspend(dev);
> + pm_runtime_set_autosuspend_delay(dev, 50); /* ~3 frames */
Frames? That feels like a rendering term, but this driver is not doing
rendering, right? Is there a better way to describe this?
> + pm_runtime_enable(dev);
> +
> + err = pm_runtime_get_sync(dev);
> +
> + version = rocket_read(core, REG_PC_VERSION);
> + version += rocket_read(core, REG_PC_VERSION_NUM) & 0xffff;
> +
> + pm_runtime_mark_last_busy(dev);
> + pm_runtime_put_autosuspend(dev);
> +
> + dev_info(dev, "Rockchip NPU core %d version: %d\n", core->index, version);
> +
> + return 0;
> +}
> +
> diff --git a/drivers/accel/rocket/rocket_device.c b/drivers/accel/rocket/rocket_device.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..ce3b533f15c1011d8a7a23dd8132e907cc334c58
> --- /dev/null
> +++ b/drivers/accel/rocket/rocket_device.c
> @@ -0,0 +1,29 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright 2024 Tomeu Vizoso <tomeu@tomeuvizoso.net> */
> +
> +#include <linux/clk.h>
> +
> +#include "rocket_device.h"
> +
> +int rocket_device_init(struct rocket_device *rdev)
> +{
> + struct device *dev = rdev->cores[0].dev;
> + int err;
> +
> + rdev->clk_npu = devm_clk_get(dev, "npu");
> + rdev->pclk = devm_clk_get(dev, "pclk");
Are these optional? It would appear that error handling is missing.
> +
> + /* Initialize core 0 (top) */
> + err = rocket_core_init(&rdev->cores[0]);
> + if (err) {
> + rocket_device_fini(rdev);
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static void rocket_drm_unbind(struct device *dev)
> +{
> + struct rocket_device *rdev = dev_get_drvdata(dev);
> + struct drm_device *ddev = &rdev->ddev;
> +
> + drm_dev_unregister(ddev);
You allocated this with devm, shouldn't that make this unnecessary?
> +
> + component_unbind_all(dev, rdev);
> +
> + rocket_device_fini(rdev);
> +}
next prev parent reply other threads:[~2025-03-21 15:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 7:55 [PATCH v2 0/7] New DRM accel driver for Rockchip's RKNN NPU Tomeu Vizoso
2025-02-25 7:55 ` [PATCH v2 1/7] dt-bindings: npu: rockchip,rknn: Add bindings Tomeu Vizoso
2025-02-25 16:02 ` Rob Herring
2025-05-14 16:26 ` Tomeu Vizoso
2025-04-25 18:50 ` Nicolas Frattaroli
2025-05-14 15:18 ` Tomeu Vizoso
2025-05-14 17:50 ` Nicolas Frattaroli
2025-05-15 8:30 ` Tomeu Vizoso
2025-05-16 10:25 ` Nicolas Frattaroli
2025-05-16 10:56 ` Tomeu Vizoso
2025-02-25 7:55 ` [PATCH v2 2/7] arm64: dts: rockchip: Add nodes for NPU and its MMU to rk3588s Tomeu Vizoso
2025-02-25 7:55 ` [PATCH v2 3/7] arm64: dts: rockchip: Enable the NPU on quartzpro64 Tomeu Vizoso
2025-02-25 7:55 ` [PATCH v2 4/7] accel/rocket: Add a new driver for Rockchip's NPU Tomeu Vizoso
2025-02-25 8:21 ` Thomas Zimmermann
2025-03-21 15:48 ` Jeff Hugo [this message]
2025-04-25 18:22 ` Nicolas Frattaroli
2025-05-16 9:15 ` Tomeu Vizoso
2025-04-29 9:39 ` Nicolas Frattaroli
2025-02-25 7:55 ` [PATCH v2 5/7] accel/rocket: Add IOCTL for BO creation Tomeu Vizoso
2025-02-25 8:35 ` Thomas Zimmermann
2025-03-21 15:56 ` Jeffrey Hugo
2025-02-25 7:55 ` [PATCH v2 6/7] accel/rocket: Add job submission IOCTL Tomeu Vizoso
2025-02-25 8:44 ` Thomas Zimmermann
2025-03-21 16:09 ` Jeff Hugo
2025-04-29 10:05 ` Nicolas Frattaroli
2025-02-25 7:55 ` [PATCH v2 7/7] accel/rocket: Add IOCTLs for synchronizing memory accesses Tomeu Vizoso
2025-03-21 16:15 ` Jeffrey Hugo
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=f96b313a-fa0d-45d6-b358-8d2da40a9b95@oss.qualcomm.com \
--to=jeff.hugo@oss.qualcomm.com \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=heiko@sntech.de \
--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=linux-rockchip@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=ogabbay@kernel.org \
--cc=robh@kernel.org \
--cc=sebastian.reichel@collabora.com \
--cc=simona@ffwll.ch \
--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
all inboxes | Powered by JetHome®