sde_crtc.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. /*
  2. * Copyright (c) 2015-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  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 _SDE_CRTC_H_
  19. #define _SDE_CRTC_H_
  20. #include <linux/kthread.h>
  21. #include <linux/of_fdt.h>
  22. #include <drm/drm_crtc.h>
  23. #include <drm/drm_vblank.h>
  24. #include "msm_prop.h"
  25. #include "sde_fence.h"
  26. #include "sde_kms.h"
  27. #include "sde_core_perf.h"
  28. #include "sde_hw_ds.h"
  29. #define SDE_CRTC_NAME_SIZE 12
  30. /* define the maximum number of in-flight frame events */
  31. /* Expand it to 2x for handling atleast 2 connectors safely */
  32. #define SDE_CRTC_FRAME_EVENT_SIZE (4 * 2)
  33. /**
  34. * enum sde_crtc_client_type: crtc client type
  35. * @RT_CLIENT: RealTime client like video/cmd mode display
  36. * voting through apps rsc
  37. * @NRT_CLIENT: Non-RealTime client like WB display
  38. * voting through apps rsc
  39. * @RT_RSC_CLIENT: Realtime display RSC voting client
  40. */
  41. enum sde_crtc_client_type {
  42. RT_CLIENT,
  43. NRT_CLIENT,
  44. RT_RSC_CLIENT,
  45. };
  46. /**
  47. * enum sde_crtc_output_capture_point
  48. * @MIXER_OUT : capture mixer output
  49. * @DSPP_OUT : capture output of dspp
  50. * @CAPTURE_DEMURA_OUT : capture output of demura
  51. */
  52. enum sde_crtc_output_capture_point {
  53. CAPTURE_MIXER_OUT,
  54. CAPTURE_DSPP_OUT,
  55. CAPTURE_DEMURA_OUT
  56. };
  57. /**
  58. * enum sde_crtc_idle_pc_state: states of idle power collapse
  59. * @IDLE_PC_NONE: no-op
  60. * @IDLE_PC_ENABLE: enable idle power-collapse
  61. * @IDLE_PC_DISABLE: disable idle power-collapse
  62. */
  63. enum sde_crtc_idle_pc_state {
  64. IDLE_PC_NONE,
  65. IDLE_PC_ENABLE,
  66. IDLE_PC_DISABLE,
  67. };
  68. /**
  69. * enum sde_crtc_cache_state: states of disp system cache
  70. * CACHE_STATE_DISABLED: sys cache has been disabled
  71. * CACHE_STATE_ENABLED: sys cache has been enabled
  72. * CACHE_STATE_NORMAL: sys cache is normal state
  73. * CACHE_STATE_PRE_CACHE: frame cache is being prepared
  74. * CACHE_STATE_FRAME_WRITE: sys cache is being written to
  75. * CACHE_STATE_FRAME_READ: sys cache is being read
  76. */
  77. enum sde_crtc_cache_state {
  78. CACHE_STATE_DISABLED,
  79. CACHE_STATE_ENABLED,
  80. CACHE_STATE_NORMAL,
  81. CACHE_STATE_PRE_CACHE,
  82. CACHE_STATE_FRAME_WRITE,
  83. CACHE_STATE_FRAME_READ
  84. };
  85. /**
  86. * enum sde_crtc_vm_req: request for VM operations
  87. * @VM_REQ_NONE: no request. Normal VM operations.
  88. * @VM_REQ_RELEASE: request to release the HW resources from the current VM
  89. * @VM_REQ_ACQUIRE: request to acquire the HW resources in the current VM
  90. */
  91. enum sde_crtc_vm_req {
  92. VM_REQ_NONE,
  93. VM_REQ_RELEASE,
  94. VM_REQ_ACQUIRE,
  95. };
  96. /**
  97. * @connectors : Currently associated drm connectors for retire event
  98. * @num_connectors: Number of associated drm connectors for retire event
  99. * @list: event list
  100. */
  101. struct sde_crtc_retire_event {
  102. struct drm_connector *connectors[MAX_CONNECTORS];
  103. int num_connectors;
  104. struct list_head list;
  105. };
  106. /**
  107. * struct sde_crtc_mixer: stores the map for each virtual pipeline in the CRTC
  108. * @hw_lm: LM HW Driver context
  109. * @hw_ctl: CTL Path HW driver context
  110. * @hw_dspp: DSPP HW driver context
  111. * @hw_ds: DS HW driver context
  112. * @encoder: Encoder attached to this lm & ctl
  113. * @mixer_op_mode: mixer blending operation mode
  114. */
  115. struct sde_crtc_mixer {
  116. struct sde_hw_mixer *hw_lm;
  117. struct sde_hw_ctl *hw_ctl;
  118. struct sde_hw_dspp *hw_dspp;
  119. struct sde_hw_ds *hw_ds;
  120. struct drm_encoder *encoder;
  121. u32 mixer_op_mode;
  122. };
  123. /**
  124. * struct sde_crtc_frame_event: stores crtc frame event for crtc processing
  125. * @work: base work structure
  126. * @crtc: Pointer to crtc handling this event
  127. * @connector: pointer to drm connector which is source of frame event
  128. * @list: event list
  129. * @ts: timestamp at queue entry
  130. * @event: event identifier
  131. */
  132. struct sde_crtc_frame_event {
  133. struct kthread_work work;
  134. struct drm_crtc *crtc;
  135. struct drm_connector *connector;
  136. struct list_head list;
  137. ktime_t ts;
  138. u32 event;
  139. };
  140. /**
  141. * struct sde_crtc_event - event callback tracking structure
  142. * @list: Linked list tracking node
  143. * @kt_work: Kthread worker structure
  144. * @sde_crtc: Pointer to associated sde_crtc structure
  145. * @cb_func: Pointer to callback function
  146. * @usr: Pointer to user data to be provided to the callback
  147. */
  148. struct sde_crtc_event {
  149. struct list_head list;
  150. struct kthread_work kt_work;
  151. void *sde_crtc;
  152. void (*cb_func)(struct drm_crtc *crtc, void *usr);
  153. void *usr;
  154. };
  155. /**
  156. * struct sde_crtc_fps_info - structure for measuring fps periodicity
  157. * @frame_count : Total frames during configured periodic duration
  158. * @last_sampled_time_us: Stores the last ktime in microsecs when fps
  159. * was calculated
  160. * @measured_fps : Last measured fps value
  161. * @fps_periodic_duration : Duration in milliseconds to measure the fps.
  162. * Default value is 1 second.
  163. * @time_buf : Buffer for storing ktime of the commits
  164. * @next_time_index : index into time_buf for storing ktime for next commit
  165. */
  166. struct sde_crtc_fps_info {
  167. u32 frame_count;
  168. ktime_t last_sampled_time_us;
  169. u32 measured_fps;
  170. u32 fps_periodic_duration;
  171. ktime_t *time_buf;
  172. u32 next_time_index;
  173. };
  174. /**
  175. * struct sde_ltm_buffer - defines LTM buffer structure.
  176. * @fb: frm framebuffer for the buffer
  177. * @gem: drm gem handle for the buffer
  178. * @asapce : pointer to address space
  179. * @drm_fb_id: framebuffer id associated with this buffer
  180. * @offset: offset for alignment
  181. * @iova: device address
  182. * @kva: kernel virtual address
  183. * @node: list node for LTM buffer list;
  184. */
  185. struct sde_ltm_buffer {
  186. struct drm_framebuffer *fb;
  187. struct drm_gem_object *gem;
  188. struct msm_gem_address_space *aspace;
  189. u32 drm_fb_id;
  190. u32 offset;
  191. u64 iova;
  192. void *kva;
  193. struct list_head node;
  194. };
  195. /**
  196. * struct sde_crtc_misr_info - structure for misr information
  197. * @misr_enable : enable/disable flag
  198. * @misr_frame_count : Number of frames for misr calculation.
  199. */
  200. struct sde_crtc_misr_info {
  201. bool misr_enable;
  202. u32 misr_frame_count;
  203. };
  204. /*
  205. * Maximum number of free event structures to cache
  206. */
  207. #define SDE_CRTC_MAX_EVENT_COUNT 16
  208. /**
  209. * struct sde_crtc - virtualized CRTC data structure
  210. * @base : Base drm crtc structure
  211. * @name : ASCII description of this crtc
  212. * @num_ctls : Number of ctl paths in use
  213. * @num_mixers : Number of mixers in use
  214. * @mixers_swapped: Whether the mixers have been swapped for left/right update
  215. * especially in the case of DSC Merge.
  216. * @mixers : List of active mixers
  217. * @event : Pointer to last received drm vblank event. If there is a
  218. * pending vblank event, this will be non-null.
  219. * @vsync_count : Running count of received vsync events
  220. * @drm_requested_vblank : Whether vblanks have been enabled in the encoder
  221. * @property_info : Opaque structure for generic property support
  222. * @property_defaults : Array of default values for generic property support
  223. * @output_fence : output release fence context
  224. * @stage_cfg : H/w mixer stage configuration
  225. * @debugfs_root : Parent of debugfs node
  226. * @priv_handle : Pointer to external private handle, if present
  227. * @vblank_cb_count : count of vblank callback since last reset
  228. * @play_count : frame count between crtc enable and disable
  229. * @vblank_cb_time : ktime at vblank count reset
  230. * @vblank_last_cb_time : ktime at last vblank notification
  231. * @retire_frame_event_time : ktime at last retire frame event
  232. * @sysfs_dev : sysfs device node for crtc
  233. * @vsync_event_sf : vsync event notifier sysfs device
  234. * @retire_frame_event_sf :retire frame event notifier sysfs device
  235. * @enabled : whether the SDE CRTC is currently enabled. updated in the
  236. * commit-thread, not state-swap time which is earlier, so
  237. * safe to make decisions on during VBLANK on/off work
  238. * @feature_list : list of color processing features supported on a crtc
  239. * @active_list : list of color processing features are active
  240. * @dirty_list : list of color processing features are dirty
  241. * @ad_dirty : list containing ad properties that are dirty
  242. * @ad_active : list containing ad properties that are active
  243. * @crtc_lock : crtc lock around create, destroy and access.
  244. * @frame_pending : Whether or not an update is pending
  245. * @frame_events : static allocation of in-flight frame events
  246. * @frame_event_list : available frame event list
  247. * @spin_lock : spin lock for frame event, transaction status, etc...
  248. * @event_thread : Pointer to event handler thread
  249. * @event_worker : Event worker queue
  250. * @event_cache : Local cache of event worker structures
  251. * @event_free_list : List of available event structures
  252. * @event_lock : Spinlock around event handling code
  253. * @misr_enable_sui : boolean entry indicates misr enable/disable status
  254. * for secure cases.
  255. * @misr_enable_debugfs : boolean entry indicates misr enable/disable status
  256. * from debugfs.
  257. * @misr_reconfigure : boolean entry indicates misr reconfigure status
  258. * @misr_frame_count : misr frame count provided by client
  259. * @misr_data : store misr data before turning off the clocks.
  260. * @idle_notify_work: delayed worker to notify idle timeout to user space
  261. * @power_event : registered power event handle
  262. * @cur_perf : current performance committed to clock/bandwidth driver
  263. * @plane_mask_old: keeps track of the planes used in the previous commit
  264. * @frame_trigger_mode: frame trigger mode
  265. * @cp_pu_feature_mask: mask indicating cp feature enable for partial update
  266. * @ltm_buffer_cnt : number of ltm buffers
  267. * @ltm_buffers : struct stores ltm buffer related data
  268. * @ltm_buf_free : list of LTM buffers that are available
  269. * @ltm_buf_busy : list of LTM buffers that are been used by HW
  270. * @ltm_hist_en : flag to indicate whether LTM hist is enabled or not
  271. * @ltm_buffer_lock : muttx to protect ltm_buffers allcation and free
  272. * @ltm_lock : Spinlock to protect ltm buffer_cnt, hist_en and ltm lists
  273. * @needs_hw_reset : Initiate a hw ctl reset
  274. * @src_bpp : source bpp used to calculate compression ratio
  275. * @target_bpp : target bpp used to calculate compression ratio
  276. * @static_cache_read_work: delayed worker to transition cache state to read
  277. * @cache_state : Current static image cache state
  278. * @dspp_blob_info : blob containing dspp hw capability information
  279. * @cached_encoder_mask : cached encoder_mask for vblank work
  280. */
  281. struct sde_crtc {
  282. struct drm_crtc base;
  283. char name[SDE_CRTC_NAME_SIZE];
  284. /* HW Resources reserved for the crtc */
  285. u32 num_ctls;
  286. u32 num_mixers;
  287. bool mixers_swapped;
  288. struct sde_crtc_mixer mixers[MAX_MIXERS_PER_CRTC];
  289. struct drm_pending_vblank_event *event;
  290. u32 vsync_count;
  291. struct msm_property_info property_info;
  292. struct msm_property_data property_data[CRTC_PROP_COUNT];
  293. struct drm_property_blob *blob_info;
  294. /* output fence support */
  295. struct sde_fence_context *output_fence;
  296. struct sde_hw_stage_cfg stage_cfg[MAX_LAYOUTS_PER_CRTC];
  297. struct dentry *debugfs_root;
  298. void *priv_handle;
  299. u32 vblank_cb_count;
  300. u64 play_count;
  301. ktime_t vblank_cb_time;
  302. ktime_t vblank_last_cb_time;
  303. ktime_t retire_frame_event_time;
  304. struct sde_crtc_fps_info fps_info;
  305. struct device *sysfs_dev;
  306. struct kernfs_node *vsync_event_sf;
  307. struct kernfs_node *retire_frame_event_sf;
  308. bool enabled;
  309. struct list_head feature_list;
  310. struct list_head active_list;
  311. struct list_head dirty_list;
  312. struct list_head ad_dirty;
  313. struct list_head ad_active;
  314. struct list_head user_event_list;
  315. struct mutex crtc_lock;
  316. struct mutex crtc_cp_lock;
  317. atomic_t frame_pending;
  318. struct sde_crtc_frame_event frame_events[SDE_CRTC_FRAME_EVENT_SIZE];
  319. struct list_head frame_event_list;
  320. spinlock_t spin_lock;
  321. /* for handling internal event thread */
  322. struct sde_crtc_event event_cache[SDE_CRTC_MAX_EVENT_COUNT];
  323. struct list_head event_free_list;
  324. spinlock_t event_lock;
  325. bool misr_enable_sui;
  326. bool misr_enable_debugfs;
  327. bool misr_reconfigure;
  328. u32 misr_frame_count;
  329. struct kthread_delayed_work idle_notify_work;
  330. struct sde_power_event *power_event;
  331. struct sde_core_perf_params cur_perf;
  332. struct sde_core_perf_params new_perf;
  333. u32 plane_mask_old;
  334. /* blob for histogram data */
  335. struct drm_property_blob *hist_blob;
  336. enum frame_trigger_mode_type frame_trigger_mode;
  337. u32 cp_pu_feature_mask;
  338. u32 ltm_buffer_cnt;
  339. struct sde_ltm_buffer *ltm_buffers[LTM_BUFFER_SIZE];
  340. struct list_head ltm_buf_free;
  341. struct list_head ltm_buf_busy;
  342. bool ltm_hist_en;
  343. struct drm_msm_ltm_cfg_param ltm_cfg;
  344. struct mutex ltm_buffer_lock;
  345. spinlock_t ltm_lock;
  346. bool needs_hw_reset;
  347. int src_bpp;
  348. int target_bpp;
  349. struct kthread_delayed_work static_cache_read_work;
  350. enum sde_crtc_cache_state cache_state;
  351. struct drm_property_blob *dspp_blob_info;
  352. u32 cached_encoder_mask;
  353. };
  354. enum sde_crtc_dirty_flags {
  355. SDE_CRTC_DIRTY_DEST_SCALER,
  356. SDE_CRTC_DIRTY_DIM_LAYERS,
  357. SDE_CRTC_NOISE_LAYER,
  358. SDE_CRTC_DIRTY_MAX,
  359. };
  360. #define to_sde_crtc(x) container_of(x, struct sde_crtc, base)
  361. /**
  362. * struct sde_crtc_state - sde container for atomic crtc state
  363. * @base: Base drm crtc state structure
  364. * @connectors : Currently associated drm connectors
  365. * @num_connectors: Number of associated drm connectors
  366. * @rsc_client : sde rsc client when mode is valid
  367. * @is_ppsplit : Whether current topology requires PPSplit special handling
  368. * @bw_control : true if bw/clk controlled by core bw/clk properties
  369. * @bw_split_vote : true if bw controlled by llcc/dram bw properties
  370. * @crtc_roi : Current CRTC ROI. Possibly sub-rectangle of mode.
  371. * Origin top left of CRTC.
  372. * @lm_bounds : LM boundaries based on current mode full resolution, no ROI.
  373. * Origin top left of CRTC.
  374. * @lm_roi : Current LM ROI, possibly sub-rectangle of mode.
  375. * Origin top left of CRTC.
  376. * @user_roi_list : List of user's requested ROIs as from set property
  377. * @cached_user_roi_list : Copy of user_roi_list from previous PU frame
  378. * @property_state: Local storage for msm_prop properties
  379. * @property_values: Current crtc property values
  380. * @input_fence_timeout_ns : Cached input fence timeout, in ns
  381. * @num_dim_layers: Number of dim layers
  382. * @dim_layer: Dim layer configs
  383. * @num_ds: Number of destination scalers to be configured
  384. * @num_ds_enabled: Number of destination scalers enabled
  385. * @ds_cfg: Destination scaler config
  386. * @scl3_lut_cfg: QSEED3 lut config
  387. * @new_perf: new performance state being requested
  388. * @noise_layer_en: flag to indicate if noise layer cfg is valid
  389. * @drm_msm_noise_layer_cfg: noise layer configuration
  390. */
  391. struct sde_crtc_state {
  392. struct drm_crtc_state base;
  393. struct drm_connector *connectors[MAX_CONNECTORS];
  394. int num_connectors;
  395. struct sde_rsc_client *rsc_client;
  396. bool rsc_update;
  397. bool bw_control;
  398. bool bw_split_vote;
  399. bool is_ppsplit;
  400. struct sde_rect crtc_roi;
  401. struct sde_rect lm_bounds[MAX_MIXERS_PER_CRTC];
  402. struct sde_rect lm_roi[MAX_MIXERS_PER_CRTC];
  403. struct msm_roi_list user_roi_list, cached_user_roi_list;
  404. struct msm_property_state property_state;
  405. struct msm_property_value property_values[CRTC_PROP_COUNT];
  406. DECLARE_BITMAP(dirty, SDE_CRTC_DIRTY_MAX);
  407. uint64_t input_fence_timeout_ns;
  408. uint32_t num_dim_layers;
  409. struct sde_hw_dim_layer dim_layer[SDE_MAX_DIM_LAYERS];
  410. uint32_t num_ds;
  411. uint32_t num_ds_enabled;
  412. struct sde_hw_ds_cfg ds_cfg[SDE_MAX_DS_COUNT];
  413. struct sde_hw_scaler3_lut_cfg scl3_lut_cfg;
  414. struct sde_core_perf_params new_perf;
  415. bool noise_layer_en;
  416. struct drm_msm_noise_layer_cfg layer_cfg;
  417. };
  418. enum sde_crtc_irq_state {
  419. IRQ_NOINIT,
  420. IRQ_ENABLED,
  421. IRQ_DISABLING,
  422. IRQ_DISABLED,
  423. };
  424. /**
  425. * sde_crtc_irq_info - crtc interrupt info
  426. * @irq: interrupt callback
  427. * @event: event type of the interrupt
  428. * @func: function pointer to enable/disable the interrupt
  429. * @list: list of user customized event in crtc
  430. * @state: state of the interrupt
  431. * @state_lock: spin lock for interrupt state
  432. */
  433. struct sde_crtc_irq_info {
  434. struct sde_irq_callback irq;
  435. u32 event;
  436. int (*func)(struct drm_crtc *crtc, bool en,
  437. struct sde_irq_callback *irq);
  438. struct list_head list;
  439. enum sde_crtc_irq_state state;
  440. spinlock_t state_lock;
  441. };
  442. #define to_sde_crtc_state(x) \
  443. container_of(x, struct sde_crtc_state, base)
  444. /**
  445. * sde_crtc_get_property - query integer value of crtc property
  446. * @S: Pointer to crtc state
  447. * @X: Property index, from enum msm_mdp_crtc_property
  448. * Returns: Integer value of requested property
  449. */
  450. #define sde_crtc_get_property(S, X) \
  451. ((S) && ((X) < CRTC_PROP_COUNT) ? ((S)->property_values[(X)].value) : 0)
  452. /**
  453. * sde_crtc_get_mixer_width - get the mixer width
  454. * Mixer width will be same as panel width(/2 for split)
  455. * unless destination scaler feature is enabled
  456. */
  457. static inline int sde_crtc_get_mixer_width(struct sde_crtc *sde_crtc,
  458. struct sde_crtc_state *cstate, struct drm_display_mode *mode)
  459. {
  460. u32 mixer_width;
  461. if (!sde_crtc || !cstate || !mode)
  462. return 0;
  463. if (cstate->num_ds_enabled)
  464. mixer_width = cstate->ds_cfg[0].lm_width;
  465. else
  466. mixer_width = mode->hdisplay / sde_crtc->num_mixers;
  467. return mixer_width;
  468. }
  469. /**
  470. * sde_crtc_get_mixer_height - get the mixer height
  471. * Mixer height will be same as panel height unless
  472. * destination scaler feature is enabled
  473. */
  474. static inline int sde_crtc_get_mixer_height(struct sde_crtc *sde_crtc,
  475. struct sde_crtc_state *cstate, struct drm_display_mode *mode)
  476. {
  477. if (!sde_crtc || !cstate || !mode)
  478. return 0;
  479. return (cstate->num_ds_enabled ?
  480. cstate->ds_cfg[0].lm_height : mode->vdisplay);
  481. }
  482. /**
  483. * sde_crtc_frame_pending - retun the number of pending frames
  484. * @crtc: Pointer to drm crtc object
  485. */
  486. static inline int sde_crtc_frame_pending(struct drm_crtc *crtc)
  487. {
  488. struct sde_crtc *sde_crtc;
  489. if (!crtc)
  490. return -EINVAL;
  491. sde_crtc = to_sde_crtc(crtc);
  492. return atomic_read(&sde_crtc->frame_pending);
  493. }
  494. /**
  495. * sde_crtc_set_needs_hw_reset - set hw reset flag, to handle reset during
  496. * commit kickoff
  497. * @crtc: Pointer to DRM crtc instance
  498. */
  499. static inline void sde_crtc_set_needs_hw_reset(struct drm_crtc *crtc)
  500. {
  501. struct sde_crtc *sde_crtc;
  502. if (!crtc)
  503. return;
  504. sde_crtc = to_sde_crtc(crtc);
  505. sde_crtc->needs_hw_reset = true;
  506. }
  507. /**
  508. * sde_crtc_reset_hw - attempt hardware reset on errors
  509. * @crtc: Pointer to DRM crtc instance
  510. * @old_state: Pointer to crtc state for previous commit
  511. * @recovery_events: Whether or not recovery events are enabled
  512. * Returns: Zero if current commit should still be attempted
  513. */
  514. int sde_crtc_reset_hw(struct drm_crtc *crtc, struct drm_crtc_state *old_state,
  515. bool recovery_events);
  516. /**
  517. * sde_crtc_request_frame_reset - requests for next frame reset
  518. * @crtc: Pointer to drm crtc object
  519. */
  520. static inline int sde_crtc_request_frame_reset(struct drm_crtc *crtc)
  521. {
  522. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  523. if (sde_crtc->frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START)
  524. sde_crtc_reset_hw(crtc, crtc->state, false);
  525. return 0;
  526. }
  527. /**
  528. * sde_crtc_vblank - enable or disable vblanks for this crtc
  529. * @crtc: Pointer to drm crtc object
  530. * @en: true to enable vblanks, false to disable
  531. */
  532. int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
  533. /**
  534. * sde_crtc_get_msm_mode - get msm_mode for a given crtc state
  535. * @c_state: Pointer to drm crtc state object
  536. * Returns: msm_display_mode corresponding to this crtc state, or NULL if none
  537. */
  538. struct msm_display_mode *sde_crtc_get_msm_mode(struct drm_crtc_state *c_state);
  539. /**
  540. * sde_crtc_commit_kickoff - trigger kickoff of the commit for this crtc
  541. * @crtc: Pointer to drm crtc object
  542. * @old_state: Pointer to drm crtc old state object
  543. */
  544. void sde_crtc_commit_kickoff(struct drm_crtc *crtc,
  545. struct drm_crtc_state *old_state);
  546. /**
  547. * sde_crtc_prepare_commit - callback to prepare for output fences
  548. * @crtc: Pointer to drm crtc object
  549. * @old_state: Pointer to drm crtc old state object
  550. */
  551. void sde_crtc_prepare_commit(struct drm_crtc *crtc,
  552. struct drm_crtc_state *old_state);
  553. /**
  554. * sde_crtc_complete_commit - callback signalling completion of current commit
  555. * @crtc: Pointer to drm crtc object
  556. * @old_state: Pointer to drm crtc old state object
  557. */
  558. void sde_crtc_complete_commit(struct drm_crtc *crtc,
  559. struct drm_crtc_state *old_state);
  560. /**
  561. * sde_crtc_init - create a new crtc object
  562. * @dev: sde device
  563. * @plane: base plane
  564. * @Return: new crtc object or error
  565. */
  566. struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane);
  567. /**
  568. * sde_crtc_post_init - update crtc object with post initialization. It
  569. * can update the debugfs, sysfs, entires.
  570. * @dev: sde device
  571. * @crtc: Pointer to drm crtc structure
  572. */
  573. int sde_crtc_post_init(struct drm_device *dev, struct drm_crtc *crtc);
  574. /**
  575. * sde_crtc_complete_flip - complete flip for clients
  576. * @crtc: Pointer to drm crtc object
  577. * @file: client to cancel's file handle
  578. */
  579. void sde_crtc_complete_flip(struct drm_crtc *crtc, struct drm_file *file);
  580. /**
  581. * sde_crtc_register_custom_event - api for enabling/disabling crtc event
  582. * @kms: Pointer to sde_kms
  583. * @crtc_drm: Pointer to crtc object
  584. * @event: Event that client is interested
  585. * @en: Flag to enable/disable the event
  586. */
  587. int sde_crtc_register_custom_event(struct sde_kms *kms,
  588. struct drm_crtc *crtc_drm, u32 event, bool en);
  589. /**
  590. * sde_crtc_get_intf_mode - get interface mode of the given crtc
  591. * @crtc: Pointert to DRM crtc
  592. * @crtc: Pointert to DRM crtc_state
  593. */
  594. enum sde_intf_mode sde_crtc_get_intf_mode(struct drm_crtc *crtc,
  595. struct drm_crtc_state *cstate);
  596. /**
  597. * sde_crtc_get_fps_mode - get frame rate of the given crtc
  598. * @crtc: Pointert to crtc
  599. */
  600. u32 sde_crtc_get_fps_mode(struct drm_crtc *crtc);
  601. /**
  602. * sde_crtc_get_dfps_maxfps - get DFPS max fps of the given crtc
  603. * @crtc: Pointert to crtc
  604. */
  605. u32 sde_crtc_get_dfps_maxfps(struct drm_crtc *crtc);
  606. /**
  607. * sde_crtc_get_client_type - check the crtc type- rt, rsc_rt, etc.
  608. * @crtc: Pointer to crtc
  609. */
  610. static inline enum sde_crtc_client_type sde_crtc_get_client_type(
  611. struct drm_crtc *crtc)
  612. {
  613. struct sde_crtc_state *cstate =
  614. crtc ? to_sde_crtc_state(crtc->state) : NULL;
  615. if (!cstate)
  616. return RT_CLIENT;
  617. return cstate->rsc_client ? RT_RSC_CLIENT : RT_CLIENT;
  618. }
  619. /**
  620. * sde_crtc_is_rt_client - check if real-time client or not
  621. * @crtc: Pointer to DRM crtc
  622. * @crtc_state: Pointer to DRM crtc_state
  623. */
  624. static inline bool sde_crtc_is_rt_client(struct drm_crtc *crtc,
  625. struct drm_crtc_state *cstate)
  626. {
  627. if (!crtc || !cstate)
  628. return true;
  629. return (sde_crtc_get_intf_mode(crtc, cstate) != INTF_MODE_WB_LINE);
  630. }
  631. /**
  632. * sde_crtc_is_enabled - check if sde crtc is enabled or not
  633. * @crtc: Pointer to crtc
  634. */
  635. static inline bool sde_crtc_is_enabled(struct drm_crtc *crtc)
  636. {
  637. return crtc ? crtc->enabled : false;
  638. }
  639. /**
  640. * sde_crtc_is_reset_required - validate the reset request based on the
  641. * pm_suspend and crtc's active status. crtc's are left active
  642. * on pm_suspend during LP1/LP2 states, as the display is still
  643. * left ON. Avoid reset for the subsequent pm_resume in such cases.
  644. * @crtc: Pointer to crtc
  645. * return: false if in suspend state and crtc active, true otherwise
  646. */
  647. static inline bool sde_crtc_is_reset_required(struct drm_crtc *crtc)
  648. {
  649. /*
  650. * reset is required even when there is no crtc_state as it is required
  651. * to create the initial state object
  652. */
  653. if (!crtc || !crtc->state)
  654. return true;
  655. /* reset not required if crtc is active during suspend state */
  656. if (sde_kms_is_suspend_state(crtc->dev) && crtc->state->active)
  657. return false;
  658. return true;
  659. }
  660. /**
  661. * sde_crtc_event_queue - request event callback
  662. * @crtc: Pointer to drm crtc structure
  663. * @func: Pointer to callback function
  664. * @usr: Pointer to user data to be passed to callback
  665. * @color_processing_event: True if color processing event
  666. * Returns: Zero on success
  667. */
  668. int sde_crtc_event_queue(struct drm_crtc *crtc,
  669. void (*func)(struct drm_crtc *crtc, void *usr),
  670. void *usr, bool color_processing_event);
  671. /**
  672. * sde_crtc_get_crtc_roi - retrieve the crtc_roi from the given state object
  673. * used to allow the planes to adjust their final lm out_xy value in the
  674. * case of partial update
  675. * @crtc_state: Pointer to crtc state
  676. * @crtc_roi: Output pointer to crtc roi in the given state
  677. */
  678. void sde_crtc_get_crtc_roi(struct drm_crtc_state *state,
  679. const struct sde_rect **crtc_roi);
  680. /**
  681. * sde_crtc_is_crtc_roi_dirty - retrieve whether crtc_roi was updated this frame
  682. * Note: Only use during atomic_check since dirty properties may be popped
  683. * @crtc_state: Pointer to crtc state
  684. * Return: true if roi is dirty, false otherwise
  685. */
  686. bool sde_crtc_is_crtc_roi_dirty(struct drm_crtc_state *state);
  687. /** sde_crt_get_secure_level - retrieve the secure level from the give state
  688. * object, this is used to determine the secure state of the crtc
  689. * @crtc : Pointer to drm crtc structure
  690. * @usr: Pointer to drm crtc state
  691. * return: secure_level
  692. */
  693. static inline int sde_crtc_get_secure_level(struct drm_crtc *crtc,
  694. struct drm_crtc_state *state)
  695. {
  696. if (!crtc || !state)
  697. return -EINVAL;
  698. return sde_crtc_get_property(to_sde_crtc_state(state),
  699. CRTC_PROP_SECURITY_LEVEL);
  700. }
  701. /** sde_crtc_atomic_check_has_modeset - checks if the new_crtc_state in the
  702. * drm_atomic_state has a modeset
  703. * @state : pointer to drm_atomic_state
  704. * @crtc : Pointer to drm crtc structure
  705. * Returns true if crtc has modeset
  706. */
  707. static inline bool sde_crtc_atomic_check_has_modeset(
  708. struct drm_atomic_state *state, struct drm_crtc *crtc)
  709. {
  710. struct drm_crtc_state *crtc_state;
  711. if (!state || !crtc)
  712. return false;
  713. crtc_state = drm_atomic_get_new_crtc_state(state,
  714. crtc);
  715. return (crtc_state && drm_atomic_crtc_needs_modeset(crtc_state));
  716. }
  717. /**
  718. * sde_crtc_get_secure_transition - determines the operations to be
  719. * performed before transitioning to secure state
  720. * This function should be called after swapping the new state
  721. * @crtc: Pointer to drm crtc structure
  722. * @old_crtc_state: Poniter to previous CRTC state
  723. * Returns the bitmask of operations need to be performed, -Error in
  724. * case of error cases
  725. */
  726. int sde_crtc_get_secure_transition_ops(struct drm_crtc *crtc,
  727. struct drm_crtc_state *old_crtc_state,
  728. bool old_valid_fb);
  729. /**
  730. * sde_crtc_find_plane_fb_modes - finds the modes of all planes attached
  731. * to crtc
  732. * @crtc: Pointer to DRM crtc object
  733. * @fb_ns: number of non secure planes
  734. * @fb_sec: number of secure-playback planes
  735. * @fb_sec_dir: number of secure-ui/secure-camera planes
  736. */
  737. int sde_crtc_find_plane_fb_modes(struct drm_crtc *crtc,
  738. uint32_t *fb_ns, uint32_t *fb_sec, uint32_t *fb_sec_dir);
  739. /**
  740. * sde_crtc_state_find_plane_fb_modes - finds the modes of all planes attached
  741. * to the crtc state
  742. * @crtc_state: Pointer to DRM crtc state object
  743. * @fb_ns: number of non secure planes
  744. * @fb_sec: number of secure-playback planes
  745. * @fb_sec_dir: number of secure-ui/secure-camera planes
  746. */
  747. int sde_crtc_state_find_plane_fb_modes(struct drm_crtc_state *state,
  748. uint32_t *fb_ns, uint32_t *fb_sec, uint32_t *fb_sec_dir);
  749. /**
  750. * sde_crtc_secure_ctrl - Initiates the transition between secure and
  751. * non-secure world
  752. * @crtc: Pointer to crtc
  753. * @post_commit: if this operation is triggered after commit
  754. */
  755. int sde_crtc_secure_ctrl(struct drm_crtc *crtc, bool post_commit);
  756. /**
  757. * sde_crtc_helper_reset_properties - reset properties to default values in the
  758. * given DRM CRTC state object
  759. * @crtc: Pointer to DRM crtc object
  760. * @crtc_state: Pointer to DRM crtc state object
  761. * Returns: 0 on success, negative errno on failure
  762. */
  763. int sde_crtc_helper_reset_custom_properties(struct drm_crtc *crtc,
  764. struct drm_crtc_state *crtc_state);
  765. /**
  766. * sde_crtc_timeline_status - current buffer timeline status
  767. * @crtc: Pointer to crtc
  768. */
  769. void sde_crtc_timeline_status(struct drm_crtc *crtc);
  770. /**
  771. * sde_crtc_update_cont_splash_settings - update mixer settings
  772. * during device bootup for cont_splash use case
  773. * @crtc: Pointer to drm crtc structure
  774. */
  775. void sde_crtc_update_cont_splash_settings(
  776. struct drm_crtc *crtc);
  777. /**
  778. * sde_crtc_set_qos_dirty - update plane dirty flag to include
  779. * QoS reprogramming which is required during fps switch
  780. * @crtc: Pointer to drm crtc structure
  781. */
  782. void sde_crtc_set_qos_dirty(struct drm_crtc *crtc);
  783. /**
  784. * sde_crtc_misr_setup - to configure and enable/disable MISR
  785. * @crtc: Pointer to drm crtc structure
  786. * @enable: boolean to indicate enable/disable misr
  787. * @frame_count: frame_count to be configured
  788. */
  789. void sde_crtc_misr_setup(struct drm_crtc *crtc, bool enable, u32 frame_count);
  790. /**
  791. * sde_crtc_get_misr_info - to configure and enable/disable MISR
  792. * @crtc: Pointer to drm crtc structure
  793. * @crtc_misr_info: Pointer to crtc misr info structure
  794. */
  795. void sde_crtc_get_misr_info(struct drm_crtc *crtc,
  796. struct sde_crtc_misr_info *crtc_misr_info);
  797. /**
  798. * sde_crtc_set_bpp - set src and target bpp values
  799. * @sde_crtc: Pointer to sde crtc struct
  800. * @src_bpp: source bpp value to be stored
  801. * @target_bpp: target value to be stored
  802. */
  803. static inline void sde_crtc_set_bpp(struct sde_crtc *sde_crtc, int src_bpp,
  804. int target_bpp)
  805. {
  806. sde_crtc->src_bpp = src_bpp;
  807. sde_crtc->target_bpp = target_bpp;
  808. }
  809. /**
  810. * sde_crtc_static_img_control - transition static img cache state
  811. * @crtc: Pointer to drm crtc structure
  812. * @state: cache state to transition to
  813. * @is_vidmode: if encoder is video mode
  814. */
  815. void sde_crtc_static_img_control(struct drm_crtc *crtc,
  816. enum sde_crtc_cache_state state, bool is_vidmode);
  817. /**
  818. * sde_crtc_static_cache_read_kickoff - kickoff cache read work
  819. * @crtc: Pointer to drm crtc structure
  820. */
  821. void sde_crtc_static_cache_read_kickoff(struct drm_crtc *crtc);
  822. /**
  823. * sde_crtc_get_num_datapath - get the number of datapath active
  824. * of primary connector
  825. * @crtc: Pointer to DRM crtc object
  826. * @connector: Pointer to DRM connector object of WB in CWB case
  827. */
  828. int sde_crtc_get_num_datapath(struct drm_crtc *crtc,
  829. struct drm_connector *connector);
  830. /**
  831. * sde_crtc_reset_sw_state - reset dirty proerties on crtc and
  832. * planes attached to the crtc
  833. * @crtc: Pointer to DRM crtc object
  834. */
  835. void sde_crtc_reset_sw_state(struct drm_crtc *crtc);
  836. #endif /* _SDE_CRTC_H_ */