sde_fence.h 11 KB

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