1 /*
2  *
3  * (C) COPYRIGHT 2008-2017 ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15 
16 
17 
18 
19 
20 #ifndef _KBASE_UKU_H_
21 #define _KBASE_UKU_H_
22 
23 #include "mali_uk.h"
24 #include "mali_base_kernel.h"
25 
26 /* This file needs to support being included from kernel and userside (which use different defines) */
27 #if defined(CONFIG_MALI_ERROR_INJECT) || MALI_ERROR_INJECT_ON
28 #define SUPPORT_MALI_ERROR_INJECT
29 #endif /* defined(CONFIG_MALI_ERROR_INJECT) || MALI_ERROR_INJECT_ON */
30 #if defined(CONFIG_MALI_NO_MALI)
31 #define SUPPORT_MALI_NO_MALI
32 #elif defined(MALI_NO_MALI)
33 #if MALI_NO_MALI
34 #define SUPPORT_MALI_NO_MALI
35 #endif
36 #endif
37 
38 #if defined(SUPPORT_MALI_NO_MALI) || defined(SUPPORT_MALI_ERROR_INJECT)
39 #include "backend/gpu/mali_kbase_model_dummy.h"
40 #endif
41 
42 #include "mali_kbase_gpuprops_types.h"
43 
44 /*
45  * 10.1:
46  * - Do mmap in kernel for SAME_VA memory allocations rather then
47  *   calling back into the kernel as a 2nd stage of the allocation request.
48  *
49  * 10.2:
50  * - Add KBASE_FUNC_MEM_JIT_INIT which allows clients to request a custom VA
51  *   region for use with JIT (ignored on 32-bit platforms)
52  *
53  * 10.3:
54  * - base_jd_core_req typedef-ed to u32 (instead of to u16)
55  * - two flags added: BASE_JD_REQ_SKIP_CACHE_STAT / _END
56  *
57  * 10.4:
58  * - Removed KBASE_FUNC_EXT_BUFFER_LOCK used only in internal tests
59  *
60  * 10.5:
61  * - Reverted to performing mmap in user space so that tools like valgrind work.
62  *
63  * 10.6:
64  * - Add flags input variable to KBASE_FUNC_TLSTREAM_ACQUIRE
65  */
66 #define BASE_UK_VERSION_MAJOR 10
67 #define BASE_UK_VERSION_MINOR 6
68 
69 #define LINUX_UK_BASE_MAGIC 0x80
70 
71 struct kbase_uk_mem_alloc {
72 	union uk_header header;
73 	/* IN */
74 	u64 va_pages;
75 	u64 commit_pages;
76 	u64 extent;
77 	/* IN/OUT */
78 	u64 flags;
79 	/* OUT */
80 	u64 gpu_va;
81 	u16 va_alignment;
82 	u8  padding[6];
83 };
84 
85 struct kbase_uk_mem_free {
86 	union uk_header header;
87 	/* IN */
88 	u64 gpu_addr;
89 	/* OUT */
90 };
91 
92 struct kbase_uk_mem_alias {
93 	union uk_header header;
94 	/* IN/OUT */
95 	u64 flags;
96 	/* IN */
97 	u64 stride;
98 	u64 nents;
99 	union kbase_pointer ai;
100 	/* OUT */
101 	u64         gpu_va;
102 	u64         va_pages;
103 };
104 
105 struct kbase_uk_mem_import {
106 	union uk_header header;
107 	/* IN */
108 	union kbase_pointer phandle;
109 	u32 type;
110 	u32 padding;
111 	/* IN/OUT */
112 	u64         flags;
113 	/* OUT */
114 	u64 gpu_va;
115 	u64         va_pages;
116 };
117 
118 struct kbase_uk_mem_flags_change {
119 	union uk_header header;
120 	/* IN */
121 	u64 gpu_va;
122 	u64 flags;
123 	u64 mask;
124 };
125 
126 struct kbase_uk_job_submit {
127 	union uk_header header;
128 	/* IN */
129 	union kbase_pointer addr;
130 	u32 nr_atoms;
131 	u32 stride;		/* bytes between atoms, i.e. sizeof(base_jd_atom_v2) */
132 	/* OUT */
133 };
134 
135 struct kbase_uk_post_term {
136 	union uk_header header;
137 };
138 
139 struct kbase_uk_sync_now {
140 	union uk_header header;
141 
142 	/* IN */
143 	struct base_syncset sset;
144 
145 	/* OUT */
146 };
147 
148 struct kbase_uk_hwcnt_setup {
149 	union uk_header header;
150 
151 	/* IN */
152 	u64 dump_buffer;
153 	u32 jm_bm;
154 	u32 shader_bm;
155 	u32 tiler_bm;
156 	u32 unused_1; /* keep for backwards compatibility */
157 	u32 mmu_l2_bm;
158 	u32 padding;
159 	/* OUT */
160 };
161 
162 /**
163  * struct kbase_uk_hwcnt_reader_setup - User/Kernel space data exchange structure
164  * @header:       UK structure header
165  * @buffer_count: requested number of dumping buffers
166  * @jm_bm:        counters selection bitmask (JM)
167  * @shader_bm:    counters selection bitmask (Shader)
168  * @tiler_bm:     counters selection bitmask (Tiler)
169  * @mmu_l2_bm:    counters selection bitmask (MMU_L2)
170  * @fd:           dumping notification file descriptor
171  *
172  * This structure sets up HWC dumper/reader for this context.
173  * Multiple instances can be created for single context.
174  */
175 struct kbase_uk_hwcnt_reader_setup {
176 	union uk_header header;
177 
178 	/* IN */
179 	u32 buffer_count;
180 	u32 jm_bm;
181 	u32 shader_bm;
182 	u32 tiler_bm;
183 	u32 mmu_l2_bm;
184 
185 	/* OUT */
186 	s32 fd;
187 };
188 
189 struct kbase_uk_hwcnt_dump {
190 	union uk_header header;
191 };
192 
193 struct kbase_uk_hwcnt_clear {
194 	union uk_header header;
195 };
196 
197 struct kbase_uk_fence_validate {
198 	union uk_header header;
199 	/* IN */
200 	s32 fd;
201 	u32 padding;
202 	/* OUT */
203 };
204 
205 struct kbase_uk_stream_create {
206 	union uk_header header;
207 	/* IN */
208 	char name[32];
209 	/* OUT */
210 	s32 fd;
211 	u32 padding;
212 };
213 
214 struct kbase_uk_gpuprops {
215 	union uk_header header;
216 
217 	/* IN */
218 	struct mali_base_gpu_props props;
219 	/* OUT */
220 };
221 
222 struct kbase_uk_mem_query {
223 	union uk_header header;
224 	/* IN */
225 	u64 gpu_addr;
226 #define KBASE_MEM_QUERY_COMMIT_SIZE  1
227 #define KBASE_MEM_QUERY_VA_SIZE      2
228 #define KBASE_MEM_QUERY_FLAGS        3
229 	u64         query;
230 	/* OUT */
231 	u64         value;
232 };
233 
234 struct kbase_uk_mem_commit {
235 	union uk_header header;
236 	/* IN */
237 	u64 gpu_addr;
238 	u64         pages;
239 	/* OUT */
240 	u32 result_subcode;
241 	u32 padding;
242 };
243 
244 struct kbase_uk_find_cpu_offset {
245 	union uk_header header;
246 	/* IN */
247 	u64 gpu_addr;
248 	u64 cpu_addr;
249 	u64 size;
250 	/* OUT */
251 	u64 offset;
252 };
253 
254 #define KBASE_GET_VERSION_BUFFER_SIZE 64
255 struct kbase_uk_get_ddk_version {
256 	union uk_header header;
257 	/* OUT */
258 	char version_buffer[KBASE_GET_VERSION_BUFFER_SIZE];
259 	u32 version_string_size;
260 	u32 padding;
261 	u32 rk_version;
262 };
263 
264 struct kbase_uk_disjoint_query {
265 	union uk_header header;
266 	/* OUT */
267 	u32 counter;
268 	u32 padding;
269 };
270 
271 struct kbase_uk_set_flags {
272 	union uk_header header;
273 	/* IN */
274 	u32 create_flags;
275 	u32 padding;
276 };
277 
278 #if MALI_UNIT_TEST
279 #define TEST_ADDR_COUNT 4
280 #define KBASE_TEST_BUFFER_SIZE 128
281 struct kbase_exported_test_data {
282 	u64 test_addr[TEST_ADDR_COUNT];		/**< memory address */
283 	u32 test_addr_pages[TEST_ADDR_COUNT];		/**<  memory size in pages */
284 	union kbase_pointer kctx;				/**<  base context created by process */
285 	union kbase_pointer mm;				/**< pointer to process address space */
286 	u8 buffer1[KBASE_TEST_BUFFER_SIZE];   /**<  unit test defined parameter */
287 	u8 buffer2[KBASE_TEST_BUFFER_SIZE];   /**<  unit test defined parameter */
288 };
289 
290 struct kbase_uk_set_test_data {
291 	union uk_header header;
292 	/* IN */
293 	struct kbase_exported_test_data test_data;
294 };
295 
296 #endif				/* MALI_UNIT_TEST */
297 
298 #ifdef SUPPORT_MALI_ERROR_INJECT
299 struct kbase_uk_error_params {
300 	union uk_header header;
301 	/* IN */
302 	struct kbase_error_params params;
303 };
304 #endif				/* SUPPORT_MALI_ERROR_INJECT */
305 
306 #ifdef SUPPORT_MALI_NO_MALI
307 struct kbase_uk_model_control_params {
308 	union uk_header header;
309 	/* IN */
310 	struct kbase_model_control_params params;
311 };
312 #endif				/* SUPPORT_MALI_NO_MALI */
313 
314 #ifdef BASE_LEGACY_UK8_SUPPORT
315 struct kbase_uk_keep_gpu_powered {
316 	union uk_header header;
317 	u32       enabled;
318 	u32       padding;
319 };
320 #endif /* BASE_LEGACY_UK8_SUPPORT */
321 
322 struct kbase_uk_profiling_controls {
323 	union uk_header header;
324 	u32 profiling_controls[FBDUMP_CONTROL_MAX];
325 };
326 
327 struct kbase_uk_debugfs_mem_profile_add {
328 	union uk_header header;
329 	u32 len;
330 	u32 padding;
331 	union kbase_pointer buf;
332 };
333 
334 struct kbase_uk_context_id {
335 	union uk_header header;
336 	/* OUT */
337 	int id;
338 };
339 
340 /**
341  * struct kbase_uk_tlstream_acquire - User/Kernel space data exchange structure
342  * @header: UK structure header
343  * @flags:  timeline stream flags
344  * @fd:     timeline stream file descriptor
345  *
346  * This structure is used when performing a call to acquire kernel side timeline
347  * stream file descriptor.
348  */
349 struct kbase_uk_tlstream_acquire {
350 	union uk_header header;
351 	/* IN */
352 	u32 flags;
353 	/* OUT */
354 	s32  fd;
355 };
356 
357 /**
358  * struct kbase_uk_tlstream_acquire_v10_4 - User/Kernel space data exchange
359  *                                          structure
360  * @header: UK structure header
361  * @fd:     timeline stream file descriptor
362  *
363  * This structure is used when performing a call to acquire kernel side timeline
364  * stream file descriptor.
365  */
366 struct kbase_uk_tlstream_acquire_v10_4 {
367 	union uk_header header;
368 	/* IN */
369 	/* OUT */
370 	s32  fd;
371 };
372 
373 /**
374  * struct kbase_uk_tlstream_flush - User/Kernel space data exchange structure
375  * @header: UK structure header
376  *
377  * This structure is used when performing a call to flush kernel side
378  * timeline streams.
379  */
380 struct kbase_uk_tlstream_flush {
381 	union uk_header header;
382 	/* IN */
383 	/* OUT */
384 };
385 
386 #if MALI_UNIT_TEST
387 /**
388  * struct kbase_uk_tlstream_test - User/Kernel space data exchange structure
389  * @header:    UK structure header
390  * @tpw_count: number of trace point writers in each context
391  * @msg_delay: time delay between tracepoints from one writer in milliseconds
392  * @msg_count: number of trace points written by one writer
393  * @aux_msg:   if non-zero aux messages will be included
394  *
395  * This structure is used when performing a call to start timeline stream test
396  * embedded in kernel.
397  */
398 struct kbase_uk_tlstream_test {
399 	union uk_header header;
400 	/* IN */
401 	u32 tpw_count;
402 	u32 msg_delay;
403 	u32 msg_count;
404 	u32 aux_msg;
405 	/* OUT */
406 };
407 
408 /**
409  * struct kbase_uk_tlstream_stats - User/Kernel space data exchange structure
410  * @header:          UK structure header
411  * @bytes_collected: number of bytes read by user
412  * @bytes_generated: number of bytes generated by tracepoints
413  *
414  * This structure is used when performing a call to obtain timeline stream
415  * statistics.
416  */
417 struct kbase_uk_tlstream_stats {
418 	union uk_header header; /**< UK structure header. */
419 	/* IN */
420 	/* OUT */
421 	u32 bytes_collected;
422 	u32 bytes_generated;
423 };
424 #endif /* MALI_UNIT_TEST */
425 
426 /**
427  * struct struct kbase_uk_prfcnt_value for the KBASE_FUNC_SET_PRFCNT_VALUES ioctl
428  * @header:          UK structure header
429  * @data:            Counter samples for the dummy model
430  * @size:............Size of the counter sample data
431  */
432 struct kbase_uk_prfcnt_values {
433 	union uk_header header;
434 	/* IN */
435 	u32 *data;
436 	u32 size;
437 };
438 
439 /**
440  * struct kbase_uk_soft_event_update - User/Kernel space data exchange structure
441  * @header:     UK structure header
442  * @evt:        the GPU address containing the event
443  * @new_status: the new event status, must be either BASE_JD_SOFT_EVENT_SET or
444  *              BASE_JD_SOFT_EVENT_RESET
445  * @flags:      reserved for future uses, must be set to 0
446  *
447  * This structure is used to update the status of a software event. If the
448  * event's status is set to BASE_JD_SOFT_EVENT_SET, any job currently waiting
449  * on this event will complete.
450  */
451 struct kbase_uk_soft_event_update {
452 	union uk_header header;
453 	/* IN */
454 	u64 evt;
455 	u32 new_status;
456 	u32 flags;
457 };
458 
459 /**
460  * struct kbase_uk_mem_jit_init - User/Kernel space data exchange structure
461  * @header:     UK structure header
462  * @va_pages:   Number of virtual pages required for JIT
463  *
464  * This structure is used when requesting initialization of JIT.
465  */
466 struct kbase_uk_mem_jit_init {
467 	union uk_header header;
468 	/* IN */
469 	u64 va_pages;
470 };
471 
472 enum kbase_uk_function_id {
473 	KBASE_FUNC_MEM_ALLOC = (UK_FUNC_ID + 0),
474 	KBASE_FUNC_MEM_IMPORT = (UK_FUNC_ID + 1),
475 	KBASE_FUNC_MEM_COMMIT = (UK_FUNC_ID + 2),
476 	KBASE_FUNC_MEM_QUERY = (UK_FUNC_ID + 3),
477 	KBASE_FUNC_MEM_FREE = (UK_FUNC_ID + 4),
478 	KBASE_FUNC_MEM_FLAGS_CHANGE = (UK_FUNC_ID + 5),
479 	KBASE_FUNC_MEM_ALIAS = (UK_FUNC_ID + 6),
480 
481 #ifdef BASE_LEGACY_UK6_SUPPORT
482 	KBASE_FUNC_JOB_SUBMIT_UK6 = (UK_FUNC_ID + 7),
483 #endif /* BASE_LEGACY_UK6_SUPPORT */
484 
485 	KBASE_FUNC_SYNC  = (UK_FUNC_ID + 8),
486 
487 	KBASE_FUNC_POST_TERM = (UK_FUNC_ID + 9),
488 
489 	KBASE_FUNC_HWCNT_SETUP = (UK_FUNC_ID + 10),
490 	KBASE_FUNC_HWCNT_DUMP = (UK_FUNC_ID + 11),
491 	KBASE_FUNC_HWCNT_CLEAR = (UK_FUNC_ID + 12),
492 
493 	KBASE_FUNC_GPU_PROPS_REG_DUMP = (UK_FUNC_ID + 14),
494 
495 	KBASE_FUNC_FIND_CPU_OFFSET = (UK_FUNC_ID + 15),
496 
497 	KBASE_FUNC_GET_VERSION = (UK_FUNC_ID + 16),
498 	KBASE_FUNC_SET_FLAGS = (UK_FUNC_ID + 18),
499 
500 	KBASE_FUNC_SET_TEST_DATA = (UK_FUNC_ID + 19),
501 	KBASE_FUNC_INJECT_ERROR = (UK_FUNC_ID + 20),
502 	KBASE_FUNC_MODEL_CONTROL = (UK_FUNC_ID + 21),
503 
504 #ifdef BASE_LEGACY_UK8_SUPPORT
505 	KBASE_FUNC_KEEP_GPU_POWERED = (UK_FUNC_ID + 22),
506 #endif /* BASE_LEGACY_UK8_SUPPORT */
507 
508 	KBASE_FUNC_FENCE_VALIDATE = (UK_FUNC_ID + 23),
509 	KBASE_FUNC_STREAM_CREATE = (UK_FUNC_ID + 24),
510 	KBASE_FUNC_GET_PROFILING_CONTROLS = (UK_FUNC_ID + 25),
511 	KBASE_FUNC_SET_PROFILING_CONTROLS = (UK_FUNC_ID + 26),
512 					    /* to be used only for testing
513 					    * purposes, otherwise these controls
514 					    * are set through gator API */
515 
516 	KBASE_FUNC_DEBUGFS_MEM_PROFILE_ADD = (UK_FUNC_ID + 27),
517 	KBASE_FUNC_JOB_SUBMIT = (UK_FUNC_ID + 28),
518 	KBASE_FUNC_DISJOINT_QUERY = (UK_FUNC_ID + 29),
519 
520 	KBASE_FUNC_GET_CONTEXT_ID = (UK_FUNC_ID + 31),
521 
522 	KBASE_FUNC_TLSTREAM_ACQUIRE_V10_4 = (UK_FUNC_ID + 32),
523 #if MALI_UNIT_TEST
524 	KBASE_FUNC_TLSTREAM_TEST = (UK_FUNC_ID + 33),
525 	KBASE_FUNC_TLSTREAM_STATS = (UK_FUNC_ID + 34),
526 #endif /* MALI_UNIT_TEST */
527 	KBASE_FUNC_TLSTREAM_FLUSH = (UK_FUNC_ID + 35),
528 
529 	KBASE_FUNC_HWCNT_READER_SETUP = (UK_FUNC_ID + 36),
530 
531 #ifdef SUPPORT_MALI_NO_MALI
532 	KBASE_FUNC_SET_PRFCNT_VALUES = (UK_FUNC_ID + 37),
533 #endif
534 
535 	KBASE_FUNC_SOFT_EVENT_UPDATE = (UK_FUNC_ID + 38),
536 
537 	KBASE_FUNC_MEM_JIT_INIT = (UK_FUNC_ID + 39),
538 
539 	KBASE_FUNC_TLSTREAM_ACQUIRE = (UK_FUNC_ID + 40),
540 
541 	KBASE_FUNC_MAX
542 };
543 
544 #endif				/* _KBASE_UKU_H_ */
545 
546