2 * Copyright (C) 2011-2015 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
11 #ifndef __MALI_PP_JOB_H__
12 #define __MALI_PP_JOB_H__
15 #include "mali_osk_list.h"
16 #include "mali_uk_types.h"
17 #include "mali_session.h"
18 #include "mali_kernel_common.h"
19 #include "regs/mali_200_regs.h"
20 #include "mali_kernel_core.h"
21 #include "mali_dlbu.h"
22 #include "mali_timeline.h"
23 #include "mali_scheduler.h"
24 #include "mali_executor.h"
25 #if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
26 #include "linux/mali_memory_dma_buf.h"
29 typedef enum pp_job_status {
36 * This structure represents a PP job, including all sub jobs.
38 * The PP job object itself is not protected by any single lock,
39 * but relies on other locks instead (scheduler, executor and timeline lock).
40 * Think of the job object as moving between these sub systems through-out
41 * its lifetime. Different part of the PP job struct is used by different
42 * subsystems. Accessor functions ensure that correct lock is taken.
43 * Do NOT access any data members directly from outside this module!
47 * These members are typically only set at creation,
48 * and only read later on.
49 * They do not require any lock protection.
51 _mali_uk_pp_start_job_s uargs; /**< Arguments from user space */
52 struct mali_session_data *session; /**< Session which submitted this job */
53 u32 pid; /**< Process ID of submitting process */
54 u32 tid; /**< Thread ID of submitting thread */
55 u32 id; /**< Identifier for this job in kernel space (sequential numbering) */
56 u32 cache_order; /**< Cache order used for L2 cache flushing (sequential numbering) */
57 struct mali_timeline_tracker tracker; /**< Timeline tracker for this job */
58 _mali_osk_notification_t *finished_notification; /**< Notification sent back to userspace on job complete */
59 u32 perf_counter_per_sub_job_count; /**< Number of values in the two arrays which is != MALI_HW_CORE_NO_COUNTER */
60 u32 perf_counter_per_sub_job_src0[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src0 */
61 u32 perf_counter_per_sub_job_src1[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src1 */
62 u32 sub_jobs_num; /**< Number of subjobs; set to 1 for Mali-450 if DLBU is used, otherwise equals number of PP cores */
64 pp_job_status swap_status; /**< Used to track each PP job swap status, if fail, we need to drop them in scheduler part */
65 mali_bool user_notification; /**< When we deferred delete PP job, we need to judge if we need to send job finish notification to user space */
66 u32 num_pp_cores_in_virtual; /**< How many PP cores we have when job finished */
69 * These members are used by both scheduler and executor.
70 * They are "protected" by atomic operations.
72 _mali_osk_atomic_t sub_jobs_completed; /**< Number of completed sub-jobs in this superjob */
73 _mali_osk_atomic_t sub_job_errors; /**< Bitfield with errors (errors for each single sub-job is or'ed together) */
76 * These members are used by scheduler, but only when no one else
77 * knows about this job object but the working function.
78 * No lock is thus needed for these.
80 u32 *memory_cookies; /**< Memory cookies attached to job */
83 * These members are used by the scheduler,
84 * protected by scheduler lock
86 _mali_osk_list_t list; /**< Used to link jobs together in the scheduler queue */
87 _mali_osk_list_t session_fb_lookup_list; /**< Used to link jobs together from the same frame builder in the session */
88 u32 sub_jobs_started; /**< Total number of sub-jobs started (always started in ascending order) */
91 * Set by executor/group on job completion, read by scheduler when
92 * returning job to user. Hold executor lock when setting,
93 * no lock needed when reading
95 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 */
96 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 */
99 void mali_pp_job_initialize(void);
100 void mali_pp_job_terminate(void);
102 struct mali_pp_job *mali_pp_job_create(struct mali_session_data *session, _mali_uk_pp_start_job_s *uargs, u32 id);
103 void mali_pp_job_delete(struct mali_pp_job *job);
105 u32 mali_pp_job_get_perf_counter_src0(struct mali_pp_job *job, u32 sub_job);
106 u32 mali_pp_job_get_perf_counter_src1(struct mali_pp_job *job, u32 sub_job);
108 void mali_pp_job_set_pp_counter_global_src0(u32 counter);
109 void mali_pp_job_set_pp_counter_global_src1(u32 counter);
110 void mali_pp_job_set_pp_counter_sub_job_src0(u32 sub_job, u32 counter);
111 void mali_pp_job_set_pp_counter_sub_job_src1(u32 sub_job, u32 counter);
113 u32 mali_pp_job_get_pp_counter_global_src0(void);
114 u32 mali_pp_job_get_pp_counter_global_src1(void);
115 u32 mali_pp_job_get_pp_counter_sub_job_src0(u32 sub_job);
116 u32 mali_pp_job_get_pp_counter_sub_job_src1(u32 sub_job);
118 MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
120 MALI_DEBUG_ASSERT_POINTER(job);
121 return (NULL == job) ? 0 : job->id;
124 MALI_STATIC_INLINE void mali_pp_job_set_cache_order(struct mali_pp_job *job,
127 MALI_DEBUG_ASSERT_POINTER(job);
128 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
129 job->cache_order = cache_order;
132 MALI_STATIC_INLINE u32 mali_pp_job_get_cache_order(struct mali_pp_job *job)
134 MALI_DEBUG_ASSERT_POINTER(job);
135 return (NULL == job) ? 0 : job->cache_order;
138 MALI_STATIC_INLINE u64 mali_pp_job_get_user_id(struct mali_pp_job *job)
140 MALI_DEBUG_ASSERT_POINTER(job);
141 return job->uargs.user_job_ptr;
144 MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
146 MALI_DEBUG_ASSERT_POINTER(job);
147 return job->uargs.frame_builder_id;
150 MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
152 MALI_DEBUG_ASSERT_POINTER(job);
153 return job->uargs.flush_id;
156 MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
158 MALI_DEBUG_ASSERT_POINTER(job);
162 MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
164 MALI_DEBUG_ASSERT_POINTER(job);
168 MALI_STATIC_INLINE u32 *mali_pp_job_get_frame_registers(struct mali_pp_job *job)
170 MALI_DEBUG_ASSERT_POINTER(job);
171 return job->uargs.frame_registers;
174 MALI_STATIC_INLINE u32 *mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
176 MALI_DEBUG_ASSERT_POINTER(job);
177 return job->uargs.dlbu_registers;
180 MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
182 #if (defined(CONFIG_MALI450) || defined(CONFIG_MALI470))
183 MALI_DEBUG_ASSERT_POINTER(job);
184 return (0 == job->uargs.num_cores) ? MALI_TRUE : MALI_FALSE;
190 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
192 MALI_DEBUG_ASSERT_POINTER(job);
194 if (mali_pp_job_is_virtual(job)) {
195 return MALI_DLBU_VIRT_ADDR;
196 } else if (0 == sub_job) {
197 return job->uargs.frame_registers[MALI200_REG_ADDR_FRAME / sizeof(u32)];
198 } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
199 return job->uargs.frame_registers_addr_frame[sub_job - 1];
205 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
207 MALI_DEBUG_ASSERT_POINTER(job);
210 return job->uargs.frame_registers[MALI200_REG_ADDR_STACK / sizeof(u32)];
211 } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
212 return job->uargs.frame_registers_addr_stack[sub_job - 1];
218 void mali_pp_job_list_add(struct mali_pp_job *job, _mali_osk_list_t *list);
220 MALI_STATIC_INLINE void mali_pp_job_list_addtail(struct mali_pp_job *job,
221 _mali_osk_list_t *list)
223 _mali_osk_list_addtail(&job->list, list);
226 MALI_STATIC_INLINE void mali_pp_job_list_move(struct mali_pp_job *job,
227 _mali_osk_list_t *list)
229 MALI_DEBUG_ASSERT_POINTER(job);
230 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
231 MALI_DEBUG_ASSERT(!_mali_osk_list_empty(&job->list));
232 _mali_osk_list_move(&job->list, list);
235 MALI_STATIC_INLINE void mali_pp_job_list_remove(struct mali_pp_job *job)
237 MALI_DEBUG_ASSERT_POINTER(job);
238 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
239 _mali_osk_list_delinit(&job->list);
242 MALI_STATIC_INLINE u32 *mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
244 MALI_DEBUG_ASSERT_POINTER(job);
245 return job->uargs.wb0_registers;
248 MALI_STATIC_INLINE u32 *mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
250 MALI_DEBUG_ASSERT_POINTER(job);
251 return job->uargs.wb1_registers;
254 MALI_STATIC_INLINE u32 *mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
256 MALI_DEBUG_ASSERT_POINTER(job);
257 return job->uargs.wb2_registers;
260 MALI_STATIC_INLINE u32 mali_pp_job_get_wb0_source_addr(struct mali_pp_job *job)
262 MALI_DEBUG_ASSERT_POINTER(job);
263 return job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_ADDR / sizeof(u32)];
266 MALI_STATIC_INLINE u32 mali_pp_job_get_wb1_source_addr(struct mali_pp_job *job)
268 MALI_DEBUG_ASSERT_POINTER(job);
269 return job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_ADDR / sizeof(u32)];
272 MALI_STATIC_INLINE u32 mali_pp_job_get_wb2_source_addr(struct mali_pp_job *job)
274 MALI_DEBUG_ASSERT_POINTER(job);
275 return job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_ADDR / sizeof(u32)];
278 MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
280 MALI_DEBUG_ASSERT_POINTER(job);
281 job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
284 MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
286 MALI_DEBUG_ASSERT_POINTER(job);
287 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
290 MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
292 MALI_DEBUG_ASSERT_POINTER(job);
293 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
296 MALI_STATIC_INLINE mali_bool mali_pp_job_all_writeback_unit_disabled(struct mali_pp_job *job)
298 MALI_DEBUG_ASSERT_POINTER(job);
300 if (job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
301 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
302 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT]
304 /* At least one output unit active */
308 /* All outputs are disabled - we can abort the job */
312 MALI_STATIC_INLINE void mali_pp_job_fb_lookup_add(struct mali_pp_job *job)
316 MALI_DEBUG_ASSERT_POINTER(job);
317 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
319 fb_lookup_id = MALI_PP_JOB_FB_LOOKUP_LIST_MASK & job->uargs.frame_builder_id;
321 MALI_DEBUG_ASSERT(MALI_PP_JOB_FB_LOOKUP_LIST_SIZE > fb_lookup_id);
323 _mali_osk_list_addtail(&job->session_fb_lookup_list,
324 &job->session->pp_job_fb_lookup_list[fb_lookup_id]);
327 MALI_STATIC_INLINE void mali_pp_job_fb_lookup_remove(struct mali_pp_job *job)
329 MALI_DEBUG_ASSERT_POINTER(job);
330 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
331 _mali_osk_list_delinit(&job->session_fb_lookup_list);
334 MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
336 MALI_DEBUG_ASSERT_POINTER(job);
340 MALI_STATIC_INLINE mali_bool mali_pp_job_has_started_sub_jobs(struct mali_pp_job *job)
342 MALI_DEBUG_ASSERT_POINTER(job);
343 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
344 return (0 < job->sub_jobs_started) ? MALI_TRUE : MALI_FALSE;
347 MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
349 MALI_DEBUG_ASSERT_POINTER(job);
350 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
351 return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
354 /* Function used when we are terminating a session with jobs. Return TRUE if it has a rendering job.
355 Makes sure that no new subjobs are started. */
356 MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_failed(struct mali_pp_job *job)
361 MALI_DEBUG_ASSERT_POINTER(job);
362 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
364 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
365 job->sub_jobs_started += jobs_remaining;
367 /* Not the most optimal way, but this is only used in error cases */
368 for (i = 0; i < jobs_remaining; i++) {
369 _mali_osk_atomic_inc(&job->sub_jobs_completed);
370 _mali_osk_atomic_inc(&job->sub_job_errors);
374 MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
376 MALI_DEBUG_ASSERT_POINTER(job);
377 return (job->sub_jobs_num ==
378 _mali_osk_atomic_read(&job->sub_jobs_completed)) ?
379 MALI_TRUE : MALI_FALSE;
382 MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
384 MALI_DEBUG_ASSERT_POINTER(job);
385 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
386 return job->sub_jobs_started;
389 MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
391 MALI_DEBUG_ASSERT_POINTER(job);
392 return job->sub_jobs_num;
395 MALI_STATIC_INLINE u32 mali_pp_job_unstarted_sub_job_count(struct mali_pp_job *job)
397 MALI_DEBUG_ASSERT_POINTER(job);
398 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
399 MALI_DEBUG_ASSERT(job->sub_jobs_num >= job->sub_jobs_started);
400 return (job->sub_jobs_num - job->sub_jobs_started);
403 MALI_STATIC_INLINE u32 mali_pp_job_num_memory_cookies(struct mali_pp_job *job)
405 MALI_DEBUG_ASSERT_POINTER(job);
406 return job->uargs.num_memory_cookies;
409 MALI_STATIC_INLINE u32 mali_pp_job_get_memory_cookie(
410 struct mali_pp_job *job, u32 index)
412 MALI_DEBUG_ASSERT_POINTER(job);
413 MALI_DEBUG_ASSERT(index < job->uargs.num_memory_cookies);
414 MALI_DEBUG_ASSERT_POINTER(job->memory_cookies);
415 return job->memory_cookies[index];
418 MALI_STATIC_INLINE mali_bool mali_pp_job_needs_dma_buf_mapping(struct mali_pp_job *job)
420 MALI_DEBUG_ASSERT_POINTER(job);
422 if (0 < job->uargs.num_memory_cookies) {
429 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
431 MALI_DEBUG_ASSERT_POINTER(job);
432 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
434 /* Assert that we are marking the "first unstarted sub job" as started */
435 MALI_DEBUG_ASSERT(job->sub_jobs_started == sub_job);
437 job->sub_jobs_started++;
440 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
442 MALI_DEBUG_ASSERT_POINTER(job);
444 _mali_osk_atomic_inc(&job->sub_jobs_completed);
445 if (MALI_FALSE == success) {
446 _mali_osk_atomic_inc(&job->sub_job_errors);
450 MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
452 MALI_DEBUG_ASSERT_POINTER(job);
453 if (0 == _mali_osk_atomic_read(&job->sub_job_errors)) {
459 MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(
460 struct mali_pp_job *job)
462 MALI_DEBUG_ASSERT_POINTER(job);
463 return (job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION) ?
464 MALI_TRUE : MALI_FALSE;
467 MALI_STATIC_INLINE mali_bool mali_pp_job_is_pilot_job(struct mali_pp_job *job)
470 * A pilot job is currently identified as jobs which
471 * require no callback notification.
473 return mali_pp_job_use_no_notification(job);
476 MALI_STATIC_INLINE _mali_osk_notification_t *
477 mali_pp_job_get_finished_notification(struct mali_pp_job *job)
479 _mali_osk_notification_t *notification;
481 MALI_DEBUG_ASSERT_POINTER(job);
482 MALI_DEBUG_ASSERT_POINTER(job->finished_notification);
484 notification = job->finished_notification;
485 job->finished_notification = NULL;
490 MALI_STATIC_INLINE mali_bool mali_pp_job_is_window_surface(
491 struct mali_pp_job *job)
493 MALI_DEBUG_ASSERT_POINTER(job);
494 return (job->uargs.flags & _MALI_PP_JOB_FLAG_IS_WINDOW_SURFACE)
495 ? MALI_TRUE : MALI_FALSE;
498 MALI_STATIC_INLINE mali_bool mali_pp_job_is_protected_job(struct mali_pp_job *job)
500 MALI_DEBUG_ASSERT_POINTER(job);
501 return (job->uargs.flags & _MALI_PP_JOB_FLAG_PROTECTED)
502 ? MALI_TRUE : MALI_FALSE;
505 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
507 MALI_DEBUG_ASSERT_POINTER(job);
508 return job->uargs.perf_counter_flag;
511 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
513 MALI_DEBUG_ASSERT_POINTER(job);
514 return job->perf_counter_value0[sub_job];
517 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
519 MALI_DEBUG_ASSERT_POINTER(job);
520 return job->perf_counter_value1[sub_job];
523 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
525 MALI_DEBUG_ASSERT_POINTER(job);
526 MALI_DEBUG_ASSERT_EXECUTOR_LOCK_HELD();
527 job->perf_counter_value0[sub_job] = value;
530 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
532 MALI_DEBUG_ASSERT_POINTER(job);
533 MALI_DEBUG_ASSERT_EXECUTOR_LOCK_HELD();
534 job->perf_counter_value1[sub_job] = value;
537 MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
539 MALI_DEBUG_ASSERT_POINTER(job);
540 if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1) {
541 return _MALI_OSK_ERR_FAULT;
543 return _MALI_OSK_ERR_OK;
547 * Returns MALI_TRUE if this job has more than two sub jobs and all sub jobs are unstarted.
549 * @param job Job to check.
550 * @return MALI_TRUE if job has more than two sub jobs and all sub jobs are unstarted, MALI_FALSE if not.
552 MALI_STATIC_INLINE mali_bool mali_pp_job_is_large_and_unstarted(struct mali_pp_job *job)
554 MALI_DEBUG_ASSERT_POINTER(job);
555 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
556 MALI_DEBUG_ASSERT(!mali_pp_job_is_virtual(job));
558 return (0 == job->sub_jobs_started && 2 < job->sub_jobs_num);
562 * Get PP job's Timeline tracker.
565 * @return Pointer to Timeline tracker for the job.
567 MALI_STATIC_INLINE struct mali_timeline_tracker *mali_pp_job_get_tracker(struct mali_pp_job *job)
569 MALI_DEBUG_ASSERT_POINTER(job);
570 return &(job->tracker);
573 MALI_STATIC_INLINE u32 *mali_pp_job_get_timeline_point_ptr(
574 struct mali_pp_job *job)
576 MALI_DEBUG_ASSERT_POINTER(job);
577 return (u32 __user *)(uintptr_t)job->uargs.timeline_point_ptr;
581 #endif /* __MALI_PP_JOB_H__ */