mali_soft_job.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * This confidential and proprietary software may be used only as
  3. * authorised by a licensing agreement from ARM Limited
  4. * (C) COPYRIGHT 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_SOFT_JOB_H__
  11. #define __MALI_SOFT_JOB_H__
  12. #include "mali_osk.h"
  13. #include "mali_timeline.h"
  14. struct mali_timeline_fence;
  15. struct mali_session_data;
  16. struct mali_soft_job;
  17. struct mali_soft_job_system;
  18. /**
  19. * Soft job types.
  20. *
  21. * Soft jobs of type MALI_SOFT_JOB_TYPE_USER_SIGNALED will only complete after activation if either
  22. * they are signaled by user-space (@ref mali_soft_job_system_signaled_job) or if they are timed out
  23. * by the Timeline system.
  24. */
  25. typedef enum mali_soft_job_type {
  26. MALI_SOFT_JOB_TYPE_USER_SIGNALED,
  27. } mali_soft_job_type;
  28. /**
  29. * Soft job state.
  30. *
  31. * All soft jobs in a soft job system will initially be in state MALI_SOFT_JOB_STATE_FREE. On @ref
  32. * mali_soft_job_system_start_job a job will first be allocated. A job in state
  33. * MALI_SOFT_JOB_STATE_FREE will be picked and the state changed to MALI_SOFT_JOB_STATE_ALLOCATED.
  34. * Once the job is added to the timeline system, the state changes to MALI_SOFT_JOB_STATE_STARTED.
  35. *
  36. * For soft jobs of type MALI_SOFT_JOB_TYPE_USER_SIGNALED the state is changed to
  37. * MALI_SOFT_JOB_STATE_SIGNALED when @ref mali_soft_job_system_signal_job is called and the soft
  38. * job's state is MALI_SOFT_JOB_STATE_STARTED or MALI_SOFT_JOB_STATE_TIMED_OUT.
  39. *
  40. * If a soft job of type MALI_SOFT_JOB_TYPE_USER_SIGNALED is timed out before being signaled, the
  41. * state is changed to MALI_SOFT_JOB_STATE_TIMED_OUT. This can only happen to soft jobs in state
  42. * MALI_SOFT_JOB_STATE_STARTED.
  43. *
  44. * When a soft job's reference count reaches zero, it will be freed and the state returns to
  45. * MALI_SOFT_JOB_STATE_FREE.
  46. */
  47. typedef enum mali_soft_job_state {
  48. MALI_SOFT_JOB_STATE_FREE,
  49. MALI_SOFT_JOB_STATE_ALLOCATED,
  50. MALI_SOFT_JOB_STATE_STARTED,
  51. MALI_SOFT_JOB_STATE_SIGNALED,
  52. MALI_SOFT_JOB_STATE_TIMED_OUT,
  53. } mali_soft_job_state;
  54. #define MALI_SOFT_JOB_INVALID_ID ((u32) -1)
  55. /* Maximum number of soft jobs per soft system. */
  56. #define MALI_MAX_NUM_SOFT_JOBS 20
  57. /**
  58. * Soft job struct.
  59. *
  60. * Soft job can be used to represent any kind of CPU work done in kernel-space.
  61. */
  62. typedef struct mali_soft_job {
  63. mali_soft_job_type type; /**< Soft job type. Must be one of MALI_SOFT_JOB_TYPE_*. */
  64. u32 user_job; /**< Identifier for soft job in user space. */
  65. _mali_osk_atomic_t refcount; /**< Soft jobs are reference counted to prevent premature deletion. */
  66. struct mali_timeline_tracker tracker; /**< Timeline tracker for soft job. */
  67. mali_bool activated; /**< MALI_TRUE if the job has been activated, MALI_FALSE if not. */
  68. _mali_osk_notification_t *activated_notification; /**< Pre-allocated notification object for ACTIVATED_NOTIFICATION. */
  69. /* Protected by soft job system lock. */
  70. u32 id; /**< Used by user-space to find corresponding soft job in kernel-space. */
  71. mali_soft_job_state state; /**< State of soft job, must be one of MALI_SOFT_JOB_STATE_*. */
  72. struct mali_soft_job_system *system; /**< The soft job system this job is in. */
  73. _mali_osk_list_t system_list; /**< List element used by soft job system. */
  74. } mali_soft_job;
  75. /**
  76. * Per-session soft job system.
  77. *
  78. * The soft job system is used to manage all soft jobs that belongs to a session.
  79. */
  80. typedef struct mali_soft_job_system {
  81. struct mali_session_data *session; /**< The session this soft job system belongs to. */
  82. struct mali_soft_job jobs[MALI_MAX_NUM_SOFT_JOBS]; /**< Array of all soft jobs in this system. */
  83. _MALI_OSK_LIST_HEAD(jobs_free); /**< List of all free soft jobs. */
  84. _MALI_OSK_LIST_HEAD(jobs_used); /**< List of all allocated soft jobs. */
  85. _mali_osk_spinlock_irq_t *lock; /**< Lock used to protect soft job system and its soft jobs. */
  86. u32 lock_owner; /**< Contains tid of thread that locked the system or 0, if not locked. */
  87. } mali_soft_job_system;
  88. /**
  89. * Create a soft job system.
  90. *
  91. * @param session The session this soft job system will belong to.
  92. * @return The new soft job system, or NULL if unsuccessful.
  93. */
  94. struct mali_soft_job_system *mali_soft_job_system_create(struct mali_session_data *session);
  95. /**
  96. * Destroy a soft job system.
  97. *
  98. * @note The soft job must not have any started or activated jobs. Call @ref
  99. * mali_soft_job_system_abort first.
  100. *
  101. * @param system The soft job system we are destroying.
  102. */
  103. void mali_soft_job_system_destroy(struct mali_soft_job_system *system);
  104. /**
  105. * Create a soft job.
  106. *
  107. * @param system Soft job system to create soft job from.
  108. * @param type Type of the soft job.
  109. * @param user_job Identifier for soft job in user space.
  110. * @return New soft job if successful, NULL if not.
  111. */
  112. struct mali_soft_job *mali_soft_job_create(struct mali_soft_job_system *system, mali_soft_job_type type, u32 user_job);
  113. /**
  114. * Destroy soft job.
  115. *
  116. * @param job Soft job to destroy.
  117. */
  118. void mali_soft_job_destroy(struct mali_soft_job *job);
  119. /**
  120. * Start a soft job.
  121. *
  122. * The soft job will be added to the Timeline system which will then activate it after all
  123. * dependencies have been resolved.
  124. *
  125. * Create soft jobs with @ref mali_soft_job_create before starting them.
  126. *
  127. * @param job Soft job to start.
  128. * @param fence Fence representing dependencies for this soft job.
  129. * @return Point on soft job timeline.
  130. */
  131. mali_timeline_point mali_soft_job_start(struct mali_soft_job *job, struct mali_timeline_fence *fence);
  132. /**
  133. * Use by user-space to signal that a soft job has completed.
  134. *
  135. * @note Only valid for soft jobs with type MALI_SOFT_JOB_TYPE_USER_SIGNALED.
  136. *
  137. * @note The soft job must be in state MALI_SOFT_JOB_STATE_STARTED for the signal to be successful.
  138. *
  139. * @note If the soft job was signaled successfully, or it received a time out, the soft job will be
  140. * destroyed after this call and should no longer be used.
  141. *
  142. * @note This function will block until the soft job has been activated.
  143. *
  144. * @param system The soft job system the job was started in.
  145. * @param job_id ID of soft job we are signaling.
  146. *
  147. * @return _MALI_OSK_ERR_ITEM_NOT_FOUND if the soft job ID was invalid, _MALI_OSK_ERR_TIMEOUT if the
  148. * soft job was timed out or _MALI_OSK_ERR_OK if we successfully signaled the soft job.
  149. */
  150. _mali_osk_errcode_t mali_soft_job_system_signal_job(struct mali_soft_job_system *system, u32 job_id);
  151. /**
  152. * Used by the Timeline system to activate a soft job.
  153. *
  154. * @param job The soft job that is being activated.
  155. */
  156. void mali_soft_job_system_activate_job(struct mali_soft_job *job);
  157. /**
  158. * Used by the Timeline system to timeout a soft job.
  159. *
  160. * A soft job is timed out if it completes or is signaled later than MALI_TIMELINE_TIMEOUT_HZ after
  161. * activation.
  162. *
  163. * @param job The soft job that is being timed out.
  164. * @return A scheduling bitmask.
  165. */
  166. mali_scheduler_mask mali_soft_job_system_timeout_job(struct mali_soft_job *job);
  167. /**
  168. * Used to cleanup activated soft jobs in the soft job system on session abort.
  169. *
  170. * @param system The soft job system that is being aborted.
  171. */
  172. void mali_soft_job_system_abort(struct mali_soft_job_system *system);
  173. #endif /* __MALI_SOFT_JOB_H__ */