projects/linux·blob master · refs

319 lines · 8.0 KiB

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)
9extern "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 */
22enum 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 DRM_ETHOSU_PERFMON_CREATE,
48 DRM_ETHOSU_PERFMON_DESTROY,
49 DRM_ETHOSU_PERFMON_GET_VALUES,
50 DRM_ETHOSU_PERFMON_SET_GLOBAL,
51};
52
53/**
54 * DOC: IOCTL arguments
55 */
56
57/**
58 * enum drm_ethosu_dev_query_type - Query type
59 *
60 * Place new types at the end, don't re-order, don't remove or replace.
61 */
62enum drm_ethosu_dev_query_type {
63 /** @DRM_ETHOSU_DEV_QUERY_NPU_INFO: Query NPU information. */
64 DRM_ETHOSU_DEV_QUERY_NPU_INFO = 0,
65};
66
67/**
68 * struct drm_ethosu_gpu_info - NPU information
69 *
70 * Structure grouping all queryable information relating to the NPU.
71 */
72struct drm_ethosu_npu_info {
73 /** @id : NPU ID. */
74 __u32 id;
75#define DRM_ETHOSU_ARCH_MAJOR(x) ((x) >> 28)
76#define DRM_ETHOSU_ARCH_MINOR(x) (((x) >> 20) & 0xff)
77#define DRM_ETHOSU_ARCH_PATCH(x) (((x) >> 16) & 0xf)
78#define DRM_ETHOSU_PRODUCT_MAJOR(x) (((x) >> 12) & 0xf)
79#define DRM_ETHOSU_VERSION_MAJOR(x) (((x) >> 8) & 0xf)
80#define DRM_ETHOSU_VERSION_MINOR(x) (((x) >> 4) & 0xff)
81#define DRM_ETHOSU_VERSION_STATUS(x) ((x) & 0xf)
82
83 /** @gpu_rev: GPU revision. */
84 __u32 config;
85
86 __u32 sram_size;
87 __u32 pmu_counters;
88};
89
90/**
91 * struct drm_ethosu_dev_query - Arguments passed to DRM_ETHOSU_IOCTL_DEV_QUERY
92 */
93struct drm_ethosu_dev_query {
94 /** @type: the query type (see drm_ethosu_dev_query_type). */
95 __u32 type;
96
97 /**
98 * @size: size of the type being queried.
99 *
100 * If pointer is NULL, size is updated by the driver to provide the
101 * output structure size. If pointer is not NULL, the driver will
102 * only copy min(size, actual_structure_size) bytes to the pointer,
103 * and update the size accordingly. This allows us to extend query
104 * types without breaking userspace.
105 */
106 __u32 size;
107
108 /**
109 * @pointer: user pointer to a query type struct.
110 *
111 * Pointer can be NULL, in which case, nothing is copied, but the
112 * actual structure size is returned. If not NULL, it must point to
113 * a location that's large enough to hold size bytes.
114 */
115 __u64 pointer;
116};
117
118/**
119 * enum drm_ethosu_bo_flags - Buffer object flags, passed at creation time.
120 */
121enum drm_ethosu_bo_flags {
122 /**
123 * @DRM_ETHOSU_BO_NO_MMAP: The buffer object will never be CPU-mapped
124 * in userspace.
125 */
126 DRM_ETHOSU_BO_NO_MMAP = (1 << 0),
127};
128
129/**
130 * struct drm_ethosu_bo_create - Arguments passed to DRM_IOCTL_ETHOSU_BO_CREATE.
131 */
132struct drm_ethosu_bo_create {
133 /**
134 * @size: Requested size for the object
135 *
136 * The (page-aligned) allocated size for the object will be returned.
137 */
138 __u64 size;
139
140 /**
141 * @flags: Flags. Must be a combination of drm_ethosu_bo_flags flags.
142 */
143 __u32 flags;
144
145 /**
146 * @handle: Returned handle for the object.
147 *
148 * Object handles are nonzero.
149 */
150 __u32 handle;
151};
152
153/**
154 * struct drm_ethosu_bo_mmap_offset - Arguments passed to DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET.
155 */
156struct drm_ethosu_bo_mmap_offset {
157 /** @handle: Handle of the object we want an mmap offset for. */
158 __u32 handle;
159
160 /** @pad: MBZ. */
161 __u32 pad;
162
163 /** @offset: The fake offset to use for subsequent mmap calls. */
164 __u64 offset;
165};
166
167/**
168 * struct drm_ethosu_wait_bo - ioctl argument for waiting for
169 * completion of the last DRM_ETHOSU_SUBMIT on a BO.
170 *
171 * This is useful for cases where multiple processes might be
172 * rendering to a BO and you want to wait for all rendering to be
173 * completed.
174 */
175struct drm_ethosu_bo_wait {
176 __u32 handle;
177 __u32 pad;
178 __s64 timeout_ns; /* absolute */
179};
180
181struct drm_ethosu_cmdstream_bo_create {
182 /* Size of the data argument. */
183 __u32 size;
184
185 /* Flags, currently must be 0. */
186 __u32 flags;
187
188 /* Pointer to the data. */
189 __u64 data;
190
191 /** Returned GEM handle for the BO. */
192 __u32 handle;
193
194 /* Pad, must be 0. */
195 __u32 pad;
196};
197
198/**
199 * struct drm_ethosu_job - A job to be run on the NPU
200 *
201 * The kernel will schedule the execution of this job taking into account its
202 * dependencies with other jobs. All tasks in the same job will be executed
203 * sequentially on the same core, to benefit from memory residency in SRAM.
204 */
205struct drm_ethosu_job {
206 /** Input: BO handle for cmdstream. */
207 __u32 cmd_bo;
208
209 /** Input: Amount of SRAM to use. */
210 __u32 sram_size;
211
212#define ETHOSU_MAX_REGIONS 8
213 /** Input: Array of BO handles for each region. */
214 __u32 region_bo_handles[ETHOSU_MAX_REGIONS];
215};
216
217/**
218 * struct drm_ethosu_submit - ioctl argument for submitting commands to the NPU.
219 *
220 * The kernel will schedule the execution of these jobs in dependency order.
221 */
222struct drm_ethosu_submit {
223 /** Input: Pointer to an array of struct drm_ethosu_job. */
224 __u64 jobs;
225
226 /** Input: Number of jobs passed in. */
227 __u32 job_count;
228
229 /** Input: Id returned by DRM_ETHOSU_PERFMON_CREATE */
230 __u32 perfmon_id;
231};
232
233#define DRM_ETHOSU_MAX_PERF_EVENT_COUNTERS 8
234#define DRM_ETHOSU_MAX_PERF_COUNTERS \
235 (DRM_ETHOSU_MAX_PERF_EVENT_COUNTERS + 1)
236
237struct drm_ethosu_perfmon_create {
238 __u32 id;
239 __u32 ncounters;
240 __u16 counters[DRM_ETHOSU_MAX_PERF_EVENT_COUNTERS];
241};
242
243struct drm_ethosu_perfmon_destroy {
244 __u32 id;
245 __u32 pad;
246};
247
248/*
249 * Returns the values of the performance counters tracked by this
250 * perfmon (as an array of (ncounters + 1) u64 values).
251 *
252 * No implicit synchronization is performed, so the user has to
253 * guarantee that any jobs using this perfmon have already been
254 * completed.
255 */
256struct drm_ethosu_perfmon_get_values {
257 __u32 id;
258 __u32 pad;
259 __u64 values_ptr;
260};
261
262#define DRM_ETHOSU_PERFMON_CLEAR_GLOBAL 0x0001
263
264/**
265 * struct drm_ethosu_perfmon_set_global - ioctl to define a global performance
266 * monitor
267 *
268 * The global performance monitor will be used for all jobs. If a global
269 * performance monitor is defined, jobs with a self-defined performance
270 * monitor won't be allowed.
271 */
272struct drm_ethosu_perfmon_set_global {
273 __u32 flags;
274 __u32 id;
275};
276
277/**
278 * DRM_IOCTL_ETHOSU() - Build a ethosu IOCTL number
279 * @__access: Access type. Must be R, W or RW.
280 * @__id: One of the DRM_ETHOSU_xxx id.
281 * @__type: Suffix of the type being passed to the IOCTL.
282 *
283 * Don't use this macro directly, use the DRM_IOCTL_ETHOSU_xxx
284 * values instead.
285 *
286 * Return: An IOCTL number to be passed to ioctl() from userspace.
287 */
288#define DRM_IOCTL_ETHOSU(__access, __id, __type) \
289 DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ETHOSU_ ## __id, \
290 struct drm_ethosu_ ## __type)
291
292enum {
293 DRM_IOCTL_ETHOSU_DEV_QUERY =
294 DRM_IOCTL_ETHOSU(WR, DEV_QUERY, dev_query),
295 DRM_IOCTL_ETHOSU_BO_CREATE =
296 DRM_IOCTL_ETHOSU(WR, BO_CREATE, bo_create),
297 DRM_IOCTL_ETHOSU_BO_WAIT =
298 DRM_IOCTL_ETHOSU(WR, BO_WAIT, bo_wait),
299 DRM_IOCTL_ETHOSU_BO_MMAP_OFFSET =
300 DRM_IOCTL_ETHOSU(WR, BO_MMAP_OFFSET, bo_mmap_offset),
301 DRM_IOCTL_ETHOSU_CMDSTREAM_BO_CREATE =
302 DRM_IOCTL_ETHOSU(WR, CMDSTREAM_BO_CREATE, cmdstream_bo_create),
303 DRM_IOCTL_ETHOSU_SUBMIT =
304 DRM_IOCTL_ETHOSU(WR, SUBMIT, submit),
305 DRM_IOCTL_ETHOSU_PERFMON_CREATE =
306 DRM_IOCTL_ETHOSU(WR, PERFMON_CREATE, perfmon_create),
307 DRM_IOCTL_ETHOSU_PERFMON_DESTROY =
308 DRM_IOCTL_ETHOSU(WR, PERFMON_DESTROY, perfmon_destroy),
309 DRM_IOCTL_ETHOSU_PERFMON_GET_VALUES =
310 DRM_IOCTL_ETHOSU(WR, PERFMON_GET_VALUES, perfmon_get_values),
311 DRM_IOCTL_ETHOSU_PERFMON_SET_GLOBAL =
312 DRM_IOCTL_ETHOSU(WR, PERFMON_SET_GLOBAL, perfmon_set_global),
313};
314
315#if defined(__cplusplus)
316}
317#endif
318
319#endif /* _ETHOSU_DRM_H_ */