sde_rotator_dev.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __SDE_ROTATOR_DEV_H__
  6. #define __SDE_ROTATOR_DEV_H__
  7. #include <linux/types.h>
  8. #include <linux/atomic.h>
  9. #include <linux/slab.h>
  10. #include <linux/ktime.h>
  11. #include <linux/iommu.h>
  12. #include <linux/dma-buf.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/soc/qcom/llcc-qcom.h>
  15. #include <linux/kthread.h>
  16. #include <media/v4l2-device.h>
  17. #include <media/v4l2-fh.h>
  18. #include <media/v4l2-ctrls.h>
  19. #include <media/msm_sde_rotator.h>
  20. #include "sde_rotator_core.h"
  21. #include "sde_rotator_sync.h"
  22. /* Rotator device name */
  23. #define SDE_ROTATOR_DRV_NAME "sde_rotator"
  24. /* Event logging constants */
  25. #define SDE_ROTATOR_NUM_EVENTS 4096
  26. #define SDE_ROTATOR_NUM_TIMESTAMPS SDE_ROTATOR_TS_MAX
  27. /* maximum number of outstanding requests per ctx session */
  28. #define SDE_ROTATOR_REQUEST_MAX 2
  29. #define MAX_ROT_OPEN_SESSION 16
  30. struct sde_rotator_device;
  31. struct sde_rotator_ctx;
  32. /*
  33. * struct sde_rotator_buf_handle - Structure contain rotator buffer information.
  34. * @fd: ion file descriptor from which this buffer is imported.
  35. * @rot_dev: Pointer to rotator device.
  36. * @ctx: Pointer to rotator context.
  37. * @size: Size of the buffer.
  38. * @addr: Address of rotator mmu mapped buffer.
  39. * @secure: Non-secure/secure buffer.
  40. * @buffer: Pointer to dma buf associated with this fd.
  41. */
  42. struct sde_rotator_buf_handle {
  43. int fd;
  44. struct sde_rotator_device *rot_dev;
  45. struct sde_rotator_ctx *ctx;
  46. unsigned long size;
  47. dma_addr_t addr;
  48. int secure;
  49. struct dma_buf *buffer;
  50. };
  51. /*
  52. * struct sde_rotator_vbinfo - Structure define video buffer info.
  53. * @fd: fence file descriptor.
  54. * @fence: fence associated with fd.
  55. * @fence_ts: completion timestamp associated with fd
  56. * @qbuf_ts: timestamp associated with buffer queue event
  57. * @dqbuf_ts: Pointer to timestamp associated with buffer dequeue event
  58. * @comp_ratio: compression ratio of this buffer
  59. */
  60. struct sde_rotator_vbinfo {
  61. int fd;
  62. struct sde_rot_sync_fence *fence;
  63. u32 fence_ts;
  64. ktime_t qbuf_ts;
  65. ktime_t *dqbuf_ts;
  66. struct sde_mult_factor comp_ratio;
  67. };
  68. /*
  69. * struct sde_rotator_request - device layer rotation request
  70. * @list: list head for submit/retire list
  71. * @submit_work: submit work structure
  72. * @retire_work: retire work structure
  73. * @req: Pointer to core layer rotator manager request
  74. * Request can be freed by core layer during sde_rotator_stop_streaming.
  75. * Avoid dereference in dev layer if possible.
  76. * @ctx: Pointer to parent context
  77. * @committed: true if request committed to hardware
  78. * @sequence_id: sequence identifier of this request
  79. */
  80. struct sde_rotator_request {
  81. struct list_head list;
  82. struct kthread_work submit_work;
  83. struct kthread_work retire_work;
  84. struct sde_rot_entry_container *req;
  85. struct sde_rotator_ctx *ctx;
  86. bool committed;
  87. u32 sequence_id;
  88. };
  89. /*
  90. * struct sde_rotator_ctx - Structure contains per open file handle context.
  91. * @kobj: kernel object of this context
  92. * @rot_dev: Pointer to rotator device.
  93. * @file: Pointer to device file handle
  94. * @fh: V4l2 file handle.
  95. * @ctrl_handler: control handler
  96. * @format_cap: Current capture format.
  97. * @format_out: Current output format.
  98. * @crop_cap: Current capture crop.
  99. * @crop_out: Current output crop.
  100. * @timeperframe: Time per frame in seconds.
  101. * @session_id: unique id for this context
  102. * @hflip: horizontal flip (1-flip)
  103. * @vflip: vertical flip (1-flip)
  104. * @rotate: rotation angle (0,90,180,270)
  105. * @secure: Non-secure (0) / Secure processing
  106. * @abort_pending: True if abort is requested for async handling.
  107. * @nbuf_cap: Number of requested buffer for capture queue
  108. * @nbuf_out: Number of requested buffer for output queue
  109. * @fence_cap: Fence info for each requested capture buffer
  110. * @fence_out: Fence info for each requested output buffer
  111. * @wait_queue: Wait queue for signaling end of job
  112. * @work_queue: work queue for submit and retire processing
  113. * @private: Pointer to session private information
  114. * @slice: Pointer to system cache slice descriptor
  115. * @commit_sequence_id: last committed sequence id
  116. * @retired_sequence_id: last retired sequence id
  117. * @list_lock: lock for pending/retired list
  118. * @pending_list: list of pending request
  119. * @retired_list: list of retired/free request
  120. * @requests: static allocation of free requests
  121. * @rotcfg: current core rotation configuration
  122. * @kthread_id: thread_id used for fence management
  123. */
  124. struct sde_rotator_ctx {
  125. struct kobject kobj;
  126. struct sde_rotator_device *rot_dev;
  127. struct file *file;
  128. struct v4l2_fh fh;
  129. struct v4l2_ctrl_handler ctrl_handler;
  130. struct v4l2_format format_cap;
  131. struct v4l2_format format_out;
  132. struct v4l2_rect crop_cap;
  133. struct v4l2_rect crop_out;
  134. struct v4l2_fract timeperframe;
  135. u32 session_id;
  136. s32 hflip;
  137. s32 vflip;
  138. s32 rotate;
  139. s32 secure;
  140. s32 secure_camera;
  141. int abort_pending;
  142. int nbuf_cap;
  143. int nbuf_out;
  144. struct sde_rotator_vbinfo *vbinfo_cap;
  145. struct sde_rotator_vbinfo *vbinfo_out;
  146. wait_queue_head_t wait_queue;
  147. struct sde_rot_queue_v1 work_queue;
  148. struct sde_rot_file_private *private;
  149. struct llcc_slice_desc *slice;
  150. u32 commit_sequence_id;
  151. u32 retired_sequence_id;
  152. spinlock_t list_lock;
  153. struct list_head pending_list;
  154. struct list_head retired_list;
  155. struct sde_rotator_request requests[SDE_ROTATOR_REQUEST_MAX];
  156. struct sde_rotation_config rotcfg;
  157. int kthread_id;
  158. };
  159. /*
  160. * struct sde_rotator_statistics - Storage for statistics
  161. * @count: Number of processed request
  162. * @fail_count: Number of failed request
  163. * @ts: Timestamps of most recent requests
  164. */
  165. struct sde_rotator_statistics {
  166. u64 count;
  167. u64 fail_count;
  168. ktime_t ts[SDE_ROTATOR_NUM_EVENTS][SDE_ROTATOR_NUM_TIMESTAMPS];
  169. };
  170. /*
  171. * struct sde_rotator_device - FD device structure.
  172. * @lock: Lock protecting this device structure and serializing IOCTL.
  173. * @dev: Pointer to device struct.
  174. * @v4l2_dev: V4l2 device.
  175. * @vdev: Pointer to video device.
  176. * @m2m_dev: Memory to memory device.
  177. * @pdev: Pointer to platform device.
  178. * @drvdata: Pointer to driver data.
  179. * @early_submit: flag enable job submission in ready state.
  180. * @disable_syscache: true to disable system cache
  181. * @mgr: Pointer to core rotator manager.
  182. * @mdata: Pointer to common rotator data/resource.
  183. * @session_id: Next context session identifier
  184. * @fence_timeout: Timeout value in msec for fence wait
  185. * @streamoff_timeout: Timeout value in msec for stream off
  186. * @min_rot_clk: Override the minimum rotator clock from perf calculation
  187. * @min_bw: Override the minimum bandwidth from perf calculation
  188. * @min_overhead_us: Override the minimum overhead in us from perf calculation
  189. * @debugfs_root: Pointer to debugfs directory entry.
  190. * @stats: placeholder for rotator statistics
  191. * @open_timeout: maximum wait time for ctx open in msec
  192. * @open_wq: wait queue for ctx open
  193. * @excl_ctx: Pointer to exclusive ctx
  194. * @rot_kw: rotator thread work
  195. * @rot_thread: rotator threads
  196. * @kthread_free: check if thread is available or not
  197. */
  198. struct sde_rotator_device {
  199. struct mutex lock;
  200. struct device *dev;
  201. struct v4l2_device v4l2_dev;
  202. struct video_device *vdev;
  203. #ifndef CONFIG_MSM_SDE_ROTATOR_INIT_ONLY
  204. struct v4l2_m2m_dev *m2m_dev;
  205. #endif
  206. struct platform_device *pdev;
  207. const void *drvdata;
  208. u32 early_submit;
  209. u32 disable_syscache;
  210. struct sde_rot_mgr *mgr;
  211. struct sde_rot_data_type *mdata;
  212. u32 session_id;
  213. u32 fence_timeout;
  214. u32 streamoff_timeout;
  215. u32 min_rot_clk;
  216. u32 min_bw;
  217. u32 min_overhead_us;
  218. struct sde_rotator_statistics stats;
  219. struct dentry *debugfs_root;
  220. struct dentry *perf_root;
  221. u32 open_timeout;
  222. wait_queue_head_t open_wq;
  223. struct sde_rotator_ctx *excl_ctx;
  224. struct kthread_worker rot_kw[MAX_ROT_OPEN_SESSION];
  225. struct task_struct *rot_thread[MAX_ROT_OPEN_SESSION];
  226. bool kthread_free[MAX_ROT_OPEN_SESSION];
  227. };
  228. static inline
  229. struct sde_rot_mgr *sde_rot_mgr_from_pdevice(struct platform_device *pdev)
  230. {
  231. return ((struct sde_rotator_device *) platform_get_drvdata(pdev))->mgr;
  232. }
  233. static inline
  234. struct sde_rot_mgr *sde_rot_mgr_from_device(struct device *dev)
  235. {
  236. return ((struct sde_rotator_device *) dev_get_drvdata(dev))->mgr;
  237. }
  238. void sde_rotator_pm_qos_add(struct sde_rot_data_type *rot_mdata);
  239. #endif /* __SDE_ROTATOR_DEV_H__ */