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
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.
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"
22 #include "mali_dlbu.h"
23 #include "mali_timeline.h"
24 #if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
25 #include "linux/mali_memory_dma_buf.h"
29 * The structure represents a PP job, including all sub-jobs
30 * (This struct unfortunately needs to be public because of how the _mali_osk_list_*
34 _mali_osk_list_t list; /**< Used to link jobs together in the scheduler queue */
35 struct mali_session_data *session; /**< Session which submitted this job */
36 _mali_osk_list_t session_list; /**< Used to link jobs together in the session job list */
37 _mali_osk_list_t session_fb_lookup_list; /**< Used to link jobs together from the same frame builder in the session */
38 _mali_uk_pp_start_job_s uargs; /**< Arguments from user space */
39 mali_dma_cmd_buf dma_cmd_buf; /**< Command buffer for starting job using Mali-450 DMA unit */
40 u32 id; /**< Identifier for this job in kernel space (sequential numbering) */
41 u32 cache_order; /**< Cache order used for L2 cache flushing (sequential numbering) */
42 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 */
43 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 */
44 u32 sub_jobs_num; /**< Number of subjobs; set to 1 for Mali-450 if DLBU is used, otherwise equals number of PP cores */
45 u32 sub_jobs_started; /**< Total number of sub-jobs started (always started in ascending order) */
46 u32 sub_jobs_completed; /**< Number of completed sub-jobs in this superjob */
47 u32 sub_job_errors; /**< Bitfield with errors (errors for each single sub-job is or'ed together) */
48 u32 pid; /**< Process ID of submitting process */
49 u32 tid; /**< Thread ID of submitting thread */
50 _mali_osk_notification_t *finished_notification; /**< Notification sent back to userspace on job complete */
51 u32 num_memory_cookies; /**< Number of memory cookies attached to job */
52 u32 *memory_cookies; /**< Memory cookies attached to job */
53 #if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
54 struct mali_dma_buf_attachment **dma_bufs; /**< Array of DMA-bufs used by job */
55 u32 num_dma_bufs; /**< Number of DMA-bufs used by job */
57 struct mali_timeline_tracker tracker; /**< Timeline tracker for this job */
58 u32 perf_counter_per_sub_job_count; /**< Number of values in the two arrays which is != MALI_HW_CORE_NO_COUNTER */
59 u32 perf_counter_per_sub_job_src0[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src0 */
60 u32 perf_counter_per_sub_job_src1[_MALI_PP_MAX_SUB_JOBS]; /**< Per sub job counters src1 */
63 void mali_pp_job_initialize(void);
64 void mali_pp_job_terminate(void);
66 struct mali_pp_job *mali_pp_job_create(struct mali_session_data *session, _mali_uk_pp_start_job_s *uargs, u32 id);
67 void mali_pp_job_delete(struct mali_pp_job *job);
69 u32 mali_pp_job_get_perf_counter_src0(struct mali_pp_job *job, u32 sub_job);
70 u32 mali_pp_job_get_perf_counter_src1(struct mali_pp_job *job, u32 sub_job);
72 void mali_pp_job_set_pp_counter_global_src0(u32 counter);
73 void mali_pp_job_set_pp_counter_global_src1(u32 counter);
74 void mali_pp_job_set_pp_counter_sub_job_src0(u32 sub_job, u32 counter);
75 void mali_pp_job_set_pp_counter_sub_job_src1(u32 sub_job, u32 counter);
77 u32 mali_pp_job_get_pp_counter_global_src0(void);
78 u32 mali_pp_job_get_pp_counter_global_src1(void);
79 u32 mali_pp_job_get_pp_counter_sub_job_src0(u32 sub_job);
80 u32 mali_pp_job_get_pp_counter_sub_job_src1(u32 sub_job);
82 MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
84 return (NULL == job) ? 0 : job->id;
87 MALI_STATIC_INLINE u32 mali_pp_job_get_cache_order(struct mali_pp_job *job)
89 return (NULL == job) ? 0 : job->cache_order;
92 MALI_STATIC_INLINE u32 mali_pp_job_get_user_id(struct mali_pp_job *job)
94 return job->uargs.user_job_ptr;
97 MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
99 return job->uargs.frame_builder_id;
102 MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
104 return job->uargs.flush_id;
107 MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
112 MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
117 MALI_STATIC_INLINE u32* mali_pp_job_get_frame_registers(struct mali_pp_job *job)
119 return job->uargs.frame_registers;
122 MALI_STATIC_INLINE u32* mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
124 return job->uargs.dlbu_registers;
127 MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
129 #if defined(CONFIG_MALI450)
130 return 0 == job->uargs.num_cores;
136 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
138 if (mali_pp_job_is_virtual(job)) {
139 return MALI_DLBU_VIRT_ADDR;
140 } else if (0 == sub_job) {
141 return job->uargs.frame_registers[MALI200_REG_ADDR_FRAME / sizeof(u32)];
142 } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
143 return job->uargs.frame_registers_addr_frame[sub_job - 1];
149 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
152 return job->uargs.frame_registers[MALI200_REG_ADDR_STACK / sizeof(u32)];
153 } else if (sub_job < _MALI_PP_MAX_SUB_JOBS) {
154 return job->uargs.frame_registers_addr_stack[sub_job - 1];
160 MALI_STATIC_INLINE u32* mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
162 return job->uargs.wb0_registers;
165 MALI_STATIC_INLINE u32* mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
167 return job->uargs.wb1_registers;
170 MALI_STATIC_INLINE u32* mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
172 return job->uargs.wb2_registers;
175 MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
177 job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
180 MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
182 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
185 MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
187 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
190 MALI_STATIC_INLINE mali_bool mali_pp_job_all_writeback_unit_disabled(struct mali_pp_job *job)
192 MALI_DEBUG_ASSERT_POINTER(job);
194 if ( job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
195 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] ||
196 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT]
198 /* At least one output unit active */
202 /* All outputs are disabled - we can abort the job */
206 MALI_STATIC_INLINE u32 mali_pp_job_get_fb_lookup_id(struct mali_pp_job *job)
208 MALI_DEBUG_ASSERT_POINTER(job);
210 return MALI_PP_JOB_FB_LOOKUP_LIST_MASK & job->uargs.frame_builder_id;
213 MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
218 MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
220 return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
223 /* Function used when we are terminating a session with jobs. Return TRUE if it has a rendering job.
224 Makes sure that no new subjobs are started. */
225 MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_failed(struct mali_pp_job *job)
227 u32 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
228 job->sub_jobs_started += jobs_remaining;
229 job->sub_jobs_completed += jobs_remaining;
230 job->sub_job_errors += jobs_remaining;
233 MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_success(struct mali_pp_job *job)
235 u32 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
236 job->sub_jobs_started += jobs_remaining;
237 job->sub_jobs_completed += jobs_remaining;
240 MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
242 return (job->sub_jobs_num == job->sub_jobs_completed) ? MALI_TRUE : MALI_FALSE;
245 MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
247 return job->sub_jobs_started;
250 MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
252 return job->sub_jobs_num;
255 MALI_STATIC_INLINE mali_bool mali_pp_job_needs_dma_buf_mapping(struct mali_pp_job *job)
257 MALI_DEBUG_ASSERT(job);
259 if (0 != job->num_memory_cookies) {
266 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
268 MALI_DEBUG_ASSERT_POINTER(job);
270 /* Assert that we are marking the "first unstarted sub job" as started */
271 MALI_DEBUG_ASSERT(job->sub_jobs_started == sub_job);
273 job->sub_jobs_started++;
276 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
278 job->sub_jobs_completed++;
279 if ( MALI_FALSE == success ) {
280 job->sub_job_errors++;
284 MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
286 if ( 0 == job->sub_job_errors ) {
292 MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(struct mali_pp_job *job)
294 return job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION ? MALI_TRUE : MALI_FALSE;
297 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
299 return job->uargs.perf_counter_flag;
303 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
305 return job->perf_counter_value0[sub_job];
308 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
310 return job->perf_counter_value1[sub_job];
313 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
315 job->perf_counter_value0[sub_job] = value;
318 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
320 job->perf_counter_value1[sub_job] = value;
323 MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
325 if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1) {
326 return _MALI_OSK_ERR_FAULT;
328 return _MALI_OSK_ERR_OK;
332 * Returns MALI_TRUE if first job should be started after second job.
334 * @param first First job.
335 * @param second Second job.
336 * @return MALI_TRUE if first job should be started after second job, MALI_FALSE if not.
338 MALI_STATIC_INLINE mali_bool mali_pp_job_should_start_after(struct mali_pp_job *first, struct mali_pp_job *second)
340 MALI_DEBUG_ASSERT_POINTER(first);
341 MALI_DEBUG_ASSERT_POINTER(second);
343 /* First job should be started after second job if second job is in progress. */
344 if (0 < second->sub_jobs_started) {
348 /* First job should be started after second job if first job has a higher job id. A span is
349 used to handle job id wrapping. */
350 if ((mali_pp_job_get_id(first) - mali_pp_job_get_id(second)) < MALI_SCHEDULER_JOB_ID_SPAN) {
354 /* Second job should be started after first job. */
359 * Returns MALI_TRUE if this job has more than two sub jobs and all sub jobs are unstarted.
361 * @param job Job to check.
362 * @return MALI_TRUE if job has more than two sub jobs and all sub jobs are unstarted, MALI_FALSE if not.
364 MALI_STATIC_INLINE mali_bool mali_pp_job_is_large_and_unstarted(struct mali_pp_job *job)
366 MALI_DEBUG_ASSERT_POINTER(job);
367 MALI_DEBUG_ASSERT(!mali_pp_job_is_virtual(job));
369 return (0 == job->sub_jobs_started && 2 < job->sub_jobs_num);
373 * Get PP job's Timeline tracker.
376 * @return Pointer to Timeline tracker for the job.
378 MALI_STATIC_INLINE struct mali_timeline_tracker *mali_pp_job_get_tracker(struct mali_pp_job *job)
380 MALI_DEBUG_ASSERT_POINTER(job);
381 return &(job->tracker);
384 #endif /* __MALI_PP_JOB_H__ */