Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014-2017 The Linux Foundation. All rights reserved. |
| 3 | * Copyright (C) 2013 Red Hat |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 5 | * |
Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 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. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 9 | * |
Dhaval Patel | 14d46ce | 2017-01-17 16:28:12 -0800 | [diff] [blame] | 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/>. |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 19 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 20 | #include <linux/sort.h> |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 22 | #include <linux/ktime.h> |
Clarence Ip | 4c1d977 | 2016-06-26 09:35:38 -0400 | [diff] [blame] | 23 | #include <uapi/drm/sde_drm.h> |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 24 | #include <drm/drm_mode.h> |
| 25 | #include <drm/drm_crtc.h> |
| 26 | #include <drm/drm_crtc_helper.h> |
| 27 | #include <drm/drm_flip_work.h> |
| 28 | |
| 29 | #include "sde_kms.h" |
| 30 | #include "sde_hw_lm.h" |
Clarence Ip | c475b08 | 2016-06-26 09:27:23 -0400 | [diff] [blame] | 31 | #include "sde_hw_ctl.h" |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 32 | #include "sde_crtc.h" |
Alan Kwong | 83285fb | 2016-10-21 20:51:17 -0400 | [diff] [blame] | 33 | #include "sde_plane.h" |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 34 | #include "sde_color_processing.h" |
Alan Kwong | 83285fb | 2016-10-21 20:51:17 -0400 | [diff] [blame] | 35 | #include "sde_encoder.h" |
| 36 | #include "sde_connector.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 37 | #include "sde_power_handle.h" |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 38 | #include "sde_core_perf.h" |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 39 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 40 | /* default input fence timeout, in ms */ |
| 41 | #define SDE_CRTC_INPUT_FENCE_TIMEOUT 2000 |
| 42 | |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 43 | /* |
| 44 | * The default input fence timeout is 2 seconds while max allowed |
| 45 | * range is 10 seconds. Any value above 10 seconds adds glitches beyond |
| 46 | * tolerance limit. |
| 47 | */ |
| 48 | #define SDE_CRTC_MAX_INPUT_FENCE_TIMEOUT 10000 |
| 49 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 50 | /* layer mixer index on sde_crtc */ |
| 51 | #define LEFT_MIXER 0 |
| 52 | #define RIGHT_MIXER 1 |
| 53 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 54 | static inline struct sde_kms *_sde_crtc_get_kms(struct drm_crtc *crtc) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 55 | { |
| 56 | struct msm_drm_private *priv = crtc->dev->dev_private; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 57 | |
Ben Chan | 78647cd | 2016-06-26 22:02:47 -0400 | [diff] [blame] | 58 | return to_sde_kms(priv->kms); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 59 | } |
| 60 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 61 | static void sde_crtc_destroy(struct drm_crtc *crtc) |
| 62 | { |
| 63 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 64 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 65 | SDE_DEBUG("\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 66 | |
| 67 | if (!crtc) |
| 68 | return; |
| 69 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 70 | if (sde_crtc->blob_info) |
| 71 | drm_property_unreference_blob(sde_crtc->blob_info); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 72 | msm_property_destroy(&sde_crtc->property_info); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 73 | sde_cp_crtc_destroy_properties(crtc); |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 74 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 75 | debugfs_remove_recursive(sde_crtc->debugfs_root); |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 76 | mutex_destroy(&sde_crtc->crtc_lock); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 77 | sde_fence_deinit(&sde_crtc->output_fence); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 78 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 79 | drm_crtc_cleanup(crtc); |
| 80 | kfree(sde_crtc); |
| 81 | } |
| 82 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 83 | static bool sde_crtc_mode_fixup(struct drm_crtc *crtc, |
| 84 | const struct drm_display_mode *mode, |
| 85 | struct drm_display_mode *adjusted_mode) |
| 86 | { |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 87 | SDE_DEBUG("\n"); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 88 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 89 | if (msm_is_mode_seamless(adjusted_mode) && |
| 90 | (!crtc->enabled || crtc->state->active_changed)) { |
| 91 | SDE_ERROR("crtc state prevents seamless transition\n"); |
| 92 | return false; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 93 | } |
| 94 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 95 | return true; |
| 96 | } |
| 97 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 98 | static void _sde_crtc_setup_blend_cfg(struct sde_crtc_mixer *mixer, |
| 99 | struct sde_plane_state *pstate, struct sde_format *format) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 100 | { |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 101 | uint32_t blend_op, fg_alpha, bg_alpha; |
| 102 | uint32_t blend_type; |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 103 | struct sde_hw_mixer *lm = mixer->hw_lm; |
| 104 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 105 | /* default to opaque blending */ |
| 106 | fg_alpha = sde_plane_get_property(pstate, PLANE_PROP_ALPHA); |
| 107 | bg_alpha = 0xFF - fg_alpha; |
| 108 | blend_op = SDE_BLEND_FG_ALPHA_FG_CONST | SDE_BLEND_BG_ALPHA_BG_CONST; |
| 109 | blend_type = sde_plane_get_property(pstate, PLANE_PROP_BLEND_OP); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 110 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 111 | SDE_DEBUG("blend type:0x%x blend alpha:0x%x\n", blend_type, fg_alpha); |
| 112 | |
| 113 | switch (blend_type) { |
| 114 | |
| 115 | case SDE_DRM_BLEND_OP_OPAQUE: |
| 116 | blend_op = SDE_BLEND_FG_ALPHA_FG_CONST | |
| 117 | SDE_BLEND_BG_ALPHA_BG_CONST; |
| 118 | break; |
| 119 | |
| 120 | case SDE_DRM_BLEND_OP_PREMULTIPLIED: |
| 121 | if (format->alpha_enable) { |
| 122 | blend_op = SDE_BLEND_FG_ALPHA_FG_CONST | |
| 123 | SDE_BLEND_BG_ALPHA_FG_PIXEL; |
| 124 | if (fg_alpha != 0xff) { |
| 125 | bg_alpha = fg_alpha; |
| 126 | blend_op |= SDE_BLEND_BG_MOD_ALPHA | |
| 127 | SDE_BLEND_BG_INV_MOD_ALPHA; |
| 128 | } else { |
| 129 | blend_op |= SDE_BLEND_BG_INV_ALPHA; |
| 130 | } |
| 131 | } |
| 132 | break; |
| 133 | |
| 134 | case SDE_DRM_BLEND_OP_COVERAGE: |
| 135 | if (format->alpha_enable) { |
| 136 | blend_op = SDE_BLEND_FG_ALPHA_FG_PIXEL | |
| 137 | SDE_BLEND_BG_ALPHA_FG_PIXEL; |
| 138 | if (fg_alpha != 0xff) { |
| 139 | bg_alpha = fg_alpha; |
| 140 | blend_op |= SDE_BLEND_FG_MOD_ALPHA | |
| 141 | SDE_BLEND_FG_INV_MOD_ALPHA | |
| 142 | SDE_BLEND_BG_MOD_ALPHA | |
| 143 | SDE_BLEND_BG_INV_MOD_ALPHA; |
| 144 | } else { |
| 145 | blend_op |= SDE_BLEND_BG_INV_ALPHA; |
| 146 | } |
| 147 | } |
| 148 | break; |
| 149 | default: |
| 150 | /* do nothing */ |
| 151 | break; |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 152 | } |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 153 | |
| 154 | lm->ops.setup_blend_config(lm, pstate->stage, fg_alpha, |
| 155 | bg_alpha, blend_op); |
| 156 | SDE_DEBUG("format 0x%x, alpha_enable %u fg alpha:0x%x bg alpha:0x%x \"\ |
| 157 | blend_op:0x%x\n", format->base.pixel_format, |
| 158 | format->alpha_enable, fg_alpha, bg_alpha, blend_op); |
| 159 | } |
| 160 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 161 | static void _sde_crtc_setup_dim_layer_cfg(struct drm_crtc *crtc, |
| 162 | struct sde_crtc *sde_crtc, struct sde_crtc_mixer *mixer, |
| 163 | struct sde_hw_dim_layer *dim_layer) |
| 164 | { |
| 165 | struct sde_hw_mixer *lm; |
| 166 | struct sde_rect mixer_rect; |
| 167 | struct sde_hw_dim_layer split_dim_layer; |
| 168 | u32 mixer_width, mixer_height; |
| 169 | int i; |
| 170 | |
| 171 | if (!dim_layer->rect.w || !dim_layer->rect.h) { |
| 172 | SDE_DEBUG("empty dim layer\n"); |
| 173 | return; |
| 174 | } |
| 175 | |
| 176 | mixer_width = get_crtc_split_width(crtc); |
| 177 | mixer_height = get_crtc_mixer_height(crtc); |
| 178 | mixer_rect = (struct sde_rect) {0, 0, mixer_width, mixer_height}; |
| 179 | |
| 180 | split_dim_layer.stage = dim_layer->stage; |
| 181 | split_dim_layer.color_fill = dim_layer->color_fill; |
| 182 | |
| 183 | /* |
| 184 | * traverse through the layer mixers attached to crtc and find the |
| 185 | * intersecting dim layer rect in each LM and program accordingly. |
| 186 | */ |
| 187 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
| 188 | split_dim_layer.flags = dim_layer->flags; |
| 189 | mixer_rect.x = i * mixer_width; |
| 190 | |
| 191 | sde_kms_rect_intersect(&split_dim_layer.rect, &mixer_rect, |
| 192 | &dim_layer->rect); |
| 193 | if (!split_dim_layer.rect.w && !split_dim_layer.rect.h) { |
| 194 | /* |
| 195 | * no extra programming required for non-intersecting |
| 196 | * layer mixers with INCLUSIVE dim layer |
| 197 | */ |
| 198 | if (split_dim_layer.flags |
| 199 | & SDE_DRM_DIM_LAYER_INCLUSIVE) |
| 200 | continue; |
| 201 | |
| 202 | /* |
| 203 | * program the other non-intersecting layer mixers with |
| 204 | * INCLUSIVE dim layer of full size for uniformity |
| 205 | * with EXCLUSIVE dim layer config. |
| 206 | */ |
| 207 | split_dim_layer.flags &= ~SDE_DRM_DIM_LAYER_EXCLUSIVE; |
| 208 | split_dim_layer.flags |= SDE_DRM_DIM_LAYER_INCLUSIVE; |
| 209 | split_dim_layer.rect = (struct sde_rect) {0, 0, |
| 210 | mixer_width, mixer_height}; |
| 211 | |
| 212 | } else { |
| 213 | split_dim_layer.rect.x = split_dim_layer.rect.x |
| 214 | - (i * mixer_width); |
| 215 | } |
| 216 | |
| 217 | lm = mixer[i].hw_lm; |
| 218 | mixer[i].mixer_op_mode |= 1 << split_dim_layer.stage; |
| 219 | lm->ops.setup_dim_layer(lm, &split_dim_layer); |
| 220 | } |
| 221 | } |
| 222 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 223 | static void _sde_crtc_blend_setup_mixer(struct drm_crtc *crtc, |
| 224 | struct sde_crtc *sde_crtc, struct sde_crtc_mixer *mixer) |
| 225 | { |
| 226 | struct drm_plane *plane; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 227 | struct sde_crtc_state *cstate; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 228 | struct sde_plane_state *pstate = NULL; |
| 229 | struct sde_format *format; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 230 | struct sde_hw_ctl *ctl; |
| 231 | struct sde_hw_mixer *lm; |
| 232 | struct sde_hw_stage_cfg *stage_cfg; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 233 | |
| 234 | u32 flush_mask = 0, crtc_split_width; |
| 235 | uint32_t lm_idx = LEFT_MIXER, idx; |
| 236 | bool bg_alpha_enable[CRTC_DUAL_MIXERS] = {false}; |
| 237 | bool lm_right = false; |
| 238 | int left_crtc_zpos_cnt[SDE_STAGE_MAX + 1] = {0}; |
| 239 | int right_crtc_zpos_cnt[SDE_STAGE_MAX + 1] = {0}; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 240 | int i; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 241 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 242 | if (!sde_crtc || !mixer) { |
| 243 | SDE_ERROR("invalid sde_crtc or mixer\n"); |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | ctl = mixer->hw_ctl; |
| 248 | lm = mixer->hw_lm; |
| 249 | stage_cfg = &sde_crtc->stage_cfg; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 250 | crtc_split_width = get_crtc_split_width(crtc); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 251 | |
| 252 | drm_atomic_crtc_for_each_plane(plane, crtc) { |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 253 | |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 254 | pstate = to_sde_plane_state(plane->state); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 255 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 256 | flush_mask = ctl->ops.get_bitmask_sspp(ctl, |
| 257 | sde_plane_pipe(plane)); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 258 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 259 | /* always stage plane on either left or right lm */ |
| 260 | if (plane->state->crtc_x >= crtc_split_width) { |
| 261 | lm_idx = RIGHT_MIXER; |
| 262 | idx = right_crtc_zpos_cnt[pstate->stage]++; |
| 263 | } else { |
| 264 | lm_idx = LEFT_MIXER; |
| 265 | idx = left_crtc_zpos_cnt[pstate->stage]++; |
| 266 | } |
| 267 | |
| 268 | /* stage plane on right LM if it crosses the boundary */ |
| 269 | lm_right = (lm_idx == LEFT_MIXER) && |
| 270 | (plane->state->crtc_x + plane->state->crtc_w > |
| 271 | crtc_split_width); |
| 272 | |
| 273 | stage_cfg->stage[lm_idx][pstate->stage][idx] = |
| 274 | sde_plane_pipe(plane); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 275 | stage_cfg->multirect_index |
| 276 | [lm_idx][pstate->stage][idx] = |
| 277 | pstate->multirect_index; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 278 | mixer[lm_idx].flush_mask |= flush_mask; |
| 279 | |
| 280 | SDE_DEBUG("crtc %d stage:%d - plane %d sspp %d fb %d\n", |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 281 | crtc->base.id, |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 282 | pstate->stage, |
| 283 | plane->base.id, |
| 284 | sde_plane_pipe(plane) - SSPP_VIG0, |
| 285 | plane->state->fb ? |
| 286 | plane->state->fb->base.id : -1); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 287 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 288 | format = to_sde_format(msm_framebuffer_format(pstate->base.fb)); |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 289 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 290 | /* blend config update */ |
| 291 | if (pstate->stage != SDE_STAGE_BASE) { |
| 292 | _sde_crtc_setup_blend_cfg(mixer + lm_idx, pstate, |
| 293 | format); |
| 294 | |
| 295 | if (bg_alpha_enable[lm_idx] && !format->alpha_enable) |
| 296 | mixer[lm_idx].mixer_op_mode = 0; |
| 297 | else |
| 298 | mixer[lm_idx].mixer_op_mode |= |
| 299 | 1 << pstate->stage; |
| 300 | } else if (format->alpha_enable) { |
| 301 | bg_alpha_enable[lm_idx] = true; |
| 302 | } |
| 303 | |
| 304 | if (lm_right) { |
| 305 | idx = right_crtc_zpos_cnt[pstate->stage]++; |
| 306 | stage_cfg->stage[RIGHT_MIXER][pstate->stage][idx] = |
| 307 | sde_plane_pipe(plane); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 308 | stage_cfg->multirect_index |
| 309 | [RIGHT_MIXER][pstate->stage][idx] = |
| 310 | pstate->multirect_index; |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 311 | mixer[RIGHT_MIXER].flush_mask |= flush_mask; |
| 312 | |
| 313 | /* blend config update */ |
| 314 | if (pstate->stage != SDE_STAGE_BASE) { |
| 315 | _sde_crtc_setup_blend_cfg(mixer + RIGHT_MIXER, |
| 316 | pstate, format); |
| 317 | |
| 318 | if (bg_alpha_enable[RIGHT_MIXER] && |
| 319 | !format->alpha_enable) |
| 320 | mixer[RIGHT_MIXER].mixer_op_mode = 0; |
| 321 | else |
| 322 | mixer[RIGHT_MIXER].mixer_op_mode |= |
| 323 | 1 << pstate->stage; |
| 324 | } else if (format->alpha_enable) { |
| 325 | bg_alpha_enable[RIGHT_MIXER] = true; |
| 326 | } |
| 327 | } |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 328 | } |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 329 | |
| 330 | if (lm && lm->ops.setup_dim_layer) { |
| 331 | cstate = to_sde_crtc_state(crtc->state); |
| 332 | for (i = 0; i < cstate->num_dim_layers; i++) |
| 333 | _sde_crtc_setup_dim_layer_cfg(crtc, sde_crtc, |
| 334 | mixer, &cstate->dim_layer[i]); |
| 335 | } |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 338 | /** |
| 339 | * _sde_crtc_blend_setup - configure crtc mixers |
| 340 | * @crtc: Pointer to drm crtc structure |
| 341 | */ |
| 342 | static void _sde_crtc_blend_setup(struct drm_crtc *crtc) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 343 | { |
| 344 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 345 | struct sde_crtc_mixer *mixer = sde_crtc->mixers; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 346 | struct sde_hw_ctl *ctl; |
| 347 | struct sde_hw_mixer *lm; |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 348 | |
| 349 | int i; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 350 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 351 | SDE_DEBUG("%s\n", sde_crtc->name); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 352 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 353 | if (sde_crtc->num_mixers > CRTC_DUAL_MIXERS) { |
| 354 | SDE_ERROR("invalid number mixers: %d\n", sde_crtc->num_mixers); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
| 359 | if (!mixer[i].hw_lm || !mixer[i].hw_ctl) { |
| 360 | SDE_ERROR("invalid lm or ctl assigned to mixer\n"); |
| 361 | return; |
| 362 | } |
| 363 | mixer[i].mixer_op_mode = 0; |
| 364 | mixer[i].flush_mask = 0; |
Lloyd Atkinson | e5ec30d | 2016-08-23 14:32:32 -0400 | [diff] [blame] | 365 | if (mixer[i].hw_ctl->ops.clear_all_blendstages) |
| 366 | mixer[i].hw_ctl->ops.clear_all_blendstages( |
| 367 | mixer[i].hw_ctl); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 368 | |
| 369 | /* clear dim_layer settings */ |
| 370 | lm = mixer[i].hw_lm; |
| 371 | if (lm->ops.clear_dim_layer) |
| 372 | lm->ops.clear_dim_layer(lm); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 375 | /* initialize stage cfg */ |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 376 | memset(&sde_crtc->stage_cfg, 0, sizeof(struct sde_hw_stage_cfg)); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 377 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 378 | _sde_crtc_blend_setup_mixer(crtc, sde_crtc, mixer); |
| 379 | |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 380 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 381 | ctl = mixer[i].hw_ctl; |
| 382 | lm = mixer[i].hw_lm; |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 383 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 384 | lm->ops.setup_alpha_out(lm, mixer[i].mixer_op_mode); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 385 | |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 386 | mixer[i].flush_mask |= ctl->ops.get_bitmask_mixer(ctl, |
Abhijit Kulkarni | 71002ba | 2016-06-24 18:36:28 -0400 | [diff] [blame] | 387 | mixer[i].hw_lm->idx); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 388 | |
| 389 | /* stage config flush mask */ |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 390 | ctl->ops.update_pending_flush(ctl, mixer[i].flush_mask); |
| 391 | |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 392 | SDE_DEBUG("lm %d, op_mode 0x%X, ctl %d, flush mask 0x%x\n", |
| 393 | mixer[i].hw_lm->idx - LM_0, |
| 394 | mixer[i].mixer_op_mode, |
| 395 | ctl->idx - CTL_0, |
| 396 | mixer[i].flush_mask); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 397 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 398 | ctl->ops.setup_blendstage(ctl, mixer[i].hw_lm->idx, |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 399 | &sde_crtc->stage_cfg, i); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 400 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 403 | void sde_crtc_prepare_commit(struct drm_crtc *crtc, |
| 404 | struct drm_crtc_state *old_state) |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 405 | { |
| 406 | struct sde_crtc *sde_crtc; |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 407 | struct sde_crtc_state *cstate; |
| 408 | struct drm_connector *conn; |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 409 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 410 | if (!crtc || !crtc->state) { |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 411 | SDE_ERROR("invalid crtc\n"); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | sde_crtc = to_sde_crtc(crtc); |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 416 | cstate = to_sde_crtc_state(crtc->state); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 417 | SDE_EVT32(DRMID(crtc)); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 418 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 419 | /* identify connectors attached to this crtc */ |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 420 | cstate->num_connectors = 0; |
| 421 | |
| 422 | drm_for_each_connector(conn, crtc->dev) |
| 423 | if (conn->state && conn->state->crtc == crtc && |
| 424 | cstate->num_connectors < MAX_CONNECTORS) { |
| 425 | cstate->connectors[cstate->num_connectors++] = conn; |
| 426 | sde_connector_prepare_fence(conn); |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 429 | if (cstate->num_connectors > 0 && cstate->connectors[0]->encoder) |
| 430 | cstate->intf_mode = sde_encoder_get_intf_mode( |
| 431 | cstate->connectors[0]->encoder); |
| 432 | else |
| 433 | cstate->intf_mode = INTF_MODE_NONE; |
| 434 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 435 | /* prepare main output fence */ |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 436 | sde_fence_prepare(&sde_crtc->output_fence); |
| 437 | } |
| 438 | |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 439 | /* if file!=NULL, this is preclose potential cancel-flip path */ |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 440 | static void _sde_crtc_complete_flip(struct drm_crtc *crtc, |
| 441 | struct drm_file *file) |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 442 | { |
| 443 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 444 | struct drm_device *dev = crtc->dev; |
| 445 | struct drm_pending_vblank_event *event; |
| 446 | unsigned long flags; |
| 447 | |
| 448 | spin_lock_irqsave(&dev->event_lock, flags); |
| 449 | event = sde_crtc->event; |
| 450 | if (event) { |
| 451 | /* if regular vblank case (!file) or if cancel-flip from |
| 452 | * preclose on file that requested flip, then send the |
| 453 | * event: |
| 454 | */ |
| 455 | if (!file || (event->base.file_priv == file)) { |
| 456 | sde_crtc->event = NULL; |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 457 | DRM_DEBUG_VBL("%s: send event: %pK\n", |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 458 | sde_crtc->name, event); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 459 | SDE_EVT32(DRMID(crtc)); |
Lloyd Atkinson | ac93364 | 2016-09-14 11:52:00 -0400 | [diff] [blame] | 460 | drm_crtc_send_vblank_event(crtc, event); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 464 | } |
| 465 | |
| 466 | static void sde_crtc_vblank_cb(void *data) |
| 467 | { |
| 468 | struct drm_crtc *crtc = (struct drm_crtc *)data; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 469 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 470 | |
| 471 | /* keep statistics on vblank callback - with auto reset via debugfs */ |
| 472 | if (ktime_equal(sde_crtc->vblank_cb_time, ktime_set(0, 0))) |
| 473 | sde_crtc->vblank_cb_time = ktime_get(); |
| 474 | else |
| 475 | sde_crtc->vblank_cb_count++; |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 476 | |
Lloyd Atkinson | ac93364 | 2016-09-14 11:52:00 -0400 | [diff] [blame] | 477 | drm_crtc_handle_vblank(crtc); |
Lloyd Atkinson | 9eabe7a | 2016-09-14 13:39:15 -0400 | [diff] [blame] | 478 | DRM_DEBUG_VBL("crtc%d\n", crtc->base.id); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 479 | SDE_EVT32_IRQ(DRMID(crtc)); |
Abhijit Kulkarni | 40e3816 | 2016-06-26 22:12:09 -0400 | [diff] [blame] | 480 | } |
| 481 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 482 | static void sde_crtc_frame_event_work(struct kthread_work *work) |
| 483 | { |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 484 | struct msm_drm_private *priv; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 485 | struct sde_crtc_frame_event *fevent; |
| 486 | struct drm_crtc *crtc; |
| 487 | struct sde_crtc *sde_crtc; |
| 488 | struct sde_kms *sde_kms; |
| 489 | unsigned long flags; |
| 490 | |
| 491 | if (!work) { |
| 492 | SDE_ERROR("invalid work handle\n"); |
| 493 | return; |
| 494 | } |
| 495 | |
| 496 | fevent = container_of(work, struct sde_crtc_frame_event, work); |
| 497 | if (!fevent->crtc) { |
| 498 | SDE_ERROR("invalid crtc\n"); |
| 499 | return; |
| 500 | } |
| 501 | |
| 502 | crtc = fevent->crtc; |
| 503 | sde_crtc = to_sde_crtc(crtc); |
| 504 | |
| 505 | sde_kms = _sde_crtc_get_kms(crtc); |
| 506 | if (!sde_kms) { |
| 507 | SDE_ERROR("invalid kms handle\n"); |
| 508 | return; |
| 509 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 510 | priv = sde_kms->dev->dev_private; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 511 | |
| 512 | SDE_DEBUG("crtc%d event:%u ts:%lld\n", crtc->base.id, fevent->event, |
| 513 | ktime_to_ns(fevent->ts)); |
| 514 | |
| 515 | if (fevent->event == SDE_ENCODER_FRAME_EVENT_DONE || |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 516 | (fevent->event & SDE_ENCODER_FRAME_EVENT_ERROR) || |
| 517 | (fevent->event & SDE_ENCODER_FRAME_EVENT_PANEL_DEAD)) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 518 | |
| 519 | if (atomic_read(&sde_crtc->frame_pending) < 1) { |
| 520 | /* this should not happen */ |
| 521 | SDE_ERROR("crtc%d ts:%lld invalid frame_pending:%d\n", |
| 522 | crtc->base.id, |
| 523 | ktime_to_ns(fevent->ts), |
| 524 | atomic_read(&sde_crtc->frame_pending)); |
| 525 | SDE_EVT32(DRMID(crtc), fevent->event, 0); |
| 526 | } else if (atomic_dec_return(&sde_crtc->frame_pending) == 0) { |
| 527 | /* release bandwidth and other resources */ |
| 528 | SDE_DEBUG("crtc%d ts:%lld last pending\n", |
| 529 | crtc->base.id, |
| 530 | ktime_to_ns(fevent->ts)); |
| 531 | SDE_EVT32(DRMID(crtc), fevent->event, 1); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 532 | sde_core_perf_crtc_release_bw(crtc); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 533 | } else { |
| 534 | SDE_EVT32(DRMID(crtc), fevent->event, 2); |
| 535 | } |
| 536 | } else { |
| 537 | SDE_ERROR("crtc%d ts:%lld unknown event %u\n", crtc->base.id, |
| 538 | ktime_to_ns(fevent->ts), |
| 539 | fevent->event); |
| 540 | SDE_EVT32(DRMID(crtc), fevent->event, 3); |
| 541 | } |
| 542 | |
Lloyd Atkinson | 8c49c58 | 2016-11-18 14:23:54 -0500 | [diff] [blame] | 543 | if (fevent->event & SDE_ENCODER_FRAME_EVENT_PANEL_DEAD) |
| 544 | SDE_ERROR("crtc%d ts:%lld received panel dead event\n", |
| 545 | crtc->base.id, ktime_to_ns(fevent->ts)); |
| 546 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 547 | spin_lock_irqsave(&sde_crtc->spin_lock, flags); |
| 548 | list_add_tail(&fevent->list, &sde_crtc->frame_event_list); |
| 549 | spin_unlock_irqrestore(&sde_crtc->spin_lock, flags); |
| 550 | } |
| 551 | |
| 552 | static void sde_crtc_frame_event_cb(void *data, u32 event) |
| 553 | { |
| 554 | struct drm_crtc *crtc = (struct drm_crtc *)data; |
| 555 | struct sde_crtc *sde_crtc; |
| 556 | struct msm_drm_private *priv; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 557 | struct sde_crtc_frame_event *fevent; |
| 558 | unsigned long flags; |
| 559 | int pipe_id; |
| 560 | |
| 561 | if (!crtc || !crtc->dev || !crtc->dev->dev_private) { |
| 562 | SDE_ERROR("invalid parameters\n"); |
| 563 | return; |
| 564 | } |
| 565 | sde_crtc = to_sde_crtc(crtc); |
| 566 | priv = crtc->dev->dev_private; |
| 567 | pipe_id = drm_crtc_index(crtc); |
| 568 | |
| 569 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
| 570 | |
| 571 | SDE_EVT32(DRMID(crtc), event); |
| 572 | |
| 573 | spin_lock_irqsave(&sde_crtc->spin_lock, flags); |
Lloyd Atkinson | 78831f8 | 2016-12-09 11:24:56 -0500 | [diff] [blame] | 574 | fevent = list_first_entry_or_null(&sde_crtc->frame_event_list, |
| 575 | struct sde_crtc_frame_event, list); |
| 576 | if (fevent) |
| 577 | list_del_init(&fevent->list); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 578 | spin_unlock_irqrestore(&sde_crtc->spin_lock, flags); |
| 579 | |
Lloyd Atkinson | 78831f8 | 2016-12-09 11:24:56 -0500 | [diff] [blame] | 580 | if (!fevent) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 581 | SDE_ERROR("crtc%d event %d overflow\n", |
| 582 | crtc->base.id, event); |
| 583 | SDE_EVT32(DRMID(crtc), event); |
| 584 | return; |
| 585 | } |
| 586 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 587 | fevent->event = event; |
| 588 | fevent->crtc = crtc; |
| 589 | fevent->ts = ktime_get(); |
| 590 | kthread_queue_work(&priv->disp_thread[pipe_id].worker, &fevent->work); |
| 591 | } |
| 592 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 593 | void sde_crtc_complete_commit(struct drm_crtc *crtc, |
| 594 | struct drm_crtc_state *old_state) |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 595 | { |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 596 | struct sde_crtc *sde_crtc; |
| 597 | struct sde_crtc_state *cstate; |
| 598 | int i; |
| 599 | |
| 600 | if (!crtc || !crtc->state) { |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 601 | SDE_ERROR("invalid crtc\n"); |
| 602 | return; |
| 603 | } |
| 604 | |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 605 | sde_crtc = to_sde_crtc(crtc); |
| 606 | cstate = to_sde_crtc_state(crtc->state); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 607 | SDE_EVT32(DRMID(crtc)); |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 608 | |
| 609 | /* signal output fence(s) at end of commit */ |
| 610 | sde_fence_signal(&sde_crtc->output_fence, 0); |
| 611 | |
| 612 | for (i = 0; i < cstate->num_connectors; ++i) |
| 613 | sde_connector_complete_commit(cstate->connectors[i]); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 616 | /** |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 617 | * _sde_crtc_set_input_fence_timeout - update ns version of in fence timeout |
| 618 | * @cstate: Pointer to sde crtc state |
| 619 | */ |
| 620 | static void _sde_crtc_set_input_fence_timeout(struct sde_crtc_state *cstate) |
| 621 | { |
| 622 | if (!cstate) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 623 | SDE_ERROR("invalid cstate\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 624 | return; |
| 625 | } |
| 626 | cstate->input_fence_timeout_ns = |
| 627 | sde_crtc_get_property(cstate, CRTC_PROP_INPUT_FENCE_TIMEOUT); |
| 628 | cstate->input_fence_timeout_ns *= NSEC_PER_MSEC; |
| 629 | } |
| 630 | |
| 631 | /** |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 632 | * _sde_crtc_set_dim_layer_v1 - copy dim layer settings from userspace |
| 633 | * @cstate: Pointer to sde crtc state |
| 634 | * @user_ptr: User ptr for sde_drm_dim_layer_v1 struct |
| 635 | */ |
| 636 | static void _sde_crtc_set_dim_layer_v1(struct sde_crtc_state *cstate, |
| 637 | void *usr_ptr) |
| 638 | { |
| 639 | struct sde_drm_dim_layer_v1 dim_layer_v1; |
| 640 | struct sde_drm_dim_layer_cfg *user_cfg; |
| 641 | u32 count, i; |
| 642 | |
| 643 | if (!cstate) { |
| 644 | SDE_ERROR("invalid cstate\n"); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | if (!usr_ptr) { |
| 649 | SDE_DEBUG("dim layer data removed\n"); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | if (copy_from_user(&dim_layer_v1, usr_ptr, sizeof(dim_layer_v1))) { |
| 654 | SDE_ERROR("failed to copy dim layer data\n"); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | count = dim_layer_v1.num_layers; |
| 659 | if (!count || (count > SDE_MAX_DIM_LAYERS)) { |
| 660 | SDE_ERROR("invalid number of Dim Layers:%d", count); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | /* populate from user space */ |
| 665 | cstate->num_dim_layers = count; |
| 666 | for (i = 0; i < count; i++) { |
| 667 | user_cfg = &dim_layer_v1.layer_cfg[i]; |
| 668 | cstate->dim_layer[i].flags = user_cfg->flags; |
| 669 | cstate->dim_layer[i].stage = user_cfg->stage + SDE_STAGE_0; |
| 670 | |
| 671 | cstate->dim_layer[i].rect.x = user_cfg->rect.x1; |
| 672 | cstate->dim_layer[i].rect.y = user_cfg->rect.y1; |
| 673 | cstate->dim_layer[i].rect.w = user_cfg->rect.x2 - |
| 674 | user_cfg->rect.x1 + 1; |
| 675 | cstate->dim_layer[i].rect.h = user_cfg->rect.y2 - |
| 676 | user_cfg->rect.y1 + 1; |
| 677 | |
| 678 | cstate->dim_layer[i].color_fill = (struct sde_mdss_color) { |
| 679 | user_cfg->color_fill.color_0, |
| 680 | user_cfg->color_fill.color_1, |
| 681 | user_cfg->color_fill.color_2, |
| 682 | user_cfg->color_fill.color_3, |
| 683 | }; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | /** |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 688 | * _sde_crtc_wait_for_fences - wait for incoming framebuffer sync fences |
| 689 | * @crtc: Pointer to CRTC object |
| 690 | */ |
| 691 | static void _sde_crtc_wait_for_fences(struct drm_crtc *crtc) |
| 692 | { |
| 693 | struct drm_plane *plane = NULL; |
| 694 | uint32_t wait_ms = 1; |
Clarence Ip | 8dedc23 | 2016-09-09 16:41:00 -0400 | [diff] [blame] | 695 | ktime_t kt_end, kt_wait; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 696 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 697 | SDE_DEBUG("\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 698 | |
| 699 | if (!crtc || !crtc->state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 700 | SDE_ERROR("invalid crtc/state %pK\n", crtc); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 701 | return; |
| 702 | } |
| 703 | |
| 704 | /* use monotonic timer to limit total fence wait time */ |
Clarence Ip | 8dedc23 | 2016-09-09 16:41:00 -0400 | [diff] [blame] | 705 | kt_end = ktime_add_ns(ktime_get(), |
| 706 | to_sde_crtc_state(crtc->state)->input_fence_timeout_ns); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 707 | |
| 708 | /* |
| 709 | * Wait for fences sequentially, as all of them need to be signalled |
| 710 | * before we can proceed. |
| 711 | * |
| 712 | * Limit total wait time to INPUT_FENCE_TIMEOUT, but still call |
| 713 | * sde_plane_wait_input_fence with wait_ms == 0 after the timeout so |
| 714 | * that each plane can check its fence status and react appropriately |
| 715 | * if its fence has timed out. |
| 716 | */ |
| 717 | drm_atomic_crtc_for_each_plane(plane, crtc) { |
| 718 | if (wait_ms) { |
| 719 | /* determine updated wait time */ |
Clarence Ip | 8dedc23 | 2016-09-09 16:41:00 -0400 | [diff] [blame] | 720 | kt_wait = ktime_sub(kt_end, ktime_get()); |
| 721 | if (ktime_compare(kt_wait, ktime_set(0, 0)) >= 0) |
| 722 | wait_ms = ktime_to_ms(kt_wait); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 723 | else |
| 724 | wait_ms = 0; |
| 725 | } |
| 726 | sde_plane_wait_input_fence(plane, wait_ms); |
| 727 | } |
| 728 | } |
| 729 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 730 | static void _sde_crtc_setup_mixer_for_encoder( |
| 731 | struct drm_crtc *crtc, |
| 732 | struct drm_encoder *enc) |
| 733 | { |
| 734 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 735 | struct sde_kms *sde_kms = _sde_crtc_get_kms(crtc); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 736 | struct sde_rm *rm = &sde_kms->rm; |
| 737 | struct sde_crtc_mixer *mixer; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 738 | struct sde_hw_ctl *last_valid_ctl = NULL; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 739 | int i; |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 740 | struct sde_rm_hw_iter lm_iter, ctl_iter, dspp_iter; |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 741 | |
| 742 | sde_rm_init_hw_iter(&lm_iter, enc->base.id, SDE_HW_BLK_LM); |
| 743 | sde_rm_init_hw_iter(&ctl_iter, enc->base.id, SDE_HW_BLK_CTL); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 744 | sde_rm_init_hw_iter(&dspp_iter, enc->base.id, SDE_HW_BLK_DSPP); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 745 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 746 | /* Set up all the mixers and ctls reserved by this encoder */ |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 747 | for (i = sde_crtc->num_mixers; i < ARRAY_SIZE(sde_crtc->mixers); i++) { |
| 748 | mixer = &sde_crtc->mixers[i]; |
| 749 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 750 | if (!sde_rm_get_hw(rm, &lm_iter)) |
| 751 | break; |
| 752 | mixer->hw_lm = (struct sde_hw_mixer *)lm_iter.hw; |
| 753 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 754 | /* CTL may be <= LMs, if <, multiple LMs controlled by 1 CTL */ |
| 755 | if (!sde_rm_get_hw(rm, &ctl_iter)) { |
| 756 | SDE_DEBUG("no ctl assigned to lm %d, using previous\n", |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 757 | mixer->hw_lm->idx - LM_0); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 758 | mixer->hw_ctl = last_valid_ctl; |
| 759 | } else { |
| 760 | mixer->hw_ctl = (struct sde_hw_ctl *)ctl_iter.hw; |
| 761 | last_valid_ctl = mixer->hw_ctl; |
| 762 | } |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 763 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 764 | /* Shouldn't happen, mixers are always >= ctls */ |
| 765 | if (!mixer->hw_ctl) { |
| 766 | SDE_ERROR("no valid ctls found for lm %d\n", |
Clarence Ip | 8e69ad0 | 2016-12-09 09:43:57 -0500 | [diff] [blame] | 767 | mixer->hw_lm->idx - LM_0); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 768 | return; |
| 769 | } |
| 770 | |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 771 | /* Dspp may be null */ |
| 772 | (void) sde_rm_get_hw(rm, &dspp_iter); |
| 773 | mixer->hw_dspp = (struct sde_hw_dspp *)dspp_iter.hw; |
| 774 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 775 | mixer->encoder = enc; |
| 776 | |
| 777 | sde_crtc->num_mixers++; |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 778 | SDE_DEBUG("setup mixer %d: lm %d\n", |
| 779 | i, mixer->hw_lm->idx - LM_0); |
| 780 | SDE_DEBUG("setup mixer %d: ctl %d\n", |
| 781 | i, mixer->hw_ctl->idx - CTL_0); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
| 785 | static void _sde_crtc_setup_mixers(struct drm_crtc *crtc) |
| 786 | { |
| 787 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 788 | struct drm_encoder *enc; |
| 789 | |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 790 | sde_crtc->num_mixers = 0; |
| 791 | memset(sde_crtc->mixers, 0, sizeof(sde_crtc->mixers)); |
| 792 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 793 | mutex_lock(&sde_crtc->crtc_lock); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 794 | /* Check for mixers on all encoders attached to this crtc */ |
| 795 | list_for_each_entry(enc, &crtc->dev->mode_config.encoder_list, head) { |
| 796 | if (enc->crtc != crtc) |
| 797 | continue; |
| 798 | |
| 799 | _sde_crtc_setup_mixer_for_encoder(crtc, enc); |
| 800 | } |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 801 | mutex_unlock(&sde_crtc->crtc_lock); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 802 | } |
| 803 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 804 | static void sde_crtc_atomic_begin(struct drm_crtc *crtc, |
Clarence Ip | 0d0e96d | 2016-10-24 18:13:13 -0400 | [diff] [blame] | 805 | struct drm_crtc_state *old_state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 806 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 807 | struct sde_crtc *sde_crtc; |
| 808 | struct drm_device *dev; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 809 | unsigned long flags; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 810 | u32 i; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 811 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 812 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 813 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 814 | return; |
| 815 | } |
| 816 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 817 | if (!crtc->state->enable) { |
| 818 | SDE_DEBUG("crtc%d -> enable %d, skip atomic_begin\n", |
| 819 | crtc->base.id, crtc->state->enable); |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
| 824 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 825 | sde_crtc = to_sde_crtc(crtc); |
| 826 | dev = crtc->dev; |
| 827 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 828 | if (!sde_crtc->num_mixers) |
| 829 | _sde_crtc_setup_mixers(crtc); |
Lloyd Atkinson | 11f3444 | 2016-08-11 11:19:52 -0400 | [diff] [blame] | 830 | |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 831 | if (sde_crtc->event) { |
| 832 | WARN_ON(sde_crtc->event); |
| 833 | } else { |
| 834 | spin_lock_irqsave(&dev->event_lock, flags); |
| 835 | sde_crtc->event = crtc->state->event; |
| 836 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 837 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 838 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 839 | /* Reset flush mask from previous commit */ |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 840 | for (i = 0; i < ARRAY_SIZE(sde_crtc->mixers); i++) { |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 841 | struct sde_hw_ctl *ctl = sde_crtc->mixers[i].hw_ctl; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 842 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 843 | if (ctl) |
| 844 | ctl->ops.clear_pending_flush(ctl); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 845 | } |
| 846 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 847 | /* |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 848 | * If no mixers have been allocated in sde_crtc_atomic_check(), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 849 | * it means we are trying to flush a CRTC whose state is disabled: |
| 850 | * nothing else needs to be done. |
| 851 | */ |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 852 | if (unlikely(!sde_crtc->num_mixers)) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 853 | return; |
| 854 | |
Clarence Ip | d9f9fa6 | 2016-09-09 13:42:32 -0400 | [diff] [blame] | 855 | _sde_crtc_blend_setup(crtc); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 856 | sde_cp_crtc_apply_properties(crtc); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 857 | |
| 858 | /* |
| 859 | * PP_DONE irq is only used by command mode for now. |
| 860 | * It is better to request pending before FLUSH and START trigger |
| 861 | * to make sure no pp_done irq missed. |
| 862 | * This is safe because no pp_done will happen before SW trigger |
| 863 | * in command mode. |
| 864 | */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 867 | static void sde_crtc_atomic_flush(struct drm_crtc *crtc, |
| 868 | struct drm_crtc_state *old_crtc_state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 869 | { |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 870 | struct drm_encoder *encoder; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 871 | struct sde_crtc *sde_crtc; |
| 872 | struct drm_device *dev; |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 873 | struct drm_plane *plane; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 874 | unsigned long flags; |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 875 | struct sde_crtc_state *cstate; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 876 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 877 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 878 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 879 | return; |
| 880 | } |
| 881 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 882 | if (!crtc->state->enable) { |
| 883 | SDE_DEBUG("crtc%d -> enable %d, skip atomic_flush\n", |
| 884 | crtc->base.id, crtc->state->enable); |
| 885 | return; |
| 886 | } |
| 887 | |
| 888 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 889 | |
| 890 | sde_crtc = to_sde_crtc(crtc); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 891 | cstate = to_sde_crtc_state(crtc->state); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 892 | dev = crtc->dev; |
| 893 | |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 894 | if (sde_crtc->event) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 895 | SDE_DEBUG("already received sde_crtc->event\n"); |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 896 | } else { |
Lloyd Atkinson | 265d221 | 2016-05-30 13:12:01 -0400 | [diff] [blame] | 897 | spin_lock_irqsave(&dev->event_lock, flags); |
| 898 | sde_crtc->event = crtc->state->event; |
| 899 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 900 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 901 | |
| 902 | /* |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 903 | * If no mixers has been allocated in sde_crtc_atomic_check(), |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 904 | * it means we are trying to flush a CRTC whose state is disabled: |
| 905 | * nothing else needs to be done. |
| 906 | */ |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 907 | if (unlikely(!sde_crtc->num_mixers)) |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 908 | return; |
| 909 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 910 | /* wait for acquire fences before anything else is done */ |
| 911 | _sde_crtc_wait_for_fences(crtc); |
| 912 | |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 913 | if (!cstate->rsc_update) { |
| 914 | drm_for_each_encoder(encoder, dev) { |
| 915 | if (encoder->crtc != crtc) |
| 916 | continue; |
| 917 | |
| 918 | cstate->rsc_client = |
| 919 | sde_encoder_update_rsc_client(encoder, true); |
| 920 | } |
| 921 | cstate->rsc_update = true; |
| 922 | } |
| 923 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 924 | /* update performance setting before crtc kickoff */ |
| 925 | sde_core_perf_crtc_update(crtc, 1, false); |
| 926 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 927 | /* |
| 928 | * Final plane updates: Give each plane a chance to complete all |
| 929 | * required writes/flushing before crtc's "flush |
| 930 | * everything" call below. |
| 931 | */ |
| 932 | drm_atomic_crtc_for_each_plane(plane, crtc) |
| 933 | sde_plane_flush(plane); |
| 934 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 935 | /* Kickoff will be scheduled by outer layer */ |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 938 | /** |
| 939 | * sde_crtc_destroy_state - state destroy hook |
| 940 | * @crtc: drm CRTC |
| 941 | * @state: CRTC state object to release |
| 942 | */ |
| 943 | static void sde_crtc_destroy_state(struct drm_crtc *crtc, |
| 944 | struct drm_crtc_state *state) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 945 | { |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 946 | struct sde_crtc *sde_crtc; |
| 947 | struct sde_crtc_state *cstate; |
| 948 | |
| 949 | if (!crtc || !state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 950 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 951 | return; |
| 952 | } |
| 953 | |
| 954 | sde_crtc = to_sde_crtc(crtc); |
| 955 | cstate = to_sde_crtc_state(state); |
| 956 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 957 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 958 | |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 959 | __drm_atomic_helper_crtc_destroy_state(state); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 960 | |
| 961 | /* destroy value helper */ |
| 962 | msm_property_destroy_state(&sde_crtc->property_info, cstate, |
| 963 | cstate->property_values, cstate->property_blobs); |
| 964 | } |
| 965 | |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 966 | void sde_crtc_commit_kickoff(struct drm_crtc *crtc) |
| 967 | { |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 968 | struct drm_encoder *encoder; |
| 969 | struct drm_device *dev; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 970 | struct sde_crtc *sde_crtc; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 971 | struct msm_drm_private *priv; |
| 972 | struct sde_kms *sde_kms; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 973 | |
| 974 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 975 | SDE_ERROR("invalid argument\n"); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 976 | return; |
| 977 | } |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 978 | dev = crtc->dev; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 979 | sde_crtc = to_sde_crtc(crtc); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 980 | sde_kms = _sde_crtc_get_kms(crtc); |
| 981 | priv = sde_kms->dev->dev_private; |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 982 | |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 983 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 984 | if (encoder->crtc != crtc) |
| 985 | continue; |
| 986 | |
| 987 | /* |
| 988 | * Encoder will flush/start now, unless it has a tx pending. |
| 989 | * If so, it may delay and flush at an irq event (e.g. ppdone) |
| 990 | */ |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 991 | sde_encoder_prepare_for_kickoff(encoder); |
| 992 | } |
| 993 | |
| 994 | if (atomic_read(&sde_crtc->frame_pending) > 2) { |
| 995 | /* framework allows only 1 outstanding + current */ |
| 996 | SDE_ERROR("crtc%d invalid frame pending\n", |
| 997 | crtc->base.id); |
| 998 | SDE_EVT32(DRMID(crtc), 0); |
| 999 | return; |
| 1000 | } else if (atomic_inc_return(&sde_crtc->frame_pending) == 1) { |
| 1001 | /* acquire bandwidth and other resources */ |
| 1002 | SDE_DEBUG("crtc%d first commit\n", crtc->base.id); |
| 1003 | SDE_EVT32(DRMID(crtc), 1); |
| 1004 | } else { |
| 1005 | SDE_DEBUG("crtc%d commit\n", crtc->base.id); |
| 1006 | SDE_EVT32(DRMID(crtc), 2); |
| 1007 | } |
| 1008 | |
| 1009 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 1010 | if (encoder->crtc != crtc) |
| 1011 | continue; |
| 1012 | |
| 1013 | sde_encoder_kickoff(encoder); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1014 | } |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1017 | /** |
| 1018 | * sde_crtc_duplicate_state - state duplicate hook |
| 1019 | * @crtc: Pointer to drm crtc structure |
| 1020 | * @Returns: Pointer to new drm_crtc_state structure |
| 1021 | */ |
| 1022 | static struct drm_crtc_state *sde_crtc_duplicate_state(struct drm_crtc *crtc) |
| 1023 | { |
| 1024 | struct sde_crtc *sde_crtc; |
| 1025 | struct sde_crtc_state *cstate, *old_cstate; |
| 1026 | |
| 1027 | if (!crtc || !crtc->state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1028 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1029 | return NULL; |
| 1030 | } |
| 1031 | |
| 1032 | sde_crtc = to_sde_crtc(crtc); |
| 1033 | old_cstate = to_sde_crtc_state(crtc->state); |
| 1034 | cstate = msm_property_alloc_state(&sde_crtc->property_info); |
| 1035 | if (!cstate) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1036 | SDE_ERROR("failed to allocate state\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1037 | return NULL; |
| 1038 | } |
| 1039 | |
| 1040 | /* duplicate value helper */ |
| 1041 | msm_property_duplicate_state(&sde_crtc->property_info, |
| 1042 | old_cstate, cstate, |
| 1043 | cstate->property_values, cstate->property_blobs); |
| 1044 | |
| 1045 | /* duplicate base helper */ |
| 1046 | __drm_atomic_helper_crtc_duplicate_state(crtc, &cstate->base); |
| 1047 | |
| 1048 | return &cstate->base; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * sde_crtc_reset - reset hook for CRTCs |
| 1053 | * Resets the atomic state for @crtc by freeing the state pointer (which might |
| 1054 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 1055 | * @crtc: Pointer to drm crtc structure |
| 1056 | */ |
| 1057 | static void sde_crtc_reset(struct drm_crtc *crtc) |
| 1058 | { |
| 1059 | struct sde_crtc *sde_crtc; |
| 1060 | struct sde_crtc_state *cstate; |
| 1061 | |
| 1062 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1063 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1064 | return; |
| 1065 | } |
| 1066 | |
| 1067 | /* remove previous state, if present */ |
| 1068 | if (crtc->state) { |
| 1069 | sde_crtc_destroy_state(crtc, crtc->state); |
| 1070 | crtc->state = 0; |
| 1071 | } |
| 1072 | |
| 1073 | sde_crtc = to_sde_crtc(crtc); |
| 1074 | cstate = msm_property_alloc_state(&sde_crtc->property_info); |
| 1075 | if (!cstate) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1076 | SDE_ERROR("failed to allocate state\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1077 | return; |
| 1078 | } |
| 1079 | |
| 1080 | /* reset value helper */ |
| 1081 | msm_property_reset_state(&sde_crtc->property_info, cstate, |
| 1082 | cstate->property_values, cstate->property_blobs); |
| 1083 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1084 | _sde_crtc_set_input_fence_timeout(cstate); |
| 1085 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1086 | cstate->base.crtc = crtc; |
| 1087 | crtc->state = &cstate->base; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1090 | static void sde_crtc_disable(struct drm_crtc *crtc) |
| 1091 | { |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1092 | struct msm_drm_private *priv; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1093 | struct sde_crtc *sde_crtc; |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 1094 | struct sde_crtc_state *cstate; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1095 | struct drm_encoder *encoder; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1096 | struct sde_kms *sde_kms; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1097 | |
| 1098 | if (!crtc) { |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1099 | SDE_ERROR("invalid crtc\n"); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1100 | return; |
| 1101 | } |
| 1102 | sde_crtc = to_sde_crtc(crtc); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 1103 | cstate = to_sde_crtc_state(crtc->state); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1104 | sde_kms = _sde_crtc_get_kms(crtc); |
| 1105 | priv = sde_kms->dev->dev_private; |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1106 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 1107 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1108 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1109 | mutex_lock(&sde_crtc->crtc_lock); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1110 | SDE_EVT32(DRMID(crtc)); |
| 1111 | |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1112 | if (atomic_read(&sde_crtc->vblank_refcount)) { |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1113 | SDE_ERROR("crtc%d invalid vblank refcount\n", |
| 1114 | crtc->base.id); |
| 1115 | SDE_EVT32(DRMID(crtc)); |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1116 | drm_for_each_encoder(encoder, crtc->dev) { |
| 1117 | if (encoder->crtc != crtc) |
| 1118 | continue; |
| 1119 | sde_encoder_register_vblank_callback(encoder, NULL, |
| 1120 | NULL); |
| 1121 | } |
| 1122 | atomic_set(&sde_crtc->vblank_refcount, 0); |
| 1123 | } |
| 1124 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1125 | if (atomic_read(&sde_crtc->frame_pending)) { |
| 1126 | /* release bandwidth and other resources */ |
| 1127 | SDE_ERROR("crtc%d invalid frame pending\n", |
| 1128 | crtc->base.id); |
| 1129 | SDE_EVT32(DRMID(crtc)); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1130 | sde_core_perf_crtc_release_bw(crtc); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1131 | atomic_set(&sde_crtc->frame_pending, 0); |
| 1132 | } |
| 1133 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1134 | sde_core_perf_crtc_update(crtc, 0, true); |
| 1135 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1136 | drm_for_each_encoder(encoder, crtc->dev) { |
| 1137 | if (encoder->crtc != crtc) |
| 1138 | continue; |
| 1139 | sde_encoder_register_frame_event_callback(encoder, NULL, NULL); |
Dhaval Patel | 82c8dbc | 2017-02-18 23:15:10 -0800 | [diff] [blame] | 1140 | sde_encoder_update_rsc_client(encoder, false); |
| 1141 | cstate->rsc_client = NULL; |
| 1142 | cstate->rsc_update = false; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
Lloyd Atkinson | c44a52e | 2016-08-16 16:40:17 -0400 | [diff] [blame] | 1145 | memset(sde_crtc->mixers, 0, sizeof(sde_crtc->mixers)); |
| 1146 | sde_crtc->num_mixers = 0; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1147 | mutex_unlock(&sde_crtc->crtc_lock); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | static void sde_crtc_enable(struct drm_crtc *crtc) |
| 1151 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1152 | struct sde_crtc *sde_crtc; |
| 1153 | struct sde_crtc_mixer *mixer; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1154 | struct sde_hw_mixer *lm; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1155 | struct drm_display_mode *mode; |
| 1156 | struct sde_hw_mixer_cfg cfg; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1157 | struct drm_encoder *encoder; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1158 | int i; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1159 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1160 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1161 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1162 | return; |
| 1163 | } |
| 1164 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 1165 | SDE_DEBUG("crtc%d\n", crtc->base.id); |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1166 | SDE_EVT32(DRMID(crtc)); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1167 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1168 | sde_crtc = to_sde_crtc(crtc); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1169 | mixer = sde_crtc->mixers; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1170 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1171 | if (WARN_ON(!crtc->state)) |
| 1172 | return; |
| 1173 | |
| 1174 | mode = &crtc->state->adjusted_mode; |
| 1175 | |
| 1176 | drm_mode_debug_printmodeline(mode); |
| 1177 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1178 | drm_for_each_encoder(encoder, crtc->dev) { |
| 1179 | if (encoder->crtc != crtc) |
| 1180 | continue; |
| 1181 | sde_encoder_register_frame_event_callback(encoder, |
| 1182 | sde_crtc_frame_event_cb, (void *)crtc); |
| 1183 | } |
| 1184 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1185 | for (i = 0; i < sde_crtc->num_mixers; i++) { |
| 1186 | lm = mixer[i].hw_lm; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1187 | cfg.out_width = sde_crtc_mixer_width(sde_crtc, mode); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 1188 | cfg.out_height = mode->vdisplay; |
| 1189 | cfg.right_mixer = (i == 0) ? false : true; |
| 1190 | cfg.flags = 0; |
| 1191 | lm->ops.setup_mixer_out(lm, &cfg); |
| 1192 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | struct plane_state { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1196 | struct sde_plane_state *sde_pstate; |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 1197 | const struct drm_plane_state *drm_pstate; |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1198 | int stage; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1199 | u32 pipe_id; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1200 | }; |
| 1201 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1202 | static int pstate_cmp(const void *a, const void *b) |
| 1203 | { |
| 1204 | struct plane_state *pa = (struct plane_state *)a; |
| 1205 | struct plane_state *pb = (struct plane_state *)b; |
| 1206 | int rc = 0; |
| 1207 | int pa_zpos, pb_zpos; |
| 1208 | |
| 1209 | pa_zpos = sde_plane_get_property(pa->sde_pstate, PLANE_PROP_ZPOS); |
| 1210 | pb_zpos = sde_plane_get_property(pb->sde_pstate, PLANE_PROP_ZPOS); |
| 1211 | |
| 1212 | if (pa_zpos != pb_zpos) |
| 1213 | rc = pa_zpos - pb_zpos; |
| 1214 | else |
| 1215 | rc = pa->drm_pstate->crtc_x - pb->drm_pstate->crtc_x; |
| 1216 | |
| 1217 | return rc; |
| 1218 | } |
| 1219 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1220 | static int sde_crtc_atomic_check(struct drm_crtc *crtc, |
| 1221 | struct drm_crtc_state *state) |
| 1222 | { |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1223 | struct sde_crtc *sde_crtc; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1224 | struct plane_state pstates[SDE_STAGE_MAX * 4]; |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1225 | struct sde_crtc_state *cstate; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1226 | |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 1227 | const struct drm_plane_state *pstate; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1228 | struct drm_plane *plane; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1229 | struct drm_display_mode *mode; |
| 1230 | |
| 1231 | int cnt = 0, rc = 0, mixer_width, i, z_pos; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1232 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1233 | struct sde_multirect_plane_states multirect_plane[SDE_STAGE_MAX * 2]; |
| 1234 | int multirect_count = 0; |
| 1235 | const struct drm_plane_state *pipe_staged[SSPP_MAX]; |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1236 | int left_zpos_cnt = 0, right_zpos_cnt = 0; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1237 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1238 | if (!crtc) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1239 | SDE_ERROR("invalid crtc\n"); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1240 | return -EINVAL; |
| 1241 | } |
| 1242 | |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 1243 | if (!state->enable || !state->active) { |
| 1244 | SDE_DEBUG("crtc%d -> enable %d, active %d, skip atomic_check\n", |
| 1245 | crtc->base.id, state->enable, state->active); |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1249 | sde_crtc = to_sde_crtc(crtc); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1250 | cstate = to_sde_crtc_state(state); |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1251 | mode = &state->adjusted_mode; |
| 1252 | SDE_DEBUG("%s: check", sde_crtc->name); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1253 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1254 | memset(pipe_staged, 0, sizeof(pipe_staged)); |
| 1255 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1256 | mixer_width = sde_crtc_mixer_width(sde_crtc, mode); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1257 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1258 | /* get plane state for all drm planes associated with crtc state */ |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 1259 | drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) { |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1260 | if (IS_ERR_OR_NULL(pstate)) { |
| 1261 | rc = PTR_ERR(pstate); |
| 1262 | SDE_ERROR("%s: failed to get plane%d state, %d\n", |
| 1263 | sde_crtc->name, plane->base.id, rc); |
Alan Kwong | 8576728 | 2016-10-03 18:03:37 -0400 | [diff] [blame] | 1264 | goto end; |
| 1265 | } |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1266 | if (cnt >= ARRAY_SIZE(pstates)) |
| 1267 | continue; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1268 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1269 | pstates[cnt].sde_pstate = to_sde_plane_state(pstate); |
| 1270 | pstates[cnt].drm_pstate = pstate; |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1271 | pstates[cnt].stage = sde_plane_get_property( |
| 1272 | pstates[cnt].sde_pstate, PLANE_PROP_ZPOS); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1273 | pstates[cnt].pipe_id = sde_plane_pipe(plane); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1274 | |
| 1275 | /* check dim layer stage with every plane */ |
| 1276 | for (i = 0; i < cstate->num_dim_layers; i++) { |
| 1277 | if (pstates[cnt].stage == cstate->dim_layer[i].stage) { |
| 1278 | SDE_ERROR("plane%d/dimlayer in same stage:%d\n", |
| 1279 | plane->base.id, |
| 1280 | cstate->dim_layer[i].stage); |
| 1281 | rc = -EINVAL; |
| 1282 | goto end; |
| 1283 | } |
| 1284 | } |
| 1285 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1286 | if (pipe_staged[pstates[cnt].pipe_id]) { |
| 1287 | multirect_plane[multirect_count].r0 = |
| 1288 | pipe_staged[pstates[cnt].pipe_id]; |
| 1289 | multirect_plane[multirect_count].r1 = pstate; |
| 1290 | multirect_count++; |
| 1291 | |
| 1292 | pipe_staged[pstates[cnt].pipe_id] = NULL; |
| 1293 | } else { |
| 1294 | pipe_staged[pstates[cnt].pipe_id] = pstate; |
| 1295 | } |
| 1296 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1297 | cnt++; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1298 | |
| 1299 | if (CHECK_LAYER_BOUNDS(pstate->crtc_y, pstate->crtc_h, |
| 1300 | mode->vdisplay) || |
| 1301 | CHECK_LAYER_BOUNDS(pstate->crtc_x, pstate->crtc_w, |
| 1302 | mode->hdisplay)) { |
| 1303 | SDE_ERROR("invalid vertical/horizontal destination\n"); |
| 1304 | SDE_ERROR("y:%d h:%d vdisp:%d x:%d w:%d hdisp:%d\n", |
| 1305 | pstate->crtc_y, pstate->crtc_h, mode->vdisplay, |
| 1306 | pstate->crtc_x, pstate->crtc_w, mode->hdisplay); |
| 1307 | rc = -E2BIG; |
| 1308 | goto end; |
| 1309 | } |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1310 | } |
| 1311 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1312 | for (i = 1; i < SSPP_MAX; i++) { |
| 1313 | if (pipe_staged[i] && |
| 1314 | is_sde_plane_virtual(pipe_staged[i]->plane)) { |
| 1315 | SDE_ERROR("invalid use of virtual plane: %d\n", |
| 1316 | pipe_staged[i]->plane->base.id); |
| 1317 | goto end; |
| 1318 | } |
| 1319 | } |
| 1320 | |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1321 | /* Check dim layer rect bounds and stage */ |
| 1322 | for (i = 0; i < cstate->num_dim_layers; i++) { |
| 1323 | if ((CHECK_LAYER_BOUNDS(cstate->dim_layer[i].rect.y, |
| 1324 | cstate->dim_layer[i].rect.h, mode->vdisplay)) || |
| 1325 | (CHECK_LAYER_BOUNDS(cstate->dim_layer[i].rect.x, |
| 1326 | cstate->dim_layer[i].rect.w, mode->hdisplay)) || |
| 1327 | (cstate->dim_layer[i].stage >= SDE_STAGE_MAX) || |
| 1328 | (!cstate->dim_layer[i].rect.w) || |
| 1329 | (!cstate->dim_layer[i].rect.h)) { |
| 1330 | SDE_ERROR("invalid dim_layer:{%d,%d,%d,%d}, stage:%d\n", |
| 1331 | cstate->dim_layer[i].rect.x, |
| 1332 | cstate->dim_layer[i].rect.y, |
| 1333 | cstate->dim_layer[i].rect.w, |
| 1334 | cstate->dim_layer[i].rect.h, |
| 1335 | cstate->dim_layer[i].stage); |
| 1336 | SDE_ERROR("display: %dx%d\n", mode->hdisplay, |
| 1337 | mode->vdisplay); |
| 1338 | rc = -E2BIG; |
| 1339 | goto end; |
| 1340 | } |
| 1341 | } |
| 1342 | |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1343 | /* assign mixer stages based on sorted zpos property */ |
| 1344 | sort(pstates, cnt, sizeof(pstates[0]), pstate_cmp, NULL); |
| 1345 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1346 | if (!sde_is_custom_client()) { |
| 1347 | int stage_old = pstates[0].stage; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1348 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1349 | z_pos = 0; |
| 1350 | for (i = 0; i < cnt; i++) { |
| 1351 | if (stage_old != pstates[i].stage) |
| 1352 | ++z_pos; |
| 1353 | stage_old = pstates[i].stage; |
| 1354 | pstates[i].stage = z_pos; |
| 1355 | } |
| 1356 | } |
| 1357 | |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1358 | z_pos = -1; |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1359 | for (i = 0; i < cnt; i++) { |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1360 | /* reset counts at every new blend stage */ |
| 1361 | if (pstates[i].stage != z_pos) { |
| 1362 | left_zpos_cnt = 0; |
| 1363 | right_zpos_cnt = 0; |
| 1364 | z_pos = pstates[i].stage; |
| 1365 | } |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1366 | |
| 1367 | /* verify z_pos setting before using it */ |
Clarence Ip | 649989a | 2016-10-21 14:28:34 -0400 | [diff] [blame] | 1368 | if (z_pos >= SDE_STAGE_MAX - SDE_STAGE_0) { |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1369 | SDE_ERROR("> %d plane stages assigned\n", |
| 1370 | SDE_STAGE_MAX - SDE_STAGE_0); |
| 1371 | rc = -EINVAL; |
| 1372 | goto end; |
| 1373 | } else if (pstates[i].drm_pstate->crtc_x < mixer_width) { |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1374 | if (left_zpos_cnt == 2) { |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1375 | SDE_ERROR("> 2 planes @ stage %d on left\n", |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1376 | z_pos); |
| 1377 | rc = -EINVAL; |
| 1378 | goto end; |
| 1379 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1380 | left_zpos_cnt++; |
| 1381 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1382 | } else { |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1383 | if (right_zpos_cnt == 2) { |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1384 | SDE_ERROR("> 2 planes @ stage %d on right\n", |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1385 | z_pos); |
| 1386 | rc = -EINVAL; |
| 1387 | goto end; |
| 1388 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1389 | right_zpos_cnt++; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1390 | } |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1391 | |
Clarence Ip | c47a069 | 2016-10-11 10:54:17 -0400 | [diff] [blame] | 1392 | pstates[i].sde_pstate->stage = z_pos + SDE_STAGE_0; |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1393 | SDE_DEBUG("%s: zpos %d", sde_crtc->name, z_pos); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1394 | } |
| 1395 | |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1396 | for (i = 0; i < multirect_count; i++) { |
| 1397 | if (sde_plane_validate_multirect_v2(&multirect_plane[i])) { |
| 1398 | SDE_ERROR( |
| 1399 | "multirect validation failed for planes (%d - %d)\n", |
| 1400 | multirect_plane[i].r0->plane->base.id, |
| 1401 | multirect_plane[i].r1->plane->base.id); |
| 1402 | rc = -EINVAL; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1403 | goto end; |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1407 | rc = sde_core_perf_crtc_check(crtc, state); |
| 1408 | if (rc) { |
| 1409 | SDE_ERROR("crtc%d failed performance check %d\n", |
| 1410 | crtc->base.id, rc); |
| 1411 | goto end; |
| 1412 | } |
| 1413 | |
Lloyd Atkinson | 629ce1f | 2016-10-27 16:50:26 -0400 | [diff] [blame] | 1414 | /* |
| 1415 | * enforce pipe priority restrictions |
| 1416 | * use pstates sorted by stage to check planes on same stage |
| 1417 | * we assume that all pipes are in source split so its valid to compare |
| 1418 | * without taking into account left/right mixer placement |
| 1419 | */ |
| 1420 | for (i = 1; i < cnt; i++) { |
| 1421 | struct plane_state *prv_pstate, *cur_pstate; |
| 1422 | int32_t prv_x, cur_x, prv_id, cur_id; |
| 1423 | |
| 1424 | prv_pstate = &pstates[i - 1]; |
| 1425 | cur_pstate = &pstates[i]; |
| 1426 | if (prv_pstate->stage != cur_pstate->stage) |
| 1427 | continue; |
| 1428 | |
| 1429 | prv_x = prv_pstate->drm_pstate->crtc_x; |
| 1430 | cur_x = cur_pstate->drm_pstate->crtc_x; |
| 1431 | prv_id = prv_pstate->sde_pstate->base.plane->base.id; |
| 1432 | cur_id = cur_pstate->sde_pstate->base.plane->base.id; |
| 1433 | |
| 1434 | /* |
| 1435 | * Planes are enumerated in pipe-priority order such that planes |
| 1436 | * with lower drm_id must be left-most in a shared blend-stage |
| 1437 | * when using source split. |
| 1438 | */ |
| 1439 | if (cur_x > prv_x && cur_id < prv_id) { |
| 1440 | SDE_ERROR( |
| 1441 | "shared z_pos %d lower id plane%d @ x%d should be left of plane%d @ x %d\n", |
| 1442 | cur_pstate->stage, cur_id, cur_x, |
| 1443 | prv_id, prv_x); |
| 1444 | rc = -EINVAL; |
| 1445 | goto end; |
| 1446 | } else if (cur_x < prv_x && cur_id > prv_id) { |
| 1447 | SDE_ERROR( |
| 1448 | "shared z_pos %d lower id plane%d @ x%d should be left of plane%d @ x %d\n", |
| 1449 | cur_pstate->stage, prv_id, prv_x, |
| 1450 | cur_id, cur_x); |
| 1451 | rc = -EINVAL; |
| 1452 | goto end; |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1457 | end: |
| 1458 | return rc; |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 1461 | int sde_crtc_vblank(struct drm_crtc *crtc, bool en) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1462 | { |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1463 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1464 | struct drm_encoder *encoder; |
| 1465 | struct drm_device *dev = crtc->dev; |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 1466 | |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1467 | if (en && atomic_inc_return(&sde_crtc->vblank_refcount) == 1) { |
| 1468 | SDE_DEBUG("crtc%d vblank enable\n", crtc->base.id); |
| 1469 | } else if (!en && atomic_read(&sde_crtc->vblank_refcount) < 1) { |
| 1470 | SDE_ERROR("crtc%d invalid vblank disable\n", crtc->base.id); |
| 1471 | return -EINVAL; |
| 1472 | } else if (!en && atomic_dec_return(&sde_crtc->vblank_refcount) == 0) { |
| 1473 | SDE_DEBUG("crtc%d vblank disable\n", crtc->base.id); |
| 1474 | } else { |
| 1475 | SDE_DEBUG("crtc%d vblank %s refcount:%d\n", |
| 1476 | crtc->base.id, |
| 1477 | en ? "enable" : "disable", |
| 1478 | atomic_read(&sde_crtc->vblank_refcount)); |
| 1479 | return 0; |
| 1480 | } |
Lloyd Atkinson | e5c2c0b | 2016-07-05 12:23:29 -0400 | [diff] [blame] | 1481 | |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1482 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 1483 | if (encoder->crtc != crtc) |
| 1484 | continue; |
Alan Kwong | cf42ee0 | 2016-10-04 09:19:17 -0400 | [diff] [blame] | 1485 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1486 | SDE_EVT32(DRMID(crtc), en); |
Lloyd Atkinson | 5d72278 | 2016-05-30 14:09:41 -0400 | [diff] [blame] | 1487 | |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1488 | if (en) |
| 1489 | sde_encoder_register_vblank_callback(encoder, |
| 1490 | sde_crtc_vblank_cb, (void *)crtc); |
| 1491 | else |
| 1492 | sde_encoder_register_vblank_callback(encoder, NULL, |
| 1493 | NULL); |
| 1494 | } |
Abhijit Kulkarni | 7acb326 | 2016-07-05 15:27:25 -0400 | [diff] [blame] | 1495 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1496 | return 0; |
| 1497 | } |
| 1498 | |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 1499 | void sde_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file) |
| 1500 | { |
| 1501 | struct sde_crtc *sde_crtc = to_sde_crtc(crtc); |
| 1502 | |
Alan Kwong | 163d261 | 2016-11-03 00:56:56 -0400 | [diff] [blame] | 1503 | SDE_DEBUG("%s: cancel: %p\n", sde_crtc->name, file); |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1504 | _sde_crtc_complete_flip(crtc, file); |
Lloyd Atkinson | 5217336c | 2016-09-15 18:21:18 -0400 | [diff] [blame] | 1505 | } |
| 1506 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1507 | /** |
| 1508 | * sde_crtc_install_properties - install all drm properties for crtc |
| 1509 | * @crtc: Pointer to drm crtc structure |
| 1510 | */ |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1511 | static void sde_crtc_install_properties(struct drm_crtc *crtc, |
| 1512 | struct sde_mdss_cfg *catalog) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1513 | { |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1514 | struct sde_crtc *sde_crtc; |
| 1515 | struct drm_device *dev; |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1516 | struct sde_kms_info *info; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1517 | struct sde_kms *sde_kms; |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1518 | |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1519 | SDE_DEBUG("\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1520 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1521 | if (!crtc || !catalog) { |
| 1522 | SDE_ERROR("invalid crtc or catalog\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1523 | return; |
| 1524 | } |
| 1525 | |
| 1526 | sde_crtc = to_sde_crtc(crtc); |
| 1527 | dev = crtc->dev; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1528 | sde_kms = _sde_crtc_get_kms(crtc); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1529 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1530 | info = kzalloc(sizeof(struct sde_kms_info), GFP_KERNEL); |
| 1531 | if (!info) { |
| 1532 | SDE_ERROR("failed to allocate info memory\n"); |
| 1533 | return; |
| 1534 | } |
| 1535 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1536 | /* range properties */ |
| 1537 | msm_property_install_range(&sde_crtc->property_info, |
Dhaval Patel | 4e57484 | 2016-08-23 15:11:37 -0700 | [diff] [blame] | 1538 | "input_fence_timeout", 0x0, 0, SDE_CRTC_MAX_INPUT_FENCE_TIMEOUT, |
| 1539 | SDE_CRTC_INPUT_FENCE_TIMEOUT, CRTC_PROP_INPUT_FENCE_TIMEOUT); |
| 1540 | |
| 1541 | msm_property_install_range(&sde_crtc->property_info, "output_fence", |
| 1542 | 0x0, 0, INR_OPEN_MAX, 0x0, CRTC_PROP_OUTPUT_FENCE); |
Clarence Ip | 1d9728b | 2016-09-01 11:10:54 -0400 | [diff] [blame] | 1543 | |
| 1544 | msm_property_install_range(&sde_crtc->property_info, |
| 1545 | "output_fence_offset", 0x0, 0, 1, 0, |
| 1546 | CRTC_PROP_OUTPUT_FENCE_OFFSET); |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1547 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1548 | msm_property_install_range(&sde_crtc->property_info, |
| 1549 | "core_clk", 0x0, 0, U64_MAX, |
| 1550 | sde_kms->perf.max_core_clk_rate, |
| 1551 | CRTC_PROP_CORE_CLK); |
| 1552 | msm_property_install_range(&sde_crtc->property_info, |
| 1553 | "core_ab", 0x0, 0, U64_MAX, |
| 1554 | SDE_POWER_HANDLE_DATA_BUS_AB_QUOTA, |
| 1555 | CRTC_PROP_CORE_AB); |
| 1556 | msm_property_install_range(&sde_crtc->property_info, |
| 1557 | "core_ib", 0x0, 0, U64_MAX, |
| 1558 | SDE_POWER_HANDLE_DATA_BUS_IB_QUOTA, |
| 1559 | CRTC_PROP_CORE_IB); |
| 1560 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1561 | msm_property_install_blob(&sde_crtc->property_info, "capabilities", |
| 1562 | DRM_MODE_PROP_IMMUTABLE, CRTC_PROP_INFO); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1563 | |
| 1564 | if (catalog->has_dim_layer) { |
| 1565 | msm_property_install_volatile_range(&sde_crtc->property_info, |
| 1566 | "dim_layer_v1", 0x0, 0, ~0, 0, CRTC_PROP_DIM_LAYER_V1); |
| 1567 | } |
| 1568 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1569 | sde_kms_info_reset(info); |
| 1570 | |
| 1571 | sde_kms_info_add_keyint(info, "hw_version", catalog->hwversion); |
| 1572 | sde_kms_info_add_keyint(info, "max_linewidth", |
| 1573 | catalog->max_mixer_width); |
| 1574 | sde_kms_info_add_keyint(info, "max_blendstages", |
| 1575 | catalog->max_mixer_blendstages); |
| 1576 | if (catalog->qseed_type == SDE_SSPP_SCALER_QSEED2) |
| 1577 | sde_kms_info_add_keystr(info, "qseed_type", "qseed2"); |
| 1578 | if (catalog->qseed_type == SDE_SSPP_SCALER_QSEED3) |
| 1579 | sde_kms_info_add_keystr(info, "qseed_type", "qseed3"); |
Jeykumar Sankaran | 2e65503 | 2017-02-04 14:05:45 -0800 | [diff] [blame] | 1580 | |
| 1581 | if (sde_is_custom_client()) { |
| 1582 | if (catalog->smart_dma_rev == SDE_SSPP_SMART_DMA_V1) |
| 1583 | sde_kms_info_add_keystr(info, |
| 1584 | "smart_dma_rev", "smart_dma_v1"); |
| 1585 | if (catalog->smart_dma_rev == SDE_SSPP_SMART_DMA_V2) |
| 1586 | sde_kms_info_add_keystr(info, |
| 1587 | "smart_dma_rev", "smart_dma_v2"); |
| 1588 | } |
| 1589 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1590 | sde_kms_info_add_keyint(info, "has_src_split", catalog->has_src_split); |
Alan Kwong | 2f84f8a | 2016-12-29 13:07:47 -0500 | [diff] [blame] | 1591 | if (catalog->perf.max_bw_low) |
| 1592 | sde_kms_info_add_keyint(info, "max_bandwidth_low", |
| 1593 | catalog->perf.max_bw_low); |
| 1594 | if (catalog->perf.max_bw_high) |
| 1595 | sde_kms_info_add_keyint(info, "max_bandwidth_high", |
| 1596 | catalog->perf.max_bw_high); |
| 1597 | if (sde_kms->perf.max_core_clk_rate) |
| 1598 | sde_kms_info_add_keyint(info, "max_mdp_clk", |
| 1599 | sde_kms->perf.max_core_clk_rate); |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1600 | msm_property_set_blob(&sde_crtc->property_info, &sde_crtc->blob_info, |
| 1601 | info->data, info->len, CRTC_PROP_INFO); |
| 1602 | |
| 1603 | kfree(info); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * sde_crtc_atomic_set_property - atomically set a crtc drm property |
| 1608 | * @crtc: Pointer to drm crtc structure |
| 1609 | * @state: Pointer to drm crtc state structure |
| 1610 | * @property: Pointer to targeted drm property |
| 1611 | * @val: Updated property value |
| 1612 | * @Returns: Zero on success |
| 1613 | */ |
| 1614 | static int sde_crtc_atomic_set_property(struct drm_crtc *crtc, |
| 1615 | struct drm_crtc_state *state, |
| 1616 | struct drm_property *property, |
| 1617 | uint64_t val) |
| 1618 | { |
| 1619 | struct sde_crtc *sde_crtc; |
| 1620 | struct sde_crtc_state *cstate; |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1621 | int idx, ret = -EINVAL; |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1622 | |
| 1623 | if (!crtc || !state || !property) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1624 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1625 | } else { |
| 1626 | sde_crtc = to_sde_crtc(crtc); |
| 1627 | cstate = to_sde_crtc_state(state); |
| 1628 | ret = msm_property_atomic_set(&sde_crtc->property_info, |
| 1629 | cstate->property_values, cstate->property_blobs, |
| 1630 | property, val); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1631 | if (!ret) { |
| 1632 | idx = msm_property_index(&sde_crtc->property_info, |
| 1633 | property); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1634 | switch (idx) { |
| 1635 | case CRTC_PROP_INPUT_FENCE_TIMEOUT: |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1636 | _sde_crtc_set_input_fence_timeout(cstate); |
Veera Sundaram Sankaran | 3171ff8 | 2017-01-04 14:34:47 -0800 | [diff] [blame] | 1637 | break; |
| 1638 | case CRTC_PROP_DIM_LAYER_V1: |
| 1639 | _sde_crtc_set_dim_layer_v1(cstate, (void *)val); |
| 1640 | break; |
| 1641 | default: |
| 1642 | /* nothing to do */ |
| 1643 | break; |
| 1644 | } |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1645 | } else { |
| 1646 | ret = sde_cp_crtc_set_property(crtc, |
| 1647 | property, val); |
Clarence Ip | cae1bb6 | 2016-07-07 12:07:13 -0400 | [diff] [blame] | 1648 | } |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1649 | if (ret) |
| 1650 | DRM_ERROR("failed to set the property\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | return ret; |
| 1654 | } |
| 1655 | |
| 1656 | /** |
| 1657 | * sde_crtc_set_property - set a crtc drm property |
| 1658 | * @crtc: Pointer to drm crtc structure |
| 1659 | * @property: Pointer to targeted drm property |
| 1660 | * @val: Updated property value |
| 1661 | * @Returns: Zero on success |
| 1662 | */ |
| 1663 | static int sde_crtc_set_property(struct drm_crtc *crtc, |
| 1664 | struct drm_property *property, uint64_t val) |
| 1665 | { |
Lloyd Atkinson | 4f1c869 | 2016-09-14 14:04:25 -0400 | [diff] [blame] | 1666 | SDE_DEBUG("\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1667 | |
| 1668 | return sde_crtc_atomic_set_property(crtc, crtc->state, property, val); |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * sde_crtc_atomic_get_property - retrieve a crtc drm property |
| 1673 | * @crtc: Pointer to drm crtc structure |
| 1674 | * @state: Pointer to drm crtc state structure |
| 1675 | * @property: Pointer to targeted drm property |
| 1676 | * @val: Pointer to variable for receiving property value |
| 1677 | * @Returns: Zero on success |
| 1678 | */ |
| 1679 | static int sde_crtc_atomic_get_property(struct drm_crtc *crtc, |
| 1680 | const struct drm_crtc_state *state, |
| 1681 | struct drm_property *property, |
| 1682 | uint64_t *val) |
| 1683 | { |
| 1684 | struct sde_crtc *sde_crtc; |
| 1685 | struct sde_crtc_state *cstate; |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1686 | int i, ret = -EINVAL; |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1687 | |
| 1688 | if (!crtc || !state) { |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1689 | SDE_ERROR("invalid argument(s)\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1690 | } else { |
| 1691 | sde_crtc = to_sde_crtc(crtc); |
| 1692 | cstate = to_sde_crtc_state(state); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1693 | i = msm_property_index(&sde_crtc->property_info, property); |
| 1694 | if (i == CRTC_PROP_OUTPUT_FENCE) { |
Clarence Ip | 1d9728b | 2016-09-01 11:10:54 -0400 | [diff] [blame] | 1695 | int offset = sde_crtc_get_property(cstate, |
| 1696 | CRTC_PROP_OUTPUT_FENCE_OFFSET); |
| 1697 | |
| 1698 | ret = sde_fence_create( |
| 1699 | &sde_crtc->output_fence, val, offset); |
| 1700 | if (ret) |
| 1701 | SDE_ERROR("fence create failed\n"); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1702 | } else { |
| 1703 | ret = msm_property_atomic_get(&sde_crtc->property_info, |
| 1704 | cstate->property_values, |
| 1705 | cstate->property_blobs, property, val); |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1706 | if (ret) |
| 1707 | ret = sde_cp_crtc_get_property(crtc, |
| 1708 | property, val); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1709 | } |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1710 | if (ret) |
| 1711 | DRM_ERROR("get property failed\n"); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1712 | } |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1713 | return ret; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1716 | #ifdef CONFIG_DEBUG_FS |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1717 | static int _sde_debugfs_status_show(struct seq_file *s, void *data) |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1718 | { |
| 1719 | struct sde_crtc *sde_crtc; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1720 | struct sde_plane_state *pstate = NULL; |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1721 | struct sde_crtc_mixer *m; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1722 | |
| 1723 | struct drm_crtc *crtc; |
| 1724 | struct drm_plane *plane; |
| 1725 | struct drm_display_mode *mode; |
| 1726 | struct drm_framebuffer *fb; |
| 1727 | struct drm_plane_state *state; |
| 1728 | |
| 1729 | int i, out_width; |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1730 | |
| 1731 | if (!s || !s->private) |
| 1732 | return -EINVAL; |
| 1733 | |
| 1734 | sde_crtc = s->private; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1735 | crtc = &sde_crtc->base; |
| 1736 | |
| 1737 | mutex_lock(&sde_crtc->crtc_lock); |
| 1738 | mode = &crtc->state->adjusted_mode; |
| 1739 | out_width = sde_crtc_mixer_width(sde_crtc, mode); |
| 1740 | |
| 1741 | seq_printf(s, "crtc:%d width:%d height:%d\n", crtc->base.id, |
| 1742 | mode->hdisplay, mode->vdisplay); |
| 1743 | |
| 1744 | seq_puts(s, "\n"); |
| 1745 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1746 | for (i = 0; i < sde_crtc->num_mixers; ++i) { |
Lloyd Atkinson | e7bcdd2 | 2016-08-11 10:53:37 -0400 | [diff] [blame] | 1747 | m = &sde_crtc->mixers[i]; |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1748 | if (!m->hw_lm) |
| 1749 | seq_printf(s, "\tmixer[%d] has no lm\n", i); |
| 1750 | else if (!m->hw_ctl) |
| 1751 | seq_printf(s, "\tmixer[%d] has no ctl\n", i); |
| 1752 | else |
| 1753 | seq_printf(s, "\tmixer:%d ctl:%d width:%d height:%d\n", |
| 1754 | m->hw_lm->idx - LM_0, m->hw_ctl->idx - CTL_0, |
| 1755 | out_width, mode->vdisplay); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1756 | } |
Dhaval Patel | 44f1247 | 2016-08-29 12:19:47 -0700 | [diff] [blame] | 1757 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1758 | seq_puts(s, "\n"); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1759 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1760 | drm_atomic_crtc_for_each_plane(plane, crtc) { |
| 1761 | pstate = to_sde_plane_state(plane->state); |
| 1762 | state = plane->state; |
| 1763 | |
| 1764 | if (!pstate || !state) |
| 1765 | continue; |
| 1766 | |
| 1767 | seq_printf(s, "\tplane:%u stage:%d\n", plane->base.id, |
| 1768 | pstate->stage); |
| 1769 | |
| 1770 | if (plane->state->fb) { |
| 1771 | fb = plane->state->fb; |
| 1772 | |
| 1773 | seq_printf(s, "\tfb:%d image format:%4.4s wxh:%ux%u bpp:%d\n", |
| 1774 | fb->base.id, (char *) &fb->pixel_format, |
| 1775 | fb->width, fb->height, fb->bits_per_pixel); |
| 1776 | |
| 1777 | seq_puts(s, "\t"); |
| 1778 | for (i = 0; i < ARRAY_SIZE(fb->modifier); i++) |
| 1779 | seq_printf(s, "modifier[%d]:%8llu ", i, |
| 1780 | fb->modifier[i]); |
| 1781 | seq_puts(s, "\n"); |
| 1782 | |
| 1783 | seq_puts(s, "\t"); |
| 1784 | for (i = 0; i < ARRAY_SIZE(fb->pitches); i++) |
| 1785 | seq_printf(s, "pitches[%d]:%8u ", i, |
| 1786 | fb->pitches[i]); |
| 1787 | seq_puts(s, "\n"); |
| 1788 | |
| 1789 | seq_puts(s, "\t"); |
| 1790 | for (i = 0; i < ARRAY_SIZE(fb->offsets); i++) |
| 1791 | seq_printf(s, "offsets[%d]:%8u ", i, |
| 1792 | fb->offsets[i]); |
Dhaval Patel | 48c7602 | 2016-09-01 17:51:23 -0700 | [diff] [blame] | 1793 | seq_puts(s, "\n"); |
| 1794 | } |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1795 | |
| 1796 | seq_printf(s, "\tsrc_x:%4d src_y:%4d src_w:%4d src_h:%4d\n", |
| 1797 | state->src_x, state->src_y, state->src_w, state->src_h); |
| 1798 | |
| 1799 | seq_printf(s, "\tdst x:%4d dst_y:%4d dst_w:%4d dst_h:%4d\n", |
| 1800 | state->crtc_x, state->crtc_y, state->crtc_w, |
| 1801 | state->crtc_h); |
| 1802 | seq_puts(s, "\n"); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1803 | } |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1804 | |
| 1805 | if (sde_crtc->vblank_cb_count) { |
| 1806 | ktime_t diff = ktime_sub(ktime_get(), sde_crtc->vblank_cb_time); |
| 1807 | s64 diff_ms = ktime_to_ms(diff); |
| 1808 | s64 fps = diff_ms ? DIV_ROUND_CLOSEST( |
| 1809 | sde_crtc->vblank_cb_count * 1000, diff_ms) : 0; |
| 1810 | |
| 1811 | seq_printf(s, |
| 1812 | "vblank fps:%lld count:%u total:%llums\n", |
| 1813 | fps, |
| 1814 | sde_crtc->vblank_cb_count, |
| 1815 | ktime_to_ms(diff)); |
| 1816 | |
| 1817 | /* reset time & count for next measurement */ |
| 1818 | sde_crtc->vblank_cb_count = 0; |
| 1819 | sde_crtc->vblank_cb_time = ktime_set(0, 0); |
| 1820 | } |
| 1821 | |
| 1822 | seq_printf(s, "vblank_refcount:%d\n", |
| 1823 | atomic_read(&sde_crtc->vblank_refcount)); |
| 1824 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1825 | mutex_unlock(&sde_crtc->crtc_lock); |
| 1826 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1827 | return 0; |
| 1828 | } |
| 1829 | |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1830 | static int _sde_debugfs_status_open(struct inode *inode, struct file *file) |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1831 | { |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1832 | return single_open(file, _sde_debugfs_status_show, inode->i_private); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1833 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1834 | #endif |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1835 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1836 | static const struct drm_crtc_funcs sde_crtc_funcs = { |
| 1837 | .set_config = drm_atomic_helper_set_config, |
| 1838 | .destroy = sde_crtc_destroy, |
| 1839 | .page_flip = drm_atomic_helper_page_flip, |
| 1840 | .set_property = sde_crtc_set_property, |
| 1841 | .atomic_set_property = sde_crtc_atomic_set_property, |
| 1842 | .atomic_get_property = sde_crtc_atomic_get_property, |
| 1843 | .reset = sde_crtc_reset, |
| 1844 | .atomic_duplicate_state = sde_crtc_duplicate_state, |
| 1845 | .atomic_destroy_state = sde_crtc_destroy_state, |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1846 | }; |
| 1847 | |
| 1848 | static const struct drm_crtc_helper_funcs sde_crtc_helper_funcs = { |
| 1849 | .mode_fixup = sde_crtc_mode_fixup, |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1850 | .disable = sde_crtc_disable, |
| 1851 | .enable = sde_crtc_enable, |
| 1852 | .atomic_check = sde_crtc_atomic_check, |
| 1853 | .atomic_begin = sde_crtc_atomic_begin, |
| 1854 | .atomic_flush = sde_crtc_atomic_flush, |
| 1855 | }; |
| 1856 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1857 | #ifdef CONFIG_DEBUG_FS |
| 1858 | #define DEFINE_SDE_DEBUGFS_SEQ_FOPS(__prefix) \ |
| 1859 | static int __prefix ## _open(struct inode *inode, struct file *file) \ |
| 1860 | { \ |
| 1861 | return single_open(file, __prefix ## _show, inode->i_private); \ |
| 1862 | } \ |
| 1863 | static const struct file_operations __prefix ## _fops = { \ |
| 1864 | .owner = THIS_MODULE, \ |
| 1865 | .open = __prefix ## _open, \ |
| 1866 | .release = single_release, \ |
| 1867 | .read = seq_read, \ |
| 1868 | .llseek = seq_lseek, \ |
| 1869 | } |
| 1870 | |
| 1871 | static int sde_crtc_debugfs_state_show(struct seq_file *s, void *v) |
| 1872 | { |
| 1873 | struct drm_crtc *crtc = (struct drm_crtc *) s->private; |
| 1874 | struct sde_crtc_state *cstate = to_sde_crtc_state(crtc->state); |
| 1875 | |
| 1876 | seq_printf(s, "num_connectors: %d\n", cstate->num_connectors); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 1877 | seq_printf(s, "client type: %d\n", sde_crtc_get_client_type(crtc)); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1878 | seq_printf(s, "intf_mode: %d\n", cstate->intf_mode); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1879 | seq_printf(s, "bw_ctl: %llu\n", cstate->cur_perf.bw_ctl); |
| 1880 | seq_printf(s, "core_clk_rate: %u\n", cstate->cur_perf.core_clk_rate); |
| 1881 | seq_printf(s, "max_per_pipe_ib: %llu\n", |
| 1882 | cstate->cur_perf.max_per_pipe_ib); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1883 | |
| 1884 | return 0; |
| 1885 | } |
| 1886 | DEFINE_SDE_DEBUGFS_SEQ_FOPS(sde_crtc_debugfs_state); |
| 1887 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1888 | static void _sde_crtc_init_debugfs(struct sde_crtc *sde_crtc, |
| 1889 | struct sde_kms *sde_kms) |
| 1890 | { |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1891 | static const struct file_operations debugfs_status_fops = { |
| 1892 | .open = _sde_debugfs_status_open, |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1893 | .read = seq_read, |
| 1894 | .llseek = seq_lseek, |
| 1895 | .release = single_release, |
| 1896 | }; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1897 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1898 | if (sde_crtc && sde_kms) { |
| 1899 | sde_crtc->debugfs_root = debugfs_create_dir(sde_crtc->name, |
| 1900 | sde_debugfs_get_root(sde_kms)); |
| 1901 | if (sde_crtc->debugfs_root) { |
| 1902 | /* don't error check these */ |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1903 | debugfs_create_file("status", 0444, |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1904 | sde_crtc->debugfs_root, |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1905 | sde_crtc, &debugfs_status_fops); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 1906 | debugfs_create_file("state", 0644, |
| 1907 | sde_crtc->debugfs_root, |
| 1908 | &sde_crtc->base, |
| 1909 | &sde_crtc_debugfs_state_fops); |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1910 | } |
| 1911 | } |
| 1912 | } |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 1913 | #else |
| 1914 | static void _sde_crtc_init_debugfs(struct sde_crtc *sde_crtc, |
| 1915 | struct sde_kms *sde_kms) |
| 1916 | { |
| 1917 | } |
| 1918 | #endif |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1919 | |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1920 | /* initialize crtc */ |
Lloyd Atkinson | ac93364 | 2016-09-14 11:52:00 -0400 | [diff] [blame] | 1921 | struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane) |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1922 | { |
| 1923 | struct drm_crtc *crtc = NULL; |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1924 | struct sde_crtc *sde_crtc = NULL; |
| 1925 | struct msm_drm_private *priv = NULL; |
| 1926 | struct sde_kms *kms = NULL; |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1927 | int i; |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1928 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1929 | priv = dev->dev_private; |
| 1930 | kms = to_sde_kms(priv->kms); |
| 1931 | |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1932 | sde_crtc = kzalloc(sizeof(*sde_crtc), GFP_KERNEL); |
| 1933 | if (!sde_crtc) |
| 1934 | return ERR_PTR(-ENOMEM); |
| 1935 | |
| 1936 | crtc = &sde_crtc->base; |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1937 | crtc->dev = dev; |
Alan Kwong | 07da098 | 2016-11-04 12:57:45 -0400 | [diff] [blame] | 1938 | atomic_set(&sde_crtc->vblank_refcount, 0); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1939 | |
Alan Kwong | 628d19e | 2016-10-31 13:50:13 -0400 | [diff] [blame] | 1940 | spin_lock_init(&sde_crtc->spin_lock); |
| 1941 | atomic_set(&sde_crtc->frame_pending, 0); |
| 1942 | |
| 1943 | INIT_LIST_HEAD(&sde_crtc->frame_event_list); |
| 1944 | for (i = 0; i < ARRAY_SIZE(sde_crtc->frame_events); i++) { |
| 1945 | INIT_LIST_HEAD(&sde_crtc->frame_events[i].list); |
| 1946 | list_add(&sde_crtc->frame_events[i].list, |
| 1947 | &sde_crtc->frame_event_list); |
| 1948 | kthread_init_work(&sde_crtc->frame_events[i].work, |
| 1949 | sde_crtc_frame_event_work); |
| 1950 | } |
| 1951 | |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 1952 | drm_crtc_init_with_planes(dev, crtc, plane, NULL, &sde_crtc_funcs, |
| 1953 | NULL); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1954 | |
| 1955 | drm_crtc_helper_add(crtc, &sde_crtc_helper_funcs); |
Abhijit Kulkarni | 3e3e0d2 | 2016-06-24 17:56:13 -0400 | [diff] [blame] | 1956 | plane->crtc = crtc; |
| 1957 | |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1958 | /* save user friendly CRTC name for later */ |
| 1959 | snprintf(sde_crtc->name, SDE_CRTC_NAME_SIZE, "crtc%u", crtc->base.id); |
| 1960 | |
Clarence Ip | 9a74a44 | 2016-08-25 18:29:03 -0400 | [diff] [blame] | 1961 | /* initialize output fence support */ |
Dhaval Patel | 3fbe6bf | 2016-10-20 20:00:41 -0700 | [diff] [blame] | 1962 | mutex_init(&sde_crtc->crtc_lock); |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 1963 | sde_fence_init(&sde_crtc->output_fence, sde_crtc->name, crtc->base.id); |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 1964 | |
| 1965 | /* initialize debugfs support */ |
Clarence Ip | 8f7366c | 2016-07-05 12:15:26 -0400 | [diff] [blame] | 1966 | _sde_crtc_init_debugfs(sde_crtc, kms); |
| 1967 | |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1968 | /* create CRTC properties */ |
| 1969 | msm_property_init(&sde_crtc->property_info, &crtc->base, dev, |
| 1970 | priv->crtc_property, sde_crtc->property_data, |
| 1971 | CRTC_PROP_COUNT, CRTC_PROP_BLOBCOUNT, |
| 1972 | sizeof(struct sde_crtc_state)); |
| 1973 | |
Dhaval Patel | e4a5dda | 2016-10-13 19:29:30 -0700 | [diff] [blame] | 1974 | sde_crtc_install_properties(crtc, kms->catalog); |
Gopikrishnaiah Anandan | 703eb90 | 2016-10-06 18:43:57 -0700 | [diff] [blame] | 1975 | |
| 1976 | /* Install color processing properties */ |
Gopikrishnaiah Anandan | e0e5e0c | 2016-05-25 11:05:33 -0700 | [diff] [blame] | 1977 | sde_cp_crtc_init(crtc); |
Gopikrishnaiah Anandan | 703eb90 | 2016-10-06 18:43:57 -0700 | [diff] [blame] | 1978 | sde_cp_crtc_install_properties(crtc); |
Clarence Ip | 7a753bb | 2016-07-07 11:47:44 -0400 | [diff] [blame] | 1979 | |
Dhaval Patel | ec10fad | 2016-08-22 14:40:48 -0700 | [diff] [blame] | 1980 | SDE_DEBUG("%s: successfully initialized crtc\n", sde_crtc->name); |
Narendra Muppalla | 1b0b335 | 2015-09-29 10:16:51 -0700 | [diff] [blame] | 1981 | return crtc; |
| 1982 | } |