tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / common / mali_gp_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_GP_JOB_H__
12 #define __MALI_GP_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_timeline.h"
19 #include "mali_scheduler_types.h"
20
21 /**
22  * The structure represents a GP job, including all sub-jobs
23  * (This struct unfortunately needs to be public because of how the _mali_osk_list_*
24  * mechanism works)
25  */
26 struct mali_gp_job {
27         _mali_osk_list_t list;                             /**< Used to link jobs together in the scheduler queue */
28         struct mali_session_data *session;                 /**< Session which submitted this job */
29         _mali_uk_gp_start_job_s uargs;                     /**< Arguments from user space */
30         u32 id;                                            /**< Identifier for this job in kernel space (sequential numbering) */
31         u32 cache_order;                                   /**< Cache order used for L2 cache flushing (sequential numbering) */
32         u32 heap_current_addr;                             /**< Holds the current HEAP address when the job has completed */
33         u32 perf_counter_value0;                           /**< Value of performance counter 0 (to be returned to user space) */
34         u32 perf_counter_value1;                           /**< Value of performance counter 1 (to be returned to user space) */
35         u32 pid;                                           /**< Process ID of submitting process */
36         u32 tid;                                           /**< Thread ID of submitting thread */
37         _mali_osk_notification_t *finished_notification;   /**< Notification sent back to userspace on job complete */
38         _mali_osk_notification_t *oom_notification;        /**< Notification sent back to userspace on OOM */
39         struct mali_timeline_tracker tracker;              /**< Timeline tracker for this job */
40         struct mali_timeline_tracker *pp_tracker;          /**< Pointer to Timeline tracker for PP job that depends on this job. */
41 };
42
43 struct mali_gp_job *mali_gp_job_create(struct mali_session_data *session, _mali_uk_gp_start_job_s *uargs, u32 id, struct mali_timeline_tracker *pp_tracker);
44 void mali_gp_job_delete(struct mali_gp_job *job);
45
46 u32 mali_gp_job_get_gp_counter_src0(void);
47 void mali_gp_job_set_gp_counter_src0(u32 counter);
48 u32 mali_gp_job_get_gp_counter_src1(void);
49 void mali_gp_job_set_gp_counter_src1(u32 counter);
50
51 MALI_STATIC_INLINE u32 mali_gp_job_get_id(struct mali_gp_job *job)
52 {
53         return (NULL == job) ? 0 : job->id;
54 }
55
56 MALI_STATIC_INLINE u32 mali_gp_job_get_cache_order(struct mali_gp_job *job)
57 {
58         return (NULL == job) ? 0 : job->cache_order;
59 }
60
61 MALI_STATIC_INLINE u32 mali_gp_job_get_user_id(struct mali_gp_job *job)
62 {
63         return job->uargs.user_job_ptr;
64 }
65
66 MALI_STATIC_INLINE u32 mali_gp_job_get_frame_builder_id(struct mali_gp_job *job)
67 {
68         return job->uargs.frame_builder_id;
69 }
70
71 MALI_STATIC_INLINE u32 mali_gp_job_get_flush_id(struct mali_gp_job *job)
72 {
73         return job->uargs.flush_id;
74 }
75
76 MALI_STATIC_INLINE u32 mali_gp_job_get_pid(struct mali_gp_job *job)
77 {
78         return job->pid;
79 }
80
81 MALI_STATIC_INLINE u32 mali_gp_job_get_tid(struct mali_gp_job *job)
82 {
83         return job->tid;
84 }
85
86 MALI_STATIC_INLINE u32* mali_gp_job_get_frame_registers(struct mali_gp_job *job)
87 {
88         return job->uargs.frame_registers;
89 }
90
91 MALI_STATIC_INLINE struct mali_session_data *mali_gp_job_get_session(struct mali_gp_job *job)
92 {
93         return job->session;
94 }
95
96 MALI_STATIC_INLINE mali_bool mali_gp_job_has_vs_job(struct mali_gp_job *job)
97 {
98         return (job->uargs.frame_registers[0] != job->uargs.frame_registers[1]) ? MALI_TRUE : MALI_FALSE;
99 }
100
101 MALI_STATIC_INLINE mali_bool mali_gp_job_has_plbu_job(struct mali_gp_job *job)
102 {
103         return (job->uargs.frame_registers[2] != job->uargs.frame_registers[3]) ? MALI_TRUE : MALI_FALSE;
104 }
105
106 MALI_STATIC_INLINE u32 mali_gp_job_get_current_heap_addr(struct mali_gp_job *job)
107 {
108         return job->heap_current_addr;
109 }
110
111 MALI_STATIC_INLINE void mali_gp_job_set_current_heap_addr(struct mali_gp_job *job, u32 heap_addr)
112 {
113         job->heap_current_addr = heap_addr;
114 }
115
116 MALI_STATIC_INLINE u32 mali_gp_job_get_perf_counter_flag(struct mali_gp_job *job)
117 {
118         return job->uargs.perf_counter_flag;
119 }
120
121 MALI_STATIC_INLINE u32 mali_gp_job_get_perf_counter_src0(struct mali_gp_job *job)
122 {
123         return job->uargs.perf_counter_src0;
124 }
125
126 MALI_STATIC_INLINE u32 mali_gp_job_get_perf_counter_src1(struct mali_gp_job *job)
127 {
128         return job->uargs.perf_counter_src1;
129 }
130
131 MALI_STATIC_INLINE u32 mali_gp_job_get_perf_counter_value0(struct mali_gp_job *job)
132 {
133         return job->perf_counter_value0;
134 }
135
136 MALI_STATIC_INLINE u32 mali_gp_job_get_perf_counter_value1(struct mali_gp_job *job)
137 {
138         return job->perf_counter_value1;
139 }
140
141 MALI_STATIC_INLINE void mali_gp_job_set_perf_counter_src0(struct mali_gp_job *job, u32 src)
142 {
143         job->uargs.perf_counter_src0 = src;
144 }
145
146 MALI_STATIC_INLINE void mali_gp_job_set_perf_counter_src1(struct mali_gp_job *job, u32 src)
147 {
148         job->uargs.perf_counter_src1 = src;
149 }
150
151 MALI_STATIC_INLINE void mali_gp_job_set_perf_counter_value0(struct mali_gp_job *job, u32 value)
152 {
153         job->perf_counter_value0 = value;
154 }
155
156 MALI_STATIC_INLINE void mali_gp_job_set_perf_counter_value1(struct mali_gp_job *job, u32 value)
157 {
158         job->perf_counter_value1 = value;
159 }
160
161 /**
162  * Returns MALI_TRUE if first job is after the second job, ordered by job ID.
163  *
164  * @param first First job.
165  * @param second Second job.
166  * @return MALI_TRUE if first job should be ordered after the second job, MALI_FALSE if not.
167  */
168 MALI_STATIC_INLINE mali_bool mali_gp_job_is_after(struct mali_gp_job *first, struct mali_gp_job *second)
169 {
170         /* A span is used to handle job ID wrapping. */
171         return (mali_gp_job_get_id(first) - mali_gp_job_get_id(second)) < MALI_SCHEDULER_JOB_ID_SPAN;
172 }
173
174 /**
175  * Release reference on tracker for PP job that depends on this GP job.
176  *
177  * @note If GP job has a reference on tracker, this function MUST be called before the GP job is
178  * deleted.
179  *
180  * @param job GP job that is done.
181  * @param success MALI_TRUE if job completed successfully, MALI_FALSE if not.
182  * @return A scheduling bitmask indicating whether scheduling needs to be done.
183  */
184 mali_scheduler_mask mali_gp_job_signal_pp_tracker(struct mali_gp_job *job, mali_bool success);
185
186 #endif /* __MALI_GP_JOB_H__ */