blob: 59bfc4732762f1d3acc3b28c642020a24d8892ab [file] [log] [blame]
Dhaval Patel14d46ce2017-01-17 16:28:12 -08001/*
2 * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
Abhijit Kulkarni40e38162016-06-26 22:12:09 -04005 *
Dhaval Patel14d46ce2017-01-17 16:28:12 -08006 * 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.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -04009 *
Dhaval Patel14d46ce2017-01-17 16:28:12 -080010 * 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/>.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040017 */
18
19#ifndef _SDE_CRTC_H_
20#define _SDE_CRTC_H_
21
Clarence Ipa18d4832017-03-13 12:35:44 -070022#include <linux/kthread.h>
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040023#include "drm_crtc.h"
Clarence Ip7a753bb2016-07-07 11:47:44 -040024#include "msm_prop.h"
Clarence Ip24f80662016-06-13 19:05:32 -040025#include "sde_fence.h"
Clarence Ip7a753bb2016-07-07 11:47:44 -040026#include "sde_kms.h"
Alan Kwong9aa061c2016-11-06 21:17:12 -050027#include "sde_core_perf.h"
Alan Kwongcdb2f282017-03-18 13:42:06 -070028#include "sde_hw_blk.h"
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +053029#include "sde_hw_ds.h"
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040030
Clarence Ip8f7366c2016-07-05 12:15:26 -040031#define SDE_CRTC_NAME_SIZE 12
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040032
Alan Kwong628d19e2016-10-31 13:50:13 -040033/* define the maximum number of in-flight frame events */
Veera Sundaram Sankaran675ff622017-06-21 21:44:46 -070034#define SDE_CRTC_FRAME_EVENT_SIZE 4
Alan Kwong628d19e2016-10-31 13:50:13 -040035
Abhijit Kulkarni40e38162016-06-26 22:12:09 -040036/**
Dhaval Patel4d424602017-02-18 19:40:14 -080037 * 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 */
44enum sde_crtc_client_type {
45 RT_CLIENT,
46 NRT_CLIENT,
47 RT_RSC_CLIENT,
48};
49
50/**
Abhijit Kulkarni1b3340c2017-06-22 12:39:37 -070051 * enum sde_crtc_smmu_state: smmu state
52 * @ATTACHED: all the context banks are attached.
53 * @DETACHED: all the context banks are detached.
54 * @DETACHED_SEC: secure context bank is detached.
55 * @ATTACH_ALL_REQ: transient state of attaching context banks.
56 * @DETACH_ALL_REQ: transient state of detaching context banks.
57 * @DETACH_SEC_REQ: tranisent state of secure context bank is detached
58 * @ATTACH_SEC_REQ: transient state of attaching secure context bank.
59 */
60enum sde_crtc_smmu_state {
61 ATTACHED = 0,
62 DETACHED,
63 DETACHED_SEC,
64 ATTACH_ALL_REQ,
65 DETACH_ALL_REQ,
66 DETACH_SEC_REQ,
67 ATTACH_SEC_REQ,
68};
69
70/**
71 * enum sde_crtc_smmu_state_transition_type: state transition type
72 * @NONE: no pending state transitions
73 * @PRE_COMMIT: state transitions should be done before processing the commit
74 * @POST_COMMIT: state transitions to be done after processing the commit.
75 */
76enum sde_crtc_smmu_state_transition_type {
77 NONE,
78 PRE_COMMIT,
79 POST_COMMIT
80};
81
82/**
83 * struct sde_crtc_smmu_state_data: stores the smmu state and transition type
84 * @state: current state of smmu context banks
85 * @transition_type: transition request type
86 * @transition_error: whether there is error while transitioning the state
87 */
88struct sde_crtc_smmu_state_data {
89 uint32_t state;
90 uint32_t transition_type;
91 uint32_t transition_error;
92};
93
94/**
Dhaval Patel5023c3c2017-08-22 12:40:11 -070095 * @connectors : Currently associated drm connectors for retire event
96 * @num_connectors: Number of associated drm connectors for retire event
97 * @list: event list
98 */
99struct sde_crtc_retire_event {
100 struct drm_connector *connectors[MAX_CONNECTORS];
101 int num_connectors;
102 struct list_head list;
103};
104
105/**
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400106 * struct sde_crtc_mixer: stores the map for each virtual pipeline in the CRTC
107 * @hw_lm: LM HW Driver context
108 * @hw_ctl: CTL Path HW driver context
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700109 * @hw_dspp: DSPP HW driver context
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530110 * @hw_ds: DS HW driver context
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400111 * @encoder: Encoder attached to this lm & ctl
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530112 * @mixer_op_mode: mixer blending operation mode
Dhaval Patel48c76022016-09-01 17:51:23 -0700113 * @flush_mask: mixer flush mask for ctl, mixer and pipe
Clarence Ip662698e2017-09-12 18:34:16 -0400114 * @pipe_mask: mixer flush mask for pipe
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400115 */
116struct sde_crtc_mixer {
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400117 struct sde_hw_mixer *hw_lm;
Lloyd Atkinsonc44a52e2016-08-16 16:40:17 -0400118 struct sde_hw_ctl *hw_ctl;
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530119 struct sde_hw_dspp *hw_dspp;
120 struct sde_hw_ds *hw_ds;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400121 struct drm_encoder *encoder;
Dhaval Patel48c76022016-09-01 17:51:23 -0700122 u32 mixer_op_mode;
123 u32 flush_mask;
Clarence Ip662698e2017-09-12 18:34:16 -0400124 u32 pipe_mask;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400125};
126
127/**
Alan Kwong628d19e2016-10-31 13:50:13 -0400128 * struct sde_crtc_frame_event: stores crtc frame event for crtc processing
129 * @work: base work structure
130 * @crtc: Pointer to crtc handling this event
131 * @list: event list
132 * @ts: timestamp at queue entry
133 * @event: event identifier
134 */
135struct sde_crtc_frame_event {
136 struct kthread_work work;
137 struct drm_crtc *crtc;
138 struct list_head list;
139 ktime_t ts;
140 u32 event;
141};
142
143/**
Clarence Ipa18d4832017-03-13 12:35:44 -0700144 * struct sde_crtc_event - event callback tracking structure
145 * @list: Linked list tracking node
146 * @kt_work: Kthread worker structure
147 * @sde_crtc: Pointer to associated sde_crtc structure
148 * @cb_func: Pointer to callback function
149 * @usr: Pointer to user data to be provided to the callback
150 */
151struct sde_crtc_event {
152 struct list_head list;
153 struct kthread_work kt_work;
154 void *sde_crtc;
155
Gopikrishnaiah Anandanb6b401f2017-03-14 16:39:49 -0700156 void (*cb_func)(struct drm_crtc *crtc, void *usr);
Clarence Ipa18d4832017-03-13 12:35:44 -0700157 void *usr;
158};
159
160/*
161 * Maximum number of free event structures to cache
162 */
163#define SDE_CRTC_MAX_EVENT_COUNT 16
164
165/**
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400166 * struct sde_crtc - virtualized CRTC data structure
167 * @base : Base drm crtc structure
168 * @name : ASCII description of this crtc
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400169 * @num_ctls : Number of ctl paths in use
170 * @num_mixers : Number of mixers in use
Lloyd Atkinson094780d2017-04-24 17:25:08 -0400171 * @mixers_swapped: Whether the mixers have been swapped for left/right update
172 * especially in the case of DSC Merge.
Lloyd Atkinsona9d7e752017-01-17 16:31:43 -0500173 * @mixers : List of active mixers
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400174 * @event : Pointer to last received drm vblank event. If there is a
175 * pending vblank event, this will be non-null.
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400176 * @vsync_count : Running count of received vsync events
Lloyd Atkinsone5c2c0b2016-07-05 12:23:29 -0400177 * @drm_requested_vblank : Whether vblanks have been enabled in the encoder
Clarence Ip7a753bb2016-07-07 11:47:44 -0400178 * @property_info : Opaque structure for generic property support
179 * @property_defaults : Array of default values for generic property support
Dhaval Patel39323d42017-03-01 23:48:24 -0800180 * @output_fence : output release fence context
Clarence Ip8f7366c2016-07-05 12:15:26 -0400181 * @stage_cfg : H/w mixer stage configuration
182 * @debugfs_root : Parent of debugfs node
Alan Kwong07da0982016-11-04 12:57:45 -0400183 * @vblank_cb_count : count of vblank callback since last reset
Dhaval Pateld67cf4a2017-06-14 18:08:32 -0700184 * @play_count : frame count between crtc enable and disable
Alan Kwong07da0982016-11-04 12:57:45 -0400185 * @vblank_cb_time : ktime at vblank count reset
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400186 * @vblank_requested : whether the user has requested vblank events
Clarence Ip7f70ce42017-03-20 06:53:46 -0700187 * @suspend : whether or not a suspend operation is in progress
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400188 * @enabled : whether the SDE CRTC is currently enabled. updated in the
189 * commit-thread, not state-swap time which is earlier, so
190 * safe to make decisions on during VBLANK on/off work
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700191 * @feature_list : list of color processing features supported on a crtc
192 * @active_list : list of color processing features are active
193 * @dirty_list : list of color processing features are dirty
Gopikrishnaiah Anandan9ba43782017-01-31 18:23:08 -0800194 * @ad_dirty: list containing ad properties that are dirty
195 * @ad_active: list containing ad properties that are active
Dhaval Patel3fbe6bf2016-10-20 20:00:41 -0700196 * @crtc_lock : crtc lock around create, destroy and access.
Alan Kwong628d19e2016-10-31 13:50:13 -0400197 * @frame_pending : Whether or not an update is pending
198 * @frame_events : static allocation of in-flight frame events
199 * @frame_event_list : available frame event list
200 * @spin_lock : spin lock for frame event, transaction status, etc...
Dhaval Patel5023c3c2017-08-22 12:40:11 -0700201 * @retire_events : static allocation of retire fence connector
202 * @retire_event_list : available retire fence connector list
Veera Sundaram Sankaran7ee99092017-06-13 11:19:36 -0700203 * @frame_done_comp : for frame_event_done synchronization
Clarence Ipa18d4832017-03-13 12:35:44 -0700204 * @event_thread : Pointer to event handler thread
205 * @event_worker : Event worker queue
206 * @event_cache : Local cache of event worker structures
207 * @event_free_list : List of available event structures
208 * @event_lock : Spinlock around event handling code
Dhaval Patelf9245d62017-03-28 16:24:00 -0700209 * @misr_enable : boolean entry indicates misr enable/disable status.
Dhaval Patel010f5172017-08-01 22:40:09 -0700210 * @misr_frame_count : misr frame count provided by client
211 * @misr_data : store misr data before turning off the clocks.
Clarence Ipb776b532017-09-12 18:30:06 -0400212 * @sbuf_flush_mask: flush mask for inline rotator
213 * @sbuf_flush_mask_old: inline rotator flush mask for previous commit
Veera Sundaram Sankaran82916e02017-03-29 18:44:22 -0700214 * @power_event : registered power event handle
Alan Kwong751cf462017-06-08 10:26:46 -0400215 * @cur_perf : current performance committed to clock/bandwidth driver
Alan Kwong310e9b02017-08-03 02:04:07 -0400216 * @rp_lock : serialization lock for resource pool
217 * @rp_head : list of active resource pool
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530218 * @scl3_cfg_lut : qseed3 lut config
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400219 */
220struct sde_crtc {
221 struct drm_crtc base;
Clarence Ip8f7366c2016-07-05 12:15:26 -0400222 char name[SDE_CRTC_NAME_SIZE];
Lloyd Atkinson11f34442016-08-11 11:19:52 -0400223
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400224 /* HW Resources reserved for the crtc */
Lloyd Atkinsonc44a52e2016-08-16 16:40:17 -0400225 u32 num_ctls;
226 u32 num_mixers;
Lloyd Atkinson094780d2017-04-24 17:25:08 -0400227 bool mixers_swapped;
Lloyd Atkinsone7bcdd22016-08-11 10:53:37 -0400228 struct sde_crtc_mixer mixers[CRTC_DUAL_MIXERS];
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530229 struct sde_hw_scaler3_lut_cfg *scl3_lut_cfg;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400230
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400231 struct drm_pending_vblank_event *event;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400232 u32 vsync_count;
Clarence Ip8f7366c2016-07-05 12:15:26 -0400233
Clarence Ip7a753bb2016-07-07 11:47:44 -0400234 struct msm_property_info property_info;
235 struct msm_property_data property_data[CRTC_PROP_COUNT];
Dhaval Patele4a5dda2016-10-13 19:29:30 -0700236 struct drm_property_blob *blob_info;
Clarence Ip7a753bb2016-07-07 11:47:44 -0400237
Clarence Ip24f80662016-06-13 19:05:32 -0400238 /* output fence support */
Dhaval Patel39323d42017-03-01 23:48:24 -0800239 struct sde_fence_context output_fence;
Clarence Ip24f80662016-06-13 19:05:32 -0400240
Clarence Ip8f7366c2016-07-05 12:15:26 -0400241 struct sde_hw_stage_cfg stage_cfg;
242 struct dentry *debugfs_root;
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700243
Alan Kwong07da0982016-11-04 12:57:45 -0400244 u32 vblank_cb_count;
Dhaval Pateld67cf4a2017-06-14 18:08:32 -0700245 u64 play_count;
Alan Kwong07da0982016-11-04 12:57:45 -0400246 ktime_t vblank_cb_time;
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400247 bool vblank_requested;
Clarence Ip7f70ce42017-03-20 06:53:46 -0700248 bool suspend;
Lloyd Atkinsondcb1c4a2017-07-27 10:52:09 -0400249 bool enabled;
Alan Kwong07da0982016-11-04 12:57:45 -0400250
Gopikrishnaiah Anandane0e5e0c2016-05-25 11:05:33 -0700251 struct list_head feature_list;
252 struct list_head active_list;
253 struct list_head dirty_list;
Gopikrishnaiah Anandan9ba43782017-01-31 18:23:08 -0800254 struct list_head ad_dirty;
255 struct list_head ad_active;
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700256 struct list_head user_event_list;
Dhaval Patel3fbe6bf2016-10-20 20:00:41 -0700257
258 struct mutex crtc_lock;
Xu Yang1b3a5d92017-09-13 11:37:54 +0800259 struct mutex crtc_cp_lock;
Alan Kwong628d19e2016-10-31 13:50:13 -0400260
261 atomic_t frame_pending;
262 struct sde_crtc_frame_event frame_events[SDE_CRTC_FRAME_EVENT_SIZE];
263 struct list_head frame_event_list;
264 spinlock_t spin_lock;
Dhaval Patel5023c3c2017-08-22 12:40:11 -0700265 struct sde_crtc_retire_event retire_events[SDE_CRTC_FRAME_EVENT_SIZE];
266 struct list_head retire_event_list;
Veera Sundaram Sankaran7ee99092017-06-13 11:19:36 -0700267 struct completion frame_done_comp;
Clarence Ipa18d4832017-03-13 12:35:44 -0700268
269 /* for handling internal event thread */
Clarence Ipa18d4832017-03-13 12:35:44 -0700270 struct sde_crtc_event event_cache[SDE_CRTC_MAX_EVENT_COUNT];
271 struct list_head event_free_list;
272 spinlock_t event_lock;
Dhaval Patelf9245d62017-03-28 16:24:00 -0700273 bool misr_enable;
Dhaval Patel010f5172017-08-01 22:40:09 -0700274 u32 misr_frame_count;
275 u32 misr_data[CRTC_DUAL_MIXERS];
Veera Sundaram Sankaran82916e02017-03-29 18:44:22 -0700276
Clarence Ipb776b532017-09-12 18:30:06 -0400277 u32 sbuf_flush_mask;
278 u32 sbuf_flush_mask_old;
279
Veera Sundaram Sankaran82916e02017-03-29 18:44:22 -0700280 struct sde_power_event *power_event;
Alan Kwong751cf462017-06-08 10:26:46 -0400281
282 struct sde_core_perf_params cur_perf;
Alan Kwong310e9b02017-08-03 02:04:07 -0400283
284 struct mutex rp_lock;
285 struct list_head rp_head;
Abhijit Kulkarni1b3340c2017-06-22 12:39:37 -0700286
287 struct sde_crtc_smmu_state_data smmu_state;
Xu Yang5e53c2e2017-07-11 16:46:28 +0800288
289 /* blob for histogram data */
290 struct drm_property_blob *hist_blob;
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400291};
292
293#define to_sde_crtc(x) container_of(x, struct sde_crtc, base)
294
Clarence Ip7a753bb2016-07-07 11:47:44 -0400295/**
Alan Kwongcdb2f282017-03-18 13:42:06 -0700296 * struct sde_crtc_res_ops - common operations for crtc resources
297 * @get: get given resource
298 * @put: put given resource
299 */
300struct sde_crtc_res_ops {
301 void *(*get)(void *val, u32 type, u64 tag);
302 void (*put)(void *val);
303};
304
305/* crtc resource type (0x0-0xffff reserved for hw block type */
306#define SDE_CRTC_RES_ROT_OUT_FBO 0x10000
307#define SDE_CRTC_RES_ROT_OUT_FB 0x10001
308#define SDE_CRTC_RES_ROT_PLANE 0x10002
309#define SDE_CRTC_RES_ROT_IN_FB 0x10003
310
311#define SDE_CRTC_RES_FLAG_FREE BIT(0)
312
313/**
314 * struct sde_crtc_res - definition of crtc resources
315 * @list: list of crtc resource
316 * @type: crtc resource type
317 * @tag: unique identifier per type
318 * @refcount: reference/usage count
319 * @ops: callback operations
320 * @val: resource handle associated with type/tag
321 * @flags: customization flags
322 */
323struct sde_crtc_res {
324 struct list_head list;
325 u32 type;
326 u64 tag;
327 atomic_t refcount;
328 struct sde_crtc_res_ops ops;
329 void *val;
330 u32 flags;
331};
332
333/**
334 * sde_crtc_respool - crtc resource pool
Alan Kwong310e9b02017-08-03 02:04:07 -0400335 * @rp_lock: pointer to serialization lock
336 * @rp_head: pointer to head of active resource pools of this crtc
337 * @rp_list: list of crtc resource pool
Alan Kwongcdb2f282017-03-18 13:42:06 -0700338 * @sequence_id: sequence identifier, incremented per state duplication
339 * @res_list: list of resource managed by this resource pool
340 * @ops: resource operations for parent resource pool
341 */
342struct sde_crtc_respool {
Alan Kwong310e9b02017-08-03 02:04:07 -0400343 struct mutex *rp_lock;
344 struct list_head *rp_head;
345 struct list_head rp_list;
Alan Kwongcdb2f282017-03-18 13:42:06 -0700346 u32 sequence_id;
347 struct list_head res_list;
348 struct sde_crtc_res_ops ops;
349};
350
351/**
Clarence Ip7a753bb2016-07-07 11:47:44 -0400352 * struct sde_crtc_state - sde container for atomic crtc state
353 * @base: Base drm crtc state structure
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400354 * @connectors : Currently associated drm connectors
355 * @num_connectors: Number of associated drm connectors
Dhaval Patel4d424602017-02-18 19:40:14 -0800356 * @rsc_client : sde rsc client when mode is valid
Lloyd Atkinson66e7dde2017-02-08 15:52:53 -0500357 * @is_ppsplit : Whether current topology requires PPSplit special handling
Alan Kwong0230a102017-05-16 11:36:44 -0700358 * @bw_control : true if bw/clk controlled by core bw/clk properties
359 * @bw_split_vote : true if bw controlled by llcc/dram bw properties
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400360 * @crtc_roi : Current CRTC ROI. Possibly sub-rectangle of mode.
361 * Origin top left of CRTC.
Lloyd Atkinson73fb8092017-02-08 16:02:55 -0500362 * @lm_bounds : LM boundaries based on current mode full resolution, no ROI.
363 * Origin top left of CRTC.
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400364 * @lm_roi : Current LM ROI, possibly sub-rectangle of mode.
365 * Origin top left of CRTC.
366 * @user_roi_list : List of user's requested ROIs as from set property
Clarence Ip4a2955d2017-07-04 18:04:33 -0400367 * @property_state: Local storage for msm_prop properties
Clarence Ip7a753bb2016-07-07 11:47:44 -0400368 * @property_values: Current crtc property values
Clarence Ipcae1bb62016-07-07 12:07:13 -0400369 * @input_fence_timeout_ns : Cached input fence timeout, in ns
Veera Sundaram Sankaran3171ff82017-01-04 14:34:47 -0800370 * @num_dim_layers: Number of dim layers
371 * @dim_layer: Dim layer configs
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530372 * @num_ds: Number of destination scalers to be configured
373 * @num_ds_enabled: Number of destination scalers enabled
374 * @ds_dirty: Boolean to indicate if dirty or not
375 * @ds_cfg: Destination scaler config
Alan Kwong751cf462017-06-08 10:26:46 -0400376 * @new_perf: new performance state being requested
Alan Kwong4dd64c82017-02-04 18:41:51 -0800377 * @sbuf_cfg: stream buffer configuration
Alan Kwong4aacd532017-02-04 18:51:33 -0800378 * @sbuf_prefill_line: number of line for inline rotator prefetch
Clarence Ip7a753bb2016-07-07 11:47:44 -0400379 */
380struct sde_crtc_state {
381 struct drm_crtc_state base;
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400382
383 struct drm_connector *connectors[MAX_CONNECTORS];
384 int num_connectors;
Dhaval Patel4d424602017-02-18 19:40:14 -0800385 struct sde_rsc_client *rsc_client;
Dhaval Patel82c8dbc2017-02-18 23:15:10 -0800386 bool rsc_update;
Alan Kwongff30f4a2017-05-23 12:02:00 -0700387 bool bw_control;
Alan Kwong0230a102017-05-16 11:36:44 -0700388 bool bw_split_vote;
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400389
Lloyd Atkinson66e7dde2017-02-08 15:52:53 -0500390 bool is_ppsplit;
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400391 struct sde_rect crtc_roi;
Lloyd Atkinson73fb8092017-02-08 16:02:55 -0500392 struct sde_rect lm_bounds[CRTC_DUAL_MIXERS];
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400393 struct sde_rect lm_roi[CRTC_DUAL_MIXERS];
394 struct msm_roi_list user_roi_list;
Lloyd Atkinsona9d7e752017-01-17 16:31:43 -0500395
Clarence Ip4a2955d2017-07-04 18:04:33 -0400396 struct msm_property_state property_state;
397 struct msm_property_value property_values[CRTC_PROP_COUNT];
Clarence Ipcae1bb62016-07-07 12:07:13 -0400398 uint64_t input_fence_timeout_ns;
Veera Sundaram Sankaran3171ff82017-01-04 14:34:47 -0800399 uint32_t num_dim_layers;
400 struct sde_hw_dim_layer dim_layer[SDE_MAX_DIM_LAYERS];
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530401 uint32_t num_ds;
402 uint32_t num_ds_enabled;
403 bool ds_dirty;
404 struct sde_hw_ds_cfg ds_cfg[SDE_MAX_DS_COUNT];
Alan Kwong9aa061c2016-11-06 21:17:12 -0500405
Alan Kwong9aa061c2016-11-06 21:17:12 -0500406 struct sde_core_perf_params new_perf;
Alan Kwong4dd64c82017-02-04 18:41:51 -0800407 struct sde_ctl_sbuf_cfg sbuf_cfg;
Clarence Ip7eb90452017-05-23 11:41:19 -0400408 u32 sbuf_prefill_line;
Alan Kwongcdb2f282017-03-18 13:42:06 -0700409
410 struct sde_crtc_respool rp;
Clarence Ip7a753bb2016-07-07 11:47:44 -0400411};
412
Xu Yang5e53c2e2017-07-11 16:46:28 +0800413enum sde_crtc_irq_state {
414 IRQ_NOINIT,
415 IRQ_ENABLED,
416 IRQ_DISABLED,
417};
418
419/**
420 * sde_crtc_irq_info - crtc interrupt info
421 * @irq: interrupt callback
422 * @event: event type of the interrupt
423 * @func: function pointer to enable/disable the interrupt
424 * @list: list of user customized event in crtc
425 * @ref_count: reference count for the interrupt
426 */
427struct sde_crtc_irq_info {
428 struct sde_irq_callback irq;
429 u32 event;
430 int (*func)(struct drm_crtc *crtc, bool en,
431 struct sde_irq_callback *irq);
432 struct list_head list;
433 enum sde_crtc_irq_state state;
434};
435
Clarence Ip7a753bb2016-07-07 11:47:44 -0400436#define to_sde_crtc_state(x) \
437 container_of(x, struct sde_crtc_state, base)
438
439/**
440 * sde_crtc_get_property - query integer value of crtc property
441 * @S: Pointer to crtc state
442 * @X: Property index, from enum msm_mdp_crtc_property
443 * Returns: Integer value of requested property
444 */
445#define sde_crtc_get_property(S, X) \
Clarence Ip4a2955d2017-07-04 18:04:33 -0400446 ((S) && ((X) < CRTC_PROP_COUNT) ? ((S)->property_values[(X)].value) : 0)
Clarence Ip7a753bb2016-07-07 11:47:44 -0400447
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530448/**
449 * sde_crtc_get_mixer_width - get the mixer width
450 * Mixer width will be same as panel width(/2 for split)
451 * unless destination scaler feature is enabled
452 */
453static inline int sde_crtc_get_mixer_width(struct sde_crtc *sde_crtc,
454 struct sde_crtc_state *cstate, struct drm_display_mode *mode)
Dhaval Patel48c76022016-09-01 17:51:23 -0700455{
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530456 u32 mixer_width;
457
458 if (!sde_crtc || !cstate || !mode)
Dhaval Patel48c76022016-09-01 17:51:23 -0700459 return 0;
460
Sravanthi Kollukuduruc7bcde92017-06-16 12:44:39 +0530461 if (cstate->num_ds_enabled)
462 mixer_width = cstate->ds_cfg[0].lm_width;
463 else
464 mixer_width = (sde_crtc->num_mixers == CRTC_DUAL_MIXERS ?
465 mode->hdisplay / CRTC_DUAL_MIXERS : mode->hdisplay);
466
467 return mixer_width;
468}
469
470/**
471 * sde_crtc_get_mixer_height - get the mixer height
472 * Mixer height will be same as panel height unless
473 * destination scaler feature is enabled
474 */
475static inline int sde_crtc_get_mixer_height(struct sde_crtc *sde_crtc,
476 struct sde_crtc_state *cstate, struct drm_display_mode *mode)
477{
478 if (!sde_crtc || !cstate || !mode)
479 return 0;
480
481 return (cstate->num_ds_enabled ?
482 cstate->ds_cfg[0].lm_height : mode->vdisplay);
Dhaval Patel48c76022016-09-01 17:51:23 -0700483}
484
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400485/**
Veera Sundaram Sankaranc9efbec2017-03-29 18:59:05 -0700486 * sde_crtc_frame_pending - retun the number of pending frames
487 * @crtc: Pointer to drm crtc object
488 */
489static inline int sde_crtc_frame_pending(struct drm_crtc *crtc)
490{
491 struct sde_crtc *sde_crtc;
492
493 if (!crtc)
494 return -EINVAL;
495
496 sde_crtc = to_sde_crtc(crtc);
497 return atomic_read(&sde_crtc->frame_pending);
498}
499
500/**
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400501 * sde_crtc_vblank - enable or disable vblanks for this crtc
502 * @crtc: Pointer to drm crtc object
503 * @en: true to enable vblanks, false to disable
504 */
505int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
506
507/**
508 * sde_crtc_commit_kickoff - trigger kickoff of the commit for this crtc
509 * @crtc: Pointer to drm crtc object
510 */
511void sde_crtc_commit_kickoff(struct drm_crtc *crtc);
512
513/**
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400514 * sde_crtc_prepare_commit - callback to prepare for output fences
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400515 * @crtc: Pointer to drm crtc object
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400516 * @old_state: Pointer to drm crtc old state object
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400517 */
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400518void sde_crtc_prepare_commit(struct drm_crtc *crtc,
519 struct drm_crtc_state *old_state);
520
521/**
Abhijit Kulkarni1b3340c2017-06-22 12:39:37 -0700522 * sde_crtc_complete_commit - callback signalling completion of current commit
523 * @crtc: Pointer to drm crtc object
524 * @old_state: Pointer to drm crtc old state object
525 */
526void sde_crtc_complete_commit(struct drm_crtc *crtc,
527 struct drm_crtc_state *old_state);
528
529/**
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400530 * sde_crtc_init - create a new crtc object
531 * @dev: sde device
532 * @plane: base plane
533 * @Return: new crtc object or error
534 */
535struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane);
536
537/**
Lloyd Atkinson9eabe7a2016-09-14 13:39:15 -0400538 * sde_crtc_cancel_pending_flip - complete flip for clients on lastclose
539 * @crtc: Pointer to drm crtc object
540 * @file: client to cancel's file handle
541 */
542void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
543
Clarence Ip0d0e96d2016-10-24 18:13:13 -0400544/**
Gopikrishnaiah Anandande2c81b2017-03-15 12:41:29 -0700545 * sde_crtc_register_custom_event - api for enabling/disabling crtc event
546 * @kms: Pointer to sde_kms
547 * @crtc_drm: Pointer to crtc object
548 * @event: Event that client is interested
549 * @en: Flag to enable/disable the event
550 */
551int sde_crtc_register_custom_event(struct sde_kms *kms,
552 struct drm_crtc *crtc_drm, u32 event, bool en);
553
554/**
555 * sde_crtc_get_intf_mode - get interface mode of the given crtc
Alan Kwong9aa061c2016-11-06 21:17:12 -0500556 * @crtc: Pointert to crtc
557 */
Alan Kwong3e985f02017-02-12 15:08:44 -0800558enum sde_intf_mode sde_crtc_get_intf_mode(struct drm_crtc *crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500559
560/**
Dhaval Patel4d424602017-02-18 19:40:14 -0800561 * sde_crtc_get_client_type - check the crtc type- rt, nrt, rsc, etc.
Alan Kwong9aa061c2016-11-06 21:17:12 -0500562 * @crtc: Pointer to crtc
563 */
Dhaval Patel82c8dbc2017-02-18 23:15:10 -0800564static inline enum sde_crtc_client_type sde_crtc_get_client_type(
565 struct drm_crtc *crtc)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500566{
567 struct sde_crtc_state *cstate =
568 crtc ? to_sde_crtc_state(crtc->state) : NULL;
569
Dhaval Patel82c8dbc2017-02-18 23:15:10 -0800570 if (!cstate)
571 return NRT_CLIENT;
572
Alan Kwongfcb57432017-09-14 17:48:11 -0400573 return sde_crtc_get_intf_mode(crtc) == INTF_MODE_WB_LINE ? NRT_CLIENT :
574 (cstate->rsc_client ? RT_RSC_CLIENT : RT_CLIENT);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500575}
576
577/**
578 * sde_crtc_is_enabled - check if sde crtc is enabled or not
579 * @crtc: Pointer to crtc
580 */
581static inline bool sde_crtc_is_enabled(struct drm_crtc *crtc)
582{
583 return crtc ? crtc->enabled : false;
584}
585
Clarence Ipa18d4832017-03-13 12:35:44 -0700586/**
Alan Kwong56f1a942017-04-04 11:53:42 -0700587 * sde_crtc_get_inline_prefill - get current inline rotation prefill
588 * @crtc: Pointer to crtc
589 * return: number of prefill lines
590 */
591static inline u32 sde_crtc_get_inline_prefill(struct drm_crtc *crtc)
592{
Clarence Ip7eb90452017-05-23 11:41:19 -0400593 struct sde_crtc_state *cstate;
594
Alan Kwong56f1a942017-04-04 11:53:42 -0700595 if (!crtc || !crtc->state)
596 return 0;
597
Clarence Ip7eb90452017-05-23 11:41:19 -0400598 cstate = to_sde_crtc_state(crtc->state);
599 return cstate->sbuf_cfg.rot_op_mode != SDE_CTL_ROT_OP_MODE_OFFLINE ?
600 cstate->sbuf_prefill_line : 0;
Alan Kwong56f1a942017-04-04 11:53:42 -0700601}
602
603/**
Veera Sundaram Sankarandb43e282017-09-19 18:32:52 -0700604 * sde_crtc_is_reset_required - validate the reset request based on the
605 * pm_suspend and crtc's active status. crtc's are left active
606 * on pm_suspend during LP1/LP2 states, as the display is still
607 * left ON. Avoid reset for the subsequent pm_resume in such cases.
608 * @crtc: Pointer to crtc
609 * return: false if in suspend state and crtc active, true otherwise
610 */
611static inline bool sde_crtc_is_reset_required(struct drm_crtc *crtc)
612{
613 /*
614 * reset is required even when there is no crtc_state as it is required
615 * to create the initial state object
616 */
617 if (!crtc || !crtc->state)
618 return true;
619
620 /* reset not required if crtc is active during suspend state */
621 if (sde_kms_is_suspend_state(crtc->dev) && crtc->state->active)
622 return false;
623
624 return true;
625}
626
627/**
Clarence Ipa18d4832017-03-13 12:35:44 -0700628 * sde_crtc_event_queue - request event callback
629 * @crtc: Pointer to drm crtc structure
630 * @func: Pointer to callback function
631 * @usr: Pointer to user data to be passed to callback
632 * Returns: Zero on success
633 */
634int sde_crtc_event_queue(struct drm_crtc *crtc,
Gopikrishnaiah Anandanb6b401f2017-03-14 16:39:49 -0700635 void (*func)(struct drm_crtc *crtc, void *usr), void *usr);
Clarence Ipa18d4832017-03-13 12:35:44 -0700636
Alan Kwongcdb2f282017-03-18 13:42:06 -0700637/**
638 * sde_crtc_res_add - add given resource to resource pool in crtc state
639 * @state: Pointer to drm crtc state
640 * @type: Resource type
641 * @tag: Search tag for given resource
642 * @val: Resource handle
643 * @ops: Resource callback operations
644 * return: 0 if success; error code otherwise
645 */
646int sde_crtc_res_add(struct drm_crtc_state *state, u32 type, u64 tag,
647 void *val, struct sde_crtc_res_ops *ops);
648
649/**
650 * sde_crtc_res_get - get given resource from resource pool in crtc state
651 * @state: Pointer to drm crtc state
652 * @type: Resource type
653 * @tag: Search tag for given resource
654 * return: Resource handle if success; pointer error or null otherwise
655 */
656void *sde_crtc_res_get(struct drm_crtc_state *state, u32 type, u64 tag);
657
658/**
659 * sde_crtc_res_put - return given resource to resource pool in crtc state
660 * @state: Pointer to drm crtc state
661 * @type: Resource type
662 * @tag: Search tag for given resource
663 * return: None
664 */
665void sde_crtc_res_put(struct drm_crtc_state *state, u32 type, u64 tag);
666
Lloyd Atkinson8ba47032017-03-22 17:13:32 -0400667/**
668 * sde_crtc_get_crtc_roi - retrieve the crtc_roi from the given state object
669 * used to allow the planes to adjust their final lm out_xy value in the
670 * case of partial update
671 * @crtc_state: Pointer to crtc state
672 * @crtc_roi: Output pointer to crtc roi in the given state
673 */
674void sde_crtc_get_crtc_roi(struct drm_crtc_state *state,
675 const struct sde_rect **crtc_roi);
676
Abhijit Kulkarni7444a7d2017-06-21 18:53:36 -0700677/** sde_crt_get_secure_level - retrieve the secure level from the give state
678 * object, this is used to determine the secure state of the crtc
679 * @crtc : Pointer to drm crtc structure
680 * @usr: Pointer to drm crtc state
681 * return: secure_level
682 */
683static inline int sde_crtc_get_secure_level(struct drm_crtc *crtc,
684 struct drm_crtc_state *state)
685{
686 if (!crtc || !state)
687 return -EINVAL;
688
689 return sde_crtc_get_property(to_sde_crtc_state(state),
690 CRTC_PROP_SECURITY_LEVEL);
691}
692
Abhijit Kulkarni1b3340c2017-06-22 12:39:37 -0700693/**
694 * sde_crtc_get_secure_transition - determines the operations to be
695 * performed before transitioning to secure state
696 * This function should be called after swapping the new state
697 * @crtc: Pointer to drm crtc structure
698 * @old_crtc_state: Poniter to previous CRTC state
699 * Returns the bitmask of operations need to be performed, -Error in
700 * case of error cases
701 */
702int sde_crtc_get_secure_transition_ops(struct drm_crtc *crtc,
703 struct drm_crtc_state *old_crtc_state,
704 bool old_valid_fb);
705
706/**
707 * sde_crtc_secure_ctrl - Initiates the transition between secure and
708 * non-secure world
709 * @crtc: Pointer to crtc
710 * @post_commit: if this operation is triggered after commit
711 */
712int sde_crtc_secure_ctrl(struct drm_crtc *crtc, bool post_commit);
Abhijit Kulkarni7444a7d2017-06-21 18:53:36 -0700713
Abhijit Kulkarni40e38162016-06-26 22:12:09 -0400714#endif /* _SDE_CRTC_H_ */