1 /*
2 * Copyright (C) 2011-2017 ARM Limited. All rights reserved.
3 *
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.
6 *
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.
9 */
10
11 #ifndef __MALI_PP_JOB_H__
12 #define __MALI_PP_JOB_H__
13
14 #include "mali_osk.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"
27 #endif
28 #if defined(CONFIG_MALI_DMA_BUF_FENCE)
29 #include "linux/mali_dma_fence.h"
30 #endif
31
32 typedef enum pp_job_status {
33 MALI_NO_SWAP_IN,
34 MALI_SWAP_IN_FAIL,
35 MALI_SWAP_IN_SUCC,
36 } pp_job_status;
37
38 /**
39 * This structure represents a PP job, including all sub jobs.
40 *
41 * The PP job object itself is not protected by any single lock,
42 * but relies on other locks instead (scheduler, executor and timeline lock).
43 * Think of the job object as moving between these sub systems through-out
44 * its lifetime. Different part of the PP job struct is used by different
45 * subsystems. Accessor functions ensure that correct lock is taken.
46 * Do NOT access any data members directly from outside this module!
47 */
48 struct mali_pp_job {
49 /*
50 * These members are typically only set at creation,
51 * and only read later on.
52 * They do not require any lock protection.
53 */
54 _mali_uk_pp_start_job_s uargs; /**< Arguments from user space */
55 struct mali_session_data *session; /**< Session which submitted this job */
56 u32 pid; /**< Process ID of submitting process */
57 u32 tid; /**< Thread ID of submitting thread */
58 u32 id; /**< Identifier for this job in kernel space (sequential numbering) */
59 u32 cache_order; /**< Cache order used for L2 cache flushing (sequential numbering) */
60 struct mali_timeline_tracker tracker; /**< Timeline tracker for this job */
61 _mali_osk_notification_t *finished_notification; /**< Notification sent back to userspace on job complete */
62 u32 perf_counter_per_sub_job_count; /**< Number of values in the two arrays which is != MALI_HW_CORE_NO_COUNTER */
63 u32 perf_counter_per_sub_job_src0[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src0 */
64 u32 perf_counter_per_sub_job_src1[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src1 */
65 u32 sub_jobs_num; /**< Number of subjobs; set to 1 for Mali-450 if DLBU is used, otherwise equals number of PP cores */
66
67 pp_job_status swap_status; /**< Used to track each PP job swap status, if fail, we need to drop them in scheduler part */
68 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 */
69 u32 num_pp_cores_in_virtual; /**< How many PP cores we have when job finished */
70
71 /*
72 * These members are used by both scheduler and executor.
73 * They are "protected" by atomic operations.
74 */
75 _mali_osk_atomic_t sub_jobs_completed; /**< Number of completed sub-jobs in this superjob */
76 _mali_osk_atomic_t sub_job_errors; /**< Bitfield with errors (errors for each single sub-job is or'ed together) */
77
78 /*
79 * These members are used by scheduler, but only when no one else
80 * knows about this job object but the working function.
81 * No lock is thus needed for these.
82 */
83 u32 *memory_cookies; /**< Memory cookies attached to job */
84
85 /*
86 * These members are used by the scheduler,
87 * protected by scheduler lock
88 */
89 _mali_osk_list_t list; /**< Used to link jobs together in the scheduler queue */
90 _mali_osk_list_t session_fb_lookup_list; /**< Used to link jobs together from the same frame builder in the session */
91
92 u32 sub_jobs_started; /**< Total number of sub-jobs started (always started in ascending order) */
93
94 /*
95 * Set by executor/group on job completion, read by scheduler when
96 * returning job to user. Hold executor lock when setting,
97 * no lock needed when reading
98 */
99 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 */
100 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 */
101
102 #if defined(CONFIG_MALI_DMA_BUF_FENCE)
103 struct mali_dma_fence_context dma_fence_context; /**< The mali dma fence context to record dma fence waiters that this job wait for */
104 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0)
105 struct dma_fence *rendered_dma_fence; /**< the new dma fence link to this job */
106 #else
107 struct fence *rendered_dma_fence; /**< the new dma fence link to this job */
108 #endif
109 #endif
110 };
111
112 void mali_pp_job_initialize(void);
113 void mali_pp_job_terminate(void);
114
115 struct mali_pp_job *mali_pp_job_create(struct mali_session_data *session, _mali_uk_pp_start_job_s *uargs, u32 id);
116 void mali_pp_job_delete(struct mali_pp_job *job);
117
118 u32 mali_pp_job_get_perf_counter_src0(struct mali_pp_job *job, u32 sub_job);
119 u32 mali_pp_job_get_perf_counter_src1(struct mali_pp_job *job, u32 sub_job);
120
121 void mali_pp_job_set_pp_counter_global_src0(u32 counter);
122 void mali_pp_job_set_pp_counter_global_src1(u32 counter);
123 void mali_pp_job_set_pp_counter_sub_job_src0(u32 sub_job, u32 counter);
124 void mali_pp_job_set_pp_counter_sub_job_src1(u32 sub_job, u32 counter);
125
126 u32 mali_pp_job_get_pp_counter_global_src0(void);
127 u32 mali_pp_job_get_pp_counter_global_src1(void);
128 u32 mali_pp_job_get_pp_counter_sub_job_src0(u32 sub_job);
129 u32 mali_pp_job_get_pp_counter_sub_job_src1(u32 sub_job);
130
mali_pp_job_get_id(struct mali_pp_job * job)131 MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
132 {
133 MALI_DEBUG_ASSERT_POINTER(job);
134 return (NULL == job) ? 0 : job->id;
135 }
136
mali_pp_job_set_cache_order(struct mali_pp_job * job,u32 cache_order)137 MALI_STATIC_INLINE void mali_pp_job_set_cache_order(struct mali_pp_job *job,
138 u32 cache_order)
139 {
140 MALI_DEBUG_ASSERT_POINTER(job);
141 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
142 job->cache_order = cache_order;
143 }
144
mali_pp_job_get_cache_order(struct mali_pp_job * job)145 MALI_STATIC_INLINE u32 mali_pp_job_get_cache_order(struct mali_pp_job *job)
146 {
147 MALI_DEBUG_ASSERT_POINTER(job);
148 return (NULL == job) ? 0 : job->cache_order;
149 }
150
mali_pp_job_get_user_id(struct mali_pp_job * job)151 MALI_STATIC_INLINE u64 mali_pp_job_get_user_id(struct mali_pp_job *job)
152 {
153 MALI_DEBUG_ASSERT_POINTER(job);
154 return job->uargs.user_job_ptr;
155 }
156
mali_pp_job_get_frame_builder_id(struct mali_pp_job * job)157 MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
158 {
159 MALI_DEBUG_ASSERT_POINTER(job);
160 return job->uargs.frame_builder_id;
161 }
162
mali_pp_job_get_flush_id(struct mali_pp_job * job)163 MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
164 {
165 MALI_DEBUG_ASSERT_POINTER(job);
166 return job->uargs.flush_id;
167 }
168
mali_pp_job_get_pid(struct mali_pp_job * job)169 MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
170 {
171 MALI_DEBUG_ASSERT_POINTER(job);
172 return job->pid;
173 }
174
mali_pp_job_get_tid(struct mali_pp_job * job)175 MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
176 {
177 MALI_DEBUG_ASSERT_POINTER(job);
178 return job->tid;
179 }
180
mali_pp_job_get_frame_registers(struct mali_pp_job * job)181 MALI_STATIC_INLINE u32 *mali_pp_job_get_frame_registers(struct mali_pp_job *job)
182 {
183 MALI_DEBUG_ASSERT_POINTER(job);
184 return job->uargs.frame_registers;
185 }
186
mali_pp_job_get_dlbu_registers(struct mali_pp_job * job)187 MALI_STATIC_INLINE u32 *mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
188 {
189 MALI_DEBUG_ASSERT_POINTER(job);
190 return job->uargs.dlbu_registers;
191 }
192
mali_pp_job_is_virtual(struct mali_pp_job * job)193 MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
194 {
195 #if (defined(CONFIG_MALI450) || defined(CONFIG_MALI470))
196 MALI_DEBUG_ASSERT_POINTER(job);
197 return (0 == job->uargs.num_cores) ? MALI_TRUE : MALI_FALSE;
198 #else
199 return MALI_FALSE;
200 #endif
201 }
202
mali_pp_job_get_addr_frame(struct mali_pp_job * job,u32 sub_job)203 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
204 {
205 MALI_DEBUG_ASSERT_POINTER(job);
206
207 if (mali_pp_job_is_virtual(job)) {
208 return MALI_DLBU_VIRT_ADDR;
209 } else if (0 == sub_job) {
210 return job->uargs.frame_registers[MALI200_REG_ADDR_FRAME / sizeof(u32)];
211 } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
212 return job->uargs.frame_registers_addr_frame[sub_job - 1];
213 }
214
215 return 0;
216 }
217
mali_pp_job_get_addr_stack(struct mali_pp_job * job,u32 sub_job)218 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
219 {
220 MALI_DEBUG_ASSERT_POINTER(job);
221
222 if (0 == sub_job) {
223 return job->uargs.frame_registers[MALI200_REG_ADDR_STACK / sizeof(u32)];
224 } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
225 return job->uargs.frame_registers_addr_stack[sub_job - 1];
226 }
227
228 return 0;
229 }
230
231 void mali_pp_job_list_add(struct mali_pp_job *job, _mali_osk_list_t *list);
232
mali_pp_job_list_addtail(struct mali_pp_job * job,_mali_osk_list_t * list)233 MALI_STATIC_INLINE void mali_pp_job_list_addtail(struct mali_pp_job *job,
234 _mali_osk_list_t *list)
235 {
236 _mali_osk_list_addtail(&job->list, list);
237 }
238
mali_pp_job_list_move(struct mali_pp_job * job,_mali_osk_list_t * list)239 MALI_STATIC_INLINE void mali_pp_job_list_move(struct mali_pp_job *job,
240 _mali_osk_list_t *list)
241 {
242 MALI_DEBUG_ASSERT_POINTER(job);
243 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
244 MALI_DEBUG_ASSERT(!_mali_osk_list_empty(&job->list));
245 _mali_osk_list_move(&job->list, list);
246 }
247
mali_pp_job_list_remove(struct mali_pp_job * job)248 MALI_STATIC_INLINE void mali_pp_job_list_remove(struct mali_pp_job *job)
249 {
250 MALI_DEBUG_ASSERT_POINTER(job);
251 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
252 _mali_osk_list_delinit(&job->list);
253 }
254
mali_pp_job_get_wb0_registers(struct mali_pp_job * job)255 MALI_STATIC_INLINE u32 *mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
256 {
257 MALI_DEBUG_ASSERT_POINTER(job);
258 return job->uargs.wb0_registers;
259 }
260
mali_pp_job_get_wb1_registers(struct mali_pp_job * job)261 MALI_STATIC_INLINE u32 *mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
262 {
263 MALI_DEBUG_ASSERT_POINTER(job);
264 return job->uargs.wb1_registers;
265 }
266
mali_pp_job_get_wb2_registers(struct mali_pp_job * job)267 MALI_STATIC_INLINE u32 *mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
268 {
269 MALI_DEBUG_ASSERT_POINTER(job);
270 return job->uargs.wb2_registers;
271 }
272
mali_pp_job_get_wb0_source_addr(struct mali_pp_job * job)273 MALI_STATIC_INLINE u32 mali_pp_job_get_wb0_source_addr(struct mali_pp_job *job)
274 {
275 MALI_DEBUG_ASSERT_POINTER(job);
276 return job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_ADDR / sizeof(u32)];
277 }
278
mali_pp_job_get_wb1_source_addr(struct mali_pp_job * job)279 MALI_STATIC_INLINE u32 mali_pp_job_get_wb1_source_addr(struct mali_pp_job *job)
280 {
281 MALI_DEBUG_ASSERT_POINTER(job);
282 return job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_ADDR / sizeof(u32)];
283 }
284
mali_pp_job_get_wb2_source_addr(struct mali_pp_job * job)285 MALI_STATIC_INLINE u32 mali_pp_job_get_wb2_source_addr(struct mali_pp_job *job)
286 {
287 MALI_DEBUG_ASSERT_POINTER(job);
288 return job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_ADDR / sizeof(u32)];
289 }
290
mali_pp_job_disable_wb0(struct mali_pp_job * job)291 MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
292 {
293 MALI_DEBUG_ASSERT_POINTER(job);
294 job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
295 }
296
mali_pp_job_disable_wb1(struct mali_pp_job * job)297 MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
298 {
299 MALI_DEBUG_ASSERT_POINTER(job);
300 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
301 }
302
mali_pp_job_disable_wb2(struct mali_pp_job * job)303 MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
304 {
305 MALI_DEBUG_ASSERT_POINTER(job);
306 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
307 }
308
mali_pp_job_all_writeback_unit_disabled(struct mali_pp_job * job)309 MALI_STATIC_INLINE mali_bool mali_pp_job_all_writeback_unit_disabled(struct mali_pp_job *job)
310 {
311 MALI_DEBUG_ASSERT_POINTER(job);
312
313 if (job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
314 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
315 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT]
316 ) {
317 /* At least one output unit active */
318 return MALI_FALSE;
319 }
320
321 /* All outputs are disabled - we can abort the job */
322 return MALI_TRUE;
323 }
324
mali_pp_job_fb_lookup_add(struct mali_pp_job * job)325 MALI_STATIC_INLINE void mali_pp_job_fb_lookup_add(struct mali_pp_job *job)
326 {
327 u32 fb_lookup_id;
328
329 MALI_DEBUG_ASSERT_POINTER(job);
330 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
331
332 fb_lookup_id = MALI_PP_JOB_FB_LOOKUP_LIST_MASK & job->uargs.frame_builder_id;
333
334 MALI_DEBUG_ASSERT(MALI_PP_JOB_FB_LOOKUP_LIST_SIZE > fb_lookup_id);
335
336 _mali_osk_list_addtail(&job->session_fb_lookup_list,
337 &job->session->pp_job_fb_lookup_list[fb_lookup_id]);
338 }
339
mali_pp_job_fb_lookup_remove(struct mali_pp_job * job)340 MALI_STATIC_INLINE void mali_pp_job_fb_lookup_remove(struct mali_pp_job *job)
341 {
342 MALI_DEBUG_ASSERT_POINTER(job);
343 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
344 _mali_osk_list_delinit(&job->session_fb_lookup_list);
345 }
346
mali_pp_job_get_session(struct mali_pp_job * job)347 MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
348 {
349 MALI_DEBUG_ASSERT_POINTER(job);
350 return job->session;
351 }
352
mali_pp_job_has_started_sub_jobs(struct mali_pp_job * job)353 MALI_STATIC_INLINE mali_bool mali_pp_job_has_started_sub_jobs(struct mali_pp_job *job)
354 {
355 MALI_DEBUG_ASSERT_POINTER(job);
356 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
357 return (0 < job->sub_jobs_started) ? MALI_TRUE : MALI_FALSE;
358 }
359
mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job * job)360 MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
361 {
362 MALI_DEBUG_ASSERT_POINTER(job);
363 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
364 return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
365 }
366
367 /* Function used when we are terminating a session with jobs. Return TRUE if it has a rendering job.
368 Makes sure that no new subjobs are started. */
mali_pp_job_mark_unstarted_failed(struct mali_pp_job * job)369 MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_failed(struct mali_pp_job *job)
370 {
371 u32 jobs_remaining;
372 u32 i;
373
374 MALI_DEBUG_ASSERT_POINTER(job);
375 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
376
377 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
378 job->sub_jobs_started += jobs_remaining;
379
380 /* Not the most optimal way, but this is only used in error cases */
381 for (i = 0; i < jobs_remaining; i++) {
382 _mali_osk_atomic_inc(&job->sub_jobs_completed);
383 _mali_osk_atomic_inc(&job->sub_job_errors);
384 }
385 }
386
mali_pp_job_is_complete(struct mali_pp_job * job)387 MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
388 {
389 MALI_DEBUG_ASSERT_POINTER(job);
390 return (job->sub_jobs_num ==
391 _mali_osk_atomic_read(&job->sub_jobs_completed)) ?
392 MALI_TRUE : MALI_FALSE;
393 }
394
mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job * job)395 MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
396 {
397 MALI_DEBUG_ASSERT_POINTER(job);
398 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
399 return job->sub_jobs_started;
400 }
401
mali_pp_job_get_sub_job_count(struct mali_pp_job * job)402 MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
403 {
404 MALI_DEBUG_ASSERT_POINTER(job);
405 return job->sub_jobs_num;
406 }
407
mali_pp_job_unstarted_sub_job_count(struct mali_pp_job * job)408 MALI_STATIC_INLINE u32 mali_pp_job_unstarted_sub_job_count(struct mali_pp_job *job)
409 {
410 MALI_DEBUG_ASSERT_POINTER(job);
411 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
412 MALI_DEBUG_ASSERT(job->sub_jobs_num >= job->sub_jobs_started);
413 return (job->sub_jobs_num - job->sub_jobs_started);
414 }
415
mali_pp_job_num_memory_cookies(struct mali_pp_job * job)416 MALI_STATIC_INLINE u32 mali_pp_job_num_memory_cookies(struct mali_pp_job *job)
417 {
418 MALI_DEBUG_ASSERT_POINTER(job);
419 return job->uargs.num_memory_cookies;
420 }
421
mali_pp_job_get_memory_cookie(struct mali_pp_job * job,u32 index)422 MALI_STATIC_INLINE u32 mali_pp_job_get_memory_cookie(
423 struct mali_pp_job *job, u32 index)
424 {
425 MALI_DEBUG_ASSERT_POINTER(job);
426 MALI_DEBUG_ASSERT(index < job->uargs.num_memory_cookies);
427 MALI_DEBUG_ASSERT_POINTER(job->memory_cookies);
428 return job->memory_cookies[index];
429 }
430
mali_pp_job_needs_dma_buf_mapping(struct mali_pp_job * job)431 MALI_STATIC_INLINE mali_bool mali_pp_job_needs_dma_buf_mapping(struct mali_pp_job *job)
432 {
433 MALI_DEBUG_ASSERT_POINTER(job);
434
435 if (0 < job->uargs.num_memory_cookies) {
436 return MALI_TRUE;
437 }
438
439 return MALI_FALSE;
440 }
441
mali_pp_job_mark_sub_job_started(struct mali_pp_job * job,u32 sub_job)442 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
443 {
444 MALI_DEBUG_ASSERT_POINTER(job);
445 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
446
447 /* Assert that we are marking the "first unstarted sub job" as started */
448 MALI_DEBUG_ASSERT(job->sub_jobs_started == sub_job);
449
450 job->sub_jobs_started++;
451 }
452
mali_pp_job_mark_sub_job_completed(struct mali_pp_job * job,mali_bool success)453 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
454 {
455 MALI_DEBUG_ASSERT_POINTER(job);
456
457 _mali_osk_atomic_inc(&job->sub_jobs_completed);
458 if (MALI_FALSE == success) {
459 _mali_osk_atomic_inc(&job->sub_job_errors);
460 }
461 }
462
mali_pp_job_was_success(struct mali_pp_job * job)463 MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
464 {
465 MALI_DEBUG_ASSERT_POINTER(job);
466 if (0 == _mali_osk_atomic_read(&job->sub_job_errors)) {
467 return MALI_TRUE;
468 }
469 return MALI_FALSE;
470 }
471
mali_pp_job_use_no_notification(struct mali_pp_job * job)472 MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(
473 struct mali_pp_job *job)
474 {
475 MALI_DEBUG_ASSERT_POINTER(job);
476 return (job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION) ?
477 MALI_TRUE : MALI_FALSE;
478 }
479
mali_pp_job_is_pilot_job(struct mali_pp_job * job)480 MALI_STATIC_INLINE mali_bool mali_pp_job_is_pilot_job(struct mali_pp_job *job)
481 {
482 /*
483 * A pilot job is currently identified as jobs which
484 * require no callback notification.
485 */
486 return mali_pp_job_use_no_notification(job);
487 }
488
489 MALI_STATIC_INLINE _mali_osk_notification_t *
mali_pp_job_get_finished_notification(struct mali_pp_job * job)490 mali_pp_job_get_finished_notification(struct mali_pp_job *job)
491 {
492 _mali_osk_notification_t *notification;
493
494 MALI_DEBUG_ASSERT_POINTER(job);
495 MALI_DEBUG_ASSERT_POINTER(job->finished_notification);
496
497 notification = job->finished_notification;
498 job->finished_notification = NULL;
499
500 return notification;
501 }
502
mali_pp_job_is_window_surface(struct mali_pp_job * job)503 MALI_STATIC_INLINE mali_bool mali_pp_job_is_window_surface(
504 struct mali_pp_job *job)
505 {
506 MALI_DEBUG_ASSERT_POINTER(job);
507 return (job->uargs.flags & _MALI_PP_JOB_FLAG_IS_WINDOW_SURFACE)
508 ? MALI_TRUE : MALI_FALSE;
509 }
510
mali_pp_job_is_protected_job(struct mali_pp_job * job)511 MALI_STATIC_INLINE mali_bool mali_pp_job_is_protected_job(struct mali_pp_job *job)
512 {
513 MALI_DEBUG_ASSERT_POINTER(job);
514 return (job->uargs.flags & _MALI_PP_JOB_FLAG_PROTECTED)
515 ? MALI_TRUE : MALI_FALSE;
516 }
517
mali_pp_job_get_perf_counter_flag(struct mali_pp_job * job)518 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
519 {
520 MALI_DEBUG_ASSERT_POINTER(job);
521 return job->uargs.perf_counter_flag;
522 }
523
mali_pp_job_get_perf_counter_value0(struct mali_pp_job * job,u32 sub_job)524 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
525 {
526 MALI_DEBUG_ASSERT_POINTER(job);
527 return job->perf_counter_value0[sub_job];
528 }
529
mali_pp_job_get_perf_counter_value1(struct mali_pp_job * job,u32 sub_job)530 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
531 {
532 MALI_DEBUG_ASSERT_POINTER(job);
533 return job->perf_counter_value1[sub_job];
534 }
535
mali_pp_job_set_perf_counter_value0(struct mali_pp_job * job,u32 sub_job,u32 value)536 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
537 {
538 MALI_DEBUG_ASSERT_POINTER(job);
539 MALI_DEBUG_ASSERT_EXECUTOR_LOCK_HELD();
540 job->perf_counter_value0[sub_job] = value;
541 }
542
mali_pp_job_set_perf_counter_value1(struct mali_pp_job * job,u32 sub_job,u32 value)543 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
544 {
545 MALI_DEBUG_ASSERT_POINTER(job);
546 MALI_DEBUG_ASSERT_EXECUTOR_LOCK_HELD();
547 job->perf_counter_value1[sub_job] = value;
548 }
549
mali_pp_job_check(struct mali_pp_job * job)550 MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
551 {
552 MALI_DEBUG_ASSERT_POINTER(job);
553 if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1) {
554 return _MALI_OSK_ERR_FAULT;
555 }
556 return _MALI_OSK_ERR_OK;
557 }
558
559 /**
560 * Returns MALI_TRUE if this job has more than two sub jobs and all sub jobs are unstarted.
561 *
562 * @param job Job to check.
563 * @return MALI_TRUE if job has more than two sub jobs and all sub jobs are unstarted, MALI_FALSE if not.
564 */
mali_pp_job_is_large_and_unstarted(struct mali_pp_job * job)565 MALI_STATIC_INLINE mali_bool mali_pp_job_is_large_and_unstarted(struct mali_pp_job *job)
566 {
567 MALI_DEBUG_ASSERT_POINTER(job);
568 MALI_DEBUG_ASSERT_SCHEDULER_LOCK_HELD();
569 MALI_DEBUG_ASSERT(!mali_pp_job_is_virtual(job));
570
571 return (0 == job->sub_jobs_started && 2 < job->sub_jobs_num);
572 }
573
574 /**
575 * Get PP job's Timeline tracker.
576 *
577 * @param job PP job.
578 * @return Pointer to Timeline tracker for the job.
579 */
mali_pp_job_get_tracker(struct mali_pp_job * job)580 MALI_STATIC_INLINE struct mali_timeline_tracker *mali_pp_job_get_tracker(struct mali_pp_job *job)
581 {
582 MALI_DEBUG_ASSERT_POINTER(job);
583 return &(job->tracker);
584 }
585
mali_pp_job_get_timeline_point_ptr(struct mali_pp_job * job)586 MALI_STATIC_INLINE u32 *mali_pp_job_get_timeline_point_ptr(
587 struct mali_pp_job *job)
588 {
589 MALI_DEBUG_ASSERT_POINTER(job);
590 return (u32 __user *)(uintptr_t)job->uargs.timeline_point_ptr;
591 }
592
593
594 #endif /* __MALI_PP_JOB_H__ */
595