sde_fence.h 11 KB

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