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_GROUP_H__
12 #define __MALI_GROUP_H__
14 #include "linux/jiffies.h"
16 #include "mali_l2_cache.h"
20 #include "mali_session.h"
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.
27 #define MALI_MAX_NUMBER_OF_GROUPS 10
29 enum mali_group_core_state
31 MALI_GROUP_STATE_IDLE,
32 MALI_GROUP_STATE_WORKING,
34 MALI_GROUP_STATE_IN_VIRTUAL,
35 MALI_GROUP_STATE_JOINING_VIRTUAL,
36 MALI_GROUP_STATE_LEAVING_VIRTUAL,
40 * The structure represents a render group
41 * A render group is defined by all the cores that share the same Mali MMU
46 struct mali_mmu_core *mmu;
47 struct mali_session_data *session;
48 int page_dir_ref_count;
50 mali_bool power_is_on;
51 enum mali_group_core_state state; /* @@@@ TODO: include power_is_on in this state? */
53 struct mali_gp_core *gp_core;
54 struct mali_gp_job *gp_running_job;
56 struct mali_pp_core *pp_core;
57 struct mali_pp_job *pp_running_job;
58 u32 pp_running_sub_job;
60 struct mali_l2_cache_core *l2_cache_core[2];
61 u32 l2_cache_core_ref_count[2];
63 struct mali_dlbu_core *dlbu_core;
64 struct mali_bcast_unit *bcast_core;
66 _mali_osk_lock_t *lock;
68 _mali_osk_list_t pp_scheduler_list;
70 /* List used for virtual groups. For a virtual group, the list represents the
72 _mali_osk_list_t group_list;
74 /* Parent virtual group (if any) */
75 struct mali_group *parent_group;
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;
81 _mali_osk_timer_t *timeout_timer;
82 mali_bool core_timed_out;
85 /** @brief Create a new Mali group object
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
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);
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);
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);
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);
104 void mali_group_delete(struct mali_group *group);
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);
111 MALI_STATIC_INLINE mali_bool mali_group_is_virtual(struct mali_group *group)
113 return (NULL != group->dlbu_core);
116 /** @brief Check if a group is considered as part of a virtual group
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.
121 MALI_STATIC_INLINE mali_bool mali_group_is_in_virtual(struct mali_group *group)
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);
128 /** @brief Reset group
130 * This function will reset the entire group, including all the cores present in the group.
132 * @param group Pointer to the group to reset
134 void mali_group_reset(struct mali_group *group);
136 /** @brief Zap MMU TLB on all groups
138 * Zap TLB on group if \a session is active.
140 void mali_group_zap_session(struct mali_group* group, struct mali_session_data *session);
142 /** @brief Get pointer to GP core object
144 struct mali_gp_core* mali_group_get_gp_core(struct mali_group *group);
146 /** @brief Get pointer to PP core object
148 struct mali_pp_core* mali_group_get_pp_core(struct mali_group *group);
150 /** @brief Lock group object
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.
155 * @param group Pointer to group to lock
157 void mali_group_lock(struct mali_group *group);
159 /** @brief Unlock group object
161 * @param group Pointer to group to unlock
163 void mali_group_unlock(struct mali_group *group);
165 void mali_group_assert_locked(struct mali_group *group);
166 #define MALI_ASSERT_GROUP_LOCKED(group) mali_group_assert_locked(group)
168 #define MALI_ASSERT_GROUP_LOCKED(group)
171 /** @brief Start GP job
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
176 _mali_osk_errcode_t mali_group_start_pp_job(struct mali_group *group, struct mali_pp_job *job, u32 sub_job);
178 /** @brief Resume GP job that suspended waiting for more heap memory
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
183 * Used to abort suspended OOM jobs when user space failed to allocte more memory.
185 void mali_group_abort_gp_job(struct mali_group *group, u32 job_id);
186 /** @brief Abort all GP jobs from \a session
188 * Used on session close when terminating all running and queued jobs from \a session.
190 void mali_group_abort_session(struct mali_group *group, struct mali_session_data *session);
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);
196 struct mali_group *mali_group_get_glob_group(u32 index);
197 u32 mali_group_get_glob_num_groups(void);
199 u32 mali_group_dump_state(struct mali_group *group, char *buf, u32 size);
201 /* MMU-related functions */
202 _mali_osk_errcode_t mali_group_upper_half_mmu(void * data);
204 /* GP-related functions */
205 _mali_osk_errcode_t mali_group_upper_half_gp(void *data);
207 /* PP-related functions */
208 _mali_osk_errcode_t mali_group_upper_half_pp(void *data);
210 #endif /* __MALI_GROUP_H__ */