dpu_crtc.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _DPU_CRTC_H_
  19. #define _DPU_CRTC_H_
  20. #include <linux/kthread.h>
  21. #include <drm/drm_crtc.h>
  22. #include "dpu_kms.h"
  23. #include "dpu_core_perf.h"
  24. #include "dpu_hw_blk.h"
  25. #define DPU_CRTC_NAME_SIZE 12
  26. /* define the maximum number of in-flight frame events */
  27. #define DPU_CRTC_FRAME_EVENT_SIZE 4
  28. /**
  29. * enum dpu_crtc_client_type: crtc client type
  30. * @RT_CLIENT: RealTime client like video/cmd mode display
  31. * voting through apps rsc
  32. * @NRT_CLIENT: Non-RealTime client like WB display
  33. * voting through apps rsc
  34. */
  35. enum dpu_crtc_client_type {
  36. RT_CLIENT,
  37. NRT_CLIENT,
  38. };
  39. /**
  40. * enum dpu_crtc_smmu_state: smmu state
  41. * @ATTACHED: all the context banks are attached.
  42. * @DETACHED: all the context banks are detached.
  43. * @ATTACH_ALL_REQ: transient state of attaching context banks.
  44. * @DETACH_ALL_REQ: transient state of detaching context banks.
  45. */
  46. enum dpu_crtc_smmu_state {
  47. ATTACHED = 0,
  48. DETACHED,
  49. ATTACH_ALL_REQ,
  50. DETACH_ALL_REQ,
  51. };
  52. /**
  53. * enum dpu_crtc_smmu_state_transition_type: state transition type
  54. * @NONE: no pending state transitions
  55. * @PRE_COMMIT: state transitions should be done before processing the commit
  56. * @POST_COMMIT: state transitions to be done after processing the commit.
  57. */
  58. enum dpu_crtc_smmu_state_transition_type {
  59. NONE,
  60. PRE_COMMIT,
  61. POST_COMMIT
  62. };
  63. /**
  64. * struct dpu_crtc_smmu_state_data: stores the smmu state and transition type
  65. * @state: current state of smmu context banks
  66. * @transition_type: transition request type
  67. * @transition_error: whether there is error while transitioning the state
  68. */
  69. struct dpu_crtc_smmu_state_data {
  70. uint32_t state;
  71. uint32_t transition_type;
  72. uint32_t transition_error;
  73. };
  74. /**
  75. * struct dpu_crtc_mixer: stores the map for each virtual pipeline in the CRTC
  76. * @hw_lm: LM HW Driver context
  77. * @lm_ctl: CTL Path HW driver context
  78. * @encoder: Encoder attached to this lm & ctl
  79. * @mixer_op_mode: mixer blending operation mode
  80. * @flush_mask: mixer flush mask for ctl, mixer and pipe
  81. */
  82. struct dpu_crtc_mixer {
  83. struct dpu_hw_mixer *hw_lm;
  84. struct dpu_hw_ctl *lm_ctl;
  85. struct drm_encoder *encoder;
  86. u32 mixer_op_mode;
  87. u32 flush_mask;
  88. };
  89. /**
  90. * struct dpu_crtc_frame_event: stores crtc frame event for crtc processing
  91. * @work: base work structure
  92. * @crtc: Pointer to crtc handling this event
  93. * @list: event list
  94. * @ts: timestamp at queue entry
  95. * @event: event identifier
  96. */
  97. struct dpu_crtc_frame_event {
  98. struct kthread_work work;
  99. struct drm_crtc *crtc;
  100. struct list_head list;
  101. ktime_t ts;
  102. u32 event;
  103. };
  104. /*
  105. * Maximum number of free event structures to cache
  106. */
  107. #define DPU_CRTC_MAX_EVENT_COUNT 16
  108. /**
  109. * struct dpu_crtc - virtualized CRTC data structure
  110. * @base : Base drm crtc structure
  111. * @name : ASCII description of this crtc
  112. * @event : Pointer to last received drm vblank event. If there is a
  113. * pending vblank event, this will be non-null.
  114. * @vsync_count : Running count of received vsync events
  115. * @drm_requested_vblank : Whether vblanks have been enabled in the encoder
  116. * @property_info : Opaque structure for generic property support
  117. * @property_defaults : Array of default values for generic property support
  118. * @stage_cfg : H/w mixer stage configuration
  119. * @debugfs_root : Parent of debugfs node
  120. * @vblank_cb_count : count of vblank callback since last reset
  121. * @play_count : frame count between crtc enable and disable
  122. * @vblank_cb_time : ktime at vblank count reset
  123. * @vblank_requested : whether the user has requested vblank events
  124. * @suspend : whether or not a suspend operation is in progress
  125. * @enabled : whether the DPU CRTC is currently enabled. updated in the
  126. * commit-thread, not state-swap time which is earlier, so
  127. * safe to make decisions on during VBLANK on/off work
  128. * @feature_list : list of color processing features supported on a crtc
  129. * @active_list : list of color processing features are active
  130. * @dirty_list : list of color processing features are dirty
  131. * @ad_dirty: list containing ad properties that are dirty
  132. * @ad_active: list containing ad properties that are active
  133. * @crtc_lock : crtc lock around create, destroy and access.
  134. * @frame_pending : Whether or not an update is pending
  135. * @frame_events : static allocation of in-flight frame events
  136. * @frame_event_list : available frame event list
  137. * @spin_lock : spin lock for frame event, transaction status, etc...
  138. * @frame_done_comp : for frame_event_done synchronization
  139. * @event_thread : Pointer to event handler thread
  140. * @event_worker : Event worker queue
  141. * @event_lock : Spinlock around event handling code
  142. * @phandle: Pointer to power handler
  143. * @power_event : registered power event handle
  144. * @cur_perf : current performance committed to clock/bandwidth driver
  145. */
  146. struct dpu_crtc {
  147. struct drm_crtc base;
  148. char name[DPU_CRTC_NAME_SIZE];
  149. struct drm_pending_vblank_event *event;
  150. u32 vsync_count;
  151. struct dpu_hw_stage_cfg stage_cfg;
  152. struct dentry *debugfs_root;
  153. u32 vblank_cb_count;
  154. u64 play_count;
  155. ktime_t vblank_cb_time;
  156. bool vblank_requested;
  157. bool suspend;
  158. bool enabled;
  159. struct list_head feature_list;
  160. struct list_head active_list;
  161. struct list_head dirty_list;
  162. struct list_head ad_dirty;
  163. struct list_head ad_active;
  164. struct mutex crtc_lock;
  165. atomic_t frame_pending;
  166. struct dpu_crtc_frame_event frame_events[DPU_CRTC_FRAME_EVENT_SIZE];
  167. struct list_head frame_event_list;
  168. spinlock_t spin_lock;
  169. struct completion frame_done_comp;
  170. /* for handling internal event thread */
  171. spinlock_t event_lock;
  172. struct dpu_power_handle *phandle;
  173. struct dpu_power_event *power_event;
  174. struct dpu_core_perf_params cur_perf;
  175. struct dpu_crtc_smmu_state_data smmu_state;
  176. };
  177. #define to_dpu_crtc(x) container_of(x, struct dpu_crtc, base)
  178. /**
  179. * struct dpu_crtc_state - dpu container for atomic crtc state
  180. * @base: Base drm crtc state structure
  181. * @bw_control : true if bw/clk controlled by core bw/clk properties
  182. * @bw_split_vote : true if bw controlled by llcc/dram bw properties
  183. * @lm_bounds : LM boundaries based on current mode full resolution, no ROI.
  184. * Origin top left of CRTC.
  185. * @property_state: Local storage for msm_prop properties
  186. * @property_values: Current crtc property values
  187. * @input_fence_timeout_ns : Cached input fence timeout, in ns
  188. * @new_perf: new performance state being requested
  189. * @num_mixers : Number of mixers in use
  190. * @mixers : List of active mixers
  191. * @num_ctls : Number of ctl paths in use
  192. * @hw_ctls : List of active ctl paths
  193. */
  194. struct dpu_crtc_state {
  195. struct drm_crtc_state base;
  196. bool bw_control;
  197. bool bw_split_vote;
  198. struct drm_rect lm_bounds[CRTC_DUAL_MIXERS];
  199. uint64_t input_fence_timeout_ns;
  200. struct dpu_core_perf_params new_perf;
  201. /* HW Resources reserved for the crtc */
  202. u32 num_mixers;
  203. struct dpu_crtc_mixer mixers[CRTC_DUAL_MIXERS];
  204. u32 num_ctls;
  205. struct dpu_hw_ctl *hw_ctls[CRTC_DUAL_MIXERS];
  206. };
  207. #define to_dpu_crtc_state(x) \
  208. container_of(x, struct dpu_crtc_state, base)
  209. /**
  210. * dpu_crtc_state_is_stereo - Is crtc virtualized with two mixers?
  211. * @cstate: Pointer to dpu crtc state
  212. * @Return: true - has two mixers, false - has one mixer
  213. */
  214. static inline bool dpu_crtc_state_is_stereo(struct dpu_crtc_state *cstate)
  215. {
  216. return cstate->num_mixers == CRTC_DUAL_MIXERS;
  217. }
  218. /**
  219. * dpu_crtc_get_mixer_height - get the mixer height
  220. * Mixer height will be same as panel height
  221. */
  222. static inline int dpu_crtc_get_mixer_height(struct dpu_crtc *dpu_crtc,
  223. struct dpu_crtc_state *cstate, struct drm_display_mode *mode)
  224. {
  225. if (!dpu_crtc || !cstate || !mode)
  226. return 0;
  227. return mode->vdisplay;
  228. }
  229. /**
  230. * dpu_crtc_frame_pending - retun the number of pending frames
  231. * @crtc: Pointer to drm crtc object
  232. */
  233. static inline int dpu_crtc_frame_pending(struct drm_crtc *crtc)
  234. {
  235. struct dpu_crtc *dpu_crtc;
  236. if (!crtc)
  237. return -EINVAL;
  238. dpu_crtc = to_dpu_crtc(crtc);
  239. return atomic_read(&dpu_crtc->frame_pending);
  240. }
  241. /**
  242. * dpu_crtc_vblank - enable or disable vblanks for this crtc
  243. * @crtc: Pointer to drm crtc object
  244. * @en: true to enable vblanks, false to disable
  245. */
  246. int dpu_crtc_vblank(struct drm_crtc *crtc, bool en);
  247. /**
  248. * dpu_crtc_commit_kickoff - trigger kickoff of the commit for this crtc
  249. * @crtc: Pointer to drm crtc object
  250. */
  251. void dpu_crtc_commit_kickoff(struct drm_crtc *crtc);
  252. /**
  253. * dpu_crtc_complete_commit - callback signalling completion of current commit
  254. * @crtc: Pointer to drm crtc object
  255. * @old_state: Pointer to drm crtc old state object
  256. */
  257. void dpu_crtc_complete_commit(struct drm_crtc *crtc,
  258. struct drm_crtc_state *old_state);
  259. /**
  260. * dpu_crtc_init - create a new crtc object
  261. * @dev: dpu device
  262. * @plane: base plane
  263. * @cursor: cursor plane
  264. * @Return: new crtc object or error
  265. */
  266. struct drm_crtc *dpu_crtc_init(struct drm_device *dev, struct drm_plane *plane,
  267. struct drm_plane *cursor);
  268. /**
  269. * dpu_crtc_register_custom_event - api for enabling/disabling crtc event
  270. * @kms: Pointer to dpu_kms
  271. * @crtc_drm: Pointer to crtc object
  272. * @event: Event that client is interested
  273. * @en: Flag to enable/disable the event
  274. */
  275. int dpu_crtc_register_custom_event(struct dpu_kms *kms,
  276. struct drm_crtc *crtc_drm, u32 event, bool en);
  277. /**
  278. * dpu_crtc_get_intf_mode - get interface mode of the given crtc
  279. * @crtc: Pointert to crtc
  280. */
  281. enum dpu_intf_mode dpu_crtc_get_intf_mode(struct drm_crtc *crtc);
  282. /**
  283. * dpu_crtc_get_client_type - check the crtc type- rt, nrt etc.
  284. * @crtc: Pointer to crtc
  285. */
  286. static inline enum dpu_crtc_client_type dpu_crtc_get_client_type(
  287. struct drm_crtc *crtc)
  288. {
  289. struct dpu_crtc_state *cstate =
  290. crtc ? to_dpu_crtc_state(crtc->state) : NULL;
  291. if (!cstate)
  292. return NRT_CLIENT;
  293. return RT_CLIENT;
  294. }
  295. /**
  296. * dpu_crtc_is_enabled - check if dpu crtc is enabled or not
  297. * @crtc: Pointer to crtc
  298. */
  299. static inline bool dpu_crtc_is_enabled(struct drm_crtc *crtc)
  300. {
  301. return crtc ? crtc->enabled : false;
  302. }
  303. #endif /* _DPU_CRTC_H_ */