3 * (C) COPYRIGHT 2010-2015 ARM Limited. All rights reserved.
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
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.
22 * Base structures shared with the kernel.
25 #ifndef _BASE_KERNEL_H_
26 #define _BASE_KERNEL_H_
32 /* Support UK6 IOCTLS */
33 #define BASE_LEGACY_UK6_SUPPORT 1
35 /* Support UK7 IOCTLS */
36 /* NB: To support UK6 we also need to support UK7 */
37 #define BASE_LEGACY_UK7_SUPPORT 1
39 typedef u64 base_mem_handle;
41 #include "mali_base_mem_priv.h"
42 #include "mali_kbase_profiling_gator_api.h"
45 * Dependency stuff, keep it private for now. May want to expose it if
46 * we decide to make the number of semaphores a configurable
49 #define BASE_JD_ATOM_COUNT 256
51 #define BASEP_JD_SEM_PER_WORD_LOG2 5
52 #define BASEP_JD_SEM_PER_WORD (1 << BASEP_JD_SEM_PER_WORD_LOG2)
53 #define BASEP_JD_SEM_WORD_NR(x) ((x) >> BASEP_JD_SEM_PER_WORD_LOG2)
54 #define BASEP_JD_SEM_MASK_IN_WORD(x) (1 << ((x) & (BASEP_JD_SEM_PER_WORD - 1)))
55 #define BASEP_JD_SEM_ARRAY_SIZE BASEP_JD_SEM_WORD_NR(BASE_JD_ATOM_COUNT)
57 #define BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3
59 #define BASE_MAX_COHERENT_GROUPS 16
61 #if defined CDBG_ASSERT
62 #define LOCAL_ASSERT CDBG_ASSERT
63 #elif defined KBASE_DEBUG_ASSERT
64 #define LOCAL_ASSERT KBASE_DEBUG_ASSERT
66 #error assert macro not defined!
70 #define LOCAL_PAGE_LSB ~PAGE_MASK
72 #include <osu/mali_osu.h>
74 #if defined OSU_CONFIG_CPU_PAGE_SIZE_LOG2
75 #define LOCAL_PAGE_LSB ((1ul << OSU_CONFIG_CPU_PAGE_SIZE_LOG2) - 1)
77 #error Failed to find page size
81 /** 32/64-bit neutral way to represent pointers */
82 typedef union kbase_pointer {
83 void __user *value; /**< client should store their pointers here */
84 u32 compat_value; /**< 64-bit kernels should fetch value here when handling 32-bit clients */
85 u64 sizer; /**< Force 64-bit storage for all clients regardless */
89 * @addtogroup base_user_api User-side Base APIs
94 * @addtogroup base_user_api_memory User-side Base Memory APIs
99 * @brief Memory allocation, access/hint flags
101 * A combination of MEM_PROT/MEM_HINT flags must be passed to each allocator
102 * in order to determine the best cache policy. Some combinations are
103 * of course invalid (eg @c MEM_PROT_CPU_WR | @c MEM_HINT_CPU_RD),
104 * which defines a @a write-only region on the CPU side, which is
105 * heavily read by the CPU...
106 * Other flags are only meaningful to a particular allocator.
107 * More flags can be added to this list, as long as they don't clash
108 * (see ::BASE_MEM_FLAGS_NR_BITS for the number of the first free bit).
110 typedef u32 base_mem_alloc_flags;
113 * @brief Memory allocation, access/hint flags
115 * See ::base_mem_alloc_flags.
120 BASE_MEM_PROT_CPU_RD = (1U << 0), /**< Read access CPU side */
121 BASE_MEM_PROT_CPU_WR = (1U << 1), /**< Write access CPU side */
122 BASE_MEM_PROT_GPU_RD = (1U << 2), /**< Read access GPU side */
123 BASE_MEM_PROT_GPU_WR = (1U << 3), /**< Write access GPU side */
124 BASE_MEM_PROT_GPU_EX = (1U << 4), /**< Execute allowed on the GPU
127 /* BASE_MEM_HINT flags have been removed, but their values are reserved
128 * for backwards compatibility with older user-space drivers. The values
129 * can be re-used once support for r5p0 user-space drivers is removed,
130 * presumably in r7p0.
132 * RESERVED: (1U << 5)
133 * RESERVED: (1U << 6)
134 * RESERVED: (1U << 7)
135 * RESERVED: (1U << 8)
138 BASE_MEM_GROW_ON_GPF = (1U << 9), /**< Grow backing store on GPU
141 BASE_MEM_COHERENT_SYSTEM = (1U << 10), /**< Page coherence Outer
142 shareable, if available */
143 BASE_MEM_COHERENT_LOCAL = (1U << 11), /**< Page coherence Inner
145 BASE_MEM_CACHED_CPU = (1U << 12), /**< Should be cached on the
149 BASE_MEM_SAME_VA = (1U << 13), /**< Must have same VA on both the GPU
152 BASE_MEM_NEED_MMAP = (1U << 14), /**< Must call mmap to aquire a GPU
153 address for the alloc */
156 BASE_MEM_COHERENT_SYSTEM_REQUIRED = (1U << 15), /**< Page coherence
157 Outer shareable, required. */
158 BASE_MEM_SECURE = (1U << 16) /**< Secure memory */
163 * @brief Number of bits used as flags for base memory management
165 * Must be kept in sync with the ::base_mem_alloc_flags flags
167 #define BASE_MEM_FLAGS_NR_BITS 17
170 * A mask for all output bits, excluding IN/OUT bits.
172 #define BASE_MEM_FLAGS_OUTPUT_MASK BASE_MEM_NEED_MMAP
175 * A mask for all input bits, including IN/OUT bits.
177 #define BASE_MEM_FLAGS_INPUT_MASK \
178 (((1 << BASE_MEM_FLAGS_NR_BITS) - 1) & ~BASE_MEM_FLAGS_OUTPUT_MASK)
182 * @brief Memory types supported by @a base_mem_import
184 * Each type defines what the supported handle type is.
186 * If any new type is added here ARM must be contacted
187 * to allocate a numeric value for it.
188 * Do not just add a new type without synchronizing with ARM
189 * as future releases from ARM might include other new types
190 * which could clash with your custom types.
192 typedef enum base_mem_import_type {
193 BASE_MEM_IMPORT_TYPE_INVALID = 0,
194 /** UMP import. Handle type is ump_secure_id. */
195 BASE_MEM_IMPORT_TYPE_UMP = 1,
196 /** UMM import. Handle type is a file descriptor (int) */
197 BASE_MEM_IMPORT_TYPE_UMM = 2
198 } base_mem_import_type;
200 /* legacy API wrappers */
201 #define base_tmem_import_type base_mem_import_type
202 #define BASE_TMEM_IMPORT_TYPE_INVALID BASE_MEM_IMPORT_TYPE_INVALID
203 #define BASE_TMEM_IMPORT_TYPE_UMP BASE_MEM_IMPORT_TYPE_UMP
204 #define BASE_TMEM_IMPORT_TYPE_UMM BASE_MEM_IMPORT_TYPE_UMM
207 * @brief Invalid memory handle type.
208 * Return value from functions returning @a base_mem_handle on error.
210 #define BASE_MEM_INVALID_HANDLE (0ull << 12)
211 #define BASE_MEM_MMU_DUMP_HANDLE (1ull << 12)
212 #define BASE_MEM_TRACE_BUFFER_HANDLE (2ull << 12)
213 #define BASE_MEM_MAP_TRACKING_HANDLE (3ull << 12)
214 #define BASE_MEM_WRITE_ALLOC_PAGES_HANDLE (4ull << 12)
215 /* reserved handles ..-64<<PAGE_SHIFT> for future special handles */
216 #define BASE_MEM_COOKIE_BASE (64ul << 12)
217 #define BASE_MEM_FIRST_FREE_ADDRESS ((BITS_PER_LONG << 12) + \
218 BASE_MEM_COOKIE_BASE)
220 /* Bit mask of cookies used for for memory allocation setup */
221 #define KBASE_COOKIE_MASK ~1UL /* bit 0 is reserved */
225 * @brief Result codes of changing the size of the backing store allocated to a tmem region
227 typedef enum base_backing_threshold_status {
228 BASE_BACKING_THRESHOLD_OK = 0, /**< Resize successful */
229 BASE_BACKING_THRESHOLD_ERROR_NOT_GROWABLE = -1, /**< Not a growable tmem object */
230 BASE_BACKING_THRESHOLD_ERROR_OOM = -2, /**< Increase failed due to an out-of-memory condition */
231 BASE_BACKING_THRESHOLD_ERROR_MAPPED = -3, /**< Resize attempted on buffer while it was mapped, which is not permitted */
232 BASE_BACKING_THRESHOLD_ERROR_INVALID_ARGUMENTS = -4 /**< Invalid arguments (not tmem, illegal size request, etc.) */
233 } base_backing_threshold_status;
236 * @addtogroup base_user_api_memory_defered User-side Base Defered Memory Coherency APIs
241 * @brief a basic memory operation (sync-set).
243 * The content of this structure is private, and should only be used
246 typedef struct base_syncset {
247 struct basep_syncset basep_sset;
250 /** @} end group base_user_api_memory_defered */
253 * Handle to represent imported memory object.
254 * Simple opague handle to imported memory, can't be used
255 * with anything but base_external_resource_init to bind to an atom.
257 typedef struct base_import_handle {
261 } base_import_handle;
263 /** @} end group base_user_api_memory */
266 * @addtogroup base_user_api_job_dispatch User-side Base Job Dispatcher APIs
270 typedef int platform_fence_type;
271 #define INVALID_PLATFORM_FENCE ((platform_fence_type)-1)
274 * Base stream handle.
276 * References an underlying base stream object.
278 typedef struct base_stream {
287 * References an underlying base fence object.
289 typedef struct base_fence {
297 * @brief Per-job data
299 * This structure is used to store per-job data, and is completly unused
300 * by the Base driver. It can be used to store things such as callback
301 * function pointer, data to handle job completion. It is guaranteed to be
302 * untouched by the Base driver.
304 typedef struct base_jd_udata {
305 u64 blob[2]; /**< per-job data array */
309 * @brief Memory aliasing info
311 * Describes a memory handle to be aliased.
312 * A subset of the handle can be chosen for aliasing, given an offset and a
314 * A special handle BASE_MEM_WRITE_ALLOC_PAGES_HANDLE is used to represent a
315 * region where a special page is mapped with a write-alloc cache setup,
316 * typically used when the write result of the GPU isn't needed, but the GPU
319 * Offset and length are specified in pages.
320 * Offset must be within the size of the handle.
321 * Offset+length must not overrun the size of the handle.
323 * @handle Handle to alias, can be BASE_MEM_WRITE_ALLOC_PAGES_HANDLE
324 * @offset Offset within the handle to start aliasing from, in pages.
325 * Not used with BASE_MEM_WRITE_ALLOC_PAGES_HANDLE.
326 * @length Length to alias, in pages. For BASE_MEM_WRITE_ALLOC_PAGES_HANDLE
327 * specifies the number of times the special page is needed.
329 struct base_mem_aliasing_info {
330 base_mem_handle handle;
336 * @brief Job dependency type.
338 * A flags field will be inserted into the atom structure to specify whether a dependency is a data or
339 * ordering dependency (by putting it before/after 'core_req' in the structure it should be possible to add without
340 * changing the structure size).
341 * When the flag is set for a particular dependency to signal that it is an ordering only dependency then
342 * errors will not be propagated.
344 typedef u8 base_jd_dep_type;
347 #define BASE_JD_DEP_TYPE_INVALID (0) /**< Invalid dependency */
348 #define BASE_JD_DEP_TYPE_DATA (1U << 0) /**< Data dependency */
349 #define BASE_JD_DEP_TYPE_ORDER (1U << 1) /**< Order dependency */
352 * @brief Job chain hardware requirements.
354 * A job chain must specify what GPU features it needs to allow the
355 * driver to schedule the job correctly. By not specifying the
356 * correct settings can/will cause an early job termination. Multiple
357 * values can be ORed together to specify multiple requirements.
358 * Special case is ::BASE_JD_REQ_DEP, which is used to express complex
359 * dependencies, and that doesn't execute anything on the hardware.
361 typedef u16 base_jd_core_req;
363 /* Requirements that come from the HW */
364 #define BASE_JD_REQ_DEP 0 /**< No requirement, dependency only */
365 #define BASE_JD_REQ_FS (1U << 0) /**< Requires fragment shaders */
367 * Requires compute shaders
368 * This covers any of the following Midgard Job types:
369 * - Vertex Shader Job
370 * - Geometry Shader Job
371 * - An actual Compute Shader Job
373 * Compare this with @ref BASE_JD_REQ_ONLY_COMPUTE, which specifies that the
374 * job is specifically just the "Compute Shader" job type, and not the "Vertex
375 * Shader" nor the "Geometry Shader" job type.
377 #define BASE_JD_REQ_CS (1U << 1)
378 #define BASE_JD_REQ_T (1U << 2) /**< Requires tiling */
379 #define BASE_JD_REQ_CF (1U << 3) /**< Requires cache flushes */
380 #define BASE_JD_REQ_V (1U << 4) /**< Requires value writeback */
382 /* SW-only requirements - the HW does not expose these as part of the job slot capabilities */
384 /* Requires fragment job with AFBC encoding */
385 #define BASE_JD_REQ_FS_AFBC (1U << 13)
388 * SW Only requirement: the job chain requires a coherent core group. We don't
389 * mind which coherent core group is used.
391 #define BASE_JD_REQ_COHERENT_GROUP (1U << 6)
394 * SW Only requirement: The performance counters should be enabled only when
395 * they are needed, to reduce power consumption.
398 #define BASE_JD_REQ_PERMON (1U << 7)
401 * SW Only requirement: External resources are referenced by this atom.
402 * When external resources are referenced no syncsets can be bundled with the atom
403 * but should instead be part of a NULL jobs inserted into the dependency tree.
404 * The first pre_dep object must be configured for the external resouces to use,
405 * the second pre_dep object can be used to create other dependencies.
407 #define BASE_JD_REQ_EXTERNAL_RESOURCES (1U << 8)
410 * SW Only requirement: Software defined job. Jobs with this bit set will not be submitted
411 * to the hardware but will cause some action to happen within the driver
413 #define BASE_JD_REQ_SOFT_JOB (1U << 9)
415 #define BASE_JD_REQ_SOFT_DUMP_CPU_GPU_TIME (BASE_JD_REQ_SOFT_JOB | 0x1)
416 #define BASE_JD_REQ_SOFT_FENCE_TRIGGER (BASE_JD_REQ_SOFT_JOB | 0x2)
417 #define BASE_JD_REQ_SOFT_FENCE_WAIT (BASE_JD_REQ_SOFT_JOB | 0x3)
420 * SW Only requirement : Replay job.
422 * If the preceeding job fails, the replay job will cause the jobs specified in
423 * the list of base_jd_replay_payload pointed to by the jc pointer to be
426 * A replay job will only cause jobs to be replayed up to BASEP_JD_REPLAY_LIMIT
427 * times. If a job fails more than BASEP_JD_REPLAY_LIMIT times then the replay
428 * job is failed, as well as any following dependencies.
430 * The replayed jobs will require a number of atom IDs. If there are not enough
431 * free atom IDs then the replay job will fail.
433 * If the preceeding job does not fail, then the replay job is returned as
436 * The replayed jobs will never be returned to userspace. The preceeding failed
437 * job will be returned to userspace as failed; the status of this job should
438 * be ignored. Completion should be determined by the status of the replay soft
441 * In order for the jobs to be replayed, the job headers will have to be
442 * modified. The Status field will be reset to NOT_STARTED. If the Job Type
443 * field indicates a Vertex Shader Job then it will be changed to Null Job.
445 * The replayed jobs have the following assumptions :
447 * - No external resources. Any required external resources will be held by the
449 * - Pre-dependencies are created based on job order.
450 * - Atom numbers are automatically assigned.
451 * - device_nr is set to 0. This is not relevant as
452 * BASE_JD_REQ_SPECIFIC_COHERENT_GROUP should not be set.
453 * - Priority is inherited from the replay job.
455 #define BASE_JD_REQ_SOFT_REPLAY (BASE_JD_REQ_SOFT_JOB | 0x4)
458 * HW Requirement: Requires Compute shaders (but not Vertex or Geometry Shaders)
460 * This indicates that the Job Chain contains Midgard Jobs of the 'Compute Shaders' type.
462 * In contrast to @ref BASE_JD_REQ_CS, this does \b not indicate that the Job
463 * Chain contains 'Geometry Shader' or 'Vertex Shader' jobs.
465 * @note This is a more flexible variant of the @ref BASE_CONTEXT_HINT_ONLY_COMPUTE flag,
466 * allowing specific jobs to be marked as 'Only Compute' instead of the entire context
468 #define BASE_JD_REQ_ONLY_COMPUTE (1U << 10)
471 * HW Requirement: Use the base_jd_atom::device_nr field to specify a
472 * particular core group
474 * If both BASE_JD_REQ_COHERENT_GROUP and this flag are set, this flag takes priority
476 * This is only guaranteed to work for BASE_JD_REQ_ONLY_COMPUTE atoms.
478 * If the core availability policy is keeping the required core group turned off, then
479 * the job will fail with a BASE_JD_EVENT_PM_EVENT error code.
481 #define BASE_JD_REQ_SPECIFIC_COHERENT_GROUP (1U << 11)
484 * SW Flag: If this bit is set then the successful completion of this atom
485 * will not cause an event to be sent to userspace
487 #define BASE_JD_REQ_EVENT_ONLY_ON_FAILURE (1U << 12)
490 * SW Flag: If this bit is set then completion of this atom will not cause an
491 * event to be sent to userspace, whether successful or not.
493 #define BASEP_JD_REQ_EVENT_NEVER (1U << 14)
496 * These requirement bits are currently unused in base_jd_core_req (currently a u16)
499 #define BASEP_JD_REQ_RESERVED_BIT5 (1U << 5)
500 #define BASEP_JD_REQ_RESERVED_BIT15 (1U << 15)
503 * Mask of all the currently unused requirement bits in base_jd_core_req.
506 #define BASEP_JD_REQ_RESERVED (BASEP_JD_REQ_RESERVED_BIT5 | \
507 BASEP_JD_REQ_RESERVED_BIT15)
510 * Mask of all bits in base_jd_core_req that control the type of the atom.
512 * This allows dependency only atoms to have flags set
514 #define BASEP_JD_REQ_ATOM_TYPE (~(BASEP_JD_REQ_RESERVED | BASE_JD_REQ_EVENT_ONLY_ON_FAILURE |\
515 BASE_JD_REQ_EXTERNAL_RESOURCES | BASEP_JD_REQ_EVENT_NEVER))
518 * @brief States to model state machine processed by kbasep_js_job_check_ref_cores(), which
519 * handles retaining cores for power management and affinity management.
521 * The state @ref KBASE_ATOM_COREREF_STATE_RECHECK_AFFINITY prevents an attack
522 * where lots of atoms could be submitted before powerup, and each has an
523 * affinity chosen that causes other atoms to have an affinity
524 * violation. Whilst the affinity was not causing violations at the time it
525 * was chosen, it could cause violations thereafter. For example, 1000 jobs
526 * could have had their affinity chosen during the powerup time, so any of
527 * those 1000 jobs could cause an affinity violation later on.
529 * The attack would otherwise occur because other atoms/contexts have to wait for:
530 * -# the currently running atoms (which are causing the violation) to
532 * -# and, the atoms that had their affinity chosen during powerup to
533 * finish. These are run preferrentially because they don't cause a
534 * violation, but instead continue to cause the violation in others.
535 * -# or, the attacker is scheduled out (which might not happen for just 2
538 * By re-choosing the affinity (which is designed to avoid violations at the
539 * time it's chosen), we break condition (2) of the wait, which minimizes the
540 * problem to just waiting for current jobs to finish (which can be bounded if
541 * the Job Scheduling Policy has a timer).
543 enum kbase_atom_coreref_state {
544 /** Starting state: No affinity chosen, and cores must be requested. kbase_jd_atom::affinity==0 */
545 KBASE_ATOM_COREREF_STATE_NO_CORES_REQUESTED,
546 /** Cores requested, but waiting for them to be powered. Requested cores given by kbase_jd_atom::affinity */
547 KBASE_ATOM_COREREF_STATE_WAITING_FOR_REQUESTED_CORES,
548 /** Cores given by kbase_jd_atom::affinity are powered, but affinity might be out-of-date, so must recheck */
549 KBASE_ATOM_COREREF_STATE_RECHECK_AFFINITY,
550 /** Cores given by kbase_jd_atom::affinity are powered, and affinity is up-to-date, but must check for violations */
551 KBASE_ATOM_COREREF_STATE_CHECK_AFFINITY_VIOLATIONS,
552 /** Cores are powered, kbase_jd_atom::affinity up-to-date, no affinity violations: atom can be submitted to HW */
553 KBASE_ATOM_COREREF_STATE_READY
559 * Only certain priority levels are actually implemented, as specified by the
560 * BASE_JD_PRIO_<...> definitions below. It is undefined to use a priority
561 * level that is not one of those defined below.
563 * Priority levels only affect scheduling between atoms of the same type within
564 * a base context, and only after the atoms have had dependencies resolved.
565 * Fragment atoms does not affect non-frament atoms with lower priorities, and
566 * the other way around. For example, a low priority atom that has had its
567 * dependencies resolved might run before a higher priority atom that has not
568 * had its dependencies resolved.
570 * The scheduling between base contexts/processes and between atoms from
571 * different base contexts/processes is unaffected by atom priority.
573 * The atoms are scheduled as follows with respect to their priorities:
574 * - Let atoms 'X' and 'Y' be for the same job slot who have dependencies
575 * resolved, and atom 'X' has a higher priority than atom 'Y'
576 * - If atom 'Y' is currently running on the HW, then it is interrupted to
577 * allow atom 'X' to run soon after
578 * - If instead neither atom 'Y' nor atom 'X' are running, then when choosing
579 * the next atom to run, atom 'X' will always be chosen instead of atom 'Y'
580 * - Any two atoms that have the same priority could run in any order with
581 * respect to each other. That is, there is no ordering constraint between
582 * atoms of the same priority.
584 typedef u8 base_jd_prio;
586 /* Medium atom priority. This is a priority higher than BASE_JD_PRIO_LOW */
587 #define BASE_JD_PRIO_MEDIUM ((base_jd_prio)0)
588 /* High atom priority. This is a priority higher than BASE_JD_PRIO_MEDIUM and
589 * BASE_JD_PRIO_LOW */
590 #define BASE_JD_PRIO_HIGH ((base_jd_prio)1)
591 /* Low atom priority. */
592 #define BASE_JD_PRIO_LOW ((base_jd_prio)2)
594 /* Count of the number of priority levels. This itself is not a valid
595 * base_jd_prio setting */
596 #define BASE_JD_NR_PRIO_LEVELS 3
598 enum kbase_jd_atom_state {
599 /** Atom is not used */
600 KBASE_JD_ATOM_STATE_UNUSED,
601 /** Atom is queued in JD */
602 KBASE_JD_ATOM_STATE_QUEUED,
603 /** Atom has been given to JS (is runnable/running) */
604 KBASE_JD_ATOM_STATE_IN_JS,
605 /** Atom has been completed, but not yet handed back to job dispatcher
606 * for dependency resolution */
607 KBASE_JD_ATOM_STATE_HW_COMPLETED,
608 /** Atom has been completed, but not yet handed back to userspace */
609 KBASE_JD_ATOM_STATE_COMPLETED
612 typedef u8 base_atom_id; /**< Type big enough to store an atom number in */
614 struct base_dependency {
615 base_atom_id atom_id; /**< An atom number */
616 base_jd_dep_type dependency_type; /**< Dependency type */
619 typedef struct base_jd_atom_v2 {
620 u64 jc; /**< job-chain GPU address */
621 struct base_jd_udata udata; /**< user data */
622 kbase_pointer extres_list; /**< list of external resources */
623 u16 nr_extres; /**< nr of external resources */
624 base_jd_core_req core_req; /**< core requirements */
625 const struct base_dependency pre_dep[2]; /**< pre-dependencies, one need to use SETTER function to assign this field,
626 this is done in order to reduce possibility of improper assigment of a dependency field */
627 base_atom_id atom_number; /**< unique number to identify the atom */
628 base_jd_prio prio; /**< Atom priority. Refer to @ref base_jd_prio for more details */
629 u8 device_nr; /**< coregroup when BASE_JD_REQ_SPECIFIC_COHERENT_GROUP specified */
633 #ifdef BASE_LEGACY_UK6_SUPPORT
634 struct base_jd_atom_v2_uk6 {
635 u64 jc; /**< job-chain GPU address */
636 struct base_jd_udata udata; /**< user data */
637 kbase_pointer extres_list; /**< list of external resources */
638 u16 nr_extres; /**< nr of external resources */
639 base_jd_core_req core_req; /**< core requirements */
640 base_atom_id pre_dep[2]; /**< pre-dependencies */
641 base_atom_id atom_number; /**< unique number to identify the atom */
642 base_jd_prio prio; /**< priority - smaller is higher priority */
643 u8 device_nr; /**< coregroup when BASE_JD_REQ_SPECIFIC_COHERENT_GROUP specified */
648 typedef enum base_external_resource_access {
649 BASE_EXT_RES_ACCESS_SHARED,
650 BASE_EXT_RES_ACCESS_EXCLUSIVE
651 } base_external_resource_access;
653 typedef struct base_external_resource {
655 } base_external_resource;
658 * @brief Setter for a dependency structure
660 * @param[in] dep The kbase jd atom dependency to be initialized.
661 * @param id The atom_id to be assigned.
662 * @param dep_type The dep_type to be assigned.
665 static inline void base_jd_atom_dep_set(const struct base_dependency *const_dep, base_atom_id id, base_jd_dep_type dep_type)
667 struct base_dependency *dep;
669 LOCAL_ASSERT(const_dep != NULL);
670 /* make sure we don't set not allowed combinations of atom_id/dependency_type */
671 LOCAL_ASSERT((id == 0 && dep_type == BASE_JD_DEP_TYPE_INVALID) ||
672 (id > 0 && dep_type != BASE_JD_DEP_TYPE_INVALID));
674 dep = (struct base_dependency *)const_dep;
677 dep->dependency_type = dep_type;
681 * @brief Make a copy of a dependency structure
683 * @param[in,out] dep The kbase jd atom dependency to be written.
684 * @param[in] from The dependency to make a copy from.
687 static inline void base_jd_atom_dep_copy(const struct base_dependency *const_dep, const struct base_dependency *from)
689 LOCAL_ASSERT(const_dep != NULL);
691 base_jd_atom_dep_set(const_dep, from->atom_id, from->dependency_type);
695 * @brief Soft-atom fence trigger setup.
697 * Sets up an atom to be a SW-only atom signaling a fence
698 * when it reaches the run state.
700 * Using the existing base dependency system the fence can
701 * be set to trigger when a GPU job has finished.
703 * The base fence object must not be terminated until the atom
704 * has been submitted to @a base_jd_submit_bag and @a base_jd_submit_bag has returned.
706 * @a fence must be a valid fence set up with @a base_fence_init.
707 * Calling this function with a uninitialized fence results in undefined behavior.
709 * @param[out] atom A pre-allocated atom to configure as a fence trigger SW atom
710 * @param[in] fence The base fence object to trigger.
712 static inline void base_jd_fence_trigger_setup_v2(struct base_jd_atom_v2 *atom, struct base_fence *fence)
716 LOCAL_ASSERT(fence->basep.fd == INVALID_PLATFORM_FENCE);
717 LOCAL_ASSERT(fence->basep.stream_fd >= 0);
718 atom->jc = (uintptr_t) fence;
719 atom->core_req = BASE_JD_REQ_SOFT_FENCE_TRIGGER;
723 * @brief Soft-atom fence wait setup.
725 * Sets up an atom to be a SW-only atom waiting on a fence.
726 * When the fence becomes triggered the atom becomes runnable
727 * and completes immediately.
729 * Using the existing base dependency system the fence can
730 * be set to block a GPU job until it has been triggered.
732 * The base fence object must not be terminated until the atom
733 * has been submitted to @a base_jd_submit_bag and @a base_jd_submit_bag has returned.
735 * @a fence must be a valid fence set up with @a base_fence_init or @a base_fence_import.
736 * Calling this function with a uninitialized fence results in undefined behavior.
738 * @param[out] atom A pre-allocated atom to configure as a fence wait SW atom
739 * @param[in] fence The base fence object to wait on
741 static inline void base_jd_fence_wait_setup_v2(struct base_jd_atom_v2 *atom, struct base_fence *fence)
745 LOCAL_ASSERT(fence->basep.fd >= 0);
746 atom->jc = (uintptr_t) fence;
747 atom->core_req = BASE_JD_REQ_SOFT_FENCE_WAIT;
751 * @brief External resource info initialization.
753 * Sets up a external resource object to reference
754 * a memory allocation and the type of access requested.
756 * @param[in] res The resource object to initialize
757 * @param handle The handle to the imported memory object
758 * @param access The type of access requested
760 static inline void base_external_resource_init(struct base_external_resource *res, struct base_import_handle handle, base_external_resource_access access)
764 address = handle.basep.handle;
766 LOCAL_ASSERT(res != NULL);
767 LOCAL_ASSERT(0 == (address & LOCAL_PAGE_LSB));
768 LOCAL_ASSERT(access == BASE_EXT_RES_ACCESS_SHARED || access == BASE_EXT_RES_ACCESS_EXCLUSIVE);
770 res->ext_resource = address | (access & LOCAL_PAGE_LSB);
774 * @brief Job chain event code bits
775 * Defines the bits used to create ::base_jd_event_code
778 BASE_JD_SW_EVENT_KERNEL = (1u << 15), /**< Kernel side event */
779 BASE_JD_SW_EVENT = (1u << 14), /**< SW defined event */
780 BASE_JD_SW_EVENT_SUCCESS = (1u << 13), /**< Event idicates success (SW events only) */
781 BASE_JD_SW_EVENT_JOB = (0u << 11), /**< Job related event */
782 BASE_JD_SW_EVENT_BAG = (1u << 11), /**< Bag related event */
783 BASE_JD_SW_EVENT_INFO = (2u << 11), /**< Misc/info event */
784 BASE_JD_SW_EVENT_RESERVED = (3u << 11), /**< Reserved event type */
785 BASE_JD_SW_EVENT_TYPE_MASK = (3u << 11) /**< Mask to extract the type from an event code */
789 * @brief Job chain event codes
791 * HW and low-level SW events are represented by event codes.
792 * The status of jobs which succeeded are also represented by
793 * an event code (see ::BASE_JD_EVENT_DONE).
794 * Events are usually reported as part of a ::base_jd_event.
796 * The event codes are encoded in the following way:
799 * @li 13 - SW success (only valid if the SW bit is set)
800 * @li 14 - SW event (HW event if not set)
801 * @li 15 - Kernel event (should never be seen in userspace)
803 * Events are split up into ranges as follows:
804 * - BASE_JD_EVENT_RANGE_\<description\>_START
805 * - BASE_JD_EVENT_RANGE_\<description\>_END
807 * \a code is in \<description\>'s range when:
808 * - <tt>BASE_JD_EVENT_RANGE_\<description\>_START <= code < BASE_JD_EVENT_RANGE_\<description\>_END </tt>
810 * Ranges can be asserted for adjacency by testing that the END of the previous
811 * is equal to the START of the next. This is useful for optimizing some tests
814 * A limitation is that the last member of this enum must explicitly be handled
815 * (with an assert-unreachable statement) in switch statements that use
816 * variables of this type. Otherwise, the compiler warns that we have not
817 * handled that enum value.
819 typedef enum base_jd_event_code {
820 /* HW defined exceptions */
822 /** Start of HW Non-fault status codes
824 * @note Obscurely, BASE_JD_EVENT_TERMINATED indicates a real fault,
825 * because the job was hard-stopped
827 BASE_JD_EVENT_RANGE_HW_NONFAULT_START = 0,
829 /* non-fatal exceptions */
830 BASE_JD_EVENT_NOT_STARTED = 0x00, /**< Can't be seen by userspace, treated as 'previous job done' */
831 BASE_JD_EVENT_DONE = 0x01,
832 BASE_JD_EVENT_STOPPED = 0x03, /**< Can't be seen by userspace, becomes TERMINATED, DONE or JOB_CANCELLED */
833 BASE_JD_EVENT_TERMINATED = 0x04, /**< This is actually a fault status code - the job was hard stopped */
834 BASE_JD_EVENT_ACTIVE = 0x08, /**< Can't be seen by userspace, jobs only returned on complete/fail/cancel */
836 /** End of HW Non-fault status codes
838 * @note Obscurely, BASE_JD_EVENT_TERMINATED indicates a real fault,
839 * because the job was hard-stopped
841 BASE_JD_EVENT_RANGE_HW_NONFAULT_END = 0x40,
843 /** Start of HW fault and SW Error status codes */
844 BASE_JD_EVENT_RANGE_HW_FAULT_OR_SW_ERROR_START = 0x40,
847 BASE_JD_EVENT_JOB_CONFIG_FAULT = 0x40,
848 BASE_JD_EVENT_JOB_POWER_FAULT = 0x41,
849 BASE_JD_EVENT_JOB_READ_FAULT = 0x42,
850 BASE_JD_EVENT_JOB_WRITE_FAULT = 0x43,
851 BASE_JD_EVENT_JOB_AFFINITY_FAULT = 0x44,
852 BASE_JD_EVENT_JOB_BUS_FAULT = 0x48,
853 BASE_JD_EVENT_INSTR_INVALID_PC = 0x50,
854 BASE_JD_EVENT_INSTR_INVALID_ENC = 0x51,
855 BASE_JD_EVENT_INSTR_TYPE_MISMATCH = 0x52,
856 BASE_JD_EVENT_INSTR_OPERAND_FAULT = 0x53,
857 BASE_JD_EVENT_INSTR_TLS_FAULT = 0x54,
858 BASE_JD_EVENT_INSTR_BARRIER_FAULT = 0x55,
859 BASE_JD_EVENT_INSTR_ALIGN_FAULT = 0x56,
860 BASE_JD_EVENT_DATA_INVALID_FAULT = 0x58,
861 BASE_JD_EVENT_TILE_RANGE_FAULT = 0x59,
862 BASE_JD_EVENT_STATE_FAULT = 0x5A,
863 BASE_JD_EVENT_OUT_OF_MEMORY = 0x60,
864 BASE_JD_EVENT_UNKNOWN = 0x7F,
867 BASE_JD_EVENT_DELAYED_BUS_FAULT = 0x80,
868 BASE_JD_EVENT_SHAREABILITY_FAULT = 0x88,
871 BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL1 = 0xC1,
872 BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL2 = 0xC2,
873 BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL3 = 0xC3,
874 BASE_JD_EVENT_TRANSLATION_FAULT_LEVEL4 = 0xC4,
875 BASE_JD_EVENT_PERMISSION_FAULT = 0xC8,
876 BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL1 = 0xD1,
877 BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL2 = 0xD2,
878 BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL3 = 0xD3,
879 BASE_JD_EVENT_TRANSTAB_BUS_FAULT_LEVEL4 = 0xD4,
880 BASE_JD_EVENT_ACCESS_FLAG = 0xD8,
882 /* SW defined exceptions */
883 BASE_JD_EVENT_MEM_GROWTH_FAILED = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x000,
884 BASE_JD_EVENT_TIMED_OUT = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x001,
885 BASE_JD_EVENT_JOB_CANCELLED = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x002,
886 BASE_JD_EVENT_JOB_INVALID = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x003,
887 BASE_JD_EVENT_PM_EVENT = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x004,
888 BASE_JD_EVENT_FORCE_REPLAY = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_JOB | 0x005,
890 BASE_JD_EVENT_BAG_INVALID = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_BAG | 0x003,
892 /** End of HW fault and SW Error status codes */
893 BASE_JD_EVENT_RANGE_HW_FAULT_OR_SW_ERROR_END = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_RESERVED | 0x3FF,
895 /** Start of SW Success status codes */
896 BASE_JD_EVENT_RANGE_SW_SUCCESS_START = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | 0x000,
898 BASE_JD_EVENT_PROGRESS_REPORT = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_JOB | 0x000,
899 BASE_JD_EVENT_BAG_DONE = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_BAG | 0x000,
900 BASE_JD_EVENT_DRV_TERMINATED = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_INFO | 0x000,
902 /** End of SW Success status codes */
903 BASE_JD_EVENT_RANGE_SW_SUCCESS_END = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_SUCCESS | BASE_JD_SW_EVENT_RESERVED | 0x3FF,
905 /** Start of Kernel-only status codes. Such codes are never returned to user-space */
906 BASE_JD_EVENT_RANGE_KERNEL_ONLY_START = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_KERNEL | 0x000,
907 BASE_JD_EVENT_REMOVED_FROM_NEXT = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_KERNEL | BASE_JD_SW_EVENT_JOB | 0x000,
909 /** End of Kernel-only status codes. */
910 BASE_JD_EVENT_RANGE_KERNEL_ONLY_END = BASE_JD_SW_EVENT | BASE_JD_SW_EVENT_KERNEL | BASE_JD_SW_EVENT_RESERVED | 0x3FF
911 } base_jd_event_code;
914 * @brief Event reporting structure
916 * This structure is used by the kernel driver to report information
917 * about GPU events. The can either be HW-specific events or low-level
918 * SW events, such as job-chain completion.
920 * The event code contains an event type field which can be extracted
921 * by ANDing with ::BASE_JD_SW_EVENT_TYPE_MASK.
923 * Based on the event type base_jd_event::data holds:
924 * @li ::BASE_JD_SW_EVENT_JOB : the offset in the ring-buffer for the completed
926 * @li ::BASE_JD_SW_EVENT_BAG : The address of the ::base_jd_bag that has
927 * been completed (ie all contained job-chains have been completed).
928 * @li ::BASE_JD_SW_EVENT_INFO : base_jd_event::data not used
930 typedef struct base_jd_event_v2 {
931 base_jd_event_code event_code; /**< event code */
932 base_atom_id atom_number; /**< the atom number that has completed */
933 struct base_jd_udata udata; /**< user data */
937 * Padding required to ensure that the @ref struct base_dump_cpu_gpu_counters structure fills
941 #define BASE_CPU_GPU_CACHE_LINE_PADDING (36)
945 * @brief Structure for BASE_JD_REQ_SOFT_DUMP_CPU_GPU_COUNTERS jobs.
947 * This structure is stored into the memory pointed to by the @c jc field of @ref base_jd_atom.
949 * This structure must be padded to ensure that it will occupy whole cache lines. This is to avoid
950 * cases where access to pages containing the structure is shared between cached and un-cached
951 * memory regions, which would cause memory corruption. Here we set the structure size to be 64 bytes
952 * which is the cache line for ARM A15 processors.
955 typedef struct base_dump_cpu_gpu_counters {
960 u8 padding[BASE_CPU_GPU_CACHE_LINE_PADDING];
961 } base_dump_cpu_gpu_counters;
965 /** @} end group base_user_api_job_dispatch */
969 * The following typedefs should be removed when a midg types header is added.
970 * See MIDCOM-1657 for details.
972 typedef u32 gpu_product_id;
973 typedef u32 gpu_cache_features;
974 typedef u32 gpu_tiler_features;
975 typedef u32 gpu_mem_features;
976 typedef u32 gpu_mmu_features;
977 typedef u32 gpu_js_features;
978 typedef u32 gpu_as_present;
979 typedef u32 gpu_js_present;
981 #define GPU_MAX_JOB_SLOTS 16
984 #include <gpu/mali_gpu_registers.h>
985 #include <gpu/mali_gpu_props.h>
989 * @page page_base_user_api_gpuprops User-side Base GPU Property Query API
991 * The User-side Base GPU Property Query API encapsulates two
994 * - @ref base_user_api_gpuprops_dyn "Dynamic GPU Properties"
995 * - @ref base_plat_config_gpuprops "Base Platform Config GPU Properties"
997 * There is a related third module outside of Base, which is owned by the MIDG
999 * - @ref gpu_props_static "Midgard Compile-time GPU Properties"
1001 * Base only deals with properties that vary between different Midgard
1002 * implementations - the Dynamic GPU properties and the Platform Config
1005 * For properties that are constant for the Midgard Architecture, refer to the
1006 * MIDG module. However, we will discuss their relevance here <b>just to
1007 * provide background information.</b>
1009 * @section sec_base_user_api_gpuprops_about About the GPU Properties in Base and MIDG modules
1011 * The compile-time properties (Platform Config, Midgard Compile-time
1012 * properties) are exposed as pre-processor macros.
1014 * Complementing the compile-time properties are the Dynamic GPU
1015 * Properties, which act as a conduit for the Midgard Configuration
1018 * In general, the dynamic properties are present to verify that the platform
1019 * has been configured correctly with the right set of Platform Config
1020 * Compile-time Properties.
1022 * As a consistant guide across the entire DDK, the choice for dynamic or
1023 * compile-time should consider the following, in order:
1024 * -# Can the code be written so that it doesn't need to know the
1025 * implementation limits at all?
1026 * -# If you need the limits, get the information from the Dynamic Property
1027 * lookup. This should be done once as you fetch the context, and then cached
1028 * as part of the context data structure, so it's cheap to access.
1029 * -# If there's a clear and arguable inefficiency in using Dynamic Properties,
1030 * then use a Compile-Time Property (Platform Config, or Midgard Compile-time
1031 * property). Examples of where this might be sensible follow:
1032 * - Part of a critical inner-loop
1033 * - Frequent re-use throughout the driver, causing significant extra load
1034 * instructions or control flow that would be worthwhile optimizing out.
1036 * We cannot provide an exhaustive set of examples, neither can we provide a
1037 * rule for every possible situation. Use common sense, and think about: what
1038 * the rest of the driver will be doing; how the compiler might represent the
1039 * value if it is a compile-time constant; whether an OEM shipping multiple
1040 * devices would benefit much more from a single DDK binary, instead of
1041 * insignificant micro-optimizations.
1043 * @section sec_base_user_api_gpuprops_dyn Dynamic GPU Properties
1045 * Dynamic GPU properties are presented in two sets:
1046 * -# the commonly used properties in @ref base_gpu_props, which have been
1047 * unpacked from GPU register bitfields.
1048 * -# The full set of raw, unprocessed properties in @ref gpu_raw_gpu_props
1049 * (also a member of @ref base_gpu_props). All of these are presented in
1050 * the packed form, as presented by the GPU registers themselves.
1052 * @usecase The raw properties in @ref gpu_raw_gpu_props are necessary to
1053 * allow a user of the Mali Tools (e.g. PAT) to determine "Why is this device
1054 * behaving differently?". In this case, all information about the
1055 * configuration is potentially useful, but it <b>does not need to be processed
1056 * by the driver</b>. Instead, the raw registers can be processed by the Mali
1057 * Tools software on the host PC.
1059 * The properties returned extend the Midgard Configuration Discovery
1060 * registers. For example, GPU clock speed is not specified in the Midgard
1061 * Architecture, but is <b>necessary for OpenCL's clGetDeviceInfo() function</b>.
1063 * The GPU properties are obtained by a call to
1064 * _mali_base_get_gpu_props(). This simply returns a pointer to a const
1065 * base_gpu_props structure. It is constant for the life of a base
1066 * context. Multiple calls to _mali_base_get_gpu_props() to a base context
1067 * return the same pointer to a constant structure. This avoids cache pollution
1068 * of the common data.
1070 * This pointer must not be freed, because it does not point to the start of a
1071 * region allocated by the memory allocator; instead, just close the @ref
1075 * @section sec_base_user_api_gpuprops_config Platform Config Compile-time Properties
1077 * The Platform Config File sets up gpu properties that are specific to a
1078 * certain platform. Properties that are 'Implementation Defined' in the
1079 * Midgard Architecture spec are placed here.
1081 * @note Reference configurations are provided for Midgard Implementations, such as
1082 * the Mali-T600 family. The customer need not repeat this information, and can select one of
1083 * these reference configurations. For example, VA_BITS, PA_BITS and the
1084 * maximum number of samples per pixel might vary between Midgard Implementations, but
1085 * \b not for platforms using the Mali-T604. This information is placed in
1086 * the reference configuration files.
1088 * The System Integrator creates the following structure:
1090 * - platform_XYZ/plat
1091 * - platform_XYZ/plat/plat_config.h
1093 * They then edit plat_config.h, using the example plat_config.h files as a
1096 * At the very least, the customer must set @ref CONFIG_GPU_CORE_TYPE, and will
1097 * receive a helpful \#error message if they do not do this correctly. This
1098 * selects the Reference Configuration for the Midgard Implementation. The rationale
1099 * behind this decision (against asking the customer to write \#include
1100 * <gpus/mali_t600.h> in their plat_config.h) is as follows:
1101 * - This mechanism 'looks' like a regular config file (such as Linux's
1103 * - It is difficult to get wrong in a way that will produce strange build
1105 * - They need not know where the mali_t600.h, other_midg_gpu.h etc. files are stored - and
1106 * so they won't accidentally pick another file with 'mali_t600' in its name
1107 * - When the build doesn't work, the System Integrator may think the DDK is
1108 * doesn't work, and attempt to fix it themselves:
1109 * - For the @ref CONFIG_GPU_CORE_TYPE mechanism, the only way to get past the
1110 * error is to set @ref CONFIG_GPU_CORE_TYPE, and this is what the \#error tells
1112 * - For a \#include mechanism, checks must still be made elsewhere, which the
1113 * System Integrator may try working around by setting \#defines (such as
1114 * VA_BITS) themselves in their plat_config.h. In the worst case, they may
1115 * set the prevention-mechanism \#define of
1116 * "A_CORRECT_MIDGARD_CORE_WAS_CHOSEN".
1117 * - In this case, they would believe they are on the right track, because
1118 * the build progresses with their fix, but with errors elsewhere.
1120 * However, there is nothing to prevent the customer using \#include to organize
1121 * their own configurations files hierarchically.
1123 * The mechanism for the header file processing is as follows:
1126 digraph plat_config_mechanism {
1135 rank = same; ordering = out;
1137 "gpu/mali_gpu_props.h";
1138 "base/midg_gpus/mali_t600.h";
1139 "base/midg_gpus/other_midg_gpu.h";
1141 { rank = same; "plat/plat_config.h"; }
1144 "gpu/mali_gpu.h" [ shape=box ];
1145 gpu_chooser [ label="" style="invisible" width=0 height=0 fixedsize=true ];
1146 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 ] ;
1149 { rank = same; "plat/plat_config.h"; }
1150 { rank = same; "mali_base.h"; }
1152 "mali_base.h" -> "gpu/mali_gpu.h" -> "gpu/mali_gpu_props.h";
1153 "mali_base.h" -> "plat/plat_config.h" ;
1154 "mali_base.h" -> select_gpu ;
1156 "plat/plat_config.h" -> gpu_chooser [style="dotted,bold" dir=none weight=4] ;
1157 gpu_chooser -> select_gpu [style="dotted,bold"] ;
1159 select_gpu -> "base/midg_gpus/mali_t600.h" ;
1160 select_gpu -> "base/midg_gpus/other_midg_gpu.h" ;
1165 * @section sec_base_user_api_gpuprops_kernel Kernel Operation
1167 * During Base Context Create time, user-side makes a single kernel call:
1168 * - A call to fill user memory with GPU information structures
1170 * The kernel-side will fill the provided the entire processed @ref base_gpu_props
1171 * structure, because this information is required in both
1172 * user and kernel side; it does not make sense to decode it twice.
1174 * Coherency groups must be derived from the bitmasks, but this can be done
1175 * kernel side, and just once at kernel startup: Coherency groups must already
1176 * be known kernel-side, to support chains that specify a 'Only Coherent Group'
1177 * SW requirement, or 'Only Coherent Group with Tiler' SW requirement.
1179 * @section sec_base_user_api_gpuprops_cocalc Coherency Group calculation
1180 * Creation of the coherent group data is done at device-driver startup, and so
1181 * is one-time. This will most likely involve a loop with CLZ, shifting, and
1182 * bit clearing on the L2_PRESENT mask, depending on whether the
1183 * system is L2 Coherent. The number of shader cores is done by a
1184 * population count, since faulty cores may be disabled during production,
1185 * producing a non-contiguous mask.
1187 * The memory requirements for this algoirthm can be determined either by a u64
1188 * population count on the L2_PRESENT mask (a LUT helper already is
1189 * requried for the above), or simple assumption that there can be no more than
1190 * 16 coherent groups, since core groups are typically 4 cores.
1194 * @addtogroup base_user_api_gpuprops User-side Base GPU Property Query APIs
1199 * @addtogroup base_user_api_gpuprops_dyn Dynamic HW Properties
1203 #define BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3
1205 #define BASE_MAX_COHERENT_GROUPS 16
1207 struct mali_base_gpu_core_props {
1209 * Product specific value.
1211 gpu_product_id product_id;
1214 * Status of the GPU release.
1215 * No defined values, but starts at 0 and increases by one for each release
1216 * status (alpha, beta, EAC, etc.).
1217 * 4 bit values (0-15).
1222 * Minor release number of the GPU. "P" part of an "RnPn" release number.
1223 * 8 bit values (0-255).
1228 * Major release number of the GPU. "R" part of an "RnPn" release number.
1229 * 4 bit values (0-15).
1236 * @usecase GPU clock speed is not specified in the Midgard Architecture, but is
1237 * <b>necessary for OpenCL's clGetDeviceInfo() function</b>.
1242 * @usecase GPU clock max/min speed is required for computing best/worst case
1243 * in tasks as job scheduling ant irq_throttling. (It is not specified in the
1244 * Midgard Architecture).
1246 u32 gpu_freq_khz_max;
1247 u32 gpu_freq_khz_min;
1250 * Size of the shader program counter, in bits.
1252 u32 log2_program_counter_size;
1255 * TEXTURE_FEATURES_x registers, as exposed by the GPU. This is a
1256 * bitpattern where a set bit indicates that the format is supported.
1258 * Before using a texture format, it is recommended that the corresponding
1261 u32 texture_features[BASE_GPU_NUM_TEXTURE_FEATURES_REGISTERS];
1264 * Theoretical maximum memory available to the GPU. It is unlikely that a
1265 * client will be able to allocate all of this memory for their own
1266 * purposes, but this at least provides an upper bound on the memory
1267 * available to the GPU.
1269 * This is required for OpenCL's clGetDeviceInfo() call when
1270 * CL_DEVICE_GLOBAL_MEM_SIZE is requested, for OpenCL GPU devices. The
1271 * client will not be expecting to allocate anywhere near this value.
1273 u64 gpu_available_memory_size;
1278 * More information is possible - but associativity and bus width are not
1279 * required by upper-level apis.
1281 struct mali_base_gpu_l2_cache_props {
1284 u8 num_l2_slices; /* Number of L2C slices. 1 or higher */
1288 struct mali_base_gpu_tiler_props {
1289 u32 bin_size_bytes; /* Max is 4*2^15 */
1290 u32 max_active_levels; /* Max is 2^15 */
1294 * GPU threading system details.
1296 struct mali_base_gpu_thread_props {
1297 u32 max_threads; /* Max. number of threads per core */
1298 u32 max_workgroup_size; /* Max. number of threads per workgroup */
1299 u32 max_barrier_size; /* Max. number of threads that can synchronize on a simple barrier */
1300 u16 max_registers; /* Total size [1..65535] of the register file available per core. */
1301 u8 max_task_queue; /* Max. tasks [1..255] which may be sent to a core before it becomes blocked. */
1302 u8 max_thread_group_split; /* Max. allowed value [1..15] of the Thread Group Split field. */
1303 u8 impl_tech; /* 0 = Not specified, 1 = Silicon, 2 = FPGA, 3 = SW Model/Emulation */
1308 * @brief descriptor for a coherent group
1310 * \c core_mask exposes all cores in that coherent group, and \c num_cores
1311 * provides a cached population-count for that mask.
1313 * @note Whilst all cores are exposed in the mask, not all may be available to
1314 * the application, depending on the Kernel Power policy.
1316 * @note if u64s must be 8-byte aligned, then this structure has 32-bits of wastage.
1318 struct mali_base_gpu_coherent_group {
1319 u64 core_mask; /**< Core restriction mask required for the group */
1320 u16 num_cores; /**< Number of cores in the group */
1325 * @brief Coherency group information
1327 * Note that the sizes of the members could be reduced. However, the \c group
1328 * member might be 8-byte aligned to ensure the u64 core_mask is 8-byte
1329 * aligned, thus leading to wastage if the other members sizes were reduced.
1331 * The groups are sorted by core mask. The core masks are non-repeating and do
1334 struct mali_base_gpu_coherent_group_info {
1338 * Number of core groups (coherent or not) in the GPU. Equivalent to the number of L2 Caches.
1340 * The GPU Counter dumping writes 2048 bytes per core group, regardless of
1341 * whether the core groups are coherent or not. Hence this member is needed
1342 * to calculate how much memory is required for dumping.
1344 * @note Do not use it to work out how many valid elements are in the
1345 * group[] member. Use num_groups instead.
1347 u32 num_core_groups;
1350 * Coherency features of the memory, accessed by @ref gpu_mem_features
1353 gpu_mem_features coherency;
1358 * Descriptors of coherent groups
1360 struct mali_base_gpu_coherent_group group[BASE_MAX_COHERENT_GROUPS];
1364 * A complete description of the GPU's Hardware Configuration Discovery
1367 * The information is presented inefficiently for access. For frequent access,
1368 * the values should be better expressed in an unpacked form in the
1369 * base_gpu_props structure.
1371 * @usecase The raw properties in @ref gpu_raw_gpu_props are necessary to
1372 * allow a user of the Mali Tools (e.g. PAT) to determine "Why is this device
1373 * behaving differently?". In this case, all information about the
1374 * configuration is potentially useful, but it <b>does not need to be processed
1375 * by the driver</b>. Instead, the raw registers can be processed by the Mali
1376 * Tools software on the host PC.
1379 struct gpu_raw_gpu_props {
1383 u64 unused_1; /* keep for backward compatibility */
1385 gpu_cache_features l2_features;
1386 u32 suspend_size; /* API 8.2+ */
1387 gpu_mem_features mem_features;
1388 gpu_mmu_features mmu_features;
1390 gpu_as_present as_present;
1393 gpu_js_features js_features[GPU_MAX_JOB_SLOTS];
1394 gpu_tiler_features tiler_features;
1395 u32 texture_features[3];
1399 u32 thread_max_threads;
1400 u32 thread_max_workgroup_size;
1401 u32 thread_max_barrier_size;
1402 u32 thread_features;
1404 u32 coherency_features;
1408 * Return structure for _mali_base_get_gpu_props().
1410 * NOTE: the raw_props member in this datastructure contains the register
1411 * values from which the value of the other members are derived. The derived
1412 * members exist to allow for efficient access and/or shielding the details
1413 * of the layout of the registers.
1416 typedef struct mali_base_gpu_props {
1417 struct mali_base_gpu_core_props core_props;
1418 struct mali_base_gpu_l2_cache_props l2_props;
1419 u64 unused_1; /* keep for backwards compatibility */
1420 struct mali_base_gpu_tiler_props tiler_props;
1421 struct mali_base_gpu_thread_props thread_props;
1423 /** This member is large, likely to be 128 bytes */
1424 struct gpu_raw_gpu_props raw_props;
1426 /** This must be last member of the structure */
1427 struct mali_base_gpu_coherent_group_info coherency_info;
1430 /** @} end group base_user_api_gpuprops_dyn */
1432 /** @} end group base_user_api_gpuprops */
1435 * @addtogroup base_user_api_core User-side Base core APIs
1440 * \enum base_context_create_flags
1442 * Flags to pass to ::base_context_init.
1443 * Flags can be ORed together to enable multiple things.
1445 * These share the same space as @ref basep_context_private_flags, and so must
1446 * not collide with them.
1448 enum base_context_create_flags {
1450 BASE_CONTEXT_CREATE_FLAG_NONE = 0,
1452 /** Base context is embedded in a cctx object (flag used for CINSTR software counter macros) */
1453 BASE_CONTEXT_CCTX_EMBEDDED = (1u << 0),
1455 /** Base context is a 'System Monitor' context for Hardware counters.
1457 * One important side effect of this is that job submission is disabled. */
1458 BASE_CONTEXT_SYSTEM_MONITOR_SUBMIT_DISABLED = (1u << 1),
1460 /** Base context flag indicating a 'hint' that this context uses Compute
1463 * Specifially, this means that it only sends atoms that <b>do not</b>
1464 * contain the following @ref base_jd_core_req :
1468 * Violation of these requirements will cause the Job-Chains to be rejected.
1470 * In addition, it is inadvisable for the atom's Job-Chains to contain Jobs
1471 * of the following @ref gpu_job_type (whilst it may work now, it may not
1473 * - @ref GPU_JOB_VERTEX
1474 * - @ref GPU_JOB_GEOMETRY
1476 * @note An alternative to using this is to specify the BASE_JD_REQ_ONLY_COMPUTE
1477 * requirement in atoms.
1479 BASE_CONTEXT_HINT_ONLY_COMPUTE = (1u << 2)
1483 * Bitpattern describing the ::base_context_create_flags that can be passed to base_context_init()
1485 #define BASE_CONTEXT_CREATE_ALLOWED_FLAGS \
1486 (((u32)BASE_CONTEXT_CCTX_EMBEDDED) | \
1487 ((u32)BASE_CONTEXT_SYSTEM_MONITOR_SUBMIT_DISABLED) | \
1488 ((u32)BASE_CONTEXT_HINT_ONLY_COMPUTE))
1491 * Bitpattern describing the ::base_context_create_flags that can be passed to the kernel
1493 #define BASE_CONTEXT_CREATE_KERNEL_FLAGS \
1494 (((u32)BASE_CONTEXT_SYSTEM_MONITOR_SUBMIT_DISABLED) | \
1495 ((u32)BASE_CONTEXT_HINT_ONLY_COMPUTE))
1498 * Private flags used on the base context
1500 * These start at bit 31, and run down to zero.
1502 * They share the same space as @ref base_context_create_flags, and so must
1503 * not collide with them.
1505 enum basep_context_private_flags {
1506 /** Private flag tracking whether job descriptor dumping is disabled */
1507 BASEP_CONTEXT_FLAG_JOB_DUMP_DISABLED = (1 << 31)
1510 /** @} end group base_user_api_core */
1512 /** @} end group base_user_api */
1515 * @addtogroup base_plat_config_gpuprops Base Platform Config GPU Properties
1518 * C Pre-processor macros are exposed here to do with Platform
1522 * - GPU Properties that are constant on a particular Midgard Family
1523 * Implementation e.g. Maximum samples per pixel on Mali-T600.
1524 * - General platform config for the GPU, such as the GPU major and minor
1528 /** @} end group base_plat_config_gpuprops */
1531 * @addtogroup base_api Base APIs
1536 * @brief The payload for a replay job. This must be in GPU memory.
1538 typedef struct base_jd_replay_payload {
1540 * Pointer to the first entry in the base_jd_replay_jc list. These
1541 * will be replayed in @b reverse order (so that extra ones can be added
1542 * to the head in future soft jobs without affecting this soft job)
1547 * Pointer to the fragment job chain.
1552 * Pointer to the tiler heap free FBD field to be modified.
1554 u64 tiler_heap_free;
1557 * Hierarchy mask for the replayed fragment jobs. May be zero.
1559 u16 fragment_hierarchy_mask;
1562 * Hierarchy mask for the replayed tiler jobs. May be zero.
1564 u16 tiler_hierarchy_mask;
1567 * Default weight to be used for hierarchy levels not in the original
1570 u32 hierarchy_default_weight;
1573 * Core requirements for the tiler job chain
1575 base_jd_core_req tiler_core_req;
1578 * Core requirements for the fragment job chain
1580 base_jd_core_req fragment_core_req;
1583 } base_jd_replay_payload;
1586 * @brief An entry in the linked list of job chains to be replayed. This must
1589 typedef struct base_jd_replay_jc {
1591 * Pointer to next entry in the list. A setting of NULL indicates the
1597 * Pointer to the job chain.
1601 } base_jd_replay_jc;
1603 /* Maximum number of jobs allowed in a fragment chain in the payload of a
1605 #define BASE_JD_REPLAY_F_CHAIN_JOB_LIMIT 256
1607 /** @} end group base_api */
1609 typedef struct base_profiling_controls {
1610 u32 profiling_controls[FBDUMP_CONTROL_MAX];
1611 } base_profiling_controls;
1613 #endif /* _BASE_KERNEL_H_ */