tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_pp_job.h
1 /*
2  * Copyright (C) 2011-2012 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 #ifdef CONFIG_SYNC
22 /* MALI_SEC */
23 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
24 #include <linux/sync.h>
25 #endif
26 #endif
27 #include "mali_dlbu.h"
28
29 /**
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_*
32  * mechanism works)
33  */
34 struct mali_pp_job
35 {
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 */
50 #ifdef CONFIG_SYNC
51 /* MALI_SEC */
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 */
57 #endif
58 #endif
59 };
60
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
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);
68
69 MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
70 {
71         return (NULL == job) ? 0 : job->id;
72 }
73
74 MALI_STATIC_INLINE u32 mali_pp_job_get_user_id(struct mali_pp_job *job)
75 {
76         return job->uargs.user_job_ptr;
77 }
78
79 MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
80 {
81         return job->uargs.frame_builder_id;
82 }
83
84 MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
85 {
86         return job->uargs.flush_id;
87 }
88
89 MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
90 {
91         return job->pid;
92 }
93
94 MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
95 {
96         return job->tid;
97 }
98
99 MALI_STATIC_INLINE u32* mali_pp_job_get_frame_registers(struct mali_pp_job *job)
100 {
101         return job->uargs.frame_registers;
102 }
103
104 MALI_STATIC_INLINE u32* mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
105 {
106         return job->uargs.dlbu_registers;
107 }
108
109 MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
110 {
111         return 0 == job->uargs.num_cores;
112 }
113
114 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
115 {
116         if (mali_pp_job_is_virtual(job))
117         {
118                 return MALI_DLBU_VIRT_ADDR;
119         }
120         else if (0 == sub_job)
121         {
122                 return job->uargs.frame_registers[MALI200_REG_ADDR_FRAME / sizeof(u32)];
123         }
124         else if (sub_job < _MALI_PP_MAX_SUB_JOBS)
125         {
126                 return job->uargs.frame_registers_addr_frame[sub_job - 1];
127         }
128
129         return 0;
130 }
131
132 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
133 {
134         if (0 == sub_job)
135         {
136                 return job->uargs.frame_registers[MALI200_REG_ADDR_STACK / sizeof(u32)];
137         }
138         else if (sub_job < _MALI_PP_MAX_SUB_JOBS)
139         {
140                 return job->uargs.frame_registers_addr_stack[sub_job - 1];
141         }
142
143         return 0;
144 }
145
146 MALI_STATIC_INLINE u32* mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
147 {
148         return job->uargs.wb0_registers;
149 }
150
151 MALI_STATIC_INLINE u32* mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
152 {
153         return job->uargs.wb1_registers;
154 }
155
156 MALI_STATIC_INLINE u32* mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
157 {
158         return job->uargs.wb2_registers;
159 }
160
161 MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
162 {
163         job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
164 }
165
166 MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
167 {
168         job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
169 }
170
171 MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
172 {
173         job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
174 }
175
176 MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
177 {
178         return job->session;
179 }
180
181 MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
182 {
183         return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
184 }
185
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)
189 {
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;
194 }
195
196 MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
197 {
198         return (job->sub_jobs_num == job->sub_jobs_completed) ? MALI_TRUE : MALI_FALSE;
199 }
200
201 MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
202 {
203         return job->sub_jobs_started;
204 }
205
206 MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
207 {
208         return job->sub_jobs_num;
209 }
210
211 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
212 {
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++;
216 }
217
218 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_not_stated(struct mali_pp_job *job, u32 sub_job)
219 {
220         /* This is only safe on Mali-200. */
221         MALI_DEBUG_ASSERT(_MALI_PRODUCT_ID_MALI200 == mali_kernel_core_get_product_id());
222
223         job->sub_jobs_started--;
224 }
225
226 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
227 {
228         job->sub_jobs_completed++;
229         if ( MALI_FALSE == success )
230         {
231                 job->sub_job_errors++;
232         }
233 }
234
235 MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
236 {
237         if ( 0 == job->sub_job_errors )
238         {
239                 return MALI_TRUE;
240         }
241         return MALI_FALSE;
242 }
243
244 MALI_STATIC_INLINE mali_bool mali_pp_job_has_active_barrier(struct mali_pp_job *job)
245 {
246         return job->uargs.flags & _MALI_PP_JOB_FLAG_BARRIER ? MALI_TRUE : MALI_FALSE;
247 }
248
249 MALI_STATIC_INLINE void mali_pp_job_barrier_enforced(struct mali_pp_job *job)
250 {
251         job->uargs.flags &= ~_MALI_PP_JOB_FLAG_BARRIER;
252 }
253
254 MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(struct mali_pp_job *job)
255 {
256         return job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION ? MALI_TRUE : MALI_FALSE;
257 }
258
259 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
260 {
261         return job->uargs.perf_counter_flag;
262 }
263
264 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_src0(struct mali_pp_job *job)
265 {
266         return job->uargs.perf_counter_src0;
267 }
268
269 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_src1(struct mali_pp_job *job)
270 {
271         return job->uargs.perf_counter_src1;
272 }
273
274 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
275 {
276         return job->perf_counter_value0[sub_job];
277 }
278
279 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
280 {
281         return job->perf_counter_value1[sub_job];
282 }
283
284 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_src0(struct mali_pp_job *job, u32 src)
285 {
286         job->uargs.perf_counter_src0 = src;
287 }
288
289 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_src1(struct mali_pp_job *job, u32 src)
290 {
291         job->uargs.perf_counter_src1 = src;
292 }
293
294 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
295 {
296         job->perf_counter_value0[sub_job] = value;
297 }
298
299 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
300 {
301         job->perf_counter_value1[sub_job] = value;
302 }
303
304 MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
305 {
306         if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1)
307         {
308                 return _MALI_OSK_ERR_FAULT;
309         }
310         return _MALI_OSK_ERR_OK;
311 }
312
313 #endif /* __MALI_PP_JOB_H__ */