sde_rotator_dev.h 8.0 KB

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