| 1 |
/* SPDX-License-Identifier: MIT */ |
| 2 |
/* Copyright (C) 2025 Arm, Ltd. */ |
| 3 |
#ifndef _ETHOSU_DRM_H_ |
| 4 |
#define _ETHOSU_DRM_H_ |
| 5 |
|
| 6 |
#include "drm.h" |
| 7 |
|
| 8 |
#if defined(__cplusplus) |
| 9 |
extern "C" { |
| 10 |
#endif |
| 11 |
|
| 12 |
/** |
| 13 |
* DOC: IOCTL IDs |
| 14 |
* |
| 15 |
* enum drm_ethosu_ioctl_id - IOCTL IDs |
| 16 |
* |
| 17 |
* Place new ioctls at the end, don't re-order, don't replace or remove entries. |
| 18 |
* |
| 19 |
* These IDs are not meant to be used directly. Use the DRM_IOCTL_ETHOSU_xxx |
| 20 |
* definitions instead. |
| 21 |
*/ |
| 22 |
enum drm_ethosu_ioctl_id { |
| 23 |
/** @DRM_ETHOSU_DEV_QUERY: Query device information. */ |
| 24 |
DRM_ETHOSU_DEV_QUERY = 0, |
| 25 |
|
| 26 |
/** @DRM_ETHOSU_BO_CREATE: Create a buffer object. */ |
| 27 |
DRM_ETHOSU_BO_CREATE, |
| 28 |
|
| 29 |
/** @DRM_ETHOSU_BO_WAIT: Wait on a buffer object's fence. */ |
| 30 |
DRM_ETHOSU_BO_WAIT, |
| 31 |
|
| 32 |
/** |
| 33 |
* @DRM_ETHOSU_BO_MMAP_OFFSET: Get the file offset to pass to |
| 34 |
* mmap to map a GEM object. |
| 35 |
*/ |
| 36 |
DRM_ETHOSU_BO_MMAP_OFFSET, |
| 37 |
|
| 38 |
/** |
| 39 |
* @DRM_ETHOSU_CMDSTREAM_BO_CREATE: Create a command stream buffer |
| 40 |
* object. |
| 41 |
*/ |
| 42 |
DRM_ETHOSU_CMDSTREAM_BO_CREATE, |
| 43 |
|
| 44 |
/** @DRM_ETHOSU_SUBMIT: Submit a job and BOs to run. */ |
| 45 |
DRM_ETHOSU_SUBMIT, |
| 46 |
}; |
| 47 |
|
| 48 |
/** |
| 49 |
* DOC: IOCTL arguments |
| 50 |
*/ |
| 51 |
|
| 52 |
/** |
| 53 |
* enum drm_ethosu_dev_query_type - Query type |
| 54 |
* |
| 55 |
* Place new types at the end, don't re-order, don't remove or replace. |
| 56 |
*/ |
| 57 |
enum drm_ethosu_dev_query_type { |
| 58 |
/** @DRM_ETHOSU_DEV_QUERY_NPU_INFO: Query NPU information. */ |
| 59 |
DRM_ETHOSU_DEV_QUERY_NPU_INFO = 0, |
| 60 |
}; |
| 61 |
|
| 62 |
/** |
| 63 |
* struct drm_ethosu_gpu_info - NPU information |
| 64 |
* |
| 65 |
* Structure grouping all queryable information relating to the NPU. |
| 66 |
*/ |
| 67 |
struct drm_ethosu_npu_info { |
| 68 |
/** @id : NPU ID. */ |
| 69 |
__u32 id; |
| 70 |
#define DRM_ETHOSU_ARCH_MAJOR(x) ((x) >> 28) |
| 71 |
#define DRM_ETHOSU_ARCH_MINOR(x) (((x) >> 20) & 0xff) |
| 72 |
#define DRM_ETHOSU_ARCH_PATCH(x) (((x) >> 16) & 0xf) |
| 73 |
#define DRM_ETHOSU_PRODUCT_MAJOR(x) (((x) >> 12) & 0xf) |
| 74 |
#define DRM_ETHOSU_VERSION_MAJOR(x) (((x) >> 8) & 0xf) |
| 75 |
#define DRM_ETHOSU_VERSION_MINOR(x) (((x) >> 4) & 0xff) |
| 76 |
#define DRM_ETHOSU_VERSION_STATUS(x) ((x) & 0xf) |
| 77 |
|
| 78 |
/** @gpu_rev: GPU revision. */ |
| 79 |
__u32 config; |
| 80 |
|
| 81 |
__u32 sram_size; |
| 82 |
}; |
| 83 |
/** |
| 84 |
* struct drm_ethosu_dev_query - Arguments passed to DRM_ETHOSU_IOCTL_DEV_QUERY |
| 85 |
*/ |
| 86 |
struct drm_ethosu_dev_query { |
| 87 |
/** @type: the query type (see drm_ethosu_dev_query_type). */ |
| 88 |
__u32 type; |
| 89 |
|
| 90 |
/** |
| 91 |
* @size: size of the type being queried. |
| 92 |
* |
| 93 |
* If pointer is NULL, size is updated by the driver to provide the |
| 94 |
* output structure size. If pointer is not NULL, the driver will |
| 95 |
* only copy min(size, actual_structure_size) bytes to the pointer, |
| 96 |
* and update the size accordingly. This allows us to extend query |
| 97 |
* types without breaking userspace. |
| 98 |
*/ |
| 99 |
__u32 size; |
| 100 |
|
| 101 |
/** |
| 102 |
* @pointer: user pointer to a query type struct. |
| 103 |
* |
| 104 |
* Pointer can be NULL, in which case, nothing is copied, but the |
| 105 |
* actual structure size is returned. If not NULL, it must point to |
| 106 |
* a location that's large enough to hold size bytes. |
| 107 |
*/ |
| 108 |
__u64 pointer; |
| 109 |
}; |
| 110 |
|
| 111 |
/** |
| 112 |
* enum drm_ethosu_bo_flags - Buffer object flags, passed at creation time. |
| 113 |
*/ |
| 114 |
enum drm_ethosu_bo_flags { |
| 115 |
/** |
| 116 |
* @DRM_ETHOSU_BO_NO_MMAP: The buffer object will never be CPU-mapped |
| 117 |
* in userspace. |
| 118 |
*/ |
| 119 |
DRM_ETHOSU_BO_NO_MMAP = (1 << 0), |
| 120 |
}; |
| 121 |
|
| 122 |
/** |
| 123 |
* struct drm_ethosu_bo_create - Arguments passed to DRM_IOCTL_ETHOSU_BO_CREATE. |
| 124 |
*/ |
| 125 |
struct drm_ethosu_bo_create { |
| 126 |
/** |
| 127 |
* @size: Requested size for the object |
| 128 |
* |
| 129 |
* The (page-aligned) allocated size for the object will be returned. |
| 130 |
*/ |
| 131 |
__u64 size; |
| 132 |
|
| 133 |
/** |
| 134 |
* @flags: Flags. Must be a combination of drm_ethosu_bo_flags flags. |
| 135 |
*/ |
| 136 |
__u32 flags; |
| 137 |
|
| 138 |
/** |
| 139 |
* @handle: Returned handle for the object. |
| 140 |
* |
| 141 |
* Object handles are nonzero. |
| 142 |
*/ |
| 143 |
__u32 handle; |
| 144 |
}; |
| 145 |
|
| 146 |
/** |
| 147 |
* struct drm_ethosu_bo_mmap_offset - Arguments passed to DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET. |
| 148 |
*/ |
| 149 |
struct drm_ethosu_bo_mmap_offset { |
| 150 |
/** @handle: Handle of the object we want an mmap offset for. */ |
| 151 |
__u32 handle; |
| 152 |
|
| 153 |
/** @pad: MBZ. */ |
| 154 |
__u32 pad; |
| 155 |
|
| 156 |
/** @offset: The fake offset to use for subsequent mmap calls. */ |
| 157 |
__u64 offset; |
| 158 |
}; |
| 159 |
|
| 160 |
/** |
| 161 |
* struct drm_ethosu_wait_bo - ioctl argument for waiting for |
| 162 |
* completion of the last DRM_ETHOSU_SUBMIT on a BO. |
| 163 |
* |
| 164 |
* This is useful for cases where multiple processes might be |
| 165 |
* rendering to a BO and you want to wait for all rendering to be |
| 166 |
* completed. |
| 167 |
*/ |
| 168 |
struct drm_ethosu_bo_wait { |
| 169 |
__u32 handle; |
| 170 |
__u32 pad; |
| 171 |
__s64 timeout_ns; /* absolute */ |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
struct drm_ethosu_cmdstream_bo_create { |
| 176 |
/* Size of the data argument. */ |
| 177 |
__u32 size; |
| 178 |
|
| 179 |
/* Flags, currently must be 0. */ |
| 180 |
__u32 flags; |
| 181 |
|
| 182 |
/* Pointer to the data. */ |
| 183 |
__u64 data; |
| 184 |
|
| 185 |
/** Returned GEM handle for the BO. */ |
| 186 |
__u32 handle; |
| 187 |
|
| 188 |
/* Pad, must be 0. */ |
| 189 |
__u32 pad; |
| 190 |
}; |
| 191 |
|
| 192 |
/** |
| 193 |
* struct drm_ethosu_job - A job to be run on the NPU |
| 194 |
* |
| 195 |
* The kernel will schedule the execution of this job taking into account its |
| 196 |
* dependencies with other jobs. All tasks in the same job will be executed |
| 197 |
* sequentially on the same core, to benefit from memory residency in SRAM. |
| 198 |
*/ |
| 199 |
struct drm_ethosu_job { |
| 200 |
/** Input: BO handle for cmdstream. */ |
| 201 |
__u32 cmd_bo; |
| 202 |
|
| 203 |
/** Input: Amount of SRAM to use. */ |
| 204 |
__u32 sram_size; |
| 205 |
|
| 206 |
#define ETHOSU_MAX_REGIONS 8 |
| 207 |
/** Input: Array of BO handles for each region. */ |
| 208 |
__u32 region_bo_handles[ETHOSU_MAX_REGIONS]; |
| 209 |
}; |
| 210 |
|
| 211 |
/** |
| 212 |
* struct drm_ethosu_submit - ioctl argument for submitting commands to the NPU. |
| 213 |
* |
| 214 |
* The kernel will schedule the execution of these jobs in dependency order. |
| 215 |
*/ |
| 216 |
struct drm_ethosu_submit { |
| 217 |
/** Input: Pointer to an array of struct drm_ethosu_job. */ |
| 218 |
__u64 jobs; |
| 219 |
|
| 220 |
/** Input: Number of jobs passed in. */ |
| 221 |
__u32 job_count; |
| 222 |
|
| 223 |
/** Reserved, must be zero. */ |
| 224 |
__u32 pad; |
| 225 |
}; |
| 226 |
|
| 227 |
|
| 228 |
/** |
| 229 |
* DRM_IOCTL_ETHOSU() - Build a ethosu IOCTL number |
| 230 |
* @__access: Access type. Must be R, W or RW. |
| 231 |
* @__id: One of the DRM_ETHOSU_xxx id. |
| 232 |
* @__type: Suffix of the type being passed to the IOCTL. |
| 233 |
* |
| 234 |
* Don't use this macro directly, use the DRM_IOCTL_ETHOSU_xxx |
| 235 |
* values instead. |
| 236 |
* |
| 237 |
* Return: An IOCTL number to be passed to ioctl() from userspace. |
| 238 |
*/ |
| 239 |
#define DRM_IOCTL_ETHOSU(__access, __id, __type) \ |
| 240 |
DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ETHOSU_ ## __id, \ |
| 241 |
struct drm_ethosu_ ## __type) |
| 242 |
|
| 243 |
enum { |
| 244 |
DRM_IOCTL_ETHOSU_DEV_QUERY = |
| 245 |
DRM_IOCTL_ETHOSU(WR, DEV_QUERY, dev_query), |
| 246 |
DRM_IOCTL_ETHOSU_BO_CREATE = |
| 247 |
DRM_IOCTL_ETHOSU(WR, BO_CREATE, bo_create), |
| 248 |
DRM_IOCTL_ETHOSU_BO_WAIT = |
| 249 |
DRM_IOCTL_ETHOSU(WR, BO_WAIT, bo_wait), |
| 250 |
DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET = |
| 251 |
DRM_IOCTL_ETHOSU(WR, BO_MMAP_OFFSET, bo_mmap_offset), |
| 252 |
DRM_IOCTL_ETHOSU_CMDSTREAM_BO_CREATE = |
| 253 |
DRM_IOCTL_ETHOSU(WR, CMDSTREAM_BO_CREATE, cmdstream_bo_create), |
| 254 |
DRM_IOCTL_ETHOSU_SUBMIT = |
| 255 |
DRM_IOCTL_ETHOSU(WR, SUBMIT, submit), |
| 256 |
}; |
| 257 |
|
| 258 |
#if defined(__cplusplus) |
| 259 |
} |
| 260 |
#endif |
| 261 |
|
| 262 |
#endif /* _ETHOSU_DRM_H_ */ |