/* SPDX-License-Identifier: MIT */1/* Copyright (C) 2025 Arm, Ltd. */2#ifndef _ETHOSU_DRM_H_3#define _ETHOSU_DRM_H_45#include "drm.h"67#if defined(__cplusplus)8extern "C" {9#endif1011/**12* DOC: IOCTL IDs13*14* enum drm_ethosu_ioctl_id - IOCTL IDs15*16* Place new ioctls at the end, don't re-order, don't replace or remove entries.17*18* These IDs are not meant to be used directly. Use the DRM_IOCTL_ETHOSU_xxx19* definitions instead.20*/21enum drm_ethosu_ioctl_id {22/** @DRM_ETHOSU_DEV_QUERY: Query device information. */23DRM_ETHOSU_DEV_QUERY = 0,2425/** @DRM_ETHOSU_BO_CREATE: Create a buffer object. */26DRM_ETHOSU_BO_CREATE,2728/** @DRM_ETHOSU_BO_WAIT: Wait on a buffer object's fence. */29DRM_ETHOSU_BO_WAIT,3031/**32* @DRM_ETHOSU_BO_MMAP_OFFSET: Get the file offset to pass to33* mmap to map a GEM object.34*/35DRM_ETHOSU_BO_MMAP_OFFSET,3637/**38* @DRM_ETHOSU_CMDSTREAM_BO_CREATE: Create a command stream buffer39* object.40*/41DRM_ETHOSU_CMDSTREAM_BO_CREATE,4243/** @DRM_ETHOSU_SUBMIT: Submit a job and BOs to run. */44DRM_ETHOSU_SUBMIT,45};4647/**48* DOC: IOCTL arguments49*/5051/**52* enum drm_ethosu_dev_query_type - Query type53*54* Place new types at the end, don't re-order, don't remove or replace.55*/56enum drm_ethosu_dev_query_type {57/** @DRM_ETHOSU_DEV_QUERY_NPU_INFO: Query NPU information. */58DRM_ETHOSU_DEV_QUERY_NPU_INFO = 0,59};6061/**62* struct drm_ethosu_gpu_info - NPU information63*64* Structure grouping all queryable information relating to the NPU.65*/66struct drm_ethosu_npu_info {67/** @id : NPU ID. */68__u32 id;69#define DRM_ETHOSU_ARCH_MAJOR(x) ((x) >> 28)70#define DRM_ETHOSU_ARCH_MINOR(x) (((x) >> 20) & 0xff)71#define DRM_ETHOSU_ARCH_PATCH(x) (((x) >> 16) & 0xf)72#define DRM_ETHOSU_PRODUCT_MAJOR(x) (((x) >> 12) & 0xf)73#define DRM_ETHOSU_VERSION_MAJOR(x) (((x) >> 8) & 0xf)74#define DRM_ETHOSU_VERSION_MINOR(x) (((x) >> 4) & 0xff)75#define DRM_ETHOSU_VERSION_STATUS(x) ((x) & 0xf)7677/** @gpu_rev: GPU revision. */78__u32 config;7980__u32 sram_size;81};8283/**84* struct drm_ethosu_dev_query - Arguments passed to DRM_ETHOSU_IOCTL_DEV_QUERY85*/86struct drm_ethosu_dev_query {87/** @type: the query type (see drm_ethosu_dev_query_type). */88__u32 type;8990/**91* @size: size of the type being queried.92*93* If pointer is NULL, size is updated by the driver to provide the94* output structure size. If pointer is not NULL, the driver will95* only copy min(size, actual_structure_size) bytes to the pointer,96* and update the size accordingly. This allows us to extend query97* types without breaking userspace.98*/99__u32 size;100101/**102* @pointer: user pointer to a query type struct.103*104* Pointer can be NULL, in which case, nothing is copied, but the105* actual structure size is returned. If not NULL, it must point to106* a location that's large enough to hold size bytes.107*/108__u64 pointer;109};110111/**112* enum drm_ethosu_bo_flags - Buffer object flags, passed at creation time.113*/114enum drm_ethosu_bo_flags {115/**116* @DRM_ETHOSU_BO_NO_MMAP: The buffer object will never be CPU-mapped117* in userspace.118*/119DRM_ETHOSU_BO_NO_MMAP = (1 << 0),120};121122/**123* struct drm_ethosu_bo_create - Arguments passed to DRM_IOCTL_ETHOSU_BO_CREATE.124*/125struct drm_ethosu_bo_create {126/**127* @size: Requested size for the object128*129* The (page-aligned) allocated size for the object will be returned.130*/131__u64 size;132133/**134* @flags: Flags. Must be a combination of drm_ethosu_bo_flags flags.135*/136__u32 flags;137138/**139* @handle: Returned handle for the object.140*141* Object handles are nonzero.142*/143__u32 handle;144};145146/**147* struct drm_ethosu_bo_mmap_offset - Arguments passed to DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET.148*/149struct drm_ethosu_bo_mmap_offset {150/** @handle: Handle of the object we want an mmap offset for. */151__u32 handle;152153/** @pad: MBZ. */154__u32 pad;155156/** @offset: The fake offset to use for subsequent mmap calls. */157__u64 offset;158};159160/**161* struct drm_ethosu_wait_bo - ioctl argument for waiting for162* completion of the last DRM_ETHOSU_SUBMIT on a BO.163*164* This is useful for cases where multiple processes might be165* rendering to a BO and you want to wait for all rendering to be166* completed.167*/168struct drm_ethosu_bo_wait {169__u32 handle;170__u32 pad;171__s64 timeout_ns; /* absolute */172};173174struct drm_ethosu_cmdstream_bo_create {175/* Size of the data argument. */176__u32 size;177178/* Flags, currently must be 0. */179__u32 flags;180181/* Pointer to the data. */182__u64 data;183184/** Returned GEM handle for the BO. */185__u32 handle;186187/* Pad, must be 0. */188__u32 pad;189};190191/**192* struct drm_ethosu_job - A job to be run on the NPU193*194* The kernel will schedule the execution of this job taking into account its195* dependencies with other jobs. All tasks in the same job will be executed196* sequentially on the same core, to benefit from memory residency in SRAM.197*/198struct drm_ethosu_job {199/** Input: BO handle for cmdstream. */200__u32 cmd_bo;201202/** Input: Amount of SRAM to use. */203__u32 sram_size;204205#define ETHOSU_MAX_REGIONS 8206/** Input: Array of BO handles for each region. */207__u32 region_bo_handles[ETHOSU_MAX_REGIONS];208};209210/**211* struct drm_ethosu_submit - ioctl argument for submitting commands to the NPU.212*213* The kernel will schedule the execution of these jobs in dependency order.214*/215struct drm_ethosu_submit {216/** Input: Pointer to an array of struct drm_ethosu_job. */217__u64 jobs;218219/** Input: Number of jobs passed in. */220__u32 job_count;221222/** Reserved, must be zero. */223__u32 pad;224};225226/**227* DRM_IOCTL_ETHOSU() - Build a ethosu IOCTL number228* @__access: Access type. Must be R, W or RW.229* @__id: One of the DRM_ETHOSU_xxx id.230* @__type: Suffix of the type being passed to the IOCTL.231*232* Don't use this macro directly, use the DRM_IOCTL_ETHOSU_xxx233* values instead.234*235* Return: An IOCTL number to be passed to ioctl() from userspace.236*/237#define DRM_IOCTL_ETHOSU(__access, __id, __type) \238DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ETHOSU_ ## __id, \239struct drm_ethosu_ ## __type)240241enum {242DRM_IOCTL_ETHOSU_DEV_QUERY =243DRM_IOCTL_ETHOSU(WR, DEV_QUERY, dev_query),244DRM_IOCTL_ETHOSU_BO_CREATE =245DRM_IOCTL_ETHOSU(WR, BO_CREATE, bo_create),246DRM_IOCTL_ETHOSU_BO_WAIT =247DRM_IOCTL_ETHOSU(WR, BO_WAIT, bo_wait),248DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET =249DRM_IOCTL_ETHOSU(WR, BO_MMAP_OFFSET, bo_mmap_offset),250DRM_IOCTL_ETHOSU_CMDSTREAM_BO_CREATE =251DRM_IOCTL_ETHOSU(WR, CMDSTREAM_BO_CREATE, cmdstream_bo_create),252DRM_IOCTL_ETHOSU_SUBMIT =253DRM_IOCTL_ETHOSU(WR, SUBMIT, submit),254};255256#if defined(__cplusplus)257}258#endif259260#endif /* _ETHOSU_DRM_H_ */261262263