xref: /linux/include/uapi/drm/ethosu_accel.h (revision f6e8dc9edf963dbc99085e54f6ced6da9daa6100)
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 /**
85  * struct drm_ethosu_dev_query - Arguments passed to DRM_ETHOSU_IOCTL_DEV_QUERY
86  */
87 struct drm_ethosu_dev_query {
88 	/** @type: the query type (see drm_ethosu_dev_query_type). */
89 	__u32 type;
90 
91 	/**
92 	 * @size: size of the type being queried.
93 	 *
94 	 * If pointer is NULL, size is updated by the driver to provide the
95 	 * output structure size. If pointer is not NULL, the driver will
96 	 * only copy min(size, actual_structure_size) bytes to the pointer,
97 	 * and update the size accordingly. This allows us to extend query
98 	 * types without breaking userspace.
99 	 */
100 	__u32 size;
101 
102 	/**
103 	 * @pointer: user pointer to a query type struct.
104 	 *
105 	 * Pointer can be NULL, in which case, nothing is copied, but the
106 	 * actual structure size is returned. If not NULL, it must point to
107 	 * a location that's large enough to hold size bytes.
108 	 */
109 	__u64 pointer;
110 };
111 
112 /**
113  * enum drm_ethosu_bo_flags - Buffer object flags, passed at creation time.
114  */
115 enum drm_ethosu_bo_flags {
116 	/**
117 	 * @DRM_ETHOSU_BO_NO_MMAP: The buffer object will never be CPU-mapped
118 	 * in userspace.
119 	 */
120 	DRM_ETHOSU_BO_NO_MMAP = (1 << 0),
121 };
122 
123 /**
124  * struct drm_ethosu_bo_create - Arguments passed to DRM_IOCTL_ETHOSU_BO_CREATE.
125  */
126 struct drm_ethosu_bo_create {
127 	/**
128 	 * @size: Requested size for the object
129 	 *
130 	 * The (page-aligned) allocated size for the object will be returned.
131 	 */
132 	__u64 size;
133 
134 	/**
135 	 * @flags: Flags. Must be a combination of drm_ethosu_bo_flags flags.
136 	 */
137 	__u32 flags;
138 
139 	/**
140 	 * @handle: Returned handle for the object.
141 	 *
142 	 * Object handles are nonzero.
143 	 */
144 	__u32 handle;
145 };
146 
147 /**
148  * struct drm_ethosu_bo_mmap_offset - Arguments passed to DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET.
149  */
150 struct drm_ethosu_bo_mmap_offset {
151 	/** @handle: Handle of the object we want an mmap offset for. */
152 	__u32 handle;
153 
154 	/** @pad: MBZ. */
155 	__u32 pad;
156 
157 	/** @offset: The fake offset to use for subsequent mmap calls. */
158 	__u64 offset;
159 };
160 
161 /**
162  * struct drm_ethosu_wait_bo - ioctl argument for waiting for
163  * completion of the last DRM_ETHOSU_SUBMIT on a BO.
164  *
165  * This is useful for cases where multiple processes might be
166  * rendering to a BO and you want to wait for all rendering to be
167  * completed.
168  */
169 struct drm_ethosu_bo_wait {
170 	__u32 handle;
171 	__u32 pad;
172 	__s64 timeout_ns;	/* absolute */
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  * DRM_IOCTL_ETHOSU() - Build a ethosu IOCTL number
229  * @__access: Access type. Must be R, W or RW.
230  * @__id: One of the DRM_ETHOSU_xxx id.
231  * @__type: Suffix of the type being passed to the IOCTL.
232  *
233  * Don't use this macro directly, use the DRM_IOCTL_ETHOSU_xxx
234  * values instead.
235  *
236  * Return: An IOCTL number to be passed to ioctl() from userspace.
237  */
238 #define DRM_IOCTL_ETHOSU(__access, __id, __type) \
239 	DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ETHOSU_ ## __id, \
240 			   struct drm_ethosu_ ## __type)
241 
242 enum {
243 	DRM_IOCTL_ETHOSU_DEV_QUERY =
244 		DRM_IOCTL_ETHOSU(WR, DEV_QUERY, dev_query),
245 	DRM_IOCTL_ETHOSU_BO_CREATE =
246 		DRM_IOCTL_ETHOSU(WR, BO_CREATE, bo_create),
247 	DRM_IOCTL_ETHOSU_BO_WAIT =
248 		DRM_IOCTL_ETHOSU(WR, BO_WAIT, bo_wait),
249 	DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET =
250 		DRM_IOCTL_ETHOSU(WR, BO_MMAP_OFFSET, bo_mmap_offset),
251 	DRM_IOCTL_ETHOSU_CMDSTREAM_BO_CREATE =
252 		DRM_IOCTL_ETHOSU(WR, CMDSTREAM_BO_CREATE, cmdstream_bo_create),
253 	DRM_IOCTL_ETHOSU_SUBMIT =
254 		DRM_IOCTL_ETHOSU(WR, SUBMIT, submit),
255 };
256 
257 #if defined(__cplusplus)
258 }
259 #endif
260 
261 #endif /* _ETHOSU_DRM_H_ */
262