tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / common / mali_group.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_GROUP_H__
12 #define __MALI_GROUP_H__
13
14 #include "linux/jiffies.h"
15 #include "mali_osk.h"
16 #include "mali_l2_cache.h"
17 #include "mali_mmu.h"
18 #include "mali_gp.h"
19 #include "mali_pp.h"
20 #include "mali_session.h"
21
22 /* max runtime [ms] for a core job - used by timeout timers  */
23 #define MAX_RUNTIME 5000
24 /** @brief A mali group object represents a MMU and a PP and/or a GP core.
25  *
26  */
27 #define MALI_MAX_NUMBER_OF_GROUPS 10
28
29 enum mali_group_core_state
30 {
31         MALI_GROUP_STATE_IDLE,
32         MALI_GROUP_STATE_WORKING,
33         MALI_GROUP_STATE_OOM,
34         MALI_GROUP_STATE_IN_VIRTUAL,
35         MALI_GROUP_STATE_JOINING_VIRTUAL,
36         MALI_GROUP_STATE_LEAVING_VIRTUAL,
37 };
38
39 /**
40  * The structure represents a render group
41  * A render group is defined by all the cores that share the same Mali MMU
42  */
43
44 struct mali_group
45 {
46         struct mali_mmu_core        *mmu;
47         struct mali_session_data    *session;
48         int                         page_dir_ref_count;
49
50         mali_bool                   power_is_on;
51         enum mali_group_core_state  state; /* @@@@ TODO: include power_is_on in this state? */
52
53         struct mali_gp_core         *gp_core;
54         struct mali_gp_job          *gp_running_job;
55
56         struct mali_pp_core         *pp_core;
57         struct mali_pp_job          *pp_running_job;
58         u32                         pp_running_sub_job;
59
60         struct mali_l2_cache_core   *l2_cache_core[2];
61         u32                         l2_cache_core_ref_count[2];
62
63         struct mali_dlbu_core       *dlbu_core;
64         struct mali_bcast_unit      *bcast_core;
65
66         _mali_osk_lock_t            *lock;
67
68         _mali_osk_list_t            pp_scheduler_list;
69
70         /* List used for virtual groups. For a virtual group, the list represents the
71          * head element. */
72         _mali_osk_list_t            group_list;
73
74         /* Parent virtual group (if any) */
75         struct mali_group           *parent_group;
76
77         _mali_osk_wq_work_t         *bottom_half_work_mmu;
78         _mali_osk_wq_work_t         *bottom_half_work_gp;
79         _mali_osk_wq_work_t         *bottom_half_work_pp;
80
81         _mali_osk_timer_t           *timeout_timer;
82         mali_bool                   core_timed_out;
83 };
84
85 /** @brief Create a new Mali group object
86  *
87  * @param cluster Pointer to the cluster to which the group is connected.
88  * @param mmu Pointer to the MMU that defines this group
89  * @return A pointer to a new group object
90  */
91 struct mali_group *mali_group_create(struct mali_l2_cache_core *core,
92                                      struct mali_dlbu_core *dlbu,
93                                      struct mali_bcast_unit *bcast);
94
95 _mali_osk_errcode_t mali_group_add_mmu_core(struct mali_group *group, struct mali_mmu_core* mmu_core);
96 void mali_group_remove_mmu_core(struct mali_group *group);
97
98 _mali_osk_errcode_t mali_group_add_gp_core(struct mali_group *group, struct mali_gp_core* gp_core);
99 void mali_group_remove_gp_core(struct mali_group *group);
100
101 _mali_osk_errcode_t mali_group_add_pp_core(struct mali_group *group, struct mali_pp_core* pp_core);
102 void mali_group_remove_pp_core(struct mali_group *group);
103
104 void mali_group_delete(struct mali_group *group);
105
106 /** @brief Virtual groups */
107 void mali_group_add_group(struct mali_group *parent, struct mali_group *child);
108 void mali_group_remove_group(struct mali_group *parent, struct mali_group *child);
109 struct mali_group *mali_group_acquire_group(struct mali_group *parent);
110
111 MALI_STATIC_INLINE mali_bool mali_group_is_virtual(struct mali_group *group)
112 {
113         return (NULL != group->dlbu_core);
114 }
115
116 /** @brief Check if a group is considered as part of a virtual group
117  *
118  * @note A group is considered to be "part of" a virtual group also during the transition
119  *       in to / out of the virtual group.
120  */
121 MALI_STATIC_INLINE mali_bool mali_group_is_in_virtual(struct mali_group *group)
122 {
123         return (MALI_GROUP_STATE_IN_VIRTUAL == group->state ||
124                 MALI_GROUP_STATE_JOINING_VIRTUAL == group->state ||
125                 MALI_GROUP_STATE_LEAVING_VIRTUAL == group->state);
126 }
127
128 /** @brief Reset group
129  *
130  * This function will reset the entire group, including all the cores present in the group.
131  *
132  * @param group Pointer to the group to reset
133  */
134 void mali_group_reset(struct mali_group *group);
135
136 /** @brief Zap MMU TLB on all groups
137  *
138  * Zap TLB on group if \a session is active.
139  */
140 void mali_group_zap_session(struct mali_group* group, struct mali_session_data *session);
141
142 /** @brief Get pointer to GP core object
143  */
144 struct mali_gp_core* mali_group_get_gp_core(struct mali_group *group);
145
146 /** @brief Get pointer to PP core object
147  */
148 struct mali_pp_core* mali_group_get_pp_core(struct mali_group *group);
149
150 /** @brief Lock group object
151  *
152  * Most group functions will lock the group object themselves. The expection is
153  * the group_bottom_half which requires the group to be locked on entry.
154  *
155  * @param group Pointer to group to lock
156  */
157 void mali_group_lock(struct mali_group *group);
158
159 /** @brief Unlock group object
160  *
161  * @param group Pointer to group to unlock
162  */
163 void mali_group_unlock(struct mali_group *group);
164 #ifdef DEBUG
165 void mali_group_assert_locked(struct mali_group *group);
166 #define MALI_ASSERT_GROUP_LOCKED(group) mali_group_assert_locked(group)
167 #else
168 #define MALI_ASSERT_GROUP_LOCKED(group)
169 #endif
170
171 /** @brief Start GP job
172  */
173 _mali_osk_errcode_t mali_group_start_gp_job(struct mali_group *group, struct mali_gp_job *job);
174 /** @brief Start fragment of PP job
175  */
176 _mali_osk_errcode_t mali_group_start_pp_job(struct mali_group *group, struct mali_pp_job *job, u32 sub_job);
177
178 /** @brief Resume GP job that suspended waiting for more heap memory
179  */
180 struct mali_gp_job *mali_group_resume_gp_with_new_heap(struct mali_group *group, u32 job_id, u32 start_addr, u32 end_addr);
181 /** @brief Abort GP job
182  *
183  * Used to abort suspended OOM jobs when user space failed to allocte more memory.
184  */
185 void mali_group_abort_gp_job(struct mali_group *group, u32 job_id);
186 /** @brief Abort all GP jobs from \a session
187  *
188  * Used on session close when terminating all running and queued jobs from \a session.
189  */
190 void mali_group_abort_session(struct mali_group *group, struct mali_session_data *session);
191
192 void mali_group_power_on(void);
193 void mali_group_power_off(void);
194 mali_bool mali_group_power_is_on(struct mali_group *group);
195
196 struct mali_group *mali_group_get_glob_group(u32 index);
197 u32 mali_group_get_glob_num_groups(void);
198
199 u32 mali_group_dump_state(struct mali_group *group, char *buf, u32 size);
200
201 /* MMU-related functions */
202 _mali_osk_errcode_t mali_group_upper_half_mmu(void * data);
203
204 /* GP-related functions */
205 _mali_osk_errcode_t mali_group_upper_half_gp(void *data);
206
207 /* PP-related functions */
208 _mali_osk_errcode_t mali_group_upper_half_pp(void *data);
209
210 #endif /* __MALI_GROUP_H__ */