mali_group.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * This confidential and proprietary software may be used only as
  3. * authorised by a licensing agreement from ARM Limited
  4. * (C) COPYRIGHT 2011-2013 ARM Limited
  5. * ALL RIGHTS RESERVED
  6. * The entire notice above must be reproduced on all authorised
  7. * copies and copies may only be made to the extent permitted
  8. * by a licensing agreement from ARM Limited.
  9. */
  10. #ifndef __MALI_GROUP_H__
  11. #define __MALI_GROUP_H__
  12. #include "linux/jiffies.h"
  13. #include "mali_osk.h"
  14. #include "mali_l2_cache.h"
  15. #include "mali_mmu.h"
  16. #include "mali_gp.h"
  17. #include "mali_pp.h"
  18. #include "mali_session.h"
  19. /**
  20. * @brief Default max runtime [ms] for a core job - used by timeout timers
  21. */
  22. #define MALI_MAX_JOB_RUNTIME_DEFAULT 4000
  23. /** @brief A mali group object represents a MMU and a PP and/or a GP core.
  24. *
  25. */
  26. #define MALI_MAX_NUMBER_OF_GROUPS 10
  27. enum mali_group_core_state {
  28. MALI_GROUP_STATE_IDLE,
  29. MALI_GROUP_STATE_WORKING,
  30. MALI_GROUP_STATE_OOM,
  31. MALI_GROUP_STATE_IN_VIRTUAL,
  32. MALI_GROUP_STATE_JOINING_VIRTUAL,
  33. MALI_GROUP_STATE_LEAVING_VIRTUAL,
  34. MALI_GROUP_STATE_DISABLED,
  35. };
  36. /* Forward declaration from mali_pm_domain.h */
  37. struct mali_pm_domain;
  38. /**
  39. * The structure represents a render group
  40. * A render group is defined by all the cores that share the same Mali MMU
  41. */
  42. struct mali_group {
  43. struct mali_mmu_core *mmu;
  44. struct mali_session_data *session;
  45. mali_bool power_is_on;
  46. enum mali_group_core_state state;
  47. struct mali_gp_core *gp_core;
  48. struct mali_gp_job *gp_running_job;
  49. struct mali_pp_core *pp_core;
  50. struct mali_pp_job *pp_running_job;
  51. u32 pp_running_sub_job;
  52. struct mali_l2_cache_core *l2_cache_core[2];
  53. u32 l2_cache_core_ref_count[2];
  54. struct mali_dlbu_core *dlbu_core;
  55. struct mali_bcast_unit *bcast_core;
  56. #ifdef MALI_UPPER_HALF_SCHEDULING
  57. _mali_osk_spinlock_irq_t *lock;
  58. #else
  59. _mali_osk_spinlock_t *lock;
  60. #endif
  61. _mali_osk_list_t pp_scheduler_list;
  62. /* List used for virtual groups. For a virtual group, the list represents the
  63. * head element. */
  64. _mali_osk_list_t group_list;
  65. struct mali_group *pm_domain_list;
  66. struct mali_pm_domain *pm_domain;
  67. /* Parent virtual group (if any) */
  68. struct mali_group *parent_group;
  69. _mali_osk_wq_work_t *bottom_half_work_mmu;
  70. _mali_osk_wq_work_t *bottom_half_work_gp;
  71. _mali_osk_wq_work_t *bottom_half_work_pp;
  72. _mali_osk_timer_t *timeout_timer;
  73. mali_bool core_timed_out;
  74. };
  75. /** @brief Create a new Mali group object
  76. *
  77. * @param cluster Pointer to the cluster to which the group is connected.
  78. * @param mmu Pointer to the MMU that defines this group
  79. * @return A pointer to a new group object
  80. */
  81. struct mali_group *mali_group_create(struct mali_l2_cache_core *core,
  82. struct mali_dlbu_core *dlbu,
  83. struct mali_bcast_unit *bcast);
  84. _mali_osk_errcode_t mali_group_add_mmu_core(struct mali_group *group, struct mali_mmu_core* mmu_core);
  85. void mali_group_remove_mmu_core(struct mali_group *group);
  86. _mali_osk_errcode_t mali_group_add_gp_core(struct mali_group *group, struct mali_gp_core* gp_core);
  87. void mali_group_remove_gp_core(struct mali_group *group);
  88. _mali_osk_errcode_t mali_group_add_pp_core(struct mali_group *group, struct mali_pp_core* pp_core);
  89. void mali_group_remove_pp_core(struct mali_group *group);
  90. void mali_group_set_pm_domain(struct mali_group *group, struct mali_pm_domain *domain);
  91. void mali_group_delete(struct mali_group *group);
  92. /** @brief Virtual groups */
  93. void mali_group_add_group(struct mali_group *parent, struct mali_group *child, mali_bool update_hw);
  94. void mali_group_remove_group(struct mali_group *parent, struct mali_group *child);
  95. struct mali_group *mali_group_acquire_group(struct mali_group *parent);
  96. MALI_STATIC_INLINE mali_bool mali_group_is_virtual(struct mali_group *group)
  97. {
  98. #if (defined(CONFIG_MALI450) || defined(CONFIG_MALI470))
  99. return (NULL != group->dlbu_core);
  100. #else
  101. return MALI_FALSE;
  102. #endif
  103. }
  104. /** @brief Check if a group is a part of a virtual group or not
  105. *
  106. * @note A group is considered to be "part of" a virtual group also during the transition
  107. * in to / out of the virtual group.
  108. */
  109. MALI_STATIC_INLINE mali_bool mali_group_is_in_virtual(struct mali_group *group)
  110. {
  111. #if (defined(CONFIG_MALI450) || defined(CONFIG_MALI470))
  112. return (MALI_GROUP_STATE_IN_VIRTUAL == group->state ||
  113. MALI_GROUP_STATE_JOINING_VIRTUAL == group->state ||
  114. MALI_GROUP_STATE_LEAVING_VIRTUAL == group->state);
  115. #else
  116. return MALI_FALSE;
  117. #endif
  118. }
  119. /** @brief Reset group
  120. *
  121. * This function will reset the entire group, including all the cores present in the group.
  122. *
  123. * @param group Pointer to the group to reset
  124. */
  125. void mali_group_reset(struct mali_group *group);
  126. /** @brief Zap MMU TLB on all groups
  127. *
  128. * Zap TLB on group if \a session is active.
  129. */
  130. void mali_group_zap_session(struct mali_group* group, struct mali_session_data *session);
  131. /** @brief Get pointer to GP core object
  132. */
  133. struct mali_gp_core* mali_group_get_gp_core(struct mali_group *group);
  134. /** @brief Get pointer to PP core object
  135. */
  136. struct mali_pp_core* mali_group_get_pp_core(struct mali_group *group);
  137. /** @brief Lock group object
  138. *
  139. * Most group functions will lock the group object themselves. The expection is
  140. * the group_bottom_half which requires the group to be locked on entry.
  141. *
  142. * @param group Pointer to group to lock
  143. */
  144. void mali_group_lock(struct mali_group *group);
  145. /** @brief Unlock group object
  146. *
  147. * @param group Pointer to group to unlock
  148. */
  149. void mali_group_unlock(struct mali_group *group);
  150. #ifdef DEBUG
  151. void mali_group_assert_locked(struct mali_group *group);
  152. #define MALI_ASSERT_GROUP_LOCKED(group) mali_group_assert_locked(group)
  153. #else
  154. #define MALI_ASSERT_GROUP_LOCKED(group)
  155. #endif
  156. /** @brief Start GP job
  157. */
  158. void mali_group_start_gp_job(struct mali_group *group, struct mali_gp_job *job);
  159. /** @brief Start fragment of PP job
  160. */
  161. void mali_group_start_pp_job(struct mali_group *group, struct mali_pp_job *job, u32 sub_job);
  162. /** @brief Resume GP job that suspended waiting for more heap memory
  163. */
  164. struct mali_gp_job *mali_group_resume_gp_with_new_heap(struct mali_group *group, u32 job_id, u32 start_addr, u32 end_addr);
  165. /** @brief Abort GP job
  166. *
  167. * Used to abort suspended OOM jobs when user space failed to allocte more memory.
  168. */
  169. void mali_group_abort_gp_job(struct mali_group *group, u32 job_id);
  170. /** @brief Abort all GP jobs from \a session
  171. *
  172. * Used on session close when terminating all running and queued jobs from \a session.
  173. */
  174. void mali_group_abort_session(struct mali_group *group, struct mali_session_data *session);
  175. mali_bool mali_group_power_is_on(struct mali_group *group);
  176. void mali_group_power_on_group(struct mali_group *group);
  177. void mali_group_power_off_group(struct mali_group *group, mali_bool power_status);
  178. void mali_group_power_on(void);
  179. /** @brief Prepare group for power off
  180. *
  181. * Update the group's state and prepare for the group to be powered off.
  182. *
  183. * If do_power_change is MALI_FALSE group session will be set to NULL so that
  184. * no more activity will happen to this group, but the power state flag will be
  185. * left unchanged.
  186. *
  187. * @do_power_change MALI_TRUE if power status is to be updated
  188. */
  189. void mali_group_power_off(mali_bool do_power_change);
  190. struct mali_group *mali_group_get_glob_group(u32 index);
  191. u32 mali_group_get_glob_num_groups(void);
  192. u32 mali_group_dump_state(struct mali_group *group, char *buf, u32 size);
  193. /* MMU-related functions */
  194. _mali_osk_errcode_t mali_group_upper_half_mmu(void * data);
  195. /* GP-related functions */
  196. _mali_osk_errcode_t mali_group_upper_half_gp(void *data);
  197. /* PP-related functions */
  198. _mali_osk_errcode_t mali_group_upper_half_pp(void *data);
  199. /** @brief Check if group is enabled
  200. *
  201. * @param group group to check
  202. * @return MALI_TRUE if enabled, MALI_FALSE if not
  203. */
  204. mali_bool mali_group_is_enabled(struct mali_group *group);
  205. /** @brief Enable group
  206. *
  207. * An enabled job is put on the idle scheduler list and can be used to handle jobs. Does nothing if
  208. * group is already enabled.
  209. *
  210. * @param group group to enable
  211. */
  212. void mali_group_enable(struct mali_group *group);
  213. /** @brief Disable group
  214. *
  215. * A disabled group will no longer be used by the scheduler. If part of a virtual group, the group
  216. * will be removed before being disabled. Cores part of a disabled group is safe to power down.
  217. *
  218. * @param group group to disable
  219. */
  220. void mali_group_disable(struct mali_group *group);
  221. MALI_STATIC_INLINE mali_bool mali_group_virtual_disable_if_empty(struct mali_group *group)
  222. {
  223. mali_bool empty = MALI_FALSE;
  224. MALI_ASSERT_GROUP_LOCKED(group);
  225. MALI_DEBUG_ASSERT(mali_group_is_virtual(group));
  226. if (_mali_osk_list_empty(&group->group_list)) {
  227. group->state = MALI_GROUP_STATE_DISABLED;
  228. group->session = NULL;
  229. empty = MALI_TRUE;
  230. }
  231. return empty;
  232. }
  233. MALI_STATIC_INLINE mali_bool mali_group_virtual_enable_if_empty(struct mali_group *group)
  234. {
  235. mali_bool empty = MALI_FALSE;
  236. MALI_ASSERT_GROUP_LOCKED(group);
  237. MALI_DEBUG_ASSERT(mali_group_is_virtual(group));
  238. if (_mali_osk_list_empty(&group->group_list)) {
  239. MALI_DEBUG_ASSERT(MALI_GROUP_STATE_DISABLED == group->state);
  240. group->state = MALI_GROUP_STATE_IDLE;
  241. empty = MALI_TRUE;
  242. }
  243. return empty;
  244. }
  245. /* Get group used l2 domain and core domain ref */
  246. void mali_group_get_pm_domain_ref(struct mali_group *group);
  247. /* Put group used l2 domain and core domain ref */
  248. void mali_group_put_pm_domain_ref(struct mali_group *group);
  249. #endif /* __MALI_GROUP_H__ */