accel/rocket: RK3576 NPU (RKNN) enablement
Subsystems (7)
v18 cover accel/rocket: RK3576 NPU (RKNN) enablement
This series adds RK3576 NPU (RKNN) support to the mainline rocket driver.
Changes in v18
- Rebased onto next-20261120. Patches 1-4 of v17 are in v7.4-rc4 and are dropped. The pmdomain series has been applied by Ulf (1/3 to fixes, 2/3 and 3/3 to next).
- 4/8 (was 8/12), following Daniel's review: the clocks are taken with devm_clk_bulk_get_all() and the resets as a reset array, so their number is no longer given per SoC and enum rocket_clk is gone. On the RK3588 this changes the reset deassert order: srst_a is now released before srst_h.
- 5/8 (was 10/12): GET_PARAM now comes before the RK3576 support. The hardware version is taken from the match data when the first core probes and stored in rocket_device, so READ_ONCE is not needed and core 0 is not assumed to exist. The driver keeps its own enum rather than PC_VERSION, which reads 0 on the RK3568. The UAPI documentation no longer ties the version to a compatible.
- 6/8 (was 9/12): the RK3576 TASK_CON uses a register definition generated from Mesa's registers.xml, selected by the hardware version. The cores are counted in rocket_drv.c. The "# Conflicts:" lines left in v17 are gone.
- 7/8 and 8/8: test notes removed from the commit messages; 8/8 states its dependency on b1bff9ced657 in Ulf's tree.
- All commit messages shortened.
Review tags
Kept: Reviewed-by from Igor and Heiko and Tested-by from Sidong on 1/8, Reviewed-by from Krzysztof on 2/8, Acked-by from Conor on 3/8. Dropped Sidong's Tested-by on v17 8-10, which were rewritten.
Sidong, could you test this again on the RK3588? The reset and recovery path after a job timeout matters most, since the deassert order has changed.
Testing
Radxa ROCK 4D (RK3576), v7.4-rc4 with this series, in an image built with Armbian:
- Both NPU cores probe.
- GET_PARAM returns the RK3576 hardware version (2); invalid requests return -EINVAL.
- 30 inference runs in a row give identical output, with no job timeout, IOMMU error or SError.
- Booted 3 times with the NPU not enabled: NPUTOP, NPU0 and NPU1 are switched off, and so is the NPU rail.
Known issue
A core reset after a job timeout can leave bank 0 of the IOMMU paging, and the NPU then does not recover. The fix has been sent separately:
https://lore.kernel.org/all/[email protected]/
With repeated forced timeouts on the ROCK 4D, about one in every 2 to 10 is not recovered from without the fix; with it, 20 in a row all recovered.
Notes
- 594 MHz (Daniel's question): mainline does not scale the NPU frequency or voltage yet. The NPU boots at 786 MHz and 750 mV, which is not in the vendor's OPP table. That table runs up to 600 MHz at 725 mV, so 594 MHz is within it.
- npu-supply: the binding requires it and the RK3588 device trees set it, but the driver does not use it. The NPU rail is switched by the power domain through domain-supply.
- The register definitions are generated from Mesa's registers.xml; the XML change will go with Mesa MR !43804.
LLM-assisted.
Jiaxing Hu (8):
accel/rocket: factor the completion tail out of the IRQ handler
dt-bindings: npu: rockchip: add rockchip,rk3576-rknn-core
dt-bindings: iommu: rockchip: describe the RK3576 NPU MMU accel/rocket: take the core clocks and resets from the devicetree accel/rocket: add a GET_PARAM ioctl for the hardware version accel/rocket: add RK3576 NPU (RKNN) support
arm64: dts: rockchip: add NPU (RKNN) nodes to rk3576
arm64: dts: rockchip: enable the NPU on rk3576-rock-4d
.../bindings/iommu/rockchip,iommu.yaml | 26 +++++++ .../npu/rockchip,rk3588-rknn-core.yaml | 40 ++++++++++- .../boot/dts/rockchip/rk3576-rock-4d.dts | 22 ++++++ arch/arm64/boot/dts/rockchip/rk3576.dtsi | 70 ++++++++++++++++++- drivers/accel/rocket/rocket_core.c | 25 +++---- drivers/accel/rocket/rocket_core.h | 13 +--- drivers/accel/rocket/rocket_device.c | 11 +-- drivers/accel/rocket/rocket_device.h | 6 +- drivers/accel/rocket/rocket_drv.c | 52 ++++++++++++-- drivers/accel/rocket/rocket_job.c | 45 ++++++++---- drivers/accel/rocket/rocket_registers.h | 32 +++++++++ include/uapi/drm/rocket_accel.h | 43 ++++++++++++ 12 files changed, 329 insertions(+), 56 deletions(-)
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
Signature · 1 line
2.43.0
PATCH v18 1/8 accel/rocket: factor the completion tail out of the IRQ handler
Move the part of the IRQ handler that starts the next task or finishes the job into rocket_job_next_locked(). No functional change.
--- drivers/accel/rocket/rocket_job.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/accel/rocket/rocket_job.c +19 -11
@@ -371,6 +371,24 @@ static struct dma_fence *rocket_job_run(struct drm_sched_job *sched_job)return ERR_PTR (ret); } +static void rocket_job_next_locked (struct rocket_core *core) +{ +lockdep_assert_held (&core->job_lock); + +if (!core->in_flight_job) +return ; + +if (core->in_flight_job->next_task_idx < core->in_flight_job->task_count) { +rocket_job_hw_submit (core, core->in_flight_job); +return ; + } + +iommu_detach_group (NULL , core->iommu_group); +dma_fence_signal (core->in_flight_job->done_fence); +pm_runtime_put_autosuspend (core->dev); + core->in_flight_job =NULL ; +} +static void rocket_job_handle_irq (struct rocket_core *core) {pm_runtime_mark_last_busy (core->dev);
@@ -384,17 +402,7 @@ static void rocket_job_handle_irq(struct rocket_core *core)rocket_pc_writel (core,OPERATION_ENABLE ,0x0 );rocket_pc_writel (core,INTERRUPT_CLEAR ,0x1ffff ); -if (core->in_flight_job) { -if (core->in_flight_job->next_task_idx < core->in_flight_job->task_count) { -rocket_job_hw_submit (core, core->in_flight_job); -return ; - } - -iommu_detach_group (NULL , core->iommu_group); -dma_fence_signal (core->in_flight_job->done_fence); -pm_runtime_put_autosuspend (core->dev); - core->in_flight_job =NULL ; - } +rocket_job_next_locked (core); } }
Signature · 1 line
2.43.0
PATCH v18 2/8 dt-bindings: npu: rockchip: add rockchip,rk3576-rknn-core
In reply to Jiaxing HuThe RK3576 uses the same NPU block as the RK3588. Each of its two cores has six clocks (aclk_cbuf and hclk_cbuf on top of the RK3588's four), one reset and no sram-supply. Describe each SoC in allOf; the RK3588 still requires sram-supply.
--- .../npu/rockchip,rk3588-rknn-core.yaml | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml +38 -2
@@ -21,6 +21,7 @@ properties: compatible: enum: + - rockchip,rk3576-rknn-core - rockchip,rk3588-rknn-core reg:
@@ -33,14 +34,18 @@ properties: - const: core # Main NPU core processing unit registers clocks: - maxItems: 4 + minItems: 4 + maxItems: 6 clock-names: + minItems: 4 items: - const: aclk - const: hclk - const: npu - const: pclk + - const: aclk_cbuf + - const: hclk_cbuf interrupts: maxItems: 1
@@ -54,9 +59,11 @@ properties: maxItems: 1 resets: + minItems: 1 maxItems: 2 reset-names: + minItems: 1 items: - const: srst_a - const: srst_h
@@ -75,7 +82,36 @@ required: - resets - reset-names - npu-supply - - sram-supply + +allOf: + - if: + properties: + compatible: + contains: + const: rockchip,rk3588-rknn-core + then: + properties: + clocks: + maxItems: 4 + clock-names: + maxItems: 4 + resets: + minItems: 2 + reset-names: + minItems: 2 + required: + - sram-supply + else: + properties: + clocks: + minItems: 6 + clock-names: + minItems: 6 + resets: + maxItems: 1 + reset-names: + maxItems: 1 + sram-supply: false additionalProperties: false
Signature · 1 line
2.43.0
PATCH v18 3/8 dt-bindings: iommu: rockchip: describe the RK3576 NPU MMU
In reply to Jiaxing HuThe RK3576 NPU IOMMU is compatible with rk3568-iommu but needs four
clocks: aclk, iface and the two CBUF clocks. Without any one of them the IOMMU reset fails and the NPU does not probe.
--- .../bindings/iommu/rockchip,iommu.yaml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)
Documentation/devicetree/bindings/iommu/rockchip,iommu.yaml +26 -0
@@ -26,6 +26,7 @@ properties: - items: - enum: - rockchip,rk3576-iommu + - rockchip,rk3576-npu-iommu - rockchip,rk3588-iommu - const: rockchip,rk3568-iommu
@@ -42,14 +43,20 @@ properties: minItems: 1 clocks: + minItems: 2 items: - description: Core clock - description: Interface clock + - description: Convolution buffer core clock + - description: Convolution buffer interface clock clock-names: + minItems: 2 items: - const: aclk - const: iface + - const: aclk_cbuf + - const: hclk_cbuf "#iommu-cells": const: 0
@@ -72,6 +79,25 @@ required: - clock-names - "#iommu-cells" +allOf: + - if: + properties: + compatible: + contains: + const: rockchip,rk3576-npu-iommu + then: + properties: + clocks: + minItems: 4 + clock-names: + minItems: 4 + else: + properties: + clocks: + maxItems: 2 + clock-names: + maxItems: 2 + additionalProperties: false examples:
Signature · 1 line
2.43.0
PATCH v18 4/8 accel/rocket: take the core clocks and resets from the devicetree
In reply to Jiaxing HuThe RK3576 NPU core has six clocks and one reset, the RK3588 core four clocks and two resets. Take all clocks and resets the core node lists instead of naming and counting them per SoC; the binding defines them and dtbs_check enforces it. The driver only uses them all together.
On the RK3588 the resets are now deasserted in devicetree order, srst_a then srst_h; before it was the reverse.
--- drivers/accel/rocket/rocket_core.c | 25 ++++++++++--------------- drivers/accel/rocket/rocket_core.h | 13 +++---------- drivers/accel/rocket/rocket_drv.c | 4 ++-- 3 files changed, 15 insertions(+), 27 deletions(-)
drivers/accel/rocket/rocket_core.c +10 -15
@@ -21,20 +21,15 @@ int rocket_core_init(struct rocket_core *core)u32 version;int err =0 ; - core->resets[0 ].id ="srst_a" ; - core->resets[1 ].id ="srst_h" ; - err =devm_reset_control_bulk_get_exclusive (&pdev->dev,ARRAY_SIZE (core->resets), - core->resets); -if (err) -return dev_err_probe (dev, err,"failed to get resets for core %d\n" , core->index); + core->resets =devm_reset_control_array_get_exclusive (dev); +if (IS_ERR (core->resets)) +return dev_err_probe (dev,PTR_ERR (core->resets), +"failed to get resets for core %d\n" , core->index); - core->clks[ROCKET_CLK_ACLK ].id ="aclk" ; - core->clks[ROCKET_CLK_HCLK ].id ="hclk" ; - core->clks[ROCKET_CLK_NPU ].id ="npu" ; - core->clks[ROCKET_CLK_PCLK ].id ="pclk" ; - err =devm_clk_bulk_get (dev,ARRAY_SIZE (core->clks), core->clks); -if (err) -return dev_err_probe (dev, err,"failed to get clocks for core %d\n" , core->index); + core->num_clks =devm_clk_bulk_get_all (dev, &core->clks); +if (core->num_clks <0 ) +return dev_err_probe (dev, core->num_clks, +"failed to get clocks for core %d\n" , core->index); core->pc_iomem =devm_platform_ioremap_resource_byname (pdev,"pc" );if (IS_ERR (core->pc_iomem))
@@ -106,9 +101,9 @@ void rocket_core_fini(struct rocket_core *core)void rocket_core_reset (struct rocket_core *core) { -reset_control_bulk_assert (ARRAY_SIZE (core->resets), core->resets); +reset_control_assert (core->resets);udelay (10 ); -reset_control_bulk_deassert (ARRAY_SIZE (core->resets), core->resets); +reset_control_deassert (core->resets); }
drivers/accel/rocket/rocket_core.h +3 -10
@@ -27,14 +27,6 @@#define rocket_core_writel (core, reg, value) \ writel(value, (core)->core_iomem + (REG_CORE_##reg) - REG_CORE_S_STATUS) -enum rocket_clk { -ROCKET_CLK_ACLK , -ROCKET_CLK_HCLK , -ROCKET_CLK_NPU , -ROCKET_CLK_PCLK , -ROCKET_CLK_MAX , -}; -struct rocket_core {struct device *dev;struct rocket_device *rdev;
@@ -48,8 +40,9 @@ struct rocket_core {void __iomem *pc_iomem;void __iomem *cna_iomem;void __iomem *core_iomem; -struct clk_bulk_data clks[ROCKET_CLK_MAX ]; -struct reset_control_bulk_data resets[2 ]; +struct clk_bulk_data *clks; +int num_clks; +struct reset_control *resets;struct iommu_group *iommu_group;
drivers/accel/rocket/rocket_drv.c +2 -2
@@ -269,7 +269,7 @@ static int rocket_device_runtime_resume(struct device *dev)if (core <0 )return -ENODEV ; - err =clk_bulk_prepare_enable (ARRAY_SIZE (rdev->cores[core].clks), rdev->cores[core].clks); + err =clk_bulk_prepare_enable (rdev->cores[core].num_clks, rdev->cores[core].clks);if (err) {dev_err (dev,"failed to enable (%d) clocks for core %d\n" , err, core);return err;
@@ -289,7 +289,7 @@ static int rocket_device_runtime_suspend(struct device *dev)if (!rocket_job_is_idle (&rdev->cores[core]))return -EBUSY ; -clk_bulk_disable_unprepare (ARRAY_SIZE (rdev->cores[core].clks), rdev->cores[core].clks); +clk_bulk_disable_unprepare (rdev->cores[core].num_clks, rdev->cores[core].clks);return 0 ; }
Signature · 1 line
2.43.0
Re: [PATCH v18 4/8] accel/rocket: take the core clocks and resets from the devicetree
Quoted 10 lines · Jiaxing Hu
The RK3576 NPU core has six clocks and one reset, the RK3588 core four clocks and two resets. Take all clocks and resets the core node lists instead of naming and counting them per SoC; the binding defines them and
dtbs_checkenforces it. The driver only uses them all together.On the RK3588 the resets are now deasserted in devicetree order,
srst_athensrst_h; before it was the reverse.Suggested-by Daniel Drake <[email protected]>Signed-off-by Jiaxing Hu <[email protected]>
PATCH v18 5/8 accel/rocket: add a GET_PARAM ioctl for the hardware version
In reply to Jiaxing HuAdd DRM_IOCTL_ROCKET_GET_PARAM so that userspace can tell which NPU it runs on. DRM_ROCKET_PARAM_HW_VERSION returns an enum drm_rocket_hw_version value, taken from the compatible's match data when the first core probes. The PC_VERSION registers cannot be used: the RK3568 reads 0 from them.
A core with a different hardware version is refused. An unknown parameter or a non-zero reserved field returns -EINVAL.
--- drivers/accel/rocket/rocket_device.c | 4 ++- drivers/accel/rocket/rocket_device.h | 6 +++- drivers/accel/rocket/rocket_drv.c | 34 +++++++++++++++++++++-- include/uapi/drm/rocket_accel.h | 41 ++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-)
drivers/accel/rocket/rocket_device.c +3 -1
@@ -11,7 +11,8 @@#include "rocket_device.h" struct rocket_device *rocket_device_init (struct platform_device *pdev, -const struct drm_driver *rocket_drm_driver) +const struct drm_driver *rocket_drm_driver, +u32 hw_version) {struct device *dev = &pdev->dev;struct device_node *core_node;
@@ -26,6 +27,7 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev, ddev = &rdev->ddev;dev_set_drvdata (dev, rdev); + rdev->hw_version = hw_version;for_each_compatible_node (core_node,NULL ,"rockchip,rk3588-rknn-core" )if (of_device_is_available (core_node))
drivers/accel/rocket/rocket_device.h +5 -1
@@ -20,10 +20,14 @@ struct rocket_device {struct rocket_core *cores;unsigned int num_cores;unsigned int max_cores; + +/* enum drm_rocket_hw_version of the NPU, the same for all cores */ +u32 hw_version; };struct rocket_device *rocket_device_init (struct platform_device *pdev, -const struct drm_driver *rocket_drm_driver); +const struct drm_driver *rocket_drm_driver, +u32 hw_version);void rocket_device_fini (struct rocket_device *rdev);#define to_rocket_device (drm_dev) \ ((struct rocket_device *)(container_of((drm_dev), struct rocket_device, ddev)))
drivers/accel/rocket/rocket_drv.c +32 -2
@@ -5,6 +5,7 @@#include <drm/drm_drv.h> #include <drm/drm_gem.h> #include <drm/drm_ioctl.h> +#include <drm/drm_print.h> #include <drm/rocket_accel.h> #include <linux/clk.h> #include <linux/err.h>
@@ -12,6 +13,7 @@#include <linux/of.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> +#include <linux/property.h> #include "rocket_device.h" #include "rocket_drv.h"
@@ -128,6 +130,26 @@ rocket_postclose(struct drm_device *dev, struct drm_file *file)module_put (THIS_MODULE ); } +static int +rocket_ioctl_get_param (struct drm_device *dev,void *data,struct drm_file *file) +{ +struct rocket_device *rdev =to_rocket_device (dev); +struct drm_rocket_get_param *args = data; + +if (args->reserved !=0 ) { +drm_dbg (dev,"Reserved field in drm_rocket_get_param struct should be 0.\n" ); +return -EINVAL ; + } + +switch (args->param) { +case DRM_ROCKET_PARAM_HW_VERSION : + args->value = rdev->hw_version; +return 0 ; +default : +return -EINVAL ; + } +} +static const struct drm_ioctl_desc rocket_drm_driver_ioctls[] = { #define ROCKET_IOCTL(n, func) \ DRM_IOCTL_DEF_DRV(ROCKET_##n, rocket_ioctl_##func, 0)
@@ -136,6 +158,7 @@ static const struct drm_ioctl_desc rocket_drm_driver_ioctls[] = {ROCKET_IOCTL (SUBMIT , submit),ROCKET_IOCTL (PREP_BO , prep_bo),ROCKET_IOCTL (FINI_BO , fini_bo), +ROCKET_IOCTL (GET_PARAM , get_param), };DEFINE_DRM_ACCEL_FOPS (rocket_accel_driver_fops);
@@ -174,9 +197,13 @@ static int rocket_core_hw_index(struct device *dev)static int rocket_probe (struct platform_device *pdev) { +u32 hw_version = (uintptr_t )device_get_match_data (&pdev->dev);int index =rocket_core_hw_index (&pdev->dev);int ret; +if (!hw_version) +return -ENODEV ; +if (index <0 )return index;
@@ -185,7 +212,7 @@ static int rocket_probe(struct platform_device *pdev) rdev_group =devres_open_group (&drm_dev->dev,NULL ,GFP_KERNEL );if (!rdev_group)return -ENOMEM ; - rdev =rocket_device_init (drm_dev, &rocket_drm_driver); + rdev =rocket_device_init (drm_dev, &rocket_drm_driver, hw_version);if (IS_ERR (rdev)) {int err =PTR_ERR (rdev);
@@ -197,6 +224,9 @@ static int rocket_probe(struct platform_device *pdev)devres_close_group (&drm_dev->dev, rdev_group); } +if (hw_version != rdev->hw_version) +return -EINVAL ; +unsigned int core = rdev->num_cores;dev_set_drvdata (&pdev->dev, rdev);
@@ -243,7 +273,7 @@ static void rocket_remove(struct platform_device *pdev) }static const struct of_device_id dt_match[] = { - { .compatible ="rockchip,rk3588-rknn-core" }, + { .compatible ="rockchip,rk3588-rknn-core" , .data = (void *)DRM_ROCKET_HW_RK3588 }, {} };MODULE_DEVICE_TABLE (of, dt_match);
include/uapi/drm/rocket_accel.h +41 -0
58 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v18 5/8] accel/rocket: add a GET_PARAM ioctl for the hardware version
Quoted 5 lines · Jiaxing Hu
Add
DRM_IOCTL_ROCKET_GET_PARAMso that userspace can tell which NPU it runs on.DRM_ROCKET_PARAM_HW_VERSIONreturns an enumdrm_rocket_hw_versionvalue, taken from the compatible's match data when the first core probes. ThePC_VERSIONregisters cannot be used: the RK3568 reads 0 from them.
I also spotted that the vendor driver uses compatible-based matching for this kind of thing.
drivers/accel/rocket/rocket_drv.c static int rocket_probe(struct platform_device *pdev) · line 229
Quoted 7 lines
drivers/accel/rocket/rocket_drv.c +3
-0@@ -197,6 +224,9 @@ static int rocket_probe(struct platform_device *pdev)devres_close_group (&drm_dev->dev, rdev_group); } +if (hw_version != rdev->hw_version) +return -EINVAL ; +
This check can be dropped, we can assume that a DT that gives cores with a mix of hw versions is invalid and broken.
With that change feel free to add my Reviewed-By
PATCH v18 6/8 accel/rocket: add RK3576 NPU (RKNN) support
In reply to Jiaxing HuAdd the RK3576 NPU. Its PC_TASK_CON has a 16-bit task number, with pp_en, count_clear and last_layer_clear at BIT16, BIT17 and BIT18, as Chaoyi Chen confirmed:
https://lore.kernel.org/all/[email protected]/
Add it to rocket_registers.h as TASK_CON_RK3576, generated from Mesa's registers.xml, and use it on the RK3576. Count the cores in rocket_drv.c against the match table, not only the RK3588 compatible.
--- drivers/accel/rocket/rocket_device.c | 9 +------ drivers/accel/rocket/rocket_device.h | 2 +- drivers/accel/rocket/rocket_drv.c | 16 ++++++++++++- drivers/accel/rocket/rocket_job.c | 15 ++++++++---- drivers/accel/rocket/rocket_registers.h | 32 +++++++++++++++++++++++++ include/uapi/drm/rocket_accel.h | 2 ++ 6 files changed, 62 insertions(+), 14 deletions(-)
drivers/accel/rocket/rocket_device.c +1 -8
@@ -6,19 +6,16 @@#include <linux/clk.h> #include <linux/dma-mapping.h> #include <linux/platform_device.h> -#include <linux/of.h> #include "rocket_device.h" struct rocket_device *rocket_device_init (struct platform_device *pdev,const struct drm_driver *rocket_drm_driver, -u32 hw_version) +unsigned int num_cores,u32 hw_version) {struct device *dev = &pdev->dev; -struct device_node *core_node;struct rocket_device *rdev;struct drm_device *ddev; -unsigned int num_cores =0 ;int err; rdev = devm_drm_dev_alloc(dev, rocket_drm_driver, struct rocket_device, ddev);
@@ -29,10 +26,6 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,dev_set_drvdata (dev, rdev); rdev->hw_version = hw_version; -for_each_compatible_node (core_node,NULL ,"rockchip,rk3588-rknn-core" ) -if (of_device_is_available (core_node)) - num_cores++; - rdev->max_cores = num_cores; rdev->cores =devm_kzalloc_objs (dev, *rdev->cores, num_cores);
drivers/accel/rocket/rocket_device.h +1 -1
@@ -27,7 +27,7 @@ struct rocket_device {struct rocket_device *rocket_device_init (struct platform_device *pdev,const struct drm_driver *rocket_drm_driver, -u32 hw_version); +unsigned int num_cores,u32 hw_version);void rocket_device_fini (struct rocket_device *rdev);#define to_rocket_device (drm_dev) \ ((struct rocket_device *)(container_of((drm_dev), struct rocket_device, ddev)))
drivers/accel/rocket/rocket_drv.c +15 -1
@@ -195,6 +195,18 @@ static int rocket_core_hw_index(struct device *dev)return -ENODEV ; } +static unsigned int rocket_count_cores (struct device *dev) +{ +struct device_node *np; +unsigned int num_cores =0 ; + +for_each_matching_node (np, dev->driver->of_match_table) +if (of_device_is_available (np)) + num_cores++; + +return num_cores; +} +static int rocket_probe (struct platform_device *pdev) {u32 hw_version = (uintptr_t )device_get_match_data (&pdev->dev);
@@ -212,7 +224,8 @@ static int rocket_probe(struct platform_device *pdev) rdev_group =devres_open_group (&drm_dev->dev,NULL ,GFP_KERNEL );if (!rdev_group)return -ENOMEM ; - rdev =rocket_device_init (drm_dev, &rocket_drm_driver, hw_version); + rdev =rocket_device_init (drm_dev, &rocket_drm_driver, +rocket_count_cores (&pdev->dev), hw_version);if (IS_ERR (rdev)) {int err =PTR_ERR (rdev);
@@ -274,6 +287,7 @@ static void rocket_remove(struct platform_device *pdev)static const struct of_device_id dt_match[] = { { .compatible ="rockchip,rk3588-rknn-core" , .data = (void *)DRM_ROCKET_HW_RK3588 }, + { .compatible ="rockchip,rk3576-rknn-core" , .data = (void *)DRM_ROCKET_HW_RK3576 }, {} };MODULE_DEVICE_TABLE (of, dt_match);
drivers/accel/rocket/rocket_job.c +11 -4
@@ -166,10 +166,17 @@ static void rocket_job_hw_submit(struct rocket_core *core, struct rocket_job *jorocket_pc_writel (core,INTERRUPT_MASK ,PC_INTERRUPT_MASK_DPU_0 |PC_INTERRUPT_MASK_DPU_1 );rocket_pc_writel (core,INTERRUPT_CLEAR ,PC_INTERRUPT_CLEAR_DPU_0 |PC_INTERRUPT_CLEAR_DPU_1 ); -rocket_pc_writel (core,TASK_CON ,PC_TASK_CON_RESERVED_0 (1 ) | -PC_TASK_CON_TASK_COUNT_CLEAR (1 ) | -PC_TASK_CON_TASK_NUMBER (1 ) | -PC_TASK_CON_TASK_PP_EN (1 )); +if (core->rdev->hw_version ==DRM_ROCKET_HW_RK3576 ) +rocket_pc_writel (core,TASK_CON_RK3576 , +PC_TASK_CON_RK3576_LAST_LAYER_CLEAR (1 ) | +PC_TASK_CON_RK3576_TASK_COUNT_CLEAR (1 ) | +PC_TASK_CON_RK3576_TASK_PP_EN (1 ) | +PC_TASK_CON_RK3576_TASK_NUMBER (1 )); +else +rocket_pc_writel (core,TASK_CON ,PC_TASK_CON_RESERVED_0 (1 ) | +PC_TASK_CON_TASK_COUNT_CLEAR (1 ) | +PC_TASK_CON_TASK_NUMBER (1 ) | +PC_TASK_CON_TASK_PP_EN (1 ));rocket_pc_writel (core,TASK_DMA_BASE_ADDR ,PC_TASK_DMA_BASE_ADDR_DMA_BASE_ADDR (0x0 ));
drivers/accel/rocket/rocket_registers.h +32 -0
@@ -195,6 +195,38 @@ static inline uint32_t PC_TASK_CON_TASK_NUMBER(uint32_t val)return ((val) <<PC_TASK_CON_TASK_NUMBER__SHIFT ) &PC_TASK_CON_TASK_NUMBER__MASK ; } +#define REG_PC_TASK_CON_RK3576 0x00000030 +#define PC_TASK_CON_RK3576_RESERVED_0__MASK 0xfff80000 +#define PC_TASK_CON_RK3576_RESERVED_0__SHIFT 19 +static inline uint32_t PC_TASK_CON_RK3576_RESERVED_0 (uint32_t val) +{ +return ((val) <<PC_TASK_CON_RK3576_RESERVED_0__SHIFT ) &PC_TASK_CON_RK3576_RESERVED_0__MASK ; +} +#define PC_TASK_CON_RK3576_LAST_LAYER_CLEAR__MASK 0x00040000 +#define PC_TASK_CON_RK3576_LAST_LAYER_CLEAR__SHIFT 18 +static inline uint32_t PC_TASK_CON_RK3576_LAST_LAYER_CLEAR (uint32_t val) +{ +return ((val) <<PC_TASK_CON_RK3576_LAST_LAYER_CLEAR__SHIFT ) &PC_TASK_CON_RK3576_LAST_LAYER_CLEAR__MASK ; +} +#define PC_TASK_CON_RK3576_TASK_COUNT_CLEAR__MASK 0x00020000 +#define PC_TASK_CON_RK3576_TASK_COUNT_CLEAR__SHIFT 17 +static inline uint32_t PC_TASK_CON_RK3576_TASK_COUNT_CLEAR (uint32_t val) +{ +return ((val) <<PC_TASK_CON_RK3576_TASK_COUNT_CLEAR__SHIFT ) &PC_TASK_CON_RK3576_TASK_COUNT_CLEAR__MASK ; +} +#define PC_TASK_CON_RK3576_TASK_PP_EN__MASK 0x00010000 +#define PC_TASK_CON_RK3576_TASK_PP_EN__SHIFT 16 +static inline uint32_t PC_TASK_CON_RK3576_TASK_PP_EN (uint32_t val) +{ +return ((val) <<PC_TASK_CON_RK3576_TASK_PP_EN__SHIFT ) &PC_TASK_CON_RK3576_TASK_PP_EN__MASK ; +} +#define PC_TASK_CON_RK3576_TASK_NUMBER__MASK 0x0000ffff +#define PC_TASK_CON_RK3576_TASK_NUMBER__SHIFT 0 +static inline uint32_t PC_TASK_CON_RK3576_TASK_NUMBER (uint32_t val) +{ +return ((val) <<PC_TASK_CON_RK3576_TASK_NUMBER__SHIFT ) &PC_TASK_CON_RK3576_TASK_NUMBER__MASK ; +} +#define REG_PC_TASK_DMA_BASE_ADDR 0x00000034#define PC_TASK_DMA_BASE_ADDR_DMA_BASE_ADDR__MASK 0xfffffff0#define PC_TASK_DMA_BASE_ADDR_DMA_BASE_ADDR__SHIFT 4
include/uapi/drm/rocket_accel.h +2 -0
@@ -199,11 +199,13 @@ enum drm_rocket_param {/** * enum drm_rocket_hw_version - the NPU, for DRM_ROCKET_PARAM_HW_VERSION * @DRM_ROCKET_HW_RK3588: the NPU of the RK3588. +* @DRM_ROCKET_HW_RK3576: the NPU of the RK3576. * * 0 is not used. */ enum drm_rocket_hw_version {DRM_ROCKET_HW_RK3588 =1 , +DRM_ROCKET_HW_RK3576 =2 , };/**
Signature · 1 line
2.43.0
Re: [PATCH v18 6/8] accel/rocket: add RK3576 NPU (RKNN) support
Quoted 9 lines · Jiaxing Hu
Add the RK3576 NPU. Its
PC_TASK_CONhas a 16-bit task number, withpp_en,count_clearandlast_layer_clearat BIT16, BIT17 and BIT18, as Chaoyi Chen confirmed:https://lore.kernel.org/all/[email protected]/
Add it to
rocket_registers.hasTASK_CON_RK3576, generated from Mesa's registers.xml, and use it on the RK3576. Count the cores inrocket_drv.cagainst the match table, not only the RK3588 compatible.
In the corresponding mesa change:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/43804/diffs
You had to tweak the header generator to allow two register definitions to exist at the same offset.
From what I can see, Mesa has another way of allowing hw-specific variants of a given register: variants/varset used in freedreno register definitions. Have you explored using that?
PATCH v18 7/8 arm64: dts: rockchip: add NPU (RKNN) nodes to rk3576
In reply to Jiaxing HuAdd the two NPU cores and their IOMMUs, disabled by default. Core 0 is in PD_NPU0, core 1 in PD_NPU1. Label PD_NPU so that boards can give it the NPU supply.
Set CLK_RKNN_DSU0 to 594 MHz. Nothing scales the NPU clock or voltage in mainline, and the boot rate of 786 MHz at the boot voltage of 750 mV is outside the vendor OPP table and gives wrong results; that table runs up to 600 MHz at 725 mV.
--- arch/arm64/boot/dts/rockchip/rk3576.dtsi | 70 +++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/rockchip/rk3576.dtsi +69 -1
@@ -1131,7 +1131,7 @@ power: power-controller { #address-cells = <1>; #size-cells = <0>; - power-domain@RK3576_PD_NPU { + pd_npu: power-domain@RK3576_PD_NPU { reg = <RK3576_PD_NPU>; #power-domain-cells = <1>; #address-cells = <1>;
@@ -1350,6 +1350,74 @@ power-domain@RK3576_PD_VO1 { }; }; + rknn_core_0: npu@27700000 { + compatible = "rockchip,rk3576-rknn-core"; + reg = <0x0 0x27700000 0x0 0x1000>, + <0x0 0x27701000 0x0 0x1000>, + <0x0 0x27703000 0x0 0x1000>; + reg-names = "pc", "cna", "core"; + interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru ACLK_RKNN0>, <&cru HCLK_RKNN_ROOT>, + <&cru CLK_RKNN_DSU0>, <&cru PCLK_NPUTOP_ROOT>, + <&cru ACLK_RKNN_CBUF>, <&cru HCLK_RKNN_CBUF>; + clock-names = "aclk", "hclk", "npu", "pclk", + "aclk_cbuf", "hclk_cbuf"; + assigned-clocks = <&cru CLK_RKNN_DSU0>; + assigned-clock-rates = <594000000>; + resets = <&cru SRST_A_RKNN0>; + reset-names = "srst_a"; + power-domains = <&power RK3576_PD_NPU0>; + iommus = <&rknn_mmu_0>; + status = "disabled"; + }; + + rknn_mmu_0: iommu@27702000 { + compatible = "rockchip,rk3576-npu-iommu", "rockchip,rk3568-iommu"; + reg = <0x0 0x27702000 0x0 0x100>, + <0x0 0x27702100 0x0 0x100>; + interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru ACLK_RKNN0>, <&cru HCLK_RKNN_ROOT>, + <&cru ACLK_RKNN_CBUF>, <&cru HCLK_RKNN_CBUF>; + clock-names = "aclk", "iface", "aclk_cbuf", "hclk_cbuf"; + #iommu-cells = <0>; + power-domains = <&power RK3576_PD_NPU0>; + status = "disabled"; + }; + + rknn_core_1: npu@27708000 { + compatible = "rockchip,rk3576-rknn-core"; + reg = <0x0 0x27708000 0x0 0x1000>, + <0x0 0x27709000 0x0 0x1000>, + <0x0 0x2770b000 0x0 0x1000>; + reg-names = "pc", "cna", "core"; + interrupts = <GIC_SPI 248 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru ACLK_RKNN1>, <&cru HCLK_RKNN_ROOT>, + <&cru CLK_RKNN_DSU0>, <&cru PCLK_NPUTOP_ROOT>, + <&cru ACLK_RKNN_CBUF>, <&cru HCLK_RKNN_CBUF>; + clock-names = "aclk", "hclk", "npu", "pclk", + "aclk_cbuf", "hclk_cbuf"; + assigned-clocks = <&cru CLK_RKNN_DSU0>; + assigned-clock-rates = <594000000>; + resets = <&cru SRST_A_RKNN1>; + reset-names = "srst_a"; + power-domains = <&power RK3576_PD_NPU1>; + iommus = <&rknn_mmu_1>; + status = "disabled"; + }; + + rknn_mmu_1: iommu@2770a000 { + compatible = "rockchip,rk3576-npu-iommu", "rockchip,rk3568-iommu"; + reg = <0x0 0x2770a000 0x0 0x100>, + <0x0 0x2770a100 0x0 0x100>; + interrupts = <GIC_SPI 248 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&cru ACLK_RKNN1>, <&cru HCLK_RKNN_ROOT>, + <&cru ACLK_RKNN_CBUF>, <&cru HCLK_RKNN_CBUF>; + clock-names = "aclk", "iface", "aclk_cbuf", "hclk_cbuf"; + #iommu-cells = <0>; + power-domains = <&power RK3576_PD_NPU1>; + status = "disabled"; + }; + gpu: gpu@27800000 { compatible = "rockchip,rk3576-mali", "arm,mali-bifrost"; reg = <0x0 0x27800000 0x0 0x20000>;
Signature · 1 line
2.43.0
Re: [PATCH v18 7/8] arm64: dts: rockchip: add NPU (RKNN) nodes to rk3576
Quoted 8 lines · Jiaxing Hu
Add the two NPU cores and their IOMMUs, disabled by default. Core 0 is in
PD_NPU0, core 1 inPD_NPU1. LabelPD_NPUso that boards can give it the NPU supply.Set
CLK_RKNN_DSU0to 594 MHz. Nothing scales the NPU clock or voltage in mainline, and the boot rate of 786 MHz at the boot voltage of 750 mV is outside the vendor OPP table and gives wrong results; that table runs up to 600 MHz at 725 mV.
I still struggled to understand this (particularly the choice of 594 MHz) even with your notes, but I think I got it now. Suggested rewrite that will hopefully make it easier for others:
---
Set the DSU0 clock to 594 MHz for now. Radxa ROCK 4D boots with the DSU0 clock at 786 MHz with a voltage of 750 mV, however this gives wrong results and the vendor OPP table suggests this voltage is only workable up to 700 MHz. The rocket driver does not control the voltage yet, so 594 MHz (GPLL/2) is selected as the highest rate that we can select for this operating point. Voltage and frequency scaling could be implemented in future to more closely match the vendor driver behaviour.
---
Please tweak something along those lines, you can add my reviewed-by.
PATCH v18 8/8 arm64: dts: rockchip: enable the NPU on rk3576-rock-4d
In reply to Jiaxing HuEnable both NPU cores and their IOMMUs, and make vdd_npu_s0 the supply of the NPU power domain. The rail is switched with the domain by commit b1bff9ced657 ("pmdomain: rockchip: manage the RK3576 NPU domain supply") in the pmdomain tree; without it nothing holds the rail and it is turned off as unused.
npu-supply is set because the binding requires it; no driver uses it.
--- .../boot/dts/rockchip/rk3576-rock-4d.dts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/arm64/boot/dts/rockchip/rk3576-rock-4d.dts +22 -0
@@ -722,6 +722,10 @@ &pcie0 { status = "okay"; }; +&pd_npu { + domain-supply = <&vdd_npu_s0>; +}; + &pinctrl { hdmi { hdmi_tx_on_h: hdmi-tx-on-h {
@@ -779,6 +783,24 @@ wifi_en_h: wifi-en-h { }; }; +&rknn_core_0 { + npu-supply = <&vdd_npu_s0>; + status = "okay"; +}; + +&rknn_mmu_0 { + status = "okay"; +}; + +&rknn_core_1 { + npu-supply = <&vdd_npu_s0>; + status = "okay"; +}; + +&rknn_mmu_1 { + status = "okay"; +}; + &sai6 { status = "okay"; };
Signature · 1 line
2.43.0
Re: [PATCH v18 8/8] arm64: dts: rockchip: enable the NPU on rk3576-rock-4d
Quoted 4 lines · Jiaxing Hu
The rail is switched with the domain by commit
b1bff9ced657("pmdomain: rockchip: manage the RK3576 NPU domain supply") in the pmdomain tree; without it nothing holds the rail and it is turned off as unused.
You can omit this part of the commit message. The dependency is stated in the cover letter, and domain-supply is standard enough that it doesn't need specific documentation.
Quoted 1 line
npu-supply is set because the binding requires it; no driver uses it.
So why does the binding even exist? Is it because it will be needed for implementing voltage scaling in future?