sde_fence.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2019, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _SDE_FENCE_H_
  7. #define _SDE_FENCE_H_
  8. #include <linux/kernel.h>
  9. #include <linux/errno.h>
  10. #include <linux/mutex.h>
  11. #include <linux/soc/qcom/msm_hw_fence.h>
  12. #ifndef CHAR_BIT
  13. #define CHAR_BIT 8 /* define this if limits.h not available */
  14. #endif
  15. #define HW_FENCE_TRIGGER_SEL_CTRL_DONE 0x0
  16. #define HW_FENCE_TRIGGER_SEL_PROG_LINE_COUNT 0x1
  17. #define SDE_INPUT_HW_FENCE_TIMESTAMP BIT(0)
  18. #define SDE_OUTPUT_HW_FENCE_TIMESTAMP BIT(1)
  19. #define SDE_FENCE_NAME_SIZE 24
  20. #define MAX_SDE_HFENCE_OUT_SIGNAL_PING_PONG 2
  21. /**
  22. * struct sde_fence_context - release/retire fence context/timeline structure
  23. * @commit_count: Number of detected commits since bootup
  24. * @done_count: Number of completed commits since bootup
  25. * @drm_id: ID number of owning DRM Object
  26. * @ref: kref counter on timeline
  27. * @lock: spinlock for fence counter protection
  28. * @list_lock: spinlock for timeline protection
  29. * @context: fence context
  30. * @list_head: fence list to hold all the fence created on this context
  31. * @name: name of fence context/timeline
  32. */
  33. struct sde_fence_context {
  34. unsigned int commit_count;
  35. unsigned int done_count;
  36. uint32_t drm_id;
  37. struct kref kref;
  38. spinlock_t lock;
  39. spinlock_t list_lock;
  40. u64 context;
  41. struct list_head fence_list_head;
  42. char name[SDE_FENCE_NAME_SIZE];
  43. };
  44. /**
  45. * enum sde_fence_event - sde fence event as hint fence operation
  46. * @SDE_FENCE_SIGNAL: Signal the fence cleanly with current timeline
  47. * @SDE_FENCE_RESET_TIMELINE: Reset timeline of the fence context
  48. * @SDE_FENCE_SIGNAL: Signal the fence but indicate error throughfence status
  49. */
  50. enum sde_fence_event {
  51. SDE_FENCE_SIGNAL,
  52. SDE_FENCE_RESET_TIMELINE,
  53. SDE_FENCE_SIGNAL_ERROR
  54. };
  55. /**
  56. * struct sde_hw_fence_data - contains the information of each display-client of the hw-fences
  57. * to communicate with the fence controller.
  58. * @client_id: client_id enum for the display driver.
  59. * @hw_fence_client_id: client_id enum for the hw-fence driver.
  60. * @mem_descriptor: memory descriptor with the hfi for the rx/tx queues mapping.
  61. * @ipcc_in_client: ipcc client triggering the signal: IN_CLIENT (APPS) -> DPU
  62. * @ipcc_in_signal: ipcc signal triggered from client to dpu: IN_SIGNAL (APPS) -> DPU
  63. * @ipcc_out_signal_pp: output signal from dpu to fctl, ping-pongs between two signals
  64. * @ipcc_out_signal_pp_idx: index of the output signal ping-pong
  65. * @ipcc_out_client: destination client id (APPS for the FCTL)
  66. * @ipcc_this_client: ipcc dpu client id (For Waipio: APPS, For Kailua: DPU HW)
  67. * @dma_context: per client dma context used to create join fences
  68. * @hw_fence_array_seqno: per-client seq number counter for join fences
  69. */
  70. struct sde_hw_fence_data {
  71. int client_id;
  72. enum hw_fence_client_id hw_fence_client_id;
  73. void *hw_fence_handle;
  74. struct msm_hw_fence_mem_addr mem_descriptor;
  75. u32 ipcc_in_client;
  76. u32 ipcc_in_signal;
  77. u32 ipcc_out_signal_pp[MAX_SDE_HFENCE_OUT_SIGNAL_PING_PONG];
  78. u32 ipcc_out_signal_pp_idx;
  79. u32 ipcc_out_client;
  80. u32 ipcc_this_client;
  81. u64 dma_context;
  82. u32 hw_fence_array_seqno;
  83. };
  84. #if IS_ENABLED(CONFIG_SYNC_FILE)
  85. /**
  86. * sde_sync_get - Query sync fence object from a file handle
  87. *
  88. * On success, this function also increments the refcount of the sync fence
  89. *
  90. * @fd: Integer sync fence handle
  91. *
  92. * Return: Pointer to sync fence object, or NULL
  93. */
  94. void *sde_sync_get(uint64_t fd);
  95. /**
  96. * sde_sync_put - Releases a sync fence object acquired by @sde_sync_get
  97. *
  98. * This function decrements the sync fence's reference count; the object will
  99. * be released if the reference count goes to zero.
  100. *
  101. * @fence: Pointer to sync fence
  102. */
  103. void sde_sync_put(void *fence);
  104. /**
  105. * sde_sync_wait - Query sync fence object from a file handle
  106. *
  107. * @fence: Pointer to sync fence
  108. * @timeout_ms: Time to wait, in milliseconds. Waits forever if timeout_ms < 0
  109. *
  110. * Return:
  111. * Zero if timed out
  112. * -ERESTARTSYS if wait interrupted
  113. * remaining jiffies in all other success cases.
  114. */
  115. signed long sde_sync_wait(void *fence, long timeout_ms);
  116. /**
  117. * sde_sync_get_name_prefix - get integer representation of fence name prefix
  118. *
  119. * @fence: Pointer to opaque fence structure
  120. *
  121. * Return: 32-bit integer containing first 4 characters of fence name,
  122. * big-endian notation
  123. */
  124. uint32_t sde_sync_get_name_prefix(void *fence);
  125. /**
  126. * sde_fence_init - initialize fence object
  127. *
  128. * @drm_id: ID number of owning DRM Object
  129. * @name: Timeline name
  130. *
  131. * Returns: fence context object on success
  132. */
  133. struct sde_fence_context *sde_fence_init(const char *name,
  134. uint32_t drm_id);
  135. /**
  136. * sde_fence_hw_fence_init - initialize hw-fence clients
  137. *
  138. * @hw_ctl: hw ctl client to init.
  139. * @use_ipcc: boolean to indicate if hw should use dpu ipcc signals.
  140. *
  141. * Returns: Zero on success, otherwise returns an error code.
  142. */
  143. int sde_hw_fence_init(struct sde_hw_ctl *hw_ctl, bool use_dpu_ipcc);
  144. /**
  145. * sde_fence_hw_fence_deinit - deinitialize hw-fence clients
  146. *
  147. * @hw_ctl: hw ctl client to init.
  148. */
  149. void sde_hw_fence_deinit(struct sde_hw_ctl *hw_ctl);
  150. /**
  151. * sde_fence_register_hw_fences_wait - registers dpu-client for wait on hw fence or fences
  152. *
  153. * @hw_ctl: hw ctl client used to register for wait.
  154. * @fences: list of dma-fences that have hw-fence support to wait-on
  155. * @num_fences: number of fences in the above list
  156. *
  157. * Returns: Zero on success, otherwise returns an error code.
  158. */
  159. int sde_fence_register_hw_fences_wait(struct sde_hw_ctl *hw_ctl, struct dma_fence **fences,
  160. u32 num_fences);
  161. /**
  162. * sde_fence_update_hw_fences_txq - updates the hw-fence txq with the list of hw-fences to signal
  163. * upon triggering the ipcc signal.
  164. *
  165. * @ctx: sde fence context
  166. * @vid_mode: is video-mode update
  167. * @line_count: prog line count value, must be non-zero
  168. *
  169. * Returns: Zero on success, otherwise returns an error code.
  170. */
  171. int sde_fence_update_hw_fences_txq(struct sde_fence_context *ctx, bool vid_mode, u32 line_count,
  172. u32 debugfs_hw_fence);
  173. /**
  174. * sde_fence_update_input_hw_fence_signal - updates input-fence ipcc signal in dpu and enables
  175. * hw-fences for the ctl.
  176. *
  177. * @ctl: hw ctl to update the input-fence and enable hw-fences
  178. * @debugfs_hw_fence: hw-fence timestamp debugfs value
  179. * @hw_mdp: pointer to hw_mdp to get timestamp registers
  180. * @disable: bool to indicate if we should disable hw-fencing for this commit
  181. *
  182. * Returns: Zero on success, otherwise returns an error code.
  183. */
  184. int sde_fence_update_input_hw_fence_signal(struct sde_hw_ctl *ctl, u32 debugfs_hw_fence,
  185. struct sde_hw_mdp *hw_mdp, bool disable);
  186. /**
  187. * sde_fence_deinit - deinit fence container
  188. * @fence: Pointer fence container
  189. */
  190. void sde_fence_deinit(struct sde_fence_context *fence);
  191. /**
  192. * sde_fence_prepare - prepare to return fences for current commit
  193. * @fence: Pointer fence container
  194. * Returns: Zero on success
  195. */
  196. void sde_fence_prepare(struct sde_fence_context *fence);
  197. /**
  198. * sde_fence_create - create output fence object
  199. * @fence: Pointer fence container
  200. * @val: Pointer to output value variable, fence fd will be placed here
  201. * @offset: Fence signal commit offset, e.g., +1 to signal on next commit
  202. * @hw_ctl: Ctl for hw fences
  203. * Returns: Zero on success
  204. */
  205. int sde_fence_create(struct sde_fence_context *fence, uint64_t *val,
  206. uint32_t offset, struct sde_hw_ctl *hw_ctl);
  207. /**
  208. * sde_fence_signal - advance fence timeline to signal outstanding fences
  209. * @fence: Pointer fence container
  210. * @ts: fence timestamp
  211. * @fence_event: fence event to indicate nature of fence signal.
  212. * @hw_ctl: ctl to signal fences for the timeline rest event
  213. */
  214. void sde_fence_signal(struct sde_fence_context *fence, ktime_t ts,
  215. enum sde_fence_event fence_event, struct sde_hw_ctl *hw_ctl);
  216. /**
  217. * sde_fence_timeline_status - prints fence timeline status
  218. * @fence: Pointer fence container
  219. * @drm_obj Pointer to drm object associated with fence timeline
  220. */
  221. void sde_fence_timeline_status(struct sde_fence_context *ctx,
  222. struct drm_mode_object *drm_obj);
  223. /**
  224. * sde_fence_timeline_dump - utility to dump fence list info in debugfs node
  225. * @fence: Pointer fence container
  226. * @drm_obj: Pointer to drm object associated with fence timeline
  227. * @s: used to writing on debugfs node
  228. */
  229. void sde_debugfs_timeline_dump(struct sde_fence_context *ctx,
  230. struct drm_mode_object *drm_obj, struct seq_file **s);
  231. /**
  232. * sde_fence_timeline_status - dumps fence timeline in debugfs node
  233. * @fence: Pointer fence container
  234. * @s: used to writing on debugfs node
  235. */
  236. void sde_fence_list_dump(struct dma_fence *fence, struct seq_file **s);
  237. /**
  238. * sde_fence_dump - dumps fence info for specified fence
  239. * @fence: Pointer to fence to dump info for
  240. */
  241. void sde_fence_dump(struct dma_fence *fence);
  242. #else
  243. static inline void *sde_sync_get(uint64_t fd)
  244. {
  245. return NULL;
  246. }
  247. static inline void sde_sync_put(void *fence)
  248. {
  249. }
  250. static inline signed long sde_sync_wait(void *fence, long timeout_ms)
  251. {
  252. return 0;
  253. }
  254. static inline uint32_t sde_sync_get_name_prefix(void *fence)
  255. {
  256. return 0x0;
  257. }
  258. static inline struct sde_fence_context *sde_fence_init(const char *name,
  259. uint32_t drm_id)
  260. {
  261. /* do nothing */
  262. return NULL;
  263. }
  264. static inline void sde_fence_deinit(struct sde_fence_context *fence)
  265. {
  266. /* do nothing */
  267. }
  268. static inline int sde_fence_get(struct sde_fence_context *fence, uint64_t *val)
  269. {
  270. return -EINVAL;
  271. }
  272. static inline void sde_fence_signal(struct sde_fence_context *fence,
  273. ktime_t ts, bool reset_timeline)
  274. {
  275. /* do nothing */
  276. }
  277. static inline void sde_fence_prepare(struct sde_fence_context *fence)
  278. {
  279. /* do nothing */
  280. }
  281. static inline int sde_fence_create(struct sde_fence_context *fence,
  282. uint64_t *val, uint32_t offset)
  283. {
  284. return 0;
  285. }
  286. static inline void sde_fence_timeline_status(struct sde_fence_context *ctx,
  287. struct drm_mode_object *drm_obj);
  288. {
  289. /* do nothing */
  290. }
  291. void sde_debugfs_timeline_dump(struct sde_fence_context *ctx,
  292. struct drm_mode_object *drm_obj, struct seq_file **s)
  293. {
  294. /* do nothing */
  295. }
  296. void sde_fence_list_dump(struct dma_fence *fence, struct seq_file **s)
  297. {
  298. /* do nothing */
  299. }
  300. void sde_fence_dump(struct dma_fence *fence)
  301. {
  302. /* do nothing */
  303. }
  304. #endif /* IS_ENABLED(CONFIG_SW_SYNC) */
  305. #endif /* _SDE_FENCE_H_ */