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