mali-ioctl.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. /*
  2. * © Copyright 2017 The BiOpenly Community
  3. *
  4. * This program is free software and is provided to you under the terms of the
  5. * GNU General Public License version 2 as published by the Free Software
  6. * Foundation, and any use by you of this program is subject to the terms
  7. * of such GNU license.
  8. *
  9. * A copy of the licence is included with the program, and can also be obtained
  10. * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  11. * Boston, MA 02110-1301, USA.
  12. *
  13. */
  14. /**
  15. * Definitions for all of the ioctls for the original open source bifrost GPU
  16. * kernel driver, written by ARM.
  17. */
  18. #ifndef __MALI_IOCTL_H__
  19. #define __MALI_IOCTL_H__
  20. #include <panloader-util.h>
  21. #define MALI_GPU_NUM_TEXTURE_FEATURES_REGISTERS 3
  22. #define MALI_GPU_MAX_JOB_SLOTS 16
  23. #define MALI_MAX_COHERENT_GROUPS 16
  24. typedef u8 mali_atom_id;
  25. /**
  26. * Since these structs are passed to and from the kernel we need to make sure
  27. * that we get the size of each struct to match exactly what the kernel is
  28. * expecting. So, when editing this file make sure to add static asserts that
  29. * check each struct's size against the arg length you see in strace.
  30. */
  31. enum mali_ioctl_mem_flags {
  32. /* IN */
  33. MALI_MEM_PROT_CPU_RD = (1U << 0), /**< Read access CPU side */
  34. MALI_MEM_PROT_CPU_WR = (1U << 1), /**< Write access CPU side */
  35. MALI_MEM_PROT_GPU_RD = (1U << 2), /**< Read access GPU side */
  36. MALI_MEM_PROT_GPU_WR = (1U << 3), /**< Write access GPU side */
  37. MALI_MEM_PROT_GPU_EX = (1U << 4), /**< Execute allowed on the GPU
  38. side */
  39. MALI_MEM_GROW_ON_GPF = (1U << 9), /**< Grow backing store on GPU
  40. Page Fault */
  41. MALI_MEM_COHERENT_SYSTEM = (1U << 10), /**< Page coherence Outer
  42. shareable, if available */
  43. MALI_MEM_COHERENT_LOCAL = (1U << 11), /**< Page coherence Inner
  44. shareable */
  45. MALI_MEM_CACHED_CPU = (1U << 12), /**< Should be cached on the
  46. CPU */
  47. /* IN/OUT */
  48. MALI_MEM_SAME_VA = (1U << 13), /**< Must have same VA on both the GPU
  49. and the CPU */
  50. /* OUT */
  51. MALI_MEM_NEED_MMAP = (1U << 14), /**< Must call mmap to acquire a GPU
  52. address for the alloc */
  53. /* IN */
  54. MALI_MEM_COHERENT_SYSTEM_REQUIRED = (1U << 15), /**< Page coherence
  55. Outer shareable, required. */
  56. MALI_MEM_SECURE = (1U << 16), /**< Secure memory */
  57. MALI_MEM_DONT_NEED = (1U << 17), /**< Not needed physical
  58. memory */
  59. MALI_MEM_IMPORT_SHARED = (1U << 18), /**< Must use shared CPU/GPU zone
  60. (SAME_VA zone) but doesn't
  61. require the addresses to
  62. be the same */
  63. };
  64. #define MALI_MEM_MAP_TRACKING_HANDLE (0x3000)
  65. enum mali_ioctl_coherency_mode {
  66. COHERENCY_ACE_LITE = 0,
  67. COHERENCY_ACE = 1,
  68. COHERENCY_NONE = 31
  69. };
  70. /*
  71. * Mali Atom priority
  72. *
  73. * Only certain priority levels are actually implemented, as specified by the
  74. * MALI_JD_PRIO_<...> definitions below. It is undefined to use a priority
  75. * level that is not one of those defined below.
  76. *
  77. * Priority levels only affect scheduling between atoms of the same type within
  78. * a mali context, and only after the atoms have had dependencies resolved.
  79. * Fragment atoms does not affect non-frament atoms with lower priorities, and
  80. * the other way around. For example, a low priority atom that has had its
  81. * dependencies resolved might run before a higher priority atom that has not
  82. * had its dependencies resolved.
  83. *
  84. * The scheduling between mali contexts/processes and between atoms from
  85. * different mali contexts/processes is unaffected by atom priority.
  86. *
  87. * The atoms are scheduled as follows with respect to their priorities:
  88. * - Let atoms 'X' and 'Y' be for the same job slot who have dependencies
  89. * resolved, and atom 'X' has a higher priority than atom 'Y'
  90. * - If atom 'Y' is currently running on the HW, then it is interrupted to
  91. * allow atom 'X' to run soon after
  92. * - If instead neither atom 'Y' nor atom 'X' are running, then when choosing
  93. * the next atom to run, atom 'X' will always be chosen instead of atom 'Y'
  94. * - Any two atoms that have the same priority could run in any order with
  95. * respect to each other. That is, there is no ordering constraint between
  96. * atoms of the same priority.
  97. */
  98. typedef u8 mali_jd_prio;
  99. #define MALI_JD_PRIO_MEDIUM ((mali_jd_prio)0)
  100. #define MALI_JD_PRIO_HIGH ((mali_jd_prio)1)
  101. #define MALI_JD_PRIO_LOW ((mali_jd_prio)2)
  102. /**
  103. * @brief Job dependency type.
  104. *
  105. * A flags field will be inserted into the atom structure to specify whether a
  106. * dependency is a data or ordering dependency (by putting it before/after
  107. * 'core_req' in the structure it should be possible to add without changing
  108. * the structure size). When the flag is set for a particular dependency to
  109. * signal that it is an ordering only dependency then errors will not be
  110. * propagated.
  111. */
  112. typedef u8 mali_jd_dep_type;
  113. #define MALI_JD_DEP_TYPE_INVALID (0) /**< Invalid dependency */
  114. #define MALI_JD_DEP_TYPE_DATA (1U << 0) /**< Data dependency */
  115. #define MALI_JD_DEP_TYPE_ORDER (1U << 1) /**< Order dependency */
  116. /**
  117. * @brief Job chain hardware requirements.
  118. *
  119. * A job chain must specify what GPU features it needs to allow the
  120. * driver to schedule the job correctly. By not specifying the
  121. * correct settings can/will cause an early job termination. Multiple
  122. * values can be ORed together to specify multiple requirements.
  123. * Special case is ::MALI_JD_REQ_DEP, which is used to express complex
  124. * dependencies, and that doesn't execute anything on the hardware.
  125. */
  126. typedef u32 mali_jd_core_req;
  127. /* Requirements that come from the HW */
  128. /**
  129. * No requirement, dependency only
  130. */
  131. #define MALI_JD_REQ_DEP ((mali_jd_core_req)0)
  132. /**
  133. * Requires fragment shaders
  134. */
  135. #define MALI_JD_REQ_FS ((mali_jd_core_req)1 << 0)
  136. /**
  137. * Requires compute shaders
  138. * This covers any of the following Midgard Job types:
  139. * - Vertex Shader Job
  140. * - Geometry Shader Job
  141. * - An actual Compute Shader Job
  142. *
  143. * Compare this with @ref MALI_JD_REQ_ONLY_COMPUTE, which specifies that the
  144. * job is specifically just the "Compute Shader" job type, and not the "Vertex
  145. * Shader" nor the "Geometry Shader" job type.
  146. */
  147. #define MALI_JD_REQ_CS ((mali_jd_core_req)1 << 1)
  148. #define MALI_JD_REQ_T ((mali_jd_core_req)1 << 2) /**< Requires tiling */
  149. #define MALI_JD_REQ_CF ((mali_jd_core_req)1 << 3) /**< Requires cache flushes */
  150. #define MALI_JD_REQ_V ((mali_jd_core_req)1 << 4) /**< Requires value writeback */
  151. /* SW-only requirements - the HW does not expose these as part of the job slot
  152. * capabilities */
  153. /* Requires fragment job with AFBC encoding */
  154. #define MALI_JD_REQ_FS_AFBC ((mali_jd_core_req)1 << 13)
  155. /**
  156. * SW-only requirement: coalesce completion events.
  157. * If this bit is set then completion of this atom will not cause an event to
  158. * be sent to userspace, whether successful or not; completion events will be
  159. * deferred until an atom completes which does not have this bit set.
  160. *
  161. * This bit may not be used in combination with MALI_JD_REQ_EXTERNAL_RESOURCES.
  162. */
  163. #define MALI_JD_REQ_EVENT_COALESCE ((mali_jd_core_req)1 << 5)
  164. /**
  165. * SW Only requirement: the job chain requires a coherent core group. We don't
  166. * mind which coherent core group is used.
  167. */
  168. #define MALI_JD_REQ_COHERENT_GROUP ((mali_jd_core_req)1 << 6)
  169. /**
  170. * SW Only requirement: The performance counters should be enabled only when
  171. * they are needed, to reduce power consumption.
  172. */
  173. #define MALI_JD_REQ_PERMON ((mali_jd_core_req)1 << 7)
  174. /**
  175. * SW Only requirement: External resources are referenced by this atom. When
  176. * external resources are referenced no syncsets can be bundled with the atom
  177. * but should instead be part of a NULL jobs inserted into the dependency
  178. * tree. The first pre_dep object must be configured for the external
  179. * resouces to use, the second pre_dep object can be used to create other
  180. * dependencies.
  181. *
  182. * This bit may not be used in combination with MALI_JD_REQ_EVENT_COALESCE.
  183. */
  184. #define MALI_JD_REQ_EXTERNAL_RESOURCES ((mali_jd_core_req)1 << 8)
  185. /**
  186. * SW Only requirement: Software defined job. Jobs with this bit set will not
  187. * be submitted to the hardware but will cause some action to happen within
  188. * the driver
  189. */
  190. #define MALI_JD_REQ_SOFT_JOB ((mali_jd_core_req)1 << 9)
  191. #define MALI_JD_REQ_SOFT_DUMP_CPU_GPU_TIME (MALI_JD_REQ_SOFT_JOB | 0x1)
  192. #define MALI_JD_REQ_SOFT_FENCE_TRIGGER (MALI_JD_REQ_SOFT_JOB | 0x2)
  193. #define MALI_JD_REQ_SOFT_FENCE_WAIT (MALI_JD_REQ_SOFT_JOB | 0x3)
  194. /**
  195. * SW Only requirement : Replay job.
  196. *
  197. * If the preceding job fails, the replay job will cause the jobs specified in
  198. * the list of mali_jd_replay_payload pointed to by the jc pointer to be
  199. * replayed.
  200. *
  201. * A replay job will only cause jobs to be replayed up to MALIP_JD_REPLAY_LIMIT
  202. * times. If a job fails more than MALIP_JD_REPLAY_LIMIT times then the replay
  203. * job is failed, as well as any following dependencies.
  204. *
  205. * The replayed jobs will require a number of atom IDs. If there are not enough
  206. * free atom IDs then the replay job will fail.
  207. *
  208. * If the preceding job does not fail, then the replay job is returned as
  209. * completed.
  210. *
  211. * The replayed jobs will never be returned to userspace. The preceding failed
  212. * job will be returned to userspace as failed; the status of this job should
  213. * be ignored. Completion should be determined by the status of the replay soft
  214. * job.
  215. *
  216. * In order for the jobs to be replayed, the job headers will have to be
  217. * modified. The Status field will be reset to NOT_STARTED. If the Job Type
  218. * field indicates a Vertex Shader Job then it will be changed to Null Job.
  219. *
  220. * The replayed jobs have the following assumptions :
  221. *
  222. * - No external resources. Any required external resources will be held by the
  223. * replay atom.
  224. * - Pre-dependencies are created based on job order.
  225. * - Atom numbers are automatically assigned.
  226. * - device_nr is set to 0. This is not relevant as
  227. * MALI_JD_REQ_SPECIFIC_COHERENT_GROUP should not be set.
  228. * - Priority is inherited from the replay job.
  229. */
  230. #define MALI_JD_REQ_SOFT_REPLAY (MALI_JD_REQ_SOFT_JOB | 0x4)
  231. /**
  232. * SW only requirement: event wait/trigger job.
  233. *
  234. * - MALI_JD_REQ_SOFT_EVENT_WAIT: this job will block until the event is set.
  235. * - MALI_JD_REQ_SOFT_EVENT_SET: this job sets the event, thus unblocks the
  236. * other waiting jobs. It completes immediately.
  237. * - MALI_JD_REQ_SOFT_EVENT_RESET: this job resets the event, making it
  238. * possible for other jobs to wait upon. It completes immediately.
  239. */
  240. #define MALI_JD_REQ_SOFT_EVENT_WAIT (MALI_JD_REQ_SOFT_JOB | 0x5)
  241. #define MALI_JD_REQ_SOFT_EVENT_SET (MALI_JD_REQ_SOFT_JOB | 0x6)
  242. #define MALI_JD_REQ_SOFT_EVENT_RESET (MALI_JD_REQ_SOFT_JOB | 0x7)
  243. #define MALI_JD_REQ_SOFT_DEBUG_COPY (MALI_JD_REQ_SOFT_JOB | 0x8)
  244. /**
  245. * SW only requirement: Just In Time allocation
  246. *
  247. * This job requests a JIT allocation based on the request in the
  248. * @base_jit_alloc_info structure which is passed via the jc element of
  249. * the atom.
  250. *
  251. * It should be noted that the id entry in @base_jit_alloc_info must not
  252. * be reused until it has been released via @MALI_JD_REQ_SOFT_JIT_FREE.
  253. *
  254. * Should this soft job fail it is expected that a @MALI_JD_REQ_SOFT_JIT_FREE
  255. * soft job to free the JIT allocation is still made.
  256. *
  257. * The job will complete immediately.
  258. */
  259. #define MALI_JD_REQ_SOFT_JIT_ALLOC (MALI_JD_REQ_SOFT_JOB | 0x9)
  260. /**
  261. * SW only requirement: Just In Time free
  262. *
  263. * This job requests a JIT allocation created by @MALI_JD_REQ_SOFT_JIT_ALLOC
  264. * to be freed. The ID of the JIT allocation is passed via the jc element of
  265. * the atom.
  266. *
  267. * The job will complete immediately.
  268. */
  269. #define MALI_JD_REQ_SOFT_JIT_FREE (MALI_JD_REQ_SOFT_JOB | 0xa)
  270. /**
  271. * SW only requirement: Map external resource
  272. *
  273. * This job requests external resource(s) are mapped once the dependencies
  274. * of the job have been satisfied. The list of external resources are
  275. * passed via the jc element of the atom which is a pointer to a
  276. * @base_external_resource_list.
  277. */
  278. #define MALI_JD_REQ_SOFT_EXT_RES_MAP (MALI_JD_REQ_SOFT_JOB | 0xb)
  279. /**
  280. * SW only requirement: Unmap external resource
  281. *
  282. * This job requests external resource(s) are unmapped once the dependencies
  283. * of the job has been satisfied. The list of external resources are
  284. * passed via the jc element of the atom which is a pointer to a
  285. * @base_external_resource_list.
  286. */
  287. #define MALI_JD_REQ_SOFT_EXT_RES_UNMAP (MALI_JD_REQ_SOFT_JOB | 0xc)
  288. /**
  289. * HW Requirement: Requires Compute shaders (but not Vertex or Geometry Shaders)
  290. *
  291. * This indicates that the Job Chain contains Midgard Jobs of the 'Compute
  292. * Shaders' type.
  293. *
  294. * In contrast to @ref MALI_JD_REQ_CS, this does \b not indicate that the Job
  295. * Chain contains 'Geometry Shader' or 'Vertex Shader' jobs.
  296. */
  297. #define MALI_JD_REQ_ONLY_COMPUTE ((mali_jd_core_req)1 << 10)
  298. /**
  299. * HW Requirement: Use the mali_jd_atom::device_nr field to specify a
  300. * particular core group
  301. *
  302. * If both @ref MALI_JD_REQ_COHERENT_GROUP and this flag are set, this flag
  303. * takes priority
  304. *
  305. * This is only guaranteed to work for @ref MALI_JD_REQ_ONLY_COMPUTE atoms.
  306. *
  307. * If the core availability policy is keeping the required core group turned
  308. * off, then the job will fail with a @ref MALI_JD_EVENT_PM_EVENT error code.
  309. */
  310. #define MALI_JD_REQ_SPECIFIC_COHERENT_GROUP ((mali_jd_core_req)1 << 11)
  311. /**
  312. * SW Flag: If this bit is set then the successful completion of this atom
  313. * will not cause an event to be sent to userspace
  314. */
  315. #define MALI_JD_REQ_EVENT_ONLY_ON_FAILURE ((mali_jd_core_req)1 << 12)
  316. /**
  317. * SW Flag: If this bit is set then completion of this atom will not cause an
  318. * event to be sent to userspace, whether successful or not.
  319. */
  320. #define MALI_JD_REQ_EVENT_NEVER ((mali_jd_core_req)1 << 14)
  321. /**
  322. * SW Flag: Skip GPU cache clean and invalidation before starting a GPU job.
  323. *
  324. * If this bit is set then the GPU's cache will not be cleaned and invalidated
  325. * until a GPU job starts which does not have this bit set or a job completes
  326. * which does not have the @ref MALI_JD_REQ_SKIP_CACHE_END bit set. Do not use if
  327. * the CPU may have written to memory addressed by the job since the last job
  328. * without this bit set was submitted.
  329. */
  330. #define MALI_JD_REQ_SKIP_CACHE_START ((mali_jd_core_req)1 << 15)
  331. /**
  332. * SW Flag: Skip GPU cache clean and invalidation after a GPU job completes.
  333. *
  334. * If this bit is set then the GPU's cache will not be cleaned and invalidated
  335. * until a GPU job completes which does not have this bit set or a job starts
  336. * which does not have the @ref MALI_JD_REQ_SKIP_CACHE_START bti set. Do not
  337. * use if the CPU may read from or partially overwrite memory addressed by the
  338. * job before the next job without this bit set completes.
  339. */
  340. #define MALI_JD_REQ_SKIP_CACHE_END ((mali_jd_core_req)1 << 16)
  341. /**
  342. * These requirement bits are currently unused in mali_jd_core_req
  343. */
  344. #define MALIP_JD_REQ_RESERVED \
  345. (~(MALI_JD_REQ_ATOM_TYPE | MALI_JD_REQ_EXTERNAL_RESOURCES | \
  346. MALI_JD_REQ_EVENT_ONLY_ON_FAILURE | MALIP_JD_REQ_EVENT_NEVER | \
  347. MALI_JD_REQ_EVENT_COALESCE | \
  348. MALI_JD_REQ_COHERENT_GROUP | MALI_JD_REQ_SPECIFIC_COHERENT_GROUP | \
  349. MALI_JD_REQ_FS_AFBC | MALI_JD_REQ_PERMON | \
  350. MALI_JD_REQ_SKIP_CACHE_START | MALI_JD_REQ_SKIP_CACHE_END))
  351. /**
  352. * Mask of all bits in mali_jd_core_req that control the type of the atom.
  353. *
  354. * This allows dependency only atoms to have flags set
  355. */
  356. #define MALI_JD_REQ_ATOM_TYPE \
  357. (MALI_JD_REQ_FS | MALI_JD_REQ_CS | MALI_JD_REQ_T | MALI_JD_REQ_CF | \
  358. MALI_JD_REQ_V | MALI_JD_REQ_SOFT_JOB | MALI_JD_REQ_ONLY_COMPUTE)
  359. /**
  360. * Mask of all bits in mali_jd_core_req that control the type of a soft job.
  361. */
  362. #define MALI_JD_REQ_SOFT_JOB_TYPE (MALI_JD_REQ_SOFT_JOB | 0x1f)
  363. /*
  364. * Returns non-zero value if core requirements passed define a soft job or
  365. * a dependency only job.
  366. */
  367. #define MALI_JD_REQ_SOFT_JOB_OR_DEP(core_req) \
  368. ((core_req & MALI_JD_REQ_SOFT_JOB) || \
  369. (core_req & MALI_JD_REQ_ATOM_TYPE) == MALI_JD_REQ_DEP)
  370. struct mali_gpu_core_props {
  371. /**
  372. * Product specific value.
  373. */
  374. u32 product_id;
  375. /**
  376. * Status of the GPU release.
  377. * No defined values, but starts at 0 and increases by one for each
  378. * release status (alpha, beta, EAC, etc.).
  379. * 4 bit values (0-15).
  380. */
  381. u16 version_status;
  382. /**
  383. * Minor release number of the GPU. "P" part of an "RnPn" release
  384. * number.
  385. * 8 bit values (0-255).
  386. */
  387. u16 minor_revision;
  388. /**
  389. * Major release number of the GPU. "R" part of an "RnPn" release
  390. * number.
  391. * 4 bit values (0-15).
  392. */
  393. u16 major_revision;
  394. u16 :16;
  395. /**
  396. * @usecase GPU clock speed is not specified in the Midgard
  397. * Architecture, but is <b>necessary for OpenCL's clGetDeviceInfo()
  398. * function</b>.
  399. */
  400. u32 gpu_speed_mhz;
  401. /**
  402. * @usecase GPU clock max/min speed is required for computing
  403. * best/worst case in tasks as job scheduling ant irq_throttling. (It
  404. * is not specified in the Midgard Architecture).
  405. */
  406. u32 gpu_freq_khz_max;
  407. u32 gpu_freq_khz_min;
  408. /**
  409. * Size of the shader program counter, in bits.
  410. */
  411. u32 log2_program_counter_size;
  412. /**
  413. * TEXTURE_FEATURES_x registers, as exposed by the GPU. This is a
  414. * bitpattern where a set bit indicates that the format is supported.
  415. *
  416. * Before using a texture format, it is recommended that the
  417. * corresponding bit be checked.
  418. */
  419. u32 texture_features[MALI_GPU_NUM_TEXTURE_FEATURES_REGISTERS];
  420. /**
  421. * Theoretical maximum memory available to the GPU. It is unlikely
  422. * that a client will be able to allocate all of this memory for their
  423. * own purposes, but this at least provides an upper bound on the
  424. * memory available to the GPU.
  425. *
  426. * This is required for OpenCL's clGetDeviceInfo() call when
  427. * CL_DEVICE_GLOBAL_MEM_SIZE is requested, for OpenCL GPU devices. The
  428. * client will not be expecting to allocate anywhere near this value.
  429. */
  430. u64 gpu_available_memory_size;
  431. };
  432. struct mali_gpu_l2_cache_props {
  433. u8 log2_line_size;
  434. u8 log2_cache_size;
  435. u8 num_l2_slices; /* Number of L2C slices. 1 or higher */
  436. u64 :40;
  437. };
  438. struct mali_gpu_tiler_props {
  439. u32 bin_size_bytes; /* Max is 4*2^15 */
  440. u32 max_active_levels; /* Max is 2^15 */
  441. };
  442. struct mali_gpu_thread_props {
  443. u32 max_threads; /* Max. number of threads per core */
  444. u32 max_workgroup_size; /* Max. number of threads per workgroup */
  445. u32 max_barrier_size; /* Max. number of threads that can
  446. synchronize on a simple barrier */
  447. u16 max_registers; /* Total size [1..65535] of the register
  448. file available per core. */
  449. u8 max_task_queue; /* Max. tasks [1..255] which may be sent
  450. to a core before it becomes blocked. */
  451. u8 max_thread_group_split; /* Max. allowed value [1..15] of the
  452. Thread Group Split field. */
  453. enum {
  454. MALI_GPU_IMPLEMENTATION_UNKNOWN = 0,
  455. MALI_GPU_IMPLEMENTATION_SILICON = 1,
  456. MALI_GPU_IMPLEMENTATION_FPGA = 2,
  457. MALI_GPU_IMPLEMENTATION_SW = 3,
  458. } impl_tech :8;
  459. u64 :56;
  460. };
  461. /**
  462. * @brief descriptor for a coherent group
  463. *
  464. * \c core_mask exposes all cores in that coherent group, and \c num_cores
  465. * provides a cached population-count for that mask.
  466. *
  467. * @note Whilst all cores are exposed in the mask, not all may be available to
  468. * the application, depending on the Kernel Power policy.
  469. *
  470. * @note if u64s must be 8-byte aligned, then this structure has 32-bits of
  471. * wastage.
  472. */
  473. struct mali_ioctl_gpu_coherent_group {
  474. u64 core_mask; /**< Core restriction mask required for the
  475. group */
  476. u16 num_cores; /**< Number of cores in the group */
  477. u64 :48;
  478. };
  479. /**
  480. * @brief Coherency group information
  481. *
  482. * Note that the sizes of the members could be reduced. However, the \c group
  483. * member might be 8-byte aligned to ensure the u64 core_mask is 8-byte
  484. * aligned, thus leading to wastage if the other members sizes were reduced.
  485. *
  486. * The groups are sorted by core mask. The core masks are non-repeating and do
  487. * not intersect.
  488. */
  489. struct mali_gpu_coherent_group_info {
  490. u32 num_groups;
  491. /**
  492. * Number of core groups (coherent or not) in the GPU. Equivalent to
  493. * the number of L2 Caches.
  494. *
  495. * The GPU Counter dumping writes 2048 bytes per core group,
  496. * regardless of whether the core groups are coherent or not. Hence
  497. * this member is needed to calculate how much memory is required for
  498. * dumping.
  499. *
  500. * @note Do not use it to work out how many valid elements are in the
  501. * group[] member. Use num_groups instead.
  502. */
  503. u32 num_core_groups;
  504. /**
  505. * Coherency features of the memory, accessed by @ref gpu_mem_features
  506. * methods
  507. */
  508. u32 coherency;
  509. u32 :32;
  510. /**
  511. * Descriptors of coherent groups
  512. */
  513. struct mali_ioctl_gpu_coherent_group group[MALI_MAX_COHERENT_GROUPS];
  514. };
  515. /**
  516. * A complete description of the GPU's Hardware Configuration Discovery
  517. * registers.
  518. *
  519. * The information is presented inefficiently for access. For frequent access,
  520. * the values should be better expressed in an unpacked form in the
  521. * base_gpu_props structure.
  522. *
  523. * @usecase The raw properties in @ref gpu_raw_gpu_props are necessary to
  524. * allow a user of the Mali Tools (e.g. PAT) to determine "Why is this device
  525. * behaving differently?". In this case, all information about the
  526. * configuration is potentially useful, but it <b>does not need to be processed
  527. * by the driver</b>. Instead, the raw registers can be processed by the Mali
  528. * Tools software on the host PC.
  529. *
  530. */
  531. struct mali_gpu_raw_props {
  532. u64 shader_present;
  533. u64 tiler_present;
  534. u64 l2_present;
  535. u64 stack_present;
  536. u32 l2_features;
  537. u32 suspend_size; /* API 8.2+ */
  538. u32 mem_features;
  539. u32 mmu_features;
  540. u32 as_present;
  541. u32 js_present;
  542. u32 js_features[MALI_GPU_MAX_JOB_SLOTS];
  543. u32 tiler_features;
  544. u32 texture_features[3];
  545. u32 gpu_id;
  546. u32 thread_max_threads;
  547. u32 thread_max_workgroup_size;
  548. u32 thread_max_barrier_size;
  549. u32 thread_features;
  550. /*
  551. * Note: This is the _selected_ coherency mode rather than the
  552. * available modes as exposed in the coherency_features register.
  553. */
  554. u32 coherency_mode;
  555. };
  556. /*
  557. * The original mali driver from ARM has 64 bit memory pointers in most of the
  558. * ioctls argument structures, regardless of whether or not the system is 32
  559. * bit or 64 bit. For 32 bit systems, the upper 32 bits are ignored
  560. *
  561. * FIXME: confirm this actually works
  562. */
  563. #ifdef __LP64__
  564. #define PAD_PTR(p) p
  565. #else
  566. #define PAD_PTR(p) p; u32 :32
  567. #endif
  568. /* FIXME: Again, they don't specify any of these as packed structs. However,
  569. * looking at these structs I'm worried that there is already spots where the
  570. * compiler is potentially sticking in padding...
  571. * Going to try something a little crazy, and just hope that our compiler
  572. * happens to add the same kind of offsets since we can't really compare sizes
  573. */
  574. /*
  575. * Blob provided by the driver to store callback driver, not actually modified
  576. * by the driver itself
  577. */
  578. struct mali_jd_udata {
  579. u64 blob[2];
  580. };
  581. struct mali_jd_dependency {
  582. mali_atom_id atom_id; /**< An atom number */
  583. mali_jd_dep_type dependency_type; /**< Dependency type */
  584. };
  585. #define MALI_EXT_RES_MAX 10
  586. /* The original header never explicitly defines any values for these. In C,
  587. * this -should- expand to SHARED == 0 and EXCLUSIVE == 1, so the only flag we
  588. * actually need to decode here is EXCLUSIVE
  589. */
  590. enum mali_external_resource_access {
  591. MALI_EXT_RES_ACCESS_SHARED,
  592. MALI_EXT_RES_ACCESS_EXCLUSIVE,
  593. };
  594. struct mali_external_resource {
  595. /*
  596. * Lyude:
  597. * At first I thought this might be the count for what could be in
  598. * ext_resource, but it looks like there's not really a reason for
  599. * ext_resource being an array with a length of one?
  600. * Maybe this is some weird compatibility crap...
  601. *
  602. * (source for this from original kdriver: mali_kbase_jd.c)
  603. */
  604. u64 count;
  605. u64 ext_resource[1];
  606. };
  607. struct mali_jd_atom_v2 {
  608. u64 jc; /**< job-chain GPU address */
  609. struct mali_jd_udata udata; /**< user data */
  610. PAD_PTR(struct mali_external_resource *ext_res_list); /**< list of external resources */
  611. u16 nr_ext_res; /**< nr of external resources */
  612. u16 compat_core_req; /**< core requirements which
  613. correspond to the legacy support
  614. for UK 10.2 */
  615. struct mali_jd_dependency pre_dep[2]; /**< pre-dependencies, one need to
  616. use SETTER function to assign
  617. this field, this is done in
  618. order to reduce possibility of
  619. improper assigment of a
  620. dependency field */
  621. mali_atom_id atom_number; /**< unique number to identify the
  622. atom */
  623. mali_jd_prio prio; /**< Atom priority. Refer to @ref
  624. mali_jd_prio for more details */
  625. u8 device_nr; /**< coregroup when
  626. BASE_JD_REQ_SPECIFIC_COHERENT_GROUP
  627. specified */
  628. u8 :8;
  629. mali_jd_core_req core_req; /**< core requirements */
  630. } __attribute__((packed));
  631. ASSERT_SIZEOF_TYPE(struct mali_jd_atom_v2, 48);
  632. /**
  633. * Header used by all ioctls
  634. */
  635. union mali_ioctl_header {
  636. /* [in] The ID of the UK function being called */
  637. u32 id :32;
  638. /* [out] The return value of the UK function that was called */
  639. u32 rc :32;
  640. u64 :64;
  641. } __attribute__((packed));
  642. ASSERT_SIZEOF_TYPE(union mali_ioctl_header, 8);
  643. struct mali_ioctl_get_version {
  644. union mali_ioctl_header header;
  645. u16 major; /* [out] */
  646. u16 minor; /* [out] */
  647. u32 :32;
  648. } __attribute__((packed));
  649. ASSERT_SIZEOF_TYPE(struct mali_ioctl_get_version, 16);
  650. struct mali_ioctl_mem_alloc {
  651. union mali_ioctl_header header;
  652. /* [in] */
  653. u64 va_pages;
  654. u64 commit_pages;
  655. u64 extent;
  656. /* [in/out] */
  657. u64 flags;
  658. /* [out] */
  659. u64 gpu_va;
  660. u16 va_alignment;
  661. u32 :32;
  662. u16 :16;
  663. } __attribute__((packed));
  664. ASSERT_SIZEOF_TYPE(struct mali_ioctl_mem_alloc, 56);
  665. struct mali_ioctl_mem_import {
  666. union mali_ioctl_header header;
  667. /* [in] */
  668. u64 phandle;
  669. enum {
  670. MALI_MEM_IMPORT_TYPE_INVALID = 0,
  671. MALI_MEM_IMPORT_TYPE_UMP = 1,
  672. MALI_MEM_IMPORT_TYPE_UMM = 2,
  673. MALI_MEM_IMPORT_TYPE_USER_BUFFER = 3,
  674. } type :32;
  675. u32 :32;
  676. /* [in/out] */
  677. u64 flags;
  678. /* [out] */
  679. u64 gpu_va;
  680. u64 va_pages;
  681. } __attribute__((packed));
  682. /* FIXME: Size unconfirmed (haven't seen in a trace yet) */
  683. struct mali_ioctl_mem_commit {
  684. union mali_ioctl_header header;
  685. /* [in] */
  686. u64 gpu_addr;
  687. u64 pages;
  688. /* [out] */
  689. u32 result_subcode;
  690. u32 :32;
  691. } __attribute__((packed));
  692. ASSERT_SIZEOF_TYPE(struct mali_ioctl_mem_commit, 32);
  693. struct mali_ioctl_mem_query {
  694. union mali_ioctl_header header;
  695. /* [in] */
  696. u64 gpu_addr;
  697. enum {
  698. MALI_MEM_QUERY_COMMIT_SIZE = 1,
  699. MALI_MEM_QUERY_VA_SIZE = 2,
  700. MALI_MEM_QUERY_FLAGS = 3
  701. } query :32;
  702. u32 :32;
  703. /* [out] */
  704. u64 value;
  705. } __attribute__((packed));
  706. ASSERT_SIZEOF_TYPE(struct mali_ioctl_mem_query, 32);
  707. struct mali_ioctl_mem_free {
  708. union mali_ioctl_header header;
  709. u64 gpu_addr; /* [in] */
  710. } __attribute__((packed));
  711. /* FIXME: Size unconfirmed (haven't seen in a trace yet) */
  712. struct mali_ioctl_mem_flags_change {
  713. union mali_ioctl_header header;
  714. /* [in] */
  715. u64 gpu_va;
  716. u64 flags;
  717. u64 mask;
  718. } __attribute__((packed));
  719. /* FIXME: Size unconfirmed (haven't seen in a trace yet) */
  720. struct mali_ioctl_mem_alias {
  721. union mali_ioctl_header header;
  722. /* [in/out] */
  723. u64 flags;
  724. /* [in] */
  725. u64 stride;
  726. u64 nents;
  727. u64 ai;
  728. /* [out] */
  729. u64 gpu_va;
  730. u64 va_pages;
  731. } __attribute__((packed));
  732. struct mali_ioctl_sync {
  733. union mali_ioctl_header header;
  734. u64 handle;
  735. PAD_PTR(void* user_addr);
  736. u64 size;
  737. enum {
  738. MALI_SYNC_TO_DEVICE = (1 << 0),
  739. MALI_SYNC_TO_CPU = (1 << 1),
  740. } type :8;
  741. u64 :56;
  742. } __attribute__((packed));
  743. ASSERT_SIZEOF_TYPE(struct mali_ioctl_sync, 40);
  744. struct mali_ioctl_gpu_props_reg_dump {
  745. union mali_ioctl_header header;
  746. struct mali_gpu_core_props core;
  747. struct mali_gpu_l2_cache_props l2;
  748. u64 :64;
  749. struct mali_gpu_tiler_props tiler;
  750. struct mali_gpu_thread_props thread;
  751. struct mali_gpu_raw_props raw;
  752. /** This must be last member of the structure */
  753. struct mali_gpu_coherent_group_info coherency_info;
  754. } __attribute__((packed));
  755. ASSERT_SIZEOF_TYPE(struct mali_ioctl_gpu_props_reg_dump, 536);
  756. struct mali_ioctl_set_flags {
  757. union mali_ioctl_header header;
  758. #define MALI_CONTEXT_CREATE_FLAG_NONE 0
  759. u32 create_flags; /* [in] */
  760. u32 :32;
  761. } __attribute__((packed));
  762. ASSERT_SIZEOF_TYPE(struct mali_ioctl_set_flags, 16);
  763. struct mali_ioctl_stream_create {
  764. union mali_ioctl_header header;
  765. /* [in] */
  766. char name[32];
  767. /* [out] */
  768. s32 fd;
  769. u32 :32;
  770. } __attribute__((packed));
  771. ASSERT_SIZEOF_TYPE(struct mali_ioctl_stream_create, 48);
  772. struct mali_ioctl_job_submit {
  773. union mali_ioctl_header header;
  774. /* [in] */
  775. PAD_PTR(struct mali_jd_atom_v2 *addr);
  776. u32 nr_atoms;
  777. u32 stride;
  778. } __attribute__((packed));
  779. ASSERT_SIZEOF_TYPE(struct mali_ioctl_job_submit, 24);
  780. struct mali_ioctl_get_context_id {
  781. union mali_ioctl_header header;
  782. /* [out] */
  783. s64 id;
  784. } __attribute__((packed));
  785. ASSERT_SIZEOF_TYPE(struct mali_ioctl_get_context_id, 16);
  786. #undef PAD_PTR
  787. /* For ioctl's we haven't written decoding stuff for yet */
  788. typedef struct {
  789. union mali_ioctl_header header;
  790. } __ioctl_placeholder;
  791. #define MALI_IOCTL_TYPE_BASE 0x80
  792. #define MALI_IOCTL_TYPE_MAX 0x82
  793. #define MALI_IOCTL_TYPE_COUNT (MALI_IOCTL_TYPE_MAX - MALI_IOCTL_TYPE_BASE + 1)
  794. #define MALI_IOCTL_GET_VERSION (_IOWR(0x80, 0, struct mali_ioctl_get_version))
  795. #define MALI_IOCTL_MEM_ALLOC (_IOWR(0x82, 0, struct mali_ioctl_mem_alloc))
  796. #define MALI_IOCTL_MEM_IMPORT (_IOWR(0x82, 1, struct mali_ioctl_mem_import))
  797. #define MALI_IOCTL_MEM_COMMIT (_IOWR(0x82, 2, struct mali_ioctl_mem_commit))
  798. #define MALI_IOCTL_MEM_QUERY (_IOWR(0x82, 3, struct mali_ioctl_mem_query))
  799. #define MALI_IOCTL_MEM_FREE (_IOWR(0x82, 4, struct mali_ioctl_mem_free))
  800. #define MALI_IOCTL_MEM_FLAGS_CHANGE (_IOWR(0x82, 5, struct mali_ioctl_mem_flags_change))
  801. #define MALI_IOCTL_MEM_ALIAS (_IOWR(0x82, 6, struct mali_ioctl_mem_alias))
  802. #define MALI_IOCTL_SYNC (_IOWR(0x82, 8, struct mali_ioctl_sync))
  803. #define MALI_IOCTL_POST_TERM (_IOWR(0x82, 9, __ioctl_placeholder))
  804. #define MALI_IOCTL_HWCNT_SETUP (_IOWR(0x82, 10, __ioctl_placeholder))
  805. #define MALI_IOCTL_HWCNT_DUMP (_IOWR(0x82, 11, __ioctl_placeholder))
  806. #define MALI_IOCTL_HWCNT_CLEAR (_IOWR(0x82, 12, __ioctl_placeholder))
  807. #define MALI_IOCTL_GPU_PROPS_REG_DUMP (_IOWR(0x82, 14, struct mali_ioctl_gpu_props_reg_dump))
  808. #define MALI_IOCTL_FIND_CPU_OFFSET (_IOWR(0x82, 15, __ioctl_placeholder))
  809. #define MALI_IOCTL_GET_VERSION_NEW (_IOWR(0x82, 16, struct mali_ioctl_get_version))
  810. #define MALI_IOCTL_SET_FLAGS (_IOWR(0x82, 18, struct mali_ioctl_set_flags))
  811. #define MALI_IOCTL_SET_TEST_DATA (_IOWR(0x82, 19, __ioctl_placeholder))
  812. #define MALI_IOCTL_INJECT_ERROR (_IOWR(0x82, 20, __ioctl_placeholder))
  813. #define MALI_IOCTL_MODEL_CONTROL (_IOWR(0x82, 21, __ioctl_placeholder))
  814. #define MALI_IOCTL_KEEP_GPU_POWERED (_IOWR(0x82, 22, __ioctl_placeholder))
  815. #define MALI_IOCTL_FENCE_VALIDATE (_IOWR(0x82, 23, __ioctl_placeholder))
  816. #define MALI_IOCTL_STREAM_CREATE (_IOWR(0x82, 24, struct mali_ioctl_stream_create))
  817. #define MALI_IOCTL_GET_PROFILING_CONTROLS (_IOWR(0x82, 25, __ioctl_placeholder))
  818. #define MALI_IOCTL_SET_PROFILING_CONTROLS (_IOWR(0x82, 26, __ioctl_placeholder))
  819. #define MALI_IOCTL_DEBUGFS_MEM_PROFILE_ADD (_IOWR(0x82, 27, __ioctl_placeholder))
  820. #define MALI_IOCTL_JOB_SUBMIT (_IOWR(0x82, 28, struct mali_ioctl_job_submit))
  821. #define MALI_IOCTL_DISJOINT_QUERY (_IOWR(0x82, 29, __ioctl_placeholder))
  822. #define MALI_IOCTL_GET_CONTEXT_ID (_IOWR(0x82, 31, struct mali_ioctl_get_context_id))
  823. #define MALI_IOCTL_TLSTREAM_ACQUIRE_V10_4 (_IOWR(0x82, 32, __ioctl_placeholder))
  824. #define MALI_IOCTL_TLSTREAM_TEST (_IOWR(0x82, 33, __ioctl_placeholder))
  825. #define MALI_IOCTL_TLSTREAM_STATS (_IOWR(0x82, 34, __ioctl_placeholder))
  826. #define MALI_IOCTL_TLSTREAM_FLUSH (_IOWR(0x82, 35, __ioctl_placeholder))
  827. #define MALI_IOCTL_HWCNT_READER_SETUP (_IOWR(0x82, 36, __ioctl_placeholder))
  828. #define MALI_IOCTL_SET_PRFCNT_VALUES (_IOWR(0x82, 37, __ioctl_placeholder))
  829. #define MALI_IOCTL_SOFT_EVENT_UPDATE (_IOWR(0x82, 38, __ioctl_placeholder))
  830. #define MALI_IOCTL_MEM_JIT_INIT (_IOWR(0x82, 39, __ioctl_placeholder))
  831. #define MALI_IOCTL_TLSTREAM_ACQUIRE (_IOWR(0x82, 40, __ioctl_placeholder))
  832. #endif /* __MALI_IOCTL_H__ */