• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2020-2021 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 #ifndef _UAPI_KBASE_CSF_IOCTL_H_
23 #define _UAPI_KBASE_CSF_IOCTL_H_
24 
25 #include <asm-generic/ioctl.h>
26 #include <linux/types.h>
27 
28 /*
29  * 1.0:
30  * - CSF IOCTL header separated from JM
31  * 1.1:
32  * - Add a new priority level BASE_QUEUE_GROUP_PRIORITY_REALTIME
33  * - Add ioctl 54: This controls the priority setting.
34  * 1.2:
35  * - Add new CSF GPU_FEATURES register into the property structure
36  *   returned by KBASE_IOCTL_GET_GPUPROPS
37  * 1.3:
38  * - Add __u32 group_uid member to
39  *   &struct_kbase_ioctl_cs_queue_group_create.out
40  * 1.4:
41  * - Replace padding in kbase_ioctl_cs_get_glb_iface with
42  *   instr_features member of same size
43  * 1.5:
44  * - Add ioctl 40: kbase_ioctl_cs_queue_register_ex, this is a new
45  *   queue registration call with extended format for supporting CS
46  *   trace configurations with CSF trace_command.
47  * 1.6:
48  * - Added new HW performance counters interface to all GPUs.
49  * 1.7:
50  * - Added reserved field to QUEUE_GROUP_CREATE ioctl for future use
51  * 1.8:
52  * - Removed Kernel legacy HWC interface
53  */
54 
55 #define BASE_UK_VERSION_MAJOR 1
56 #define BASE_UK_VERSION_MINOR 8
57 
58 /**
59  * struct kbase_ioctl_version_check - Check version compatibility between
60  * kernel and userspace
61  *
62  * @major: Major version number
63  * @minor: Minor version number
64  */
65 struct kbase_ioctl_version_check {
66 	__u16 major;
67 	__u16 minor;
68 };
69 
70 #define KBASE_IOCTL_VERSION_CHECK_RESERVED \
71 	_IOWR(KBASE_IOCTL_TYPE, 0, struct kbase_ioctl_version_check)
72 
73 
74 /**
75  * struct kbase_ioctl_cs_queue_register - Register a GPU command queue with the
76  *                                        base back-end
77  *
78  * @buffer_gpu_addr: GPU address of the buffer backing the queue
79  * @buffer_size: Size of the buffer in bytes
80  * @priority: Priority of the queue within a group when run within a process
81  * @padding: Currently unused, must be zero
82  *
83  * @Note: There is an identical sub-section in kbase_ioctl_cs_queue_register_ex.
84  *        Any change of this struct should also be mirrored to the latter.
85  */
86 struct kbase_ioctl_cs_queue_register {
87 	__u64 buffer_gpu_addr;
88 	__u32 buffer_size;
89 	__u8 priority;
90 	__u8 padding[3];
91 };
92 
93 #define KBASE_IOCTL_CS_QUEUE_REGISTER \
94 	_IOW(KBASE_IOCTL_TYPE, 36, struct kbase_ioctl_cs_queue_register)
95 
96 /**
97  * struct kbase_ioctl_cs_queue_kick - Kick the GPU command queue group scheduler
98  *                                    to notify that a queue has been updated
99  *
100  * @buffer_gpu_addr: GPU address of the buffer backing the queue
101  */
102 struct kbase_ioctl_cs_queue_kick {
103 	__u64 buffer_gpu_addr;
104 };
105 
106 #define KBASE_IOCTL_CS_QUEUE_KICK \
107 	_IOW(KBASE_IOCTL_TYPE, 37, struct kbase_ioctl_cs_queue_kick)
108 
109 /**
110  * union kbase_ioctl_cs_queue_bind - Bind a GPU command queue to a group
111  *
112  * @in:                 Input parameters
113  * @in.buffer_gpu_addr: GPU address of the buffer backing the queue
114  * @in.group_handle:    Handle of the group to which the queue should be bound
115  * @in.csi_index:       Index of the CSF interface the queue should be bound to
116  * @in.padding:         Currently unused, must be zero
117  * @out:                Output parameters
118  * @out.mmap_handle:    Handle to be used for creating the mapping of CS
119  *                      input/output pages
120  */
121 union kbase_ioctl_cs_queue_bind {
122 	struct {
123 		__u64 buffer_gpu_addr;
124 		__u8 group_handle;
125 		__u8 csi_index;
126 		__u8 padding[6];
127 	} in;
128 	struct {
129 		__u64 mmap_handle;
130 	} out;
131 };
132 
133 #define KBASE_IOCTL_CS_QUEUE_BIND \
134 	_IOWR(KBASE_IOCTL_TYPE, 39, union kbase_ioctl_cs_queue_bind)
135 
136 /**
137  * struct kbase_ioctl_cs_queue_register_ex - Register a GPU command queue with the
138  *                                           base back-end in extended format,
139  *                                           involving trace buffer configuration
140  *
141  * @buffer_gpu_addr: GPU address of the buffer backing the queue
142  * @buffer_size: Size of the buffer in bytes
143  * @priority: Priority of the queue within a group when run within a process
144  * @padding: Currently unused, must be zero
145  * @ex_offset_var_addr: GPU address of the trace buffer write offset variable
146  * @ex_buffer_base: Trace buffer GPU base address for the queue
147  * @ex_buffer_size: Size of the trace buffer in bytes
148  * @ex_event_size: Trace event write size, in log2 designation
149  * @ex_event_state: Trace event states configuration
150  * @ex_padding: Currently unused, must be zero
151  *
152  * @Note: There is an identical sub-section at the start of this struct to that
153  *        of @ref kbase_ioctl_cs_queue_register. Any change of this sub-section
154  *        must also be mirrored to the latter. Following the said sub-section,
155  *        the remaining fields forms the extension, marked with ex_*.
156  */
157 struct kbase_ioctl_cs_queue_register_ex {
158 	__u64 buffer_gpu_addr;
159 	__u32 buffer_size;
160 	__u8 priority;
161 	__u8 padding[3];
162 	__u64 ex_offset_var_addr;
163 	__u64 ex_buffer_base;
164 	__u32 ex_buffer_size;
165 	__u8 ex_event_size;
166 	__u8 ex_event_state;
167 	__u8 ex_padding[2];
168 };
169 
170 #define KBASE_IOCTL_CS_QUEUE_REGISTER_EX \
171 	_IOW(KBASE_IOCTL_TYPE, 40, struct kbase_ioctl_cs_queue_register_ex)
172 
173 /**
174  * struct kbase_ioctl_cs_queue_terminate - Terminate a GPU command queue
175  *
176  * @buffer_gpu_addr: GPU address of the buffer backing the queue
177  */
178 struct kbase_ioctl_cs_queue_terminate {
179 	__u64 buffer_gpu_addr;
180 };
181 
182 #define KBASE_IOCTL_CS_QUEUE_TERMINATE \
183 	_IOW(KBASE_IOCTL_TYPE, 41, struct kbase_ioctl_cs_queue_terminate)
184 
185 /**
186  * union kbase_ioctl_cs_queue_group_create_1_6 - Create a GPU command queue
187  *                                               group
188  * @in:               Input parameters
189  * @in.tiler_mask:    Mask of tiler endpoints the group is allowed to use.
190  * @in.fragment_mask: Mask of fragment endpoints the group is allowed to use.
191  * @in.compute_mask:  Mask of compute endpoints the group is allowed to use.
192  * @in.cs_min:        Minimum number of CSs required.
193  * @in.priority:      Queue group's priority within a process.
194  * @in.tiler_max:     Maximum number of tiler endpoints the group is allowed
195  *                    to use.
196  * @in.fragment_max:  Maximum number of fragment endpoints the group is
197  *                    allowed to use.
198  * @in.compute_max:   Maximum number of compute endpoints the group is allowed
199  *                    to use.
200  * @in.padding:       Currently unused, must be zero
201  * @out:              Output parameters
202  * @out.group_handle: Handle of a newly created queue group.
203  * @out.padding:      Currently unused, must be zero
204  * @out.group_uid:    UID of the queue group available to base.
205  */
206 union kbase_ioctl_cs_queue_group_create_1_6 {
207 	struct {
208 		__u64 tiler_mask;
209 		__u64 fragment_mask;
210 		__u64 compute_mask;
211 		__u8 cs_min;
212 		__u8 priority;
213 		__u8 tiler_max;
214 		__u8 fragment_max;
215 		__u8 compute_max;
216 		__u8 padding[3];
217 
218 	} in;
219 	struct {
220 		__u8 group_handle;
221 		__u8 padding[3];
222 		__u32 group_uid;
223 	} out;
224 };
225 
226 #define KBASE_IOCTL_CS_QUEUE_GROUP_CREATE_1_6                                  \
227 	_IOWR(KBASE_IOCTL_TYPE, 42, union kbase_ioctl_cs_queue_group_create_1_6)
228 
229 /**
230  * union kbase_ioctl_cs_queue_group_create - Create a GPU command queue group
231  * @in:               Input parameters
232  * @in.tiler_mask:    Mask of tiler endpoints the group is allowed to use.
233  * @in.fragment_mask: Mask of fragment endpoints the group is allowed to use.
234  * @in.compute_mask:  Mask of compute endpoints the group is allowed to use.
235  * @in.cs_min:        Minimum number of CSs required.
236  * @in.priority:      Queue group's priority within a process.
237  * @in.tiler_max:     Maximum number of tiler endpoints the group is allowed
238  *                    to use.
239  * @in.fragment_max:  Maximum number of fragment endpoints the group is
240  *                    allowed to use.
241  * @in.compute_max:   Maximum number of compute endpoints the group is allowed
242  *                    to use.
243  * @in.padding:       Currently unused, must be zero
244  * @out:              Output parameters
245  * @out.group_handle: Handle of a newly created queue group.
246  * @out.padding:      Currently unused, must be zero
247  * @out.group_uid:    UID of the queue group available to base.
248  */
249 union kbase_ioctl_cs_queue_group_create {
250 	struct {
251 		__u64 tiler_mask;
252 		__u64 fragment_mask;
253 		__u64 compute_mask;
254 		__u8 cs_min;
255 		__u8 priority;
256 		__u8 tiler_max;
257 		__u8 fragment_max;
258 		__u8 compute_max;
259 		__u8 padding[3];
260 		__u64 reserved;
261 	} in;
262 	struct {
263 		__u8 group_handle;
264 		__u8 padding[3];
265 		__u32 group_uid;
266 	} out;
267 };
268 
269 #define KBASE_IOCTL_CS_QUEUE_GROUP_CREATE                                      \
270 	_IOWR(KBASE_IOCTL_TYPE, 58, union kbase_ioctl_cs_queue_group_create)
271 
272 /**
273  * struct kbase_ioctl_cs_queue_group_term - Terminate a GPU command queue group
274  *
275  * @group_handle: Handle of the queue group to be terminated
276  * @padding: Padding to round up to a multiple of 8 bytes, must be zero
277  */
278 struct kbase_ioctl_cs_queue_group_term {
279 	__u8 group_handle;
280 	__u8 padding[7];
281 };
282 
283 #define KBASE_IOCTL_CS_QUEUE_GROUP_TERMINATE \
284 	_IOW(KBASE_IOCTL_TYPE, 43, struct kbase_ioctl_cs_queue_group_term)
285 
286 #define KBASE_IOCTL_CS_EVENT_SIGNAL \
287 	_IO(KBASE_IOCTL_TYPE, 44)
288 
289 typedef __u8 base_kcpu_queue_id; /* We support up to 256 active KCPU queues */
290 
291 /**
292  * struct kbase_ioctl_kcpu_queue_new - Create a KCPU command queue
293  *
294  * @id: ID of the new command queue returned by the kernel
295  * @padding: Padding to round up to a multiple of 8 bytes, must be zero
296  */
297 struct kbase_ioctl_kcpu_queue_new {
298 	base_kcpu_queue_id id;
299 	__u8 padding[7];
300 };
301 
302 #define KBASE_IOCTL_KCPU_QUEUE_CREATE \
303 	_IOR(KBASE_IOCTL_TYPE, 45, struct kbase_ioctl_kcpu_queue_new)
304 
305 /**
306  * struct kbase_ioctl_kcpu_queue_delete - Destroy a KCPU command queue
307  *
308  * @id: ID of the command queue to be destroyed
309  * @padding: Padding to round up to a multiple of 8 bytes, must be zero
310  */
311 struct kbase_ioctl_kcpu_queue_delete {
312 	base_kcpu_queue_id id;
313 	__u8 padding[7];
314 };
315 
316 #define KBASE_IOCTL_KCPU_QUEUE_DELETE \
317 	_IOW(KBASE_IOCTL_TYPE, 46, struct kbase_ioctl_kcpu_queue_delete)
318 
319 /**
320  * struct kbase_ioctl_kcpu_queue_enqueue - Enqueue commands into the KCPU queue
321  *
322  * @addr: Memory address of an array of struct base_kcpu_queue_command
323  * @nr_commands: Number of commands in the array
324  * @id: kcpu queue identifier, returned by KBASE_IOCTL_KCPU_QUEUE_CREATE ioctl
325  * @padding: Padding to round up to a multiple of 8 bytes, must be zero
326  */
327 struct kbase_ioctl_kcpu_queue_enqueue {
328 	__u64 addr;
329 	__u32 nr_commands;
330 	base_kcpu_queue_id id;
331 	__u8 padding[3];
332 };
333 
334 #define KBASE_IOCTL_KCPU_QUEUE_ENQUEUE \
335 	_IOW(KBASE_IOCTL_TYPE, 47, struct kbase_ioctl_kcpu_queue_enqueue)
336 
337 /**
338  * union kbase_ioctl_cs_tiler_heap_init - Initialize chunked tiler memory heap
339  * @in:                Input parameters
340  * @in.chunk_size:     Size of each chunk.
341  * @in.initial_chunks: Initial number of chunks that heap will be created with.
342  * @in.max_chunks:     Maximum number of chunks that the heap is allowed to use.
343  * @in.target_in_flight: Number of render-passes that the driver should attempt to
344  *                     keep in flight for which allocation of new chunks is
345  *                     allowed.
346  * @in.group_id:       Group ID to be used for physical allocations.
347  * @in.padding:        Padding
348  * @out:               Output parameters
349  * @out.gpu_heap_va:   GPU VA (virtual address) of Heap context that was set up
350  *                     for the heap.
351  * @out.first_chunk_va: GPU VA of the first chunk allocated for the heap,
352  *                     actually points to the header of heap chunk and not to
353  *                     the low address of free memory in the chunk.
354  */
355 union kbase_ioctl_cs_tiler_heap_init {
356 	struct {
357 		__u32 chunk_size;
358 		__u32 initial_chunks;
359 		__u32 max_chunks;
360 		__u16 target_in_flight;
361 		__u8 group_id;
362 		__u8 padding;
363 	} in;
364 	struct {
365 		__u64 gpu_heap_va;
366 		__u64 first_chunk_va;
367 	} out;
368 };
369 
370 #define KBASE_IOCTL_CS_TILER_HEAP_INIT \
371 	_IOWR(KBASE_IOCTL_TYPE, 48, union kbase_ioctl_cs_tiler_heap_init)
372 
373 /**
374  * struct kbase_ioctl_cs_tiler_heap_term - Terminate a chunked tiler heap
375  *                                         instance
376  *
377  * @gpu_heap_va: GPU VA of Heap context that was set up for the heap.
378  */
379 struct kbase_ioctl_cs_tiler_heap_term {
380 	__u64 gpu_heap_va;
381 };
382 
383 #define KBASE_IOCTL_CS_TILER_HEAP_TERM \
384 	_IOW(KBASE_IOCTL_TYPE, 49, struct kbase_ioctl_cs_tiler_heap_term)
385 
386 /**
387  * union kbase_ioctl_cs_get_glb_iface - Request the global control block
388  *                                        of CSF interface capabilities
389  *
390  * @in:                    Input parameters
391  * @in.max_group_num:      The maximum number of groups to be read. Can be 0, in
392  *                         which case groups_ptr is unused.
393  * @in.max_total_stream    _num: The maximum number of CSs to be read. Can be 0, in
394  *                         which case streams_ptr is unused.
395  * @in.groups_ptr:         Pointer where to store all the group data (sequentially).
396  * @in.streams_ptr:        Pointer where to store all the CS data (sequentially).
397  * @out:                   Output parameters
398  * @out.glb_version:       Global interface version.
399  * @out.features:          Bit mask of features (e.g. whether certain types of job
400  *                         can be suspended).
401  * @out.group_num:         Number of CSGs supported.
402  * @out.prfcnt_size:       Size of CSF performance counters, in bytes. Bits 31:16
403  *                         hold the size of firmware performance counter data
404  *                         and 15:0 hold the size of hardware performance counter
405  *                         data.
406  * @out.total_stream_num:  Total number of CSs, summed across all groups.
407  * @out.instr_features:    Instrumentation features. Bits 7:4 hold the maximum
408  *                         size of events. Bits 3:0 hold the offset update rate.
409  *                         (csf >= 1.1.0)
410  *
411  */
412 union kbase_ioctl_cs_get_glb_iface {
413 	struct {
414 		__u32 max_group_num;
415 		__u32 max_total_stream_num;
416 		__u64 groups_ptr;
417 		__u64 streams_ptr;
418 	} in;
419 	struct {
420 		__u32 glb_version;
421 		__u32 features;
422 		__u32 group_num;
423 		__u32 prfcnt_size;
424 		__u32 total_stream_num;
425 		__u32 instr_features;
426 	} out;
427 };
428 
429 #define KBASE_IOCTL_CS_GET_GLB_IFACE \
430 	_IOWR(KBASE_IOCTL_TYPE, 51, union kbase_ioctl_cs_get_glb_iface)
431 
432 struct kbase_ioctl_cs_cpu_queue_info {
433 	__u64 buffer;
434 	__u64 size;
435 };
436 
437 #define KBASE_IOCTL_VERSION_CHECK \
438 	_IOWR(KBASE_IOCTL_TYPE, 52, struct kbase_ioctl_version_check)
439 
440 #define KBASE_IOCTL_CS_CPU_QUEUE_DUMP \
441 	_IOW(KBASE_IOCTL_TYPE, 53, struct kbase_ioctl_cs_cpu_queue_info)
442 
443 /***************
444  * test ioctls *
445  ***************/
446 #if MALI_UNIT_TEST
447 /* These ioctls are purely for test purposes and are not used in the production
448  * driver, they therefore may change without notice
449  */
450 
451 /**
452  * struct kbase_ioctl_cs_event_memory_write - Write an event memory address
453  * @cpu_addr: Memory address to write
454  * @value: Value to write
455  * @padding: Currently unused, must be zero
456  */
457 struct kbase_ioctl_cs_event_memory_write {
458 	__u64 cpu_addr;
459 	__u8 value;
460 	__u8 padding[7];
461 };
462 
463 /**
464  * union kbase_ioctl_cs_event_memory_read - Read an event memory address
465  * @in: Input parameters
466  * @in.cpu_addr: Memory address to read
467  * @out: Output parameters
468  * @out.value: Value read
469  * @out.padding: Currently unused, must be zero
470  */
471 union kbase_ioctl_cs_event_memory_read {
472 	struct {
473 		__u64 cpu_addr;
474 	} in;
475 	struct {
476 		__u8 value;
477 		__u8 padding[7];
478 	} out;
479 };
480 
481 #endif /* MALI_UNIT_TEST */
482 
483 #endif /* _UAPI_KBASE_CSF_IOCTL_H_ */
484