accel: Add Arm Ethos-U NPU
Subsystems (6)
Rob Herring (Arm)
maintainerv3 cover accel: Add Arm Ethos-U NPU
The Arm Ethos-U65/85 NPUs are designed for edge AI inference applications[0].
The driver works with Mesa Teflon. A merge request for Ethos support is here[1]. The UAPI should also be compatible with the downstream (open source) driver stack[2] and Vela compiler though that has not been implemented.
Testing so far has been on i.MX93 boards with Ethos-U65 and a FVP model with Ethos-U85. More work is needed in mesa for handling U85 command stream differences, but that doesn't affect the UABI.
A git tree is here[3].
Rob
[0] https://www.arm.com/products/silicon-ip-cpu?families=ethos%20npus
[1] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36699/
[2] https://gitlab.arm.com/artificial-intelligence/ethos-u/
[3] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git ethos-v3
---
Changes in v3:
- Rework and improve job submit validation
- Rename ethos to ethosu. There was an Ethos-Nxx that's unrelated.
- Add missing init for sched_lock mutex
- Drop some prints to debug level
- Fix i.MX93 SRAM accesses (AXI config)
- Add U85 AXI configuration and test on FVP with U85
- Print the current cmd value on timeout
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Rebase on v6.17-rc1 adapting to scheduler changes
- scheduler: Drop the reset workqueue. According to the scheduler docs, we don't need it since we have a single h/w queue.
- scheduler: Rework the timeout handling to continue running if we are making progress. Fixes timeouts on larger jobs.
- Reset the NPU on resume so it's in a known state
- Add error handling on clk_get() calls
- Fix drm_mm splat on module unload. We were missing a put on the cmdstream BO in the scheduler clean-up.
- Fix 0-day report needing explicit bitfield.h include
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Rob Herring (Arm) (2):
dt-bindings: npu: Add Arm Ethos-U65/U85
accel: Add Arm Ethos-U NPU driver
.../devicetree/bindings/npu/arm,ethos.yaml | 79 +++ MAINTAINERS | 9 + drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 1 + drivers/accel/ethosu/Kconfig | 10 + drivers/accel/ethosu/Makefile | 4 + drivers/accel/ethosu/ethosu_device.h | 187 ++++++ drivers/accel/ethosu/ethosu_drv.c | 430 +++++++++++++ drivers/accel/ethosu/ethosu_drv.h | 15 + drivers/accel/ethosu/ethosu_gem.c | 709 +++++++++++++++++++++ drivers/accel/ethosu/ethosu_gem.h | 46 ++ drivers/accel/ethosu/ethosu_job.c | 543 ++++++++++++++++ drivers/accel/ethosu/ethosu_job.h | 41 ++ include/uapi/drm/ethosu_accel.h | 262 ++++++++ 14 files changed, 2337 insertions(+)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250715-ethos-3fdd39ef6f19
Best regards,
Signature · 1 line
Rob Herring (Arm) <[email protected]>
Rob Herring (Arm)
maintainerPATCH v3 1/2 dt-bindings: npu: Add Arm Ethos-U65/U85
Add a binding schema for Arm Ethos-U65/U85 NPU. The Arm Ethos-U NPUs are designed for edge AI inference applications.
--- .../devicetree/bindings/npu/arm,ethos.yaml | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+)
Documentation/devicetree/bindings/npu/arm,ethos.yaml new file +79 -0
@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/npu/arm,ethos.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Arm Ethos U65/U85 + +maintainers: + - Rob Herring <[email protected]> + +description: > + The Arm Ethos-U NPUs are designed for IoT inference applications. The NPUs + can accelerate 8-bit and 16-bit integer quantized networks: + + Transformer networks (U85 only) + Convolutional Neural Networks (CNN) + Recurrent Neural Networks (RNN) + + Further documentation is available here: + + U65 TRM: https://developer.arm.com/documentation/102023/ + U85 TRM: https://developer.arm.com/documentation/102685/ + +properties: + compatible: + oneOf: + - items: + - enum: + - fsl,imx93-npu + - const: arm,ethos-u65 + - items: + - {} + - const: arm,ethos-u85 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: core + - const: apb + + power-domains: + maxItems: 1 + + sram: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/imx93-clock.h> + + npu@4a900000 { + compatible = "fsl,imx93-npu", "arm,ethos-u65"; + reg = <0x4a900000 0x1000>; + interrupts = <GIC_SPI 178 IRQ_TYPE_LEVEL_HIGH>; + power-domains = <&mlmix>; + clocks = <&clk IMX93_CLK_ML>, <&clk IMX93_CLK_ML_APB>; + clock-names = "core", "apb"; + sram = <&sram>; + }; +...
Signature · 1 line
2.51.0
Re: [PATCH v3 1/2] dt-bindings: npu: Add Arm Ethos-U65/U85
Quoted 37 lines · Rob Herring (Arm)
Add a binding schema for Arm Ethos-U65/U85 NPU. The Arm Ethos-U NPUs are designed for edge AI inference applications.
Signed-off-by Rob Herring (Arm) <[email protected]>--- .../devicetree/bindings/npu/arm,ethos.yaml | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+)Documentation/devicetree/bindings/npu/arm,ethos.yaml new file +23
-0@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/npu/arm,ethos.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Arm Ethos U65/U85 + +maintainers: + - Rob Herring <[email protected]> + +description: > + The Arm Ethos-U NPUs are designed for IoT inference applications. The NPUs + can accelerate 8-bit and 16-bit integer quantized networks: + + Transformer networks (U85 only) + Convolutional Neural Networks (CNN) + Recurrent Neural Networks (RNN) + + Further documentation is available here: + + U65 TRM: https://developer.arm.com/documentation/102023/ + U85 TRM: https://developer.arm.com/documentation/102685/
Documentation/devicetree/bindings/npu/arm,ethos.yaml line 33
Quoted 10 lines
Documentation/devicetree/bindings/npu/arm,ethos.yaml new file +10
-0+ +properties: + compatible: + oneOf: + - items: + - enum: + - fsl,imx93-npu + - const: arm,ethos-u65 + - items: + - {}
what's means {} here ?, just not allow arm,ethos-u85 alone?
Quoted 50 lines
Documentation/devicetree/bindings/npu/arm,ethos.yaml new file +46
-1+ - const: arm,ethos-u85 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: core + - const: apb + + power-domains: + maxItems: 1 + + sram: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/clock/imx93-clock.h> + + npu@4a900000 { + compatible = "fsl,imx93-npu", "arm,ethos-u65"; + reg = <0x4a900000 0x1000>; + interrupts = <GIC_SPI 178 IRQ_TYPE_LEVEL_HIGH>; + power-domains = <&mlmix>; + clocks = <&clk IMX93_CLK_ML>, <&clk IMX93_CLK_ML_APB>; + clock-names = "core", "apb"; + sram = <&sram>; + }; +... --2.51.0
Rob Herring
maintainerRe: [PATCH v3 1/2] dt-bindings: npu: Add Arm Ethos-U65/U85
Quoted 43 lines · Frank Li
Quoted 41 lines · Rob Herring (Arm)
Add a binding schema for Arm Ethos-U65/U85 NPU. The Arm Ethos-U NPUs are designed for edge AI inference applications.
Signed-off-by Rob Herring (Arm) <[email protected]>--- .../devicetree/bindings/npu/arm,ethos.yaml | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+)Documentation/devicetree/bindings/npu/arm,ethos.yaml new file +27
-0@@ -0,0 +1,79 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/npu/arm,ethos.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Arm Ethos U65/U85 + +maintainers: + - Rob Herring <[email protected]> + +description: > + The Arm Ethos-U NPUs are designed for IoT inference applications. The NPUs + can accelerate 8-bit and 16-bit integer quantized networks: + + Transformer networks (U85 only) + Convolutional Neural Networks (CNN) + Recurrent Neural Networks (RNN) + + Further documentation is available here: + + U65 TRM: https://developer.arm.com/documentation/102023/ + U85 TRM: https://developer.arm.com/documentation/102685/ + +properties: + compatible: + oneOf:
Quoted 8 lines
Documentation/devicetree/bindings/npu/arm,ethos.yaml line 33
Quoted 6 lines
Documentation/devicetree/bindings/npu/arm,ethos.yaml new file +6
-0+ - items: + - enum: + - fsl,imx93-npu + - const: arm,ethos-u65 + - items: + - {}what's means {} here ?, just not allow arm,ethos-u85 alone?
Yes, u85 support is currently on a FVP model. The naming for it isn't really clear yet nor is it clear if it ever will be. So really just a placeholder until there is a chip using it. It keeps folks from using just the fallback.
Quoted 2 lines
Reviewed-by Frank Li <[email protected]>
Thanks,
Rob
Rob Herring (Arm)
maintainerPATCH v3 2/2 accel: Add Arm Ethos-U NPU driver
In reply to Rob Herring (Arm)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.
---
v3:
- Rework and improve job submit validation
- Rename ethos to ethosu. There was an Ethos-Nxx that's unrelated.
- Add missing init for sched_lock mutex
- Drop some prints to debug level
- Fix i.MX93 SRAM accesses (AXI config)
- Add U85 AXI configuration
- Print the current cmd value on timeout
v2:
- Rebase on v6.17-rc1 adapting to scheduler changes
- scheduler: Drop the reset workqueue. According to the scheduler docs, we don't need it since we have a single h/w queue.
- scheduler: Rework the timeout handling to continue running if we are making progress.
- Reset the NPU on resume so it's in a known state
- Add error handling on clk_get() calls
- Fix drm_mm splat on module unload. We were missing a put on the cmdstream BO in the scheduler clean-up.
- Fix 0-day report needing explicit bitfield.h include
--- MAINTAINERS | 9 + drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 1 + drivers/accel/ethosu/Kconfig | 10 + drivers/accel/ethosu/Makefile | 4 + drivers/accel/ethosu/ethosu_device.h | 187 +++++++++ drivers/accel/ethosu/ethosu_drv.c | 430 +++++++++++++++++++++ drivers/accel/ethosu/ethosu_drv.h | 15 + drivers/accel/ethosu/ethosu_gem.c | 709 +++++++++++++++++++++++++++++++++++ drivers/accel/ethosu/ethosu_gem.h | 46 +++ drivers/accel/ethosu/ethosu_job.c | 543 +++++++++++++++++++++++++++ drivers/accel/ethosu/ethosu_job.h | 41 ++ include/uapi/drm/ethosu_accel.h | 262 +++++++++++++ 13 files changed, 2258 insertions(+)
MAINTAINERS +9 -0
@@ -1991,6 +1991,15 @@ F: arch/arm/include/asm/arch_timer.h F: arch/arm64/include/asm/arch_timer.h F: drivers/clocksource/arm_arch_timer.c +ARM ETHOS-U NPU DRIVER +M: Rob Herring (Arm) <[email protected]> +M: Tomeu Vizoso <[email protected]> +L: [email protected] +S: Supported +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: drivers/accel/ethosu/ +F: include/uapi/drm/ethosu_accel.h + ARM GENERIC INTERRUPT CONTROLLER DRIVERS M: Marc Zyngier <[email protected]> L: [email protected] (moderated for non-subscribers)
drivers/accel/Kconfig +1 -0
@@ -25,6 +25,7 @@ menuconfig DRM_ACCEL and debugfs). source "drivers/accel/amdxdna/Kconfig" +source "drivers/accel/ethosu/Kconfig" source "drivers/accel/habanalabs/Kconfig" source "drivers/accel/ivpu/Kconfig" source "drivers/accel/qaic/Kconfig"
drivers/accel/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only 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_QAIC) += qaic/
drivers/accel/ethosu/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config DRM_ACCEL_ARM_ETHOSU + tristate "Arm Ethos-U65/U85 NPU" + depends on HAS_IOMEM + depends on DRM_ACCEL + select DRM_GEM_DMA_HELPER + select DRM_SCHED + help + Enables driver for Arm Ethos-U65/U85 NPUs
drivers/accel/ethosu/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_ACCEL_ARM_ETHOSU) := ethosu.o +ethosu-y += ethosu_drv.o ethosu_gem.o ethosu_job.o
drivers/accel/ethosu/ethosu_device.h new file +187 -0
187 lines not on this page · raw message
drivers/accel/ethosu/ethosu_drv.c new file +430 -0
430 lines not on this page · raw message
drivers/accel/ethosu/ethosu_drv.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* Copyright 2025 Arm, Ltd. */ +#ifndef __ETHOSU_DRV_H__ +#define __ETHOSU_DRV_H__ + +#include <drm/gpu_scheduler.h> + +struct ethosu_device ; + +struct ethosu_file_priv { +struct ethosu_device *edev; +struct drm_sched_entity sched_entity; +}; + +#endif
drivers/accel/ethosu/ethosu_gem.c new file +709 -0
709 lines not on this page · raw message
drivers/accel/ethosu/ethosu_gem.h new file +46 -0
46 lines not on this page · raw message
drivers/accel/ethosu/ethosu_job.c new file +543 -0
543 lines not on this page · raw message
drivers/accel/ethosu/ethosu_job.h new file +41 -0
41 lines not on this page · raw message
include/uapi/drm/ethosu_accel.h new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
2.51.0
kernel test robot
build botRe: [PATCH v3 2/2] accel: Add Arm Ethos-U NPU driver
kernel test robot noticed the following build errors:
Hi Rob,
kernel test robot noticed the following build errors:
[auto build test ERROR on 8f5ae30d69d7543eee0d70083daf4de8fe15d585]
url: https://github.com/intel-lab-lkp/linux/commits/Rob-Herring-Arm/dt-bindings-npu-Add-Arm-Ethos-U65-U85/20250927-040244 base: 8f5ae30d69d7543eee0d70083daf4de8fe15d585 patch link: https://lore.kernel.org/r/20250926-ethos-v3-2-6bd24373e4f5%40kernel.org patch subject: [PATCH v3 2/2] accel: Add Arm Ethos-U NPU driver config: riscv-allyesconfig (https://download.01.org/0day-ci/archive/20250930/[email protected]/config) compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250930/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/accel/ethosu/ethosu_gem.c:222:3: error: expected expression
u32 element_size = BIT((fm->precision >> 1) & 0x3);
^
>> drivers/accel/ethosu/ethosu_gem.c:224:60: error: use of undeclared identifier 'element_size'
addr += (c / 16) * fm->stride_c + (16 * x + (c & 0xf)) * element_size;
^
drivers/accel/ethosu/ethosu_gem.c:393:4: error: expected expression
u64 srclen = dma_length(info, &st.dma, &st.dma.src);
^
>> drivers/accel/ethosu/ethosu_gem.c:399:43: error: use of undeclared identifier 'srclen'; did you mean 'strlen'?
st.dma.src.region, st.dma.src.offset, srclen,
^~~~~~
strlen
include/linux/dev_printk.h:165:39: note: expanded from macro 'dev_dbg'
dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
^
include/linux/dynamic_debug.h:274:19: note: expanded from macro 'dynamic_dev_dbg'
dev, fmt, ##__VA_ARGS__)
^
include/linux/dynamic_debug.h:250:59: note: expanded from macro '_dynamic_func_call'
_dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
^
include/linux/dynamic_debug.h:248:65: note: expanded from macro '_dynamic_func_call_cls'
__dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
^
include/linux/dynamic_debug.h:224:15: note: expanded from macro '__dynamic_func_call_cls'
func(&id, ##__VA_ARGS__); \
^
include/linux/string.h:201:24: note: 'strlen' declared here
extern __kernel_size_t strlen(const char *);
^4 errors generated.
vim +222 drivers/accel/ethosu/ethosu_gem.c
180
181 static u64 feat_matrix_length(struct ethosu_validated_cmdstream_info *info,
182 struct feat_matrix *fm,
183 u32 x, u32 y, u32 c)
184 {
185 int storage = fm->precision >> 14;
186 int tile = 0;
187
188 if (fm->region < 0)
189 return U64_MAX;
190
191 switch (storage) {
192 case 0:
193 if (x >= fm->width0 + 1) {
194 x -= fm->width0 + 1;
195 tile += 1;
196 }
197 if (y >= fm->height[tile] + 1) {
198 y -= fm->height[tile] + 1;
199 tile += 2;
200 }
201 break;
202 case 1:
203 if (y >= fm->height[1] + 1) {
204 y -= fm->height[1] + 1;
205 tile = 2;
206 } else if (y >= fm->height[0] + 1) {
207 y -= fm->height[0] + 1;
208 tile = 1;
209 }
210 break;
211 }
212 if (fm->base[tile] == U64_MAX)
213 return U64_MAX;
214
215 u64 addr = fm->base[tile] + y * fm->stride_y;
216
217 switch ((fm->precision >> 6) & 0x3) { // format
218 case 0: //nhwc:
219 addr += x * fm->stride_x + c;
220 break;
221 case 1: //nhcwb16:
> 222 u32 element_size = BIT((fm->precision >> 1) & 0x3);
223
> 224 addr += (c / 16) * fm->stride_c + (16 * x + (c & 0xf)) * element_size;
225 break;
226 }
227
228 info->region_size[fm->region] = max(info->region_size[fm->region], addr + 1);
229
230 return addr;
231 }
232
233 static int calc_sizes(struct drm_device *ddev,
234 struct ethosu_validated_cmdstream_info *info,
235 u16 op, struct cmd_state *st,
236 bool ifm, bool ifm2, bool weight, bool scale)
237 {
238 u64 len;
239
240 if (ifm) {
241 if (st->ifm.stride_kernel == U16_MAX)
242 return -EINVAL;
243 u32 stride_y = ((st->ifm.stride_kernel >> 8) & 0x2) +
244 ((st->ifm.stride_kernel >> 1) & 0x1) + 1;
245 u32 stride_x = ((st->ifm.stride_kernel >> 5) & 0x2) +
246 (st->ifm.stride_kernel & 0x1) + 1;
247 u32 ifm_height = st->ofm.height[2] * stride_y +
248 st->ifm.height[2] - (st->ifm.pad_top + st->ifm.pad_bottom);
249 u32 ifm_width = st->ofm.width * stride_x +
250 st->ifm.width - (st->ifm.pad_left + st->ifm.pad_right);
251
252 len = feat_matrix_length(info, &st->ifm, ifm_width,
253 ifm_height, st->ifm.depth);
254 dev_dbg(ddev->dev, "op %d: IFM:%d:0x%llx-0x%llx\n",
255 op, st->ifm.region, st->ifm.base[0], len);
256 if (len == U64_MAX)
257 return -EINVAL;
258 }
259
260 if (ifm2) {
261 len = feat_matrix_length(info, &st->ifm2, st->ifm.depth,
262 0, st->ofm.depth);
263 dev_dbg(ddev->dev, "op %d: IFM2:%d:0x%llx-0x%llx\n",
264 op, st->ifm2.region, st->ifm2.base[0], len);
265 if (len == U64_MAX)
266 return -EINVAL;
267 }
268
269 if (weight) {
270 dev_dbg(ddev->dev, "op %d: W:%d:0x%llx-0x%llx\n",
271 op, st->weight[0].region, st->weight[0].base,
272 st->weight[0].base + st->weight[0].length - 1);
273 if (st->weight[0].region < 0 || st->weight[0].base == U64_MAX ||
274 st->weight[0].length == U32_MAX)
275 return -EINVAL;
276 info->region_size[st->weight[0].region] =
277 max(info->region_size[st->weight[0].region],
278 st->weight[0].base + st->weight[0].length);
279 }
280
281 if (scale) {
282 dev_dbg(ddev->dev, "op %d: S:%d:0x%llx-0x%llx\n",
283 op, st->scale[0].region, st->scale[0].base,
284 st->scale[0].base + st->scale[0].length - 1);
285 if (st->scale[0].region < 0 || st->scale[0].base == U64_MAX ||
286 st->scale[0].length == U32_MAX)
287 return -EINVAL;
288 info->region_size[st->scale[0].region] =
289 max(info->region_size[st->scale[0].region],
290 st->scale[0].base + st->scale[0].length);
291 }
292
293 len = feat_matrix_length(info, &st->ofm, st->ofm.width,
294 st->ofm.height[2], st->ofm.depth);
295 dev_dbg(ddev->dev, "op %d: OFM:%d:0x%llx-0x%llx\n",
296 op, st->ofm.region, st->ofm.base[0], len);
297 if (len == U64_MAX)
298 return -EINVAL;
299 info->output_region[st->ofm.region] = true;
300
301 return 0;
302 }
303
304 static int calc_sizes_elemwise(struct drm_device *ddev,
305 struct ethosu_validated_cmdstream_info *info,
306 u16 op, struct cmd_state *st,
307 bool ifm, bool ifm2)
308 {
309 u32 height, width, depth;
310 u64 len;
311
312 if (ifm) {
313 height = st->ifm.broadcast & 0x1 ? 0 : st->ofm.height[2];
314 width = st->ifm.broadcast & 0x2 ? 0 : st->ofm.width;
315 depth = st->ifm.broadcast & 0x4 ? 0 : st->ofm.depth;
316
317 len = feat_matrix_length(info, &st->ifm, width,
318 height, depth);
319 dev_dbg(ddev->dev, "op %d: IFM:%d:0x%llx-0x%llx\n",
320 op, st->ifm.region, st->ifm.base[0], len);
321 if (len == U64_MAX)
322 return -EINVAL;
323 }
324
325 if (ifm2) {
326 height = st->ifm2.broadcast & 0x1 ? 0 : st->ofm.height[2];
327 width = st->ifm2.broadcast & 0x2 ? 0 : st->ofm.width;
328 depth = st->ifm2.broadcast & 0x4 ? 0 : st->ofm.depth;
329
330 len = feat_matrix_length(info, &st->ifm2, width,
331 height, depth);
332 dev_dbg(ddev->dev, "op %d: IFM2:%d:0x%llx-0x%llx\n",
333 op, st->ifm2.region, st->ifm2.base[0], len);
334 if (len == U64_MAX)
335 return -EINVAL;
336 }
337
338 len = feat_matrix_length(info, &st->ofm, st->ofm.width,
339 st->ofm.height[2], st->ofm.depth);
340 dev_dbg(ddev->dev, "op %d: OFM:%d:0x%llx-0x%llx\n",
341 op, st->ofm.region, st->ofm.base[0], len);
342 if (len == U64_MAX)
343 return -EINVAL;
344 info->output_region[st->ofm.region] = true;
345
346 return 0;
347 }
348
349 static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
350 u32 __user *ucmds,
351 struct ethosu_gem_object *bo,
352 u32 size)
353 {
354 struct ethosu_validated_cmdstream_info *info;
355 u32 *bocmds = bo->base.vaddr;
356 struct cmd_state st;
357 int i, ret;
358
359 cmd_state_init(&st);
360
361 info = kzalloc(sizeof(*info), GFP_KERNEL);
362 if (!info)
363 return -ENOMEM;
364 info->cmd_size = size;
365
366 for (i = 0; i < size/4; i++) {
367 bool use_ifm, use_ifm2, use_scale;
368 u16 cmd, param;
369 u32 cmds[2];
370 u64 addr;
371
372 if (get_user(cmds[0], ucmds++)) {
373 ret = -EFAULT;
374 goto fault;
375 }
376 bocmds[i] = cmds[0];
377
378 cmd = cmds[0];
379 param = cmds[0] >> 16;
380
381 if (cmd & 0x4000) {
382 if (get_user(cmds[1], ucmds++)) {
383 ret = -EFAULT;
384 goto fault;
385 }
386 i++;
387 bocmds[i] = cmds[1];
388 addr = cmd_to_addr(cmds);
389 }
390
391 switch (cmd) {
392 case NPU_OP_DMA_START:
393 u64 srclen = dma_length(info, &st.dma, &st.dma.src);
394 u64 dstlen = dma_length(info, &st.dma, &st.dma.dst);
395
396 if (st.dma.dst.region >= 0)
397 info->output_region[st.dma.dst.region] = true;
398 dev_dbg(ddev->dev, "cmd: DMA SRC:%d:0x%llx+0x%llx DST:%d:0x%llx+0x%llx\n",
> 399 st.dma.src.region, st.dma.src.offset, srclen, 400 st.dma.dst.region, st.dma.dst.offset, dstlen);
401 break;
402 case NPU_OP_CONV:
403 case NPU_OP_DEPTHWISE:
404 use_ifm2 = param & 0x1; // weights_ifm2
405 use_scale = !(st.ofm.precision & 0x100);
406 ret = calc_sizes(ddev, info, cmd, &st, true, use_ifm2,
407 !use_ifm2, use_scale);
408 if (ret)
409 goto fault;
410 break;
411 case NPU_OP_POOL:
412 use_ifm = param != 0x4; // pooling mode
413 use_scale = !(st.ofm.precision & 0x100);
414 ret = calc_sizes(ddev, info, cmd, &st, use_ifm, false,
415 false, use_scale);
416 if (ret)
417 goto fault;
418 break;
419 case NPU_OP_ELEMENTWISE:
420 use_ifm2 = !((st.ifm2.broadcast == 8) || (param == 5) ||
421 (param == 6) || (param == 7) || (param == 0x24));
422 use_ifm = st.ifm.broadcast != 8;
423 ret = calc_sizes_elemwise(ddev, info, cmd, &st, use_ifm, use_ifm2);
424 if (ret)
425 goto fault;
426 break;
427 case NPU_OP_RESIZE: // U85 only
428 WARN_ON(1); // TODO
429 break;
430 case NPU_SET_KERNEL_WIDTH_M1:
431 st.ifm.width = param;
432 break;
433 case NPU_SET_KERNEL_HEIGHT_M1:
434 st.ifm.height[2] = param;
435 break;
436 case NPU_SET_KERNEL_STRIDE:
437 st.ifm.stride_kernel = param;
438 break;
439 case NPU_SET_IFM_PAD_TOP:
440 st.ifm.pad_top = param & 0x7f;
441 break;
442 case NPU_SET_IFM_PAD_LEFT:
443 st.ifm.pad_left = param & 0x7f;
444 break;
445 case NPU_SET_IFM_PAD_RIGHT:
446 st.ifm.pad_right = param & 0xff;
447 break;
448 case NPU_SET_IFM_PAD_BOTTOM:
449 st.ifm.pad_bottom = param & 0xff;
450 break;
451 case NPU_SET_IFM_DEPTH_M1:
452 st.ifm.depth = param;
453 break;
454 case NPU_SET_IFM_PRECISION:
455 st.ifm.precision = param;
456 break;
457 case NPU_SET_IFM_BROADCAST:
458 st.ifm.broadcast = param;
459 break;
460 case NPU_SET_IFM_REGION:
461 st.ifm.region = param & 0x7f;
462 break;
463 case NPU_SET_IFM_WIDTH0_M1:
464 st.ifm.width0 = param;
465 break;
466 case NPU_SET_IFM_HEIGHT0_M1:
467 st.ifm.height[0] = param;
468 break;
469 case NPU_SET_IFM_HEIGHT1_M1:
470 st.ifm.height[1] = param;
471 break;
472 case NPU_SET_IFM_BASE0:
473 case NPU_SET_IFM_BASE1:
474 case NPU_SET_IFM_BASE2:
475 case NPU_SET_IFM_BASE3:
476 st.ifm.base[cmd & 0x3] = addr;
477 break;
478 case NPU_SET_IFM_STRIDE_X:
479 st.ifm.stride_x = addr;
480 break;
481 case NPU_SET_IFM_STRIDE_Y:
482 st.ifm.stride_y = addr;
483 break;
484 case NPU_SET_IFM_STRIDE_C:
485 st.ifm.stride_c = addr;
486 break;
487
488 case NPU_SET_OFM_WIDTH_M1:
489 st.ofm.width = param;
490 break;
491 case NPU_SET_OFM_HEIGHT_M1:
492 st.ofm.height[2] = param;
493 break;
494 case NPU_SET_OFM_DEPTH_M1:
495 st.ofm.depth = param;
496 break;
497 case NPU_SET_OFM_PRECISION:
498 st.ofm.precision = param;
499 break;
500 case NPU_SET_OFM_REGION:
501 st.ofm.region = param & 0x7;
502 break;
503 case NPU_SET_OFM_WIDTH0_M1:
504 st.ofm.width0 = param;
505 break;
506 case NPU_SET_OFM_HEIGHT0_M1:
507 st.ofm.height[0] = param;
508 break;
509 case NPU_SET_OFM_HEIGHT1_M1:
510 st.ofm.height[1] = param;
511 break;
512 case NPU_SET_OFM_BASE0:
513 case NPU_SET_OFM_BASE1:
514 case NPU_SET_OFM_BASE2:
515 case NPU_SET_OFM_BASE3:
516 st.ofm.base[cmd & 0x3] = addr;
517 break;
518 case NPU_SET_OFM_STRIDE_X:
519 st.ofm.stride_x = addr;
520 break;
521 case NPU_SET_OFM_STRIDE_Y:
522 st.ofm.stride_y = addr;
523 break;
524 case NPU_SET_OFM_STRIDE_C:
525 st.ofm.stride_c = addr;
526 break;
527
528 case NPU_SET_IFM2_BROADCAST:
529 st.ifm2.broadcast = param;
530 break;
531 case NPU_SET_IFM2_PRECISION:
532 st.ifm2.precision = param;
533 break;
534 case NPU_SET_IFM2_REGION:
535 st.ifm2.region = param & 0x7;
536 break;
537 case NPU_SET_IFM2_WIDTH0_M1:
538 st.ifm2.width0 = param;
539 break;
540 case NPU_SET_IFM2_HEIGHT0_M1:
541 st.ifm2.height[0] = param;
542 break;
543 case NPU_SET_IFM2_HEIGHT1_M1:
544 st.ifm2.height[1] = param;
545 break;
546 case NPU_SET_IFM2_BASE0:
547 case NPU_SET_IFM2_BASE1:
548 case NPU_SET_IFM2_BASE2:
549 case NPU_SET_IFM2_BASE3:
550 st.ifm2.base[cmd & 0x3] = addr;
551 break;
552 case NPU_SET_IFM2_STRIDE_X:
553 st.ifm2.stride_x = addr;
554 break;
555 case NPU_SET_IFM2_STRIDE_Y:
556 st.ifm2.stride_y = addr;
557 break;
558 case NPU_SET_IFM2_STRIDE_C:
559 st.ifm2.stride_c = addr;
560 break;
561
562 case NPU_SET_WEIGHT_REGION:
563 st.weight[0].region = param & 0x7;
564 break;
565 case NPU_SET_SCALE_REGION:
566 st.scale[0].region = param & 0x7;
567 break;
568 case NPU_SET_WEIGHT_BASE:
569 st.weight[0].base = addr;
570 break;
571 case NPU_SET_WEIGHT_LENGTH:
572 st.weight[0].length = cmds[1];
573 break;
574 case NPU_SET_SCALE_BASE:
575 st.scale[0].base = addr;
576 break;
577 case NPU_SET_SCALE_LENGTH:
578 st.scale[0].length = cmds[1];
579 break;
580 case NPU_SET_WEIGHT1_BASE:
581 st.weight[1].base = addr;
582 break;
583 case NPU_SET_WEIGHT1_LENGTH:
584 st.weight[1].length = cmds[1];
585 break;
586 case NPU_SET_SCALE1_BASE: // NPU_SET_WEIGHT2_BASE (U85)
587 if (0 /*U85*/)
588 st.weight[2].base = addr;
589 else
590 st.scale[1].base = addr;
591 break;
592 case NPU_SET_SCALE1_LENGTH: // NPU_SET_WEIGHT2_LENGTH (U85)
593 if (0 /*U85*/)
594 st.weight[1].length = cmds[1];
595 else
596 st.scale[1].length = cmds[1];
597 break;
598 case NPU_SET_WEIGHT3_BASE:
599 st.weight[3].base = addr;
600 break;
601 case NPU_SET_WEIGHT3_LENGTH:
602 st.weight[3].length = cmds[1];
603 break;
604
605 case NPU_SET_DMA0_SRC_REGION:
606 if (param & 0x100)
607 st.dma.src.region = -1;
608 else
609 st.dma.src.region = param & 0x7;
610 st.dma.mode = (param >> 9) & 0x3;
611 break;
612 case NPU_SET_DMA0_DST_REGION:
613 if (param & 0x100)
614 st.dma.dst.region = -1;
615 else
616 st.dma.dst.region = param & 0x7;
617 break;
618 case NPU_SET_DMA0_SIZE0:
619 st.dma.size0 = param;
620 break;
621 case NPU_SET_DMA0_SIZE1:
622 st.dma.size1 = param;
623 break;
624 case NPU_SET_DMA0_SRC_STRIDE0:
625 st.dma.src.stride[0] = ((s64)addr << 24) >> 24;
626 break;
627 case NPU_SET_DMA0_SRC_STRIDE1:
628 st.dma.src.stride[1] = ((s64)addr << 24) >> 24;
629 break;
630 case NPU_SET_DMA0_DST_STRIDE0:
631 st.dma.dst.stride[0] = ((s64)addr << 24) >> 24;
632 break;
633 case NPU_SET_DMA0_DST_STRIDE1:
634 st.dma.dst.stride[1] = ((s64)addr << 24) >> 24;
635 break;
636 case NPU_SET_DMA0_SRC:
637 st.dma.src.offset = addr;
638 break;
639 case NPU_SET_DMA0_DST:
640 st.dma.dst.offset = addr;
641 break;
642 case NPU_SET_DMA0_LEN:
643 st.dma.src.len = st.dma.dst.len = addr;
644 break;
645 default:
646 break;
647 }
648
649 }
650
651 for (i = 0; i < NPU_BASEP_REGION_MAX; i++) {
652 if (!info->region_size[i])
653 continue;
654 dev_dbg(ddev->dev, "region %d max size: 0x%llx\n",
655 i, info->region_size[i]);
656 }
657
658 bo->info = info;
659 return 0;
660
661 fault:
662 kfree(info);
663 return ret;
664 }
665
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v3 2/2] accel: Add Arm Ethos-U NPU driver
In reply to Rob Herring (Arm)Quoted 103 lines · Rob Herring (Arm)
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.
Signed-off-by Rob Herring (Arm) <[email protected]>---
v3:
- Rework and improve job submit validation
- Rename ethos to ethosu. There was an Ethos-Nxx that's unrelated.
- Add missing init forsched_lockmutex
- Drop some prints to debug level
- Fix i.MX93 SRAM accesses (AXI config)
- Add U85 AXI configuration
- Print the current cmd value on timeoutv2:
- Rebase on v6.17-rc1 adapting to scheduler changes
- scheduler: Drop the reset workqueue. According to the scheduler docs, we don't need it since we have a single h/w queue.
- scheduler: Rework the timeout handling to continue running if we are making progress.
- Reset the NPU on resume so it's in a known state
- Add error handling onclk_get()calls
- Fixdrm_mmsplat on module unload. We were missing a put on the cmdstream BO in the scheduler clean-up.
- Fix 0-day report needing explicitbitfield.hinclude--- MAINTAINERS | 9 + drivers/accel/Kconfig | 1 + drivers/accel/Makefile | 1 + drivers/accel/ethosu/Kconfig | 10 + drivers/accel/ethosu/Makefile | 4 + drivers/accel/ethosu/ethosu_device.h | 187 +++++++++ drivers/accel/ethosu/ethosu_drv.c | 430 +++++++++++++++++++++ drivers/accel/ethosu/ethosu_drv.h | 15 + drivers/accel/ethosu/ethosu_gem.c | 709 +++++++++++++++++++++++++++++++++++ drivers/accel/ethosu/ethosu_gem.h | 46 +++ drivers/accel/ethosu/ethosu_job.c | 543 +++++++++++++++++++++++++++ drivers/accel/ethosu/ethosu_job.h | 41 ++ include/uapi/drm/ethosu_accel.h | 262 +++++++++++++ 13 files changed, 2258 insertions(+)MAINTAINERS +9
-0@@ -1991,6 +1991,15 @@ F: arch/arm/include/asm/arch_timer.h F: arch/arm64/include/asm/arch_timer.h F: drivers/clocksource/arm_arch_timer.c +ARM ETHOS-U NPU DRIVER +M: Rob Herring (Arm) <[email protected]> +M: Tomeu Vizoso <[email protected]> +L: [email protected] +S: Supported +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: drivers/accel/ethosu/ +F: include/uapi/drm/ethosu_accel.h + ARM GENERIC INTERRUPT CONTROLLER DRIVERS M: Marc Zyngier <[email protected]> L: [email protected] (moderated for non-subscribers)drivers/accel/Kconfig +1
-0@@ -25,6 +25,7 @@ menuconfig DRM_ACCEL and debugfs). source "drivers/accel/amdxdna/Kconfig" +source "drivers/accel/ethosu/Kconfig" source "drivers/accel/habanalabs/Kconfig" source "drivers/accel/ivpu/Kconfig" source "drivers/accel/qaic/Kconfig"drivers/accel/Makefile +1
-0@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only 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_QAIC) += qaic/
...
Quoted 11 lines
drivers/accel/Makefile +11
-0+#include <drm/ethosu_accel.h> + +struct clk; +struct gen_pool; + +#define NPU_REG_ID 0x0000 +#define NPU_REG_STATUS 0x0004 +#define NPU_REG_CMD 0x0008 +#define NPU_REG_RESET 0x000C +#define NPU_REG_QBASE 0x0010 +#define NPU_REG_QBASE_HI 0x0014
drivers/accel/Makefile
Quoted 10 lines
drivers/accel/Makefile +10
-0+#define NPU_REG_QREAD 0x0018 +#define NPU_REG_QCONFIG 0x001C +#define NPU_REG_QSIZE 0x0020 +#define NPU_REG_PROT 0x0024 +#define NPU_REG_CONFIG 0x0028 +#define NPU_REG_REGIONCFG 0x003C +#define NPU_REG_AXILIMIT0 0x0040 // U65 +#define NPU_REG_AXILIMIT1 0x0044 // U65 +#define NPU_REG_AXILIMIT2 0x0048 // U65 +#define NPU_REG_AXILIMIT3 0x004c // U65
Nit: can you keep low-case/up-case consistent for Hex value
Quoted 7 lines
drivers/accel/Makefile +7
-0+#define NPU_REG_MEM_ATTR0 0x0040 // U85 +#define NPU_REG_MEM_ATTR1 0x0044 // U85 +#define NPU_REG_MEM_ATTR2 0x0048 // U85 +#define NPU_REG_MEM_ATTR3 0x004c // U85 +#define NPU_REG_AXI_SRAM 0x0050 // U85 +#define NPU_REG_AXI_EXT 0x0054 // U85 +
...
Quoted 18 lines
drivers/accel/Makefile +18
-0+ +#define ETHOSU_SRAM_REGION 2 /* Matching Vela compiler */ + +/** + * struct ethosu_device - Ethosu device + */ +struct ethosu_device { + /** @base: Base drm_device. */ + struct drm_device base; + + /** @iomem: CPU mapping of the registers. */ + void __iomem *regs; + + void __iomem *sram; + struct gen_pool *srampool; + dma_addr_t sramphys; + + struct clk *core_clk;
drivers/accel/Makefile
Quoted 10 lines
drivers/accel/Makefile +10
-0+ struct clk *apb_clk; + + int irq; + + bool coherent; + + struct drm_ethosu_npu_info npu_info; + + struct ethosu_job *in_flight_job; + struct mutex job_lock;
I remember checkpatch.py require all locks need comments.
Quoted 17 lines
drivers/accel/Makefile +12
-0+ spinlock_t fence_lock; + + struct drm_gpu_scheduler sched; + struct mutex sched_lock; + u64 fence_context; + u64 emit_seqno; +}; + +#define to_ethosu_device(drm_dev) \ + ((struct ethosu_device *)container_of(drm_dev, struct ethosu_device, base)) + +#endifdrivers/accel/ethosu/ethosu_drv.c new file +0
-0
...
drivers/accel/ethosu/ethosu_drv.c line 270
Quoted 13 lines
drivers/accel/ethosu/ethosu_drv.c new file +13
-0+ +static int ethosu_device_resume (struct device *dev) +{ +struct ethosu_device *ethosudev =dev_get_drvdata (dev); +int ret; + + ret =clk_prepare_enable (ethosudev->core_clk); +if (ret) +return ret; + + ret =clk_prepare_enable (ethosudev->apb_clk); +if (ret) + goto err_disable_core_clk;
use clk bulk api should be simple.
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+ + ret =ethosu_reset (ethosudev); +if (!ret) +return 0 ; + +err_disable_core_clk: +clk_disable_unprepare (ethosudev->core_clk); +return ret; +} +
...
Quoted 6 lines
drivers/accel/ethosu/ethosu_drv.c new file +6
-0+ +static int ethosu_init (struct ethosu_device *ethosudev) +{ +int ret; +u32 id, config; +
drivers/accel/ethosu/ethosu_drv.c line 325
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+ 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);
pm_runtime_use_autosuspend() should be after last register read readl_relaxed(ethosudev->regs + NPU_REG_CONFIG);
incase schedule happen between pm_runtime_use_autosuspend(ethosudev->base.dev); and readl().
Quoted 31 lines
drivers/accel/ethosu/ethosu_drv.c new file +31
-0+ +/* 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; + } + + ethosudev->npu_info.id = id =readl_relaxed (ethosudev->regs +NPU_REG_ID ); + ethosudev->npu_info.config = config =readl_relaxed (ethosudev->regs +NPU_REG_CONFIG ); + +ethosu_sram_init (ethosudev); + +dev_info (ethosudev->base.dev, +"Ethos-U NPU, arch v%ld.%ld.%ld, rev r%ldp%ld, cmd stream ver%ld, %d MACs, %dKB SRAM\n" , +FIELD_GET (ID_ARCH_MAJOR_MASK , id), +FIELD_GET (ID_ARCH_MINOR_MASK , id), +FIELD_GET (ID_ARCH_PATCH_MASK , id), +FIELD_GET (ID_VER_MAJOR_MASK , id), +FIELD_GET (ID_VER_MINOR_MASK , id), +FIELD_GET (CONFIG_CMD_STREAM_VER_MASK , config), +1 <<FIELD_GET (CONFIG_MACS_PER_CC_MASK , config), + ethosudev->npu_info.sram_size /1024 ); + +return 0 ; +} + +static int ethosu_probe (struct platform_device *pdev) +{ +int ret; +struct ethosu_device *ethosudev;
drivers/accel/ethosu/ethosu_drv.c line 366
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+ + ethosudev =devm_drm_dev_alloc (&pdev->dev, ðosu_drm_driver, + struct ethosu_device, base); +if (IS_ERR (ethosudev)) +return -ENOMEM ; +platform_set_drvdata (pdev, ethosudev); + + ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (40 )); +if (ret) +return ret;
bigger than 32, dma_set_mask_and_coherent() always return true. Needn't check return value.
Quoted 3 lines
drivers/accel/ethosu/ethosu_drv.c new file +3
-0+ + ethosudev->regs =devm_platform_ioremap_resource (pdev,0 ); +
...
Quoted 8 lines
drivers/accel/ethosu/ethosu_drv.c new file +8
-0+ +/** +* ethosu_gem_create_with_handle() - Create a GEM object and attach it to a handle. +* @file: DRM file. +* @ddev: DRM device. +* @size: Size of the GEM object to allocate. +* @flags: Combination of drm_ethosu_bo_flags flags. +* @handle: Pointer holding the handle pointing to the new GEM object.
drivers/accel/ethosu/ethosu_drv.c
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+* +* Return: Zero on success +*/ +int ethosu_gem_create_with_handle (struct drm_file *file, +struct drm_device *ddev, +u64 *size,u32 flags,u32 *handle) +{ +int ret; +struct drm_gem_dma_object *mem; +struct ethosu_gem_object *bo;
move 'ret' here to keep reverise christmas tree order.
Quoted 22 lines
drivers/accel/ethosu/ethosu_drv.c new file +22
-0+ + mem =drm_gem_dma_create (ddev, *size); +if (IS_ERR (mem)) +return PTR_ERR (mem); + + bo =to_ethosu_bo (&mem->base); + bo->flags = flags; + +/* +* Allocate an id of idr table where the obj is registered +* and handle has the id what user can see. +*/ + ret =drm_gem_handle_create (file, &mem->base, handle); +if (!ret) + *size = bo->base.base.size; + +/* drop reference from allocate - handle holds it now. */ +drm_gem_object_put (&mem->base); + +return ret; +} +
...
drivers/accel/ethosu/ethosu_drv.c
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+ +static void cmd_state_init (struct cmd_state *st) +{ +/* Initialize to all 1s to detect missing setup */ +memset (st,0xff ,sizeof (*st)); +} + +static u64 cmd_to_addr (u32 *cmd) +{ +return ((u64)((cmd[0 ] &0xff0000 ) <<16 )) | cmd[1 ];
will FIELD_PREP helpful?
Quoted 23 lines
drivers/accel/ethosu/ethosu_drv.c new file +23
-0+} + +static u64 dma_length (struct ethosu_validated_cmdstream_info *info, +struct dma_state *dma_st,struct dma *dma) +{ +s8 mode = dma_st->mode; +u64 len = dma->len; + +if (mode >=1 ) { + len += dma->stride[0 ]; + len *= dma_st->size0; + } +if (mode ==2 ) { + len += dma->stride[1 ]; + len *= dma_st->size1; + } +if (dma->region >=0 ) + info->region_size[dma->region] =max (info->region_size[dma->region], + len + dma->offset); + +return len; +} +
...
drivers/accel/ethosu/ethosu_drv.c
Quoted 6 lines
drivers/accel/ethosu/ethosu_drv.c new file +6
-0+ +static void ethosu_job_handle_irq (struct ethosu_device *dev) +{ +u32 status; + +pm_runtime_mark_last_busy (dev->base.dev);
I think don't need pm_runtime_mark_last_busy() here because pm_runtime_put_autosuspend() already call pm_runtime_mark_last_busy().
only mark last busy without pm_runtime_put() can't affect run time pm state, still in active state.
Quoted 18 lines
drivers/accel/ethosu/ethosu_drv.c new file +18
-0+ + status =readl_relaxed (dev->regs +NPU_REG_STATUS ); + +if (status & (STATUS_BUS_STATUS |STATUS_CMD_PARSE_ERR )) { +dev_err (dev->base.dev,"Error IRQ - %x\n" , status); +drm_sched_fault (&dev->sched); +return ; + } + + scoped_guard(mutex, &dev->job_lock) { +if (dev->in_flight_job) { +dma_fence_signal (dev->in_flight_job->done_fence); +pm_runtime_put_autosuspend (dev->base.dev); + dev->in_flight_job =NULL ; + } + } +} +
...
Quoted 6 lines
drivers/accel/ethosu/ethosu_drv.c new file +6
-0+ +int ethosu_job_init (struct ethosu_device *dev) +{ +struct drm_sched_init_args args = { + .ops = ðosu_sched_ops, + .num_rqs =DRM_SCHED_PRIORITY_COUNT ,
drivers/accel/ethosu/ethosu_drv.c
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+ .credit_limit = 1, + .timeout = msecs_to_jiffies(JOB_TIMEOUT_MS), + .name = dev_name(dev->base.dev), + .dev = dev->base.dev, + }; +int ret; + +spin_lock_init (&dev->fence_lock); +mutex_init (&dev->job_lock); +mutex_init (&dev->sched_lock);
now perfer use dev_mutex_init().
Frank
Quoted 30 lines
drivers/accel/ethosu/ethosu_drv.c new file +30
-0+ + dev->irq =platform_get_irq (to_platform_device (dev->base.dev),0 ); +if (dev->irq <0 ) +return dev->irq; + + ret =devm_request_threaded_irq (dev->base.dev, dev->irq, + ethosu_job_irq_handler, + ethosu_job_irq_handler_thread, +IRQF_SHARED ,KBUILD_MODNAME , + dev); +if (ret) { +dev_err (dev->base.dev,"failed to request irq" ); +return ret; + } + + dev->fence_context =dma_fence_context_alloc (1 ); + + ret =drm_sched_init (&dev->sched, &args); +if (ret) { +dev_err (dev->base.dev,"Failed to create scheduler: %d." , ret); + goto err_sched; + } + +return 0 ; + +err_sched: +drm_sched_fini (&dev->sched); +return ret; +} +
...
Quoted 19 lines
drivers/accel/ethosu/ethosu_drv.c new file +15
-1+DRM_IOCTL_ETHOSU_BO_WAIT = +DRM_IOCTL_ETHOSU (WR ,BO_WAIT , bo_wait), +DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET = +DRM_IOCTL_ETHOSU (WR ,BO_MMAP_OFFSET , bo_mmap_offset), +DRM_IOCTL_ETHOSU_CMDSTREAM_BO_CREATE = +DRM_IOCTL_ETHOSU (WR ,CMDSTREAM_BO_CREATE , cmdstream_bo_create), +DRM_IOCTL_ETHOSU_SUBMIT = + DRM_IOCTL_ETHOSU(WR, SUBMIT, submit), +}; + +#if defined(__cplusplus) +} +#endif + +#endif /* _ETHOSU_DRM_H_ */ --2.51.0
Rob Herring
maintainerRe: [PATCH v3 2/2] accel: Add Arm Ethos-U NPU driver
Quoted 32 lines · Frank Li
Quoted 8 lines · Rob Herring (Arm)
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.
...
Quoted 6 lines
drivers/accel/ethosu/ethosu_drv.c new file +6
-0+ +static int ethosu_init (struct ethosu_device *ethosudev) +{ +int ret; +u32 id, config; +drivers/accel/ethosu/ethosu_drv.c line 325
Quoted 10 lines
drivers/accel/ethosu/ethosu_drv.c new file +10
-0+ 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);
pm_runtime_use_autosuspend()should be after last register readreadl_relaxed(ethosudev->regs + NPU_REG_CONFIG);
Quoted 2 lines
incase schedule happen between
pm_runtime_use_autosuspend(ethosudev->base.dev); andreadl().
All the call does is enable autosuspend. I don't think it matters exactly when we enable it. We already did a get preventing autosuspend until we do a put.
Quoted 24 lines
Quoted 9 lines
drivers/accel/ethosu/ethosu_drv.c new file +9
-0+/* 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; + } + + ethosudev->npu_info.id = id =readl_relaxed (ethosudev->regs +NPU_REG_ID ); + ethosudev->npu_info.config = config =readl_relaxed (ethosudev->regs +NPU_REG_CONFIG );...
Quoted 12 lines
drivers/accel/ethosu/ethosu_gem.c new file +12
-0+ +/** +* ethosu_gem_create_with_handle() - Create a GEM object and attach it to a handle. +* @file: DRM file. +* @ddev: DRM device. +* @size: Size of the GEM object to allocate. +* @flags: Combination of drm_ethosu_bo_flags flags. +* @handle: Pointer holding the handle pointing to the new GEM object. +* +* Return: Zero on success +*/ +int ethosu_gem_create_with_handle(struct drm_file *file,
Quoted 8 lines
drivers/accel/ethosu/ethosu_gem.c line 77
Quoted 6 lines
drivers/accel/ethosu/ethosu_gem.c new file +6
-0+struct drm_device *ddev, + u64 *size, u32 flags, u32 *handle) +{ + int ret; +struct drm_gem_dma_object *mem; +struct ethosu_gem_object *bo;move 'ret' here to keep reverise christmas tree order.
Is that the order DRM likes? It's got to be the dumbest coding standard we have.
Quoted 23 lines
Quoted 22 lines
drivers/accel/ethosu/ethosu_gem.c new file +22
-0+ + mem =drm_gem_dma_create (ddev, *size); +if (IS_ERR (mem)) +return PTR_ERR (mem); + + bo =to_ethosu_bo (&mem->base); + bo->flags = flags; + +/* +* Allocate an id of idr table where the obj is registered +* and handle has the id what user can see. +*/ + ret =drm_gem_handle_create (file, &mem->base, handle); +if (!ret) + *size = bo->base.base.size; + +/* drop reference from allocate - handle holds it now. */ +drm_gem_object_put (&mem->base); + +return ret; +} +...
Quoted 12 lines
drivers/accel/ethosu/ethosu_gem.c line 157
Quoted 10 lines
drivers/accel/ethosu/ethosu_gem.c new file +10
-0+ +static void cmd_state_init (struct cmd_state *st) +{ +/* Initialize to all 1s to detect missing setup */ +memset (st,0xff ,sizeof (*st)); +} + +static u64 cmd_to_addr (u32 *cmd) +{ +return ((u64)((cmd[0 ] &0xff0000 ) <<16 )) | cmd[1 ];will
FIELD_PREPhelpful?
Like this?:
return ((u64)FIELD_PREP(GENMASK(23, 16), cmd[0]) << 32) | cmd[1];
Questionable to me if that's better...
Quoted 36 lines
Quoted 24 lines
drivers/accel/ethosu/ethosu_gem.c new file +23
-0+} + +static u64 dma_length (struct ethosu_validated_cmdstream_info *info, +struct dma_state *dma_st,struct dma *dma) +{ +s8 mode = dma_st->mode; +u64 len = dma->len; + +if (mode >=1 ) { + len += dma->stride[0 ]; + len *= dma_st->size0; + } +if (mode ==2 ) { + len += dma->stride[1 ]; + len *= dma_st->size1; + } +if (dma->region >=0 ) + info->region_size[dma->region] =max (info->region_size[dma->region], + len + dma->offset); + +return len; +} +...
drivers/accel/ethosu/ethosu_job.c line 233
Quoted 6 lines
drivers/accel/ethosu/ethosu_job.c new file +6
-0+ +static void ethosu_job_handle_irq (struct ethosu_device *dev) +{ +u32 status; + +pm_runtime_mark_last_busy (dev->base.dev);I think don't need
pm_runtime_mark_last_busy()here becausepm_runtime_put_autosuspend()already callpm_runtime_mark_last_busy().
Quoted 2 lines
only mark last busy without
pm_runtime_put()can't affect run time pm state, still in active state.
Yes, agreed. Copied from rocket, so Tomeu, you may want to look at that.
Quoted 30 lines
Quoted 19 lines
drivers/accel/ethosu/ethosu_job.c new file +18
-0+ + status =readl_relaxed (dev->regs +NPU_REG_STATUS ); + +if (status & (STATUS_BUS_STATUS |STATUS_CMD_PARSE_ERR )) { +dev_err (dev->base.dev,"Error IRQ - %x\n" , status); +drm_sched_fault (&dev->sched); +return ; + } + + scoped_guard(mutex, &dev->job_lock) { +if (dev->in_flight_job) { +dma_fence_signal (dev->in_flight_job->done_fence); +pm_runtime_put_autosuspend (dev->base.dev); + dev->in_flight_job =NULL ; + } + } +} +...
Quoted 10 lines
drivers/accel/ethosu/ethosu_job.c new file +10
-0+ +int ethosu_job_init (struct ethosu_device *dev) +{ +struct drm_sched_init_args args = { + .ops = ðosu_sched_ops, + .num_rqs =DRM_SCHED_PRIORITY_COUNT , + .credit_limit =1 , + .timeout =msecs_to_jiffies (JOB_TIMEOUT_MS ), + .name =dev_name (dev->base.dev), + .dev = dev->base.dev,
Quoted 8 lines
drivers/accel/ethosu/ethosu_job.c line 346
Quoted 6 lines
drivers/accel/ethosu/ethosu_job.c new file +6
-0+ }; +int ret; + +spin_lock_init (&dev->fence_lock); +mutex_init (&dev->job_lock); +mutex_init (&dev->sched_lock);now perfer use
dev_mutex_init().
$ git grep dev_mutex_init (END)
Huh??
Re: [v3,2/2] accel: Add Arm Ethos-U NPU driver
In reply to Rob Herring (Arm)Hi,
On 2025/9/27 04:00, Rob Herring (Arm) wrote:
[...]
Quoted 12 lines
drivers/accel/ethosu/ethosu_device.h new file +12
-0+ +/** +* struct ethosu_device - Ethosu device +*/ +struct ethosu_device { +/** @base: Base drm_device. */ +struct drm_device base; + +/** @iomem: CPU mapping of the registers. */ +void __iomem *regs; + +void __iomem *sram;
drivers/accel/ethosu/ethosu_device.h line 171
Quoted 10 lines
drivers/accel/ethosu/ethosu_device.h new file +10
-0+struct gen_pool *srampool; +dma_addr_t sramphys; + +struct clk *core_clk; +struct clk *apb_clk; + +int irq; + +bool coherent; +
The 'coherent' member is not get used on anywhere.
Best Regards,
Sui
Signature · 2 lines
Best regards, Sui
A message that is not in the archive (sent off-list or not yet received): [email protected]
Rob Herring
maintainerQuoted 7 lines · Patchwork Integration
Dear Rob Herring (Arm):
Thanks for your patches! Unfortunately the Media CI robot detected some issues:
Quoted 5 lines
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport"> <title>Something went wrong (502)</title>
Dear Patchwork,
I think something went wrong on your end. Take the rest of the week off.
Rob
P.S. Every report I've gotten from the Media CI robot seems to be a problem with the robot...
Quoted 124 lines
<style> :root { --background: white; --border: #dcdcde; --color: #3a383f; --subtle: #626168; --link: #0b5cad;background-color: var(--background); color: var(--color); } body { text-align: center; font-family: "GitLab Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; margin: auto; font-size: 14px; } h1 { font-size: 56px; line-height: 100px; font-weight: 400; color: var(--subtle); } h2 { color: var(--subtle); font-size: 20px; font-weight: 400; line-height: 28px; } hr { max-width: 800px; margin: 18px auto; border: 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--background); } img { max-width: 40vw; display: block; margin: 40px auto; } a { line-height: 100px; font-weight: 400; color: var(--link); font-size: 18px; text-decoration: none; } .container { margin: auto 20px; } .go-back { display: none; } @media (prefers-color-scheme: dark) { :root { --background: #18171d; --border: #4c4b51; --color: #ececef; --subtle: #bfbfc3; --link: #9dc7f1; } }</style>
</head><body>
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjE5MiIgdmlld0JveD0iMCAwIDI1IDI0IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgogIDxwYXRoIGQ9Im0yNC41MDcgOS41LS4wMzQtLjA5TDIxLjA4Mi41NjJhLjg5Ni44OTYgMCAwIDAtMS42OTQuMDkxbC0yLjI5IDcuMDFINy44MjVMNS41MzUuNjUzYS44OTguODk4IDAgMCAwLTEuNjk0LS4wOUwuNDUxIDkuNDExLjQxNiA5LjVhNi4yOTcgNi4yOTcgMCAwIDAgMi4wOSA3LjI3OGwuMDEyLjAxLjAzLjAyMiA1LjE2IDMuODY3IDIuNTYgMS45MzUgMS41NTQgMS4xNzZhMS4wNTEgMS4wNTEgMCAwIDAgMS4yNjggMGwxLjU1NS0xLjE3NiAyLjU2LTEuOTM1IDUuMTk3LTMuODkuMDE0LS4wMUE2LjI5NyA2LjI5NyAwIDAgMCAyNC41MDcgOS41WiIKICAgICAgICBmaWxsPSIjRTI0MzI5Ii8+CiAgPHBhdGggZD0ibTI0LjUwNyA5LjUtLjAzNC0uMDlhMTEuNDQgMTEuNDQgMCAwIDAtNC41NiAyLjA1MWwtNy40NDcgNS42MzIgNC43NDIgMy41ODQgNS4xOTctMy44OS4wMTQtLjAxQTYuMjk3IDYuMjk3IDAgMCAwIDI0LjUwNyA5LjVaIgogICAgICAgIGZpbGw9IiNGQzZEMjYiLz4KICA8cGF0aCBkPSJtNy43MDcgMjAuNjc3IDIuNTYgMS45MzUgMS41NTUgMS4xNzZhMS4wNTEgMS4wNTEgMCAwIDAgMS4yNjggMGwxLjU1NS0xLjE3NiAyLjU2LTEuOTM1LTQuNzQzLTMuNTg0LTQuNzU1IDMuNTg0WiIKICAgICAgICBmaWxsPSIjRkNBMzI2Ii8+CiAgPHBhdGggZD0iTTUuMDEgMTEuNDYxYTExLjQzIDExLjQzIDAgMCAwLTQuNTYtMi4wNUwuNDE2IDkuNWE2LjI5NyA2LjI5NyAwIDAgMCAyLjA5IDcuMjc4bC4wMTIuMDEuMDMuMDIyIDUuMTYgMy44NjcgNC43NDUtMy41ODQtNy40NDQtNS42MzJaIgogICAgICAgIGZpbGw9IiNGQzZEMjYiLz4KPC9zdmc+Cg=="
alt="GitLab Logo" />
<h1>502 </h1> <div class="container"> <h2>Whoops, something went wrong on our end.</h2> <hr /> <p>Try refreshing the page, or going back and attempting the action again.</p> <p>Please contact your GitLab administrator if this problem persists.</p> <a href="javascript:history.back()" class="js-go-back go-back">Go back</a> </div> <script> (function () { var goBack = document.querySelector('.js-go-back'); if (history.length > 1) { goBack.style.display = 'inline'; } })();</script>
</body>
</html>Please fix your series, and upload a new version. If you have a patchwork account, do not forget to mark the current series as Superseded.
For more details, check the full report at:
https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/85132778/artifacts/report.htm .Best regards, and Happy Hacking!
Media CI robot on behalf of the linux-media community.---
Check the latest rules for contributing your patches at:
https://docs.kernel.org/driver-api/media/maintainer-entry-profile.htmlIf you believe that the CI is wrong, kindly open an issue at
https://gitlab.freedesktop.org/linux-media/media-ci/-/issues or reply-all to this message.