MALI: rockchip: upgrade midgard DDK to r14p0-01rel0
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_base_kernel.h
1 /*
2  *
3  * (C) COPYRIGHT 2010-2016 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 /**
21  * @file
22  * Base structures shared with the kernel.
23  */
24
25 #ifndef _BASE_KERNEL_H_
26 #define _BASE_KERNEL_H_
27
28 #ifndef __user
29 #define __user
30 #endif
31
32 /* Support UK6 IOCTLS */
33 #define BASE_LEGACY_UK6_SUPPORT 1
34
35 /* Support UK7 IOCTLS */
36 /* NB: To support UK6 we also need to support UK7 */
37 #define BASE_LEGACY_UK7_SUPPORT 1
38
39 /* Support UK8 IOCTLS */
40 #define BASE_LEGACY_UK8_SUPPORT 1
41
42 /* Support UK9 IOCTLS */
43 #define BASE_LEGACY_UK9_SUPPORT 1
44
45 /* Support UK10_2 IOCTLS */
46 #define BASE_LEGACY_UK10_2_SUPPORT 1
47
48 /* Support UK10_4 IOCTLS */
49 #define BASE_LEGACY_UK10_4_SUPPORT 1
50
51 typedef struct base_mem_handle {
52         struct {
53                 u64 handle;
54         } basep;
55 } base_mem_handle;
56
57 #include "mali_base_mem_priv.h"
58 #include "mali_kbase_profiling_gator_api.h"
59 #include "mali_midg_coherency.h"
60 #include "mali_kbase_gpu_id.h"
61
62 /*
63  * Dependency stuff, keep it private for now. May want to expose it if
64  * we decide to make the number of semaphores a configurable
65  * option.
66  */
67 #define BASE_JD_ATOM_COUNT              256
68
69 #define BASEP_JD_SEM_PER_WORD_LOG2      5
70 #define BASEP_JD_SEM_PER_WORD           (1 << BASEP_JD_SEM_PER_WORD_LOG2)
71 #define BASEP_JD_SEM_WORD_NR(x)         ((x) >> BASEP_JD_SEM_PER_WORD_LOG2)
72 #define BASEP_JD_SEM_MASK_IN_WORD(x)    (1 << ((x) & (BASEP_JD_SEM_PER_WORD - 1)))
73 #define BASEP_JD_SEM_ARRAY_SIZE         BASEP_JD_SEM_WORD_NR(BASE_JD_ATOM_COUNT)
74
75 /* Set/reset values for a software event */
76 #define BASE_JD_SOFT_EVENT_SET             ((unsigned char)1)
77 #define BASE_JD_SOFT_EVENT_RESET           ((unsigned char)0)
78
79 #define BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3
80
81 #define BASE_MAX_COHERENT_GROUPS 16
82
83 #if defined CDBG_ASSERT
84 #define LOCAL_ASSERT CDBG_ASSERT
85 #elif defined KBASE_DEBUG_ASSERT
86 #define LOCAL_ASSERT KBASE_DEBUG_ASSERT
87 #else
88 #error assert macro not defined!
89 #endif
90
91 #if defined PAGE_MASK
92 #define LOCAL_PAGE_LSB ~PAGE_MASK
93 #else
94 #include <osu/mali_osu.h>
95
96 #if defined OSU_CONFIG_CPU_PAGE_SIZE_LOG2
97 #define LOCAL_PAGE_LSB ((1ul << OSU_CONFIG_CPU_PAGE_SIZE_LOG2) - 1)
98 #else
99 #error Failed to find page size
100 #endif
101 #endif
102
103 /** 32/64-bit neutral way to represent pointers */
104 typedef union kbase_pointer {
105         void __user *value;       /**< client should store their pointers here */
106         u32 compat_value; /**< 64-bit kernels should fetch value here when handling 32-bit clients */
107         u64 sizer;        /**< Force 64-bit storage for all clients regardless */
108 } kbase_pointer;
109
110 /**
111  * @addtogroup base_user_api User-side Base APIs
112  * @{
113  */
114
115 /**
116  * @addtogroup base_user_api_memory User-side Base Memory APIs
117  * @{
118  */
119
120 /**
121  * @brief Memory allocation, access/hint flags
122  *
123  * A combination of MEM_PROT/MEM_HINT flags must be passed to each allocator
124  * in order to determine the best cache policy. Some combinations are
125  * of course invalid (eg @c MEM_PROT_CPU_WR | @c MEM_HINT_CPU_RD),
126  * which defines a @a write-only region on the CPU side, which is
127  * heavily read by the CPU...
128  * Other flags are only meaningful to a particular allocator.
129  * More flags can be added to this list, as long as they don't clash
130  * (see ::BASE_MEM_FLAGS_NR_BITS for the number of the first free bit).
131  */
132 typedef u32 base_mem_alloc_flags;
133
134 /**
135  * @brief Memory allocation, access/hint flags
136  *
137  * See ::base_mem_alloc_flags.
138  *
139  */
140 enum {
141 /* IN */
142         BASE_MEM_PROT_CPU_RD = (1U << 0),      /**< Read access CPU side */
143         BASE_MEM_PROT_CPU_WR = (1U << 1),      /**< Write access CPU side */
144         BASE_MEM_PROT_GPU_RD = (1U << 2),      /**< Read access GPU side */
145         BASE_MEM_PROT_GPU_WR = (1U << 3),      /**< Write access GPU side */
146         BASE_MEM_PROT_GPU_EX = (1U << 4),      /**< Execute allowed on the GPU
147                                                     side */
148
149         /* BASE_MEM_HINT flags have been removed, but their values are reserved
150          * for backwards compatibility with older user-space drivers. The values
151          * can be re-used once support for r5p0 user-space drivers is removed,
152          * presumably in r7p0.
153          *
154          * RESERVED: (1U << 5)
155          * RESERVED: (1U << 6)
156          * RESERVED: (1U << 7)
157          * RESERVED: (1U << 8)
158          */
159
160         BASE_MEM_GROW_ON_GPF = (1U << 9),      /**< Grow backing store on GPU
161                                                     Page Fault */
162
163         BASE_MEM_COHERENT_SYSTEM = (1U << 10), /**< Page coherence Outer
164                                                     shareable, if available */
165         BASE_MEM_COHERENT_LOCAL = (1U << 11),  /**< Page coherence Inner
166                                                     shareable */
167         BASE_MEM_CACHED_CPU = (1U << 12),      /**< Should be cached on the
168                                                     CPU */
169
170 /* IN/OUT */
171         BASE_MEM_SAME_VA = (1U << 13), /**< Must have same VA on both the GPU
172                                             and the CPU */
173 /* OUT */
174         BASE_MEM_NEED_MMAP = (1U << 14), /**< Must call mmap to aquire a GPU
175                                              address for the alloc */
176 /* IN */
177         BASE_MEM_COHERENT_SYSTEM_REQUIRED = (1U << 15), /**< Page coherence
178                                              Outer shareable, required. */
179         BASE_MEM_SECURE = (1U << 16),          /**< Secure memory */
180         BASE_MEM_DONT_NEED = (1U << 17),       /**< Not needed physical
181                                                     memory */
182         BASE_MEM_IMPORT_SHARED = (1U << 18),   /**< Must use shared CPU/GPU zone
183                                                     (SAME_VA zone) but doesn't
184                                                     require the addresses to
185                                                     be the same */
186 };
187
188 /**
189  * @brief Number of bits used as flags for base memory management
190  *
191  * Must be kept in sync with the ::base_mem_alloc_flags flags
192  */
193 #define BASE_MEM_FLAGS_NR_BITS 19
194
195 /**
196   * A mask for all output bits, excluding IN/OUT bits.
197   */
198 #define BASE_MEM_FLAGS_OUTPUT_MASK BASE_MEM_NEED_MMAP
199
200 /**
201   * A mask for all input bits, including IN/OUT bits.
202   */
203 #define BASE_MEM_FLAGS_INPUT_MASK \
204         (((1 << BASE_MEM_FLAGS_NR_BITS) - 1) & ~BASE_MEM_FLAGS_OUTPUT_MASK)
205
206 /**
207  * A mask for all the flags which are modifiable via the base_mem_set_flags
208  * interface.
209  */
210 #define BASE_MEM_FLAGS_MODIFIABLE \
211         (BASE_MEM_DONT_NEED | BASE_MEM_COHERENT_SYSTEM | \
212          BASE_MEM_COHERENT_LOCAL)
213
214 /**
215  * enum base_mem_import_type - Memory types supported by @a base_mem_import
216  *
217  * @BASE_MEM_IMPORT_TYPE_INVALID: Invalid type
218  * @BASE_MEM_IMPORT_TYPE_UMP: UMP import. Handle type is ump_secure_id.
219  * @BASE_MEM_IMPORT_TYPE_UMM: UMM import. Handle type is a file descriptor (int)
220  * @BASE_MEM_IMPORT_TYPE_USER_BUFFER: User buffer import. Handle is a
221  * base_mem_import_user_buffer
222  *
223  * Each type defines what the supported handle type is.
224  *
225  * If any new type is added here ARM must be contacted
226  * to allocate a numeric value for it.
227  * Do not just add a new type without synchronizing with ARM
228  * as future releases from ARM might include other new types
229  * which could clash with your custom types.
230  */
231 typedef enum base_mem_import_type {
232         BASE_MEM_IMPORT_TYPE_INVALID = 0,
233         BASE_MEM_IMPORT_TYPE_UMP = 1,
234         BASE_MEM_IMPORT_TYPE_UMM = 2,
235         BASE_MEM_IMPORT_TYPE_USER_BUFFER = 3
236 } base_mem_import_type;
237
238 /**
239  * struct base_mem_import_user_buffer - Handle of an imported user buffer
240  *
241  * @ptr:        kbase_pointer to imported user buffer
242  * @length:     length of imported user buffer in bytes
243  *
244  * This structure is used to represent a handle of an imported user buffer.
245  */
246
247 struct base_mem_import_user_buffer {
248         kbase_pointer ptr;
249         u64 length;
250 };
251
252 /**
253  * @brief Invalid memory handle.
254  *
255  * Return value from functions returning @ref base_mem_handle on error.
256  *
257  * @warning @ref base_mem_handle_new_invalid must be used instead of this macro
258  *          in C++ code or other situations where compound literals cannot be used.
259  */
260 #define BASE_MEM_INVALID_HANDLE ((base_mem_handle) { {BASEP_MEM_INVALID_HANDLE} })
261
262 /**
263  * @brief Special write-alloc memory handle.
264  *
265  * A special handle is used to represent a region where a special page is mapped
266  * with a write-alloc cache setup, typically used when the write result of the
267  * GPU isn't needed, but the GPU must write anyway.
268  *
269  * @warning @ref base_mem_handle_new_write_alloc must be used instead of this macro
270  *          in C++ code or other situations where compound literals cannot be used.
271  */
272 #define BASE_MEM_WRITE_ALLOC_PAGES_HANDLE ((base_mem_handle) { {BASEP_MEM_WRITE_ALLOC_PAGES_HANDLE} })
273
274 #define BASEP_MEM_INVALID_HANDLE               (0ull  << 12)
275 #define BASE_MEM_MMU_DUMP_HANDLE               (1ull  << 12)
276 #define BASE_MEM_TRACE_BUFFER_HANDLE           (2ull  << 12)
277 #define BASE_MEM_MAP_TRACKING_HANDLE           (3ull  << 12)
278 #define BASEP_MEM_WRITE_ALLOC_PAGES_HANDLE     (4ull  << 12)
279 /* reserved handles ..-64<<PAGE_SHIFT> for future special handles */
280 #define BASE_MEM_COOKIE_BASE                   (64ul  << 12)
281 #define BASE_MEM_FIRST_FREE_ADDRESS            ((BITS_PER_LONG << 12) + \
282                                                 BASE_MEM_COOKIE_BASE)
283
284 /* Mask to detect 4GB boundary alignment */
285 #define BASE_MEM_MASK_4GB  0xfffff000UL
286
287
288 /* Bit mask of cookies used for for memory allocation setup */
289 #define KBASE_COOKIE_MASK  ~1UL /* bit 0 is reserved */
290
291
292 /**
293  * @brief Result codes of changing the size of the backing store allocated to a tmem region
294  */
295 typedef enum base_backing_threshold_status {
296         BASE_BACKING_THRESHOLD_OK = 0,                      /**< Resize successful */
297         BASE_BACKING_THRESHOLD_ERROR_NOT_GROWABLE = -1,     /**< Not a growable tmem object */
298         BASE_BACKING_THRESHOLD_ERROR_OOM = -2,              /**< Increase failed due to an out-of-memory condition */
299         BASE_BACKING_THRESHOLD_ERROR_INVALID_ARGUMENTS = -4 /**< Invalid arguments (not tmem, illegal size request, etc.) */
300 } base_backing_threshold_status;
301
302 /**
303  * @addtogroup base_user_api_memory_defered User-side Base Defered Memory Coherency APIs
304  * @{
305  */
306
307 /**
308  * @brief a basic memory operation (sync-set).
309  *
310  * The content of this structure is private, and should only be used
311  * by the accessors.
312  */
313 typedef struct base_syncset {
314         struct basep_syncset basep_sset;
315 } base_syncset;
316
317 /** @} end group base_user_api_memory_defered */
318
319 /**
320  * Handle to represent imported memory object.
321  * Simple opague handle to imported memory, can't be used
322  * with anything but base_external_resource_init to bind to an atom.
323  */
324 typedef struct base_import_handle {
325         struct {
326                 u64 handle;
327         } basep;
328 } base_import_handle;
329
330 /** @} end group base_user_api_memory */
331
332 /**
333  * @addtogroup base_user_api_job_dispatch User-side Base Job Dispatcher APIs
334  * @{
335  */
336
337 typedef int platform_fence_type;
338 #define INVALID_PLATFORM_FENCE ((platform_fence_type)-1)
339
340 /**
341  * Base stream handle.
342  *
343  * References an underlying base stream object.
344  */
345 typedef struct base_stream {
346         struct {
347                 int fd;
348         } basep;
349 } base_stream;
350
351 /**
352  * Base fence handle.
353  *
354  * References an underlying base fence object.
355  */
356 typedef struct base_fence {
357         struct {
358                 int fd;
359                 int stream_fd;
360         } basep;
361 } base_fence;
362
363 /**
364  * @brief Per-job data
365  *
366  * This structure is used to store per-job data, and is completly unused
367  * by the Base driver. It can be used to store things such as callback
368  * function pointer, data to handle job completion. It is guaranteed to be
369  * untouched by the Base driver.
370  */
371 typedef struct base_jd_udata {
372         u64 blob[2];     /**< per-job data array */
373 } base_jd_udata;
374
375 /**
376  * @brief Memory aliasing info
377  *
378  * Describes a memory handle to be aliased.
379  * A subset of the handle can be chosen for aliasing, given an offset and a
380  * length.
381  * A special handle BASE_MEM_WRITE_ALLOC_PAGES_HANDLE is used to represent a
382  * region where a special page is mapped with a write-alloc cache setup,
383  * typically used when the write result of the GPU isn't needed, but the GPU
384  * must write anyway.
385  *
386  * Offset and length are specified in pages.
387  * Offset must be within the size of the handle.
388  * Offset+length must not overrun the size of the handle.
389  *
390  * @handle Handle to alias, can be BASE_MEM_WRITE_ALLOC_PAGES_HANDLE
391  * @offset Offset within the handle to start aliasing from, in pages.
392  *         Not used with BASE_MEM_WRITE_ALLOC_PAGES_HANDLE.
393  * @length Length to alias, in pages. For BASE_MEM_WRITE_ALLOC_PAGES_HANDLE
394  *         specifies the number of times the special page is needed.
395  */
396 struct base_mem_aliasing_info {
397         base_mem_handle handle;
398         u64 offset;
399         u64 length;
400 };
401
402 /**
403  * struct base_jit_alloc_info - Structure which describes a JIT allocation
404  *                              request.
405  * @gpu_alloc_addr:             The GPU virtual address to write the JIT
406  *                              allocated GPU virtual address to.
407  * @va_pages:                   The minimum number of virtual pages required.
408  * @commit_pages:               The minimum number of physical pages which
409  *                              should back the allocation.
410  * @extent:                     Granularity of physical pages to grow the
411  *                              allocation by during a fault.
412  * @id:                         Unique ID provided by the caller, this is used
413  *                              to pair allocation and free requests.
414  *                              Zero is not a valid value.
415  */
416 struct base_jit_alloc_info {
417         u64 gpu_alloc_addr;
418         u64 va_pages;
419         u64 commit_pages;
420         u64 extent;
421         u8 id;
422 };
423
424 /**
425  * @brief Job dependency type.
426  *
427  * A flags field will be inserted into the atom structure to specify whether a dependency is a data or
428  * ordering dependency (by putting it before/after 'core_req' in the structure it should be possible to add without
429  * changing the structure size).
430  * When the flag is set for a particular dependency to signal that it is an ordering only dependency then
431  * errors will not be propagated.
432  */
433 typedef u8 base_jd_dep_type;
434
435
436 #define BASE_JD_DEP_TYPE_INVALID  (0)       /**< Invalid dependency */
437 #define BASE_JD_DEP_TYPE_DATA     (1U << 0) /**< Data dependency */
438 #define BASE_JD_DEP_TYPE_ORDER    (1U << 1) /**< Order dependency */
439
440 /**
441  * @brief Job chain hardware requirements.
442  *
443  * A job chain must specify what GPU features it needs to allow the
444  * driver to schedule the job correctly.  By not specifying the
445  * correct settings can/will cause an early job termination.  Multiple
446  * values can be ORed together to specify multiple requirements.
447  * Special case is ::BASE_JD_REQ_DEP, which is used to express complex
448  * dependencies, and that doesn't execute anything on the hardware.
449  */
450 typedef u32 base_jd_core_req;
451
452 /* Requirements that come from the HW */
453
454 /**
455  * No requirement, dependency only
456  */
457 #define BASE_JD_REQ_DEP ((base_jd_core_req)0)
458
459 /**
460  * Requires fragment shaders
461  */
462 #define BASE_JD_REQ_FS  ((base_jd_core_req)1 << 0)
463
464 /**
465  * Requires compute shaders
466  * This covers any of the following Midgard Job types:
467  * - Vertex Shader Job
468  * - Geometry Shader Job
469  * - An actual Compute Shader Job
470  *
471  * Compare this with @ref BASE_JD_REQ_ONLY_COMPUTE, which specifies that the
472  * job is specifically just the "Compute Shader" job type, and not the "Vertex
473  * Shader" nor the "Geometry Shader" job type.
474  */
475 #define BASE_JD_REQ_CS  ((base_jd_core_req)1 << 1)
476 #define BASE_JD_REQ_T   ((base_jd_core_req)1 << 2)   /**< Requires tiling */
477 #define BASE_JD_REQ_CF  ((base_jd_core_req)1 << 3)   /**< Requires cache flushes */
478 #define BASE_JD_REQ_V   ((base_jd_core_req)1 << 4)   /**< Requires value writeback */
479
480 /* SW-only requirements - the HW does not expose these as part of the job slot capabilities */
481
482 /* Requires fragment job with AFBC encoding */
483 #define BASE_JD_REQ_FS_AFBC  ((base_jd_core_req)1 << 13)
484
485 /**
486  * SW-only requirement: coalesce completion events.
487  * If this bit is set then completion of this atom will not cause an event to
488  * be sent to userspace, whether successful or not; completion events will be
489  * deferred until an atom completes which does not have this bit set.
490  *
491  * This bit may not be used in combination with BASE_JD_REQ_EXTERNAL_RESOURCES.
492  */
493 #define BASE_JD_REQ_EVENT_COALESCE ((base_jd_core_req)1 << 5)
494
495 /**
496  * SW Only requirement: the job chain requires a coherent core group. We don't
497  * mind which coherent core group is used.
498  */
499 #define BASE_JD_REQ_COHERENT_GROUP  ((base_jd_core_req)1 << 6)
500
501 /**
502  * SW Only requirement: The performance counters should be enabled only when
503  * they are needed, to reduce power consumption.
504  */
505
506 #define BASE_JD_REQ_PERMON               ((base_jd_core_req)1 << 7)
507
508 /**
509  * SW Only requirement: External resources are referenced by this atom.
510  * When external resources are referenced no syncsets can be bundled with the atom
511  * but should instead be part of a NULL jobs inserted into the dependency tree.
512  * The first pre_dep object must be configured for the external resouces to use,
513  * the second pre_dep object can be used to create other dependencies.
514  *
515  * This bit may not be used in combination with BASE_JD_REQ_EVENT_COALESCE.
516  */
517 #define BASE_JD_REQ_EXTERNAL_RESOURCES   ((base_jd_core_req)1 << 8)
518
519 /**
520  * SW Only requirement: Software defined job. Jobs with this bit set will not be submitted
521  * to the hardware but will cause some action to happen within the driver
522  */
523 #define BASE_JD_REQ_SOFT_JOB        ((base_jd_core_req)1 << 9)
524
525 #define BASE_JD_REQ_SOFT_DUMP_CPU_GPU_TIME      (BASE_JD_REQ_SOFT_JOB | 0x1)
526 #define BASE_JD_REQ_SOFT_FENCE_TRIGGER          (BASE_JD_REQ_SOFT_JOB | 0x2)
527 #define BASE_JD_REQ_SOFT_FENCE_WAIT             (BASE_JD_REQ_SOFT_JOB | 0x3)
528
529 /**
530  * SW Only requirement : Replay job.
531  *
532  * If the preceeding job fails, the replay job will cause the jobs specified in
533  * the list of base_jd_replay_payload pointed to by the jc pointer to be
534  * replayed.
535  *
536  * A replay job will only cause jobs to be replayed up to BASEP_JD_REPLAY_LIMIT
537  * times. If a job fails more than BASEP_JD_REPLAY_LIMIT times then the replay
538  * job is failed, as well as any following dependencies.
539  *
540  * The replayed jobs will require a number of atom IDs. If there are not enough
541  * free atom IDs then the replay job will fail.
542  *
543  * If the preceeding job does not fail, then the replay job is returned as
544  * completed.
545  *
546  * The replayed jobs will never be returned to userspace. The preceeding failed
547  * job will be returned to userspace as failed; the status of this job should
548  * be ignored. Completion should be determined by the status of the replay soft
549  * job.
550  *
551  * In order for the jobs to be replayed, the job headers will have to be
552  * modified. The Status field will be reset to NOT_STARTED. If the Job Type
553  * field indicates a Vertex Shader Job then it will be changed to Null Job.
554  *
555  * The replayed jobs have the following assumptions :
556  *
557  * - No external resources. Any required external resources will be held by the
558  *   replay atom.
559  * - Pre-dependencies are created based on job order.
560  * - Atom numbers are automatically assigned.
561  * - device_nr is set to 0. This is not relevant as
562  *   BASE_JD_REQ_SPECIFIC_COHERENT_GROUP should not be set.
563  * - Priority is inherited from the replay job.
564  */
565 #define BASE_JD_REQ_SOFT_REPLAY                 (BASE_JD_REQ_SOFT_JOB | 0x4)
566 /**
567  * SW only requirement: event wait/trigger job.
568  *
569  * - BASE_JD_REQ_SOFT_EVENT_WAIT: this job will block until the event is set.
570  * - BASE_JD_REQ_SOFT_EVENT_SET: this job sets the event, thus unblocks the
571  *   other waiting jobs. It completes immediately.
572  * - BASE_JD_REQ_SOFT_EVENT_RESET: this job resets the event, making it
573  *   possible for other jobs to wait upon. It completes immediately.
574  */
575 #define BASE_JD_REQ_SOFT_EVENT_WAIT             (BASE_JD_REQ_SOFT_JOB | 0x5)
576 #define BASE_JD_REQ_SOFT_EVENT_SET              (BASE_JD_REQ_SOFT_JOB | 0x6)
577 #define BASE_JD_REQ_SOFT_EVENT_RESET            (BASE_JD_REQ_SOFT_JOB | 0x7)
578
579 #define BASE_JD_REQ_SOFT_DEBUG_COPY             (BASE_JD_REQ_SOFT_JOB | 0x8)
580
581 /**
582  * SW only requirement: Just In Time allocation
583  *
584  * This job requests a JIT allocation based on the request in the
585  * @base_jit_alloc_info structure which is passed via the jc element of
586  * the atom.
587  *
588  * It should be noted that the id entry in @base_jit_alloc_info must not
589  * be reused until it has been released via @BASE_JD_REQ_SOFT_JIT_FREE.
590  *
591  * Should this soft job fail it is expected that a @BASE_JD_REQ_SOFT_JIT_FREE
592  * soft job to free the JIT allocation is still made.
593  *
594  * The job will complete immediately.
595  */
596 #define BASE_JD_REQ_SOFT_JIT_ALLOC              (BASE_JD_REQ_SOFT_JOB | 0x9)
597 /**
598  * SW only requirement: Just In Time free
599  *
600  * This job requests a JIT allocation created by @BASE_JD_REQ_SOFT_JIT_ALLOC
601  * to be freed. The ID of the JIT allocation is passed via the jc element of
602  * the atom.
603  *
604  * The job will complete immediately.
605  */
606 #define BASE_JD_REQ_SOFT_JIT_FREE               (BASE_JD_REQ_SOFT_JOB | 0xa)
607
608 /**
609  * SW only requirement: Map external resource
610  *
611  * This job requests external resource(s) are mapped once the dependencies
612  * of the job have been satisfied. The list of external resources are
613  * passed via the jc element of the atom which is a pointer to a
614  * @base_external_resource_list.
615  */
616 #define BASE_JD_REQ_SOFT_EXT_RES_MAP            (BASE_JD_REQ_SOFT_JOB | 0xb)
617 /**
618  * SW only requirement: Unmap external resource
619  *
620  * This job requests external resource(s) are unmapped once the dependencies
621  * of the job has been satisfied. The list of external resources are
622  * passed via the jc element of the atom which is a pointer to a
623  * @base_external_resource_list.
624  */
625 #define BASE_JD_REQ_SOFT_EXT_RES_UNMAP          (BASE_JD_REQ_SOFT_JOB | 0xc)
626
627 /**
628  * HW Requirement: Requires Compute shaders (but not Vertex or Geometry Shaders)
629  *
630  * This indicates that the Job Chain contains Midgard Jobs of the 'Compute Shaders' type.
631  *
632  * In contrast to @ref BASE_JD_REQ_CS, this does \b not indicate that the Job
633  * Chain contains 'Geometry Shader' or 'Vertex Shader' jobs.
634  */
635 #define BASE_JD_REQ_ONLY_COMPUTE    ((base_jd_core_req)1 << 10)
636
637 /**
638  * HW Requirement: Use the base_jd_atom::device_nr field to specify a
639  * particular core group
640  *
641  * If both @ref BASE_JD_REQ_COHERENT_GROUP and this flag are set, this flag takes priority
642  *
643  * This is only guaranteed to work for @ref BASE_JD_REQ_ONLY_COMPUTE atoms.
644  *
645  * If the core availability policy is keeping the required core group turned off, then
646  * the job will fail with a @ref BASE_JD_EVENT_PM_EVENT error code.
647  */
648 #define BASE_JD_REQ_SPECIFIC_COHERENT_GROUP ((base_jd_core_req)1 << 11)
649
650 /**
651  * SW Flag: If this bit is set then the successful completion of this atom
652  * will not cause an event to be sent to userspace
653  */
654 #define BASE_JD_REQ_EVENT_ONLY_ON_FAILURE   ((base_jd_core_req)1 << 12)
655
656 /**
657  * SW Flag: If this bit is set then completion of this atom will not cause an
658  * event to be sent to userspace, whether successful or not.
659  */
660 #define BASEP_JD_REQ_EVENT_NEVER ((base_jd_core_req)1 << 14)
661
662 /**
663  * SW Flag: Skip GPU cache clean and invalidation before starting a GPU job.
664  *
665  * If this bit is set then the GPU's cache will not be cleaned and invalidated
666  * until a GPU job starts which does not have this bit set or a job completes
667  * which does not have the @ref BASE_JD_REQ_SKIP_CACHE_END bit set. Do not use if
668  * the CPU may have written to memory addressed by the job since the last job
669  * without this bit set was submitted.
670  */
671 #define BASE_JD_REQ_SKIP_CACHE_START ((base_jd_core_req)1 << 15)
672
673 /**
674  * SW Flag: Skip GPU cache clean and invalidation after a GPU job completes.
675  *
676  * If this bit is set then the GPU's cache will not be cleaned and invalidated
677  * until a GPU job completes which does not have this bit set or a job starts
678  * which does not have the @ref BASE_JD_REQ_SKIP_CACHE_START bti set. Do not use if
679  * the CPU may read from or partially overwrite memory addressed by the job
680  * before the next job without this bit set completes.
681  */
682 #define BASE_JD_REQ_SKIP_CACHE_END ((base_jd_core_req)1 << 16)
683
684 /**
685  * These requirement bits are currently unused in base_jd_core_req
686  */
687 #define BASEP_JD_REQ_RESERVED \
688         (~(BASE_JD_REQ_ATOM_TYPE | BASE_JD_REQ_EXTERNAL_RESOURCES | \
689         BASE_JD_REQ_EVENT_ONLY_ON_FAILURE | BASEP_JD_REQ_EVENT_NEVER | \
690         BASE_JD_REQ_EVENT_COALESCE | \
691         BASE_JD_REQ_COHERENT_GROUP | BASE_JD_REQ_SPECIFIC_COHERENT_GROUP | \
692         BASE_JD_REQ_FS_AFBC | BASE_JD_REQ_PERMON | \
693         BASE_JD_REQ_SKIP_CACHE_START | BASE_JD_REQ_SKIP_CACHE_END))
694
695 /**
696  * Mask of all bits in base_jd_core_req that control the type of the atom.
697  *
698  * This allows dependency only atoms to have flags set
699  */
700 #define BASE_JD_REQ_ATOM_TYPE \
701         (BASE_JD_REQ_FS | BASE_JD_REQ_CS | BASE_JD_REQ_T | BASE_JD_REQ_CF | \
702         BASE_JD_REQ_V | BASE_JD_REQ_SOFT_JOB | BASE_JD_REQ_ONLY_COMPUTE)
703
704 /**
705  * Mask of all bits in base_jd_core_req that control the type of a soft job.
706  */
707 #define BASE_JD_REQ_SOFT_JOB_TYPE (BASE_JD_REQ_SOFT_JOB | 0x1f)
708
709 /**
710  * @brief States to model state machine processed by kbasep_js_job_check_ref_cores(), which
711  * handles retaining cores for power management and affinity management.
712  *
713  * The state @ref KBASE_ATOM_COREREF_STATE_RECHECK_AFFINITY prevents an attack
714  * where lots of atoms could be submitted before powerup, and each has an
715  * affinity chosen that causes other atoms to have an affinity
716  * violation. Whilst the affinity was not causing violations at the time it
717  * was chosen, it could cause violations thereafter. For example, 1000 jobs
718  * could have had their affinity chosen during the powerup time, so any of
719  * those 1000 jobs could cause an affinity violation later on.
720  *
721  * The attack would otherwise occur because other atoms/contexts have to wait for:
722  * -# the currently running atoms (which are causing the violation) to
723  * finish
724  * -# and, the atoms that had their affinity chosen during powerup to
725  * finish. These are run preferrentially because they don't cause a
726  * violation, but instead continue to cause the violation in others.
727  * -# or, the attacker is scheduled out (which might not happen for just 2
728  * contexts)
729  *
730  * By re-choosing the affinity (which is designed to avoid violations at the
731  * time it's chosen), we break condition (2) of the wait, which minimizes the
732  * problem to just waiting for current jobs to finish (which can be bounded if
733  * the Job Scheduling Policy has a timer).
734  */
735 enum kbase_atom_coreref_state {
736         /** Starting state: No affinity chosen, and cores must be requested. kbase_jd_atom::affinity==0 */
737         KBASE_ATOM_COREREF_STATE_NO_CORES_REQUESTED,
738         /** Cores requested, but waiting for them to be powered. Requested cores given by kbase_jd_atom::affinity */
739         KBASE_ATOM_COREREF_STATE_WAITING_FOR_REQUESTED_CORES,
740         /** Cores given by kbase_jd_atom::affinity are powered, but affinity might be out-of-date, so must recheck */
741         KBASE_ATOM_COREREF_STATE_RECHECK_AFFINITY,
742         /** Cores given by kbase_jd_atom::affinity are powered, and affinity is up-to-date, but must check for violations */
743         KBASE_ATOM_COREREF_STATE_CHECK_AFFINITY_VIOLATIONS,
744         /** Cores are powered, kbase_jd_atom::affinity up-to-date, no affinity violations: atom can be submitted to HW */
745         KBASE_ATOM_COREREF_STATE_READY
746 };
747
748 /*
749  * Base Atom priority
750  *
751  * Only certain priority levels are actually implemented, as specified by the
752  * BASE_JD_PRIO_<...> definitions below. It is undefined to use a priority
753  * level that is not one of those defined below.
754  *
755  * Priority levels only affect scheduling between atoms of the same type within
756  * a base context, and only after the atoms have had dependencies resolved.
757  * Fragment atoms does not affect non-frament atoms with lower priorities, and
758  * the other way around. For example, a low priority atom that has had its
759  * dependencies resolved might run before a higher priority atom that has not
760  * had its dependencies resolved.
761  *
762  * The scheduling between base contexts/processes and between atoms from
763  * different base contexts/processes is unaffected by atom priority.
764  *
765  * The atoms are scheduled as follows with respect to their priorities:
766  * - Let atoms 'X' and 'Y' be for the same job slot who have dependencies
767  *   resolved, and atom 'X' has a higher priority than atom 'Y'
768  * - If atom 'Y' is currently running on the HW, then it is interrupted to
769  *   allow atom 'X' to run soon after
770  * - If instead neither atom 'Y' nor atom 'X' are running, then when choosing
771  *   the next atom to run, atom 'X' will always be chosen instead of atom 'Y'
772  * - Any two atoms that have the same priority could run in any order with
773  *   respect to each other. That is, there is no ordering constraint between
774  *   atoms of the same priority.
775  */
776 typedef u8 base_jd_prio;
777
778 /* Medium atom priority. This is a priority higher than BASE_JD_PRIO_LOW */
779 #define BASE_JD_PRIO_MEDIUM  ((base_jd_prio)0)
780 /* High atom priority. This is a priority higher than BASE_JD_PRIO_MEDIUM and
781  * BASE_JD_PRIO_LOW */
782 #define BASE_JD_PRIO_HIGH    ((base_jd_prio)1)
783 /* Low atom priority. */
784 #define BASE_JD_PRIO_LOW     ((base_jd_prio)2)
785
786 /* Count of the number of priority levels. This itself is not a valid
787  * base_jd_prio setting */
788 #define BASE_JD_NR_PRIO_LEVELS 3
789
790 enum kbase_jd_atom_state {
791         /** Atom is not used */
792         KBASE_JD_ATOM_STATE_UNUSED,
793         /** Atom is queued in JD */
794         KBASE_JD_ATOM_STATE_QUEUED,
795         /** Atom has been given to JS (is runnable/running) */
796         KBASE_JD_ATOM_STATE_IN_JS,
797         /** Atom has been completed, but not yet handed back to job dispatcher
798          *  for dependency resolution */
799         KBASE_JD_ATOM_STATE_HW_COMPLETED,
800         /** Atom has been completed, but not yet handed back to userspace */
801         KBASE_JD_ATOM_STATE_COMPLETED
802 };
803
804 typedef u8 base_atom_id; /**< Type big enough to store an atom number in */
805
806 struct base_dependency {
807         base_atom_id  atom_id;               /**< An atom number */
808         base_jd_dep_type dependency_type;    /**< Dependency type */
809 };
810
811 /* This structure has changed since UK 10.2 for which base_jd_core_req was a u16 value.
812  * In order to keep the size of the structure same, padding field has been adjusted
813  * accordingly and core_req field of a u32 type (to which UK 10.3 base_jd_core_req defines)
814  * is added at the end of the structure. Place in the structure previously occupied by u16 core_req
815  * is kept but renamed to compat_core_req and as such it can be used in ioctl call for job submission
816  * as long as UK 10.2 legacy is supported. Once when this support ends, this field can be left
817  * for possible future use. */
818 typedef struct base_jd_atom_v2 {
819         u64 jc;                     /**< job-chain GPU address */
820         struct base_jd_udata udata;                 /**< user data */
821         kbase_pointer extres_list;          /**< list of external resources */
822         u16 nr_extres;                      /**< nr of external resources */
823         u16 compat_core_req;                /**< core requirements which correspond to the legacy support for UK 10.2 */
824         struct base_dependency pre_dep[2];  /**< pre-dependencies, one need to use SETTER function to assign this field,
825         this is done in order to reduce possibility of improper assigment of a dependency field */
826         base_atom_id atom_number;           /**< unique number to identify the atom */
827         base_jd_prio prio;                  /**< Atom priority. Refer to @ref base_jd_prio for more details */
828         u8 device_nr;                       /**< coregroup when BASE_JD_REQ_SPECIFIC_COHERENT_GROUP specified */
829         u8 padding[1];
830         base_jd_core_req core_req;          /**< core requirements */
831 } base_jd_atom_v2;
832
833 #ifdef BASE_LEGACY_UK6_SUPPORT
834 struct base_jd_atom_v2_uk6 {
835         u64 jc;                     /**< job-chain GPU address */
836         struct base_jd_udata udata;                 /**< user data */
837         kbase_pointer extres_list;          /**< list of external resources */
838         u16 nr_extres;                      /**< nr of external resources */
839         u16 core_req;                       /**< core requirements */
840         base_atom_id pre_dep[2]; /**< pre-dependencies */
841         base_atom_id atom_number;           /**< unique number to identify the atom */
842         base_jd_prio prio;                  /**< priority - smaller is higher priority */
843         u8 device_nr;                       /**< coregroup when BASE_JD_REQ_SPECIFIC_COHERENT_GROUP specified */
844         u8 padding[7];
845 };
846 #endif /* BASE_LEGACY_UK6_SUPPORT */
847
848 typedef enum base_external_resource_access {
849         BASE_EXT_RES_ACCESS_SHARED,
850         BASE_EXT_RES_ACCESS_EXCLUSIVE
851 } base_external_resource_access;
852
853 typedef struct base_external_resource {
854         u64 ext_resource;
855 } base_external_resource;
856
857
858 /**
859  * The maximum number of external resources which can be mapped/unmapped
860  * in a single request.
861  */
862 #define BASE_EXT_RES_COUNT_MAX 10
863
864 /**
865  * struct base_external_resource_list - Structure which describes a list of
866  *                                      external resources.
867  * @count:                              The number of resources.
868  * @ext_res:                            Array of external resources which is
869  *                                      sized at allocation time.
870  */
871 struct base_external_resource_list {
872         u64 count;
873         struct base_external_resource ext_res[1];
874 };
875
876 struct base_jd_debug_copy_buffer {
877         u64 address;
878         u64 size;
879         struct base_external_resource extres;
880 };
881
882 /**
883  * @brief Setter for a dependency structure
884  *
885  * @param[in] dep          The kbase jd atom dependency to be initialized.
886  * @param     id           The atom_id to be assigned.
887  * @param     dep_type     The dep_type to be assigned.
888  *
889  */
890 static inline void base_jd_atom_dep_set(struct base_dependency *dep,
891                 base_atom_id id, base_jd_dep_type dep_type)
892 {
893         LOCAL_ASSERT(dep != NULL);
894
895         /*
896          * make sure we don't set not allowed combinations
897          * of atom_id/dependency_type.
898          */
899         LOCAL_ASSERT((id == 0 && dep_type == BASE_JD_DEP_TYPE_INVALID) ||
900                         (id > 0 && dep_type != BASE_JD_DEP_TYPE_INVALID));
901
902         dep->atom_id = id;
903         dep->dependency_type = dep_type;
904 }
905
906 /**
907  * @brief Make a copy of a dependency structure
908  *
909  * @param[in,out] dep          The kbase jd atom dependency to be written.
910  * @param[in]     from         The dependency to make a copy from.
911  *
912  */
913 static inline void base_jd_atom_dep_copy(struct base_dependency *dep,
914                 const struct base_dependency *from)
915 {
916         LOCAL_ASSERT(dep != NULL);
917
918         base_jd_atom_dep_set(dep, from->atom_id, from->dependency_type);
919 }
920
921 /**
922  * @brief Soft-atom fence trigger setup.
923  *
924  * Sets up an atom to be a SW-only atom signaling a fence
925  * when it reaches the run state.
926  *
927  * Using the existing base dependency system the fence can
928  * be set to trigger when a GPU job has finished.
929  *
930  * The base fence object must not be terminated until the atom
931  * has been submitted to @a base_jd_submit_bag and @a base_jd_submit_bag has returned.
932  *
933  * @a fence must be a valid fence set up with @a base_fence_init.
934  * Calling this function with a uninitialized fence results in undefined behavior.
935  *
936  * @param[out] atom A pre-allocated atom to configure as a fence trigger SW atom
937  * @param[in] fence The base fence object to trigger.
938  */
939 static inline void base_jd_fence_trigger_setup_v2(struct base_jd_atom_v2 *atom, struct base_fence *fence)
940 {
941         LOCAL_ASSERT(atom);
942         LOCAL_ASSERT(fence);
943         LOCAL_ASSERT(fence->basep.fd == INVALID_PLATFORM_FENCE);
944         LOCAL_ASSERT(fence->basep.stream_fd >= 0);
945         atom->jc = (uintptr_t) fence;
946         atom->core_req = BASE_JD_REQ_SOFT_FENCE_TRIGGER;
947 }
948
949 /**
950  * @brief Soft-atom fence wait setup.
951  *
952  * Sets up an atom to be a SW-only atom waiting on a fence.
953  * When the fence becomes triggered the atom becomes runnable
954  * and completes immediately.
955  *
956  * Using the existing base dependency system the fence can
957  * be set to block a GPU job until it has been triggered.
958  *
959  * The base fence object must not be terminated until the atom
960  * has been submitted to @a base_jd_submit_bag and @a base_jd_submit_bag has returned.
961  *
962  * @a fence must be a valid fence set up with @a base_fence_init or @a base_fence_import.
963  * Calling this function with a uninitialized fence results in undefined behavior.
964  *
965  * @param[out] atom A pre-allocated atom to configure as a fence wait SW atom
966  * @param[in] fence The base fence object to wait on
967  */
968 static inline void base_jd_fence_wait_setup_v2(struct base_jd_atom_v2 *atom, struct base_fence *fence)
969 {
970         LOCAL_ASSERT(atom);
971         LOCAL_ASSERT(fence);
972         LOCAL_ASSERT(fence->basep.fd >= 0);
973         atom->jc = (uintptr_t) fence;
974         atom->core_req = BASE_JD_REQ_SOFT_FENCE_WAIT;
975 }
976
977 /**
978  * @brief External resource info initialization.
979  *
980  * Sets up an external resource object to reference
981  * a memory allocation and the type of access requested.
982  *
983  * @param[in] res     The resource object to initialize
984  * @param     handle  The handle to the imported memory object, must be
985  *                    obtained by calling @ref base_mem_as_import_handle().
986  * @param     access  The type of access requested
987  */
988 static inline void base_external_resource_init(struct base_external_resource *res, struct base_import_handle handle, base_external_resource_access access)
989 {
990         u64 address;
991
992         address = handle.basep.handle;
993
994         LOCAL_ASSERT(res != NULL);
995         LOCAL_ASSERT(0 == (address & LOCAL_PAGE_LSB));
996         LOCAL_ASSERT(access == BASE_EXT_RES_ACCESS_SHARED || access == BASE_EXT_RES_ACCESS_EXCLUSIVE);
997
998         res->ext_resource = address | (access & LOCAL_PAGE_LSB);
999 }
1000
1001 /**
1002  * @brief Job chain event code bits
1003  * Defines the bits used to create ::base_jd_event_code
1004  */
1005 enum {
1006         BASE_JD_SW_EVENT_KERNEL = (1u << 15), /**< Kernel side event */
1007         BASE_JD_SW_EVENT = (1u << 14), /**< SW defined event */
1008         BASE_JD_SW_EVENT_SUCCESS = (1u << 13), /**< Event idicates success (SW events only) */
1009         BASE_JD_SW_EVENT_JOB = (0u << 11), /**< Job related event */
1010         BASE_JD_SW_EVENT_BAG = (1u << 11), /**< Bag related event */
1011         BASE_JD_SW_EVENT_INFO = (2u << 11), /**< Misc/info event */
1012         BASE_JD_SW_EVENT_RESERVED = (3u << 11), /**< Reserved event type */
1013         BASE_JD_SW_EVENT_TYPE_MASK = (3u << 11)     /**< Mask to extract the type from an event code */
1014 };
1015
1016 /**
1017  * @brief Job chain event codes
1018  *
1019  * HW and low-level SW events are represented by event codes.
1020  * The status of jobs which succeeded are also represented by
1021  * an event code (see ::BASE_JD_EVENT_DONE).
1022  * Events are usually reported as part of a ::base_jd_event.
1023  *
1024  * The event codes are encoded in the following way:
1025  * @li 10:0  - subtype
1026  * @li 12:11 - type
1027  * @li 13    - SW success (only valid if the SW bit is set)
1028  * @li 14    - SW event (HW event if not set)
1029  * @li 15    - Kernel event (should never be seen in userspace)
1030  *
1031  * Events are split up into ranges as follows:
1032  * - BASE_JD_EVENT_RANGE_\<description\>_START
1033  * - BASE_JD_EVENT_RANGE_\<description\>_END
1034  *
1035  * \a code is in \<description\>'s range when:
1036  * - <tt>BASE_JD_EVENT_RANGE_\<description\>_START <= code < BASE_JD_EVENT_RANGE_\<description\>_END </tt>
1037  *
1038  * Ranges can be asserted for adjacency by testing that the END of the previous
1039  * is equal to the START of the next. This is useful for optimizing some tests
1040  * for range.
1041  *
1042  * A limitation is that the last member of this enum must explicitly be handled
1043  * (with an assert-unreachable statement) in switch statements that use
1044  * variables of this type. Otherwise, the compiler warns that we have not
1045  * handled that enum value.
1046  */
1047 typedef enum base_jd_event_code {
1048         /* HW defined exceptions */
1049
1050         /** Start of HW Non-fault status codes
1051          *
1052          * @note Obscurely, BASE_JD_EVENT_TERMINATED indicates a real fault,
1053          * because the job was hard-stopped
1054          */
1055         BASE_JD_EVENT_RANGE_HW_NONFAULT_START = 0,
1056
1057         /* non-fatal exceptions */
1058         BASE_JD_EVENT_NOT_STARTED = 0x00, /**< Can't be seen by userspace, treated as 'previous job done' */
1059         BASE_JD_EVENT_DONE = 0x01,
1060         BASE_JD_EVENT_STOPPED = 0x03,     /**< Can't be seen by userspace, becomes TERMINATED, DONE or JOB_CANCELLED */
1061         BASE_JD_EVENT_TERMINATED = 0x04,  /**< This is actually a fault status code - the job was hard stopped */
1062         BASE_JD_EVENT_ACTIVE = 0x08,      /**< Can't be seen by userspace, jobs only returned on complete/fail/cancel */
1063
1064         /** End of HW Non-fault status codes
1065          *
1066          * @note Obscurely, BASE_JD_EVENT_TERMINATED indicates a real fault,
1067          * because the job was hard-stopped
1068          */
1069         BASE_JD_EVENT_RANGE_HW_NONFAULT_END = 0x40,
1070
1071         /** Start of HW fault and SW Error status codes */
1072         BASE_JD_EVENT_RANGE_HW_FAULT_OR_SW_ERROR_START = 0x40,
1073
1074         /* job exceptions */
1075         BASE_JD_EVENT_JOB_CONFIG_FAULT = 0x40,
1076         BASE_JD_EVENT_JOB_POWER_FAULT = 0x41,
1077         BASE_JD_EVENT_JOB_READ_FAULT = 0x42,
1078         BASE_JD_EVENT_JOB_WRITE_FAULT = 0x43,
1079         BASE_JD_EVENT_JOB_AFFINITY_FAULT = 0x44,
1080         BASE_JD_EVENT_JOB_BUS_FAULT = 0x48,
1081         BASE_JD_EVENT_INSTR_INVALID_PC = 0x50,
1082         BASE_JD_EVENT_INSTR_INVALID_ENC = 0x51,
1083         BASE_JD_EVENT_INSTR_TYPE_MISMATCH = 0x52,
1084         BASE_JD_EVENT_INSTR_OPERAND_FAULT = 0x53,
1085         BASE_JD_EVENT_INSTR_TLS_FAULT = 0x54,
1086         BASE_JD_EVENT_INSTR_BARRIER_FAULT = 0x55,
1087         BASE_JD_EVENT_INSTR_ALIGN_FAULT = 0x56,
1088         BASE_JD_EVENT_DATA_INVALID_FAULT = 0x58,
1089         BASE_JD_EVENT_TILE_RANGE_FAULT = 0x59,
1090         BASE_JD_EVENT_STATE_FAULT = 0x5A,
1091         BASE_JD_EVENT_OUT_OF_MEMORY = 0x60,
1092         BASE_JD_EVENT_UNKNOWN = 0x7F,
1093
1094         /* GPU exceptions */
1095         BASE_JD_EVENT_DELAYED_BUS_FAULT = 0x80,
1096         BASE_JD_EVENT_SHAREABILITY_FAULT = 0x88,
1097
1098         /* MMU exceptions */
1099         BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL1 = 0xC1,
1100         BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL2 = 0xC2,
1101         BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL3 = 0xC3,
1102         BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL4 = 0xC4,
1103         BASE_JD_EVENT_PERMISSION_FAULT = 0xC8,
1104         BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL1 = 0xD1,
1105         BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL2 = 0xD2,
1106         BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL3 = 0xD3,
1107         BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL4 = 0xD4,
1108         BASE_JD_EVENT_ACCESS_FLAG = 0xD8,
1109
1110         /* SW defined exceptions */
1111         BASE_JD_EVENT_MEM_GROWTH_FAILED = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x000,
1112         BASE_JD_EVENT_TIMED_OUT         = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x001,
1113         BASE_JD_EVENT_JOB_CANCELLED     = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x002,
1114         BASE_JD_EVENT_JOB_INVALID       = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x003,
1115         BASE_JD_EVENT_PM_EVENT          = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x004,
1116         BASE_JD_EVENT_FORCE_REPLAY      = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x005,
1117
1118         BASE_JD_EVENT_BAG_INVALID       = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_BAG | 0x003,
1119
1120         /** End of HW fault and SW Error status codes */
1121         BASE_JD_EVENT_RANGE_HW_FAULT_OR_SW_ERROR_END = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_RESERVED | 0x3FF,
1122
1123         /** Start of SW Success status codes */
1124         BASE_JD_EVENT_RANGE_SW_SUCCESS_START = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | 0x000,
1125
1126         BASE_JD_EVENT_PROGRESS_REPORT = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_JOB | 0x000,
1127         BASE_JD_EVENT_BAG_DONE = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_BAG | 0x000,
1128         BASE_JD_EVENT_DRV_TERMINATED = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_INFO | 0x000,
1129
1130         /** End of SW Success status codes */
1131         BASE_JD_EVENT_RANGE_SW_SUCCESS_END = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_RESERVED | 0x3FF,
1132
1133         /** Start of Kernel-only status codes. Such codes are never returned to user-space */
1134         BASE_JD_EVENT_RANGE_KERNEL_ONLY_START = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_KERNEL | 0x000,
1135         BASE_JD_EVENT_REMOVED_FROM_NEXT = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_KERNEL | BASE_JD_SW_EVENT_JOB | 0x000,
1136
1137         /** End of Kernel-only status codes. */
1138         BASE_JD_EVENT_RANGE_KERNEL_ONLY_END = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_KERNEL | BASE_JD_SW_EVENT_RESERVED | 0x3FF
1139 } base_jd_event_code;
1140
1141 /**
1142  * @brief Event reporting structure
1143  *
1144  * This structure is used by the kernel driver to report information
1145  * about GPU events. The can either be HW-specific events or low-level
1146  * SW events, such as job-chain completion.
1147  *
1148  * The event code contains an event type field which can be extracted
1149  * by ANDing with ::BASE_JD_SW_EVENT_TYPE_MASK.
1150  *
1151  * Based on the event type base_jd_event::data holds:
1152  * @li ::BASE_JD_SW_EVENT_JOB : the offset in the ring-buffer for the completed
1153  * job-chain
1154  * @li ::BASE_JD_SW_EVENT_BAG : The address of the ::base_jd_bag that has
1155  * been completed (ie all contained job-chains have been completed).
1156  * @li ::BASE_JD_SW_EVENT_INFO : base_jd_event::data not used
1157  */
1158 typedef struct base_jd_event_v2 {
1159         base_jd_event_code event_code;  /**< event code */
1160         base_atom_id atom_number;       /**< the atom number that has completed */
1161         struct base_jd_udata udata;     /**< user data */
1162 } base_jd_event_v2;
1163
1164 /**
1165  * Padding required to ensure that the @ref struct base_dump_cpu_gpu_counters structure fills
1166  * a full cache line.
1167  */
1168
1169 #define BASE_CPU_GPU_CACHE_LINE_PADDING (36)
1170
1171
1172 /**
1173  * @brief Structure for BASE_JD_REQ_SOFT_DUMP_CPU_GPU_COUNTERS jobs.
1174  *
1175  * This structure is stored into the memory pointed to by the @c jc field of @ref base_jd_atom.
1176  *
1177  * This structure must be padded to ensure that it will occupy whole cache lines. This is to avoid
1178  * cases where access to pages containing the structure is shared between cached and un-cached
1179  * memory regions, which would cause memory corruption.  Here we set the structure size to be 64 bytes
1180  * which is the cache line for ARM A15 processors.
1181  */
1182
1183 typedef struct base_dump_cpu_gpu_counters {
1184         u64 system_time;
1185         u64 cycle_counter;
1186         u64 sec;
1187         u32 usec;
1188         u8 padding[BASE_CPU_GPU_CACHE_LINE_PADDING];
1189 } base_dump_cpu_gpu_counters;
1190
1191
1192
1193 /** @} end group base_user_api_job_dispatch */
1194
1195 #define GPU_MAX_JOB_SLOTS 16
1196
1197 /**
1198  * @page page_base_user_api_gpuprops User-side Base GPU Property Query API
1199  *
1200  * The User-side Base GPU Property Query API encapsulates two
1201  * sub-modules:
1202  *
1203  * - @ref base_user_api_gpuprops_dyn "Dynamic GPU Properties"
1204  * - @ref base_plat_config_gpuprops "Base Platform Config GPU Properties"
1205  *
1206  * There is a related third module outside of Base, which is owned by the MIDG
1207  * module:
1208  * - @ref gpu_props_static "Midgard Compile-time GPU Properties"
1209  *
1210  * Base only deals with properties that vary between different Midgard
1211  * implementations - the Dynamic GPU properties and the Platform Config
1212  * properties.
1213  *
1214  * For properties that are constant for the Midgard Architecture, refer to the
1215  * MIDG module. However, we will discuss their relevance here <b>just to
1216  * provide background information.</b>
1217  *
1218  * @section sec_base_user_api_gpuprops_about About the GPU Properties in Base and MIDG modules
1219  *
1220  * The compile-time properties (Platform Config, Midgard Compile-time
1221  * properties) are exposed as pre-processor macros.
1222  *
1223  * Complementing the compile-time properties are the Dynamic GPU
1224  * Properties, which act as a conduit for the Midgard Configuration
1225  * Discovery.
1226  *
1227  * In general, the dynamic properties are present to verify that the platform
1228  * has been configured correctly with the right set of Platform Config
1229  * Compile-time Properties.
1230  *
1231  * As a consistant guide across the entire DDK, the choice for dynamic or
1232  * compile-time should consider the following, in order:
1233  * -# Can the code be written so that it doesn't need to know the
1234  * implementation limits at all?
1235  * -# If you need the limits, get the information from the Dynamic Property
1236  * lookup. This should be done once as you fetch the context, and then cached
1237  * as part of the context data structure, so it's cheap to access.
1238  * -# If there's a clear and arguable inefficiency in using Dynamic Properties,
1239  * then use a Compile-Time Property (Platform Config, or Midgard Compile-time
1240  * property). Examples of where this might be sensible follow:
1241  *  - Part of a critical inner-loop
1242  *  - Frequent re-use throughout the driver, causing significant extra load
1243  * instructions or control flow that would be worthwhile optimizing out.
1244  *
1245  * We cannot provide an exhaustive set of examples, neither can we provide a
1246  * rule for every possible situation. Use common sense, and think about: what
1247  * the rest of the driver will be doing; how the compiler might represent the
1248  * value if it is a compile-time constant; whether an OEM shipping multiple
1249  * devices would benefit much more from a single DDK binary, instead of
1250  * insignificant micro-optimizations.
1251  *
1252  * @section sec_base_user_api_gpuprops_dyn Dynamic GPU Properties
1253  *
1254  * Dynamic GPU properties are presented in two sets:
1255  * -# the commonly used properties in @ref base_gpu_props, which have been
1256  * unpacked from GPU register bitfields.
1257  * -# The full set of raw, unprocessed properties in @ref gpu_raw_gpu_props
1258  * (also a member of @ref base_gpu_props). All of these are presented in
1259  * the packed form, as presented by the GPU  registers themselves.
1260  *
1261  * @usecase The raw properties in @ref gpu_raw_gpu_props are necessary to
1262  * allow a user of the Mali Tools (e.g. PAT) to determine "Why is this device
1263  * behaving differently?". In this case, all information about the
1264  * configuration is potentially useful, but it <b>does not need to be processed
1265  * by the driver</b>. Instead, the raw registers can be processed by the Mali
1266  * Tools software on the host PC.
1267  *
1268  * The properties returned extend the Midgard Configuration Discovery
1269  * registers. For example, GPU clock speed is not specified in the Midgard
1270  * Architecture, but is <b>necessary for OpenCL's clGetDeviceInfo() function</b>.
1271  *
1272  * The GPU properties are obtained by a call to
1273  * _mali_base_get_gpu_props(). This simply returns a pointer to a const
1274  * base_gpu_props structure. It is constant for the life of a base
1275  * context. Multiple calls to _mali_base_get_gpu_props() to a base context
1276  * return the same pointer to a constant structure. This avoids cache pollution
1277  * of the common data.
1278  *
1279  * This pointer must not be freed, because it does not point to the start of a
1280  * region allocated by the memory allocator; instead, just close the @ref
1281  * base_context.
1282  *
1283  *
1284  * @section sec_base_user_api_gpuprops_config Platform Config Compile-time Properties
1285  *
1286  * The Platform Config File sets up gpu properties that are specific to a
1287  * certain platform. Properties that are 'Implementation Defined' in the
1288  * Midgard Architecture spec are placed here.
1289  *
1290  * @note Reference configurations are provided for Midgard Implementations, such as
1291  * the Mali-T600 family. The customer need not repeat this information, and can select one of
1292  * these reference configurations. For example, VA_BITS, PA_BITS and the
1293  * maximum number of samples per pixel might vary between Midgard Implementations, but
1294  * \b not for platforms using the Mali-T604. This information is placed in
1295  * the reference configuration files.
1296  *
1297  * The System Integrator creates the following structure:
1298  * - platform_XYZ
1299  * - platform_XYZ/plat
1300  * - platform_XYZ/plat/plat_config.h
1301  *
1302  * They then edit plat_config.h, using the example plat_config.h files as a
1303  * guide.
1304  *
1305  * At the very least, the customer must set @ref CONFIG_GPU_CORE_TYPE, and will
1306  * receive a helpful \#error message if they do not do this correctly. This
1307  * selects the Reference Configuration for the Midgard Implementation. The rationale
1308  * behind this decision (against asking the customer to write \#include
1309  * <gpus/mali_t600.h> in their plat_config.h) is as follows:
1310  * - This mechanism 'looks' like a regular config file (such as Linux's
1311  * .config)
1312  * - It is difficult to get wrong in a way that will produce strange build
1313  * errors:
1314  *  - They need not know where the mali_t600.h, other_midg_gpu.h etc. files are stored - and
1315  *  so they won't accidentally pick another file with 'mali_t600' in its name
1316  *  - When the build doesn't work, the System Integrator may think the DDK is
1317  *  doesn't work, and attempt to fix it themselves:
1318  *   - For the @ref CONFIG_GPU_CORE_TYPE mechanism, the only way to get past the
1319  *   error is to set @ref CONFIG_GPU_CORE_TYPE, and this is what the \#error tells
1320  *   you.
1321  *   - For a \#include mechanism, checks must still be made elsewhere, which the
1322  *   System Integrator may try working around by setting \#defines (such as
1323  *   VA_BITS) themselves in their plat_config.h. In the  worst case, they may
1324  *   set the prevention-mechanism \#define of
1325  *   "A_CORRECT_MIDGARD_CORE_WAS_CHOSEN".
1326  *   - In this case, they would believe they are on the right track, because
1327  *   the build progresses with their fix, but with errors elsewhere.
1328  *
1329  * However, there is nothing to prevent the customer using \#include to organize
1330  * their own configurations files hierarchically.
1331  *
1332  * The mechanism for the header file processing is as follows:
1333  *
1334  * @dot
1335    digraph plat_config_mechanism {
1336            rankdir=BT
1337            size="6,6"
1338
1339        "mali_base.h";
1340            "gpu/mali_gpu.h";
1341
1342            node [ shape=box ];
1343            {
1344                rank = same; ordering = out;
1345
1346                    "gpu/mali_gpu_props.h";
1347                    "base/midg_gpus/mali_t600.h";
1348                    "base/midg_gpus/other_midg_gpu.h";
1349            }
1350            { rank = same; "plat/plat_config.h"; }
1351            {
1352                rank = same;
1353                    "gpu/mali_gpu.h" [ shape=box ];
1354                    gpu_chooser [ label="" style="invisible" width=0 height=0 fixedsize=true ];
1355                    select_gpu [ label="Mali-T600 | Other\n(select_gpu.h)" shape=polygon,sides=4,distortion=0.25 width=3.3 height=0.99 fixedsize=true ] ;
1356            }
1357            node [ shape=box ];
1358            { rank = same; "plat/plat_config.h"; }
1359            { rank = same; "mali_base.h"; }
1360
1361            "mali_base.h" -> "gpu/mali_gpu.h" -> "gpu/mali_gpu_props.h";
1362            "mali_base.h" -> "plat/plat_config.h" ;
1363            "mali_base.h" -> select_gpu ;
1364
1365            "plat/plat_config.h" -> gpu_chooser [style="dotted,bold" dir=none weight=4] ;
1366            gpu_chooser -> select_gpu [style="dotted,bold"] ;
1367
1368            select_gpu -> "base/midg_gpus/mali_t600.h" ;
1369            select_gpu -> "base/midg_gpus/other_midg_gpu.h" ;
1370    }
1371    @enddot
1372  *
1373  *
1374  * @section sec_base_user_api_gpuprops_kernel Kernel Operation
1375  *
1376  * During Base Context Create time, user-side makes a single kernel call:
1377  * - A call to fill user memory with GPU information structures
1378  *
1379  * The kernel-side will fill the provided the entire processed @ref base_gpu_props
1380  * structure, because this information is required in both
1381  * user and kernel side; it does not make sense to decode it twice.
1382  *
1383  * Coherency groups must be derived from the bitmasks, but this can be done
1384  * kernel side, and just once at kernel startup: Coherency groups must already
1385  * be known kernel-side, to support chains that specify a 'Only Coherent Group'
1386  * SW requirement, or 'Only Coherent Group with Tiler' SW requirement.
1387  *
1388  * @section sec_base_user_api_gpuprops_cocalc Coherency Group calculation
1389  * Creation of the coherent group data is done at device-driver startup, and so
1390  * is one-time. This will most likely involve a loop with CLZ, shifting, and
1391  * bit clearing on the L2_PRESENT mask, depending on whether the
1392  * system is L2 Coherent. The number of shader cores is done by a
1393  * population count, since faulty cores may be disabled during production,
1394  * producing a non-contiguous mask.
1395  *
1396  * The memory requirements for this algoirthm can be determined either by a u64
1397  * population count on the L2_PRESENT mask (a LUT helper already is
1398  * requried for the above), or simple assumption that there can be no more than
1399  * 16 coherent groups, since core groups are typically 4 cores.
1400  */
1401
1402 /**
1403  * @addtogroup base_user_api_gpuprops User-side Base GPU Property Query APIs
1404  * @{
1405  */
1406
1407 /**
1408  * @addtogroup base_user_api_gpuprops_dyn Dynamic HW Properties
1409  * @{
1410  */
1411
1412 #define BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3
1413
1414 #define BASE_MAX_COHERENT_GROUPS 16
1415
1416 struct mali_base_gpu_core_props {
1417         /**
1418          * Product specific value.
1419          */
1420         u32 product_id;
1421
1422         /**
1423          * Status of the GPU release.
1424      * No defined values, but starts at 0 and increases by one for each release
1425      * status (alpha, beta, EAC, etc.).
1426      * 4 bit values (0-15).
1427          */
1428         u16 version_status;
1429
1430         /**
1431          * Minor release number of the GPU. "P" part of an "RnPn" release number.
1432      * 8 bit values (0-255).
1433          */
1434         u16 minor_revision;
1435
1436         /**
1437          * Major release number of the GPU. "R" part of an "RnPn" release number.
1438      * 4 bit values (0-15).
1439          */
1440         u16 major_revision;
1441
1442         u16 padding;
1443
1444         /**
1445          * @usecase GPU clock speed is not specified in the Midgard Architecture, but is
1446          * <b>necessary for OpenCL's clGetDeviceInfo() function</b>.
1447          */
1448         u32 gpu_speed_mhz;
1449
1450         /**
1451          * @usecase GPU clock max/min speed is required for computing best/worst case
1452          * in tasks as job scheduling ant irq_throttling. (It is not specified in the
1453          *  Midgard Architecture).
1454          */
1455         u32 gpu_freq_khz_max;
1456         u32 gpu_freq_khz_min;
1457
1458         /**
1459          * Size of the shader program counter, in bits.
1460          */
1461         u32 log2_program_counter_size;
1462
1463         /**
1464          * TEXTURE_FEATURES_x registers, as exposed by the GPU. This is a
1465          * bitpattern where a set bit indicates that the format is supported.
1466          *
1467          * Before using a texture format, it is recommended that the corresponding
1468          * bit be checked.
1469          */
1470         u32 texture_features[BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS];
1471
1472         /**
1473          * Theoretical maximum memory available to the GPU. It is unlikely that a
1474          * client will be able to allocate all of this memory for their own
1475          * purposes, but this at least provides an upper bound on the memory
1476          * available to the GPU.
1477          *
1478          * This is required for OpenCL's clGetDeviceInfo() call when
1479          * CL_DEVICE_GLOBAL_MEM_SIZE is requested, for OpenCL GPU devices. The
1480          * client will not be expecting to allocate anywhere near this value.
1481          */
1482         u64 gpu_available_memory_size;
1483 };
1484
1485 /**
1486  *
1487  * More information is possible - but associativity and bus width are not
1488  * required by upper-level apis.
1489  */
1490 struct mali_base_gpu_l2_cache_props {
1491         u8 log2_line_size;
1492         u8 log2_cache_size;
1493         u8 num_l2_slices; /* Number of L2C slices. 1 or higher */
1494         u8 padding[5];
1495 };
1496
1497 struct mali_base_gpu_tiler_props {
1498         u32 bin_size_bytes;     /* Max is 4*2^15 */
1499         u32 max_active_levels;  /* Max is 2^15 */
1500 };
1501
1502 /**
1503  * GPU threading system details.
1504  */
1505 struct mali_base_gpu_thread_props {
1506         u32 max_threads;            /* Max. number of threads per core */
1507         u32 max_workgroup_size;     /* Max. number of threads per workgroup */
1508         u32 max_barrier_size;       /* Max. number of threads that can synchronize on a simple barrier */
1509         u16 max_registers;          /* Total size [1..65535] of the register file available per core. */
1510         u8  max_task_queue;         /* Max. tasks [1..255] which may be sent to a core before it becomes blocked. */
1511         u8  max_thread_group_split; /* Max. allowed value [1..15] of the Thread Group Split field. */
1512         u8  impl_tech;              /* 0 = Not specified, 1 = Silicon, 2 = FPGA, 3 = SW Model/Emulation */
1513         u8  padding[7];
1514 };
1515
1516 /**
1517  * @brief descriptor for a coherent group
1518  *
1519  * \c core_mask exposes all cores in that coherent group, and \c num_cores
1520  * provides a cached population-count for that mask.
1521  *
1522  * @note Whilst all cores are exposed in the mask, not all may be available to
1523  * the application, depending on the Kernel Power policy.
1524  *
1525  * @note if u64s must be 8-byte aligned, then this structure has 32-bits of wastage.
1526  */
1527 struct mali_base_gpu_coherent_group {
1528         u64 core_mask;         /**< Core restriction mask required for the group */
1529         u16 num_cores;         /**< Number of cores in the group */
1530         u16 padding[3];
1531 };
1532
1533 /**
1534  * @brief Coherency group information
1535  *
1536  * Note that the sizes of the members could be reduced. However, the \c group
1537  * member might be 8-byte aligned to ensure the u64 core_mask is 8-byte
1538  * aligned, thus leading to wastage if the other members sizes were reduced.
1539  *
1540  * The groups are sorted by core mask. The core masks are non-repeating and do
1541  * not intersect.
1542  */
1543 struct mali_base_gpu_coherent_group_info {
1544         u32 num_groups;
1545
1546         /**
1547          * Number of core groups (coherent or not) in the GPU. Equivalent to the number of L2 Caches.
1548          *
1549          * The GPU Counter dumping writes 2048 bytes per core group, regardless of
1550          * whether the core groups are coherent or not. Hence this member is needed
1551          * to calculate how much memory is required for dumping.
1552          *
1553          * @note Do not use it to work out how many valid elements are in the
1554          * group[] member. Use num_groups instead.
1555          */
1556         u32 num_core_groups;
1557
1558         /**
1559          * Coherency features of the memory, accessed by @ref gpu_mem_features
1560          * methods
1561          */
1562         u32 coherency;
1563
1564         u32 padding;
1565
1566         /**
1567          * Descriptors of coherent groups
1568          */
1569         struct mali_base_gpu_coherent_group group[BASE_MAX_COHERENT_GROUPS];
1570 };
1571
1572 /**
1573  * A complete description of the GPU's Hardware Configuration Discovery
1574  * registers.
1575  *
1576  * The information is presented inefficiently for access. For frequent access,
1577  * the values should be better expressed in an unpacked form in the
1578  * base_gpu_props structure.
1579  *
1580  * @usecase The raw properties in @ref gpu_raw_gpu_props are necessary to
1581  * allow a user of the Mali Tools (e.g. PAT) to determine "Why is this device
1582  * behaving differently?". In this case, all information about the
1583  * configuration is potentially useful, but it <b>does not need to be processed
1584  * by the driver</b>. Instead, the raw registers can be processed by the Mali
1585  * Tools software on the host PC.
1586  *
1587  */
1588 struct gpu_raw_gpu_props {
1589         u64 shader_present;
1590         u64 tiler_present;
1591         u64 l2_present;
1592         u64 unused_1; /* keep for backward compatibility */
1593
1594         u32 l2_features;
1595         u32 suspend_size; /* API 8.2+ */
1596         u32 mem_features;
1597         u32 mmu_features;
1598
1599         u32 as_present;
1600
1601         u32 js_present;
1602         u32 js_features[GPU_MAX_JOB_SLOTS];
1603         u32 tiler_features;
1604         u32 texture_features[3];
1605
1606         u32 gpu_id;
1607
1608         u32 thread_max_threads;
1609         u32 thread_max_workgroup_size;
1610         u32 thread_max_barrier_size;
1611         u32 thread_features;
1612
1613         /*
1614          * Note: This is the _selected_ coherency mode rather than the
1615          * available modes as exposed in the coherency_features register.
1616          */
1617         u32 coherency_mode;
1618 };
1619
1620 /**
1621  * Return structure for _mali_base_get_gpu_props().
1622  *
1623  * NOTE: the raw_props member in this datastructure contains the register
1624  * values from which the value of the other members are derived. The derived
1625  * members exist to allow for efficient access and/or shielding the details
1626  * of the layout of the registers.
1627  *
1628  */
1629 typedef struct mali_base_gpu_props {
1630         struct mali_base_gpu_core_props core_props;
1631         struct mali_base_gpu_l2_cache_props l2_props;
1632         u64 unused_1; /* keep for backwards compatibility */
1633         struct mali_base_gpu_tiler_props tiler_props;
1634         struct mali_base_gpu_thread_props thread_props;
1635
1636         /** This member is large, likely to be 128 bytes */
1637         struct gpu_raw_gpu_props raw_props;
1638
1639         /** This must be last member of the structure */
1640         struct mali_base_gpu_coherent_group_info coherency_info;
1641 } base_gpu_props;
1642
1643 /** @} end group base_user_api_gpuprops_dyn */
1644
1645 /** @} end group base_user_api_gpuprops */
1646
1647 /**
1648  * @addtogroup base_user_api_core User-side Base core APIs
1649  * @{
1650  */
1651
1652 /**
1653  * \enum base_context_create_flags
1654  *
1655  * Flags to pass to ::base_context_init.
1656  * Flags can be ORed together to enable multiple things.
1657  *
1658  * These share the same space as BASEP_CONTEXT_FLAG_*, and so must
1659  * not collide with them.
1660  */
1661 enum base_context_create_flags {
1662         /** No flags set */
1663         BASE_CONTEXT_CREATE_FLAG_NONE = 0,
1664
1665         /** Base context is embedded in a cctx object (flag used for CINSTR software counter macros) */
1666         BASE_CONTEXT_CCTX_EMBEDDED = (1u << 0),
1667
1668         /** Base context is a 'System Monitor' context for Hardware counters.
1669          *
1670          * One important side effect of this is that job submission is disabled. */
1671         BASE_CONTEXT_SYSTEM_MONITOR_SUBMIT_DISABLED = (1u << 1)
1672 };
1673
1674 /**
1675  * Bitpattern describing the ::base_context_create_flags that can be passed to base_context_init()
1676  */
1677 #define BASE_CONTEXT_CREATE_ALLOWED_FLAGS \
1678         (((u32)BASE_CONTEXT_CCTX_EMBEDDED) | \
1679           ((u32)BASE_CONTEXT_SYSTEM_MONITOR_SUBMIT_DISABLED))
1680
1681 /**
1682  * Bitpattern describing the ::base_context_create_flags that can be passed to the kernel
1683  */
1684 #define BASE_CONTEXT_CREATE_KERNEL_FLAGS \
1685         ((u32)BASE_CONTEXT_SYSTEM_MONITOR_SUBMIT_DISABLED)
1686
1687 /*
1688  * Private flags used on the base context
1689  *
1690  * These start at bit 31, and run down to zero.
1691  *
1692  * They share the same space as @ref base_context_create_flags, and so must
1693  * not collide with them.
1694  */
1695 /** Private flag tracking whether job descriptor dumping is disabled */
1696 #define BASEP_CONTEXT_FLAG_JOB_DUMP_DISABLED ((u32)(1 << 31))
1697
1698 /** @} end group base_user_api_core */
1699
1700 /** @} end group base_user_api */
1701
1702 /**
1703  * @addtogroup base_plat_config_gpuprops Base Platform Config GPU Properties
1704  * @{
1705  *
1706  * C Pre-processor macros are exposed here to do with Platform
1707  * Config.
1708  *
1709  * These include:
1710  * - GPU Properties that are constant on a particular Midgard Family
1711  * Implementation e.g. Maximum samples per pixel on Mali-T600.
1712  * - General platform config for the GPU, such as the GPU major and minor
1713  * revison.
1714  */
1715
1716 /** @} end group base_plat_config_gpuprops */
1717
1718 /**
1719  * @addtogroup base_api Base APIs
1720  * @{
1721  */
1722
1723 /**
1724  * @brief The payload for a replay job. This must be in GPU memory.
1725  */
1726 typedef struct base_jd_replay_payload {
1727         /**
1728          * Pointer to the first entry in the base_jd_replay_jc list.  These
1729          * will be replayed in @b reverse order (so that extra ones can be added
1730          * to the head in future soft jobs without affecting this soft job)
1731          */
1732         u64 tiler_jc_list;
1733
1734         /**
1735          * Pointer to the fragment job chain.
1736          */
1737         u64 fragment_jc;
1738
1739         /**
1740          * Pointer to the tiler heap free FBD field to be modified.
1741          */
1742         u64 tiler_heap_free;
1743
1744         /**
1745          * Hierarchy mask for the replayed fragment jobs. May be zero.
1746          */
1747         u16 fragment_hierarchy_mask;
1748
1749         /**
1750          * Hierarchy mask for the replayed tiler jobs. May be zero.
1751          */
1752         u16 tiler_hierarchy_mask;
1753
1754         /**
1755          * Default weight to be used for hierarchy levels not in the original
1756          * mask.
1757          */
1758         u32 hierarchy_default_weight;
1759
1760         /**
1761          * Core requirements for the tiler job chain
1762          */
1763         base_jd_core_req tiler_core_req;
1764
1765         /**
1766          * Core requirements for the fragment job chain
1767          */
1768         base_jd_core_req fragment_core_req;
1769 } base_jd_replay_payload;
1770
1771 #ifdef BASE_LEGACY_UK10_2_SUPPORT
1772 typedef struct base_jd_replay_payload_uk10_2 {
1773         u64 tiler_jc_list;
1774         u64 fragment_jc;
1775         u64 tiler_heap_free;
1776         u16 fragment_hierarchy_mask;
1777         u16 tiler_hierarchy_mask;
1778         u32 hierarchy_default_weight;
1779         u16 tiler_core_req;
1780         u16 fragment_core_req;
1781         u8 padding[4];
1782 } base_jd_replay_payload_uk10_2;
1783 #endif /* BASE_LEGACY_UK10_2_SUPPORT */
1784
1785 /**
1786  * @brief An entry in the linked list of job chains to be replayed. This must
1787  *        be in GPU memory.
1788  */
1789 typedef struct base_jd_replay_jc {
1790         /**
1791          * Pointer to next entry in the list. A setting of NULL indicates the
1792          * end of the list.
1793          */
1794         u64 next;
1795
1796         /**
1797          * Pointer to the job chain.
1798          */
1799         u64 jc;
1800
1801 } base_jd_replay_jc;
1802
1803 /* Maximum number of jobs allowed in a fragment chain in the payload of a
1804  * replay job */
1805 #define BASE_JD_REPLAY_F_CHAIN_JOB_LIMIT 256
1806
1807 /** @} end group base_api */
1808
1809 typedef struct base_profiling_controls {
1810         u32 profiling_controls[FBDUMP_CONTROL_MAX];
1811 } base_profiling_controls;
1812
1813 /* Enable additional tracepoints for latency measurements (TL_ATOM_READY,
1814  * TL_ATOM_DONE, TL_ATOM_PRIO_CHANGE, TL_ATOM_EVENT_POST) */
1815 #define BASE_TLSTREAM_ENABLE_LATENCY_TRACEPOINTS (1 << 0)
1816
1817 #define BASE_TLSTREAM_FLAGS_MASK (BASE_TLSTREAM_ENABLE_LATENCY_TRACEPOINTS)
1818
1819 #endif                          /* _BASE_KERNEL_H_ */