sde_fence.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SDE_FENCE_H_
  6. #define _SDE_FENCE_H_
  7. #include <linux/kernel.h>
  8. #include <linux/errno.h>
  9. #include <linux/mutex.h>
  10. #ifndef CHAR_BIT
  11. #define CHAR_BIT 8 /* define this if limits.h not available */
  12. #endif
  13. #define SDE_FENCE_NAME_SIZE 24
  14. /**
  15. * struct sde_fence_context - release/retire fence context/timeline structure
  16. * @commit_count: Number of detected commits since bootup
  17. * @done_count: Number of completed commits since bootup
  18. * @drm_id: ID number of owning DRM Object
  19. * @ref: kref counter on timeline
  20. * @lock: spinlock for fence counter protection
  21. * @list_lock: spinlock for timeline protection
  22. * @context: fence context
  23. * @list_head: fence list to hold all the fence created on this context
  24. * @name: name of fence context/timeline
  25. */
  26. struct sde_fence_context {
  27. unsigned int commit_count;
  28. unsigned int done_count;
  29. uint32_t drm_id;
  30. struct kref kref;
  31. spinlock_t lock;
  32. spinlock_t list_lock;
  33. u64 context;
  34. struct list_head fence_list_head;
  35. char name[SDE_FENCE_NAME_SIZE];
  36. };
  37. /**
  38. * enum sde_fence_event - sde fence event as hint fence operation
  39. * @SDE_FENCE_SIGNAL: Signal the fence cleanly with current timeline
  40. * @SDE_FENCE_RESET_TIMELINE: Reset timeline of the fence context
  41. * @SDE_FENCE_SIGNAL: Signal the fence but indicate error throughfence status
  42. */
  43. enum sde_fence_event {
  44. SDE_FENCE_SIGNAL,
  45. SDE_FENCE_RESET_TIMELINE,
  46. SDE_FENCE_SIGNAL_ERROR
  47. };
  48. #if IS_ENABLED(CONFIG_SYNC_FILE)
  49. /**
  50. * sde_sync_get - Query sync fence object from a file handle
  51. *
  52. * On success, this function also increments the refcount of the sync fence
  53. *
  54. * @fd: Integer sync fence handle
  55. *
  56. * Return: Pointer to sync fence object, or NULL
  57. */
  58. void *sde_sync_get(uint64_t fd);
  59. /**
  60. * sde_sync_put - Releases a sync fence object acquired by @sde_sync_get
  61. *
  62. * This function decrements the sync fence's reference count; the object will
  63. * be released if the reference count goes to zero.
  64. *
  65. * @fence: Pointer to sync fence
  66. */
  67. void sde_sync_put(void *fence);
  68. /**
  69. * sde_sync_wait - Query sync fence object from a file handle
  70. *
  71. * @fence: Pointer to sync fence
  72. * @timeout_ms: Time to wait, in milliseconds. Waits forever if timeout_ms < 0
  73. *
  74. * Return:
  75. * Zero if timed out
  76. * -ERESTARTSYS if wait interrupted
  77. * remaining jiffies in all other success cases.
  78. */
  79. signed long sde_sync_wait(void *fence, long timeout_ms);
  80. /**
  81. * sde_sync_get_name_prefix - get integer representation of fence name prefix
  82. * @fence: Pointer to opaque fence structure
  83. *
  84. * Return: 32-bit integer containing first 4 characters of fence name,
  85. * big-endian notation
  86. */
  87. uint32_t sde_sync_get_name_prefix(void *fence);
  88. /**
  89. * sde_fence_init - initialize fence object
  90. * @drm_id: ID number of owning DRM Object
  91. * @name: Timeline name
  92. * Returns: fence context object on success
  93. */
  94. struct sde_fence_context *sde_fence_init(const char *name,
  95. uint32_t drm_id);
  96. /**
  97. * sde_fence_deinit - deinit fence container
  98. * @fence: Pointer fence container
  99. */
  100. void sde_fence_deinit(struct sde_fence_context *fence);
  101. /**
  102. * sde_fence_prepare - prepare to return fences for current commit
  103. * @fence: Pointer fence container
  104. * Returns: Zero on success
  105. */
  106. void sde_fence_prepare(struct sde_fence_context *fence);
  107. /**
  108. * sde_fence_create - create output fence object
  109. * @fence: Pointer fence container
  110. * @val: Pointer to output value variable, fence fd will be placed here
  111. * @offset: Fence signal commit offset, e.g., +1 to signal on next commit
  112. * Returns: Zero on success
  113. */
  114. int sde_fence_create(struct sde_fence_context *fence, uint64_t *val,
  115. uint32_t offset);
  116. /**
  117. * sde_fence_signal - advance fence timeline to signal outstanding fences
  118. * @fence: Pointer fence container
  119. * @ts: fence timestamp
  120. * @fence_event: fence event to indicate nature of fence signal.
  121. */
  122. void sde_fence_signal(struct sde_fence_context *fence, ktime_t ts,
  123. enum sde_fence_event fence_event);
  124. /**
  125. * sde_fence_timeline_status - prints fence timeline status
  126. * @fence: Pointer fence container
  127. * @drm_obj Pointer to drm object associated with fence timeline
  128. */
  129. void sde_fence_timeline_status(struct sde_fence_context *ctx,
  130. struct drm_mode_object *drm_obj);
  131. /**
  132. * sde_fence_timeline_dump - utility to dump fence list info in debugfs node
  133. * @fence: Pointer fence container
  134. * @drm_obj: Pointer to drm object associated with fence timeline
  135. * @s: used to writing on debugfs node
  136. */
  137. void sde_debugfs_timeline_dump(struct sde_fence_context *ctx,
  138. struct drm_mode_object *drm_obj, struct seq_file **s);
  139. /**
  140. * sde_fence_timeline_status - dumps fence timeline in debugfs node
  141. * @fence: Pointer fence container
  142. * @s: used to writing on debugfs node
  143. */
  144. void sde_fence_list_dump(struct dma_fence *fence, struct seq_file **s);
  145. #else
  146. static inline void *sde_sync_get(uint64_t fd)
  147. {
  148. return NULL;
  149. }
  150. static inline void sde_sync_put(void *fence)
  151. {
  152. }
  153. static inline signed long sde_sync_wait(void *fence, long timeout_ms)
  154. {
  155. return 0;
  156. }
  157. static inline uint32_t sde_sync_get_name_prefix(void *fence)
  158. {
  159. return 0x0;
  160. }
  161. static inline struct sde_fence_context *sde_fence_init(const char *name,
  162. uint32_t drm_id)
  163. {
  164. /* do nothing */
  165. return NULL;
  166. }
  167. static inline void sde_fence_deinit(struct sde_fence_context *fence)
  168. {
  169. /* do nothing */
  170. }
  171. static inline int sde_fence_get(struct sde_fence_context *fence, uint64_t *val)
  172. {
  173. return -EINVAL;
  174. }
  175. static inline void sde_fence_signal(struct sde_fence_context *fence,
  176. ktime_t ts, bool reset_timeline)
  177. {
  178. /* do nothing */
  179. }
  180. static inline void sde_fence_prepare(struct sde_fence_context *fence)
  181. {
  182. /* do nothing */
  183. }
  184. static inline int sde_fence_create(struct sde_fence_context *fence,
  185. uint64_t *val, uint32_t offset)
  186. {
  187. return 0;
  188. }
  189. static inline void sde_fence_timeline_status(struct sde_fence_context *ctx,
  190. struct drm_mode_object *drm_obj);
  191. {
  192. /* do nothing */
  193. }
  194. void sde_debugfs_timeline_dump(struct sde_fence_context *ctx,
  195. struct drm_mode_object *drm_obj, struct seq_file **s)
  196. {
  197. /* do nothing */
  198. }
  199. void sde_fence_list_dump(struct dma_fence *fence, struct seq_file **s)
  200. {
  201. /* do nothing */
  202. }
  203. #endif /* IS_ENABLED(CONFIG_SW_SYNC) */
  204. #endif /* _SDE_FENCE_H_ */