sde_crtc.h 33 KB

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