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