tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / 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 #include "mali_dma.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"
26 #endif
27
28 /**
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_*
31  * mechanism works)
32  */
33 struct mali_pp_job {
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 */
56 #endif
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 */
61 };
62
63 void mali_pp_job_initialize(void);
64 void mali_pp_job_terminate(void);
65
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);
68
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);
71
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);
76
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);
81
82 MALI_STATIC_INLINE u32 mali_pp_job_get_id(struct mali_pp_job *job)
83 {
84         return (NULL == job) ? 0 : job->id;
85 }
86
87 MALI_STATIC_INLINE u32 mali_pp_job_get_cache_order(struct mali_pp_job *job)
88 {
89         return (NULL == job) ? 0 : job->cache_order;
90 }
91
92 MALI_STATIC_INLINE u32 mali_pp_job_get_user_id(struct mali_pp_job *job)
93 {
94         return job->uargs.user_job_ptr;
95 }
96
97 MALI_STATIC_INLINE u32 mali_pp_job_get_frame_builder_id(struct mali_pp_job *job)
98 {
99         return job->uargs.frame_builder_id;
100 }
101
102 MALI_STATIC_INLINE u32 mali_pp_job_get_flush_id(struct mali_pp_job *job)
103 {
104         return job->uargs.flush_id;
105 }
106
107 MALI_STATIC_INLINE u32 mali_pp_job_get_pid(struct mali_pp_job *job)
108 {
109         return job->pid;
110 }
111
112 MALI_STATIC_INLINE u32 mali_pp_job_get_tid(struct mali_pp_job *job)
113 {
114         return job->tid;
115 }
116
117 MALI_STATIC_INLINE u32* mali_pp_job_get_frame_registers(struct mali_pp_job *job)
118 {
119         return job->uargs.frame_registers;
120 }
121
122 MALI_STATIC_INLINE u32* mali_pp_job_get_dlbu_registers(struct mali_pp_job *job)
123 {
124         return job->uargs.dlbu_registers;
125 }
126
127 MALI_STATIC_INLINE mali_bool mali_pp_job_is_virtual(struct mali_pp_job *job)
128 {
129 #if defined(CONFIG_MALI450)
130         return 0 == job->uargs.num_cores;
131 #else
132         return MALI_FALSE;
133 #endif
134 }
135
136 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_frame(struct mali_pp_job *job, u32 sub_job)
137 {
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];
144         }
145
146         return 0;
147 }
148
149 MALI_STATIC_INLINE u32 mali_pp_job_get_addr_stack(struct mali_pp_job *job, u32 sub_job)
150 {
151         if (0 == 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];
155         }
156
157         return 0;
158 }
159
160 MALI_STATIC_INLINE u32* mali_pp_job_get_wb0_registers(struct mali_pp_job *job)
161 {
162         return job->uargs.wb0_registers;
163 }
164
165 MALI_STATIC_INLINE u32* mali_pp_job_get_wb1_registers(struct mali_pp_job *job)
166 {
167         return job->uargs.wb1_registers;
168 }
169
170 MALI_STATIC_INLINE u32* mali_pp_job_get_wb2_registers(struct mali_pp_job *job)
171 {
172         return job->uargs.wb2_registers;
173 }
174
175 MALI_STATIC_INLINE void mali_pp_job_disable_wb0(struct mali_pp_job *job)
176 {
177         job->uargs.wb0_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
178 }
179
180 MALI_STATIC_INLINE void mali_pp_job_disable_wb1(struct mali_pp_job *job)
181 {
182         job->uargs.wb1_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
183 }
184
185 MALI_STATIC_INLINE void mali_pp_job_disable_wb2(struct mali_pp_job *job)
186 {
187         job->uargs.wb2_registers[MALI200_REG_ADDR_WB_SOURCE_SELECT] = 0;
188 }
189
190 MALI_STATIC_INLINE mali_bool mali_pp_job_all_writeback_unit_disabled(struct mali_pp_job *job)
191 {
192         MALI_DEBUG_ASSERT_POINTER(job);
193
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]
197            ) {
198                 /* At least one output unit active */
199                 return MALI_FALSE;
200         }
201
202         /* All outputs are disabled - we can abort the job */
203         return MALI_TRUE;
204 }
205
206 MALI_STATIC_INLINE u32 mali_pp_job_get_fb_lookup_id(struct mali_pp_job *job)
207 {
208         MALI_DEBUG_ASSERT_POINTER(job);
209
210         return MALI_PP_JOB_FB_LOOKUP_LIST_MASK & job->uargs.frame_builder_id;
211 }
212
213 MALI_STATIC_INLINE struct mali_session_data *mali_pp_job_get_session(struct mali_pp_job *job)
214 {
215         return job->session;
216 }
217
218 MALI_STATIC_INLINE mali_bool mali_pp_job_has_unstarted_sub_jobs(struct mali_pp_job *job)
219 {
220         return (job->sub_jobs_started < job->sub_jobs_num) ? MALI_TRUE : MALI_FALSE;
221 }
222
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)
226 {
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;
231 }
232
233 MALI_STATIC_INLINE void mali_pp_job_mark_unstarted_success(struct mali_pp_job *job)
234 {
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;
238 }
239
240 MALI_STATIC_INLINE mali_bool mali_pp_job_is_complete(struct mali_pp_job *job)
241 {
242         return (job->sub_jobs_num == job->sub_jobs_completed) ? MALI_TRUE : MALI_FALSE;
243 }
244
245 MALI_STATIC_INLINE u32 mali_pp_job_get_first_unstarted_sub_job(struct mali_pp_job *job)
246 {
247         return job->sub_jobs_started;
248 }
249
250 MALI_STATIC_INLINE u32 mali_pp_job_get_sub_job_count(struct mali_pp_job *job)
251 {
252         return job->sub_jobs_num;
253 }
254
255 MALI_STATIC_INLINE mali_bool mali_pp_job_needs_dma_buf_mapping(struct mali_pp_job *job)
256 {
257         MALI_DEBUG_ASSERT(job);
258
259         if (0 != job->num_memory_cookies) {
260                 return MALI_TRUE;
261         }
262
263         return MALI_FALSE;
264 }
265
266 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_started(struct mali_pp_job *job, u32 sub_job)
267 {
268         MALI_DEBUG_ASSERT_POINTER(job);
269
270         /* Assert that we are marking the "first unstarted sub job" as started */
271         MALI_DEBUG_ASSERT(job->sub_jobs_started == sub_job);
272
273         job->sub_jobs_started++;
274 }
275
276 MALI_STATIC_INLINE void mali_pp_job_mark_sub_job_completed(struct mali_pp_job *job, mali_bool success)
277 {
278         job->sub_jobs_completed++;
279         if ( MALI_FALSE == success ) {
280                 job->sub_job_errors++;
281         }
282 }
283
284 MALI_STATIC_INLINE mali_bool mali_pp_job_was_success(struct mali_pp_job *job)
285 {
286         if ( 0 == job->sub_job_errors ) {
287                 return MALI_TRUE;
288         }
289         return MALI_FALSE;
290 }
291
292 MALI_STATIC_INLINE mali_bool mali_pp_job_use_no_notification(struct mali_pp_job *job)
293 {
294         return job->uargs.flags & _MALI_PP_JOB_FLAG_NO_NOTIFICATION ? MALI_TRUE : MALI_FALSE;
295 }
296
297 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job)
298 {
299         return job->uargs.perf_counter_flag;
300 }
301
302
303 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value0(struct mali_pp_job *job, u32 sub_job)
304 {
305         return job->perf_counter_value0[sub_job];
306 }
307
308 MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_value1(struct mali_pp_job *job, u32 sub_job)
309 {
310         return job->perf_counter_value1[sub_job];
311 }
312
313 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value0(struct mali_pp_job *job, u32 sub_job, u32 value)
314 {
315         job->perf_counter_value0[sub_job] = value;
316 }
317
318 MALI_STATIC_INLINE void mali_pp_job_set_perf_counter_value1(struct mali_pp_job *job, u32 sub_job, u32 value)
319 {
320         job->perf_counter_value1[sub_job] = value;
321 }
322
323 MALI_STATIC_INLINE _mali_osk_errcode_t mali_pp_job_check(struct mali_pp_job *job)
324 {
325         if (mali_pp_job_is_virtual(job) && job->sub_jobs_num != 1) {
326                 return _MALI_OSK_ERR_FAULT;
327         }
328         return _MALI_OSK_ERR_OK;
329 }
330
331 /**
332  * Returns MALI_TRUE if first job should be started after second job.
333  *
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.
337  */
338 MALI_STATIC_INLINE mali_bool mali_pp_job_should_start_after(struct mali_pp_job *first, struct mali_pp_job *second)
339 {
340         MALI_DEBUG_ASSERT_POINTER(first);
341         MALI_DEBUG_ASSERT_POINTER(second);
342
343         /* First job should be started after second job if second job is in progress. */
344         if (0 < second->sub_jobs_started) {
345                 return MALI_TRUE;
346         }
347
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) {
351                 return MALI_TRUE;
352         }
353
354         /* Second job should be started after first job. */
355         return MALI_FALSE;
356 }
357
358 /**
359  * Returns MALI_TRUE if this job has more than two sub jobs and all sub jobs are unstarted.
360  *
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.
363  */
364 MALI_STATIC_INLINE mali_bool mali_pp_job_is_large_and_unstarted(struct mali_pp_job *job)
365 {
366         MALI_DEBUG_ASSERT_POINTER(job);
367         MALI_DEBUG_ASSERT(!mali_pp_job_is_virtual(job));
368
369         return (0 == job->sub_jobs_started && 2 < job->sub_jobs_num);
370 }
371
372 /**
373  * Get PP job's Timeline tracker.
374  *
375  * @param job PP job.
376  * @return Pointer to Timeline tracker for the job.
377  */
378 MALI_STATIC_INLINE struct mali_timeline_tracker *mali_pp_job_get_tracker(struct mali_pp_job *job)
379 {
380         MALI_DEBUG_ASSERT_POINTER(job);
381         return &(job->tracker);
382 }
383
384 #endif /* __MALI_PP_JOB_H__ */