Path: blob/master/drivers/accel/ethosu/ethosu_device.h
122915 views
/* SPDX-License-Identifier: GPL-2.0-only or MIT */1/* Copyright 2025 Arm, Ltd. */23#ifndef __ETHOSU_DEVICE_H__4#define __ETHOSU_DEVICE_H__56#include <linux/bitfield.h>7#include <linux/bits.h>8#include <linux/types.h>910#include <drm/drm_device.h>11#include <drm/gpu_scheduler.h>1213#include <drm/ethosu_accel.h>1415struct clk;16struct gen_pool;1718#define NPU_REG_ID 0x000019#define NPU_REG_STATUS 0x000420#define NPU_REG_CMD 0x000821#define NPU_REG_RESET 0x000c22#define NPU_REG_QBASE 0x001023#define NPU_REG_QBASE_HI 0x001424#define NPU_REG_QREAD 0x001825#define NPU_REG_QCONFIG 0x001c26#define NPU_REG_QSIZE 0x002027#define NPU_REG_PROT 0x002428#define NPU_REG_CONFIG 0x002829#define NPU_REG_REGIONCFG 0x003c30#define NPU_REG_AXILIMIT0 0x0040 // U6531#define NPU_REG_AXILIMIT1 0x0044 // U6532#define NPU_REG_AXILIMIT2 0x0048 // U6533#define NPU_REG_AXILIMIT3 0x004c // U6534#define NPU_REG_MEM_ATTR0 0x0040 // U8535#define NPU_REG_MEM_ATTR1 0x0044 // U8536#define NPU_REG_MEM_ATTR2 0x0048 // U8537#define NPU_REG_MEM_ATTR3 0x004c // U8538#define NPU_REG_AXI_SRAM 0x0050 // U8539#define NPU_REG_AXI_EXT 0x0054 // U854041#define NPU_REG_BASEP(x) (0x0080 + (x) * 8)42#define NPU_REG_BASEP_HI(x) (0x0084 + (x) * 8)43#define NPU_BASEP_REGION_MAX 84445#define ID_ARCH_MAJOR_MASK GENMASK(31, 28)46#define ID_ARCH_MINOR_MASK GENMASK(27, 20)47#define ID_ARCH_PATCH_MASK GENMASK(19, 16)48#define ID_VER_MAJOR_MASK GENMASK(11, 8)49#define ID_VER_MINOR_MASK GENMASK(7, 4)5051#define CONFIG_MACS_PER_CC_MASK GENMASK(3, 0)52#define CONFIG_CMD_STREAM_VER_MASK GENMASK(7, 4)5354#define STATUS_STATE_RUNNING BIT(0)55#define STATUS_IRQ_RAISED BIT(1)56#define STATUS_BUS_STATUS BIT(2)57#define STATUS_RESET_STATUS BIT(3)58#define STATUS_CMD_PARSE_ERR BIT(4)59#define STATUS_CMD_END_REACHED BIT(5)6061#define CMD_CLEAR_IRQ BIT(1)62#define CMD_TRANSITION_TO_RUN BIT(0)6364#define RESET_PENDING_CSL BIT(1)65#define RESET_PENDING_CPL BIT(0)6667#define PROT_ACTIVE_CSL BIT(1)6869enum ethosu_cmds {70NPU_OP_CONV = 0x2,71NPU_OP_DEPTHWISE = 0x3,72NPU_OP_POOL = 0x5,73NPU_OP_ELEMENTWISE = 0x6,74NPU_OP_RESIZE = 0x7, // U85 only75NPU_OP_DMA_START = 0x10,76NPU_SET_IFM_PAD_TOP = 0x100,77NPU_SET_IFM_PAD_LEFT = 0x101,78NPU_SET_IFM_PAD_RIGHT = 0x102,79NPU_SET_IFM_PAD_BOTTOM = 0x103,80NPU_SET_IFM_DEPTH_M1 = 0x104,81NPU_SET_IFM_PRECISION = 0x105,82NPU_SET_IFM_BROADCAST = 0x108,83NPU_SET_IFM_WIDTH0_M1 = 0x10a,84NPU_SET_IFM_HEIGHT0_M1 = 0x10b,85NPU_SET_IFM_HEIGHT1_M1 = 0x10c,86NPU_SET_IFM_REGION = 0x10f,87NPU_SET_OFM_WIDTH_M1 = 0x111,88NPU_SET_OFM_HEIGHT_M1 = 0x112,89NPU_SET_OFM_DEPTH_M1 = 0x113,90NPU_SET_OFM_PRECISION = 0x114,91NPU_SET_OFM_WIDTH0_M1 = 0x11a,92NPU_SET_OFM_HEIGHT0_M1 = 0x11b,93NPU_SET_OFM_HEIGHT1_M1 = 0x11c,94NPU_SET_OFM_REGION = 0x11f,95NPU_SET_KERNEL_WIDTH_M1 = 0x120,96NPU_SET_KERNEL_HEIGHT_M1 = 0x121,97NPU_SET_KERNEL_STRIDE = 0x122,98NPU_SET_WEIGHT_REGION = 0x128,99NPU_SET_SCALE_REGION = 0x129,100NPU_SET_DMA0_SRC_REGION = 0x130,101NPU_SET_DMA0_DST_REGION = 0x131,102NPU_SET_DMA0_SIZE0 = 0x132,103NPU_SET_DMA0_SIZE1 = 0x133,104NPU_SET_IFM2_BROADCAST = 0x180,105NPU_SET_IFM2_PRECISION = 0x185,106NPU_SET_IFM2_WIDTH0_M1 = 0x18a,107NPU_SET_IFM2_HEIGHT0_M1 = 0x18b,108NPU_SET_IFM2_HEIGHT1_M1 = 0x18c,109NPU_SET_IFM2_REGION = 0x18f,110NPU_SET_IFM_BASE0 = 0x4000,111NPU_SET_IFM_BASE1 = 0x4001,112NPU_SET_IFM_BASE2 = 0x4002,113NPU_SET_IFM_BASE3 = 0x4003,114NPU_SET_IFM_STRIDE_X = 0x4004,115NPU_SET_IFM_STRIDE_Y = 0x4005,116NPU_SET_IFM_STRIDE_C = 0x4006,117NPU_SET_OFM_BASE0 = 0x4010,118NPU_SET_OFM_BASE1 = 0x4011,119NPU_SET_OFM_BASE2 = 0x4012,120NPU_SET_OFM_BASE3 = 0x4013,121NPU_SET_OFM_STRIDE_X = 0x4014,122NPU_SET_OFM_STRIDE_Y = 0x4015,123NPU_SET_OFM_STRIDE_C = 0x4016,124NPU_SET_WEIGHT_BASE = 0x4020,125NPU_SET_WEIGHT_LENGTH = 0x4021,126NPU_SET_SCALE_BASE = 0x4022,127NPU_SET_SCALE_LENGTH = 0x4023,128NPU_SET_DMA0_SRC = 0x4030,129NPU_SET_DMA0_DST = 0x4031,130NPU_SET_DMA0_LEN = 0x4032,131NPU_SET_DMA0_SRC_STRIDE0 = 0x4033,132NPU_SET_DMA0_SRC_STRIDE1 = 0x4034,133NPU_SET_DMA0_DST_STRIDE0 = 0x4035,134NPU_SET_DMA0_DST_STRIDE1 = 0x4036,135NPU_SET_IFM2_BASE0 = 0x4080,136NPU_SET_IFM2_BASE1 = 0x4081,137NPU_SET_IFM2_BASE2 = 0x4082,138NPU_SET_IFM2_BASE3 = 0x4083,139NPU_SET_IFM2_STRIDE_X = 0x4084,140NPU_SET_IFM2_STRIDE_Y = 0x4085,141NPU_SET_IFM2_STRIDE_C = 0x4086,142NPU_SET_WEIGHT1_BASE = 0x4090,143NPU_SET_WEIGHT1_LENGTH = 0x4091,144NPU_SET_SCALE1_BASE = 0x4092,145NPU_SET_WEIGHT2_BASE = 0x4092,146NPU_SET_SCALE1_LENGTH = 0x4093,147NPU_SET_WEIGHT2_LENGTH = 0x4093,148NPU_SET_WEIGHT3_BASE = 0x4094,149NPU_SET_WEIGHT3_LENGTH = 0x4095,150};151152#define ETHOSU_SRAM_REGION 2 /* Matching Vela compiler */153154/**155* struct ethosu_device - Ethosu device156*/157struct ethosu_device {158/** @base: Base drm_device. */159struct drm_device base;160161/** @iomem: CPU mapping of the registers. */162void __iomem *regs;163164void __iomem *sram;165struct gen_pool *srampool;166dma_addr_t sramphys;167168struct clk_bulk_data *clks;169int num_clks;170int irq;171172struct drm_ethosu_npu_info npu_info;173174struct ethosu_job *in_flight_job;175/* For in_flight_job and ethosu_job_hw_submit() */176struct mutex job_lock;177178/* For dma_fence */179spinlock_t fence_lock;180181struct drm_gpu_scheduler sched;182/* For ethosu_job_do_push() */183struct mutex sched_lock;184u64 fence_context;185u64 emit_seqno;186};187188#define to_ethosu_device(drm_dev) \189((struct ethosu_device *)container_of(drm_dev, struct ethosu_device, base))190191static inline bool ethosu_is_u65(const struct ethosu_device *ethosudev)192{193return FIELD_GET(ID_ARCH_MAJOR_MASK, ethosudev->npu_info.id) == 1;194}195196#endif197198199