mali_pp_job.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * This confidential and proprietary software may be used only as
  3. * authorised by a licensing agreement from ARM Limited
  4. * (C) COPYRIGHT 2011-2013 ARM Limited
  5. * ALL RIGHTS RESERVED
  6. * The entire notice above must be reproduced on all authorised
  7. * copies and copies may only be made to the extent permitted
  8. * by a licensing agreement from ARM Limited.
  9. */
  10. #ifndef __MALI_PP_JOB_H__
  11. #define __MALI_PP_JOB_H__
  12. #include "mali_osk.h"
  13. #include "mali_osk_list.h"
  14. #include "mali_uk_types.h"
  15. #include "mali_session.h"
  16. #include "mali_kernel_common.h"
  17. #include "regs/mali_200_regs.h"
  18. #include "mali_kernel_core.h"
  19. #include "mali_dma.h"
  20. #include "mali_dlbu.h"
  21. #include "mali_timeline.h"
  22. #if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
  23. #include "linux/mali_memory_dma_buf.h"
  24. #endif
  25. /**
  26. * The structure represents a PP job, including all sub-jobs
  27. * (This struct unfortunately needs to be public because of how the _mali_osk_list_*
  28. * mechanism works)
  29. */
  30. struct mali_pp_job {
  31. _mali_osk_list_t list; /**< Used to link jobs together in the scheduler queue */
  32. struct mali_session_data *session; /**< Session which submitted this job */
  33. _mali_osk_list_t session_list; /**< Used to link jobs together in the session job list */
  34. _mali_osk_list_t session_fb_lookup_list; /**< Used to link jobs together from the same frame builder in the session */
  35. _mali_uk_pp_start_job_s uargs; /**< Arguments from user space */
  36. mali_dma_cmd_buf dma_cmd_buf; /**< Command buffer for starting job using Mali-450 DMA unit */
  37. u32 id; /**< Identifier for this job in kernel space (sequential numbering) */
  38. u32 cache_order; /**< Cache order used for L2 cache flushing (sequential numbering) */
  39. u32 perf_counter_value0[_MALI_PP_MAX_SUB_JOBS]; /**< Value of performance counter 0 (to be returned to user space), one for each sub job */
  40. u32 perf_counter_value1[_MALI_PP_MAX_SUB_JOBS]; /**< Value of performance counter 1 (to be returned to user space), one for each sub job */
  41. u32 sub_jobs_num; /**< Number of subjobs; set to 1 for Mali-450 if DLBU is used, otherwise equals number of PP cores */
  42. u32 sub_jobs_started; /**< Total number of sub-jobs started (always started in ascending order) */
  43. u32 sub_jobs_completed; /**< Number of completed sub-jobs in this superjob */
  44. u32 sub_job_errors; /**< Bitfield with errors (errors for each single sub-job is or'ed together) */
  45. u32 pid; /**< Process ID of submitting process */
  46. u32 tid; /**< Thread ID of submitting thread */
  47. _mali_osk_notification_t *finished_notification; /**< Notification sent back to userspace on job complete */
  48. u32 num_memory_cookies; /**< Number of memory cookies attached to job */
  49. u32 *memory_cookies; /**< Memory cookies attached to job */
  50. #if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
  51. struct mali_dma_buf_attachment **dma_bufs; /**< Array of DMA-bufs used by job */
  52. u32 num_dma_bufs; /**< Number of DMA-bufs used by job */
  53. #endif
  54. struct mali_timeline_tracker tracker; /**< Timeline tracker for this job */
  55. u32 perf_counter_per_sub_job_count; /**< Number of values in the two arrays which is != MALI_HW_CORE_NO_COUNTER */
  56. u32 perf_counter_per_sub_job_src0[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src0 */
  57. u32 perf_counter_per_sub_job_src1[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src1 */
  58. };
  59. void mali_pp_job_initialize(void);
  60. void mali_pp_job_terminate(void);
  61. struct mali_pp_job *mali_pp_job_create(struct mali_session_data *session, _mali_uk_pp_start_job_s *uargs, u32 id);
  62. void mali_pp_job_delete(struct mali_pp_job *job);
  63. u32 mali_pp_job_get_perf_counter_src0(struct mali_pp_job *job, u32 sub_job);
  64. u32 mali_pp_job_get_perf_counter_src1(struct mali_pp_job *job, u32 sub_job);
  65. void mali_pp_job_set_pp_counter_global_src0(u32 counter);
  66. void mali_pp_job_set_pp_counter_global_src1(u32 counter);
  67. void mali_pp_job_set_pp_counter_sub_job_src0(u32 sub_job, u32 counter);
  68. void mali_pp_job_set_pp_counter_sub_job_src1(u32 sub_job, u32 counter);
  69. u32 mali_pp_job_get_pp_counter_global_src0(void);
  70. u32 mali_pp_job_get_pp_counter_global_src1(void);
  71. u32 mali_pp_job_get_pp_counter_sub_job_src0(u32 sub_job);
  72. u32 mali_pp_job_get_pp_counter_sub_job_src1(u32 sub_job);
  73. MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
  74. {
  75. return (NULL == job) ? 0 : job->id;
  76. }
  77. MALI_STATIC_INLINE u32 mali_pp_job_get_cache_order(struct mali_pp_job *job)
  78. {
  79. return (NULL == job) ? 0 : job->cache_order;
  80. }
  81. MALI_STATIC_INLINE u32 mali_pp_job_get_user_id(struct mali_pp_job *job)
  82. {
  83. return job->uargs.user_job_ptr;
  84. }
  85. MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
  86. {
  87. return job->uargs.frame_builder_id;
  88. }
  89. MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
  90. {
  91. return job->uargs.flush_id;
  92. }
  93. MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
  94. {
  95. return job->pid;
  96. }
  97. MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
  98. {
  99. return job->tid;
  100. }
  101. MALI_STATIC_INLINE u32* mali_pp_job_get_frame_registers(struct mali_pp_job *job)
  102. {
  103. return job->uargs.frame_registers;
  104. }
  105. MALI_STATIC_INLINE u32* mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
  106. {
  107. return job->uargs.dlbu_registers;
  108. }
  109. MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
  110. {
  111. #if (defined(CONFIG_MALI450) || defined(CONFIG_MALI470))
  112. MALI_DEBUG_ASSERT_POINTER(job);
  113. return 0 == job->uargs.num_cores;
  114. #else
  115. return MALI_FALSE;
  116. #endif
  117. }
  118. MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
  119. {
  120. if (mali_pp_job_is_virtual(job)) {
  121. return MALI_DLBU_VIRT_ADDR;
  122. } else if (0 == sub_job) {
  123. return job->uargs.frame_registers[MALI200_REG_ADDR_FRAME / sizeof(u32)];
  124. } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
  125. return job->uargs.frame_registers_addr_frame[sub_job - 1];
  126. }
  127. return 0;
  128. }
  129. MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
  130. {
  131. if (0 == sub_job) {
  132. return job->uargs.frame_registers[MALI200_REG_ADDR_STACK / sizeof(u32)];
  133. } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
  134. return job->uargs.frame_registers_addr_stack[sub_job - 1];
  135. }
  136. return 0;
  137. }
  138. MALI_STATIC_INLINE u32* mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
  139. {
  140. return job->uargs.wb0_registers;
  141. }
  142. MALI_STATIC_INLINE u32* mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
  143. {
  144. return job->uargs.wb1_registers;
  145. }
  146. MALI_STATIC_INLINE u32* mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
  147. {
  148. return job->uargs.wb2_registers;
  149. }
  150. MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
  151. {
  152. job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
  153. }
  154. MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
  155. {
  156. job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
  157. }
  158. MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
  159. {
  160. job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
  161. }
  162. MALI_STATIC_INLINE mali_bool mali_pp_job_all_writeback_unit_disabled(struct mali_pp_job *job)
  163. {
  164. MALI_DEBUG_ASSERT_POINTER(job);
  165. if ( job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
  166. job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
  167. job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT]
  168. ) {
  169. /* At least one output unit active */
  170. return MALI_FALSE;
  171. }
  172. /* All outputs are disabled - we can abort the job */
  173. return MALI_TRUE;
  174. }
  175. MALI_STATIC_INLINE u32 mali_pp_job_get_fb_lookup_id(struct mali_pp_job *job)
  176. {
  177. MALI_DEBUG_ASSERT_POINTER(job);
  178. return MALI_PP_JOB_FB_LOOKUP_LIST_MASK & job->uargs.frame_builder_id;
  179. }
  180. MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
  181. {
  182. return job->session;
  183. }
  184. MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
  185. {
  186. return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
  187. }
  188. /* Function used when we are terminating a session with jobs. Return TRUE if it has a rendering job.
  189. Makes sure that no new subjobs are started. */
  190. MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_failed(struct mali_pp_job *job)
  191. {
  192. u32 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
  193. job->sub_jobs_started += jobs_remaining;
  194. job->sub_jobs_completed += jobs_remaining;
  195. job->sub_job_errors += jobs_remaining;
  196. }
  197. MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_success(struct mali_pp_job *job)
  198. {
  199. u32 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
  200. job->sub_jobs_started += jobs_remaining;
  201. job->sub_jobs_completed += jobs_remaining;
  202. }
  203. MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
  204. {
  205. return (job->sub_jobs_num == job->sub_jobs_completed) ? MALI_TRUE : MALI_FALSE;
  206. }
  207. MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
  208. {
  209. return job->sub_jobs_started;
  210. }
  211. MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
  212. {
  213. return job->sub_jobs_num;
  214. }
  215. MALI_STATIC_INLINE mali_bool mali_pp_job_needs_dma_buf_mapping(struct mali_pp_job *job)
  216. {
  217. MALI_DEBUG_ASSERT(job);
  218. if (0 != job->num_memory_cookies) {
  219. return MALI_TRUE;
  220. }
  221. return MALI_FALSE;
  222. }
  223. MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
  224. {
  225. MALI_DEBUG_ASSERT_POINTER(job);
  226. /* Assert that we are marking the "first unstarted sub job" as started */
  227. MALI_DEBUG_ASSERT(job->sub_jobs_started == sub_job);
  228. job->sub_jobs_started++;
  229. }
  230. MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
  231. {
  232. job->sub_jobs_completed++;
  233. if ( MALI_FALSE == success ) {
  234. job->sub_job_errors++;
  235. }
  236. }
  237. MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
  238. {
  239. if ( 0 == job->sub_job_errors ) {
  240. return MALI_TRUE;
  241. }
  242. return MALI_FALSE;
  243. }
  244. MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(struct mali_pp_job *job)
  245. {
  246. return job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION ? MALI_TRUE : MALI_FALSE;
  247. }
  248. MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
  249. {
  250. return job->uargs.perf_counter_flag;
  251. }
  252. MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
  253. {
  254. return job->perf_counter_value0[sub_job];
  255. }
  256. MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
  257. {
  258. return job->perf_counter_value1[sub_job];
  259. }
  260. MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
  261. {
  262. job->perf_counter_value0[sub_job] = value;
  263. }
  264. MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
  265. {
  266. job->perf_counter_value1[sub_job] = value;
  267. }
  268. MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
  269. {
  270. if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1) {
  271. return _MALI_OSK_ERR_FAULT;
  272. }
  273. return _MALI_OSK_ERR_OK;
  274. }
  275. /**
  276. * Returns MALI_TRUE if first job should be started after second job.
  277. *
  278. * @param first First job.
  279. * @param second Second job.
  280. * @return MALI_TRUE if first job should be started after second job, MALI_FALSE if not.
  281. */
  282. MALI_STATIC_INLINE mali_bool mali_pp_job_should_start_after(struct mali_pp_job *first, struct mali_pp_job *second)
  283. {
  284. MALI_DEBUG_ASSERT_POINTER(first);
  285. MALI_DEBUG_ASSERT_POINTER(second);
  286. /* First job should be started after second job if second job is in progress. */
  287. if (0 < second->sub_jobs_started) {
  288. return MALI_TRUE;
  289. }
  290. /* First job should be started after second job if first job has a higher job id. A span is
  291. used to handle job id wrapping. */
  292. if ((mali_pp_job_get_id(first) - mali_pp_job_get_id(second)) < MALI_SCHEDULER_JOB_ID_SPAN) {
  293. return MALI_TRUE;
  294. }
  295. /* Second job should be started after first job. */
  296. return MALI_FALSE;
  297. }
  298. /**
  299. * Returns MALI_TRUE if this job has more than two sub jobs and all sub jobs are unstarted.
  300. *
  301. * @param job Job to check.
  302. * @return MALI_TRUE if job has more than two sub jobs and all sub jobs are unstarted, MALI_FALSE if not.
  303. */
  304. MALI_STATIC_INLINE mali_bool mali_pp_job_is_large_and_unstarted(struct mali_pp_job *job)
  305. {
  306. MALI_DEBUG_ASSERT_POINTER(job);
  307. MALI_DEBUG_ASSERT(!mali_pp_job_is_virtual(job));
  308. return (0 == job->sub_jobs_started && 2 < job->sub_jobs_num);
  309. }
  310. /**
  311. * Get PP job's Timeline tracker.
  312. *
  313. * @param job PP job.
  314. * @return Pointer to Timeline tracker for the job.
  315. */
  316. MALI_STATIC_INLINE struct mali_timeline_tracker *mali_pp_job_get_tracker(struct mali_pp_job *job)
  317. {
  318. MALI_DEBUG_ASSERT_POINTER(job);
  319. return &(job->tracker);
  320. }
  321. #endif /* __MALI_PP_JOB_H__ */