2 * Copyright (C) 2011-2012 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"
23 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
24 #include <linux/sync.h>
27 #include "mali_dlbu.h"
30 * The structure represents a PP job, including all sub-jobs
31 * (This struct unfortunately needs to be public because of how the _mali_osk_list_*
36 _mali_osk_list_t list; /**< Used to link jobs together in the scheduler queue */
37 struct mali_session_data *session; /**< Session which submitted this job */
38 _mali_osk_list_t session_list; /**< Used to link jobs together in the session job list */
39 _mali_uk_pp_start_job_s uargs; /**< Arguments from user space */
40 u32 id; /**< Identifier for this job in kernel space (sequential numbering) */
41 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 */
42 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 */
43 u32 sub_jobs_num; /**< Number of subjobs; set to 1 for Mali-450 if DLBU is used, otherwise equals number of PP cores */
44 u32 sub_jobs_started; /**< Total number of sub-jobs started (always started in ascending order) */
45 u32 sub_jobs_completed; /**< Number of completed sub-jobs in this superjob */
46 u32 sub_job_errors; /**< Bitfield with errors (errors for each single sub-job is or'ed together) */
47 u32 pid; /**< Process ID of submitting process */
48 u32 tid; /**< Thread ID of submitting thread */
49 _mali_osk_notification_t *finished_notification; /**< Notification sent back to userspace on job complete */
52 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
53 mali_sync_pt *sync_point; /**< Sync point to signal on completion */
54 struct sync_fence_waiter sync_waiter; /**< Sync waiter for async wait */
55 _mali_osk_wq_work_t *sync_work; /**< Work to schedule in callback */
56 struct sync_fence *pre_fence; /**< Sync fence this job must wait for */
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);
64 u32 mali_pp_job_get_pp_counter_src0(void);
65 mali_bool mali_pp_job_set_pp_counter_src0(u32 counter);
66 u32 mali_pp_job_get_pp_counter_src1(void);
67 mali_bool mali_pp_job_set_pp_counter_src1(u32 counter);
69 MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
71 return (NULL == job) ? 0 : job->id;
74 MALI_STATIC_INLINE u32 mali_pp_job_get_user_id(struct mali_pp_job *job)
76 return job->uargs.user_job_ptr;
79 MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
81 return job->uargs.frame_builder_id;
84 MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
86 return job->uargs.flush_id;
89 MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
94 MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
99 MALI_STATIC_INLINE u32* mali_pp_job_get_frame_registers(struct mali_pp_job *job)
101 return job->uargs.frame_registers;
104 MALI_STATIC_INLINE u32* mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
106 return job->uargs.dlbu_registers;
109 MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
111 return 0 == job->uargs.num_cores;
114 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
116 if (mali_pp_job_is_virtual(job))
118 return MALI_DLBU_VIRT_ADDR;
120 else if (0 == sub_job)
122 return job->uargs.frame_registers[MALI200_REG_ADDR_FRAME / sizeof(u32)];
124 else if (sub_job < _MALI_PP_MAX_SUB_JOBS)
126 return job->uargs.frame_registers_addr_frame[sub_job - 1];
132 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
136 return job->uargs.frame_registers[MALI200_REG_ADDR_STACK / sizeof(u32)];
138 else if (sub_job < _MALI_PP_MAX_SUB_JOBS)
140 return job->uargs.frame_registers_addr_stack[sub_job - 1];
146 MALI_STATIC_INLINE u32* mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
148 return job->uargs.wb0_registers;
151 MALI_STATIC_INLINE u32* mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
153 return job->uargs.wb1_registers;
156 MALI_STATIC_INLINE u32* mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
158 return job->uargs.wb2_registers;
161 MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
163 job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
166 MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
168 job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
171 MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
173 job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
176 MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
181 MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
183 return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
186 /* Function used when we are terminating a session with jobs. Return TRUE if it has a rendering job.
187 Makes sure that no new subjobs are started. */
188 MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_failed(struct mali_pp_job *job)
190 u32 jobs_remaining = job->sub_jobs_num - job->sub_jobs_started;
191 job->sub_jobs_started += jobs_remaining;
192 job->sub_jobs_completed += jobs_remaining;
193 job->sub_job_errors += jobs_remaining;
196 MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
198 return (job->sub_jobs_num == job->sub_jobs_completed) ? MALI_TRUE : MALI_FALSE;
201 MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
203 return job->sub_jobs_started;
206 MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
208 return job->sub_jobs_num;
211 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
213 /* Assert that we are marking the "first unstarted sub job" as started */
214 MALI_DEBUG_ASSERT(job->sub_jobs_started == sub_job);
215 job->sub_jobs_started++;
218 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_not_stated(struct mali_pp_job *job, u32 sub_job)
220 /* This is only safe on Mali-200. */
221 MALI_DEBUG_ASSERT(_MALI_PRODUCT_ID_MALI200 == mali_kernel_core_get_product_id());
223 job->sub_jobs_started--;
226 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
228 job->sub_jobs_completed++;
229 if ( MALI_FALSE == success )
231 job->sub_job_errors++;
235 MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
237 if ( 0 == job->sub_job_errors )
244 MALI_STATIC_INLINE mali_bool mali_pp_job_has_active_barrier(struct mali_pp_job *job)
246 return job->uargs.flags & _MALI_PP_JOB_FLAG_BARRIER ? MALI_TRUE : MALI_FALSE;
249 MALI_STATIC_INLINE void mali_pp_job_barrier_enforced(struct mali_pp_job *job)
251 job->uargs.flags &= ~_MALI_PP_JOB_FLAG_BARRIER;
254 MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(struct mali_pp_job *job)
256 return job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION ? MALI_TRUE : MALI_FALSE;
259 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
261 return job->uargs.perf_counter_flag;
264 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_src0(struct mali_pp_job *job)
266 return job->uargs.perf_counter_src0;
269 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_src1(struct mali_pp_job *job)
271 return job->uargs.perf_counter_src1;
274 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
276 return job->perf_counter_value0[sub_job];
279 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
281 return job->perf_counter_value1[sub_job];
284 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_src0(struct mali_pp_job *job, u32 src)
286 job->uargs.perf_counter_src0 = src;
289 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_src1(struct mali_pp_job *job, u32 src)
291 job->uargs.perf_counter_src1 = src;
294 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
296 job->perf_counter_value0[sub_job] = value;
299 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
301 job->perf_counter_value1[sub_job] = value;
304 MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
306 if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1)
308 return _MALI_OSK_ERR_FAULT;
310 return _MALI_OSK_ERR_OK;
313 #endif /* __MALI_PP_JOB_H__ */