sde_fence.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. */
  68. struct sde_hw_fence_data {
  69. int client_id;
  70. enum hw_fence_client_id hw_fence_client_id;
  71. void *hw_fence_handle;
  72. struct msm_hw_fence_mem_addr mem_descriptor;
  73. u32 ipcc_in_client;
  74. u32 ipcc_in_signal;
  75. u32 ipcc_out_signal_pp[MAX_SDE_HFENCE_OUT_SIGNAL_PING_PONG];
  76. u32 ipcc_out_signal_pp_idx;
  77. u32 ipcc_out_client;
  78. u32 ipcc_this_client;
  79. };
  80. #if IS_ENABLED(CONFIG_SYNC_FILE)
  81. /**
  82. * sde_sync_get - Query sync fence object from a file handle
  83. *
  84. * On success, this function also increments the refcount of the sync fence
  85. *
  86. * @fd: Integer sync fence handle
  87. *
  88. * Return: Pointer to sync fence object, or NULL
  89. */
  90. void *sde_sync_get(uint64_t fd);
  91. /**
  92. * sde_sync_put - Releases a sync fence object acquired by @sde_sync_get
  93. *
  94. * This function decrements the sync fence's reference count; the object will
  95. * be released if the reference count goes to zero.
  96. *
  97. * @fence: Pointer to sync fence
  98. */
  99. void sde_sync_put(void *fence);
  100. /**
  101. * sde_sync_wait - Query sync fence object from a file handle
  102. *
  103. * @fence: Pointer to sync fence
  104. * @timeout_ms: Time to wait, in milliseconds. Waits forever if timeout_ms < 0
  105. *
  106. * Return:
  107. * Zero if timed out
  108. * -ERESTARTSYS if wait interrupted
  109. * remaining jiffies in all other success cases.
  110. */
  111. signed long sde_sync_wait(void *fence, long timeout_ms);
  112. /**
  113. * sde_sync_get_name_prefix - get integer representation of fence name prefix
  114. *
  115. * @fence: Pointer to opaque fence structure
  116. *
  117. * Return: 32-bit integer containing first 4 characters of fence name,
  118. * big-endian notation
  119. */
  120. uint32_t sde_sync_get_name_prefix(void *fence);
  121. /**
  122. * sde_fence_init - initialize fence object
  123. *
  124. * @drm_id: ID number of owning DRM Object
  125. * @name: Timeline name
  126. *
  127. * Returns: fence context object on success
  128. */
  129. struct sde_fence_context *sde_fence_init(const char *name,
  130. uint32_t drm_id);
  131. /**
  132. * sde_fence_hw_fence_init - initialize hw-fence clients
  133. *
  134. * @hw_ctl: hw ctl client to init.
  135. * @use_ipcc: boolean to indicate if hw should use dpu ipcc signals.
  136. *
  137. * Returns: Zero on success, otherwise returns an error code.
  138. */
  139. int sde_hw_fence_init(struct sde_hw_ctl *hw_ctl, bool use_dpu_ipcc);
  140. /**
  141. * sde_fence_hw_fence_deinit - deinitialize hw-fence clients
  142. *
  143. * @hw_ctl: hw ctl client to init.
  144. */
  145. void sde_hw_fence_deinit(struct sde_hw_ctl *hw_ctl);
  146. /**
  147. * sde_fence_register_hw_fences_wait - registers dpu-client for wait on hw fence or fences
  148. *
  149. * @hw_ctl: hw ctl client used to register for wait.
  150. * @fences: list of dma-fences that have hw-fence support to wait-on
  151. * @num_fences: number of fences in the above list
  152. *
  153. * Returns: Zero on success, otherwise returns an error code.
  154. */
  155. int sde_fence_register_hw_fences_wait(struct sde_hw_ctl *hw_ctl, struct dma_fence **fences,
  156. u32 num_fences);
  157. /**
  158. * sde_fence_update_hw_fences_txq - updates the hw-fence txq with the list of hw-fences to signal
  159. * upon triggering the ipcc signal.
  160. *
  161. * @ctx: sde fence context
  162. * @vid_mode: is video-mode update
  163. * @line_count: prog line count value, must be non-zero
  164. *
  165. * Returns: Zero on success, otherwise returns an error code.
  166. */
  167. int sde_fence_update_hw_fences_txq(struct sde_fence_context *ctx, bool vid_mode, u32 line_count,
  168. u32 debugfs_hw_fence);
  169. /**
  170. * sde_fence_update_input_hw_fence_signal - updates input-fence ipcc signal in dpu and enables
  171. * hw-fences for the ctl.
  172. *
  173. * @ctl: hw ctl to update the input-fence and enable hw-fences
  174. * @debugfs_hw_fence: hw-fence timestamp debugfs value
  175. * @hw_mdp: pointer to hw_mdp to get timestamp registers
  176. *
  177. * Returns: Zero on success, otherwise returns an error code.
  178. */
  179. int sde_fence_update_input_hw_fence_signal(struct sde_hw_ctl *ctl, u32 debugfs_hw_fence,
  180. struct sde_hw_mdp *hw_mdp);
  181. /**
  182. * sde_fence_deinit - deinit fence container
  183. * @fence: Pointer fence container
  184. */
  185. void sde_fence_deinit(struct sde_fence_context *fence);
  186. /**
  187. * sde_fence_prepare - prepare to return fences for current commit
  188. * @fence: Pointer fence container
  189. * Returns: Zero on success
  190. */
  191. void sde_fence_prepare(struct sde_fence_context *fence);
  192. /**
  193. * sde_fence_create - create output fence object
  194. * @fence: Pointer fence container
  195. * @val: Pointer to output value variable, fence fd will be placed here
  196. * @offset: Fence signal commit offset, e.g., +1 to signal on next commit
  197. * @hw_ctl: Ctl for hw fences
  198. * Returns: Zero on success
  199. */
  200. int sde_fence_create(struct sde_fence_context *fence, uint64_t *val,
  201. uint32_t offset, struct sde_hw_ctl *hw_ctl);
  202. /**
  203. * sde_fence_signal - advance fence timeline to signal outstanding fences
  204. * @fence: Pointer fence container
  205. * @ts: fence timestamp
  206. * @fence_event: fence event to indicate nature of fence signal.
  207. * @hw_ctl: ctl to signal fences for the timeline rest event
  208. */
  209. void sde_fence_signal(struct sde_fence_context *fence, ktime_t ts,
  210. enum sde_fence_event fence_event, struct sde_hw_ctl *hw_ctl);
  211. /**
  212. * sde_fence_timeline_status - prints fence timeline status
  213. * @fence: Pointer fence container
  214. * @drm_obj Pointer to drm object associated with fence timeline
  215. */
  216. void sde_fence_timeline_status(struct sde_fence_context *ctx,
  217. struct drm_mode_object *drm_obj);
  218. /**
  219. * sde_fence_timeline_dump - utility to dump fence list info in debugfs node
  220. * @fence: Pointer fence container
  221. * @drm_obj: Pointer to drm object associated with fence timeline
  222. * @s: used to writing on debugfs node
  223. */
  224. void sde_debugfs_timeline_dump(struct sde_fence_context *ctx,
  225. struct drm_mode_object *drm_obj, struct seq_file **s);
  226. /**
  227. * sde_fence_timeline_status - dumps fence timeline in debugfs node
  228. * @fence: Pointer fence container
  229. * @s: used to writing on debugfs node
  230. */
  231. void sde_fence_list_dump(struct dma_fence *fence, struct seq_file **s);
  232. #else
  233. static inline void *sde_sync_get(uint64_t fd)
  234. {
  235. return NULL;
  236. }
  237. static inline void sde_sync_put(void *fence)
  238. {
  239. }
  240. static inline signed long sde_sync_wait(void *fence, long timeout_ms)
  241. {
  242. return 0;
  243. }
  244. static inline uint32_t sde_sync_get_name_prefix(void *fence)
  245. {
  246. return 0x0;
  247. }
  248. static inline struct sde_fence_context *sde_fence_init(const char *name,
  249. uint32_t drm_id)
  250. {
  251. /* do nothing */
  252. return NULL;
  253. }
  254. static inline void sde_fence_deinit(struct sde_fence_context *fence)
  255. {
  256. /* do nothing */
  257. }
  258. static inline int sde_fence_get(struct sde_fence_context *fence, uint64_t *val)
  259. {
  260. return -EINVAL;
  261. }
  262. static inline void sde_fence_signal(struct sde_fence_context *fence,
  263. ktime_t ts, bool reset_timeline)
  264. {
  265. /* do nothing */
  266. }
  267. static inline void sde_fence_prepare(struct sde_fence_context *fence)
  268. {
  269. /* do nothing */
  270. }
  271. static inline int sde_fence_create(struct sde_fence_context *fence,
  272. uint64_t *val, uint32_t offset)
  273. {
  274. return 0;
  275. }
  276. static inline void sde_fence_timeline_status(struct sde_fence_context *ctx,
  277. struct drm_mode_object *drm_obj);
  278. {
  279. /* do nothing */
  280. }
  281. void sde_debugfs_timeline_dump(struct sde_fence_context *ctx,
  282. struct drm_mode_object *drm_obj, struct seq_file **s)
  283. {
  284. /* do nothing */
  285. }
  286. void sde_fence_list_dump(struct dma_fence *fence, struct seq_file **s)
  287. {
  288. /* do nothing */
  289. }
  290. #endif /* IS_ENABLED(CONFIG_SW_SYNC) */
  291. #endif /* _SDE_FENCE_H_ */