mali_base_kernel.h 61 KB

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