sde_crtc.h 34 KB

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